there is no moc file generated for this class
[kdegraphics.git] / kolourpaint / mainWindow / kpMainWindow_Help.cpp
blob65dfe240c2098e4cb2203d97c4b010b54962a250
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <kpMainWindow.h>
30 #include <kpMainWindowPrivate.h>
32 #include <QLabel>
33 #include <QtDBus>
35 #include <kaction.h>
36 #include <kactioncollection.h>
38 #include <kconfig.h>
39 #include <kconfiggroup.h>
40 #include <kdebug.h>
41 #include <kdialog.h>
42 #include <kglobal.h>
43 #include <klocale.h>
44 #include <krun.h>
45 #include <kshortcut.h>
48 // private
49 void kpMainWindow::setupHelpMenuActions ()
51 KActionCollection *ac = actionCollection ();
54 // Explanation for action name:
55 // "Taking" is like a digital camera when you record the image and is
56 // analogous to pressing PrintScreen. However, "Acquiring" is when
57 // the image is brought into KolourPaint, just as you would acquire
58 // from a digital camera in future versions of KolourPaint. Hence
59 // "Acquiring" is more appropriate.
60 // -- Thurston
61 d->actionHelpTakingScreenshots = ac->addAction ("help_taking_screenshots");
62 d->actionHelpTakingScreenshots->setText (i18n ("Acquiring &Screenshots"));
63 connect (d->actionHelpTakingScreenshots, SIGNAL (triggered (bool)),
64 SLOT (slotHelpTakingScreenshots ()));
67 enableHelpMenuDocumentActions (false);
70 // private
71 void kpMainWindow::enableHelpMenuDocumentActions (bool /*enable*/)
73 // d->m_actionHelpTakingScreenshots
77 // SYNC: kdebase/kwin/kwinbindings.cpp
78 static QString printScreenShortcutString ()
80 KConfigGroup cfg (KGlobal::config (), "Global Shortcuts");
82 // TODO: i18n() entry name? kwinbindings.cpp seems to but it doesn't
83 // make sense.
84 const QString cfgEntryString = cfg.readEntry ("Desktop Screenshot");
87 // (only use 1st key sequence, if it exists)
88 const QString humanReadableShortcut =
89 KShortcut (cfgEntryString).primary().toString ();
91 if (!humanReadableShortcut.isEmpty ())
93 return humanReadableShortcut;
95 else
97 // (localised)
98 return KShortcut (Qt::CTRL + Qt::Key_Print).toString ();
103 // private slot
104 void kpMainWindow::slotHelpTakingScreenshots ()
106 #if DEBUG_KP_MAIN_WINDOW
107 kDebug () << "kpMainWindow::slotHelpTakingScreenshots()";
108 #endif
110 toolEndShape ();
113 // TODO: Totally bogus logic if kwin not running under same user as KolourPaint.
114 // SYNC: KWin contains PrintScreen key logic
115 #if DEBUG_KP_MAIN_WINDOW
116 //kDebug () << "\tdcopApps=" << dcopApps;
117 #endif
118 bool isRunningKDE = true; // COMPAT QDBus::sessionBus().busService()->nameHasOwner("kwin");
120 #if 0
122 int i = 0;
123 FILE *fp = fopen ("/home/kdevel/kolourpaint.tmp", "rt");
124 if (fp && fscanf (fp, "Hello: %d", &i) == 1)
125 isRunningKDE = i, fclose (fp);
127 #endif
129 QString message;
130 if (isRunningKDE)
132 message = i18n
134 "<p>"
135 "To acquire a screenshot, press <b>%1</b>."
136 " The screenshot will be placed into the clipboard"
137 " and you will be able to paste it in KolourPaint."
138 "</p>"
140 "<p>"
141 "You may configure the <b>Desktop Screenshot</b> shortcut"
142 " in the KDE Control Center"
143 " module <a href=\"configure kde shortcuts\">Keyboard Shortcuts</a>."
144 "</p>"
146 "<p>Alternatively, you may try the application"
147 " <a href=\"run ksnapshot\">KSnapshot</a>."
148 "</p>",
149 // TODO: Totally bogus logic if kwin not running under same user as KolourPaint.
150 ::printScreenShortcutString ()
153 else
155 message = i18n
157 "<p>"
158 "You do not appear to be running KDE."
159 "</p>"
161 // We tell them this much even though they aren't running KDE
162 // to entice them to use KDE since it's so easy.
163 "<p>"
164 "Once you have loaded KDE:<br>"
165 "<blockquote>"
166 "To acquire a screenshot, press <b>%1</b>."
167 " The screenshot will be placed into the clipboard"
168 " and you will be able to paste it in KolourPaint."
169 "</blockquote>"
170 "</p>"
172 "<p>Alternatively, you may try the application"
173 " <a href=\"run ksnapshot\">KSnapshot</a>."
174 "</p>",
175 // TODO: Totally bogus logic if kwin not running under same user as KolourPaint.
176 ::printScreenShortcutString ()
181 // Add extra vertical space
182 message += "<p>&nbsp;</p>";
185 KDialog dlg (this);
186 dlg.setCaption (i18n ("Acquiring Screenshots"));
187 dlg.setButtons (KDialog::Close);
188 dlg.setDefaultButton (KDialog::Close);
189 dlg.showButtonSeparator (true);
191 QLabel *messageLabel = new QLabel (message, &dlg);
192 messageLabel->setWordWrap(true);
194 connect (messageLabel, SIGNAL (linkActivated (const QString &)),
195 this, SLOT (slotHelpTakingScreenshotsFollowLink (const QString &)));
197 dlg.setMainWidget (messageLabel);
199 dlg.exec ();
202 // private
203 void kpMainWindow::slotHelpTakingScreenshotsFollowLink (const QString &link)
205 #if DEBUG_KP_MAIN_WINDOW
206 kDebug () << "kpMainWindow::slotHelpTakingScreenshotsFollowLink("
207 << link << ")" << endl;
208 #endif
210 if (link == "configure kde shortcuts")
212 KRun::runCommand ("kcmshell4 keys", this);
214 else if (link == "run ksnapshot")
216 KRun::runCommand ("ksnapshot", this);
218 else
220 kError () << "kpMainWindow::slotHelpTakingScreenshotsFollowLink("
221 << link << ")" << endl;