Changeset View
Changeset View
Standalone View
Standalone View
kcms/colors/editor/kcolorschemeeditor.cpp
- This file was moved from kcms/colors/kcolorschemeeditor.cpp.
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "scmeditordialog.h" | 20 | #include "scmeditordialog.h" | ||
21 | 21 | | |||
22 | #include <QApplication> | 22 | #include <QApplication> | ||
23 | #include <QCommandLineParser> | 23 | #include <QCommandLineParser> | ||
24 | #include <QTextStream> | 24 | #include <QTextStream> | ||
25 | 25 | | |||
26 | #include <KAboutData> | 26 | #include <KAboutData> | ||
27 | #include <KWindowSystem> | ||||
27 | 28 | | |||
28 | int main(int argc, char* argv[]) | 29 | int main(int argc, char* argv[]) | ||
29 | { | 30 | { | ||
30 | | ||||
31 | QApplication app(argc, argv); | 31 | QApplication app(argc, argv); | ||
32 | 32 | | |||
33 | KAboutData aboutData( | 33 | KAboutData aboutData( | ||
34 | QStringLiteral("kcolorschemeeditor"), | 34 | QStringLiteral("kcolorschemeeditor"), | ||
35 | i18n("KColorSchemeEditor"), | 35 | i18n("KColorSchemeEditor"), | ||
36 | QStringLiteral("0.1"), | 36 | QStringLiteral("0.1"), | ||
37 | i18n("Utility to edit and create color schemes"), | 37 | i18n("Utility to edit and create color schemes"), | ||
38 | KAboutLicense::GPL_V3 | 38 | KAboutLicense::GPL_V3 | ||
39 | ); | 39 | ); | ||
40 | aboutData.addAuthor(i18n("Olivier Churlaud"), i18n("Utility creation"), | 40 | aboutData.addAuthor(i18n("Olivier Churlaud"), i18n("Utility creation"), | ||
41 | QStringLiteral("olivier@churlaud.com")); | 41 | QStringLiteral("olivier@churlaud.com")); | ||
42 | aboutData.addAuthor(i18n("Jeremy Whiting"), i18n("KCM code (reused in here)"), | 42 | aboutData.addAuthor(i18n("Jeremy Whiting"), i18n("KCM code (reused in here)"), | ||
43 | QStringLiteral("jpwhiting@kde.org")); | 43 | QStringLiteral("jpwhiting@kde.org")); | ||
44 | aboutData.addAuthor(i18n("Matthew Woehlke"), i18n("KCM code (reused in here)"), | 44 | aboutData.addAuthor(i18n("Matthew Woehlke"), i18n("KCM code (reused in here)"), | ||
45 | QStringLiteral("mw_triad@users.sourceforge.net")); | 45 | QStringLiteral("mw_triad@users.sourceforge.net")); | ||
46 | KAboutData::setApplicationData(aboutData); | 46 | KAboutData::setApplicationData(aboutData); | ||
47 | 47 | | |||
48 | QCommandLineParser parser; | 48 | QCommandLineParser parser; | ||
49 | parser.addPositionalArgument("theme", i18n("Scheme to edit or to use as a base."), | 49 | parser.addPositionalArgument("theme", i18n("Scheme to edit or to use as a base."), | ||
50 | QStringLiteral("kcolorschemeeditor ThemeName")); | 50 | QStringLiteral("kcolorschemeeditor ThemeName")); | ||
51 | // TODO --attach | ||||
52 | | ||||
53 | QCommandLineOption overwriteOption(QStringLiteral("overwrite"), i18n("Overwrite edited theme when saving")); | ||||
54 | parser.addOption(overwriteOption); | ||||
55 | | ||||
56 | QCommandLineOption attachOption(QStringLiteral("attach"), i18n("Makes the dialog transient for another application window specified by handle"), QStringLiteral("handle")); | ||||
57 | parser.addOption(attachOption); | ||||
58 | | ||||
51 | aboutData.setupCommandLine(&parser); | 59 | aboutData.setupCommandLine(&parser); | ||
52 | parser.process(app); | 60 | parser.process(app); | ||
53 | aboutData.processCommandLine(&parser); | 61 | aboutData.processCommandLine(&parser); | ||
54 | 62 | | |||
55 | const QStringList args = parser.positionalArguments(); | 63 | const QStringList args = parser.positionalArguments(); | ||
56 | QString path = ""; | 64 | QString path = ""; | ||
57 | if (args.count() == 1) | 65 | if (args.count() == 1) | ||
58 | { | 66 | { | ||
59 | const QString fileBaseName(args.at(0)); | 67 | const QString fileBaseName(args.at(0)); | ||
60 | path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | 68 | path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | ||
61 | "color-schemes/" + fileBaseName + ".colors"); | 69 | "color-schemes/" + fileBaseName + ".colors"); | ||
62 | } | 70 | } | ||
63 | if (path.isEmpty()) | 71 | if (path.isEmpty()) | ||
64 | { | 72 | { | ||
65 | QTextStream out(stderr); | 73 | QTextStream out(stderr); | ||
66 | out << i18n("Scheme not found, falling back to current one.\n"); | 74 | out << i18n("Scheme not found, falling back to current one.\n"); | ||
67 | } | 75 | } | ||
68 | 76 | | |||
69 | SchemeEditorDialog dialog(path); | 77 | SchemeEditorDialog dialog(path); | ||
78 | dialog.setOverwriteOnSave(parser.isSet(overwriteOption)); | ||||
79 | | ||||
80 | // FIXME doesn't work :( | ||||
81 | const QString attachHandle = parser.value(attachOption); | ||||
82 | if (!attachHandle.isEmpty()) { | ||||
83 | // TODO wayland: once we have foreign surface support | ||||
84 | const QString x11Prefix = QStringLiteral("x11:"); | ||||
85 | | ||||
86 | if (attachHandle.startsWith(x11Prefix)) { | ||||
87 | bool ok = false; | ||||
88 | WId winId = attachHandle.mid(x11Prefix.length()).toLong(&ok, 0); | ||||
89 | if (ok) { | ||||
90 | KWindowSystem::setMainWindow(&dialog, winId); | ||||
91 | } | ||||
92 | } | ||||
93 | } | ||||
70 | 94 | | |||
71 | dialog.show(); | 95 | dialog.show(); | ||
72 | 96 | | |||
73 | return app.exec(); | 97 | return app.exec(); | ||
74 | } | 98 | } |