void TOC::buildCache() { KXmlGuiWindow *mainWindow = dynamic_cast<KXmlGuiWindow *>( kapp->activeWindow() ); KProcess *meinproc = new KProcess; connect( meinproc, SIGNAL( finished( int, QProcess::ExitStatus) ), this, SLOT( meinprocExited( int, QProcess::ExitStatus) ) ); *meinproc << KStandardDirs::locate("exe", "meinproc4"); *meinproc << "--stylesheet" << KStandardDirs::locate( "data", "khelpcenter/table-of-contents.xslt" ); *meinproc << "--output" << m_cacheFile; *meinproc << m_sourceFile; meinproc->setOutputChannelMode(KProcess::OnlyStderrChannel); meinproc->start(); if (!meinproc->waitForStarted()) { kError() << "could not start process" << meinproc->program(); if (mainWindow && !m_alreadyWarned) { ; // add warning message box with don't display again option // http://api.kde.org/4.0-api/kdelibs-apidocs/kdeui/html/classKDialog.html m_alreadyWarned = true; } delete meinproc; } }
void IndexBuilder::processCmdQueue() { kDebug(1402) << "IndexBuilder::processCmdQueue()"; QStringList::Iterator it = mCmdQueue.begin(); if ( it == mCmdQueue.end() ) { quit(); return; } QString cmd = *it; kDebug(1402) << "PROCESS: " << cmd; KProcess *proc = new KProcess; *proc << KShell::splitArgs(cmd); connect( proc, SIGNAL( finished( int, QProcess::ExitStatus) ), SLOT( slotProcessExited( int, QProcess::ExitStatus) ) ); mCmdQueue.erase( it ); proc->start(); if ( !proc->waitForStarted() ) { sendErrorSignal( i18n("Unable to start command '%1'.", cmd ) ); processCmdQueue(); delete proc; } }
//Warning: This assumes that both files are CLOSED bool IndexedEdictFile::buildIndex() { KProcess proc; proc << QStandardPaths::findExecutable("kitengen") << m_dictFile.fileName() << m_indexFile.fileName(); proc.start(); proc.waitForStarted(); do { QApplication::processEvents(); } while( proc.waitForFinished( 5000 ) ); //FIXME: This just cuts the index generator off after 5 sec //FIXME: Check for the result of this operation return proc.exitStatus() == QProcess::NormalExit && proc.exitCode() == 0; }
QString CustomScriptPlugin::formatSourceWithStyle(SourceFormatterStyle style, const QString& text, const QUrl &url, const QMimeType& /*mime*/, const QString& leftContext, const QString& rightContext) { KProcess proc; QTextStream ios(&proc); std::unique_ptr<QTemporaryFile> tmpFile; if (style.content().isEmpty()) { style = predefinedStyle(style.name()); if (style.content().isEmpty()) { qWarning() << "Empty contents for style" << style.name() << "for indent plugin"; return text; } } QString useText = text; useText = leftContext + useText + rightContext; QMap<QString, QString> projectVariables; foreach(IProject* project, ICore::self()->projectController()->projects()) projectVariables[project->name()] = project->folder().toLocalFile(); QString command = style.content(); // Replace ${Project} with the project path command = replaceVariables( command, projectVariables ); command.replace("$FILE", url.toLocalFile()); if(command.contains("$TMPFILE")) { tmpFile.reset(new QTemporaryFile(QDir::tempPath() + "/code")); tmpFile->setAutoRemove(false); if(tmpFile->open()) { qCDebug(CUSTOMSCRIPT) << "using temporary file" << tmpFile->fileName(); command.replace("$TMPFILE", tmpFile->fileName()); QByteArray useTextArray = useText.toLocal8Bit(); if( tmpFile->write(useTextArray) != useTextArray.size() ) { qWarning() << "failed to write text to temporary file"; return text; } }else{ qWarning() << "Failed to create a temporary file"; return text; } tmpFile->close(); } qCDebug(CUSTOMSCRIPT) << "using shell command for indentation: " << command; proc.setShellCommand(command); proc.setOutputChannelMode(KProcess::OnlyStdoutChannel); proc.start(); if(!proc.waitForStarted()) { qCDebug(CUSTOMSCRIPT) << "Unable to start indent" << endl; return text; } if(!tmpFile.get()) proc.write(useText.toLocal8Bit()); proc.closeWriteChannel(); if(!proc.waitForFinished()) { qCDebug(CUSTOMSCRIPT) << "Process doesn't finish" << endl; return text; } QString output; if(tmpFile.get()) { QFile f(tmpFile->fileName()); if( f.open(QIODevice::ReadOnly) ) { output = QString::fromLocal8Bit(f.readAll()); }else{ qWarning() << "Failed opening the temporary file for reading"; return text; } }else{ output = ios.readAll(); } if (output.isEmpty()) { qWarning() << "indent returned empty text for style" << style.name() << style.content(); return text; } int tabWidth = 4; if((!leftContext.isEmpty() || !rightContext.isEmpty()) && (text.contains(' ') || output.contains(' '))) { // If we have to do contex-matching with tabs, determine the correct tab-width so that the context // can be matched correctly Indentation indent = indentation(url); if(indent.indentationTabWidth > 0) tabWidth = indent.indentationTabWidth; } return KDevelop::extractFormattedTextFromContext(output, text, leftContext, rightContext, tabWidth); }
MatchChecksumDlg::MatchChecksumDlg(const QStringList& files, bool containFolders, const QString& path, const QString& checksumFile) : QDialog(krApp) { setWindowTitle(i18n("Verify Checksum")); setWindowModality(Qt::WindowModal); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); QList<CS_Tool *> tools = getTools(containFolders); if (tools.count() == 0) { // nothing was suggested?! QString error = i18n("<qt>Cannot verify checksum since no supported tool was found. " "Please check the <b>Dependencies</b> page in Krusader's settings.</qt>"); if (containFolders) error += i18n("<qt><b>Note</b>: you have selected folders, and probably have no recursive checksum tool installed." " Krusader currently supports <i>md5deep, sha1deep, sha256deep, tigerdeep and cfv</i></qt>"); KMessageBox::error(0, error); return; } QWidget * widget = new QWidget(this); QGridLayout *layout = new QGridLayout(widget); int row = 0; // title (icon+text) QHBoxLayout *hlayout = new QHBoxLayout; QLabel *p = new QLabel(widget); p->setPixmap(krLoader->loadIcon("document-edit-decrypt-verify", KIconLoader::Desktop, 32)); hlayout->addWidget(p); QLabel *l1 = new QLabel(widget); if (containFolders) l1->setText(i18n("About to verify checksum for the following files and folders:")); else l1->setText(i18n("About to verify checksum for the following files:")); hlayout->addWidget(l1); layout->addLayout(hlayout, row, 0, 1, 2, Qt::AlignLeft); ++row; // file list KrListWidget *lb = new KrListWidget(widget); lb->addItems(files); layout->addWidget(lb, row, 0, 1, 2); ++row; // checksum file QHBoxLayout *hlayout2 = new QHBoxLayout; QLabel *l2 = new QLabel(i18n("Checksum file:"), widget); hlayout2->addWidget(l2); KUrlRequester *checksumFileReq = new KUrlRequester(widget); checksumFileReq->setUrl(QUrl::fromLocalFile(path)); if (!checksumFile.isEmpty()) checksumFileReq->setUrl(QUrl::fromLocalFile(checksumFile)); checksumFileReq->setFocus(); hlayout2->addWidget(checksumFileReq); layout->addLayout(hlayout2, row, 0, 1, 2, Qt::AlignLeft); mainLayout->addWidget(widget); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); mainLayout->addWidget(buttonBox); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); if (exec() != Accepted) return; QString file = checksumFileReq->url().toDisplayString(QUrl::PreferLocalFile); QString extension; if (!verifyChecksumFile(file, extension)) { KMessageBox::error(0, i18n("<qt>Error reading checksum file <i>%1</i>.<br />Please specify a valid checksum file.</qt>", file)); return; } // do we have a tool for that extension? int i; CS_Tool *mytool = 0; for (i = 0; i < tools.count(); ++i) if (cs_typeToText[tools.at(i)->type] == extension.toLower()) { mytool = tools.at(i); break; } if (!mytool) { KMessageBox::error(0, i18n("<qt>Krusader cannot find a checksum tool that handles %1 on your system. Please check the <b>Dependencies</b> page in Krusader's settings.</qt>", extension)); return; } // else implied: run the process QTemporaryFile tmpOut(QDir::tempPath() + QLatin1String("/krusader_XXXXXX.stdout")); tmpOut.open(); // necessary to create the filename QTemporaryFile tmpErr(QDir::tempPath() + QLatin1String("/krusader_XXXXXX.stderr")); tmpErr.open(); // necessary to create the filename KProcess proc; mytool->verify(proc, mytool, files, file, containFolders, extension); proc.setOutputChannelMode(KProcess::SeparateChannels); // without this the next 2 lines have no effect! proc.setStandardOutputFile(tmpOut.fileName()); proc.setStandardErrorFile(tmpErr.fileName()); proc.setWorkingDirectory(path); krApp->startWaiting(i18n("Verifying checksums..."), 0, true); QApplication::setOverrideCursor(Qt::WaitCursor); proc.start(); // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking // it would be better to connect to started(), error() and finished() if (proc.waitForStarted()) while (proc.state() == QProcess::Running) { usleep(500); qApp->processEvents(); if (krApp->wasWaitingCancelled()) { // user cancelled proc.kill(); QApplication::restoreOverrideCursor(); return; } }; if (proc.exitStatus() != QProcess::NormalExit) { KMessageBox::error(0, i18n("<qt>There was an error while running <b>%1</b>.</qt>", mytool->binary)); return; } QApplication::restoreOverrideCursor(); krApp->stopWait(); // send both stdout and stderr QStringList stdOut, stdErr; if (!KrServices::fileToStringList(&tmpOut, stdOut) || !KrServices::fileToStringList(&tmpErr, stdErr)) { KMessageBox::error(krApp, i18n("Error reading stdout or stderr")); return; } VerifyResultDlg dlg(mytool->failed(stdOut, stdErr)); }
CreateChecksumDlg::CreateChecksumDlg(const QStringList& files, bool containFolders, const QString& path) : QDialog(krApp) { setWindowModality(Qt::WindowModal); setWindowTitle(i18n("Create Checksum")); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); QList<CS_Tool *> tools = getTools(containFolders); if (tools.count() == 0) { // nothing was suggested?! QString error = i18n("<qt>Cannot calculate checksum since no supported tool was found. " "Please check the <b>Dependencies</b> page in Krusader's settings.</qt>"); if (containFolders) error += i18n("<qt><b>Note</b>: you have selected folders, and probably have no recursive checksum tool installed." " Krusader currently supports <i>md5deep, sha1deep, sha256deep, tigerdeep and cfv</i></qt>"); KMessageBox::error(0, error); return; } QWidget * widget = new QWidget(this); QGridLayout *layout = new QGridLayout(widget); int row = 0; // title (icon+text) QHBoxLayout *hlayout = new QHBoxLayout; QLabel *p = new QLabel(widget); p->setPixmap(krLoader->loadIcon("document-edit-sign", KIconLoader::Desktop, 32)); hlayout->addWidget(p); QLabel *l1 = new QLabel(widget); if (containFolders) l1->setText(i18n("About to calculate checksum for the following files and folders:")); else l1->setText(i18n("About to calculate checksum for the following files:")); hlayout->addWidget(l1); layout->addLayout(hlayout, row, 0, 1, 2, Qt::AlignLeft); ++row; // file list KrListWidget *lb = new KrListWidget(widget); lb->addItems(files); layout->addWidget(lb, row, 0, 1, 2); ++row; // checksum method QHBoxLayout *hlayout2 = new QHBoxLayout; QLabel *l2 = new QLabel(i18n("Select the checksum method:"), widget); hlayout2->addWidget(l2); KComboBox *method = new KComboBox(widget); // -- fill the combo with available methods int i; for (i = 0; i < tools.count(); ++i) method->addItem(cs_typeToText[tools.at(i)->type], i); method->setFocus(); hlayout2->addWidget(method); layout->addLayout(hlayout2, row, 0, 1, 2, Qt::AlignLeft); ++row; mainLayout->addWidget(widget); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); mainLayout->addWidget(buttonBox); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); if (exec() != Accepted) return; // else implied: run the process QTemporaryFile tmpOut(QDir::tempPath() + QLatin1String("/krusader_XXXXXX.stdout")); tmpOut.open(); // necessary to create the filename QTemporaryFile tmpErr(QDir::tempPath() + QLatin1String("/krusader_XXXXXX.stderr")); tmpErr.open(); // necessary to create the filename KProcess proc; CS_Tool *mytool = tools.at(method->currentIndex()); mytool->create(proc, mytool, files, QString(), containFolders, method->currentText()); proc.setOutputChannelMode(KProcess::SeparateChannels); // without this the next 2 lines have no effect! proc.setStandardOutputFile(tmpOut.fileName()); proc.setStandardErrorFile(tmpErr.fileName()); proc.setWorkingDirectory(path); krApp->startWaiting(i18n("Calculating checksums..."), 0, true); QApplication::setOverrideCursor(Qt::WaitCursor); proc.start(); // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking // it would be better to connect to started(), error() and finished() if (proc.waitForStarted()) while (proc.state() == QProcess::Running) { usleep(500); qApp->processEvents(); if (krApp->wasWaitingCancelled()) { // user cancelled proc.kill(); QApplication::restoreOverrideCursor(); return; } }; krApp->stopWait(); QApplication::restoreOverrideCursor(); if (proc.exitStatus() != QProcess::NormalExit) { KMessageBox::error(0, i18n("<qt>There was an error while running <b>%1</b>.</qt>", mytool->binary)); return; } // suggest a filename QString suggestedFilename = path + '/'; if (files.count() > 1) suggestedFilename += ("checksum." + cs_typeToText[mytool->type]); else suggestedFilename += (files[0] + '.' + cs_typeToText[mytool->type]); // send both stdout and stderr QStringList stdOut, stdErr; if (!KrServices::fileToStringList(&tmpOut, stdOut) || !KrServices::fileToStringList(&tmpErr, stdErr)) { KMessageBox::error(krApp, i18n("Error reading stdout or stderr")); return; } ChecksumResultsDlg dlg(stdOut, stdErr, suggestedFilename, mytool->standardFormat); }
void runRdb( uint flags ) { // Obtain the application palette that is about to be set. bool exportColors = flags & KRdbExportColors; bool exportQtColors = flags & KRdbExportQtColors; bool exportQtSettings = flags & KRdbExportQtSettings; bool exportXftSettings = flags & KRdbExportXftSettings; bool exportGtkTheme = flags & KRdbExportGtkTheme; KSharedConfigPtr kglobalcfg = KSharedConfig::openConfig( "kdeglobals" ); KConfigGroup kglobals(kglobalcfg, "KDE"); QPalette newPal = KGlobalSettings::createApplicationPalette(kglobalcfg); KTemporaryFile tmpFile; if (!tmpFile.open()) { kDebug() << "Couldn't open temp file"; exit(0); } KConfigGroup generalCfgGroup(kglobalcfg, "General"); QString gtkTheme; if (generalCfgGroup.hasKey("widgetStyle")) gtkTheme = generalCfgGroup.readEntry("widgetStyle"); else gtkTheme = "oxygen"; createGtkrc( exportColors, newPal, exportGtkTheme, gtkTheme, 1 ); createGtkrc( exportColors, newPal, exportGtkTheme, gtkTheme, 2 ); // Export colors to non-(KDE/Qt) apps (e.g. Motif, GTK+ apps) if (exportColors) { KGlobal::dirs()->addResourceType("appdefaults", "data", "kdisplay/app-defaults/"); QString preproc; QColor backCol = newPal.color( QPalette::Active, QPalette::Background ); addColorDef(preproc, "FOREGROUND" , newPal.color( QPalette::Active, QPalette::Foreground ) ); addColorDef(preproc, "BACKGROUND" , backCol); addColorDef(preproc, "HIGHLIGHT" , backCol.light(100+(2*KGlobalSettings::contrast()+4)*16/1)); addColorDef(preproc, "LOWLIGHT" , backCol.dark(100+(2*KGlobalSettings::contrast()+4)*10)); addColorDef(preproc, "SELECT_BACKGROUND" , newPal.color( QPalette::Active, QPalette::Highlight)); addColorDef(preproc, "SELECT_FOREGROUND" , newPal.color( QPalette::Active, QPalette::HighlightedText)); addColorDef(preproc, "WINDOW_BACKGROUND" , newPal.color( QPalette::Active, QPalette::Base ) ); addColorDef(preproc, "WINDOW_FOREGROUND" , newPal.color( QPalette::Active, QPalette::Foreground ) ); addColorDef(preproc, "INACTIVE_BACKGROUND", KGlobalSettings::inactiveTitleColor()); addColorDef(preproc, "INACTIVE_FOREGROUND", KGlobalSettings::inactiveTitleColor()); addColorDef(preproc, "ACTIVE_BACKGROUND" , KGlobalSettings::activeTitleColor()); addColorDef(preproc, "ACTIVE_FOREGROUND" , KGlobalSettings::activeTitleColor()); //--------------------------------------------------------------- tmpFile.write( preproc.toLatin1(), preproc.length() ); QStringList list; const QStringList adPaths = KGlobal::dirs()->findDirs("appdefaults", ""); for (QStringList::ConstIterator it = adPaths.constBegin(); it != adPaths.constEnd(); ++it) { QDir dSys( *it ); if ( dSys.exists() ) { dSys.setFilter( QDir::Files ); dSys.setSorting( QDir::Name ); dSys.setNameFilters(QStringList("*.ad")); list += dSys.entryList(); } } for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) copyFile(tmpFile, KStandardDirs::locate("appdefaults", *it ), true); } // Merge ~/.Xresources or fallback to ~/.Xdefaults QString homeDir = QDir::homePath(); QString xResources = homeDir + "/.Xresources"; // very primitive support for ~/.Xresources by appending it if ( QFile::exists( xResources ) ) copyFile(tmpFile, xResources, true); else copyFile(tmpFile, homeDir + "/.Xdefaults", true); // Export the Xcursor theme & size settings KConfigGroup mousecfg(KSharedConfig::openConfig( "kcminputrc" ), "Mouse" ); QString theme = mousecfg.readEntry("cursorTheme", QString()); QString size = mousecfg.readEntry("cursorSize", QString()); QString contents; if (!theme.isNull()) contents = "Xcursor.theme: " + theme + '\n'; if (!size.isNull()) contents += "Xcursor.size: " + size + '\n'; if (exportXftSettings) { if (generalCfgGroup.hasKey("XftAntialias")) { contents += "Xft.antialias: "; if(generalCfgGroup.readEntry("XftAntialias", true)) contents += "1\n"; else contents += "0\n"; } if (generalCfgGroup.hasKey("XftHintStyle")) { QString hintStyle = generalCfgGroup.readEntry("XftHintStyle", "hintmedium"); contents += "Xft.hinting: "; if(hintStyle.isEmpty()) contents += "-1\n"; else { if(hintStyle!="hintnone") contents += "1\n"; else contents += "0\n"; contents += "Xft.hintstyle: " + hintStyle + '\n'; } } if (generalCfgGroup.hasKey("XftSubPixel")) { QString subPixel = generalCfgGroup.readEntry("XftSubPixel"); if(!subPixel.isEmpty()) contents += "Xft.rgba: " + subPixel + '\n'; } KConfig _cfgfonts( "kcmfonts" ); KConfigGroup cfgfonts(&_cfgfonts, "General"); if( cfgfonts.readEntry( "forceFontDPI", 0 ) != 0 ) contents += "Xft.dpi: " + cfgfonts.readEntry( "forceFontDPI" ) + '\n'; else { KProcess proc; proc << "xrdb" << "-quiet" << "-remove" << "-nocpp"; proc.start(); if (proc.waitForStarted()) { proc.write( QByteArray( "Xft.dpi\n" ) ); proc.closeWriteChannel(); proc.waitForFinished(); } } } if (contents.length() > 0) tmpFile.write( contents.toLatin1(), contents.length() ); tmpFile.flush(); KProcess proc; #ifndef NDEBUG proc << "xrdb" << "-merge" << tmpFile.fileName(); #else proc << "xrdb" << "-quiet" << "-merge" << tmpFile.fileName(); #endif proc.execute(); applyGtkStyles(exportColors, 1); applyGtkStyles(exportColors, 2); /* Qt exports */ if ( exportQtColors || exportQtSettings ) { QSettings* settings = new QSettings(QLatin1String("Trolltech")); if ( exportQtColors ) applyQtColors( kglobalcfg, *settings, newPal ); // For kcmcolors if ( exportQtSettings ) applyQtSettings( kglobalcfg, *settings ); // For kcmstyle delete settings; QApplication::flush(); #if HAVE_X11 if (qApp->platformName() == QStringLiteral("xcb")) { // We let KIPC take care of ourselves, as we are in a KDE app with // QApp::setDesktopSettingsAware(false); // Instead of calling QApp::x11_apply_settings() directly, we instead // modify the timestamp which propagates the settings changes onto // Qt-only apps without adversely affecting ourselves. // Cheat and use the current timestamp, since we just saved to qtrc. QDateTime settingsstamp = QDateTime::currentDateTime(); static Atom qt_settings_timestamp = 0; if (!qt_settings_timestamp) { QString atomname("_QT_SETTINGS_TIMESTAMP_"); atomname += XDisplayName( 0 ); // Use the $DISPLAY envvar. qt_settings_timestamp = XInternAtom( QX11Info::display(), atomname.toLatin1(), False); } QBuffer stamp; QDataStream s(&stamp.buffer(), QIODevice::WriteOnly); s << settingsstamp; XChangeProperty( QX11Info::display(), QX11Info::appRootWindow(), qt_settings_timestamp, qt_settings_timestamp, 8, PropModeReplace, (unsigned char*) stamp.buffer().data(), stamp.buffer().size() ); QApplication::flush(); } #endif } }
void runRdb( uint flags ) { // Obtain the application palette that is about to be set. bool exportColors = flags & KRdbExportColors; bool exportQtColors = flags & KRdbExportQtColors; bool exportQtSettings = flags & KRdbExportQtSettings; bool exportXftSettings = flags & KRdbExportXftSettings; bool exportGtkTheme = flags & KRdbExportGtkTheme; KSharedConfigPtr kglobalcfg = KSharedConfig::openConfig( QStringLiteral("kdeglobals") ); KConfigGroup kglobals(kglobalcfg, "KDE"); QPalette newPal = KColorScheme::createApplicationPalette(kglobalcfg); QTemporaryFile tmpFile; if (!tmpFile.open()) { qDebug() << "Couldn't open temp file"; exit(0); } KConfigGroup generalCfgGroup(kglobalcfg, "General"); QString gtkTheme; if (kglobals.hasKey("widgetStyle")) gtkTheme = kglobals.readEntry("widgetStyle"); else gtkTheme = QStringLiteral("oxygen"); createGtkrc( exportColors, newPal, exportGtkTheme, gtkTheme, 1 ); createGtkrc( exportColors, newPal, exportGtkTheme, gtkTheme, 2 ); // Export colors to non-(KDE/Qt) apps (e.g. Motif, GTK+ apps) if (exportColors) { KConfigGroup g(KSharedConfig::openConfig(), "WM"); QString preproc; QColor backCol = newPal.color( QPalette::Active, QPalette::Background ); addColorDef(preproc, "FOREGROUND" , newPal.color( QPalette::Active, QPalette::Foreground ) ); addColorDef(preproc, "BACKGROUND" , backCol); addColorDef(preproc, "HIGHLIGHT" , backCol.light(100+(2*KColorScheme::contrast()+4)*16/1)); addColorDef(preproc, "LOWLIGHT" , backCol.dark(100+(2*KColorScheme::contrast()+4)*10)); addColorDef(preproc, "SELECT_BACKGROUND" , newPal.color( QPalette::Active, QPalette::Highlight)); addColorDef(preproc, "SELECT_FOREGROUND" , newPal.color( QPalette::Active, QPalette::HighlightedText)); addColorDef(preproc, "WINDOW_BACKGROUND" , newPal.color( QPalette::Active, QPalette::Base ) ); addColorDef(preproc, "WINDOW_FOREGROUND" , newPal.color( QPalette::Active, QPalette::Text ) ); addColorDef(preproc, "INACTIVE_BACKGROUND", g.readEntry("inactiveBackground", QColor(224, 223, 222))); addColorDef(preproc, "INACTIVE_FOREGROUND", g.readEntry("inactiveBackground", QColor(224, 223, 222))); addColorDef(preproc, "ACTIVE_BACKGROUND" , g.readEntry("activeBackground", QColor(48, 174, 232))); addColorDef(preproc, "ACTIVE_FOREGROUND" , g.readEntry("activeBackground", QColor(48, 174, 232))); //--------------------------------------------------------------- tmpFile.write( preproc.toLatin1(), preproc.length() ); QStringList list; const QStringList adPaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kdisplay/app-defaults/"), QStandardPaths::LocateDirectory); for (QStringList::ConstIterator it = adPaths.constBegin(); it != adPaths.constEnd(); ++it) { QDir dSys( *it ); if ( dSys.exists() ) { dSys.setFilter( QDir::Files ); dSys.setSorting( QDir::Name ); dSys.setNameFilters(QStringList(QStringLiteral("*.ad"))); list += dSys.entryList(); } } for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) copyFile(tmpFile, QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdisplay/app-defaults/"+(*it)), true); } // Merge ~/.Xresources or fallback to ~/.Xdefaults QString homeDir = QDir::homePath(); QString xResources = homeDir + "/.Xresources"; // very primitive support for ~/.Xresources by appending it if ( QFile::exists( xResources ) ) copyFile(tmpFile, xResources, true); else copyFile(tmpFile, homeDir + "/.Xdefaults", true); // Export the Xcursor theme & size settings KConfigGroup mousecfg(KSharedConfig::openConfig( QStringLiteral("kcminputrc") ), "Mouse" ); QString theme = mousecfg.readEntry("cursorTheme", QString()); QString size = mousecfg.readEntry("cursorSize", QString()); QString contents; if (!theme.isNull()) contents = "Xcursor.theme: " + theme + '\n'; if (!size.isNull()) contents += "Xcursor.size: " + size + '\n'; if (exportXftSettings) { if (generalCfgGroup.hasKey("XftAntialias")) { contents += QLatin1String("Xft.antialias: "); if(generalCfgGroup.readEntry("XftAntialias", true)) contents += QLatin1String("1\n"); else contents += QLatin1String("0\n"); } if (generalCfgGroup.hasKey("XftHintStyle")) { QString hintStyle = generalCfgGroup.readEntry("XftHintStyle", "hintmedium"); contents += QLatin1String("Xft.hinting: "); if(hintStyle.isEmpty()) contents += QLatin1String("-1\n"); else { if(hintStyle!=QLatin1String("hintnone")) contents += QLatin1String("1\n"); else contents += QLatin1String("0\n"); contents += "Xft.hintstyle: " + hintStyle + '\n'; } } if (generalCfgGroup.hasKey("XftSubPixel")) { QString subPixel = generalCfgGroup.readEntry("XftSubPixel"); if(!subPixel.isEmpty()) contents += "Xft.rgba: " + subPixel + '\n'; } KConfig _cfgfonts( QStringLiteral("kcmfonts") ); KConfigGroup cfgfonts(&_cfgfonts, "General"); if( cfgfonts.readEntry( "forceFontDPI", 0 ) != 0 ) contents += "Xft.dpi: " + cfgfonts.readEntry( "forceFontDPI" ) + '\n'; else { KProcess proc; proc << QStringLiteral("xrdb") << QStringLiteral("-quiet") << QStringLiteral("-remove") << QStringLiteral("-nocpp"); proc.start(); if (proc.waitForStarted()) { proc.write( QByteArray( "Xft.dpi\n" ) ); proc.closeWriteChannel(); proc.waitForFinished(); } } } if (contents.length() > 0) tmpFile.write( contents.toLatin1(), contents.length() ); tmpFile.flush(); KProcess proc; #ifndef NDEBUG proc << QStringLiteral("xrdb") << QStringLiteral("-merge") << tmpFile.fileName(); #else proc << "xrdb" << "-quiet" << "-merge" << tmpFile.fileName(); #endif proc.execute(); applyGtkStyles(exportColors, 1); applyGtkStyles(exportColors, 2); /* Qt exports */ if ( exportQtColors || exportQtSettings ) { QSettings* settings = new QSettings(QStringLiteral("Trolltech")); if ( exportQtColors ) applyQtColors( kglobalcfg, *settings, newPal ); // For kcmcolors if ( exportQtSettings ) applyQtSettings( kglobalcfg, *settings ); // For kcmstyle delete settings; QApplication::flush(); #if HAVE_X11 if (qApp->platformName() == QStringLiteral("xcb")) { // We let KIPC take care of ourselves, as we are in a KDE app with // QApp::setDesktopSettingsAware(false); // Instead of calling QApp::x11_apply_settings() directly, we instead // modify the timestamp which propagates the settings changes onto // Qt-only apps without adversely affecting ourselves. // Cheat and use the current timestamp, since we just saved to qtrc. QDateTime settingsstamp = QDateTime::currentDateTime(); static Atom qt_settings_timestamp = 0; if (!qt_settings_timestamp) { QString atomname(QStringLiteral("_QT_SETTINGS_TIMESTAMP_")); atomname += XDisplayName( 0 ); // Use the $DISPLAY envvar. qt_settings_timestamp = XInternAtom( QX11Info::display(), atomname.toLatin1(), False); } QBuffer stamp; QDataStream s(&stamp.buffer(), QIODevice::WriteOnly); s << settingsstamp; XChangeProperty( QX11Info::display(), QX11Info::appRootWindow(), qt_settings_timestamp, qt_settings_timestamp, 8, PropModeReplace, (unsigned char*) stamp.buffer().data(), stamp.buffer().size() ); QApplication::flush(); } #endif } //Legacy support: //Try to sync kde4 settings with ours Kdelibs4Migration migration; //kf5 congig groups for general and icons KConfigGroup generalGroup(kglobalcfg, "General"); KConfigGroup iconsGroup(kglobalcfg, "Icons"); const QString colorSchemeName = generalGroup.readEntry("ColorScheme", QString()); //if no valid color scheme saved, something weird is going on, abort if (colorSchemeName.isEmpty()) { return; } //fix filename, copied from ColorsCM::saveScheme() QString colorSchemeFilename = colorSchemeName; colorSchemeFilename.remove('\''); // So Foo's does not become FooS QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); int offset; while ((offset = fixer.indexIn(colorSchemeFilename)) >= 0) colorSchemeFilename.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); colorSchemeFilename.replace(0, 1, colorSchemeFilename.at(0).toUpper()); //clone the color scheme QString src = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + colorSchemeFilename + ".colors"); QString dest = migration.saveLocation("data", QStringLiteral("color-schemes")) + colorSchemeName + ".colors"; QFile::remove(dest); QFile::copy(src, dest); //Apply the color scheme QString configFilePath = migration.saveLocation("config") + "kdeglobals"; if (configFilePath.isEmpty()) { return; } KConfig kde4config(configFilePath, KConfig::SimpleConfig); KConfigGroup kde4generalGroup(&kde4config, "General"); kde4generalGroup.writeEntry("ColorScheme", colorSchemeName); //fonts QString font = generalGroup.readEntry("font", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("font", font); } font = generalGroup.readEntry("desktopFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("desktopFont", font); } font = generalGroup.readEntry("menuFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("menuFont", font); } font = generalGroup.readEntry("smallestReadableFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("smallestReadableFont", font); } font = generalGroup.readEntry("taskbarFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("taskbarFont", font); } font = generalGroup.readEntry("toolBarFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("toolBarFont", font); } //TODO: does exist any way to check if a qt4 widget style is present from a qt5 app? //kde4generalGroup.writeEntry("widgetStyle", "qtcurve"); kde4generalGroup.sync(); KConfigGroup kde4IconGroup(&kde4config, "Icons"); QString iconTheme = iconsGroup.readEntry("Theme", QString()); if (!iconTheme.isEmpty()) { kde4IconGroup.writeEntry("Theme", iconTheme); } kde4IconGroup.sync(); //copy all the groups in the color scheme in kdeglobals KSharedConfigPtr kde4ColorConfig = KSharedConfig::openConfig(src, KConfig::SimpleConfig); foreach (const QString &grp, kde4ColorConfig->groupList()) { KConfigGroup cg(kde4ColorConfig, grp); KConfigGroup cg2(&kde4config, grp); cg.copyTo(&cg2); } //widgets settings KConfigGroup kglobals4(&kde4config, "KDE"); kglobals4.writeEntry("ShowIconsInMenuItems", kglobals.readEntry("ShowIconsInMenuItems", true)); kglobals4.writeEntry("ShowIconsOnPushButtons", kglobals.readEntry("ShowIconsOnPushButtons", true)); kglobals4.writeEntry("contrast", kglobals.readEntry("contrast", 4)); //FIXME: this should somehow check if the kde4 version of the style is installed kde4generalGroup.writeEntry("widgetStyle", kglobals.readEntry("widgetStyle", "breeze")); //toolbar style KConfigGroup toolbars4(&kde4config, "Toolbar style"); KConfigGroup toolbars5(kglobalcfg, "Toolbar style"); toolbars4.writeEntry("ToolButtonStyle", toolbars5.readEntry("ToolButtonStyle", "TextBesideIcon")); toolbars4.writeEntry("ToolButtonStyleOtherToolbars", toolbars5.readEntry("ToolButtonStyleOtherToolbars", "TextBesideIcon")); }