[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: kio&kcontrol patch against hardcoded subdir paths
From: David Faure <david () mandrakesoft ! com>(by way of David Faure <david () mandrakesoft ! c
Date: 2000-09-04 18:10:34
[Download RAW message or body]
kcontrol looks for its items in "Settings/". But if you use the menu
editor to move that as a subdir of something else, or if you work
for a distribution that likes things named another way :), then hardcoding
a relative path looks no good at all.
The attached patch introduces a new notion: the one of base group.
A key in the .directory is added in the config file (X-KDE-BaseGroup),
so that it gets moved with the directory. KServiceGroup provides a method
for finding the group.
Used by kcontrol for the Settings group, and by kscreensaver for the
System/ScreenSavers group.
--
David FAURE, david@mandrakesoft.com, faure@kde.org
http://home.clara.net/faure/, http://www.konqueror.org/
KDE, Making The Future of Computing Available Today
See http://www.kde.org/kde1-and-kde2.html for how to set up KDE 2
["kcontrol.diff" (text/x-c)]
Index: global.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/global.cpp,v
retrieving revision 1.6
diff -u -p -b -r1.6 global.cpp
--- global.cpp 2000/04/07 14:23:40 1.6
+++ global.cpp 2000/09/04 17:09:49
@@ -21,6 +21,9 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/utsname.h>
+#include <kservicegroup.h>
+#include <ksycoca.h>
+#include <kdebug.h>
#include "config.h"
#include "utils.h"
@@ -37,6 +40,7 @@ QString KCGlobal::_iversion = "";
QString KCGlobal::_imachine = "";
IndexViewMode KCGlobal::_viewmode = Icon;
IndexIconSize KCGlobal::_iconsize = Medium;
+QString KCGlobal::_baseGroup = QString::null;
void KCGlobal::init()
{
@@ -68,4 +72,25 @@ void KCGlobal::setType(const QCString& s
{
QString string = s.lower();
splitString(string, ',', _types);
+}
+
+QString KCGlobal::baseGroup()
+{
+ if ( _baseGroup.isEmpty() )
+ {
+ KServiceGroup::Ptr group = KServiceGroup::baseGroupByNumber( \
KServiceGroup::BASEGROUP_KCONTROL ); + if (group)
+ {
+ _baseGroup = group->relPath();
+ kdDebug() << "Found basegroup = " << _baseGroup << endl;
+ return _baseGroup;
+ }
+ // Compatibility with old behaviour, in case of missing .directory files.
+ if (_baseGroup.isEmpty())
+ {
+ kdWarning() << "No K menu group with X-KDE-KControl-Base=true found ! \
Defaulting to Settings/" << endl; + _baseGroup = \
QString::fromLatin1("Settings"); + }
+ }
+ return _baseGroup;
}
Index: global.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/global.h,v
retrieving revision 1.5
diff -u -p -b -r1.5 global.h
--- global.h 2000/04/07 14:16:30 1.5
+++ global.h 2000/09/04 17:09:50
@@ -44,6 +44,7 @@ public:
static QString systemMachine() { return _imachine; }
static IndexViewMode viewMode() { return _viewmode; }
static IndexIconSize iconSize() { return _iconsize; }
+ static QString baseGroup();
static void setRoot(bool r) { _root = r; }
static void setType(const QCString& s);
@@ -63,6 +64,7 @@ private:
static QString _uname, _hname, _isystem, _irelease, _iversion, _imachine, \
_kdeversion; static IndexViewMode _viewmode;
static IndexIconSize _iconsize;
+ static QString _baseGroup;
};
#endif
Index: kcmshell.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/kcmshell.cpp,v
retrieving revision 1.22
diff -u -p -b -r1.22 kcmshell.cpp
--- kcmshell.cpp 2000/08/30 11:42:36 1.22
+++ kcmshell.cpp 2000/09/04 17:09:51
@@ -38,6 +38,7 @@
#include "kcdialog.h"
#include "moduleinfo.h"
#include "modloader.h"
+#include "global.h"
static KCmdLineOptions options[] =
@@ -70,7 +71,7 @@ int main(int _argc, char *_argv[])
if (args->isSet("list")) {
QStringList files;
KGlobal::dirs()->findAllResources("apps",
- "Settings/*.desktop",
+ KCGlobal::baseGroup() + "*.desktop",
true, true, files);
QStringList modules;
QStringList descriptions;
@@ -80,8 +81,8 @@ int main(int _argc, char *_argv[])
if (KDesktopFile::isDesktopFile(*it)) {
KDesktopFile file(*it, true);
QString module = *it;
- if (module.left(9) == "Settings/")
- module = module.mid(9);
+ if (module.startsWith(KCGlobal::baseGroup()))
+ module = module.mid(KCGlobal::baseGroup().length());
if (module.right(8) == ".desktop")
module.truncate(module.length() - 8);
@@ -123,7 +124,7 @@ int main(int _argc, char *_argv[])
//files.append(args->arg(0));
}
- QCString path = "Settings/";
+ QString path = KCGlobal::baseGroup();
path += arg;
path += ".desktop";
@@ -132,7 +133,7 @@ int main(int _argc, char *_argv[])
// Path didn't work. Trying as a name
KService::Ptr serv = KService::serviceByDesktopName( arg );
if ( serv )
- path = QFile::encodeName(serv->entryPath());
+ path = serv->entryPath();
else
{
cerr << i18n("Module %1 not found!").arg(arg).local8Bit() << endl;
Index: moduleiconview.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/moduleiconview.cpp,v
retrieving revision 1.20
diff -u -p -b -r1.20 moduleiconview.cpp
--- moduleiconview.cpp 2000/07/05 09:31:04 1.20
+++ moduleiconview.cpp 2000/09/04 17:09:52
@@ -143,7 +143,7 @@ void ModuleIconView::fill()
{
QString subdir = (*it);
- KServiceGroup::Ptr group = KServiceGroup::group("Settings/"+subdir+"/");
+ KServiceGroup::Ptr group = \
KServiceGroup::group(KCGlobal::baseGroup()+subdir+'/');
if (KCGlobal::iconSize() == Small)
{
@@ -228,7 +228,7 @@ QDragObject *ModuleIconView::dragObject(
if (!item->tag().isEmpty())
{
QString dir = _path + "/" + item->tag();
- dir = locate("apps", "Settings/"+dir+"/.directory");
+ dir = locate("apps", KCGlobal::baseGroup()+dir+"/.directory");
int pos = dir.findRev("/.directory");
if (pos > 0)
{
Index: moduleinfo.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/moduleinfo.cpp,v
retrieving revision 1.21
diff -u -p -b -r1.21 moduleinfo.cpp
--- moduleinfo.cpp 2000/08/11 15:41:50 1.21
+++ moduleinfo.cpp 2000/09/04 17:09:53
@@ -29,6 +29,7 @@
#include "moduleinfo.h"
#include "moduleinfo.moc"
#include "utils.h"
+#include "global.h"
ModuleInfo::ModuleInfo(QString desktopFile)
: _fileName(desktopFile)
@@ -52,9 +53,9 @@ ModuleInfo::ModuleInfo(QString desktopFi
// try to find out the modules groups
QString group = desktopFile;
- int pos = group.find("Settings/");
+ int pos = group.find(KCGlobal::baseGroup());
if (pos >= 0)
- group = group.mid(pos+9);
+ group = group.mid(pos+KCGlobal::baseGroup().length());
pos = group.findRev('/');
if (pos >= 0)
group = group.left(pos);
Index: modulemenu.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/modulemenu.cpp,v
retrieving revision 1.8
diff -u -p -b -r1.8 modulemenu.cpp
--- modulemenu.cpp 2000/07/05 09:31:04 1.8
+++ modulemenu.cpp 2000/09/04 17:09:53
@@ -95,7 +95,7 @@ KPopupMenu *ModuleMenu::getGroupMenu(con
KPopupMenu *menu = new KPopupMenu(parent);
connect(menu, SIGNAL(activated(int)), this, SLOT(moduleSelected(int)));
- KServiceGroup::Ptr group = KServiceGroup::group("Settings/"+path);
+ KServiceGroup::Ptr group = KServiceGroup::group(KCGlobal::baseGroup()+path);
parent->insertItem(KGlobal::iconLoader()->loadIcon(group->icon(), KIcon::Desktop, \
KIcon::SizeSmall) , group->caption(), menu);
Index: modules.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/modules.cpp,v
retrieving revision 1.18
diff -u -p -b -r1.18 modules.cpp
--- modules.cpp 2000/07/30 11:04:06 1.18
+++ modules.cpp 2000/09/04 17:09:54
@@ -27,6 +27,7 @@
#include <kapp.h>
+#include <kdebug.h>
#include <kglobal.h>
#include <kservicegroup.h>
#include <kcmodule.h>
@@ -39,6 +40,7 @@
#include "modules.h"
#include "modules.moc"
+#include "global.h"
#include "utils.h"
#include "proxywidget.h"
#include "modloader.h"
@@ -204,7 +206,7 @@ const KAboutData *ConfigModule::aboutDat
void ConfigModuleList::readDesktopEntries()
{
- readDesktopEntriesRecursive("Settings/");
+ readDesktopEntriesRecursive( KCGlobal::baseGroup() );
}
void ConfigModuleList::readDesktopEntriesRecursive(const QString &path)
Index: moduletreeview.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/moduletreeview.cpp,v
retrieving revision 1.26
diff -u -p -b -r1.26 moduletreeview.cpp
--- moduletreeview.cpp 2000/08/12 12:50:50 1.26
+++ moduletreeview.cpp 2000/09/04 17:09:55
@@ -188,7 +188,7 @@ ModuleTreeItem *ModuleTreeView::getGroup
else
menu = new ModuleTreeItem(this);
- KServiceGroup::Ptr group = KServiceGroup::group("Settings/"+path);
+ KServiceGroup::Ptr group = KServiceGroup::group(KCGlobal::baseGroup()+path);
QString defName = path.left(path.length()-1);
int pos = defName.findRev('/');
if (pos >= 0)
Index: toplevel.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/toplevel.cpp,v
retrieving revision 1.70
diff -u -p -b -r1.70 toplevel.cpp
--- toplevel.cpp 2000/09/01 05:03:57 1.70
+++ toplevel.cpp 2000/09/04 17:09:57
@@ -302,7 +302,7 @@ void TopLevel::showModule(QString deskto
// locate the desktop file
QStringList files;
- files = KGlobal::dirs()->findAllResources("apps", \
"Settings/"+desktopFile+".desktop", TRUE); + files = \
KGlobal::dirs()->findAllResources("apps", \
KCGlobal::baseGroup()+desktopFile+".desktop", TRUE);
// show all matches
QStringList::Iterator it;
["screensaver.diff" (text/x-c)]
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdebase/kcontrol/screensaver/Makefile.am,v
retrieving revision 1.1
diff -u -p -b -r1.1 Makefile.am
--- Makefile.am 2000/06/28 11:09:26 1.1
+++ Makefile.am 2000/09/04 16:58:41
@@ -8,7 +8,7 @@ lib_LTLIBRARIES = libkcm_screensaver.la
libkcm_screensaver_la_SOURCES = scrnsave.cpp
libkcm_screensaver_la_LDFLAGS = -module -avoid-version $(all_libraries) \
-no-undefined
-libkcm_screensaver_la_LIBADD = $(LIB_KDEUI) $(DPMSLIB)
+libkcm_screensaver_la_LIBADD = $(LIB_KSYCOCA) $(DPMSLIB)
libkcm_screensaver_la_METASOURCES = scrnsave.moc
noinst_HEADERS = scrnsave.h
Index: scrnsave.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/screensaver/scrnsave.cpp,v
retrieving revision 1.6
diff -u -p -b -r1.6 scrnsave.cpp
--- scrnsave.cpp 2000/08/10 10:29:39 1.6
+++ scrnsave.cpp 2000/09/04 16:58:45
@@ -35,6 +35,7 @@
#include <qwhatsthis.h>
#include <kapp.h>
+#include <kdebug.h>
#include <kprocess.h>
#include <ksimpleconfig.h>
#include <knuminput.h>
@@ -46,6 +47,7 @@
#include <kcmodule.h>
#include <kglobal.h>
#include <dcopclient.h>
+#include <kservicegroup.h>
#include <X11/Xlib.h>
@@ -147,9 +149,15 @@ KScreenSaver::KScreenSaver(QWidget *pare
"apps/ScreenSavers/");
// Add KDE specific screensaver path
+ QString relPath="System/ScreenSavers/";
+ KServiceGroup::Ptr servGroup = KServiceGroup::baseGroupByNumber( \
KServiceGroup::BASEGROUP_SCREENSAVERS ); + if (servGroup)
+ relPath=servGroup->relPath();
+
KGlobal::dirs()->addResourceType("scrsav",
KGlobal::dirs()->kde_default("apps") +
- "System/ScreenSavers/");
+ relPath);
+
readSettings();
["kio.diff" (text/english)]
? sabine
? ftp/RFC_for_aborting
Index: kservicegroup.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kservicegroup.cpp,v
retrieving revision 1.6
diff -u -p -b -r1.6 kservicegroup.cpp
--- kservicegroup.cpp 2000/08/07 09:01:11 1.6
+++ kservicegroup.cpp 2000/09/04 17:12:42
@@ -33,6 +33,7 @@ KServiceGroup::KServiceGroup( const QStr
: KSycocaEntry(_relpath)
{
m_bDeleted = false;
+ m_iBaseGroup = 0;
if (!configFile.isEmpty())
{
@@ -44,6 +45,7 @@ KServiceGroup::KServiceGroup( const QStr
m_strIcon = config.readEntry( "Icon" );
m_strComment = config.readEntry( "Comment" );
m_bDeleted = config.readBoolEntry( "Hidden", false );
+ m_iBaseGroup = config.readNumEntry( "X-KDE-BaseGroup", 0 );
}
// Fill in defaults.
if (m_strCaption.isEmpty())
@@ -75,7 +77,7 @@ void KServiceGroup::load( QDataStream& s
QStringList groupList;
s >> m_strCaption >> m_strIcon >>
- m_strComment >> groupList;
+ m_strComment >> groupList >> m_iBaseGroup;
if (m_bDeep)
{
@@ -130,7 +132,7 @@ void KServiceGroup::save( QDataStream& s
}
s << m_strCaption << m_strIcon <<
- m_strComment << groupList;
+ m_strComment << groupList << m_iBaseGroup;
}
KServiceGroup::List
@@ -216,6 +218,29 @@ KServiceGroup::entries(bool sort)
sorted.append(*sit);
return sorted;
+}
+
+KServiceGroup::Ptr
+KServiceGroup::baseGroupByNumber( int groupNumber )
+{
+ KServiceGroup::Ptr root = KServiceGroup::root();
+ // Initially fill the list with the toplevel groups
+ KServiceGroup::List list = root->entries(false);
+ for (KServiceGroup::List::ConstIterator it(list.begin()); it != list.end(); ++it)
+ {
+ KSycocaEntry *p = (*it);
+ // Only interested in groups.
+ if (p->isType(KST_KServiceGroup))
+ {
+ KServiceGroup *serviceGroup = static_cast<KServiceGroup *>(p);
+ if (serviceGroup->baseGroup() == groupNumber)
+ return KServiceGroup::Ptr(serviceGroup);
+ // Look for the subgroups later. A depth-first search wouldn't be
+ // the best bet.
+ list += serviceGroup->entries(false);
+ }
+ }
+ return KServiceGroup::Ptr(0L);
}
KServiceGroup::Ptr
Index: kservicegroup.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kservicegroup.h,v
retrieving revision 1.6
diff -u -p -b -r1.6 kservicegroup.h
--- kservicegroup.h 2000/08/24 12:44:48 1.6
+++ kservicegroup.h 2000/09/04 17:12:42
@@ -102,6 +102,23 @@ public:
*/
virtual List entries(bool sorted = false);
+ /**
+ * @return non zero if the group is a special base group.
+ * By default, "Settings/" is the kcontrol base group and
+ * "Screensavers" is the screensavers base group.
+ *
+ * The base group
+ * This allows moving the groups without breaking those apps.
+ */
+ int baseGroup() const { return m_iBaseGroup; }
+ enum { BASEGROUP_KCONTROL = 1, BASEGROUP_SCREENSAVERS };
+
+ /**
+ * @return the group for the given groupNumber
+ * Can return 0L if the directory (or the .directory file) was deleted.
+ */
+ static Ptr baseGroupByNumber( int groupNumber );
+
static Ptr root();
static Ptr group(const QString &relPath);
@@ -118,5 +135,6 @@ protected:
List m_serviceList;
bool m_bDeep;
+ int m_iBaseGroup;
};
#endif
Index: ksycoca.h
===================================================================
RCS file: /home/kde/kdelibs/kio/ksycoca.h,v
retrieving revision 1.33
diff -u -p -b -r1.33 ksycoca.h
--- ksycoca.h 2000/07/18 13:06:47 1.33
+++ ksycoca.h 2000/09/04 17:12:43
@@ -33,7 +33,7 @@ class KSycocaFactoryList;
* If the existing file is outdated, it will not get read
* but instead we'll ask kded to regenerate a new one...
*/
-#define KSYCOCA_VERSION 27
+#define KSYCOCA_VERSION 28
/**
* @internal
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic