OSDN Git Service

jovie: make use of KStandardDirs
authorIvailo Monev <xakepa10@gmail.com>
Sat, 26 Jun 2021 14:37:12 +0000 (17:37 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Sat, 26 Jun 2021 14:37:12 +0000 (17:37 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
jovie/filters/stringreplacer/stringreplacerconf.cpp
jovie/filters/xmltransformer/xmltransformerconf.cpp
jovie/libkttsd/filterconf.cpp
jovie/libkttsd/filterconf.h

index 6464bf6..54b690b 100644 (file)
@@ -251,7 +251,7 @@ void StringReplacerConf::save(KConfig* c, const QString& configGroup){
     if ( errMsg.isEmpty() )
     {
         KConfigGroup config( c, configGroup );
-        config.writeEntry( "WordListFile", realFilePath(wordsFilename) );
+        config.writeEntry( "WordListFile", KStandardDirs::realFilePath(wordsFilename) );
     }
     else
         kDebug() << "StringReplacerConf::save: " << errMsg;
index ef684b9..f612bfa 100644 (file)
@@ -95,8 +95,8 @@ void XmlTransformerConf::save(KConfig* c, const QString& configGroup){
     // kDebug() << "XmlTransformerConf::save: Running";
     KConfigGroup config( c, configGroup );
     config.writeEntry( "UserFilterName", nameLineEdit->text() );
-    config.writeEntry( "XsltFilePath", realFilePath( xsltPath->url().path() ) );
-    config.writeEntry( "XsltprocPath", realFilePath( xsltprocPath->url().path() ) );
+    config.writeEntry( "XsltFilePath", KStandardDirs::realFilePath( xsltPath->url().path() ) );
+    config.writeEntry( "XsltprocPath", KStandardDirs::realFilePath( xsltprocPath->url().path() ) );
     config.writeEntry( "RootElement", rootElementLineEdit->text() );
     config.writeEntry( "DocType", doctypeLineEdit->text() );
     config.writeEntry( "AppID", appIdLineEdit->text().remove(QLatin1Char( ' ' )) );
@@ -143,13 +143,13 @@ bool XmlTransformerConf::supportsMultiInstance() { return true; }
  */
 QString XmlTransformerConf::userPlugInName()
 {
-    QString filePath = realFilePath(xsltprocPath->url().path());
+    QString filePath = KStandardDirs::realFilePath(xsltprocPath->url().path());
     if (filePath.isEmpty()) return QString();
-    if (getLocation(filePath).isEmpty()) return QString();
+    if (KStandardDirs::findExe(filePath).isEmpty()) return QString();
 
-    filePath = realFilePath(xsltPath->url().path());
+    filePath = KStandardDirs::realFilePath(xsltPath->url().path());
     if (filePath.isEmpty()) return QString();
-    if (getLocation(filePath).isEmpty()) return QString();
+    if (KStandardDirs::findExe(filePath).isEmpty()) return QString();
     if (!QFileInfo(filePath).isFile()) return QString();
 
     return nameLineEdit->text();
index 41b3f1d..27b7f92 100644 (file)
 #include "filterconf.h"
 #include "moc_filterconf.cpp"
 
-// C++ library includes.
-#include <stdlib.h>
-#include <sys/param.h>
-
 // Qt includes.
 #include <QtCore/QFile>
 #include <QtCore/QFileInfo>
@@ -44,9 +40,6 @@
 KttsFilterConf::KttsFilterConf( QWidget *parent, const QVariantList &) : QWidget(parent){
     //setObjectName( QLatin1String( name ) );
     // kDebug() << "KttsFilterConf::KttsFilterConf: Running";
-    QString systemPath(QLatin1String( qgetenv("PATH" ) ));
-    // kDebug() << "Path is " << systemPath;
-    m_path = systemPath.split( QLatin1Char( ':' ));
 }
 
 /**
@@ -120,47 +113,3 @@ QString KttsFilterConf::userPlugInName() { return QString(); }
  * @return          True if this filter is a SBD.
  */
 bool KttsFilterConf::isSBD() { return false; }
-
-/**
-* Return the full path to any program in the $PATH environmental variable
-* @param name        The name of the file to search for.
-* @returns           The path to the file on success, a blank QString
-*                    if it is not found.
-*/
-QString KttsFilterConf::getLocation(const QString &name) {
-    // Iterate over the path and see if 'name' exists in it. Return the
-    // full path to it if it does. Else return an empty QString.
-    if (QFile::exists(name)) return name;
-    // kDebug() << "KttsFilterConf::getLocation: Searching for " << name << " in the path..";
-    // kDebug() << m_path;
-    for(QStringList::iterator it = m_path.begin(); it != m_path.end(); ++it) {
-        QString fullName = *it;
-        fullName += QLatin1Char( '/' );
-        fullName += name;
-        // The user either has the directory of the file in the path...
-        if(QFile::exists(fullName)) {
-            // kDebug() << "KttsFilterConf:getLocation: " << fullName;
-            return fullName;
-        }
-        // ....Or the file itself
-        else if(QFileInfo(*it).baseName().append(QString(QLatin1String( "." )).append(QFileInfo(*it).suffix())) == name) {
-            // kDebug() << "KttsFilterConf:getLocation: " << fullName;
-            return fullName;
-        }
-    }
-    return QString();
-}
-
-/*static*/ QString KttsFilterConf::realFilePath(const QString &filename)
-{
-    char *realpath_buffer;
-
-    /* If the path contains symlinks, get the real name */
-    if ((realpath_buffer = realpath( QFile::encodeName(filename).data(), NULL)) != NULL) {
-        //succes, use result from realpath
-        QString result = QFile::decodeName(realpath_buffer);
-        free(realpath_buffer);
-        return result;
-    }
-    return filename;
-}
index 0e6a5b6..fbbaa8a 100644 (file)
@@ -111,8 +111,6 @@ class KDE_EXPORT KttsFilterConf : public QWidget{
          */
         virtual bool isSBD();
 
-        static QString realFilePath(const QString &filename);
-
     public slots:
         /**
         * This slot is used internally when the configuration is changed.  It is
@@ -130,19 +128,6 @@ class KDE_EXPORT KttsFilterConf : public QWidget{
         * It should be emitted whenever user changes something in the configuration widget.
         */
         void changed(bool);
-
-    protected:
-        /**
-        * Searches the $PATH variable for any file. If that file exists in the PATH, or
-        * is contained in any directory in the PATH, it returns the full path to it.
-        * @param name        The name of the file to search for.
-        * @returns           The path to the file on success, a blank QString
-        *                    if it is not found.
-        */
-        QString getLocation(const QString &name);
-
-        /// The system path in a QStringList.
-        QStringList m_path;
 };
 
 #endif  //FILTERCONF_H