NepomukDaemons
config.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.h"
00020
00021 #include <QtCore/QStringList>
00022 #include <QtCore/QDir>
00023
00024 #include <kdirwatch.h>
00025 #include <kstandarddirs.h>
00026 #include <kconfiggroup.h>
00027
00028
00029 Nepomuk::Config::Config()
00030 : QObject(),
00031 m_config( "nepomukstrigirc" )
00032 {
00033 KDirWatch* dirWatch = KDirWatch::self();
00034 connect( dirWatch, SIGNAL( dirty( const QString& ) ),
00035 this, SLOT( slotConfigDirty() ) );
00036 connect( dirWatch, SIGNAL( created( const QString& ) ),
00037 this, SLOT( slotConfigDirty() ) );
00038 dirWatch->addFile( KStandardDirs::locateLocal( "config", m_config.name() ) );
00039 }
00040
00041
00042 Nepomuk::Config::~Config()
00043 {
00044 m_config.group( "General" ).writeEntry( "first run", false );
00045 }
00046
00047
00048 Nepomuk::Config* Nepomuk::Config::self()
00049 {
00050 K_GLOBAL_STATIC( Config, _self );
00051 return _self;
00052 }
00053
00054
00055 QStringList Nepomuk::Config::folders() const
00056 {
00057 return m_config.group( "General" ).readPathEntry( "folders", QStringList() << QDir::homePath() );
00058 }
00059
00060
00061 QStringList Nepomuk::Config::excludeFolders() const
00062 {
00063 return m_config.group( "General" ).readPathEntry( "exclude folders", QStringList() );
00064 }
00065
00066
00067 QStringList Nepomuk::Config::excludeFilters() const
00068 {
00069 return m_config.group( "General" ).readEntry( "exclude filters", QStringList() << ".*/" << ".*" << "*~" << "*.part" );
00070 }
00071
00072
00073 QStringList Nepomuk::Config::includeFilters() const
00074 {
00075 return m_config.group( "General" ).readEntry( "include filters", QStringList() );
00076 }
00077
00078
00079 KIO::filesize_t Nepomuk::Config::minDiskSpace() const
00080 {
00081
00082 return m_config.group( "General" ).readEntry( "min disk space", KIO::filesize_t( 200*1024*1024 ) );
00083 }
00084
00085
00086 void Nepomuk::Config::slotConfigDirty()
00087 {
00088 m_config.reparseConfiguration();
00089 emit configChanged();
00090 }
00091
00092
00093 bool Nepomuk::Config::showGui() const
00094 {
00095 return m_config.group( "General" ).readEntry( "show gui", true );
00096 }
00097
00098
00099 void Nepomuk::Config::setShowGui( bool showGui )
00100 {
00101 m_config.group( "General" ).writeEntry( "show gui", showGui );
00102 }
00103
00104
00105 bool Nepomuk::Config::isInitialRun() const
00106 {
00107 return m_config.group( "General" ).readEntry( "first run", true );
00108 }
00109
00110
00111 bool Nepomuk::Config::shouldFolderBeIndexed( const QString& path )
00112 {
00113 QStringList inDirs = folders();
00114 QStringList exDirs = excludeFolders();
00115
00116 if( inDirs.contains( path ) ) {
00117 return true;
00118 }
00119 else if( exDirs.contains( path ) ) {
00120 return false;
00121 }
00122 else {
00123 QString parent = path.section( QDir::separator(), 0, -2, QString::SectionSkipEmpty|QString::SectionIncludeLeadingSep );
00124 if( parent.isEmpty() ) {
00125 return false;
00126 }
00127 else {
00128 return shouldFolderBeIndexed( parent );
00129 }
00130 }
00131 }
00132
00133 #include "config.moc"