[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdebase/kcontrol/kfontinst/kfontinst
From:       Craig Drummond <craig () kde ! org>
Date:       2005-04-20 19:37:03
Message-ID: 20050420193703.70A635FA () office ! kde ! org
[Download RAW message or body]

CVS commit by craig: 

Better checking of existing and alias entries


  M +48 -20    Fontmap.cpp   1.4


--- kdebase/kcontrol/kfontinst/kfontinst/Fontmap.cpp  #1.3:1.4
@@ -172,8 +172,34 @@ static QString createName(const QString 
 }
 
+static QString getEntry(QStringList &list, const QString &name)
+{
+    QStringList::Iterator it(list.begin()),
+                          end(list.end());
+
+    for( ; it!=end; ++it)
+        if(0==(*it).find('/'+name+' '))
+            return *it;
+
+    return QString::null;
+}
+
+inline bool isAlias(const QString &entry)
+{
+    return -1==entry.findRev(QRegExp(")\\s*;\\s*$"));
+}
+
 static void addEntry(QStringList &list, const QString &name, const QString &file, \
const QString &fmapDir)  {
-    // CPD: TODO: The check below should really be more robust, need to check if an \
                alias for this psname has already
-    // been added, is so remove.
+    QString existing(getEntry(list, name));
+    bool    insert=true;
+
+    if(!existing.isEmpty())
+        if(isAlias(existing))
+            list.remove(existing);
+        else
+            insert=false;
+
+    if(insert)
+    {
     QString      entry;
     QTextOStream str(&entry);
@@ -187,21 +213,23 @@ static void addEntry(QStringList &list, 
 
     str << ") ;";
-    if(-1==list.findIndex(entry))
         list.append(entry);
+    }
 }
 
 static void addAliasEntry(QStringList &list, const QString &x11Name, const QString \
&psName)  {
-    // CPD: TODO: The check below should really be more robust, need to check that \
                no other alias to this psname exists,
-    // and that the x11Name does not map onto anything else...
     if(x11Name!=psName)
     {
+        QString existing(getEntry(list, x11Name));
+
+        if(existing.isEmpty())
+        {
         QString      entry;
         QTextOStream str(&entry);
 
         str << '/' << x11Name << " /" << psName << " ;";
-        if(-1==list.findIndex(entry))
             list.append(entry);
     }
+    }
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic