Source Code (Use browser search to find items of interest.)
Class Index
kcontrol'Theme (./kdebase/kcontrol/themes/theme.h:34)
class Theme: public KSimpleConfig
{
Q_OBJECT
public:
/** Construct a theme object */
Theme();
virtual ~Theme();
/** Load theme and prepare it for installation or modification. Returns
true on success. */
virtual bool load(const QString path);
/** Apply current theme to the users Kde configuration. This updates several
config files and executes the initialization programs. */
virtual void install(void);
/** Write theme file. If no path is given the theme is stored in the default
kde location with the given theme name. Returns true on success. */
virtual bool save(const QString path=0);
/** Read current Kde configuration from several config files. */
virtual void readCurrent(void);
/** set theme name. */
virtual void setName(const char *newName);
/** Returns path + name where theme is stored. */
const QString fileName(void) { return mFileName; }
/** Get preview pixmap. */
const QPixmap& preview(void) const { return mPreview; }
/** Description */
const QString description(void) const { return mDescription; }
virtual void setDescription(const QString);
/** Color scheme colors. */
QColor foregroundColor;
QColor backgroundColor;
QColor selectForegroundColor;
QColor selectBackgroundColor;
QColor activeForegroundColor;
QColor activeBackgroundColor;
QColor activeBlendColor;
QColor inactiveForegroundColor;
QColor inactiveBackgroundColor;
QColor inactiveBlendColor;
QColor windowForegroundColor;
QColor windowBackgroundColor;
int contrast;
/** Theme packet installation options */
bool instPanel, instIcons, instColors, instWindowBorder;
bool instWindowTitlebar, instWallpapers, instSounds;
bool instWindowButtonLayout, instWindowGimmick, instKfm;
bool instOverwrite;
/** Clear config contents */
virtual void clear(void);
/** Test if group with given name exists. If notEmpty is true the
method also tests if the group is not empty. */
virtual bool hasGroup(const QString& name, bool notEmpty=false);
/** Working directory. */
static const QString workDir(void);
/** Create directory hierarchy, relative to given base directory
or ~/.kde if none given. Returns true on success. */
static bool mkdirhier(const char* dirHier, const char* baseDir=NULL);
/** Uninstall files of last theme installation for given group */
virtual void uninstallFiles(const char* groupName);
signals:
/** This signal is emitted after import() or load() */
void changed();
/** This signal is emitted to ask for apply of all changes. */
void apply();
protected:
/** Write color entry to config file. */
void writeColorEntry(KConfigBase*, const char* key, const QColor& color);
/** Read color entry to config file. */
const QColor& readColorEntry(KConfigBase*, const char* key,
const QColor* pDefault=0L) const;
/** Read values from config file. */
virtual void readConfig(void);
/** Write values to config file. */
virtual void writeConfig(void);
/** Create KConfig object and load fitting data. */
virtual KConfig* openConfig(const QString appName) const;
/** Installs file by calling cp. The source name is prepended
with the theme work directory, the dest name is prepended
with KApp::localkdedir(). Returns true on success. */
virtual bool installFile(const QString& name, const QString& dest);
/** Removes given file. If dirName is given and name is
no absolute path, then dirName+"/"+name is removed. Does
nothing if name is empty or null. */
virtual void removeFile(const QString& name, const QString dirName=0);
/** Install theme group. Returns number of installed files. */
virtual int installGroup(const char* groupName);
/** Install icons from Icon group. Returns number of installed icons. */
virtual int installIcons(void);
/** Apply color scheme change to all open windows. Taken from
kdisplay / colorscm.cpp */
virtual void colorSchemeApply(void);
/** Load mappings file. */
virtual void loadMappings(void);
/** Execute all commands in the command list mCmdList. called from
install(). */
virtual void doCmdList(void);
/** Called from installGroup() with the value of the ConfigInstallCmd
value. */
virtual void installCmd(KSimpleConfig* cfg, const QString& cmd,
int installedFiles);
/** Called from installGroup() with the value of the ConfigPreInstallCmd
value. */
virtual void preInstallCmd(KSimpleConfig* cfg, const QString& cmd);
/** Delete all files in work directory. */
virtual void cleanupWorkDir(void);
/** Rename file by adding a tilde (~) to the filename. Returns
true if file exists. */
virtual bool backupFile(const QString filename) const;
/** Load/save config settings */
virtual void loadSettings(void);
virtual void saveSettings(void);
/** Rotate image file by given angle. */
virtual void rotateImage(const QString filename, int angle);
/** Convert icon to mini icon */
void iconToMiniIcon(const QString icon, const QString miniIcon);
/** Stretch pixmap. Drops "None" color when there is no pixel
using it. This crashes kwm. */
void stretchPixmap(const QString filename, bool verticalStretch);
/** Add file to list of installed files. */
virtual void addInstFile(const char* filename);
/** Read list of installled files. */
virtual void readInstFileList(const char* groupName);
/** Write list of installled files. */
virtual void writeInstFileList(const char* groupName);
/** Run krdb if krdb-usage is enabled. */
virtual void runKrdb(void) const;
/** Returns filename of given file+path (name up to the last slash) */
virtual const QString fileOf(const QString&) const;
/** Returns path of given file+path (up to the last slash) */
virtual const QString pathOf(const QString&) const;
protected:
QString mFileName; // Name+path
QString mThemePath; // Path to dir where theme files are stored
QString mDescription;
QString mThemercFile; // Name of the .themerc file
QString mPreviewFile; // Name of the preview image
QString mRestartCmd; // Shell command that restarts an app
QPixmap mPreview;
QString mConfigDir;
KSimpleConfig* mMappings;
QStrList mCmdList;
QStrList mInstFiles; // List of installed files
int mInstIcons; // Number of installed icons
};
kcontrol'Theme::Theme() (./kdebase/kcontrol/themes/theme.cpp:66)
Theme::Theme(): ThemeInherited(QString::null), mInstFiles(true)
{
int len;
setLocale();
instOverwrite = false;
mConfigDir = KGlobal::dirs()->getSaveLocation("config");
len = mConfigDir.length();
if (len > 0 && mConfigDir[len-1] != '/') mConfigDir += '/';
mMappings = NULL;
loadMappings();
// ensure that work directory exists
mkdirhier(workDir().ascii());
loadSettings();
}
//-----------------------------------------------------------------------------
kcontrol'Theme::~Theme() (./kdebase/kcontrol/themes/theme.cpp:89)
Theme::~Theme()
{
saveSettings();
if (mMappings) delete mMappings;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::loadSettings() (./kdebase/kcontrol/themes/theme.cpp:97)
void Theme::loadSettings(void)
{
KConfig* cfg = kapp->getConfig();
cfg->setGroup("Install");
mRestartCmd = cfg->readEntry("restart-cmd",
"kill `pidof %s`; %s >/dev/null 2>&1 &");
mInstIcons = cfg->readNumEntry("icons");
}
//-----------------------------------------------------------------------------
kcontrol'Theme::saveSettings() (./kdebase/kcontrol/themes/theme.cpp:109)
void Theme::saveSettings(void)
{
KConfig* cfg = kapp->getConfig();
cfg->setGroup("Install");
cfg->writeEntry("icons", mInstIcons);
cfg->sync();
}
//-----------------------------------------------------------------------------
kcontrol'Theme::setDescription() (./kdebase/kcontrol/themes/theme.cpp:120)
void Theme::setDescription(const QString aDescription)
{
mDescription = aDescription.copy();
}
//-----------------------------------------------------------------------------
kcontrol'Theme::setName() (./kdebase/kcontrol/themes/theme.cpp:127)
void Theme::setName(const char *_name)
{
QString aName = _name;
QString mName;
int i = aName.findRev('/');
if (i>0)
QObject::setName(aName.mid(i+1, 1024).ascii());
else
QObject::setName((mName = aName).ascii());
if (aName[0]=='/')
mFileName = aName;
else
mFileName = workDir() + aName;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::workDir() (./kdebase/kcontrol/themes/theme.cpp:144)
const QString Theme::workDir(void)
{
static QString str;
if (str.isEmpty())
str = locateLocal("appdata", "Work/");
return str;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::loadMappings() (./kdebase/kcontrol/themes/theme.cpp:154)
void Theme::loadMappings()
{
QFile file;
file.setName(locateLocal("appdata", "theme.mappings"));
if (!file.exists())
{
file.setName("theme.mappings");
if (!file.exists())
{
file.setName(locate("appdata", "theme.mappings"));
if (!file.exists())
fatal(i18n("Mappings file theme.mappings not found.").ascii());
}
}
if (mMappings) delete mMappings;
mMappings = new KSimpleConfig(file.name(), true);
}
//-----------------------------------------------------------------------------
kcontrol'Theme::cleanupWorkDir() (./kdebase/kcontrol/themes/theme.cpp:176)
void Theme::cleanupWorkDir(void)
{
QString cmd;
int rc;
// cleanup work directory
cmd.sprintf("rm -rf %s*", workDir().ascii());
rc = system(cmd.ascii());
if (rc) warning(i18n("Error during cleanup of work directory: rc=%d\n%s").ascii(),
rc, cmd.ascii());
}
//-----------------------------------------------------------------------------
kcontrol'Theme::load() (./kdebase/kcontrol/themes/theme.cpp:190)
bool Theme::load(const QString aPath)
{
QString cmd, str;
QFileInfo finfo(aPath);
int rc, num, i;
assert(!aPath.isEmpty());
debug("Theme::load()");
clear();
cleanupWorkDir();
setName(aPath.ascii());
if (finfo.isDir())
{
// The theme given is a directory. Copy files over into work dir.
i = aPath.findRev('/');
if (i >= 0) str = workDir() + aPath.mid(i, 1024);
else str = workDir();
cmd.sprintf("cp -r \"%s\" \"%s\"", aPath.ascii(),
str.ascii());
debug(cmd.ascii());
rc = system(cmd.ascii());
if (rc)
{
warning(i18n("Failed to copy theme contents\nfrom %s\ninto %s").ascii(),
aPath.ascii(), str.ascii());
return false;
}
}
else
{
// The theme given is a tar package. Unpack theme package.
cmd.sprintf("cd \"%s\"; gzip -c -d \"%s\" | tar xf -",
workDir().ascii(), aPath.ascii());
debug(cmd.ascii());
rc = system(cmd.ascii());
if (rc)
{
warning(i18n("Failed to unpack %s with\n%s").ascii(),
aPath.ascii(),
cmd.ascii());
return false;
}
}
// Let's see if the theme is stored in a subdirectory.
QDir dir(workDir(), QString::null, QDir::Name, QDir::Files|QDir::Dirs);
for (i=0, mThemePath=QString::null, num=0; dir[i]!=0; i++)
{
if (dir[i][0]=='.') continue;
finfo.setFile(workDir() + dir[i]);
if (!finfo.isDir()) break;
mThemePath = dir[i];
num++;
}
if (num==1) mThemePath = workDir() + mThemePath + '/';
else mThemePath = workDir();
// Search for the themerc file
dir.setNameFilter("*.themerc");
dir.setPath(mThemePath);
mThemercFile = dir[0];
if (mThemercFile.isEmpty())
{
warning(i18n("Theme contains no .themerc file").ascii());
return false;
}
// Search for the preview image
dir.setNameFilter("*.preview.*");
mPreviewFile = dir[0];
// read theme config file
setReadOnly(TRUE);
backEnd->changeFileName(mThemercFile, "", false);
reparseConfiguration();
readConfig();
emit changed();
return true;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::save() (./kdebase/kcontrol/themes/theme.cpp:278)
bool Theme::save(const QString aPath)
{
QString cmd;
int rc;
emit apply();
writeConfig();
backEnd->changeFileName(mThemercFile, "", false);
backEnd->sync(true); // true so that disk entries are merged. Is this right?
if (stricmp(aPath.right(4).ascii(), ".tgz") == 0 ||
stricmp(aPath.right(7).ascii(), ".tar.gz") == 0)
{
cmd.sprintf("cd \"%s\";tar cf - *|gzip -c >\"%s\"",
workDir().ascii(), aPath.ascii());
}
else
{
cmd.sprintf("cd \"%s\"; rm -rf \"%s\"; cp -r * \"%s\"",
workDir().ascii(), aPath.ascii(),
aPath.ascii());
}
debug(cmd.ascii());
rc = system(cmd.ascii());
if (rc) debug(i18n("Failed to save theme to\n%s\nwith command\n%s").ascii(),
aPath.ascii(), cmd.ascii());
return (rc==0);
}
//-----------------------------------------------------------------------------
kcontrol'Theme::removeFile() (./kdebase/kcontrol/themes/theme.cpp:312)
void Theme::removeFile(const QString& aName, const QString aDirName)
{
if (aName.isEmpty()) return;
if (aName[0] == '/' || aDirName.isEmpty())
unlink(aName.ascii());
else if (aDirName[aDirName.length()-1] == '/')
unlink((aDirName + aName).ascii());
else unlink((aDirName + '/' + aName).ascii());
}
//-----------------------------------------------------------------------------
kcontrol'Theme::installFile() (./kdebase/kcontrol/themes/theme.cpp:325)
bool Theme::installFile(const QString& aSrc, const QString& aDest)
{
QString cmd, dest, src;
QFileInfo finfo;
QFile srcFile, destFile;
int len, i;
char buf[32768];
bool backupMade = false;
if (aSrc.isEmpty()) return true;
if (aDest[0] == '/') dest = aDest;
dest = locateLocal("appdata", aDest);
src = mThemePath + aSrc;
finfo.setFile(src);
if (!finfo.exists())
{
debug("File %s is not in theme package.", aSrc.ascii());
return false;
}
finfo.setFile(dest);
if (finfo.isDir()) // destination is a directory
{
len = dest.length();
if (dest[len-1]=='/') dest[len-1] = '\0';
i = src.findRev('/');
dest = dest + '/' + src.mid(i+1,1024);
finfo.setFile(dest);
}
if (!instOverwrite && finfo.exists()) // make backup copy
{
unlink((dest+'~').ascii());
rename(dest.ascii(), (dest+'~').ascii());
backupMade = true;
}
srcFile.setName(src);
if (!srcFile.open(IO_ReadOnly))
{
warning(i18n("Cannot open file %s for reading").ascii(), src.ascii());
return false;
}
destFile.setName(dest);
if (!destFile.open(IO_WriteOnly))
{
warning(i18n("Cannot open file %s for writing").ascii(), dest.ascii());
return false;
}
while (!srcFile.atEnd())
{
len = srcFile.readBlock(buf, 32768);
if (len <= 0) break;
if (destFile.writeBlock(buf, len) != len)
{
warning(i18n("Write error to %s:\n%s").ascii(), dest.ascii(),
strerror(errno));
return false;
}
}
srcFile.close();
destFile.close();
addInstFile(dest.ascii());
debug("Installed %s to %s %s", src.ascii(), dest.ascii(),
backupMade ? "(backup of existing file)" : "");
return true;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::installGroup() (./kdebase/kcontrol/themes/theme.cpp:403)
int Theme::installGroup(const char* aGroupName)
{
QString value, oldValue, cfgFile, cfgGroup, appDir, group, emptyValue;
QString oldCfgFile, key, cfgKey, cfgValue, themeValue, instCmd, baseDir;
QString preInstCmd;
bool absPath = false, doInstall;
KSimpleConfig* cfg = NULL;
int len, i, installed = 0;
const char* missing = 0;
debug("*** beginning with %s", aGroupName);
group = aGroupName;
setGroup(group);
if (!instOverwrite) uninstallFiles(aGroupName);
else readInstFileList(aGroupName);
while (!group.isEmpty())
{
mMappings->setGroup(group);
debug("Mappings group [%s]", group.ascii());
// Read config settings
value = mMappings->readEntry("ConfigFile");
if (!value.isEmpty())
{
cfgFile = value.copy();
if (cfgFile == "KDERC") cfgFile = QDir::homeDirPath() + "/.kderc";
else if (cfgFile[0] != '/') cfgFile = mConfigDir + cfgFile;
}
value = mMappings->readEntry("ConfigGroup");
if (!value.isEmpty()) cfgGroup = value.copy();
value = mMappings->readEntry("ConfigAppDir");
if (!value.isEmpty())
{
appDir = value.copy();
if (appDir[0] != '/') baseDir = kapp->localkdedir() + "/share/";
else baseDir = QString::null;
mkdirhier(appDir.ascii(), baseDir.ascii());
appDir = baseDir + appDir;
len = appDir.length();
if (len > 0 && appDir[len-1]!='/') appDir += '/';
}
absPath = mMappings->readBoolEntry("ConfigAbsolutePaths", absPath);
value = mMappings->readEntry("ConfigEmpty");
if (!value.isEmpty()) emptyValue = value.copy();
value = mMappings->readEntry("ConfigActivateCmd");
if (!value.isEmpty() && mCmdList.find(value.ascii()) < 0)
mCmdList.append(value.ascii());
instCmd = mMappings->readEntry("ConfigInstallCmd").stripWhiteSpace();
preInstCmd = mMappings->readEntry("ConfigPreInstallCmd").stripWhiteSpace();
// Some checks
if (cfgFile.isEmpty()) missing = "ConfigFile";
if (cfgGroup.isEmpty()) missing = "ConfigGroup";
if (missing)
{
warning(i18n("Internal error in theme mappings\n"
"(file theme.mappings) in group %s:\n\n"
"Entry `%s' is missing or has no value.").ascii(),
group.ascii(), missing);
break;
}
// Open config file and sync/close old one
if (oldCfgFile != cfgFile)
{
if (cfg)
{
debug("closing config file");
cfg->sync();
delete cfg;
}
debug("opening config file %s", cfgFile.ascii());
cfg = new KSimpleConfig(cfgFile);
oldCfgFile = cfgFile;
}
// Set group in config file
cfg->setGroup(cfgGroup);
debug("%s: [%s]", cfgFile.ascii(), cfgGroup.ascii());
// Execute pre-install command (if given)
if (!preInstCmd.isEmpty()) preInstallCmd(cfg, preInstCmd);
// Process all mapping entries for the group
QMap<QString, QString> aMap = mMappings->entryMap(group);
QMap<QString, QString>::Iterator aIt(aMap.begin());
for (; aIt != aMap.end(); ++aIt) {
key = aIt.key();
if (stricmp(key.left(6).ascii(),"Config")==0) continue;
value = (*aIt).stripWhiteSpace();
len = value.length();
if (len>0 && value[len-1]=='!')
{
doInstall = false;
value.truncate(len - 1);
}
else doInstall = true;
// parse mapping
i = value.find(':');
if (i >= 0)
{
cfgKey = value.left(i);
cfgValue = value.mid(i+1, 1024);
}
else
{
cfgKey = value;
cfgValue = QString::null;
}
if (cfgKey.isEmpty()) cfgKey = key;
if (doInstall)
{
oldValue = cfg->readEntry(cfgKey);
if (!oldValue.isEmpty() && oldValue==emptyValue)
oldValue = QString::null;
}
else oldValue = QString::null;
themeValue = readEntry(key);
if (cfgValue.isEmpty()) cfgValue = themeValue;
// Install file
if (doInstall)
{
if (!themeValue.isEmpty())
{
if (installFile(themeValue, appDir + cfgValue))
installed++;
else doInstall = false;
}
}
// Determine config value
if (cfgValue.isEmpty()) cfgValue = emptyValue;
else if (doInstall && absPath) cfgValue = appDir + cfgValue;
// Set config entry
debug("%s=%s", cfgKey.ascii(), cfgValue.ascii());
if (cfgKey == "-") cfg->deleteEntry(key, false);
else cfg->writeEntry(cfgKey, cfgValue);
}
if (!instCmd.isEmpty()) installCmd(cfg, instCmd, installed);
group = mMappings->readEntry("ConfigNextGroup");
}
if (cfg)
{
debug("closing config file");
cfg->sync();
delete cfg;
}
writeInstFileList(aGroupName);
debug("*** done with %s", aGroupName);
return installed;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::preInstallCmd() (./kdebase/kcontrol/themes/theme.cpp:570)
void Theme::preInstallCmd(KSimpleConfig* aCfg, const QString& aCmd)
{
QString grp = aCfg->group();
QString value, cmd;
cmd = aCmd.stripWhiteSpace();
if (cmd == "stretchBorders")
{
value = readEntry("ShapePixmapBottom");
if (!value.isEmpty()) stretchPixmap(mThemePath + value, false);
value = readEntry("ShapePixmapTop");
if (!value.isEmpty()) stretchPixmap(mThemePath + value, false);
value = readEntry("ShapePixmapLeft");
if (!value.isEmpty()) stretchPixmap(mThemePath + value, true);
value = readEntry("ShapePixmapRight");
if (!value.isEmpty()) stretchPixmap(mThemePath + value, true);
}
else
{
warning(i18n("Unknown pre-install command `%s' in\n"
"theme.mappings file in group %s.").ascii(),
aCmd.ascii(), mMappings->group().ascii());
}
}
//-----------------------------------------------------------------------------
kcontrol'Theme::installCmd() (./kdebase/kcontrol/themes/theme.cpp:598)
void Theme::installCmd(KSimpleConfig* aCfg, const QString& aCmd,
int aInstalled)
{
QString grp = aCfg->group();
QString value, cmd;
bool flag;
cmd = aCmd.stripWhiteSpace();
if (cmd == "winShapeMode")
{
aCfg->writeEntry("ShapeMode", aInstalled ? "on" : "off");
}
else if (cmd == "winTitlebar")
{
if (hasKey("TitlebarPixmapActive") || hasKey("TitlebarPixmapInactive"))
value = "pixmap";
else if (aCfg->readEntry("TitlebarLook") == "pixmap")
value = "shadedHorizontal";
else value = QString::null;
if (!value.isEmpty()) aCfg->writeEntry("TitlebarLook", value);
}
else if (cmd == "winGimmickMode")
{
if (hasKey("Pixmap")) value = "on";
else value = "off";
aCfg->writeEntry("GimmickMode", value);
}
/*CT 17Jan1999 no more needed - handled by the kpanel now
else if (cmd == "panelBack")
{
value = aCfg->readEntry("Position");
if (stricmp(value,"right")==0 || stricmp(value,"left")==0)
{
value = aCfg->readEntry("BackgroundTexture");
rotateImage(kapp->localkdedir()+"/share/apps/kpanel/pics/"+value, -90);
}
}
*/
else if (cmd == "enableSounds")
{
aCfg->setGroup("GlobalConfiguration");
aCfg->writeEntry("EnableSounds", aInstalled>0 ? "Yes" : "No");
}
else if (cmd == "setWallpaperMode")
{
value = aCfg->readEntry("wallpaper",QString::null);
aCfg->writeEntry("UseWallpaper", !value.isEmpty());
}
else if (cmd == "oneDesktopMode")
{
flag = readBoolEntry("CommonDesktop", true);
flag |= (aInstalled==1);
aCfg->writeEntry("OneDesktopMode", flag);
if (flag) aCfg->writeEntry("DeskNum", 0);
}
else
{
warning(i18n("Unknown command `%s' in theme.mappings\n"
"file in group %s.").ascii(), aCmd.ascii(),
mMappings->group().ascii());
}
if (stricmp(aCfg->group().ascii(), grp.ascii())!=0)
aCfg->setGroup(grp);
}
//-----------------------------------------------------------------------------
kcontrol'Theme::doCmdList() (./kdebase/kcontrol/themes/theme.cpp:667)
void Theme::doCmdList(void)
{
QString cmd, str, appName;
bool kwmRestart = false;
// int rc;
for (cmd=mCmdList.first(); !cmd.isNull(); cmd=mCmdList.next())
{
debug("do command: %s", cmd.ascii());
if (cmd.left(6) == "kwmcom")
{
cmd = cmd.mid(6,256).stripWhiteSpace();
if (stricmp(cmd.ascii(),"restart") == 0) kwmRestart = true;
else KWM::sendKWMCommand(cmd);
}
else if (cmd.left(9) == "kfmclient")
{
system(cmd.ascii());
}
else if (cmd == "applyColors")
{
colorSchemeApply();
runKrdb();
}
else if (strncmp(cmd.ascii(), "restart", 7) == 0)
{
appName = cmd.mid(7,256).stripWhiteSpace();
str.sprintf(i18n("Restart %s to activate the new settings?").ascii(),
appName.ascii());
if (KMessageBox::questionYesNo(0, str) == KMessageBox::Yes) {
str.sprintf(mRestartCmd.ascii(), appName.ascii(),
appName.ascii());
system(str.ascii());
}
}
}
if (kwmRestart) KWM::sendKWMCommand("restart");
mCmdList.clear();
}
//-----------------------------------------------------------------------------
kcontrol'Theme::backupFile() (./kdebase/kcontrol/themes/theme.cpp:710)
bool Theme::backupFile(const QString fname) const
{
QFileInfo fi(fname);
QString cmd;
int rc;
if (!fi.exists()) return false;
unlink((fname + '~').ascii());
cmd.sprintf("mv \"%s\" \"%s~\"", fname.ascii(),
fname.ascii());
rc = system(cmd.ascii());
if (rc) warning(i18n("Cannot make backup copy of %s: mv returned %d").ascii(),
fname.ascii(), rc);
return (rc==0);
}
//-----------------------------------------------------------------------------
kcontrol'Theme::installIcons() (./kdebase/kcontrol/themes/theme.cpp:729)
int Theme::installIcons(void)
{
QString key, value, mapval, fname, fpath, destName, icon, miniIcon;
QString iconDir, miniIconDir, cmd, destNameMini, localShareDir;
QStrList extraIcons;
QFileInfo finfo;
int i, installed = 0;
const char* groupName = "Icons";
const char* groupNameExtra = "Extra Icons";
bool wantRestart = false;
debug("*** beginning with %s", groupName);
if (!instOverwrite)
{
uninstallFiles(groupName);
if (mInstIcons > 0) wantRestart = true;
mInstIcons = 0;
}
else readInstFileList(groupName);
setGroup(groupName);
mMappings->setGroup(groupName);
mkdirhier("share/icons/mini");
iconDir = kapp->localkdedir() + "/share/icons/";
miniIconDir = kapp->localkdedir() + "/share/icons/mini/";
localShareDir = kapp->localkdedir() + "/share/";
// Process all mapping entries for the group
QMap<QString, QString> aMap = entryMap(groupName);
QMap<QString, QString>::Iterator aIt(aMap.begin());
for (; aIt != aMap.end(); ++aIt) {
key = aIt.key();
if (stricmp(key.left(6).ascii(),"Config")==0)
{
warning(i18n("Icon key name %s can not be used").ascii(), key.ascii());
continue;
}
value = *aIt;
i = value.find(':');
if (i > 0)
{
icon = value.left(i);
miniIcon = value.mid(i+1, 1024);
}
else
{
icon = value;
miniIcon = "mini-" + icon;
iconToMiniIcon(mThemePath + icon, mThemePath + miniIcon);
}
// test if there is a 1:1 mapping in the mappings file
destName = mMappings->readEntry(key,QString::null);
destNameMini = QString::null;
// if not we have to search for the proper kdelnk file
// and extract the icon name from there.
if (destName.isEmpty())
{
fname = "/" + key + ".kdelnk";
fpath = locate("apps", fname);
if (fpath.isNull())
fpath = locate("mime", fname);
if (!fpath.isEmpty()) {
KDesktopFile cfg(fpath, true);
destName = cfg.readIcon();
}
}
else
{
// test if the 1:1 mapping contains different names for icon
// and mini icon
i = destName.find(':');
if (i >= 0)
{
debug("mapping %s to...", destName.ascii());
destNameMini = destName.mid(i+1, 1024);
destName.truncate(i);
debug(" %s %s", destName.ascii(), destNameMini.ascii());
}
}
if (destNameMini.isEmpty()) destNameMini = destName;
// If we have still not found a destination icon name we will install
// the icons with their current name
if (destName.isEmpty())
{
if (icon.isEmpty()) continue;
warning(i18n("No proper kdelnk file found for %s.\n"
"Installing icon(s) as %s").ascii(),
key.ascii(), icon.ascii());
destName = icon;
}
// install icons
if (destName.find('/')>=0)
{
mkdirhier(pathOf(destName).ascii(),localShareDir.ascii());
value = localShareDir + destName;
}
else value = iconDir + destName;
if (installFile(icon, value)) installed++;
if (destNameMini != "-")
{
if (destNameMini.find('/')>=0)
{
mkdirhier(pathOf(destNameMini).ascii(),localShareDir.ascii());
value = localShareDir + destNameMini;
}
else value = miniIconDir + destNameMini;
if (installFile(miniIcon, value)) installed++;
}
}
// Look if there is anything to do after installation
value = mMappings->readEntry("ConfigActivateCmd");
if (!value.isEmpty() && (installed>0 || wantRestart) &&
mCmdList.find(value.ascii()) < 0) mCmdList.append(value.ascii());
writeInstFileList(groupName);
// Handle extra icons
setGroup(groupNameExtra);
mMappings->setGroup(groupNameExtra);
aMap = entryMap(groupNameExtra);
for (aIt = aMap.begin(); aIt != aMap.end(); ++aIt) {
key = aIt.key();
value = *aIt;
i = value.find(':');
if (i > 0)
{
icon = value.left(i);
miniIcon = value.mid(i+1, 1024);
}
else
{
icon = value;
miniIcon = "mini-" + icon;
iconToMiniIcon(mThemePath + icon, mThemePath + miniIcon);
}
// Install icons
value = iconDir + icon;
if (installFile(icon, value)) installed++;
value = miniIconDir + icon;
if (installFile(miniIcon, value)) installed++;
}
writeInstFileList(groupName);
debug("*** done with %s (%d icons installed)", groupName, installed);
mInstIcons += installed;
return installed;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::addInstFile() (./kdebase/kcontrol/themes/theme.cpp:894)
void Theme::addInstFile(const char* aFileName)
{
if (aFileName && *aFileName && mInstFiles.find(aFileName) < 0)
mInstFiles.append(strdup(aFileName));
}
//-----------------------------------------------------------------------------
kcontrol'Theme::readInstFileList() (./kdebase/kcontrol/themes/theme.cpp:902)
void Theme::readInstFileList(const char* aGroupName)
{
KConfig* cfg = kapp->getConfig();
assert(aGroupName!=0);
cfg->setGroup("Installed Files");
mInstFiles.clear();
cfg->readListEntry(aGroupName, mInstFiles, ':');
}
//-----------------------------------------------------------------------------
kcontrol'Theme::writeInstFileList() (./kdebase/kcontrol/themes/theme.cpp:914)
void Theme::writeInstFileList(const char* aGroupName)
{
KConfig* cfg = kapp->getConfig();
assert(aGroupName!=0);
cfg->setGroup("Installed Files");
cfg->writeEntry(aGroupName, mInstFiles, ':');
}
//-----------------------------------------------------------------------------
kcontrol'Theme::uninstallFiles() (./kdebase/kcontrol/themes/theme.cpp:925)
void Theme::uninstallFiles(const char* aGroupName)
{
QString cmd, fname, value;
QFileInfo finfo;
bool reverted = false;
int processed = 0;
QStrList fileList;
debug("*** beginning uninstall of %s", aGroupName);
readInstFileList(aGroupName);
for (fname=mInstFiles.first(); !fname.isEmpty(); fname=mInstFiles.next())
{
reverted = false;
if (unlink(fname.ascii())==0) reverted = true;
finfo.setFile(fname+'~');
if (finfo.exists())
{
if (rename((fname+'~').ascii(), fname.ascii()))
warning(i18n("Failed to rename %s to %s~:\n%s").ascii(),
fname.ascii(), fname.ascii(),
strerror(errno));
else reverted = true;
}
if (reverted)
{
debug("uninstalled %s", fname.ascii());
processed++;
}
}
mInstFiles.clear();
writeInstFileList(aGroupName);
debug("*** done uninstall of %s", aGroupName);
}
//-----------------------------------------------------------------------------
kcontrol'Theme::install() (./kdebase/kcontrol/themes/theme.cpp:964)
void Theme::install(void)
{
debug("Theme::install() started");
loadMappings();
mCmdList.clear();
if (instPanel) installGroup("Panel");
if (instSounds) installGroup("Sounds");
if (instWindowBorder) installGroup("Window Border");
if (instWindowTitlebar) installGroup("Window Titlebar");
if (instWindowButtonLayout) installGroup("Window Button Layout");
if (instWindowGimmick) installGroup("Window Gimmick");
if (instWallpapers) installGroup("Display");
if (instKfm) installGroup("File Manager");
if (instColors) installGroup("Colors");
if (instIcons) installIcons();
debug("*** executing command list");
doCmdList();
debug("Theme::install() done");
saveSettings();
}
//-----------------------------------------------------------------------------
kcontrol'Theme::readCurrent() (./kdebase/kcontrol/themes/theme.cpp:992)
void Theme::readCurrent(void)
{
emit changed();
}
//-----------------------------------------------------------------------------
kcontrol'Theme::openConfig() (./kdebase/kcontrol/themes/theme.cpp:999)
KConfig* Theme::openConfig(const QString aAppName) const
{
return new KConfig(aAppName + "rc");
}
//-----------------------------------------------------------------------------
kcontrol'Theme::readConfig() (./kdebase/kcontrol/themes/theme.cpp:1006)
void Theme::readConfig(void)
{
QString fname;
QColor col;
col.setRgb(192,192,192);
setGroup("General");
mDescription = readEntry("description", QString(name()) + " Theme");
setGroup("Colors");
foregroundColor = readColorEntry(this, "foreground", &col);
backgroundColor = readColorEntry(this, "background", &col);
selectForegroundColor = readColorEntry(this, "selectForeground", &col);
selectBackgroundColor = readColorEntry(this, "selectBackground", &col);
activeForegroundColor = readColorEntry(this, "activeForeground", &col);
activeBackgroundColor = readColorEntry(this, "activeBackground", &col);
activeBlendColor = readColorEntry(this, "activeBlend", &col);
inactiveForegroundColor = readColorEntry(this, "inactiveForeground", &col);
inactiveBackgroundColor = readColorEntry(this, "inactiveBackground", &col);
inactiveBlendColor = readColorEntry(this, "inactiveBlend", &col);
windowForegroundColor = readColorEntry(this, "windowForeground", &col);
windowBackgroundColor = readColorEntry(this, "windowBackground", &col);
contrast = readNumEntry("Contrast", 7);
if (!mPreviewFile.isEmpty())
{
fname = mThemePath + mPreviewFile;
if (!mPreview.load(fname))
{
warning(i18n("Failed to load preview image %s").ascii(), fname.ascii());
mPreview.resize(0,0);
}
}
else mPreview.resize(0,0);
}
//-----------------------------------------------------------------------------
kcontrol'Theme::writeConfig() (./kdebase/kcontrol/themes/theme.cpp:1044)
void Theme::writeConfig(void)
{
debug("Theme::writeConfig() is broken");
return;
setGroup("General");
writeEntry("description", mDescription);
#ifdef BROKEN
setGroup("Colors");
writeColorEntry(this, "BackgroundColor", backgroundColor);
writeColorEntry(this, "SelectColor", selectColor);
writeColorEntry(this, "TextColor", textColor);
writeColorEntry(this, "ActiveTitleTextColor", activeTextColor);
writeColorEntry(this, "InactiveTitleBarColor", inactiveTitleColor);
writeColorEntry(this, "ActiveTitleBarColor", activeTitleColor);
writeColorEntry(this, "InactiveTitleTextColor", inactiveTextColor);
writeColorEntry(this, "WindowTextColor", windowTextColor);
writeColorEntry(this, "WindowColor", windowColor);
writeColorEntry(this, "SelectTextColor", selectTextColor);
writeEntry("Contrast", contrast);
#endif
}
//-----------------------------------------------------------------------------
kcontrol'Theme::writeColorEntry() (./kdebase/kcontrol/themes/theme.cpp:1070)
void Theme::writeColorEntry(KConfigBase* cfg, const char* aKey,
const QColor& aColor)
{
QString str; // !!! Changed from QString(32). It should be safe with Qt2.0 (ce)
str.sprintf("#%02x%02x%02x", aColor.red(), aColor.green(), aColor.blue());
cfg->writeEntry(aKey, str);
}
//-----------------------------------------------------------------------------
kcontrol'Theme::readColorEntry() (./kdebase/kcontrol/themes/theme.cpp:1080)
const QColor& Theme::readColorEntry(KConfigBase* cfg, const char* aKey,
const QColor* aDefault) const
{
static QColor col;
QString str = cfg->readEntry(aKey, QString::null);
if (!str.isEmpty()) col.setNamedColor(str);
else if (aDefault) col = *aDefault;
return col;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::clear() (./kdebase/kcontrol/themes/theme.cpp:1094)
void Theme::clear(void)
{
QStringList gList(groupList());
for (QStringList::Iterator gIt(gList.begin()); gIt != gList.end(); ++gIt) {
deleteGroup(*gIt);
}
}
//-----------------------------------------------------------------------------
kcontrol'Theme::mkdirhier() (./kdebase/kcontrol/themes/theme.cpp:1105)
bool Theme::mkdirhier(const char* aDir, const char* aBaseDir)
{
QDir dir;
const char* dirName;
int oldMask = umask(077);
if (aBaseDir) dir.cd(aBaseDir,true);
else if (aDir[0]!='/') dir.cd(kapp->localkdedir());
else dir.cd("/");
char *buffer = qstrdup(aDir);
for (dirName=strtok(buffer,"/"); dirName; dirName=strtok(0, "/"))
{
if (dirName[0]=='\0') continue;
if (!dir.exists(dirName))
{
if (!dir.mkdir(dirName))
{
warning(i18n("Cannot create directory %s").ascii(),
(dir.dirName() + dirName).ascii());
umask(oldMask);
return false;
}
}
if (!dir.cd(dirName))
{
warning(i18n("Cannot enter directory %s").ascii(),
(dir.dirName() + dirName).ascii());
umask(oldMask);
return false;
}
}
delete [] buffer;
umask(oldMask);
return true;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::hasGroup() (./kdebase/kcontrol/themes/theme.cpp:1146)
bool Theme::hasGroup(const QString& aName, bool aNotEmpty)
{
debug(QString("==> hasGroup: name = %1 aNotEmpty = %2").arg(aName).
arg(aNotEmpty ? "true" : "false"));
// Endless recursion??
// bool found(hasGroup(aName));
bool found = false;
if (!aNotEmpty)
return found;
QMap<QString, QString> aMap = entryMap(aName);
if (found && aNotEmpty)
found = aMap.isEmpty();
return found;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::stretchPixmap() (./kdebase/kcontrol/themes/theme.cpp:1195)
void Theme::stretchPixmap(const QString aFname, bool aStretchVert)
{
QPixmap src, dest;
QBitmap *srcMask, *destMask;
int w, h, w2, h2;
QPainter p;
src.load(aFname);
if (src.isNull()) return;
w = src.width();
h = src.height();
if (aStretchVert)
{
w2 = w;
for (h2=h; h2<64; h2=h2<<1)
;
}
else
{
h2 = h;
for (w2=w; w2<64; w2=w2<<1)
;
}
dest = src;
dest.resize(w2, h2);
debug("stretching %s from %dx%d to %dx%d", aFname.ascii(),
w, h, w2, h2);
p.begin(&dest);
p.drawTiledPixmap(0, 0, w2, h2, src);
p.end();
srcMask = (QBitmap*)src.mask();
if (srcMask)
{
destMask = (QBitmap*)dest.mask();
p.begin(destMask);
p.drawTiledPixmap(0, 0, w2, h2, *srcMask);
p.end();
}
dest.save(aFname, QPixmap::imageFormat(aFname));
}
//-----------------------------------------------------------------------------
kcontrol'Theme::rotateImage() (./kdebase/kcontrol/themes/theme.cpp:1245)
void Theme::rotateImage(const QString aFname, int aAngle)
{
QPixmap src, dest;
QWMatrix mx;
src.load(aFname);
if (src.isNull()) return;
mx.rotate(aAngle);
dest = src.xForm(mx);
dest.save(aFname, QPixmap::imageFormat(aFname));
}
//-----------------------------------------------------------------------------
kcontrol'Theme::iconToMiniIcon() (./kdebase/kcontrol/themes/theme.cpp:1261)
void Theme::iconToMiniIcon(const QString aIcon, const QString aMiniIcon)
{
QPixmap src, dest;
QWMatrix mx;
src.load(aIcon);
if (src.isNull()) return;
mx.scale(.5, .5);
dest = src.xForm(mx);
dest.save(aMiniIcon, QPixmap::imageFormat(aIcon));
}
//-----------------------------------------------------------------------------
kcontrol'Theme::runKrdb() (./kdebase/kcontrol/themes/theme.cpp:1277)
void Theme::runKrdb(void) const
{
KSimpleConfig cfg("kcmdisplayrc", true);
cfg.setGroup("X11");
if (cfg.readBoolEntry("useResourceManager", true))
system("krdb");
}
//-----------------------------------------------------------------------------
kcontrol'Theme::colorSchemeApply() (./kdebase/kcontrol/themes/theme.cpp:1288)
void Theme::colorSchemeApply(void)
{
KIPC::sendMessageAll("KDEChangePalette");
}
//-----------------------------------------------------------------------------
kcontrol'Theme::fileOf() (./kdebase/kcontrol/themes/theme.cpp:1295)
const QString Theme::fileOf(const QString& aName) const
{
int i = aName.findRev('/');
if (i >= 0) return aName.mid(i+1, 1024);
return aName;
}
//-----------------------------------------------------------------------------
kcontrol'Theme::pathOf() (./kdebase/kcontrol/themes/theme.cpp:1304)
const QString Theme::pathOf(const QString& aName) const
{
int i = aName.findRev('/');
if (i >= 0) return aName.left(i);
return aName;
}
//-----------------------------------------------------------------------------