TDE graphics utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kpmainwindow_help.cpp 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  13. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  14. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  15. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  18. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #include <kpmainwindow.h>
  24. #include <kpmainwindow_p.h>
  25. #include <dcopclient.h>
  26. #include <tdeaction.h>
  27. #include <kactivelabel.h>
  28. #include <tdeapplication.h>
  29. #include <tdeconfig.h>
  30. #include <kdebug.h>
  31. #include <kdialogbase.h>
  32. #include <krun.h>
  33. #include <tdelocale.h>
  34. #include <tdeshortcut.h>
  35. #include <kptool.h>
  36. // private
  37. void kpMainWindow::setupHelpMenuActions ()
  38. {
  39. TDEActionCollection *ac = actionCollection ();
  40. // Explanation for action name:
  41. // "Taking" is like a digital camera when you record the image and is
  42. // analogous to pressing PrintScreen. However, "Acquiring" is when
  43. // the image is brought into KolourPaint, just as you would acquire
  44. // from a digital camera in future versions of KolourPaint. Hence
  45. // "Acquiring" is more appropriate.
  46. // -- Thurston
  47. d->m_actionHelpTakingScreenshots = new TDEAction (
  48. i18n ("Acquiring &Screenshots"), 0,
  49. TQT_TQOBJECT(this), TQT_SLOT (slotHelpTakingScreenshots ()),
  50. ac, "help_taking_screenshots");
  51. enableHelpMenuDocumentActions (false);
  52. }
  53. // private
  54. void kpMainWindow::enableHelpMenuDocumentActions (bool /*enable*/)
  55. {
  56. }
  57. // SYNC: tdebase/twin/twinbindings.cpp
  58. static TQString printScreenShortcutString ()
  59. {
  60. TDEConfigGroupSaver cfgGroupSaver (TDEGlobal::config (), "Global Shortcuts");
  61. TDEConfigBase *cfg = cfgGroupSaver.config ();
  62. // TODO: i18n() entry name? twinbindings.cpp seems to but it doesn't
  63. // make sense.
  64. const TQString cfgEntryString = cfg->readEntry ("Desktop Screenshot");
  65. // (only use 1st key sequence, if it exists)
  66. const TQString humanReadableShortcut =
  67. TDEShortcut (cfgEntryString).seq (0).toString ();
  68. if (!humanReadableShortcut.isEmpty ())
  69. {
  70. return humanReadableShortcut;
  71. }
  72. else
  73. {
  74. // (localised)
  75. return KKey (TQt::CTRL + TQt::Key_Print).toString ();
  76. }
  77. }
  78. // private slot
  79. void kpMainWindow::slotHelpTakingScreenshots ()
  80. {
  81. #if DEBUG_KP_MAIN_WINDOW
  82. kdDebug () << "kpMainWindow::slotHelpTakingScreenshots()" << endl;
  83. #endif
  84. if (toolHasBegunShape ())
  85. tool ()->endShapeInternal ();
  86. // TODO: Totally bogus logic if twin not running under same user as KolourPaint.
  87. // SYNC: KWin contains PrintScreen key logic
  88. QCStringList dcopApps = TDEApplication::dcopClient ()->registeredApplications ();
  89. #if DEBUG_KP_MAIN_WINDOW
  90. kdDebug () << "\tdcopApps=" << dcopApps << endl;
  91. #endif
  92. bool isRunningKDE = (dcopApps.findIndex ("twin") >= 0);
  93. #if 0
  94. {
  95. int i = 0;
  96. FILE *fp = fopen ("/home/kdevel/kolourpaint.tmp", "rt");
  97. if (fp && fscanf (fp, "Hello: %d", &i) == 1)
  98. isRunningKDE = i, fclose (fp);
  99. }
  100. #endif
  101. TQString message;
  102. if (isRunningKDE)
  103. {
  104. message = i18n
  105. (
  106. "<p>"
  107. "To acquire a screenshot, press <b>%1</b>."
  108. " The screenshot will be placed into the clipboard"
  109. " and you will be able to paste it in KolourPaint."
  110. "</p>"
  111. "<p>"
  112. "You may configure the <b>Desktop Screenshot</b> shortcut"
  113. " in the Trinity Control Center"
  114. " module <a href=\"configure kde shortcuts\">Keyboard Shortcuts</a>."
  115. "</p>"
  116. "<p>Alternatively, you may try the application"
  117. " <a href=\"run ksnapshot\">KSnapshot</a>."
  118. "</p>"
  119. );
  120. }
  121. else
  122. {
  123. message = i18n
  124. (
  125. "<p>"
  126. "You do not appear to be running TDE."
  127. "</p>"
  128. // We tell them this much even though they aren't running KDE
  129. // to entice them to use KDE since it's so easy.
  130. "<p>"
  131. "Once you have loaded TDE:<br>"
  132. "<blockquote>"
  133. "To acquire a screenshot, press <b>%1</b>."
  134. " The screenshot will be placed into the clipboard"
  135. " and you will be able to paste it in KolourPaint."
  136. "</blockquote>"
  137. "</p>"
  138. "<p>Alternatively, you may try the application"
  139. " <a href=\"run ksnapshot\">KSnapshot</a>."
  140. "</p>"
  141. );
  142. }
  143. // TODO: Totally bogus logic if twin not running under same user as KolourPaint.
  144. message = message.arg (::printScreenShortcutString ());
  145. // Add extra vertical space
  146. message += "<p>&nbsp;</p>";
  147. KDialogBase dlg (this, "helpTakingScreenshotsDialog", true/*modal*/,
  148. i18n ("Acquiring Screenshots"),
  149. KDialogBase::Close, KDialogBase::Close/*default btn*/,
  150. true/*separator line*/);
  151. KActiveLabel *messageLabel = new KActiveLabel (message, &dlg);
  152. disconnect (messageLabel, TQT_SIGNAL (linkClicked (const TQString &)),
  153. messageLabel, TQT_SLOT (openLink (const TQString &)));
  154. connect (messageLabel, TQT_SIGNAL (linkClicked (const TQString &)),
  155. TQT_TQOBJECT(this), TQT_SLOT (slotHelpTakingScreenshotsFollowLink (const TQString &)));
  156. dlg.setMainWidget (messageLabel);
  157. dlg.exec ();
  158. }
  159. // private
  160. void kpMainWindow::slotHelpTakingScreenshotsFollowLink (const TQString &link)
  161. {
  162. #if DEBUG_KP_MAIN_WINDOW
  163. kdDebug () << "kpMainWindow::slotHelpTakingScreenshotsFollowLink("
  164. << link << ")" << endl;
  165. #endif
  166. if (link == "configure kde shortcuts")
  167. {
  168. KRun::runCommand ("tdecmshell keys");
  169. }
  170. else if (link == "run ksnapshot")
  171. {
  172. KRun::runCommand ("ksnapshot");
  173. }
  174. else
  175. {
  176. kdError () << "kpMainWindow::slotHelpTakingScreenshotsFollowLink("
  177. << link << ")" << endl;
  178. }
  179. }