KnowIt – tool for managing notes
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  1. /***************************************************************************
  2. knowit.cpp - description
  3. -------------------
  4. begin : czw wrz 26 08:27:40 CEST 2002
  5. copyright : (C) 2002-2004 by Micha� Rudolf
  6. email : mrudolf@tdewebdev.org
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include <tqtimer.h>
  17. #include <tqclipboard.h>
  18. #include <tqdatetime.h>
  19. #include <tqdir.h>
  20. #include <tqfile.h>
  21. #include <tqtextstream.h>
  22. #include <tqpainter.h>
  23. #include <tqpaintdevicemetrics.h>
  24. #include <tqwhatsthis.h>
  25. #include <tqsimplerichtext.h>
  26. #include <tqsplitter.h>
  27. #include <kaction.h>
  28. #include <kcmdlineargs.h>
  29. #include <kcolordialog.h>
  30. #include <tdeconfig.h>
  31. #include <tdeversion.h>
  32. #include <kedittoolbar.h>
  33. #include <tdefiledialog.h>
  34. #include <kkeydialog.h>
  35. #include <kmenubar.h>
  36. #include <kmessagebox.h>
  37. #include <kmimetype.h>
  38. #include <kpopupmenu.h>
  39. #include <kprinter.h>
  40. #include <kstatusbar.h>
  41. #include <ktip.h>
  42. #if KDE_IS_VERSION(3,2,0)
  43. #include <kinputdialog.h>
  44. #else
  45. #include <klineeditdlg.h>
  46. #define KInputDialog KLineEditDlg
  47. #endif
  48. #include "knowit.h"
  49. #include "knowitapp.h"
  50. #include "knowittray.h"
  51. #include "knowittree.h"
  52. #include "knowitlinks.h"
  53. const TQString Knowit::Untitled = i18n("untitled") + ".kno";
  54. Knowit::Knowit(TQWidget*, const char *name) : TDEMainWindow(0, name),
  55. FindDlg(), PrefDlg(), ChooserDlg(), LinkDlg(), Notes()
  56. {
  57. statusBar()->insertItem(i18n("Ready"), 0);
  58. Layout = new TQSplitter(this);
  59. Items = new KnowitTree(Layout, "Items");
  60. TQSplitter* EditLayout = new TQSplitter(Layout);
  61. EditLayout->setOrientation(Qt::Vertical);
  62. Edit = new KnowitEdit(EditLayout, "Edit");
  63. Links = new KnowitLinks(EditLayout);
  64. connect(&FindDlg, TQT_SIGNAL(search()), TQT_TQOBJECT(this), TQT_SLOT(slotEditFind()));
  65. lastSought = 0;
  66. /* main view */
  67. setAutoSaveSettings();
  68. setCentralWidget(Layout);
  69. TQWhatsThis::add(Layout, i18n("Move it to change tree/edit layout."));
  70. connect(Items, TQT_SIGNAL(contextMenu(TDEListView*, TQListViewItem*, const TQPoint&)),
  71. TQT_TQOBJECT(this), TQT_SLOT(slotContextMenu(TDEListView*, TQListViewItem*, const TQPoint&)));
  72. connect(Items, TQT_SIGNAL(selectionChanged(TQListViewItem*)), this,
  73. TQT_SLOT(slotItemChanged(TQListViewItem*)));
  74. connect(Items, TQT_SIGNAL(selectionChanged(TQListViewItem*)), this,
  75. TQT_SLOT(slotItemChanged(TQListViewItem*)));
  76. /* Edit (TQTextEdit) */
  77. Edit->setMinimumSize(200, 150);
  78. Edit->setTextFormat(TQt::RichText);
  79. TQWhatsThis::add(Edit, i18n("<h2>Note text</h2>Add text for selected note here.\n"
  80. "Text can be formatted, for example <b>bold</b> or <i>italic</i>."));
  81. connect(Edit, TQT_SIGNAL(selectionChanged()), TQT_TQOBJECT(this), TQT_SLOT(slotEditChanged()));
  82. connect(Edit, TQT_SIGNAL(textChanged()), TQT_TQOBJECT(this), TQT_SLOT(slotEditChanged()));
  83. connect(Edit, TQT_SIGNAL(cursorPositionChanged(int, int)), this,
  84. TQT_SLOT(slotEditCursorChanged(int, int)));
  85. connect(Edit, TQT_SIGNAL(textDropped(const TQString&, int)),
  86. TQT_TQOBJECT(this), TQT_SLOT(slotLinkDropped(const TQString&, int)));
  87. /* Links (TDEListBox) */
  88. connect(Links, TQT_SIGNAL(doubleClicked(TQListBoxItem*)),
  89. TQT_TQOBJECT(this), TQT_SLOT(slotShowAttachment(TQListBoxItem*)));
  90. connect(Links, TQT_SIGNAL(contextMenuRequested(TQListBoxItem*, const TQPoint&)),
  91. TQT_TQOBJECT(this), TQT_SLOT(slotContextLinksMenu(TQListBoxItem*, const TQPoint&)));
  92. connect(Links, TQT_SIGNAL(textDropped(const TQString&, int)),
  93. TQT_TQOBJECT(this), TQT_SLOT(slotLinkDropped(const TQString&, int)));
  94. connect(Links, TQT_SIGNAL(linkRemove()), TQT_TQOBJECT(this), TQT_SLOT(slotLinkRemove()));
  95. connect(Links, TQT_SIGNAL(linkOpen()), TQT_TQOBJECT(this), TQT_SLOT(slotLinkOpen()));
  96. connect(Links, TQT_SIGNAL(linkOpenWith()), TQT_TQOBJECT(this), TQT_SLOT(slotLinkOpenWith()));
  97. /* Actions: File */
  98. KStdAction::openNew(TQT_TQOBJECT(this), TQT_SLOT(slotFileNew()), actionCollection());
  99. KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(slotFileOpen()), actionCollection());
  100. actionRecent = KStdAction::openRecent(TQT_TQOBJECT(this), TQT_SLOT(slotFileRecent(const KURL&)), actionCollection());
  101. KStdAction::save(TQT_TQOBJECT(this), TQT_SLOT(slotFileSave()), actionCollection());
  102. KStdAction::saveAs(TQT_TQOBJECT(this), TQT_SLOT(slotFileSaveAs()), actionCollection());
  103. new TDEAction(i18n("&Export to HTML..."), "", "", TQT_TQOBJECT(this),
  104. TQT_SLOT(slotFileExport()), actionCollection(), "file_export_html");
  105. KStdAction::print(TQT_TQOBJECT(this), TQT_SLOT(slotFilePrint()), actionCollection());
  106. new TDEAction(i18n("Document &information..."), "", "", TQT_TQOBJECT(this),
  107. TQT_SLOT(slotFileInfo()), actionCollection(), "file_info");
  108. KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(slotFileQuit()), actionCollection());
  109. /* Actions: Edit */
  110. actionCut = KStdAction::cut(TQT_TQOBJECT(Edit), TQT_SLOT(cut()), actionCollection());
  111. actionCopy = KStdAction::copy(TQT_TQOBJECT(Edit), TQT_SLOT(copy()), actionCollection());
  112. KStdAction::paste(TQT_TQOBJECT(Edit), TQT_SLOT(paste()), actionCollection());
  113. actionUndo = KStdAction::undo(TQT_TQOBJECT(Edit), TQT_SLOT(undo()), actionCollection());
  114. actionRedo = KStdAction::redo(TQT_TQOBJECT(Edit), TQT_SLOT(redo()), actionCollection());
  115. actionBold = new TDEToggleAction(i18n("Toggle &bold"), "text_bold",
  116. "Ctrl+B", TQT_TQOBJECT(this), TQT_SLOT(slotEditBold()), actionCollection(), "edit_bold");
  117. actionItalic = new TDEToggleAction(i18n("Toggle &italic"), "text_italic",
  118. "Ctrl+I", TQT_TQOBJECT(this), TQT_SLOT(slotEditItalic()), actionCollection(),
  119. "edit_italic");
  120. actionUnderline = new TDEToggleAction(i18n("Toggle &underline"), "text_under",
  121. "Ctrl+U", TQT_TQOBJECT(this), TQT_SLOT(slotEditUnderline()), actionCollection(),
  122. "edit_underline");
  123. new TDEAction(i18n("&Text color..."), "color_line", "Ctrl+#", TQT_TQOBJECT(this),
  124. TQT_SLOT(slotEditColor()), actionCollection(), "edit_color");
  125. new TDEAction(i18n("&Superscript"), "text_super", "", TQT_TQOBJECT(this),
  126. TQT_SLOT(slotEditSuperscript()), actionCollection(), "edit_superscript");
  127. new TDEAction(i18n("&Subscript"), "text_sub", "", TQT_TQOBJECT(this),
  128. TQT_SLOT(slotEditSubscript()), actionCollection(), "edit_subscript");
  129. new TDEAction(i18n("&Normal text"), "", "", TQT_TQOBJECT(this),
  130. TQT_SLOT(slotEditNormal()), actionCollection(), "edit_align_normal");
  131. new TDEAction(i18n("&Bullet list"), "", "", TQT_TQOBJECT(this),
  132. TQT_SLOT(slotEditListBullet()), actionCollection(), "list_bullet");
  133. new TDEAction(i18n("&Numbered list"), "", "", TQT_TQOBJECT(this),
  134. TQT_SLOT(slotEditListNumber()), actionCollection(), "list_number");
  135. new TDEAction(i18n("&Uppercase list"), "", "", TQT_TQOBJECT(this),
  136. TQT_SLOT(slotEditListUpper()), actionCollection(), "list_upper");
  137. new TDEAction(i18n("&Lowercase list"), "", "", TQT_TQOBJECT(this),
  138. TQT_SLOT(slotEditListLower()), actionCollection(), "list_lower");
  139. new TDEAction(i18n("N&o list"), "", "", TQT_TQOBJECT(this),
  140. TQT_SLOT(slotEditListNone()), actionCollection(), "list_none");
  141. KStdAction::find(TQT_TQOBJECT(&FindDlg), TQT_SLOT(exec()), actionCollection());
  142. KStdAction::findNext(TQT_TQOBJECT(this), TQT_SLOT(slotEditFindNext()), actionCollection());
  143. new TDEAction(i18n("&Go to &note..."), "goto", "Ctrl+G", TQT_TQOBJECT(this),
  144. TQT_SLOT(slotEditGoTo()), actionCollection(), "goto_note");
  145. actionEditAlignLeft = new TDEToggleAction(i18n("Align &left"), "text_left", "Ctrl+L", TQT_TQOBJECT(this),
  146. TQT_SLOT(slotEditAlignLeft()), actionCollection(), "edit_align_left");
  147. actionEditAlignRight = new TDEToggleAction(i18n("Align &right"), "text_right", "Ctrl+R",
  148. TQT_TQOBJECT(this), TQT_SLOT(slotEditAlignRight()), actionCollection(), "edit_align_right");
  149. actionEditAlignJustify = new TDEToggleAction(i18n("&Justify"), "text_block", "Ctrl+J",
  150. TQT_TQOBJECT(this), TQT_SLOT(slotEditAlignJustify()), actionCollection(), "edit_align_justify");
  151. actionEditAlignCenter = new TDEToggleAction(i18n("&Center"), "text_center", "Ctrl+E", TQT_TQOBJECT(this),
  152. TQT_SLOT(slotEditAlignCenter()), actionCollection(), "edit_align_center");
  153. new TDEAction(i18n("Insert &date"), "date", "F5", TQT_TQOBJECT(this),
  154. TQT_SLOT(slotEditInsertDate()), actionCollection(), "edit_insert_date");
  155. new TDEAction(i18n("Insert &file..."), "", "", TQT_TQOBJECT(this),
  156. TQT_SLOT(slotEditInsertFile()), actionCollection(), "edit_insert_file");
  157. actionRawTextMode = new TDEToggleAction(i18n("&Raw Text Mode"),
  158. "source", "F10", TQT_TQOBJECT(this), TQT_SLOT(slotRawTextMode()),
  159. actionCollection(), "edit_raw_text");
  160. /* Actions: edit setup */
  161. actionCut->setEnabled(false);
  162. actionCopy->setEnabled(false);
  163. connect(Edit, TQT_SIGNAL(copyAvailable(bool)), actionCut, TQT_SLOT(setEnabled(bool)));
  164. connect(Edit, TQT_SIGNAL(copyAvailable(bool)), actionCopy, TQT_SLOT(setEnabled(bool)));
  165. connect(Edit, TQT_SIGNAL(undoAvailable(bool)), actionUndo, TQT_SLOT(setEnabled(bool)));
  166. connect(Edit, TQT_SIGNAL(redoAvailable(bool)), actionRedo, TQT_SLOT(setEnabled(bool)));
  167. /* Actions: notes */
  168. new TDEAction(i18n("&Add"), "", "Alt+Insert", TQT_TQOBJECT(this), TQT_SLOT(slotNoteAdd()),
  169. actionCollection(), "note_add");
  170. new TDEAction(i18n("Add &subnote"), "", "Alt+Shift+Insert", TQT_TQOBJECT(this),
  171. TQT_SLOT(slotNoteAddChild()), actionCollection(), "note_add_child");
  172. new TDEAction(i18n("&Delete"), "", "Alt+Delete", TQT_TQOBJECT(this),
  173. TQT_SLOT(slotNoteRemove()), actionCollection(), "note_delete");
  174. new TDEAction(i18n("&Rename"), "", "F2", TQT_TQOBJECT(this),
  175. TQT_SLOT(slotNoteRename()), actionCollection(), "note_rename");
  176. new TDEAction(i18n("E&xpand all"), "", "", TQT_TQOBJECT(Items),
  177. TQT_SLOT(slotExpandAll()), actionCollection(), "note_expand_all");
  178. new TDEAction(i18n("&Expand current"), "", "Alt++", TQT_TQOBJECT(Items),
  179. TQT_SLOT(slotExpand()), actionCollection(), "note_expand");
  180. new TDEAction(i18n("Co&llapse all"), "", "", TQT_TQOBJECT(Items),
  181. TQT_SLOT(slotCollapseAll()), actionCollection(), "note_collapse_all");
  182. new TDEAction(i18n("&Collapse current"), "", "Alt+-", TQT_TQOBJECT(Items),
  183. TQT_SLOT(slotCollapse()), actionCollection(), "note_collapse");
  184. new TDEAction(i18n("Move up"), "up", "Alt+Shift+Up", TQT_TQOBJECT(this),
  185. TQT_SLOT(slotNoteMoveUp()), actionCollection(), "note_move_up");
  186. new TDEAction(i18n("Move down"), "down", "Alt+Shift+Down", TQT_TQOBJECT(this),
  187. TQT_SLOT(slotNoteMoveDown()), actionCollection(), "note_move_down");
  188. new TDEAction(i18n("Move level up"), "back", "Alt+Shift+Left", TQT_TQOBJECT(this),
  189. TQT_SLOT(slotNoteMoveLeft()), actionCollection(), "note_move_left");
  190. new TDEAction(i18n("Move level down"), "forward", "Alt+Shift+Right", TQT_TQOBJECT(this),
  191. TQT_SLOT(slotNoteMoveRight()), actionCollection(), "note_move_right");
  192. new TDEAction(i18n("Move at the beginning"), "top", "Alt+Shift+Home", TQT_TQOBJECT(this),
  193. TQT_SLOT(slotNoteMoveBegin()), actionCollection(), "note_move_begin");
  194. new TDEAction(i18n("Move at the end"), "bottom", "Alt+Shift+End", TQT_TQOBJECT(this),
  195. TQT_SLOT(slotNoteMoveEnd()), actionCollection(), "note_move_end");
  196. new TDEAction(i18n("Sort"), "", "", TQT_TQOBJECT(this),
  197. TQT_SLOT(slotNoteSort()), actionCollection(), "note_sort");
  198. /* Actions: Links */
  199. new TDEAction(i18n("&Add link..."), "attach", "Ctrl+Shift+I", TQT_TQOBJECT(this),
  200. TQT_SLOT(slotLinkAdd()), actionCollection(), "link_add");
  201. new TDEAction(i18n("&Remove link"), "", "", TQT_TQOBJECT(this),
  202. TQT_SLOT(slotLinkRemove()), actionCollection(), "link_remove");
  203. new TDEAction(i18n("Open link"), "run", "", TQT_TQOBJECT(this),
  204. TQT_SLOT(slotLinkOpen()), actionCollection(), "link_open");
  205. new TDEAction(i18n("Open link with..."), "", "", TQT_TQOBJECT(this),
  206. TQT_SLOT(slotLinkOpenWith()), actionCollection(), "link_open_with");
  207. new TDEAction(i18n("&Modify link..."), "", "", TQT_TQOBJECT(this),
  208. TQT_SLOT(slotLinkModify()), actionCollection(), "link_modify");
  209. new TDEAction(i18n("&Copy link location"), "", "", TQT_TQOBJECT(this),
  210. TQT_SLOT(slotLinkCopy()), actionCollection(), "link_copy");
  211. /* Actions: Options */
  212. KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(slotOptionsKeys()), actionCollection());
  213. KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotOptionsToolbar()), actionCollection());
  214. KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotOptions()), actionCollection());
  215. /* Actions: Help */
  216. new TDEAction(i18n("&Tip of the day"), "idea", "", TQT_TQOBJECT(this),
  217. TQT_SLOT(slotHelpTip()), actionCollection(), "help_tip");
  218. /* Actions: nonplugged */
  219. new TDEAction(i18n("Minimize"), "", "", TQT_TQOBJECT(this), TQT_SLOT(showMinimized()),
  220. actionCollection(), "window_minimize");
  221. new TDEAction(i18n("Switch area"), "", "Ctrl+M", TQT_TQOBJECT(this),
  222. TQT_SLOT(slotEditSwitch()), actionCollection(), "edit_switch");
  223. new TDEAction(i18n("Overwrite Mode"), "", "Insert", TQT_TQOBJECT(this),
  224. TQT_SLOT(slotOverwriteModeChange()), actionCollection(), "overwrite_mode_change");
  225. new TDEAction(i18n("Go to previous note"), "", "Alt+Up", TQT_TQOBJECT(Items),
  226. TQT_SLOT(slotItemUp()), actionCollection(), "note_previous");
  227. new TDEAction(i18n("Go to next note"), "", "Alt+Down", TQT_TQOBJECT(Items),
  228. TQT_SLOT(slotItemDown()), actionCollection(), "note_next");
  229. new TDEAction(i18n("Go to first note"), "", "Alt+Home", TQT_TQOBJECT(Items),
  230. TQT_SLOT(slotItemBegin()), actionCollection(), "note_begin");
  231. new TDEAction(i18n("Go to last note"), "", "Alt+End", TQT_TQOBJECT(Items),
  232. TQT_SLOT(slotItemEnd()), actionCollection(), "note_end");
  233. new TDEAction(i18n("Go to first subnote"), "", "Alt+Right", TQT_TQOBJECT(Items),
  234. TQT_SLOT(slotItemRight()), actionCollection(), "note_right");
  235. new TDEAction(i18n("Go to parent note"), "", "Alt+Left", TQT_TQOBJECT(Items),
  236. TQT_SLOT(slotItemLeft()), actionCollection(), "note_left");
  237. /* Actions */
  238. #if TDE_VERSION_MAJOR >= 3 && TDE_VERSION_MINOR >= 1
  239. setStandardToolBarMenuEnabled(true);
  240. #endif
  241. createGUI("knowitui.rc", false);
  242. /* Insert/overwrite mode */
  243. statusBar()->insertFixedItem(("WWW"), StatusOvr, true);
  244. statusBar()->changeItem(i18n("INS"), StatusOvr);
  245. connect(statusBar(), TQT_SIGNAL(pressed(int)), this,
  246. TQT_SLOT(slotOverwriteModeChange(int)));
  247. /* System tray */
  248. systray = new KnowitTray(this, "Systray");
  249. systray->setPixmap(Notes.Pixmaps[1]);
  250. systray->setAlignment(TQt::AlignHCenter | TQt::AlignVCenter);
  251. /* Autosave */
  252. AutosaveTimer = new TQTimer(this);
  253. connect(AutosaveTimer, TQT_SIGNAL(timeout()), TQT_TQOBJECT(this), TQT_SLOT(slotFileAutosave()));
  254. /* Configuration */
  255. config = kapp->config();
  256. readOptions();
  257. if (runMinimized)
  258. showMinimized();
  259. else
  260. show();
  261. bool opened = false;
  262. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  263. for(int i = 0; i < args->count(); i++)
  264. if (open(args->url(i))) {
  265. opened = true; break;
  266. }
  267. args->clear();
  268. if (!opened && Options.reopen && filename.path() != "")
  269. open(KURL(filename));
  270. slotActionUpdate();
  271. KTipDialog::showTip(this);
  272. shuttingDown = false;
  273. applyMainWindowSettings(config);
  274. /* check if knowituirc was found */
  275. TQWidget *w = factory()->container("notes_popup", this);
  276. if (!w)
  277. KMessageBox::error(0, i18n("<qt><p>Cannot open resource file <b>knowitui.rc</b>. "
  278. "Some of the menus and toolbars will be missing.</p>"
  279. "<p>Probably Knowit was not installed properly. "
  280. "If you installed from source, please invoke <i>make install</i>."
  281. "If you use precompiled package, please contact packager.</p></qt>"));
  282. }
  283. Knowit::~Knowit()
  284. {
  285. delete systray;
  286. delete AutosaveTimer;
  287. }
  288. bool Knowit::open(const KURL& fname)
  289. {
  290. TQFile file(fname.path());
  291. if (!file.open(IO_ReadOnly)) {
  292. KMessageBox::error(0, i18n("<qt>Cannot open file<br><b>%1</b></qt>")
  293. .arg(fname.url()));
  294. if (filename == fname)
  295. filename = "";
  296. return false;
  297. }
  298. uint prevdepth = 0;
  299. reset();
  300. TQTextStream ts(&file);
  301. ts.setEncoding(TQTextStream::UnicodeUTF8);
  302. TQString s = "";
  303. TQListViewItem* current = 0;
  304. TQListViewItem* active = 0;
  305. Notes.autoUpdate = false;
  306. while (!s.isNull()) {
  307. s = ts.readLine();
  308. if (s.left(9) == "\\NewEntry" || s.left(13) == "\\CurrentEntry") {
  309. TQString name;
  310. uint depth;
  311. TQTextIStream ls(&s);
  312. ls >> name >> depth;
  313. name = ls.readLine();
  314. name = name.stripWhiteSpace();
  315. if (depth == prevdepth) /* same level */
  316. if (depth) current = new TDEListViewItem(current->parent(), current, name);
  317. else current = new TDEListViewItem(Items, current, name);
  318. else if (depth > prevdepth) /* subnote */
  319. current = new TDEListViewItem(current, name);
  320. else { /* parent note */
  321. for(uint i=depth; i<prevdepth && current; i++)
  322. current = current->parent();
  323. if (current && current->parent())
  324. current = new TDEListViewItem(current->parent(), current, name);
  325. else current = new TDEListViewItem(Items, current, name);
  326. }
  327. prevdepth = depth;
  328. Notes.addNote(current);
  329. Notes.find(current)->open(ts);
  330. if (s.left(13) == "\\CurrentEntry")
  331. active = current;
  332. }
  333. }
  334. Notes.autoUpdate = true;
  335. Notes.updateNotesView();
  336. filename = fname;
  337. setCaption(fname.fileName());
  338. Notes.modified = false;
  339. Edit->clear();
  340. slotNoteChanged(active);
  341. Edit->setModified(false);
  342. actionRecent->addURL(filename);
  343. slotStatusMsg(i18n("File %1 opened.").arg(filename.fileName()));
  344. slotActionUpdate();
  345. file.close();
  346. if (Options.backup)
  347. URLOperator.copy(fname.path(), fname.path() + "~", false, false);
  348. if (Options.autosave)
  349. AutosaveTimer->start(Options.autosave * 60 * 1000, true);
  350. return true;
  351. }
  352. bool Knowit::save(const KURL& fname)
  353. {
  354. TQFile file(fname.path());
  355. if (!file.open(IO_WriteOnly)) {
  356. KMessageBox::error(0, i18n("<qt>Cannot save file<br><b>%1</b></qt>")
  357. .arg(fname.url()));
  358. return false;
  359. }
  360. if (Items->prevItem && Edit->isModified())
  361. Notes.changeNote(Items->prevItem, Edit->length() ? Edit->text() : TQString());
  362. TQTextStream ts(&file);
  363. ts.setEncoding(TQTextStream::UnicodeUTF8);
  364. for (TQListViewItemIterator it(Items); it.current(); it++)
  365. Notes.find(it.current())->save(ts, it.current() == Items->currentItem());
  366. filename = fname;
  367. setCaption(fname.fileName());
  368. Notes.modified = false;
  369. Edit->setModified(false);
  370. actionRecent->addURL(filename);
  371. slotStatusMsg(i18n("File %1 saved.").arg(filename.fileName()));
  372. if (Options.autosave)
  373. AutosaveTimer->start(Options.autosave * 60 * 1000, true);
  374. return true;
  375. }
  376. void Knowit::reset()
  377. {
  378. Items->prevItem = 0;
  379. Notes.clearNotes();
  380. Items->clear();
  381. Edit->clear();
  382. filename = "";
  383. setCaption(Untitled);
  384. Notes.modified = false;
  385. slotActionUpdate();
  386. }
  387. void Knowit::closeEvent(TQCloseEvent* e)
  388. {
  389. if (!Options.docked || ((KnowitApplication*)kapp)->closeByLogout()) {
  390. saveOptions();
  391. TDEMainWindow::closeEvent(e);
  392. }
  393. else
  394. hide();
  395. }
  396. bool Knowit::queryClose()
  397. {
  398. if (!modified()) return shuttingDown = true;
  399. else if (Options.unconditionalSave) {
  400. slotFileSave();
  401. return shuttingDown = filename.isEmpty() || !modified() || (KMessageBox::questionYesNo(0,
  402. i18n("<qt>File <b>%1</b><br>\ncannot be saved. Quit anyway?</qt>").arg(filename.fileName()))
  403. == KMessageBox::Yes);
  404. }
  405. else
  406. switch (KMessageBox::questionYesNoCancel(0,
  407. i18n("<qt>File <b>%1</b><br>\nwas modified. Do you want to save it?</qt>")
  408. .arg(filename.isEmpty() ? Untitled : filename.fileName()))) {
  409. case KMessageBox::Yes:
  410. slotFileSave();
  411. return shuttingDown = !modified();
  412. case KMessageBox::No:
  413. return shuttingDown = true;
  414. default:
  415. return false;
  416. }
  417. }
  418. bool Knowit::queryExit()
  419. {
  420. if (!shuttingDown) {
  421. /* brutally closed by session manager */
  422. if (modified())
  423. save(filename.isEmpty() ? i18n("untitled.kno") : filename);
  424. saveOptions();
  425. }
  426. return true;
  427. }
  428. void Knowit::find(TQListViewItem* start)
  429. {
  430. if (soughtText.isEmpty() || !Items->firstChild()) return;
  431. if (start && lastSought == start &&
  432. Edit->find(soughtText, FindDlg.case_sensitive(), false))
  433. return;
  434. if (!start) start = Items->firstChild();
  435. TQListViewItemIterator it(start);
  436. while (it.current()) {
  437. TQString s = Notes.text(it.current());
  438. if (lastSought != it.current() &&
  439. s.contains(soughtText, FindDlg.case_sensitive())) {
  440. slotNoteChanged(it.current());
  441. Edit->find(soughtText, FindDlg.case_sensitive(), false);
  442. lastSought = it.current();
  443. return;
  444. }
  445. it++;
  446. }
  447. KMessageBox::information(0, i18n("<qt>Sought text:<br><b>%1</b><br>not found.</qt>").arg(soughtText));
  448. }
  449. void Knowit::saveOptions()
  450. {
  451. config->setGroup("MainWindow");
  452. config->writeEntry("Widgets", Layout->sizes());
  453. Options.save(config);
  454. config->setGroup("General");
  455. config->writeEntry("Minimized", isMinimized() || !isVisible());
  456. config->writeEntry("LastFile", filename.path());
  457. config->writeEntry("Geometry", size());
  458. actionCollection()->writeShortcutSettings("Keys", config);
  459. config->deleteGroup("Recent Files");
  460. actionRecent->saveEntries(config, "Recent Files");
  461. saveMainWindowSettings(config);
  462. }
  463. void Knowit::readOptions()
  464. {
  465. config->setGroup("MainWindow");
  466. TQValueList<int> sizes = config->readIntListEntry("Widgets");
  467. if (sizes.count() == 2)
  468. Layout->setSizes(sizes);
  469. Options.read(config);
  470. config->setGroup("General");
  471. runMinimized = config->readBoolEntry("Minimized", false);
  472. TQString oldfile = config->readEntry("LastFile");
  473. TQSize defSize = size();
  474. resize(config->readSizeEntry("Geometry", &defSize));
  475. actionCollection()->readShortcutSettings("Keys", config);
  476. actionRecent->loadEntries(config,"Recent Files");
  477. if (!oldfile.isEmpty())
  478. filename = KURL(oldfile);
  479. applyOptions(Options);
  480. }
  481. void Knowit::slotNoteChanged(TQListViewItem* item)
  482. {
  483. if (item) {
  484. if (Options.autoCollapse)
  485. Items->slotCollapseAll();
  486. Items->setCurrentItem(item);
  487. Items->setSelected(item, true);
  488. Items->ensureItemVisible(item);
  489. }
  490. }
  491. bool Knowit::modified()
  492. {
  493. return Notes.modified || (Items->currentItem() && Edit->isModified());
  494. }
  495. void Knowit::applyOptions(const KnowitOptions& O, bool store)
  496. {
  497. if (store) Options = O;
  498. if (O.docked)
  499. systray->show();
  500. else
  501. systray->hide();
  502. if (O.customColors) {
  503. Edit->setPaletteForegroundColor(TQColor(Options.foreEditColor));
  504. Edit->setPaletteBackgroundColor(TQColor(Options.backEditColor));
  505. }
  506. else Edit->unsetPalette();
  507. if (Options.customFont)
  508. Edit->setFont(TQFont(Options.fontFamily, Options.fontSize));
  509. else
  510. Edit->unsetFont();
  511. Edit->setWordWrap(O.wordwrap ? TQTextEdit::WidgetWidth : TQTextEdit::NoWrap);
  512. #if TDE_VERSION_MAJOR >= 3 && TDE_VERSION_MINOR >= 1
  513. Edit->setTabChangesFocus(O.tabfocus);
  514. #endif
  515. if (!O.autosave)
  516. AutosaveTimer->stop();
  517. else
  518. AutosaveTimer->start(O.autosave * 60 * 1000, true);
  519. Edit->swapEOL = O.enterBreakLine;
  520. Layout->setOrientation(O.horizontalSplit ? Qt::Horizontal :
  521. Qt::Vertical);
  522. Items->setAlternateBackground(O.alternateTree ? TQColor(O.alternateColor) : TQColor());
  523. Items->repaintContents();
  524. if (Items->currentItem())
  525. slotItemChanged(Items->currentItem());
  526. slotNoteChanged(Items->currentItem());
  527. }
  528. TNote* Knowit::currentNote() const
  529. {
  530. if (!Items->currentItem()) return 0;
  531. return Notes.find(Items->currentItem());
  532. }
  533. /*** Slots ***/
  534. void Knowit::slotStatusMsg(const TQString &text)
  535. {
  536. statusBar()->clear();
  537. statusBar()->changeItem(text, 0);
  538. }
  539. void Knowit::slotContextMenu(TDEListView*, TQListViewItem*, const TQPoint& p)
  540. {
  541. TQWidget *w = factory()->container("notes_popup", this);
  542. if (w)
  543. static_cast<TQPopupMenu *>(w)->exec(p);
  544. }
  545. void Knowit::slotContextLinksMenu(TQListBoxItem*, const TQPoint& p)
  546. {
  547. TQWidget *w = factory()->container("links_popup", this);
  548. if (w)
  549. static_cast<TQPopupMenu *>(w)->exec(p);
  550. }
  551. /******* Slots: Notes *******/
  552. void Knowit::slotNoteAdd()
  553. {
  554. bool Ok;
  555. TDEListViewItem* elt;
  556. TQString text = KInputDialog::getText(i18n("Add note"),
  557. i18n("Note title:"), Options.defaultName, &Ok);
  558. if (!Ok) return;
  559. if (Items->currentItem())
  560. if (Items->currentItem()->parent())
  561. elt = new TDEListViewItem(Items->currentItem()->parent(),
  562. Items->currentItem(), text);
  563. else
  564. elt = new TDEListViewItem(Items, Items->currentItem(), text);
  565. else
  566. elt = new TDEListViewItem(Items, text);
  567. Notes.addNote(elt);
  568. slotNoteChanged(elt);
  569. if (Notes.count() == 1)
  570. slotActionUpdate();
  571. }
  572. void Knowit::slotNoteAddChild()
  573. {
  574. if (!Items->currentItem()) {
  575. KMessageBox::error(0, i18n("You have to choose note before adding subnote."));
  576. return;
  577. }
  578. bool Ok;
  579. TQString text = KInputDialog::getText(i18n("Add subnote"),
  580. i18n("Note title:"), Options.defaultName, &Ok);
  581. if (!Ok) return;
  582. TQListViewItem* lastChild = Items->currentItem()->firstChild();
  583. while (lastChild && lastChild->nextSibling())
  584. lastChild = lastChild->nextSibling();
  585. TDEListViewItem* elt;
  586. if (lastChild)
  587. elt = new TDEListViewItem(Items->currentItem(), lastChild, text);
  588. else
  589. elt = new TDEListViewItem(Items->currentItem(), text);
  590. Notes.addNote(elt);
  591. slotNoteChanged(elt);
  592. }
  593. void Knowit::slotNoteRemove()
  594. {
  595. TQListViewItem* elt = Items->currentItem();
  596. if (!elt) return;
  597. TQString msg = elt->childCount() ?
  598. i18n("<qt>Are you sure you want to delete note<br><b>%1</b><br> "
  599. "and its subnotes?</qt>") :
  600. i18n("<qt>Are you sure you want to delete note<br><b>%1</b>?</qt>");
  601. if (KMessageBox::questionYesNo(0, msg.arg(elt->text(0))) == KMessageBox::Yes) {
  602. TQListViewItem* parent = elt->parent();
  603. Notes.removeNote(elt);
  604. if (!Notes.count())
  605. slotActionUpdate();
  606. if (!parent)
  607. parent = Items->firstChild();
  608. Items->prevItem = 0;
  609. slotNoteChanged(parent);
  610. }
  611. }
  612. void Knowit::slotNoteRename()
  613. {
  614. if (Items->currentItem()) {
  615. Items->currentItem()->setRenameEnabled(0, true);
  616. Items->currentItem()->startRename(0);
  617. }
  618. }
  619. void Knowit::slotItemChanged(TQListViewItem* i)
  620. {
  621. if (Items->prevItem && Edit->isModified())
  622. Notes.changeNote(Items->prevItem, Edit->length() ? Edit->text() : TQString());
  623. Items->prevItem = i;
  624. TQString s;
  625. if (!Items->prevItem || (s = Notes.text(Items->prevItem)).isEmpty())
  626. Edit->setText("");
  627. else
  628. Edit->setText(s);
  629. Edit->setModified(false);
  630. Links->clear();
  631. TNote* note = Notes.find(i);
  632. if (note)
  633. for (int j=0; j<note->linkCount(); j++)
  634. Links->insertItem(note->link(j).icon(), note->link(j).text(Options.linkFormat));
  635. if (Links->count())
  636. Links->show();
  637. else
  638. Links->hide();
  639. }
  640. void Knowit::slotNoteMoveUp()
  641. {
  642. TQListViewItem* elt = Items->currentItem();
  643. if (elt && elt->itemAbove()) {
  644. TQListViewItem* above = elt->parent() ? elt->parent()->firstChild()
  645. : Items->firstChild();
  646. if (above == elt)
  647. return;
  648. if (!above->nextSibling() || above->nextSibling() == elt)
  649. above = 0;
  650. else while (above->nextSibling()->nextSibling() != elt)
  651. above = above->nextSibling();
  652. if (above)
  653. elt->moveItem(above);
  654. else {
  655. TQListViewItem* parent = elt->parent();
  656. Items->takeNode(elt);
  657. Items->insertNode(parent, elt);
  658. }
  659. slotNoteChanged(elt);
  660. Notes.modified = true;
  661. }
  662. }
  663. void Knowit::slotNoteMoveDown()
  664. {
  665. TQListViewItem* elt = Items->currentItem();
  666. if (elt && elt->nextSibling()) {
  667. elt->moveItem(elt->nextSibling());
  668. slotNoteChanged(elt);
  669. Notes.modified = true;
  670. }
  671. }
  672. void Knowit::slotNoteMoveBegin()
  673. {
  674. TQListViewItem* elt = Items->currentItem();
  675. if (elt) {
  676. TQListViewItem* parent = elt->parent();
  677. Items->takeNode(elt);
  678. Items->insertItem(elt);
  679. if (parent)
  680. Notes.find(parent)->updateView();
  681. slotNoteChanged(elt);
  682. Notes.modified = true;
  683. }
  684. }
  685. void Knowit::slotNoteMoveEnd()
  686. {
  687. TQListViewItem* elt = Items->currentItem();
  688. if (!elt)
  689. return;
  690. TQListViewItem* last = Items->firstChild();
  691. TQListViewItem* parent = elt->parent();
  692. while (last->nextSibling())
  693. last = last->nextSibling();
  694. if (elt && elt != last) {
  695. Items->takeNode(elt);
  696. Items->insertNode(0, elt, last);
  697. slotNoteChanged(elt);
  698. if (parent)
  699. Notes.find(parent)->updateView();
  700. Notes.modified = true;
  701. }
  702. }
  703. void Knowit::slotNoteMoveLeft()
  704. {
  705. TQListViewItem* elt = Items->currentItem();
  706. TQListViewItem* parent = elt->parent();
  707. if (elt && parent) {
  708. Items->takeNode(elt);
  709. Items->insertNode(parent->parent(), elt, parent);
  710. Notes.find(parent)->updateView();
  711. slotNoteChanged(elt);
  712. Notes.modified = true;
  713. }
  714. }
  715. void Knowit::slotNoteMoveRight()
  716. {
  717. TQListViewItem* elt = Items->currentItem();
  718. TQListViewItem* above = elt->itemAbove();
  719. if (elt && above) {
  720. if (above->depth() < elt->depth())
  721. return;
  722. else if (above->depth() == elt->depth()) {
  723. Items->takeNode(elt);
  724. Items->insertNode(above, elt);
  725. }
  726. else {
  727. while (above->depth() > elt->depth()+1)
  728. above = above->parent();
  729. Items->takeNode(elt);
  730. Items->insertNode(above->parent(), elt, above);
  731. }
  732. Notes.find(above)->updateView();
  733. slotNoteChanged(elt);
  734. Notes.modified = true;
  735. }
  736. }
  737. void Knowit::slotNoteSort()
  738. {
  739. if (Items->currentItem()) {
  740. Items->currentItem()->sortChildItems(0, true);
  741. Items->repaintContents();
  742. }
  743. }
  744. void Knowit::slotFileNew()
  745. {
  746. if (queryClose()) reset();
  747. }
  748. void Knowit::slotFileOpen()
  749. {
  750. if (!queryClose()) return;
  751. KURL url=KFileDialog::getOpenURL(TQString(),
  752. i18n("*.kno|KnowIt files (*.kno)\n*|All files"), this, i18n("Open File..."));
  753. if (!url.isEmpty())
  754. open(url);
  755. }
  756. void Knowit::slotFileSave()
  757. {
  758. if (filename.isEmpty())
  759. slotFileSaveAs();
  760. else {
  761. save(filename);
  762. }
  763. }
  764. void Knowit::slotFileAutosave()
  765. {
  766. if (modified())
  767. slotFileSave();
  768. if (modified()) { /* file wasn't saved */
  769. KMessageBox::sorry(0, i18n("<qt><p>File couldn not be saved automatically."
  770. "<p>Autosaving disabled - save file manually to turn autosaving on.</p></qt>"));
  771. AutosaveTimer->stop();
  772. }
  773. }
  774. void Knowit::slotFileRecent(const KURL& url)
  775. {
  776. if (queryClose())
  777. if (!open(url))
  778. actionRecent->removeURL(url);
  779. }
  780. void Knowit::slotFileSaveAs()
  781. {
  782. KURL url=KFileDialog::getSaveURL(TQDir::currentDirPath(),
  783. i18n("*.kno|KnowIt files (*.kno)\n*|All files"), this, i18n("Save as..."));
  784. if (!url.isEmpty()) {
  785. if (!url.fileName().contains('.'))
  786. url = KURL(url.path() + ".kno");
  787. TQFileInfo fileinfo(url.path());
  788. if (fileinfo.exists() && KMessageBox::questionYesNo(0,
  789. i18n("<qt>File<br><b>%1</b><br>already exists. Overwrite it?</qt>")
  790. .arg(url.path())) == KMessageBox::No)
  791. return;
  792. save(url);
  793. }
  794. }
  795. void Knowit::slotFileInfo()
  796. {
  797. int count = 0;
  798. TQListViewItemIterator it(Items);
  799. while (it.current()) {
  800. count++;
  801. it++;
  802. }
  803. KMessageBox::information(0, i18n("<qt><h1>%1</h1>"
  804. "Document path: %2<br>"
  805. "Number of notes: %3</qt>").arg(filename.fileName())
  806. .arg(filename.path()).arg(count));
  807. }
  808. void Knowit::slotFilePrint()
  809. {
  810. KPrinter printer;
  811. printer.setFullPage(true);
  812. if (Edit->text().stripWhiteSpace().isEmpty() || !printer.setup(this))
  813. return;
  814. TQSimpleRichText richText(Edit->text(), Edit->font());
  815. TQPainter p(&printer);
  816. TQPaintDeviceMetrics metrics(p.device());
  817. int dpix = metrics.logicalDpiX();
  818. int dpiy = metrics.logicalDpiY();
  819. const int margin = 72; // pt
  820. TQRect body(margin*dpix / 72, margin*dpiy / 72,
  821. metrics.width()- margin*dpix /72*2,
  822. metrics.height()-margin*dpiy/72*2);
  823. richText.setWidth(&p, body.width());
  824. TQRect view(body);
  825. int page = 1;
  826. while (true) {
  827. richText.draw(&p, body.left(), body.top(), view, colorGroup());
  828. view.moveBy(0, body.height());
  829. p.translate( 0 , -body.height());
  830. p.setFont(Edit->font());
  831. p.drawText( view.right() - p.fontMetrics().width( TQString::number(page)),
  832. view.bottom() + p.fontMetrics().ascent() + 5, TQString::number(page));
  833. if (view.top() >= body.top() + richText.height())
  834. break;
  835. printer.newPage();
  836. page++;
  837. }
  838. }
  839. void Knowit::slotFileQuit()
  840. {
  841. if (queryClose()) {
  842. saveOptions();
  843. kapp->quit();
  844. }
  845. }
  846. void Knowit::slotFileExport()
  847. {
  848. if (!Items->firstChild()) return; /* nothing to export */
  849. ChooserDlg.setChoice(Options.exportFlags);
  850. if (ChooserDlg.exec() != TQDialog::Accepted) return; /* cancelled */
  851. /* Deduce filename from Knowit document name */
  852. TQString htmlfile;
  853. if (filename.isValid()) {
  854. htmlfile = filename.path();
  855. if (htmlfile.right(4) == ".kno")
  856. htmlfile = htmlfile.left(htmlfile.length() - 4) + ".html";
  857. else htmlfile = "";
  858. }
  859. if (htmlfile.isEmpty())
  860. htmlfile == TQDir::currentDirPath();
  861. /* Confirm/choose filename */
  862. KURL url=KFileDialog::getSaveURL(htmlfile,
  863. i18n("*.html|HTML files (*.html)\n*|All files"), this, i18n("Export to HTML"));
  864. if (!url.isEmpty()) {
  865. if (!url.fileName().contains('.'))
  866. url = KURL(url.path() + ".html");
  867. TQFileInfo fileinfo(url.path());
  868. if (fileinfo.exists() && KMessageBox::questionYesNo(0,
  869. i18n("<qt>File<br><b>%1</b><br>already exists. Overwrite it?</qt>")
  870. .arg(url.path())) == KMessageBox::No)
  871. return;
  872. int choice = ChooserDlg.getChoice();
  873. TQListViewItem* start = (choice & KnowitChooser::SaveAll) ?
  874. Items->firstChild() : Items->currentItem();
  875. TQString origname = filename.isEmpty() ? Untitled : filename.path();
  876. TQString style;
  877. if (choice & KnowitChooser::Style)
  878. style = TQString("body {font-family: \"%1\"; color: %2; background-color: %3}")
  879. .arg(Edit->family()).arg(Edit->paletteForegroundColor().name())
  880. .arg(Edit->paletteBackgroundColor().name());
  881. Notes.find(start)->saveHTML(url, origname, style, choice);
  882. Options.exportFlags = choice;
  883. }
  884. }
  885. void Knowit::slotEditBold()
  886. {
  887. Edit->setBold(actionBold->isChecked());
  888. }
  889. void Knowit::slotEditItalic()
  890. {
  891. Edit->setItalic(actionItalic->isChecked());
  892. }
  893. void Knowit::slotEditUnderline()
  894. {
  895. Edit->setUnderline(actionUnderline->isChecked());
  896. }
  897. void Knowit::slotEditColor()
  898. {
  899. TQColor color = Edit->color();
  900. if (KColorDialog::getColor(color) == TQDialog::Accepted)
  901. Edit->setColor(color);
  902. }
  903. void Knowit::slotEditSuperscript()
  904. {
  905. Edit->setVerticalAlignment(TQTextEdit::AlignSuperScript);
  906. }
  907. void Knowit::slotEditSubscript()
  908. {
  909. Edit->setVerticalAlignment(TQTextEdit::AlignSubScript);
  910. }
  911. void Knowit::slotEditNormal()
  912. {
  913. Edit->setVerticalAlignment(TQTextEdit::AlignNormal);
  914. }
  915. void Knowit::slotEditAlignLeft()
  916. {
  917. Edit->setAlignment(TQt::AlignLeft);
  918. }
  919. void Knowit::slotEditAlignRight()
  920. {
  921. Edit->setAlignment(TQt::AlignRight);
  922. }
  923. void Knowit::slotEditAlignJustify()
  924. {
  925. Edit->setAlignment(TQt::AlignJustify);
  926. }
  927. void Knowit::slotEditAlignCenter()
  928. {
  929. Edit->setAlignment(TQt::AlignCenter);
  930. }
  931. void Knowit::slotEditListBullet()
  932. {
  933. Edit->setParagType(TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListDisc);
  934. }
  935. void Knowit::slotEditListNumber()
  936. {
  937. Edit->setParagType(TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListDecimal);
  938. }
  939. void Knowit::slotEditListUpper()
  940. {
  941. Edit->setParagType(TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListUpperAlpha);
  942. }
  943. void Knowit::slotEditListLower()
  944. {
  945. Edit->setParagType(TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListLowerAlpha);
  946. }
  947. void Knowit::slotEditListNone()
  948. {
  949. Edit->setParagType(TQStyleSheetItem::DisplayBlock, TQStyleSheetItem::ListDisc);
  950. }
  951. void Knowit::slotEditFind()
  952. {
  953. if (soughtText != FindDlg.getText()) {
  954. soughtText = FindDlg.getText();
  955. lastSought = 0;
  956. find();
  957. }
  958. else
  959. find(Items->currentItem());
  960. }
  961. void Knowit::slotEditFindNext()
  962. {
  963. if (soughtText.isEmpty()) FindDlg.exec();
  964. find(Items->currentItem());
  965. }
  966. void Knowit::slotEditGoTo()
  967. {
  968. bool Ok;
  969. TQString page = KInputDialog::getText(i18n("Go to"),
  970. i18n("Go to page with given title"), "", &Ok);
  971. if (Ok && !page.isEmpty()) {
  972. TQListViewItem* item = Items->findItem(page, 0);
  973. if (!item) item = Items->findItem(page, 0, TQt::ExactMatch);
  974. if (!item) item = Items->findItem(page, 0, TQt::Contains);
  975. slotNoteChanged(item);
  976. }
  977. }
  978. void Knowit::slotEditInsertDate()
  979. {
  980. if (Items->currentItem()) {
  981. bool ib = actionBold->isChecked(), ii=actionItalic->isChecked(), iu=actionUnderline->isChecked();
  982. TQColor color = Edit->color();
  983. Edit->setItalic(Options.insertDateItalic);
  984. Edit->setBold(Options.insertDateBold);
  985. Edit->setUnderline(Options.insertDateUnderline);
  986. Edit->setColor(TQColor(Options.insertDateColor));
  987. Edit->insert(TQString("%1")
  988. .arg(TQDateTime::currentDateTime().toString(Options.insertDateFormat)));
  989. Edit->setItalic(ii);
  990. Edit->setBold(ib);
  991. Edit->setUnderline(iu);
  992. Edit->setColor(color);
  993. }
  994. }
  995. void Knowit::slotEditInsertFile()
  996. {
  997. if (!Items->currentItem())
  998. return;
  999. KURL url=KFileDialog::getOpenURL(TQString(),
  1000. i18n("*|All files"), this, i18n("Insert file..."));
  1001. if (url.isEmpty())
  1002. return;
  1003. TQFile file(url.path());
  1004. if (!file.open(IO_ReadOnly)) {
  1005. KMessageBox::error(0, i18n("<qt>Cannot open file<br><b>%1</b></qt>")
  1006. .arg(url.url()));
  1007. return;
  1008. }
  1009. TQTextStream ts(&file);
  1010. ts.setEncoding(TQTextStream::UnicodeUTF8);
  1011. TQString s, text;
  1012. while (true) {
  1013. s = ts.readLine();
  1014. if (s.isNull())
  1015. break;
  1016. if (s.isEmpty())
  1017. text += '\n';
  1018. else
  1019. text += s;
  1020. }
  1021. Edit->insert(text);
  1022. }
  1023. void Knowit::slotEditSwitch()
  1024. {
  1025. if (Items->hasFocus())
  1026. Edit->setFocus();
  1027. else Items->setFocus();
  1028. }
  1029. void Knowit::slotEditChanged()
  1030. {
  1031. actionBold->setChecked(Edit->bold());
  1032. actionItalic->setChecked(Edit->italic());
  1033. actionUnderline->setChecked(Edit->underline());
  1034. actionEditAlignLeft->setChecked(Edit->alignment() == TQt::AlignLeft);
  1035. actionEditAlignRight->setChecked(Edit->alignment() == TQt::AlignRight);
  1036. actionEditAlignCenter->setChecked(Edit->alignment() == TQt::AlignCenter);
  1037. actionEditAlignJustify->setChecked(Edit->alignment() == TQt::AlignJustify);
  1038. }
  1039. void Knowit::slotEditCursorChanged(int, int)
  1040. {
  1041. slotEditChanged();
  1042. }
  1043. void Knowit::slotOptions()
  1044. {
  1045. PrefDlg.setOptions(Options);
  1046. if (PrefDlg.exec() == TQDialog::Accepted)
  1047. applyOptions(PrefDlg.getOptions());
  1048. }
  1049. void Knowit::slotOptionsKeys()
  1050. {
  1051. KKeyDialog K(false);
  1052. K.configure(actionCollection());
  1053. }
  1054. void Knowit::slotOptionsToolbar()
  1055. {
  1056. KEditToolbar dlg(actionCollection());
  1057. if (dlg.exec())
  1058. createGUI();
  1059. }
  1060. void Knowit::slotUndock()
  1061. {
  1062. Options.docked = false;
  1063. applyOptions(Options);
  1064. }
  1065. void Knowit::slotHelpTip()
  1066. {
  1067. KTipDialog::showTip(this, 0, true);
  1068. }
  1069. void Knowit::slotActionUpdate()
  1070. {
  1071. if (Items->childCount())
  1072. stateChanged("notesPresent");
  1073. else
  1074. stateChanged("notesPresent", KXMLGUIClient::StateReverse);
  1075. Edit->setEnabled(Notes.count());
  1076. }
  1077. void Knowit::slotOverwriteModeChange(int i)
  1078. {
  1079. if (i == StatusOvr)
  1080. slotOverwriteModeChange();
  1081. }
  1082. void Knowit::slotOverwriteModeChange()
  1083. {
  1084. Edit->setOverwriteMode(!Edit->isOverwriteMode());
  1085. statusBar()->changeItem(Edit->isOverwriteMode() ? i18n("OVR") :
  1086. i18n("INS"), StatusOvr);
  1087. }
  1088. void Knowit::slotRawTextMode()
  1089. {
  1090. if (!Items->currentItem())
  1091. return;
  1092. if (Items->prevItem && Edit->isModified())
  1093. Notes.changeNote(Items->prevItem, Edit->length() ? Edit->text() : TQString());
  1094. Edit->setTextFormat(actionRawTextMode->isChecked() ?
  1095. TQt::PlainText : TQt::RichText);
  1096. Edit->setText(Notes.text(Items->currentItem()));
  1097. }
  1098. void Knowit::slotShowAttachment(TQListBoxItem*)
  1099. {
  1100. slotLinkOpen();
  1101. }
  1102. void Knowit::slotLinkAdd()
  1103. {
  1104. slotLinkDropped("", 0);
  1105. }
  1106. void Knowit::slotLinkDropped(const TQString& s, int flags)
  1107. {
  1108. TNoteLink link;
  1109. link.link = s;
  1110. if (!flags && !LinkDlg.modifyLink(link))
  1111. return;
  1112. currentNote()->addLink(link);
  1113. Links->insertItem(link.icon(), link.text(Options.linkFormat));
  1114. if (Links->count() == 1)
  1115. Links->show();
  1116. if (Options.firstLink) {
  1117. KMessageBox::information(0, i18n("You have just added your first link. "
  1118. "Please remember that only links are stored in Knowit document, "
  1119. "not linked files. If you move your document to other computer, "
  1120. "links to local files probably won't work."));
  1121. Options.firstLink = false;
  1122. }
  1123. }
  1124. void Knowit::slotLinkRemove()
  1125. {
  1126. TQString msg = i18n("<qt>Are you sure you want to remove link:<br><b>%1</b>?</qt>");
  1127. if (Links->currentItem() != -1 && KMessageBox::questionYesNo(0,
  1128. msg.arg(Links->currentText())) == KMessageBox::Yes) {
  1129. currentNote()->removeLink(Links->currentItem());
  1130. Links->removeItem(Links->currentItem());
  1131. if (!Links->count())
  1132. Links->hide();
  1133. }
  1134. }
  1135. void Knowit::slotLinkOpen()
  1136. {
  1137. if (Links->currentItem() == -1)
  1138. return;
  1139. TNoteLink link = currentNote()->link(Links->currentItem());
  1140. if (link.isLocalReference()) {
  1141. TQString s = link.link.remove(0, 9);
  1142. TQListViewItem* item = Items->findItem(s, 0);
  1143. if (!item) Items->findItem(s, 0, TQt::BeginsWith);
  1144. if (!item) Items->findItem(s, 0, TQt::Contains);
  1145. slotNoteChanged(item);
  1146. }
  1147. else
  1148. link.open();
  1149. }
  1150. void Knowit::slotLinkOpenWith()
  1151. {
  1152. if (Links->currentItem() != -1)
  1153. currentNote()->link(Links->currentItem()).openWith();
  1154. }
  1155. void Knowit::slotLinkModify()
  1156. {
  1157. if (Links->currentItem() == -1) return;
  1158. TNoteLink link = currentNote()->link(Links->currentItem());
  1159. if (LinkDlg.modifyLink(link)) {
  1160. currentNote()->modifyLink(Links->currentItem(), link);
  1161. Links->changeItem(link.icon(), link.text(Options.linkFormat),
  1162. Links->currentItem());
  1163. }
  1164. }
  1165. void Knowit::slotLinkCopy()
  1166. {
  1167. if (Links->currentItem() == -1) return;
  1168. TNoteLink link = currentNote()->link(Links->currentItem());
  1169. kapp->clipboard()->setText(link.link, TQClipboard::Clipboard);
  1170. kapp->clipboard()->setText(link.link, TQClipboard::Selection);
  1171. }