Changeset View
Changeset View
Standalone View
Standalone View
src/Main.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 38 | { | |||
---|---|---|---|---|---|
63 | parser.addHelpOption(); | 63 | parser.addHelpOption(); | ||
64 | aboutData.setupCommandLine(&parser); | 64 | aboutData.setupCommandLine(&parser); | ||
65 | 65 | | |||
66 | parser.addOptions({ | 66 | parser.addOptions({ | ||
67 | {{QStringLiteral("f"), QStringLiteral("fullscreen")}, i18n("Capture the entire desktop (default)")}, | 67 | {{QStringLiteral("f"), QStringLiteral("fullscreen")}, i18n("Capture the entire desktop (default)")}, | ||
68 | {{QStringLiteral("m"), QStringLiteral("current")}, i18n("Capture the current monitor")}, | 68 | {{QStringLiteral("m"), QStringLiteral("current")}, i18n("Capture the current monitor")}, | ||
69 | {{QStringLiteral("a"), QStringLiteral("activewindow")}, i18n("Capture the active window")}, | 69 | {{QStringLiteral("a"), QStringLiteral("activewindow")}, i18n("Capture the active window")}, | ||
70 | {{QStringLiteral("u"), QStringLiteral("windowundercursor")}, i18n("Capture the window currently under the cursor, including parents of pop-up menus")}, | 70 | {{QStringLiteral("u"), QStringLiteral("windowundercursor")}, i18n("Capture the window currently under the cursor, including parents of pop-up menus")}, | ||
71 | {{QStringLiteral("t"), QStringLiteral("transientonly")}, i18n("Capture the window currently under the cursor, excluding parents of pop-up menus")}, | 71 | // A non-working option... commented out until it's fixed or decided upon to be removed | ||
72 | //{{QStringLiteral("t"), QStringLiteral("transientonly")}, i18n("Capture the window currently under the cursor, excluding parents of pop-up menus")}, | ||||
72 | {{QStringLiteral("r"), QStringLiteral("region")}, i18n("Capture a rectangular region of the screen")}, | 73 | {{QStringLiteral("r"), QStringLiteral("region")}, i18n("Capture a rectangular region of the screen")}, | ||
73 | {{QStringLiteral("g"), QStringLiteral("gui")}, i18n("Start in GUI mode (default)")}, | 74 | // Parser option to start in GUI mode removed as redundant, as that's the default mode | ||
74 | {{QStringLiteral("b"), QStringLiteral("background")}, i18n("Take a screenshot and exit without showing the GUI")}, | 75 | {{QStringLiteral("n"), QStringLiteral("nonotify")}, i18n("Take a screenshot and save it with an automatic filename, with no notification or GUI.")}, | ||
76 | {{QStringLiteral("o"), QStringLiteral("output")}, i18n("Take a screenshot and save it to the specified filename."), QStringLiteral("filename")}, | ||||
77 | // "delay" input changed to seconds instead of milliseconds (more user-friendly) | ||||
78 | {{QStringLiteral("d"), QStringLiteral("delay")}, i18n("Delay before automatically taking the shot (in seconds)"), QStringLiteral("delaySeconds")}, | ||||
79 | // Commented-out "wait for mouse click" becuase it's not implemented. | ||||
80 | // see line 37 of ImageGrabber.cpp - manually returns false to a check for mouse click supported | ||||
81 | //{{QStringLiteral("w"), QStringLiteral("onclick")}, i18n("Wait for a mouse click before taking screenshot.")}, | ||||
82 | // DBus option moved to bottom of help output, since it's the most obscure | ||||
75 | {{QStringLiteral("s"), QStringLiteral("dbus")}, i18n("Start in DBus-Activation mode")}, | 83 | {{QStringLiteral("s"),QStringLiteral("dbus")}, i18n("Start in DBus-Activation mode")}, | ||
76 | {{QStringLiteral("n"), QStringLiteral("nonotify")}, i18n("In background mode, do not pop up a notification when the screenshot is taken")}, | | |||
77 | {{QStringLiteral("o"), QStringLiteral("output")}, i18n("In background mode, save image to specified file"), QStringLiteral("fileName")}, | | |||
78 | {{QStringLiteral("d"), QStringLiteral("delay")}, i18n("In background mode, delay before taking the shot (in milliseconds)"), QStringLiteral("delayMsec")}, | | |||
79 | {{QStringLiteral("w"), QStringLiteral("onclick")}, i18n("Wait for a click before taking screenshot. Invalidates delay")} | | |||
80 | }); | 84 | }); | ||
81 | 85 | | |||
82 | parser.process(app); | 86 | parser.process(app); | ||
83 | aboutData.processCommandLine(&parser); | 87 | aboutData.processCommandLine(&parser); | ||
84 | 88 | | |||
85 | // extract the capture mode | 89 | // extract the capture mode | ||
86 | 90 | | |||
87 | ImageGrabber::GrabMode grabMode = ImageGrabber::FullScreen; | 91 | ImageGrabber::GrabMode grabMode = ImageGrabber::FullScreen; | ||
88 | if (parser.isSet(QStringLiteral("current"))) { | 92 | if (parser.isSet(QStringLiteral("current"))) { | ||
89 | grabMode = ImageGrabber::CurrentScreen; | 93 | grabMode = ImageGrabber::CurrentScreen; | ||
90 | } else if (parser.isSet(QStringLiteral("activewindow"))) { | 94 | } else if (parser.isSet(QStringLiteral("activewindow"))) { | ||
91 | grabMode = ImageGrabber::ActiveWindow; | 95 | grabMode = ImageGrabber::ActiveWindow; | ||
92 | } else if (parser.isSet(QStringLiteral("region"))) { | 96 | } else if (parser.isSet(QStringLiteral("region"))) { | ||
93 | grabMode = ImageGrabber::RectangularRegion; | 97 | grabMode = ImageGrabber::RectangularRegion; | ||
94 | } else if (parser.isSet(QStringLiteral("windowundercursor"))) { | 98 | } else if (parser.isSet(QStringLiteral("windowundercursor"))) { | ||
95 | grabMode = ImageGrabber::TransientWithParent; | 99 | grabMode = ImageGrabber::TransientWithParent; | ||
96 | } else if (parser.isSet(QStringLiteral("transientonly"))) { | 100 | // comment out another non-working option | ||
97 | grabMode = ImageGrabber::WindowUnderCursor; | 101 | //} else if (parser.isSet(QStringLiteral("transientonly"))) { | ||
102 | // grabMode = ImageGrabber::WindowUnderCursor; | ||||
98 | } | 103 | } | ||
99 | 104 | | |||
100 | // are we running in background or dbus mode? | 105 | // are we running in background or dbus mode? | ||
101 | 106 | | |||
102 | SpectacleCore::StartMode startMode = SpectacleCore::GuiMode; | 107 | SpectacleCore::StartMode startMode = SpectacleCore::GuiMode; | ||
103 | bool notify = true; | 108 | bool notify = true; | ||
104 | qint64 delayMsec = 0; | 109 | qint64 delayMsec = 0; | ||
105 | QString fileName = QString(); | 110 | QString fileName = QString(); | ||
106 | 111 | | |||
107 | if (parser.isSet(QStringLiteral("background"))) { | | |||
108 | startMode = SpectacleCore::BackgroundMode; | | |||
109 | } else if (parser.isSet(QStringLiteral("dbus"))) { | | |||
110 | startMode = SpectacleCore::DBusMode; | | |||
111 | } | | |||
112 | 112 | | |||
113 | switch (startMode) { | 113 | // BackgroundMode varieties... | ||
114 | case SpectacleCore::BackgroundMode: | | |||
115 | if (parser.isSet(QStringLiteral("nonotify"))) { | | |||
116 | notify = false; | | |||
117 | } | | |||
118 | 114 | | |||
119 | if (parser.isSet(QStringLiteral("output"))) { | 115 | if (parser.isSet(QStringLiteral("dbus"))) { | ||
116 | startMode = SpectacleCore::DBusMode; | ||||
117 | app.setQuitOnLastWindowClosed(false); | ||||
118 | } else if (parser.isSet(QStringLiteral("nonotify"))) { | ||||
119 | startMode = SpectacleCore::BackgroundMode; | ||||
120 | notify = false; | ||||
121 | } else if (parser.isSet(QStringLiteral("output"))) { | ||||
122 | startMode = SpectacleCore::BackgroundMode; | ||||
120 | fileName = parser.value(QStringLiteral("output")); | 123 | fileName = parser.value(QStringLiteral("output")); | ||
124 | notify = false; | ||||
125 | } else if (parser.isSet(QStringLiteral("delay"))) { | ||||
126 | bool ok; | ||||
127 | startMode = SpectacleCore::BackgroundMode; | ||||
128 | // Human-friendly seconds back to computer-friendly milliseconds | ||||
129 | delayMsec = (parser.value(QStringLiteral("delay")).toLongLong(&ok) * 1000); | ||||
130 | // ok variable automatically set by string->int conversion (handy!) | ||||
131 | if (!ok) { | ||||
132 | QTextStream(stdout) << i18n("ERROR: Invalid value for ") << "<delaySeconds>\n" << endl; | ||||
133 | app.exit(); | ||||
121 | } | 134 | } | ||
135 | }; | ||||
122 | 136 | | |||
123 | if (parser.isSet(QStringLiteral("delay"))) { | | |||
124 | bool ok = false; | | |||
125 | qint64 delayValue = parser.value(QStringLiteral("delay")).toLongLong(&ok); | | |||
126 | if (ok) { | | |||
127 | delayMsec = delayValue; | | |||
128 | } | | |||
129 | } | | |||
130 | 137 | | |||
131 | if (parser.isSet(QStringLiteral("onclick"))) { | | |||
132 | delayMsec = -1; | | |||
133 | } | | |||
134 | case SpectacleCore::DBusMode: | | |||
135 | app.setQuitOnLastWindowClosed(false); | | |||
136 | case SpectacleCore::GuiMode: | | |||
137 | break; | | |||
138 | } | | |||
139 | 138 | | |||
140 | // release the kraken | 139 | // (re)release the kraken (with a version number update) | ||
141 | 140 | | |||
142 | SpectacleCore core(startMode, grabMode, fileName, delayMsec, notify); | 141 | SpectacleCore core(startMode, grabMode, fileName, delayMsec, notify); | ||
143 | QObject::connect(&core, &SpectacleCore::allDone, qApp, &QApplication::quit); | 142 | QObject::connect(&core, &SpectacleCore::allDone, qApp, &QApplication::quit); | ||
144 | 143 | | |||
145 | // create the dbus connections | 144 | // create the dbus connections | ||
146 | 145 | | |||
147 | new KDBusService(KDBusService::Multiple, &core); | 146 | new KDBusService(KDBusService::Multiple, &core); | ||
148 | 147 | | |||
Show All 13 Lines |