summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am35
-rw-r--r--src/hi16-app-knowit.pngbin0 -> 848 bytes
-rw-r--r--src/hi32-app-knowit.pngbin0 -> 2207 bytes
-rw-r--r--src/knowit.cpp1328
-rw-r--r--src/knowit.desktop14
-rw-r--r--src/knowit.h257
-rw-r--r--src/knowit.lsm14
-rw-r--r--src/knowitapp.cpp33
-rw-r--r--src/knowitapp.h45
-rw-r--r--src/knowitchooser.cpp85
-rw-r--r--src/knowitchooser.h48
-rw-r--r--src/knowitedit.cpp66
-rw-r--r--src/knowitedit.h38
-rw-r--r--src/knowitlink.cpp101
-rw-r--r--src/knowitlink.h45
-rw-r--r--src/knowitlinks.cpp56
-rw-r--r--src/knowitlinks.h43
-rw-r--r--src/knowitpref.cpp392
-rw-r--r--src/knowitpref.h104
-rw-r--r--src/knowittray.cpp33
-rw-r--r--src/knowittray.h31
-rw-r--r--src/knowittree.cpp146
-rw-r--r--src/knowittree.h55
-rw-r--r--src/knowitui.rc187
-rw-r--r--src/main.cpp51
-rw-r--r--src/notes.cpp432
-rw-r--r--src/notes.h106
-rw-r--r--src/tips63
-rw-r--r--src/x-knowit.desktop6
29 files changed, 3814 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..7364a0b
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,35 @@
+# set the include path for X, qt and KDE
+INCLUDES = $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = knowit.h knowitlink.h knowittree.h notes.h knowitlinks.h knowittray.h knowitpref.h knowitapp.h knowitchooser.h knowitedit.h
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/knowit.pot
+
+KDE_ICON = knowit
+
+#########################################################################
+# APPLICATION SECTION
+#########################################################################
+# this is the program that gets installed. it's name is used for all
+# of the other Makefile.am variables
+bin_PROGRAMS = knowit
+
+# the application source, library search path, and link libraries
+knowit_SOURCES = main.cpp knowit.cpp notes.cpp knowittree.cpp knowitlinks.cpp knowittray.cpp knowitpref.cpp knowitlink.cpp knowitapp.cpp knowitchooser.cpp knowitedit.cpp tips x-knowit.desktop
+knowit_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+knowit_LDADD = $(LIB_KDEPRINT) $(LIB_KDEUI)
+
+# this is where the desktop file will go
+shelldesktopdir = $(kde_appsdir)/Applications
+shelldesktop_DATA = knowit.desktop
+
+# this is where the shell's XML-GUI resource file goes
+shellrcdir = $(kde_datadir)/knowit
+shellrc_DATA = knowitui.rc tips
+
+shellmimedir = $(kde_mimedir)/application
diff --git a/src/hi16-app-knowit.png b/src/hi16-app-knowit.png
new file mode 100644
index 0000000..877b9bd
--- /dev/null
+++ b/src/hi16-app-knowit.png
Binary files differ
diff --git a/src/hi32-app-knowit.png b/src/hi32-app-knowit.png
new file mode 100644
index 0000000..a6a5aa0
--- /dev/null
+++ b/src/hi32-app-knowit.png
Binary files differ
diff --git a/src/knowit.cpp b/src/knowit.cpp
new file mode 100644
index 0000000..f789582
--- /dev/null
+++ b/src/knowit.cpp
@@ -0,0 +1,1328 @@
+/***************************************************************************
+ knowit.cpp - description
+ -------------------
+ begin : czw wrz 26 08:27:40 CEST 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <qtimer.h>
+#include <qclipboard.h>
+#include <qdatetime.h>
+#include <qdir.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
+#include <qwhatsthis.h>
+#include <qsimplerichtext.h>
+#include <qsplitter.h>
+
+#include <kaction.h>
+#include <kcmdlineargs.h>
+#include <kcolordialog.h>
+#include <kconfig.h>
+#include <kdeversion.h>
+#include <kedittoolbar.h>
+#include <kfiledialog.h>
+#include <kkeydialog.h>
+#include <kmenubar.h>
+#include <kmessagebox.h>
+#include <kmimetype.h>
+#include <kpopupmenu.h>
+#include <kprinter.h>
+#include <kstatusbar.h>
+#include <ktip.h>
+#if KDE_IS_VERSION(3,2,0)
+#include <kinputdialog.h>
+#else
+#include <klineeditdlg.h>
+#define KInputDialog KLineEditDlg
+#endif
+
+#include "knowit.h"
+#include "knowitapp.h"
+#include "knowittray.h"
+#include "knowittree.h"
+#include "knowitlinks.h"
+
+const QString Knowit::Untitled = i18n("untitled") + ".kno";
+
+Knowit::Knowit(QWidget*, const char *name) : KMainWindow(0, name),
+ FindDlg(), PrefDlg(), ChooserDlg(), LinkDlg(), Notes()
+{
+
+ statusBar()->insertItem(i18n("Ready"), 0);
+ Layout = new QSplitter(this);
+ Items = new KnowitTree(Layout, "Items");
+ QSplitter* EditLayout = new QSplitter(Layout);
+ EditLayout->setOrientation(QSplitter::Vertical);
+ Edit = new KnowitEdit(EditLayout, "Edit");
+ Links = new KnowitLinks(EditLayout);
+
+ connect(&FindDlg, SIGNAL(search()), this, SLOT(slotEditFind()));
+ lastSought = 0;
+
+ /* main view */
+ setAutoSaveSettings();
+ setCentralWidget(Layout);
+
+ QWhatsThis::add(Layout, i18n("Move it to change tree/edit layout."));
+ connect(Items, SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint&)),
+ this, SLOT(slotContextMenu(KListView*, QListViewItem*, const QPoint&)));
+ connect(Items, SIGNAL(selectionChanged(QListViewItem*)), this,
+ SLOT(slotItemChanged(QListViewItem*)));
+ connect(Items, SIGNAL(selectionChanged(QListViewItem*)), this,
+ SLOT(slotItemChanged(QListViewItem*)));
+
+ /* Edit (QTextEdit) */
+ Edit->setMinimumSize(200, 150);
+ Edit->setTextFormat(Qt::RichText);
+ QWhatsThis::add(Edit, i18n("<h2>Note text</h2>Add text for selected note here.\n"
+ "Text can be formatted, for example <b>bold</b> or <i>italic</i>."));
+ connect(Edit, SIGNAL(selectionChanged()), this, SLOT(slotEditChanged()));
+ connect(Edit, SIGNAL(textChanged()), this, SLOT(slotEditChanged()));
+ connect(Edit, SIGNAL(cursorPositionChanged(int, int)), this,
+ SLOT(slotEditCursorChanged(int, int)));
+ connect(Edit, SIGNAL(textDropped(const QString&, int)),
+ this, SLOT(slotLinkDropped(const QString&, int)));
+
+ /* Links (KListBox) */
+ connect(Links, SIGNAL(doubleClicked(QListBoxItem*)),
+ this, SLOT(slotShowAttachment(QListBoxItem*)));
+ connect(Links, SIGNAL(contextMenuRequested(QListBoxItem*, const QPoint&)),
+ this, SLOT(slotContextLinksMenu(QListBoxItem*, const QPoint&)));
+ connect(Links, SIGNAL(textDropped(const QString&, int)),
+ this, SLOT(slotLinkDropped(const QString&, int)));
+ connect(Links, SIGNAL(linkRemove()), this, SLOT(slotLinkRemove()));
+ connect(Links, SIGNAL(linkOpen()), this, SLOT(slotLinkOpen()));
+ connect(Links, SIGNAL(linkOpenWith()), this, SLOT(slotLinkOpenWith()));
+
+ /* Actions: File */
+ KStdAction::openNew(this, SLOT(slotFileNew()), actionCollection());
+ KStdAction::open(this, SLOT(slotFileOpen()), actionCollection());
+ actionRecent = KStdAction::openRecent(this, SLOT(slotFileRecent(const KURL&)), actionCollection());
+ KStdAction::save(this, SLOT(slotFileSave()), actionCollection());
+ KStdAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection());
+ new KAction(i18n("&Export to HTML..."), "", "", this,
+ SLOT(slotFileExport()), actionCollection(), "file_export_html");
+ KStdAction::print(this, SLOT(slotFilePrint()), actionCollection());
+ new KAction(i18n("Document &information..."), "", "", this,
+ SLOT(slotFileInfo()), actionCollection(), "file_info");
+ KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
+
+ /* Actions: Edit */
+ actionCut = KStdAction::cut(Edit, SLOT(cut()), actionCollection());
+ actionCopy = KStdAction::copy(Edit, SLOT(copy()), actionCollection());
+ KStdAction::paste(Edit, SLOT(paste()), actionCollection());
+ actionUndo = KStdAction::undo(Edit, SLOT(undo()), actionCollection());
+ actionRedo = KStdAction::redo(Edit, SLOT(redo()), actionCollection());
+ actionBold = new KToggleAction(i18n("Toggle &bold"), "text_bold",
+ "Ctrl+B", this, SLOT(slotEditBold()), actionCollection(), "edit_bold");
+ actionItalic = new KToggleAction(i18n("Toggle &italic"), "text_italic",
+ "Ctrl+I", this, SLOT(slotEditItalic()), actionCollection(),
+ "edit_italic");
+ actionUnderline = new KToggleAction(i18n("Toggle &underline"), "text_under",
+ "Ctrl+U", this, SLOT(slotEditUnderline()), actionCollection(),
+ "edit_underline");
+ new KAction(i18n("&Text color..."), "color_line", "Ctrl+#", this,
+ SLOT(slotEditColor()), actionCollection(), "edit_color");
+ new KAction(i18n("&Superscript"), "text_super", "", this,
+ SLOT(slotEditSuperscript()), actionCollection(), "edit_superscript");
+ new KAction(i18n("&Subscript"), "text_sub", "", this,
+ SLOT(slotEditSubscript()), actionCollection(), "edit_subscript");
+ new KAction(i18n("&Normal text"), "", "", this,
+ SLOT(slotEditNormal()), actionCollection(), "edit_align_normal");
+ new KAction(i18n("&Bullet list"), "", "", this,
+ SLOT(slotEditListBullet()), actionCollection(), "list_bullet");
+ new KAction(i18n("&Numbered list"), "", "", this,
+ SLOT(slotEditListNumber()), actionCollection(), "list_number");
+ new KAction(i18n("&Uppercase list"), "", "", this,
+ SLOT(slotEditListUpper()), actionCollection(), "list_upper");
+ new KAction(i18n("&Lowercase list"), "", "", this,
+ SLOT(slotEditListLower()), actionCollection(), "list_lower");
+ new KAction(i18n("N&o list"), "", "", this,
+ SLOT(slotEditListNone()), actionCollection(), "list_none");
+ KStdAction::find(&FindDlg, SLOT(exec()), actionCollection());
+ KStdAction::findNext(this, SLOT(slotEditFindNext()), actionCollection());
+ new KAction(i18n("&Go to &note..."), "goto", "Ctrl+G", this,
+ SLOT(slotEditGoTo()), actionCollection(), "goto_note");
+ actionEditAlignLeft = new KToggleAction(i18n("Align &left"), "text_left", "Ctrl+L", this,
+ SLOT(slotEditAlignLeft()), actionCollection(), "edit_align_left");
+ actionEditAlignRight = new KToggleAction(i18n("Align &right"), "text_right", "Ctrl+R",
+ this, SLOT(slotEditAlignRight()), actionCollection(), "edit_align_right");
+ actionEditAlignJustify = new KToggleAction(i18n("&Justify"), "text_block", "Ctrl+J",
+ this, SLOT(slotEditAlignJustify()), actionCollection(), "edit_align_justify");
+ actionEditAlignCenter = new KToggleAction(i18n("&Center"), "text_center", "Ctrl+E", this,
+ SLOT(slotEditAlignCenter()), actionCollection(), "edit_align_center");
+ new KAction(i18n("Insert &date"), "date", "F5", this,
+ SLOT(slotEditInsertDate()), actionCollection(), "edit_insert_date");
+ new KAction(i18n("Insert &file..."), "", "", this,
+ SLOT(slotEditInsertFile()), actionCollection(), "edit_insert_file");
+ actionRawTextMode = new KToggleAction(i18n("&Raw Text Mode"),
+ "source", "F10", this, SLOT(slotRawTextMode()),
+ actionCollection(), "edit_raw_text");
+
+ /* Actions: edit setup */
+ actionCut->setEnabled(false);
+ actionCopy->setEnabled(false);
+ connect(Edit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
+ connect(Edit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
+ connect(Edit, SIGNAL(undoAvailable(bool)), actionUndo, SLOT(setEnabled(bool)));
+ connect(Edit, SIGNAL(redoAvailable(bool)), actionRedo, SLOT(setEnabled(bool)));
+
+ /* Actions: notes */
+ new KAction(i18n("&Add"), "", "Alt+Insert", this, SLOT(slotNoteAdd()),
+ actionCollection(), "note_add");
+ new KAction(i18n("Add &subnote"), "", "Alt+Shift+Insert", this,
+ SLOT(slotNoteAddChild()), actionCollection(), "note_add_child");
+ new KAction(i18n("&Delete"), "", "Alt+Delete", this,
+ SLOT(slotNoteRemove()), actionCollection(), "note_delete");
+ new KAction(i18n("&Rename"), "", "F2", this,
+ SLOT(slotNoteRename()), actionCollection(), "note_rename");
+ new KAction(i18n("E&xpand all"), "", "", Items,
+ SLOT(slotExpandAll()), actionCollection(), "note_expand_all");
+ new KAction(i18n("&Expand current"), "", "Alt++", Items,
+ SLOT(slotExpand()), actionCollection(), "note_expand");
+ new KAction(i18n("Co&llapse all"), "", "", Items,
+ SLOT(slotCollapseAll()), actionCollection(), "note_collapse_all");
+ new KAction(i18n("&Collapse current"), "", "Alt+-", Items,
+ SLOT(slotCollapse()), actionCollection(), "note_collapse");
+ new KAction(i18n("Move up"), "up", "Alt+Shift+Up", this,
+ SLOT(slotNoteMoveUp()), actionCollection(), "note_move_up");
+ new KAction(i18n("Move down"), "down", "Alt+Shift+Down", this,
+ SLOT(slotNoteMoveDown()), actionCollection(), "note_move_down");
+ new KAction(i18n("Move level up"), "back", "Alt+Shift+Left", this,
+ SLOT(slotNoteMoveLeft()), actionCollection(), "note_move_left");
+ new KAction(i18n("Move level down"), "forward", "Alt+Shift+Right", this,
+ SLOT(slotNoteMoveRight()), actionCollection(), "note_move_right");
+ new KAction(i18n("Move at the beginning"), "top", "Alt+Shift+Home", this,
+ SLOT(slotNoteMoveBegin()), actionCollection(), "note_move_begin");
+ new KAction(i18n("Move at the end"), "bottom", "Alt+Shift+End", this,
+ SLOT(slotNoteMoveEnd()), actionCollection(), "note_move_end");
+ new KAction(i18n("Sort"), "", "", this,
+ SLOT(slotNoteSort()), actionCollection(), "note_sort");
+
+ /* Actions: Links */
+ new KAction(i18n("&Add link..."), "attach", "Ctrl+Shift+I", this,
+ SLOT(slotLinkAdd()), actionCollection(), "link_add");
+ new KAction(i18n("&Remove link"), "", "", this,
+ SLOT(slotLinkRemove()), actionCollection(), "link_remove");
+ new KAction(i18n("Open link"), "run", "", this,
+ SLOT(slotLinkOpen()), actionCollection(), "link_open");
+ new KAction(i18n("Open link with..."), "", "", this,
+ SLOT(slotLinkOpenWith()), actionCollection(), "link_open_with");
+ new KAction(i18n("&Modify link..."), "", "", this,
+ SLOT(slotLinkModify()), actionCollection(), "link_modify");
+ new KAction(i18n("&Copy link location"), "", "", this,
+ SLOT(slotLinkCopy()), actionCollection(), "link_copy");
+
+ /* Actions: Options */
+ KStdAction::keyBindings(this, SLOT(slotOptionsKeys()), actionCollection());
+ KStdAction::configureToolbars(this, SLOT(slotOptionsToolbar()), actionCollection());
+ KStdAction::preferences(this, SLOT(slotOptions()), actionCollection());
+
+ /* Actions: Help */
+ new KAction(i18n("&Tip of the day"), "idea", "", this,
+ SLOT(slotHelpTip()), actionCollection(), "help_tip");
+
+ /* Actions: nonplugged */
+ new KAction(i18n("Minimize"), "", "", this, SLOT(showMinimized()),
+ actionCollection(), "window_minimize");
+ new KAction(i18n("Switch area"), "", "Ctrl+M", this,
+ SLOT(slotEditSwitch()), actionCollection(), "edit_switch");
+ new KAction(i18n("Overwrite Mode"), "", "Insert", this,
+ SLOT(slotOverwriteModeChange()), actionCollection(), "overwrite_mode_change");
+ new KAction(i18n("Go to previous note"), "", "Alt+Up", Items,
+ SLOT(slotItemUp()), actionCollection(), "note_previous");
+ new KAction(i18n("Go to next note"), "", "Alt+Down", Items,
+ SLOT(slotItemDown()), actionCollection(), "note_next");
+ new KAction(i18n("Go to first note"), "", "Alt+Home", Items,
+ SLOT(slotItemBegin()), actionCollection(), "note_begin");
+ new KAction(i18n("Go to last note"), "", "Alt+End", Items,
+ SLOT(slotItemEnd()), actionCollection(), "note_end");
+ new KAction(i18n("Go to first subnote"), "", "Alt+Right", Items,
+ SLOT(slotItemRight()), actionCollection(), "note_right");
+ new KAction(i18n("Go to parent note"), "", "Alt+Left", Items,
+ SLOT(slotItemLeft()), actionCollection(), "note_left");
+
+ /* Actions */
+#if KDE_VERSION_MAJOR >= 3 && KDE_VERSION_MINOR >= 1
+ setStandardToolBarMenuEnabled(true);
+#endif
+ createGUI("knowitui.rc", false);
+
+
+ /* Insert/overwrite mode */
+ statusBar()->insertFixedItem(("WWW"), StatusOvr, true);
+ statusBar()->changeItem(i18n("INS"), StatusOvr);
+ connect(statusBar(), SIGNAL(pressed(int)), this,
+ SLOT(slotOverwriteModeChange(int)));
+
+ /* System tray */
+ systray = new KnowitTray(this, "Systray");
+ systray->setPixmap(Notes.Pixmaps[1]);
+ systray->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
+
+ /* Autosave */
+ AutosaveTimer = new QTimer(this);
+ connect(AutosaveTimer, SIGNAL(timeout()), this, SLOT(slotFileAutosave()));
+
+ /* Configuration */
+ config = kapp->config();
+ readOptions();
+
+ if (runMinimized)
+ showMinimized();
+ else
+ show();
+
+ bool opened = false;
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ for(int i = 0; i < args->count(); i++)
+ if (open(args->url(i))) {
+ opened = true; break;
+ }
+ args->clear();
+
+ if (!opened && Options.reopen && filename.path() != "")
+ open(KURL(filename));
+
+ slotActionUpdate();
+
+ KTipDialog::showTip(this);
+
+ shuttingDown = false;
+
+ applyMainWindowSettings(config);
+
+ /* check if knowituirc was found */
+ QWidget *w = factory()->container("notes_popup", this);
+ if (!w)
+ KMessageBox::error(0, i18n("<qt><p>Cannot open resource file <b>knowitui.rc</b>. "
+ "Some of the menus and toolbars will be missing.</p>"
+ "<p>Probably Knowit was not installed properly. "
+ "If you installed from source, please invoke <i>make install</i>."
+ "If you use precompiled package, please contact packager.</p></qt>"));
+}
+
+Knowit::~Knowit()
+{
+ delete systray;
+ delete AutosaveTimer;
+}
+
+bool Knowit::open(const KURL& fname)
+{
+ QFile file(fname.path());
+ if (!file.open(IO_ReadOnly)) {
+ KMessageBox::error(0, i18n("<qt>Cannot open file<br><b>%1</b></qt>")
+ .arg(fname.url()));
+ if (filename == fname)
+ filename = "";
+ return false;
+ }
+ uint prevdepth = 0;
+ reset();
+ QTextStream ts(&file);
+ ts.setEncoding(QTextStream::UnicodeUTF8);
+ QString s = "";
+ QListViewItem* current = 0;
+ QListViewItem* active = 0;
+ Notes.autoUpdate = false;
+ while (!s.isNull()) {
+ s = ts.readLine();
+ if (s.left(9) == "\\NewEntry" || s.left(13) == "\\CurrentEntry") {
+ QString name;
+ uint depth;
+ QTextIStream ls(&s);
+ ls >> name >> depth;
+ name = ls.readLine();
+ name = name.stripWhiteSpace();
+ if (depth == prevdepth) /* same level */
+ if (depth) current = new KListViewItem(current->parent(), current, name);
+ else current = new KListViewItem(Items, current, name);
+ else if (depth > prevdepth) /* subnote */
+ current = new KListViewItem(current, name);
+ else { /* parent note */
+ for(uint i=depth; i<prevdepth && current; i++)
+ current = current->parent();
+ if (current && current->parent())
+ current = new KListViewItem(current->parent(), current, name);
+ else current = new KListViewItem(Items, current, name);
+ }
+ prevdepth = depth;
+ Notes.addNote(current);
+ Notes.find(current)->open(ts);
+ if (s.left(13) == "\\CurrentEntry")
+ active = current;
+ }
+ }
+ Notes.autoUpdate = true;
+ Notes.updateNotesView();
+ filename = fname;
+ setCaption(fname.fileName());
+ Notes.modified = false;
+ Edit->clear();
+ slotNoteChanged(active);
+ Edit->setModified(false);
+ actionRecent->addURL(filename);
+ slotStatusMsg(i18n("File %1 opened.").arg(filename.fileName()));
+ slotActionUpdate();
+
+ file.close();
+ if (Options.backup)
+ URLOperator.copy(fname.path(), fname.path() + "~", false, false);
+ if (Options.autosave)
+ AutosaveTimer->start(Options.autosave * 60 * 1000, true);
+ return true;
+}
+
+bool Knowit::save(const KURL& fname)
+{
+ QFile file(fname.path());
+ if (!file.open(IO_WriteOnly)) {
+ KMessageBox::error(0, i18n("<qt>Cannot save file<br><b>%1</b></qt>")
+ .arg(fname.url()));
+ return false;
+ }
+ if (Items->prevItem && Edit->isModified())
+ Notes.changeNote(Items->prevItem, Edit->length() ? Edit->text() : QString());
+
+ QTextStream ts(&file);
+ ts.setEncoding(QTextStream::UnicodeUTF8);
+ for (QListViewItemIterator it(Items); it.current(); it++)
+ Notes.find(it.current())->save(ts, it.current() == Items->currentItem());
+ filename = fname;
+ setCaption(fname.fileName());
+ Notes.modified = false;
+ Edit->setModified(false);
+ actionRecent->addURL(filename);
+ slotStatusMsg(i18n("File %1 saved.").arg(filename.fileName()));
+ if (Options.autosave)
+ AutosaveTimer->start(Options.autosave * 60 * 1000, true);
+ return true;
+}
+
+void Knowit::reset()
+{
+ Items->prevItem = 0;
+ Notes.clearNotes();
+ Items->clear();
+ Edit->clear();
+ filename = "";
+ setCaption(Untitled);
+ Notes.modified = false;
+ slotActionUpdate();
+}
+
+
+
+void Knowit::closeEvent(QCloseEvent* e)
+{
+ if (!Options.docked || ((KnowitApplication*)kapp)->closeByLogout()) {
+ saveOptions();
+ KMainWindow::closeEvent(e);
+ }
+ else
+ hide();
+}
+
+bool Knowit::queryClose()
+{
+ if (!modified()) return shuttingDown = true;
+ else if (Options.unconditionalSave) {
+ slotFileSave();
+ return shuttingDown = filename.isEmpty() || !modified() || (KMessageBox::questionYesNo(0,
+ i18n("<qt>File <b>%1</b><br>\ncannot be saved. Quit anyway?</qt>").arg(filename.fileName()))
+ == KMessageBox::Yes);
+ }
+ else
+ switch (KMessageBox::questionYesNoCancel(0,
+ i18n("<qt>File <b>%1</b><br>\nwas modified. Do you want to save it?</qt>")
+ .arg(filename.isEmpty() ? Untitled : filename.fileName()))) {
+ case KMessageBox::Yes:
+ slotFileSave();
+ return shuttingDown = !modified();
+ case KMessageBox::No:
+ return shuttingDown = true;
+ default:
+ return false;
+ }
+}
+
+bool Knowit::queryExit()
+{
+ if (!shuttingDown) {
+ /* brutally closed by session manager */
+ if (modified())
+ save(filename.isEmpty() ? i18n("untitled.kno") : filename);
+ saveOptions();
+ }
+ return true;
+}
+
+
+void Knowit::find(QListViewItem* start)
+{
+ if (soughtText.isEmpty() || !Items->firstChild()) return;
+ if (start && lastSought == start &&
+ Edit->find(soughtText, FindDlg.case_sensitive(), false))
+ return;
+ if (!start) start = Items->firstChild();
+ QListViewItemIterator it(start);
+ while (it.current()) {
+ QString s = Notes.text(it.current());
+ if (lastSought != it.current() &&
+ s.contains(soughtText, FindDlg.case_sensitive())) {
+ slotNoteChanged(it.current());
+ Edit->find(soughtText, FindDlg.case_sensitive(), false);
+ lastSought = it.current();
+ return;
+ }
+ it++;
+ }
+ KMessageBox::information(0, i18n("<qt>Sought text:<br><b>%1</b><br>not found.</qt>").arg(soughtText));
+}
+
+
+void Knowit::saveOptions()
+{
+ config->setGroup("MainWindow");
+ config->writeEntry("Widgets", Layout->sizes());
+ Options.save(config);
+ config->setGroup("General");
+ config->writeEntry("Minimized", isMinimized() || !isVisible());
+ config->writeEntry("LastFile", filename.path());
+ config->writeEntry("Geometry", size());
+ actionCollection()->writeShortcutSettings("Keys", config);
+ config->deleteGroup("Recent Files");
+ actionRecent->saveEntries(config, "Recent Files");
+ saveMainWindowSettings(config);
+}
+
+void Knowit::readOptions()
+{
+ config->setGroup("MainWindow");
+ QValueList<int> sizes = config->readIntListEntry("Widgets");
+ if (sizes.count() == 2)
+ Layout->setSizes(sizes);
+ Options.read(config);
+ config->setGroup("General");
+ runMinimized = config->readBoolEntry("Minimized", false);
+ QString oldfile = config->readEntry("LastFile");
+ QSize defSize = size();
+ resize(config->readSizeEntry("Geometry", &defSize));
+ actionCollection()->readShortcutSettings("Keys", config);
+ actionRecent->loadEntries(config,"Recent Files");
+ if (!oldfile.isEmpty())
+ filename = KURL(oldfile);
+ applyOptions(Options);
+}
+
+void Knowit::slotNoteChanged(QListViewItem* item)
+{
+ if (item) {
+ if (Options.autoCollapse)
+ Items->slotCollapseAll();
+ Items->setCurrentItem(item);
+ Items->setSelected(item, true);
+ Items->ensureItemVisible(item);
+ }
+}
+
+bool Knowit::modified()
+{
+ return Notes.modified || (Items->currentItem() && Edit->isModified());
+}
+
+void Knowit::applyOptions(const KnowitOptions& O, bool store)
+{
+ if (store) Options = O;
+ if (O.docked)
+ systray->show();
+ else
+ systray->hide();
+
+ if (O.customColors) {
+ Edit->setPaletteForegroundColor(QColor(Options.foreEditColor));
+ Edit->setPaletteBackgroundColor(QColor(Options.backEditColor));
+ }
+ else Edit->unsetPalette();
+
+ if (Options.customFont)
+ Edit->setFont(QFont(Options.fontFamily, Options.fontSize));
+ else
+ Edit->unsetFont();
+
+ Edit->setWordWrap(O.wordwrap ? QTextEdit::WidgetWidth : QTextEdit::NoWrap);
+#if KDE_VERSION_MAJOR >= 3 && KDE_VERSION_MINOR >= 1
+ Edit->setTabChangesFocus(O.tabfocus);
+#endif
+ if (!O.autosave)
+ AutosaveTimer->stop();
+ else
+ AutosaveTimer->start(O.autosave * 60 * 1000, true);
+ Edit->swapEOL = O.enterBreakLine;
+ Layout->setOrientation(O.horizontalSplit ? QSplitter::Horizontal :
+ QSplitter::Vertical);
+ Items->setAlternateBackground(O.alternateTree ? QColor(O.alternateColor) : QColor());
+ Items->repaintContents();
+ if (Items->currentItem())
+ slotItemChanged(Items->currentItem());
+ slotNoteChanged(Items->currentItem());
+}
+
+TNote* Knowit::currentNote() const
+{
+ if (!Items->currentItem()) return 0;
+ return Notes.find(Items->currentItem());
+}
+
+
+
+
+
+
+/*** Slots ***/
+void Knowit::slotStatusMsg(const QString &text)
+{
+ statusBar()->clear();
+ statusBar()->changeItem(text, 0);
+}
+
+
+void Knowit::slotContextMenu(KListView*, QListViewItem*, const QPoint& p)
+{
+ QWidget *w = factory()->container("notes_popup", this);
+ if (w)
+ static_cast<QPopupMenu *>(w)->exec(p);
+}
+
+
+void Knowit::slotContextLinksMenu(QListBoxItem*, const QPoint& p)
+{
+ QWidget *w = factory()->container("links_popup", this);
+ if (w)
+ static_cast<QPopupMenu *>(w)->exec(p);
+}
+
+
+
+/******* Slots: Notes *******/
+void Knowit::slotNoteAdd()
+{
+ bool Ok;
+ KListViewItem* elt;
+ QString text = KInputDialog::getText(i18n("Add note"),
+ i18n("Note title:"), Options.defaultName, &Ok);
+ if (!Ok) return;
+ if (Items->currentItem())
+ if (Items->currentItem()->parent())
+ elt = new KListViewItem(Items->currentItem()->parent(),
+ Items->currentItem(), text);
+ else
+ elt = new KListViewItem(Items, Items->currentItem(), text);
+ else
+ elt = new KListViewItem(Items, text);
+ Notes.addNote(elt);
+ slotNoteChanged(elt);
+ if (Notes.count() == 1)
+ slotActionUpdate();
+}
+
+void Knowit::slotNoteAddChild()
+{
+ if (!Items->currentItem()) {
+ KMessageBox::error(0, i18n("You have to choose note before adding subnote."));
+ return;
+ }
+ bool Ok;
+ QString text = KInputDialog::getText(i18n("Add subnote"),
+ i18n("Note title:"), Options.defaultName, &Ok);
+ if (!Ok) return;
+ QListViewItem* lastChild = Items->currentItem()->firstChild();
+ while (lastChild && lastChild->nextSibling())
+ lastChild = lastChild->nextSibling();
+
+ KListViewItem* elt;
+ if (lastChild)
+ elt = new KListViewItem(Items->currentItem(), lastChild, text);
+ else
+ elt = new KListViewItem(Items->currentItem(), text);
+ Notes.addNote(elt);
+ slotNoteChanged(elt);
+}
+
+void Knowit::slotNoteRemove()
+{
+ QListViewItem* elt = Items->currentItem();
+ if (!elt) return;
+ QString msg = elt->childCount() ?
+ i18n("<qt>Are you sure you want to delete note<br><b>%1</b><br> "
+ "and its subnotes?</qt>") :
+ i18n("<qt>Are you sure you want to delete note<br><b>%1</b>?</qt>");
+ if (KMessageBox::questionYesNo(0, msg.arg(elt->text(0))) == KMessageBox::Yes) {
+ QListViewItem* parent = elt->parent();
+ Notes.removeNote(elt);
+ if (!Notes.count())
+ slotActionUpdate();
+ if (!parent)
+ parent = Items->firstChild();
+ Items->prevItem = 0;
+ slotNoteChanged(parent);
+ }
+}
+
+void Knowit::slotNoteRename()
+{
+ if (Items->currentItem()) {
+ Items->currentItem()->setRenameEnabled(0, true);
+ Items->currentItem()->startRename(0);
+ }
+}
+
+
+
+
+
+
+void Knowit::slotItemChanged(QListViewItem* i)
+{
+ if (Items->prevItem && Edit->isModified())
+ Notes.changeNote(Items->prevItem, Edit->length() ? Edit->text() : QString());
+ Items->prevItem = i;
+ QString s;
+ if (!Items->prevItem || (s = Notes.text(Items->prevItem)).isEmpty())
+ Edit->setText("");
+ else
+ Edit->setText(s);
+ Edit->setModified(false);
+ Links->clear();
+ TNote* note = Notes.find(i);
+ if (note)
+ for (int j=0; j<note->linkCount(); j++)
+ Links->insertItem(note->link(j).icon(), note->link(j).text(Options.linkFormat));
+ if (Links->count())
+ Links->show();
+ else
+ Links->hide();
+}
+
+void Knowit::slotNoteMoveUp()
+{
+ QListViewItem* elt = Items->currentItem();
+ if (elt && elt->itemAbove()) {
+ QListViewItem* above = elt->parent() ? elt->parent()->firstChild()
+ : Items->firstChild();
+ if (above == elt)
+ return;
+ if (!above->nextSibling() || above->nextSibling() == elt)
+ above = 0;
+ else while (above->nextSibling()->nextSibling() != elt)
+ above = above->nextSibling();
+ if (above)
+ elt->moveItem(above);
+ else {
+ QListViewItem* parent = elt->parent();
+ Items->takeNode(elt);
+ Items->insertNode(parent, elt);
+ }
+ slotNoteChanged(elt);
+ Notes.modified = true;
+ }
+}
+
+void Knowit::slotNoteMoveDown()
+{
+ QListViewItem* elt = Items->currentItem();
+ if (elt && elt->nextSibling()) {
+ elt->moveItem(elt->nextSibling());
+ slotNoteChanged(elt);
+ Notes.modified = true;
+ }
+}
+
+void Knowit::slotNoteMoveBegin()
+{
+ QListViewItem* elt = Items->currentItem();
+ if (elt) {
+ QListViewItem* parent = elt->parent();
+ Items->takeNode(elt);
+ Items->insertItem(elt);
+ if (parent)
+ Notes.find(parent)->updateView();
+ slotNoteChanged(elt);
+ Notes.modified = true;
+ }
+}
+
+void Knowit::slotNoteMoveEnd()
+{
+ QListViewItem* elt = Items->currentItem();
+ if (!elt)
+ return;
+ QListViewItem* last = Items->firstChild();
+ QListViewItem* parent = elt->parent();
+ while (last->nextSibling())
+ last = last->nextSibling();
+ if (elt && elt != last) {
+ Items->takeNode(elt);
+ Items->insertNode(0, elt, last);
+ slotNoteChanged(elt);
+ if (parent)
+ Notes.find(parent)->updateView();
+ Notes.modified = true;
+ }
+}
+
+void Knowit::slotNoteMoveLeft()
+{
+ QListViewItem* elt = Items->currentItem();
+ QListViewItem* parent = elt->parent();
+ if (elt && parent) {
+ Items->takeNode(elt);
+ Items->insertNode(parent->parent(), elt, parent);
+ Notes.find(parent)->updateView();
+ slotNoteChanged(elt);
+ Notes.modified = true;
+ }
+}
+
+void Knowit::slotNoteMoveRight()
+{
+ QListViewItem* elt = Items->currentItem();
+ QListViewItem* above = elt->itemAbove();
+ if (elt && above) {
+ if (above->depth() < elt->depth())
+ return;
+ else if (above->depth() == elt->depth()) {
+ Items->takeNode(elt);
+ Items->insertNode(above, elt);
+ }
+ else {
+ while (above->depth() > elt->depth()+1)
+ above = above->parent();
+ Items->takeNode(elt);
+ Items->insertNode(above->parent(), elt, above);
+ }
+ Notes.find(above)->updateView();
+ slotNoteChanged(elt);
+ Notes.modified = true;
+ }
+}
+
+void Knowit::slotNoteSort()
+{
+ if (Items->currentItem()) {
+ Items->currentItem()->sortChildItems(0, true);
+ Items->repaintContents();
+ }
+}
+
+
+
+void Knowit::slotFileNew()
+{
+ if (queryClose()) reset();
+}
+
+void Knowit::slotFileOpen()
+{
+ if (!queryClose()) return;
+ KURL url=KFileDialog::getOpenURL(QString::null,
+ i18n("*.kno|KnowIt files (*.kno)\n*|All files"), this, i18n("Open File..."));
+ if (!url.isEmpty())
+ open(url);
+}
+
+void Knowit::slotFileSave()
+{
+ if (filename.isEmpty())
+ slotFileSaveAs();
+ else {
+ save(filename);
+ }
+}
+
+void Knowit::slotFileAutosave()
+{
+ if (modified())
+ slotFileSave();
+ if (modified()) { /* file wasn't saved */
+ KMessageBox::sorry(0, i18n("<qt><p>File couldn not be saved automatically."
+ "<p>Autosaving disabled - save file manually to turn autosaving on.</p></qt>"));
+ AutosaveTimer->stop();
+ }
+}
+
+
+void Knowit::slotFileRecent(const KURL& url)
+{
+ if (queryClose())
+ if (!open(url))
+ actionRecent->removeURL(url);
+}
+
+
+void Knowit::slotFileSaveAs()
+{
+ KURL url=KFileDialog::getSaveURL(QDir::currentDirPath(),
+ i18n("*.kno|KnowIt files (*.kno)\n*|All files"), this, i18n("Save as..."));
+ if (!url.isEmpty()) {
+ if (!url.fileName().contains('.'))
+ url = KURL(url.path() + ".kno");
+ QFileInfo fileinfo(url.path());
+ if (fileinfo.exists() && KMessageBox::questionYesNo(0,
+ i18n("<qt>File<br><b>%1</b><br>already exists. Overwrite it?</qt>")
+ .arg(url.path())) == KMessageBox::No)
+ return;
+ save(url);
+ }
+}
+
+
+void Knowit::slotFileInfo()
+{
+ int count = 0;
+ QListViewItemIterator it(Items);
+ while (it.current()) {
+ count++;
+ it++;
+ }
+ KMessageBox::information(0, i18n("<qt><h1>%1</h1>"
+ "Document path: %2<br>"
+ "Number of notes: %3</qt>").arg(filename.fileName())
+ .arg(filename.path()).arg(count));
+}
+
+
+void Knowit::slotFilePrint()
+{
+ KPrinter printer;
+ printer.setFullPage(true);
+ if (Edit->text().stripWhiteSpace().isEmpty() || !printer.setup(this))
+ return;
+
+ QSimpleRichText richText(Edit->text(), Edit->font());
+ QPainter p(&printer);
+ QPaintDeviceMetrics metrics(p.device());
+ int dpix = metrics.logicalDpiX();
+ int dpiy = metrics.logicalDpiY();
+ const int margin = 72; // pt
+ QRect body(margin*dpix / 72, margin*dpiy / 72,
+ metrics.width()- margin*dpix /72*2,
+ metrics.height()-margin*dpiy/72*2);
+ richText.setWidth(&p, body.width());
+ QRect view(body);
+ int page = 1;
+ while (true) {
+ richText.draw(&p, body.left(), body.top(), view, colorGroup());
+ view.moveBy(0, body.height());
+ p.translate( 0 , -body.height());
+ p.setFont(Edit->font());
+ p.drawText( view.right() - p.fontMetrics().width( QString::number(page)),
+ view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page));
+ if (view.top() >= body.top() + richText.height())
+ break;
+ printer.newPage();
+ page++;
+ }
+}
+
+
+
+
+void Knowit::slotFileQuit()
+{
+ if (queryClose()) {
+ saveOptions();
+ kapp->quit();
+ }
+}
+
+void Knowit::slotFileExport()
+{
+ if (!Items->firstChild()) return; /* nothing to export */
+ ChooserDlg.setChoice(Options.exportFlags);
+ if (ChooserDlg.exec() != QDialog::Accepted) return; /* cancelled */
+
+ /* Deduce filename from Knowit document name */
+ QString htmlfile;
+ if (filename.isValid()) {
+ htmlfile = filename.path();
+ if (htmlfile.right(4) == ".kno")
+ htmlfile = htmlfile.left(htmlfile.length() - 4) + ".html";
+ else htmlfile = "";
+ }
+ if (htmlfile.isEmpty())
+ htmlfile == QDir::currentDirPath();
+
+ /* Confirm/choose filename */
+ KURL url=KFileDialog::getSaveURL(htmlfile,
+ i18n("*.html|HTML files (*.html)\n*|All files"), this, i18n("Export to HTML"));
+ if (!url.isEmpty()) {
+ if (!url.fileName().contains('.'))
+ url = KURL(url.path() + ".html");
+ QFileInfo fileinfo(url.path());
+ if (fileinfo.exists() && KMessageBox::questionYesNo(0,
+ i18n("<qt>File<br><b>%1</b><br>already exists. Overwrite it?</qt>")
+ .arg(url.path())) == KMessageBox::No)
+ return;
+ int choice = ChooserDlg.getChoice();
+ QListViewItem* start = (choice & KnowitChooser::SaveAll) ?
+ Items->firstChild() : Items->currentItem();
+ QString origname = filename.isEmpty() ? Untitled : filename.path();
+ QString style;
+ if (choice & KnowitChooser::Style)
+ style = QString("body {font-family: \"%1\"; color: %2; background-color: %3}")
+ .arg(Edit->family()).arg(Edit->paletteForegroundColor().name())
+ .arg(Edit->paletteBackgroundColor().name());
+ Notes.find(start)->saveHTML(url, origname, style, choice);
+ Options.exportFlags = choice;
+ }
+}
+
+void Knowit::slotEditBold()
+{
+ Edit->setBold(actionBold->isChecked());
+}
+
+void Knowit::slotEditItalic()
+{
+ Edit->setItalic(actionItalic->isChecked());
+}
+
+void Knowit::slotEditUnderline()
+{
+ Edit->setUnderline(actionUnderline->isChecked());
+}
+
+void Knowit::slotEditColor()
+{
+ QColor color = Edit->color();
+ if (KColorDialog::getColor(color) == QDialog::Accepted)
+ Edit->setColor(color);
+}
+
+void Knowit::slotEditSuperscript()
+{
+ Edit->setVerticalAlignment(QTextEdit::AlignSuperScript);
+}
+
+void Knowit::slotEditSubscript()
+{
+ Edit->setVerticalAlignment(QTextEdit::AlignSubScript);
+}
+
+void Knowit::slotEditNormal()
+{
+ Edit->setVerticalAlignment(QTextEdit::AlignNormal);
+}
+
+void Knowit::slotEditAlignLeft()
+{
+ Edit->setAlignment(Qt::AlignLeft);
+}
+
+void Knowit::slotEditAlignRight()
+{
+ Edit->setAlignment(Qt::AlignRight);
+}
+
+void Knowit::slotEditAlignJustify()
+{
+ Edit->setAlignment(Qt::AlignJustify);
+}
+
+void Knowit::slotEditAlignCenter()
+{
+ Edit->setAlignment(Qt::AlignCenter);
+}
+
+void Knowit::slotEditListBullet()
+{
+ Edit->setParagType(QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc);
+}
+
+void Knowit::slotEditListNumber()
+{
+ Edit->setParagType(QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDecimal);
+}
+
+void Knowit::slotEditListUpper()
+{
+ Edit->setParagType(QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListUpperAlpha);
+}
+
+void Knowit::slotEditListLower()
+{
+ Edit->setParagType(QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListLowerAlpha);
+}
+
+void Knowit::slotEditListNone()
+{
+ Edit->setParagType(QStyleSheetItem::DisplayBlock, QStyleSheetItem::ListDisc);
+}
+
+void Knowit::slotEditFind()
+{
+ if (soughtText != FindDlg.getText()) {
+ soughtText = FindDlg.getText();
+ lastSought = 0;
+ find();
+ }
+ else
+ find(Items->currentItem());
+}
+
+void Knowit::slotEditFindNext()
+{
+ if (soughtText.isEmpty()) FindDlg.exec();
+ find(Items->currentItem());
+}
+
+void Knowit::slotEditGoTo()
+{
+ bool Ok;
+ QString page = KInputDialog::getText(i18n("Go to"),
+ i18n("Go to page with given title"), "", &Ok);
+ if (Ok && !page.isEmpty()) {
+ QListViewItem* item = Items->findItem(page, 0);
+ if (!item) item = Items->findItem(page, 0, Qt::ExactMatch);
+ if (!item) item = Items->findItem(page, 0, Qt::Contains);
+ slotNoteChanged(item);
+ }
+}
+
+void Knowit::slotEditInsertDate()
+{
+ if (Items->currentItem()) {
+ bool ib = actionBold->isChecked(), ii=actionItalic->isChecked(), iu=actionUnderline->isChecked();
+ QColor color = Edit->color();
+ Edit->setItalic(Options.insertDateItalic);
+ Edit->setBold(Options.insertDateBold);
+ Edit->setUnderline(Options.insertDateUnderline);
+ Edit->setColor(QColor(Options.insertDateColor));
+ Edit->insert(QString("%1")
+ .arg(QDateTime::currentDateTime().toString(Options.insertDateFormat)));
+ Edit->setItalic(ii);
+ Edit->setBold(ib);
+ Edit->setUnderline(iu);
+ Edit->setColor(color);
+
+ }
+}
+
+void Knowit::slotEditInsertFile()
+{
+ if (!Items->currentItem())
+ return;
+ KURL url=KFileDialog::getOpenURL(QString::null,
+ i18n("*|All files"), this, i18n("Insert file..."));
+ if (url.isEmpty())
+ return;
+ QFile file(url.path());
+ if (!file.open(IO_ReadOnly)) {
+ KMessageBox::error(0, i18n("<qt>Cannot open file<br><b>%1</b></qt>")
+ .arg(url.url()));
+ return;
+ }
+ QTextStream ts(&file);
+ ts.setEncoding(QTextStream::UnicodeUTF8);
+ QString s, text;
+ while (true) {
+ s = ts.readLine();
+ if (s.isNull())
+ break;
+ if (s.isEmpty())
+ text += '\n';
+ else
+ text += s;
+ }
+ Edit->insert(text);
+}
+
+
+void Knowit::slotEditSwitch()
+{
+ if (Items->hasFocus())
+ Edit->setFocus();
+ else Items->setFocus();
+}
+
+void Knowit::slotEditChanged()
+{
+ actionBold->setChecked(Edit->bold());
+ actionItalic->setChecked(Edit->italic());
+ actionUnderline->setChecked(Edit->underline());
+ actionEditAlignLeft->setChecked(Edit->alignment() == Qt::AlignLeft);
+ actionEditAlignRight->setChecked(Edit->alignment() == Qt::AlignRight);
+ actionEditAlignCenter->setChecked(Edit->alignment() == Qt::AlignCenter);
+ actionEditAlignJustify->setChecked(Edit->alignment() == Qt::AlignJustify);
+}
+
+void Knowit::slotEditCursorChanged(int, int)
+{
+ slotEditChanged();
+}
+
+
+
+void Knowit::slotOptions()
+{
+ PrefDlg.setOptions(Options);
+ if (PrefDlg.exec() == QDialog::Accepted)
+ applyOptions(PrefDlg.getOptions());
+}
+
+void Knowit::slotOptionsKeys()
+{
+ KKeyDialog K(false);
+ K.configure(actionCollection());
+}
+
+void Knowit::slotOptionsToolbar()
+{
+ KEditToolbar dlg(actionCollection());
+ if (dlg.exec())
+ createGUI();
+}
+
+
+void Knowit::slotUndock()
+{
+ Options.docked = false;
+ applyOptions(Options);
+}
+
+void Knowit::slotHelpTip()
+{
+ KTipDialog::showTip(this, 0, true);
+}
+
+
+void Knowit::slotActionUpdate()
+{
+ if (Items->childCount())
+ stateChanged("notesPresent");
+ else
+ stateChanged("notesPresent", KXMLGUIClient::StateReverse);
+ Edit->setEnabled(Notes.count());
+}
+
+void Knowit::slotOverwriteModeChange(int i)
+{
+ if (i == StatusOvr)
+ slotOverwriteModeChange();
+}
+
+void Knowit::slotOverwriteModeChange()
+{
+ Edit->setOverwriteMode(!Edit->isOverwriteMode());
+ statusBar()->changeItem(Edit->isOverwriteMode() ? i18n("OVR") :
+ i18n("INS"), StatusOvr);
+}
+
+void Knowit::slotRawTextMode()
+{
+ if (!Items->currentItem())
+ return;
+ if (Items->prevItem && Edit->isModified())
+ Notes.changeNote(Items->prevItem, Edit->length() ? Edit->text() : QString());
+ Edit->setTextFormat(actionRawTextMode->isChecked() ?
+ Qt::PlainText : Qt::RichText);
+ Edit->setText(Notes.text(Items->currentItem()));
+}
+
+void Knowit::slotShowAttachment(QListBoxItem*)
+{
+ slotLinkOpen();
+}
+
+void Knowit::slotLinkAdd()
+{
+ slotLinkDropped("", 0);
+}
+
+void Knowit::slotLinkDropped(const QString& s, int flags)
+{
+ TNoteLink link;
+ link.link = s;
+ if (!flags && !LinkDlg.modifyLink(link))
+ return;
+ currentNote()->addLink(link);
+ Links->insertItem(link.icon(), link.text(Options.linkFormat));
+ if (Links->count() == 1)
+ Links->show();
+ if (Options.firstLink) {
+ KMessageBox::information(0, i18n("You have just added your first link. "
+ "Please remember that only links are stored in Knowit document, "
+ "not linked files. If you move your document to other computer, "
+ "links to local files probably won't work."));
+ Options.firstLink = false;
+ }
+}
+
+void Knowit::slotLinkRemove()
+{
+ QString msg = i18n("<qt>Are you sure you want to remove link:<br><b>%1</b>?</qt>");
+ if (Links->currentItem() != -1 && KMessageBox::questionYesNo(0,
+ msg.arg(Links->currentText())) == KMessageBox::Yes) {
+ currentNote()->removeLink(Links->currentItem());
+ Links->removeItem(Links->currentItem());
+ if (!Links->count())
+ Links->hide();
+ }
+}
+
+void Knowit::slotLinkOpen()
+{
+ if (Links->currentItem() == -1)
+ return;
+ TNoteLink link = currentNote()->link(Links->currentItem());
+ if (link.isLocalReference()) {
+ QString s = link.link.remove(0, 9);
+ QListViewItem* item = Items->findItem(s, 0);
+ if (!item) Items->findItem(s, 0, Qt::BeginsWith);
+ if (!item) Items->findItem(s, 0, Qt::Contains);
+ slotNoteChanged(item);
+ }
+ else
+ link.open();
+}
+
+void Knowit::slotLinkOpenWith()
+{
+ if (Links->currentItem() != -1)
+ currentNote()->link(Links->currentItem()).openWith();
+}
+
+void Knowit::slotLinkModify()
+{
+ if (Links->currentItem() == -1) return;
+ TNoteLink link = currentNote()->link(Links->currentItem());
+ if (LinkDlg.modifyLink(link)) {
+ currentNote()->modifyLink(Links->currentItem(), link);
+ Links->changeItem(link.icon(), link.text(Options.linkFormat),
+ Links->currentItem());
+ }
+}
+
+void Knowit::slotLinkCopy()
+{
+ if (Links->currentItem() == -1) return;
+ TNoteLink link = currentNote()->link(Links->currentItem());
+ kapp->clipboard()->setText(link.link, QClipboard::Clipboard);
+ kapp->clipboard()->setText(link.link, QClipboard::Selection);
+}
+
diff --git a/src/knowit.desktop b/src/knowit.desktop
new file mode 100644
index 0000000..93653e5
--- /dev/null
+++ b/src/knowit.desktop
@@ -0,0 +1,14 @@
+# KDE Config File
+[Desktop Entry]
+Encoding=UTF-8
+Type=Application
+Exec=knowit -caption "%c" %i %m
+MimeType=application/x-knowit
+Icon=knowit.png
+DocPath=knowit/index.html
+Comment=
+Comment[de]=
+Terminal=0
+Name=KnowIt
+Name[de]=KnowIt
+Categories=Qt;KDE;Office
diff --git a/src/knowit.h b/src/knowit.h
new file mode 100644
index 0000000..59c0ca7
--- /dev/null
+++ b/src/knowit.h
@@ -0,0 +1,257 @@
+/***************************************************************************
+ knowit.h - description
+ -------------------
+ begin : czw wrz 26 08:27:40 CEST 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef KNOWIT_H
+#define KNOWIT_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qurloperator.h>
+
+#include <keditcl.h>
+#include <klocale.h>
+#include <kmainwindow.h>
+#include <kurl.h>
+#include "knowitpref.h"
+#include "knowitchooser.h"
+#include "knowitedit.h"
+#include "knowitlink.h"
+#include "notes.h"
+
+class QSplitter;
+class QTimer;
+class KAction;
+class KConfig;
+class KListBox;
+class KToggleAction;
+class KRecentFilesAction;
+
+class KnowitTray;
+class KnowitEdit;
+class KnowitTree;
+
+
+/** Knowit is the base class of the project */
+class Knowit : public KMainWindow
+{
+ Q_OBJECT
+ private:
+ static const QString Untitled;
+ KConfig *config;
+ QSplitter* Layout;
+ KnowitTree* Items;
+ KListBox* Links;
+ KnowitEdit* Edit;
+ KURL filename;
+ QPixmap pixmapFolder, pixmapFolderText, pixmapText, pixmapEmpty;
+ KEdFind FindDlg;
+ KnowitOptions Options;
+ KnowitPreferences PrefDlg;
+ KnowitChooser ChooserDlg;
+ KnowitLinkDialog LinkDlg;
+ KnowitTray* systray;
+ /* data items */
+ TNotesCollection Notes;
+ bool runMinimized;
+ QListViewItem* lastSought;
+ QString soughtText;
+ QTimer* AutosaveTimer;
+ /* for saving backups */
+ QUrlOperator URLOperator;
+ /* false by default, set to true on queryClose() */
+ bool shuttingDown;
+ /* actions */
+ KRecentFilesAction *actionRecent;
+ KToggleAction *actionBold, *actionItalic, *actionUnderline,
+ *actionEditAlignLeft, *actionEditAlignRight, *actionEditAlignCenter,
+ *actionEditAlignJustify, *actionRawTextMode;
+ KAction *actionCut, *actionCopy, *actionUndo, *actionRedo;
+
+ /** Insert/Overwrite status */
+ enum {StatusText = 1, StatusOvr = 2};
+ public:
+ /** Constructor of main window */
+ Knowit(QWidget* parent=0, const char *name=0);
+ /** Standard destructor */
+ ~Knowit();
+ /** Opens document */
+ bool open(const KURL& fname);
+ /** Saves document */
+ bool save(const KURL& fname);
+ /** Removes all data, creante new document */
+ void reset();
+ /** Checks if file was changed since last save, if so,
+ user is prompted to save changes */
+ virtual bool queryClose();
+ /** Saves options and exits */
+ virtual bool queryExit();
+ /** Reads configuration from disk */
+ void readOptions();
+ /** Saves configuration to disk */
+ void saveOptions();
+
+ /** Finds and shows next occurence of currently sought text
+ - or show message that it couldn't be found */
+ void find(QListViewItem* start = 0);
+ /** Returns true if notes or current text were modified */
+ bool modified();
+ /** Reimplemented from QWidget to prevent from closing when docked */
+ virtual void closeEvent(QCloseEvent* e);
+ /** Apply current configuration */
+ void applyOptions(const KnowitOptions& O, bool store = true);
+ /** Returns current note */
+ TNote* currentNote() const;
+
+ public slots:
+ /** Status bar text has changed - displays it */
+ void slotStatusMsg(const QString& text);
+ /** Shows requested popup menu for notes */
+ void slotContextMenu(KListView*, QListViewItem*, const QPoint&);
+ /** Shows given note */
+ void slotNoteChanged(QListViewItem* item);
+ /** Add same-level note */
+ void slotNoteAdd();
+ /** Adds subnote */
+ void slotNoteAddChild();
+ /** Changes note's name */
+ void slotNoteRename();
+ /** Removes current note */
+ void slotNoteRemove();
+ /** Sort subnotes */
+ void slotNoteSort();
+
+ /** Move note up */
+ void slotNoteMoveUp();
+ /** Move note down */
+ void slotNoteMoveDown();
+ /** Move note at the beginning of current list */
+ void slotNoteMoveBegin();
+ /** Move note at the end of current list */
+ void slotNoteMoveEnd();
+ /** Move note level up */
+ void slotNoteMoveLeft();
+ /** Move note level down */
+ void slotNoteMoveRight();
+
+ /** Current item has changed - updates associated text and shows next */
+ void slotItemChanged(QListViewItem*);
+ /** Resets to a new file */
+ void slotFileNew();
+ /** Prompts for a file to open and opens it */
+ void slotFileOpen();
+ /** Opens selected of recent files */
+ void slotFileRecent(const KURL&);
+ /** Saves file using previous name */
+ void slotFileSave();
+ /** Autosaves file using previous name */
+ void slotFileAutosave();
+ /** Prompts for filename and saves file */
+ void slotFileSaveAs();
+ /** Exports all notes to HTML */
+ void slotFileExport();
+ /** Prints current note */
+ void slotFilePrint();
+ /** Shows basic file statistics */
+ void slotFileInfo();
+ /** Quits KnowIt */
+ void slotFileQuit();
+ /** Turns bold in edit window on/off */
+ void slotEditBold();
+ /** Turns italic in edit window on/off */
+ void slotEditItalic();
+ /** Turns underlining in edit window on/off */
+ void slotEditUnderline();
+ /** Changes color of selected/current text */
+ void slotEditColor();
+ /** Changes vertical alignment to superscript */
+ void slotEditSuperscript();
+ /** Changes vertical alignment to subscript */
+ void slotEditSubscript();
+ /** Restores normal vertical alignment */
+ void slotEditNormal();
+ /** Prompts for text and shows note containing it */
+ void slotEditFind();
+ /** Shows next note with sought text */
+ void slotEditFindNext();
+ /** Shows note with given title */
+ void slotEditGoTo();
+ /** Aligns text to the left */
+ void slotEditAlignLeft();
+ /** Aligns text to the right */
+ void slotEditAlignRight();
+ /** Justifies text */
+ void slotEditAlignJustify();
+ /** Centers text */
+ void slotEditAlignCenter();
+ /** Change selected paragraphs to list. Warning: uses obsolete Qt function */
+ void slotEditListBullet();
+ void slotEditListNumber();
+ void slotEditListUpper();
+ void slotEditListLower();
+ void slotEditListNone();
+ /** Inserts current date */
+ void slotEditInsertDate();
+ /** Inserts file into editor */
+ void slotEditInsertFile();
+ /** Switches active window (notes/editor) */
+ void slotEditSwitch();
+ /** Edited text has changed - update bold/italic/... status */
+ void slotEditChanged();
+ /** Cursor position has changed - update bold/italic/... status */
+ void slotEditCursorChanged(int para, int pos);
+ /** Shows options dialog */
+ void slotOptions();
+ /** Shows shortcut configuration dialog */
+ void slotOptionsKeys();
+ /** Shows toolbar configuration dialog */
+ void slotOptionsToolbar();
+ /** Removes KnowIt from Applet Tray */
+ void slotUndock();
+ /** Shows tip of the day */
+ void slotHelpTip();
+ /** Updates available commands */
+ void slotActionUpdate();
+ /** Text Insert mode changed, called from statusbar */
+ void slotOverwriteModeChange(int);
+ /** Text Insert mode changed, called from Shortcut Key */
+ void slotOverwriteModeChange();
+ /** Toggles raw text/rich text edit mode */
+ void slotRawTextMode();
+
+ /** Shows requested popup menu for links */
+ void slotContextLinksMenu(QListBoxItem* item, const QPoint&);
+ /** show current attachment **/
+ void slotShowAttachment(QListBoxItem* i);
+ /** Add link **/
+ void slotLinkAdd();
+ /** Handle dropped link **/
+ void slotLinkDropped(const QString& s, int flags);
+ /** Remove link **/
+ void slotLinkRemove();
+ /** Open link **/
+ void slotLinkOpen();
+ /** Open link with selected application **/
+ void slotLinkOpenWith();
+ /** Modify link **/
+ void slotLinkModify();
+ /** Copy link location **/
+ void slotLinkCopy();
+};
+
+#endif
diff --git a/src/knowit.lsm b/src/knowit.lsm
new file mode 100644
index 0000000..ac510e6
--- /dev/null
+++ b/src/knowit.lsm
@@ -0,0 +1,14 @@
+Begin3
+Title: KnowIt
+Version: 0.10
+Entered-date: 31 Mar 2004
+Description: tool for knowledge management
+Keywords: notes knowledge management tree hierarchy
+Author: Micha³ Rudolf <mrudolf@kdewebdev.org>
+Maintained-by: Micha³ Rudolf <mrudolf@kdewebdev.org>
+Primary-site:
+Home-page: http://knowit.sourceforge.net
+Original-site:
+Platforms: Linux and other Unices
+Copying-policy: GNU Public License
+End
diff --git a/src/knowitapp.cpp b/src/knowitapp.cpp
new file mode 100644
index 0000000..56d0f4b
--- /dev/null
+++ b/src/knowitapp.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ knowitApplication.cpp - description
+ -------------------
+ begin : wto maj 20 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "knowitapp.h"
+
+KnowitApplication::KnowitApplication(bool allowStyles, bool GUIEnabled)
+ : KUniqueApplication(allowStyles, GUIEnabled, true), mcloseByLogout(false)
+{
+}
+
+KnowitApplication::~KnowitApplication()
+{
+}
+
+void KnowitApplication::commitData(QSessionManager& sm)
+{
+ mcloseByLogout = true;
+ KUniqueApplication::commitData(sm);
+}
diff --git a/src/knowitapp.h b/src/knowitapp.h
new file mode 100644
index 0000000..f876202
--- /dev/null
+++ b/src/knowitapp.h
@@ -0,0 +1,45 @@
+/***************************************************************************
+ knowitApplication.h - description
+ -------------------
+ begin : wto maj 20 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef __KNOWIT_APP_H__
+#define __KNOWIT_APP_H__
+#include <kuniqueapplication.h>
+
+class KnowitApplication : public KUniqueApplication
+{
+Q_OBJECT
+
+public:
+ KnowitApplication(bool allowStyles = true, bool GUIEnabled = true);
+ ~KnowitApplication();
+ /** Commits all Application-relevant data on shutdown.
+ *
+ * This function is called when the QSessionManager wants to close the
+ * Application. It is reimplemented to set the boolean sessionClose flag.
+ *
+ * @param sm The QSessionManager object.
+ */
+ virtual void commitData(QSessionManager& sm);
+ /** Returns TRUE if the Application is closed by the session manager. */
+ bool closeByLogout() {return(mcloseByLogout);}
+
+private:
+ bool mcloseByLogout;
+};
+
+#endif
+
diff --git a/src/knowitchooser.cpp b/src/knowitchooser.cpp
new file mode 100644
index 0000000..61e6542
--- /dev/null
+++ b/src/knowitchooser.cpp
@@ -0,0 +1,85 @@
+/***************************************************************************
+ knowitchooser.cpp - description
+ -------------------
+ begin : pi? lut 14 2003
+ copyright : (C) 2003 by Micha? Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "knowitchooser.h"
+
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qvbox.h>
+
+#include <kcombobox.h>
+#include <klocale.h>
+
+
+KnowitChooser::KnowitChooser(int flags)
+ : KDialogBase(Plain, i18n("Export"), Ok|Cancel, Ok)
+{
+ QLabel* l1;
+ QLabel* l2;
+ QVBoxLayout* layout = new QVBoxLayout(plainPage());
+ layout->addWidget(l1 = new QLabel(i18n("&Exported notes:"), plainPage()));
+ layout->addWidget(notes = new KComboBox(plainPage(), "Notes"));
+ l1->setBuddy(notes);
+ notes->insertItem(i18n("All"));
+ notes->insertItem(i18n("Current with children"));
+ notes->insertItem(i18n("Current only"));
+
+ layout->addWidget(l2 = new QLabel(i18n("&Encoding:"), plainPage()));
+ layout->addWidget(charset = new KComboBox(plainPage(), "Encoding"));
+ l2->setBuddy(charset);
+ charset->insertItem(i18n("Local (8-bit)"));
+ charset->insertItem(i18n("UTF-8"));
+
+ layout->addItem(new QSpacerItem(0, 10));
+ layout->addWidget(enumerate = new QCheckBox(i18n("Numbered titles"),
+ plainPage(), "Numbered"));
+ layout->addWidget(toc = new QCheckBox(i18n("Table of contents"),
+ plainPage(), "TOC"));
+ layout->addWidget(rule = new QCheckBox(i18n("Rule betweeen notes"),
+ plainPage(), "Rule"));
+ layout->addWidget(style = new QCheckBox(i18n("Use editor font and colors"),
+ plainPage(), "Style"));
+ setChoice(flags);
+}
+
+KnowitChooser::~KnowitChooser()
+{
+}
+
+int KnowitChooser::getChoice() const
+{
+ int flags = 2 - notes->currentItem();
+ if (charset->currentItem() == 1) flags = flags | UseUTF8;
+ if (enumerate->isChecked()) flags = flags | Enumerate;
+ if (toc->isChecked()) flags = flags | TOC;
+ if (rule->isChecked()) flags = flags | AddRule;
+ if (style->isChecked()) flags = flags | Style;
+ return flags;
+}
+
+void KnowitChooser::setChoice(int flags)
+{
+ if (flags & SaveAll) notes->setCurrentItem(0);
+ else if (flags & SaveSubnotes) notes->setCurrentItem(1);
+ else notes->setCurrentItem(2);
+ charset->setCurrentItem((flags & UseUTF8) != 0);
+ enumerate->setChecked(flags & Enumerate);
+ toc->setChecked(flags & TOC);
+ rule->setChecked(flags & AddRule);
+ style->setChecked(flags & Style);
+}
diff --git a/src/knowitchooser.h b/src/knowitchooser.h
new file mode 100644
index 0000000..b644f3d
--- /dev/null
+++ b/src/knowitchooser.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ knowitchooser.h - description
+ -------------------
+ begin : pi? lut 14 2003
+ copyright : (C) 2003 by Micha? Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef KNOWITCHOOSER_H
+#define KNOWITCHOOSER_H
+
+#include <kdialogbase.h>
+
+class QCheckBox;
+class KComboBox;
+
+/**
+ *@author Micha³ Rudolf
+ */
+
+class KnowitChooser : public KDialogBase {
+ Q_OBJECT
+protected:
+ KComboBox* notes;
+ KComboBox* charset;
+ QCheckBox* enumerate;
+ QCheckBox* toc;
+ QCheckBox* rule;
+ QCheckBox* style;
+public:
+ enum {SaveCurrent = 0, SaveSubnotes = 0x0001, SaveAll = 0x0002, UseUTF8 = 0x0040,
+ Enumerate = 0x0080, AddRule = 0x0100, Style = 0x0200, TOC = 0x0400};
+ KnowitChooser(int flags = 0);
+ ~KnowitChooser();
+ int getChoice() const;
+ void setChoice(int flags);
+};
+
+#endif
diff --git a/src/knowitedit.cpp b/src/knowitedit.cpp
new file mode 100644
index 0000000..298d63c
--- /dev/null
+++ b/src/knowitedit.cpp
@@ -0,0 +1,66 @@
+/***************************************************************************
+ knowitedit.cpp - description
+ -------------------
+ begin : pi± maj 23 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "knowitedit.h"
+#include <kurldrag.h>
+
+KnowitEdit::KnowitEdit(const QString& text, const QString& context, QWidget* parent,
+ const char* name) : KTextEdit(text, context, parent, name), swapEOL(true)
+{
+ setAcceptDrops(true);
+}
+
+
+KnowitEdit::KnowitEdit(QWidget* parent, const char* name) : KTextEdit(parent, name),
+ swapEOL(true)
+{
+
+}
+
+void KnowitEdit::keyPressEvent(QKeyEvent* e)
+{
+ if (swapEOL &&
+ (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) &&
+ (e->state() | (Qt::NoButton | Qt::ControlButton | Qt::Keypad) ==
+ (Qt::NoButton | Qt::ControlButton | Qt::Keypad))) {
+ QKeyEvent* e1 = new QKeyEvent(QKeyEvent::KeyPress, e->key(),
+ e->ascii(), e->state() ^ Qt::ControlButton, e->text(), e->isAutoRepeat(),
+ e->count());
+ e->ignore();
+ QTextEdit::keyPressEvent(e1);
+ }
+ else QTextEdit::keyPressEvent(e);
+}
+
+void KnowitEdit::contentsDragEnterEvent(QDragEnterEvent* event)
+{
+ if (KURLDrag::canDecode(event))
+ event->accept(true);
+ else QTextEdit::contentsDragEnterEvent(event);
+}
+
+void KnowitEdit::contentsDropEvent(QDropEvent* event)
+{
+ if (KURLDrag::canDecode(event)) {
+ KURL::List L;
+ KURLDrag::decode(event, L);
+ for (uint i=0; i<L.count(); i++)
+ emit textDropped(L[i].url(), L.count() > 1);
+ }
+ else QTextEdit::contentsDropEvent(event);
+}
+
diff --git a/src/knowitedit.h b/src/knowitedit.h
new file mode 100644
index 0000000..f391468
--- /dev/null
+++ b/src/knowitedit.h
@@ -0,0 +1,38 @@
+/***************************************************************************
+ knowitedit.h - description
+ -------------------
+ begin : pi± maj 23 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef __KNOWIT_EDIT_H__
+#define __KNOWIT_EDIT_H__
+#include <ktextedit.h>
+
+class KnowitEdit : public KTextEdit
+{
+ Q_OBJECT
+public:
+ bool swapEOL;
+ KnowitEdit(const QString& text, const QString& context=QString::null,
+ QWidget* parent=0, const char* name = 0);
+ KnowitEdit(QWidget* parent=0, const char* name = 0);
+ virtual void keyPressEvent(QKeyEvent* e);
+ virtual void contentsDragEnterEvent(QDragEnterEvent* event);
+ virtual void contentsDropEvent(QDropEvent* event);
+signals:
+ void textDropped(const QString& s, int flags);
+};
+
+
+#endif
+
diff --git a/src/knowitlink.cpp b/src/knowitlink.cpp
new file mode 100644
index 0000000..7aa3a7f
--- /dev/null
+++ b/src/knowitlink.cpp
@@ -0,0 +1,101 @@
+/***************************************************************************
+ knowitlink.cpp - description
+ -------------------
+ begin : pi± cze 27 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "knowitlink.h"
+#include "notes.h"
+
+#include <qtoolbutton.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qvbox.h>
+
+#include <kfiledialog.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kcombobox.h>
+#include <klineedit.h>
+
+KnowitLinkDialog::KnowitLinkDialog()
+ : KDialogBase(Plain, i18n("Modify link"), Ok|Cancel, Ok)
+{
+ QVBoxLayout* layout = new QVBoxLayout(plainPage());
+
+ QHBox* typeBox = new QHBox(plainPage());
+ layout->addWidget(typeBox);
+ new QLabel(i18n("Referenced item:"), typeBox);
+ linkType = new KComboBox(typeBox, "LinkType");
+ linkType->insertItem(i18n("File or URL"));
+ linkType->insertItem(i18n("KnowIt note"));
+
+ layout->addItem(new QSpacerItem(0, 5));
+ QHBox* editBox = new QHBox(plainPage());
+ layout->addWidget(editBox);
+ linkValue = new KLineEdit("Link text", editBox);
+ linkValue->setMinimumWidth(300);
+ browse = new QToolButton(editBox, "Browse");
+ browse->setIconSet(QIconSet(KGlobal::iconLoader()->loadIcon("fileopen",
+ KIcon::Toolbar, KIcon::SizeSmall)));
+
+ layout->addItem(new QSpacerItem(0, 5));
+ layout->addWidget(new QLabel(i18n("Link description:"), plainPage()));
+ layout->addWidget(linkDescription = new KLineEdit("Link description", plainPage()));
+
+ connect(browse, SIGNAL(clicked()), this, SLOT(slotBrowse()));
+ connect(linkType, SIGNAL(activated(int)), this, SLOT(slotTypeChanged(int)));
+}
+
+KnowitLinkDialog::~KnowitLinkDialog()
+{
+}
+
+bool KnowitLinkDialog::modifyLink(TNoteLink& link)
+{
+ linkDescription->setText(link.description);
+ linkType->setCurrentItem(link.isLocalReference());
+ if (link.isLocalReference())
+ linkValue->setText(link.link.remove(0, 9));
+ else
+ linkValue->setText(link.link);
+ slotTypeChanged(linkType->currentItem());
+ if (exec() == QDialog::Accepted) {
+ link.description = linkDescription->text();
+ if (linkType->currentItem())
+ link.link = "knowit://" + linkValue->text();
+ else
+ link.link = linkValue->text();
+ return true;
+ }
+ else
+ return false;
+}
+
+void KnowitLinkDialog::slotBrowse()
+{
+ KURL url=KFileDialog::getOpenURL(QString::null,
+ i18n("*|All files"), this, i18n("Choose link..."));
+ if (!url.isEmpty()) {
+ linkValue->setText(url.url());
+ linkType->setCurrentItem(0);
+ }
+}
+
+void KnowitLinkDialog::slotTypeChanged(int index)
+{
+ browse->setEnabled(!index);
+}
+
diff --git a/src/knowitlink.h b/src/knowitlink.h
new file mode 100644
index 0000000..2c9b712
--- /dev/null
+++ b/src/knowitlink.h
@@ -0,0 +1,45 @@
+/***************************************************************************
+ knowitlink.h - description
+ -------------------
+ begin : pi± cze 27 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef __KNOWITLINK_H__
+#define __KNOWITLINK_H__
+
+#include <kdialogbase.h>
+
+class KComboBox;
+class KLineEdit;
+class TNoteLink;
+class QToolButton;
+
+class KnowitLinkDialog : public KDialogBase {
+ Q_OBJECT
+protected:
+ KComboBox* linkType;
+ KLineEdit* linkValue;
+ KLineEdit* linkDescription;
+ QToolButton* browse;
+public:
+ KnowitLinkDialog();
+ ~KnowitLinkDialog();
+ bool modifyLink(TNoteLink& link);
+public slots:
+ void slotBrowse();
+ void slotTypeChanged(int index);
+};
+
+
+#endif
diff --git a/src/knowitlinks.cpp b/src/knowitlinks.cpp
new file mode 100644
index 0000000..daab0bb
--- /dev/null
+++ b/src/knowitlinks.cpp
@@ -0,0 +1,56 @@
+/***************************************************************************
+ knowitlinks.cpp - description
+ -------------------
+ begin : nie gru 21 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "knowitlinks.h"
+#include <qevent.h>
+#include <kurldrag.h>
+
+KnowitLinks::KnowitLinks(QWidget* parent, const char* name)
+ : KListBox(parent, name)
+{
+ setAcceptDrops(true);
+}
+
+void KnowitLinks::dragEnterEvent(QDragEnterEvent* event)
+{
+ event->accept(KURLDrag::canDecode(event));
+}
+
+void KnowitLinks::dropEvent(QDropEvent* event)
+{
+ if (KURLDrag::canDecode(event)) {
+ KURL::List L;
+ KURLDrag::decode(event, L);
+ for (uint i=0; i<L.count(); i++)
+ emit textDropped(L[i].url(), L.count() > 1);
+ }
+}
+
+void KnowitLinks::keyPressEvent(QKeyEvent* e)
+{
+ if (currentItem() != -1 && (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)) {
+ e->ignore();
+ if ((e->state() | Qt::NoButton | Qt::Keypad) ==
+ (Qt::NoButton | Qt::Keypad)) emit linkOpen();
+ else emit linkOpenWith();
+ }
+ else if (currentItem() != -1 && e->key() == Qt::Key_Delete) {
+ e->ignore();
+ emit linkRemove();
+ }
+ else KListBox::keyPressEvent(e);
+}
diff --git a/src/knowitlinks.h b/src/knowitlinks.h
new file mode 100644
index 0000000..24606a7
--- /dev/null
+++ b/src/knowitlinks.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ knowitlinks.h - description
+ -------------------
+ begin : nie gru 21 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef __KNOWIT_LINKS_H__
+#define __KNOWIT_LINKS_H__
+#include <klistbox.h>
+
+class QDropEvent;
+class QKeyEvent;
+class QDragEnterEvent;
+
+class KnowitLinks : public KListBox
+{
+ Q_OBJECT
+public:
+ KnowitLinks(QWidget* parent=0, const char* name = 0);
+protected:
+ virtual void dragEnterEvent(QDragEnterEvent* event);
+ virtual void dropEvent(QDropEvent* event);
+ virtual void keyPressEvent(QKeyEvent* e);
+signals:
+ void textDropped(const QString& s, int flags);
+ void linkRemove();
+ void linkOpen();
+ void linkOpenWith();
+};
+
+#endif
+
diff --git a/src/knowitpref.cpp b/src/knowitpref.cpp
new file mode 100644
index 0000000..8f089c9
--- /dev/null
+++ b/src/knowitpref.cpp
@@ -0,0 +1,392 @@
+/***************************************************************************
+ knowitpref.cpp - description
+ -------------------
+ begin : czw lis 28 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "knowitpref.h"
+
+
+#include <qcheckbox.h>
+#include <qcolor.h>
+#include <qtoolbutton.h>
+#include <qspinbox.h>
+#include <qdatetime.h>
+#include <qlayout.h>
+#include <qwhatsthis.h>
+#include <qstring.h>
+#include <qlabel.h>
+#include <qvbox.h>
+
+#include <kconfig.h>
+#include <kcombobox.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kdeversion.h>
+#include <kfontdialog.h>
+#include <klineedit.h>
+#include <kcolorbutton.h>
+#include <kdualcolorbutton.h>
+
+void KnowitOptions::save(KConfig* config) const
+{
+ config->setGroup("KDE");
+ config->writeEntry("MultipleInstances", multipleInstances);
+ config->setGroup("General");
+ config->writeEntry("Docked", docked);
+ config->writeEntry("Autosave", autosave);
+ config->writeEntry("Reopen", reopen);
+ config->writeEntry("HorizontalSplit", horizontalSplit);
+ config->writeEntry("UnconditionalSave", unconditionalSave);
+ config->writeEntry("Backup", backup);
+ config->writeEntry("DefaultName", defaultName);
+ config->writeEntry("AlternateTree", alternateTree);
+ config->writeEntry("AlternateColor", alternateColor);
+ config->writeEntry("AutoCollapse", autoCollapse);
+
+ config->setGroup("Links");
+ config->writeEntry("First", firstLink);
+ config->writeEntry("Format", linkFormat);
+
+ config->setGroup("Editor");
+ config->writeEntry("WordWrap", wordwrap);
+ config->writeEntry("EnterBreakLine", enterBreakLine);
+ config->writeEntry("TabFocus", tabfocus);
+ config->writeEntry("CustomColors", customColors);
+ config->writeEntry("ForeEditColor", foreEditColor);
+ config->writeEntry("BackEditColor", backEditColor);
+ config->writeEntry("CustomFont", customFont);
+ config->writeEntry("FontFamily", fontFamily);
+ config->writeEntry("FontSize", fontSize);
+
+ config->setGroup("Templates");
+ config->writeEntry("InsertDateFormatString", insertDateFormat);
+ config->writeEntry("InsertDateColor", insertDateColor);
+ config->writeEntry("InsertDateBold", insertDateBold);
+ config->writeEntry("InsertDateItalic", insertDateItalic);
+ config->writeEntry("InsertDateUnderline", insertDateUnderline);
+
+ config->setGroup("Export");
+ config->writeEntry("Flags", exportFlags);
+
+}
+
+
+void KnowitOptions::read(KConfig* config)
+{
+ config->setGroup("KDE");
+ multipleInstances = config->readBoolEntry("MultipleInstances", true);
+ config->setGroup("General");
+ docked = config->readBoolEntry("Docked", false);
+ autosave = config->readNumEntry("Autosave", 0);
+ reopen = config->readBoolEntry("Reopen", true);
+ horizontalSplit = config->readNumEntry("HorizontalSplit", true);
+ defaultName = config->readEntry("DefaultName", i18n("New note"));
+ alternateTree = config->readBoolEntry("AlternateTree", false);
+ alternateColor = config->readEntry("AlternateColor", QString("LightYellow"));
+ autoCollapse = config->readBoolEntry("AutoCollapse", false);
+ unconditionalSave = config->readBoolEntry("UnconditionalSave", false);
+ backup = config->readBoolEntry("Backup", true);
+
+ config->setGroup("Links");
+ firstLink = config->readBoolEntry("First", true);
+ linkFormat = config->readNumEntry("Format", 0);
+
+ config->setGroup("Editor");
+ wordwrap = config->readBoolEntry("WordWrap", true);
+ enterBreakLine = config->readBoolEntry("EnterBreakLine", true);
+ tabfocus = config->readBoolEntry("TabFocus", false);
+ customColors = config->readBoolEntry("CustomColors", false);
+ foreEditColor = config->readEntry("ForeEditColor", QString("Black"));
+ backEditColor = config->readEntry("BackEditColor", QString("White"));
+ customFont = config->readBoolEntry("CustomFont", false);
+ fontFamily = config->readEntry("FontFamily", QString("Helvetica"));
+ fontSize = config->readNumEntry("FontSize", 10); // KDE-Default?
+
+ config->setGroup("Templates");
+ insertDateFormat = config->readEntry("InsertDateFormatString", QString("ddd d MMM yyyy, hh:mm:ss"));
+ insertDateColor = config->readEntry("InsertDateColor", QString("Blue"));
+ insertDateBold = config->readBoolEntry("InsertDateBold", false);
+ insertDateItalic = config->readBoolEntry("InsertDateItalic", true);
+ insertDateUnderline = config->readBoolEntry("InsertDateUnderline", false);
+
+ config->setGroup("Export");
+ exportFlags = config->readNumEntry("Flags", 0);
+}
+
+
+
+KnowitPreferences::KnowitPreferences()
+ : KDialogBase(IconList, i18n("KnowIt Preferences"), Ok|Cancel, Ok)
+{
+ QFrame* page;
+ QVBoxLayout* layout;
+
+ /* first page: General */
+ page = addPage(i18n("General"), i18n("General options"),
+ KGlobal::iconLoader()->loadIcon(QString("configure"), KIcon::Toolbar, KIcon::SizeMedium));
+ layout = new QVBoxLayout(page, 0, spacingHint());
+ layout->addWidget(docked = new QCheckBox(i18n("&Dock in System tray"), page, "Dock"));
+ layout->addWidget(reopen = new QCheckBox(i18n("Open &last file on startup"), page, "Reopen"));
+
+ QHBox* autosaveBox = new QHBox(page);
+ layout->addWidget(autosaveBox);
+ new QLabel(i18n("Autosave:"), autosaveBox);
+ autosave = new QSpinBox(0, 120, 5, autosaveBox, "Autosave");
+ autosave->setPrefix(i18n("every "));
+ autosave->setSuffix(i18n(" min."));
+ autosave->setSpecialValueText(i18n("Never"));
+ QWhatsThis::add(autosave, i18n("Current file will be automatically saved "
+ "after the specified interval. Set to <i>never</i> to disable autosave."));
+
+ layout->addWidget(unconditionalSave = new QCheckBox(i18n("Automatically save file on e&xit"),
+ page, "UnconditionalSave"));
+ QWhatsThis::add(unconditionalSave, i18n("Current file will be automatically saved "
+ "on exit without confirmation."));
+ layout->addWidget(backup = new QCheckBox(i18n("Create &backups"),
+ page, "Backup"));
+ QWhatsThis::add(backup, i18n("Create backup of current document before it is saved."));
+ layout->addWidget(multipleInstances = new QCheckBox(i18n("Allow &multiple instances of KnowIt"),
+ page, "Instances"));
+ QWhatsThis::add(multipleInstances, i18n("If this option is disabled, only one "
+ "instance of KnowIt will be allowed. If there is another instance already running, "
+ "it will be automatically activated instead of running new one."));
+ layout->addStretch(1);
+
+
+ /* second page: Interface */
+ page = addPage(i18n("Interface"), i18n("Interface options"),
+ KGlobal::iconLoader()->loadIcon(QString("misc"), KIcon::Toolbar, KIcon::SizeMedium));
+ layout = new QVBoxLayout(page, 0, spacingHint());
+ layout->addWidget(horizontalSplit = new QCheckBox(i18n("Split window &horizontally"), page, "Split"));
+ QWhatsThis::add(horizontalSplit, i18n("If this option is set, notes tree will "
+ "be displayed on the left and the editor on the right (this is default).<br>"
+ "Otherwise notes tree will be displayed at the top and the editor at the bottom."));
+
+ QHBox* defaultNameBox = new QHBox(page);
+ layout->addWidget(defaultNameBox);
+ new QLabel(i18n("Default note name:"), defaultNameBox);
+ defaultName = new KLineEdit(defaultNameBox, "DefaultName");
+ QWhatsThis::add(defaultName, i18n("Default name for new notes. It would be "
+ "autoselected, so if you often copy text using mouse selection, you may "
+ "consider setting default name to none."));
+
+ QHBox* linkBox = new QHBox(page);
+ layout->addWidget(linkBox);
+ new QLabel(i18n("Link format:"), linkBox);
+ linkFormat = new KComboBox(linkBox, "LinkFormat");
+ linkFormat->insertItem(i18n("Description (link)"));
+ linkFormat->insertItem(i18n("Link (description)"));
+ linkFormat->insertItem(i18n("Link only"));
+ linkFormat->insertItem(i18n("Description only"));
+
+ QHBox* alternateBox = new QHBox(page);
+ layout->addWidget(alternateBox);
+ alternateTree = new QCheckBox(i18n("Alternate colors in tree"), alternateBox, "Alternate");
+ alternateColor = new KColorButton(QColor("White"), alternateBox, "AlternateColor");
+
+ layout->addWidget(autoCollapse = new QCheckBox(i18n("Automatically collapse other notes"), page, "AutoCollapse"));
+ QWhatsThis::add(autoCollapse, i18n("If this option is set, only current subtree "
+ "will be visible, other notes will be automatically collapsed."));
+ layout->addStretch(1);
+
+
+ /* third page: Editor */
+ page = addPage(i18n("Editor"), i18n("Editor options"),
+ KGlobal::iconLoader()->loadIcon(QString("edit"), KIcon::Toolbar, KIcon::SizeMedium));
+ layout = new QVBoxLayout(page, 0, spacingHint());
+ layout->addWidget(wordwrap = new QCheckBox(i18n("Use &word wrap"),
+ page, "WordWrap"));
+ layout->addWidget(enterBreakLine = new QCheckBox(i18n("'Enter' ends current line, not paragraph"),
+ page, "EnterLineBreak"));
+ layout->addWidget(tabfocus = new QCheckBox(i18n("'Tab' in editor changes focus"),
+ page, "TabFocus"));
+#if KDE_VERSION_MAJOR == 3 && KDE_VERSION_MINOR < 1
+ tabfocus->hide();
+#endif
+ QHBox* colorBox = new QHBox(page);
+ layout->addWidget(colorBox);
+ customColors = new QCheckBox(i18n("Use &custom colors"), colorBox, "CustomColors");
+ editColors = new KDualColorButton(colorBox);
+
+ const char fontSizes[] = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,24,26,28,32,48,64,0};
+ QStringList fontList;
+ KFontChooser::getFontList(fontList, false);
+
+ QHBox* fontBox = new QHBox(page);
+ layout->addWidget(fontBox);
+ customFont = new QCheckBox(i18n("Use custom font:"), fontBox, "customFont");
+ fontFamily = new KComboBox(true, fontBox);
+ fontFamily->insertStringList(fontList);
+ fontSize = new KComboBox(true, fontBox);
+ for( int i=0; fontSizes[i] != 0; i++ ){
+ fontSize->insertItem(QString().setNum(fontSizes[i]),i);
+ }
+
+ layout->addStretch(1);
+
+
+ /* fourth page: Templates */
+ page = addPage(i18n("Templates"), i18n("Templates configuration"),
+ KGlobal::iconLoader()->loadIcon(QString("wizard"), KIcon::Toolbar, KIcon::SizeMedium));
+ layout = new QVBoxLayout(page, 0, spacingHint());
+ QWhatsThis::add(page, i18n("<html>\n"
+"<p>These expressions may be used: </p>\n"
+"<table>\n"
+"<tr><th>d</th><td>the day as number without a leading zero (1-31)</td></tr>\n"
+"<tr><th>dd</th><td>the day as number with a leading zero (01-31)</td></tr>\n"
+"<tr><th>ddd</th><td>the abbreviated localized day name (e.g. 'Mon'..'Sun')</td></tr>\n"
+"<tr><th>dddd</th><td>the long localized day name (e.g. 'Monday'..'Sunday')</td></tr>\n"
+"<tr><th>M</th><td>the month as number without a leading zero (1-12)</td></tr>\n"
+"<tr><th>MM</th><td>the month as number with a leading zero (01-12)</td></tr>\n"
+"<tr><th>MMM</th><td>the abbreviated localized month name (e.g. 'Jan'..'Dec')</td></tr>\n"
+"<tr><th>MMMM</th><td>the long localized month name (e.g. 'January'..'December')</td></tr>\n"
+"<tr><th>yy</th><td>the year as two digit number (00-99)</td></tr>\n"
+"<tr><th>yyyy</th><td>the year as four digit number (1752-8000)</td></tr>\n"
+"<tr><th>h</th><td>the hour without a leading zero (0..23 or 1..12 if AM/PM display)</td></tr>\n"
+"<tr><th>hh</th><td>the hour with a leading zero (00..23 or 01..12 if AM/PM display)</td></tr>\n"
+"<tr><th>m</th><td>the minute without a leading zero (0..59)</td></tr>\n"
+"<tr><th>mm</th><td>the minute with a leading zero (00..59)</td></tr>\n"
+"<tr><th>s</th><td>the second without a leading zero (0..59)</td></tr>\n"
+"<tr><th>ss</th><td>the second with a leading zero (00..59)</td></tr>\n"
+"<tr><th>AP</th><td>use AM/PM display</td></tr>\n"
+"<tr><th>AP</th><td>use am/pm display</td></tr>\n"
+"</table></html>"));
+
+ QHBox* topBox = new QHBox(page);
+ layout->addWidget(topBox);
+ QLabel * label1 = new QLabel(i18n("Date Format: "), topBox);
+ label1->setFixedSize(label1->sizeHint());
+ insertDatePreview = new QLabel("", topBox);
+
+ QHBox *tmpBox = new QHBox(page);
+ layout->addWidget(tmpBox);
+ insertDateColorButton = new KColorButton(QColor("Blue"), tmpBox, "InsertDateColorButton");
+ insertDateFormatEdit = new KLineEdit(tmpBox, "InsertDateFormatEdit");
+ insertDateItalicButton = new QToolButton(tmpBox,"InsertDateItalicButton");
+ insertDateItalicButton->setIconSet(QIconSet(KGlobal::iconLoader()->loadIcon("text_italic", KIcon::Toolbar)));
+ insertDateItalicButton->setToggleButton(true);
+ insertDateBoldButton = new QToolButton(tmpBox,"InsertDateBoldButton");
+ insertDateBoldButton->setIconSet(QIconSet(KGlobal::iconLoader()->loadIcon("text_bold", KIcon::Toolbar)));
+ insertDateBoldButton->setToggleButton(true);
+ insertDateUnderlineButton = new QToolButton(tmpBox, "InsertDateUnderlineButton");
+ insertDateUnderlineButton->setIconSet(QIconSet(KGlobal::iconLoader()->loadIcon("text_under", KIcon::Toolbar)));
+ insertDateUnderlineButton->setToggleButton(true);
+ insertDateColorButton->setFixedSize(insertDateBoldButton->sizeHint());
+ insertDateFormatEdit->setMinimumWidth(6*insertDateBoldButton->sizeHint().width());
+ layout->addStretch(1);
+
+ setIconListAllVisible(true);
+}
+
+void KnowitPreferences::setOptions(const KnowitOptions& Options)
+{
+ docked->setChecked(Options.docked);
+ reopen->setChecked(Options.reopen);
+ autosave->setValue(Options.autosave);
+ unconditionalSave->setChecked(Options.unconditionalSave);
+ backup->setChecked(Options.backup);
+ multipleInstances->setChecked(Options.multipleInstances);
+
+ horizontalSplit->setChecked(Options.horizontalSplit);
+ defaultName->setText(Options.defaultName);
+ alternateTree->setChecked(Options.alternateTree);
+ alternateColor->setColor(QColor(Options.alternateColor));
+ autoCollapse->setChecked(Options.autoCollapse);
+ linkFormat->setCurrentItem(Options.linkFormat);
+
+ wordwrap->setChecked(Options.wordwrap);
+ enterBreakLine->setChecked(Options.enterBreakLine);
+ tabfocus->setChecked(Options.tabfocus);
+ customColors->setChecked(Options.customColors);
+ editColors->setForeground(QColor(Options.foreEditColor));
+ editColors->setBackground(QColor(Options.backEditColor));
+ customFont->setChecked(Options.customFont);
+ fontFamily->setCurrentText(Options.fontFamily);
+ fontSize->setCurrentText(QString().setNum(Options.fontSize));
+
+ insertDateFormatEdit->setText(Options.insertDateFormat);
+ insertDateColorButton->setColor(QColor(Options.insertDateColor));
+ insertDateBoldButton->setOn(Options.insertDateBold);
+ insertDateItalicButton->setOn(Options.insertDateItalic);
+ insertDateUnderlineButton->setOn(Options.insertDateUnderline);
+ slotUpdateDatePreview();
+ connect(insertDateColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateDatePreview()));
+ connect(insertDateFormatEdit, SIGNAL(textChanged (const QString &)), this, SLOT(slotUpdateDatePreview()));
+ connect(insertDateItalicButton, SIGNAL(toggled(bool)), this, SLOT(slotUpdateDatePreview()));
+ connect(insertDateBoldButton, SIGNAL(toggled(bool)), this, SLOT(slotUpdateDatePreview()));
+ connect(insertDateUnderlineButton, SIGNAL(toggled(bool)), this, SLOT(slotUpdateDatePreview()));
+
+ /* non-GUI options */
+ firstLink = Options.firstLink;
+ exportFlags = Options.exportFlags;
+}
+
+KnowitOptions KnowitPreferences::getOptions() const
+{
+ KnowitOptions Options;
+ Options.docked = docked->isChecked();
+ Options.reopen = reopen->isChecked();
+ Options.autosave = autosave->value();
+ Options.unconditionalSave = unconditionalSave->isChecked();
+ Options.multipleInstances = multipleInstances->isChecked();
+ Options.backup = backup->isChecked();
+
+ Options.horizontalSplit = horizontalSplit->isChecked();
+ Options.defaultName = defaultName->text();
+ Options.alternateTree = alternateTree->isChecked();
+ Options.alternateColor = alternateColor->color().name();
+ Options.autoCollapse = autoCollapse->isChecked();
+ Options.linkFormat = linkFormat->currentItem();
+
+ Options.wordwrap = wordwrap->isChecked();
+ Options.enterBreakLine = enterBreakLine->isChecked();
+ Options.tabfocus = tabfocus->isChecked();
+ Options.customColors = customColors->isChecked();
+ Options.foreEditColor = editColors->foreground().name();
+ Options.backEditColor = editColors->background().name();
+ Options.customFont = customFont->isChecked();
+ Options.fontFamily = fontFamily->currentText();
+ Options.fontSize = fontSize->currentText().toInt();
+
+ Options.insertDateFormat = insertDateFormatEdit->text();
+ Options.insertDateColor = insertDateColorButton->color().name();
+ Options.insertDateBold = insertDateBoldButton->isOn();
+ Options.insertDateItalic = insertDateItalicButton->isOn();
+ Options.insertDateUnderline = insertDateUnderlineButton->isOn();
+
+ Options.firstLink = firstLink;
+ Options.exportFlags = exportFlags;
+ return Options;
+}
+
+void KnowitPreferences::slotUpdateDatePreview()
+{
+ QString str = "<html><p align=\"center\">";
+ if(insertDateBoldButton->isOn()) str += "<b>";
+ if(insertDateItalicButton->isOn()) str +="<i>";
+ if(insertDateUnderlineButton->isOn()) str += "<u>";
+ str += "<font COLOR=\""+insertDateColorButton->color().name()+"\">";
+ str += QString("%1").arg(QDateTime::currentDateTime().toString(insertDateFormatEdit->text()));
+ str += "</font>";
+ if(insertDateUnderlineButton->isOn()) str += "</u>";
+ if(insertDateItalicButton->isOn()) str +="</i>";
+ if(insertDateBoldButton->isOn()) str += "</b>";
+ str += "</p></html>";
+ insertDatePreview->setPaletteBackgroundColor(QColor("White"));
+ insertDatePreview->setText(str);
+}
+
+
diff --git a/src/knowitpref.h b/src/knowitpref.h
new file mode 100644
index 0000000..bc74398
--- /dev/null
+++ b/src/knowitpref.h
@@ -0,0 +1,104 @@
+/***************************************************************************
+ knowitpref.h - description
+ -------------------
+ begin : czw lis 28 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef KNOWITPREF_H
+#define KNOWITPREF_H
+
+#include <qstring.h>
+#include <kdialogbase.h>
+
+class QCheckBox;
+class QSpinBox;
+class QToolButton;
+class KLineEdit;
+class KColorButton;
+class KDualColorButton;
+class KConfig;
+class KComboBox;
+
+class KnowitOptions
+{
+public:
+ /* General */
+ bool docked;
+ bool reopen;
+ int autosave;
+ bool unconditionalSave;
+ bool multipleInstances;
+ bool backup;
+ /* GUI */
+ bool horizontalSplit;
+ int linkFormat;
+ QString defaultName;
+ bool alternateTree;
+ QString alternateColor;
+ bool autoCollapse;
+ /* Links */
+ bool firstLink;
+ /* Editor */
+ bool wordwrap;
+ bool enterBreakLine;
+ bool tabfocus;
+ bool customColors;
+ QString backEditColor;
+ QString foreEditColor;
+ bool customFont;
+ QString fontFamily;
+ int fontSize;
+ /* Date format */
+ QString insertDateFormat, insertDateColor;
+ bool insertDateBold, insertDateItalic, insertDateUnderline;
+ void save(KConfig* config) const;
+ void read(KConfig* config);
+ /* Export */
+ int exportFlags;
+};
+
+
+class KnowitPreferences : public KDialogBase
+{
+Q_OBJECT
+private:
+ QCheckBox *docked, *reopen, *horizontalSplit, *multipleInstances, *backup;
+ QCheckBox *unconditionalSave;
+ QCheckBox *wordwrap, *tabfocus, *customColors;
+ KDualColorButton* editColors;
+ QCheckBox *enterBreakLine;
+ KLineEdit *defaultName;
+ QCheckBox *alternateTree;
+ KColorButton *alternateColor;
+ QCheckBox* autoCollapse;
+ QCheckBox* customFont;
+ KComboBox *fontFamily, *fontSize;
+ KComboBox *linkFormat;
+ KLineEdit *insertDateFormatEdit;
+ KColorButton *insertDateColorButton;
+ QLabel *insertDatePreview;
+ QSpinBox* autosave;
+ QToolButton *insertDateItalicButton, *insertDateBoldButton, *insertDateUnderlineButton;
+ bool firstLink;
+ int exportFlags;
+public:
+ KnowitPreferences();
+ void setOptions(const KnowitOptions& Options);
+ KnowitOptions getOptions() const;
+ public slots:
+ void slotUpdateDatePreview();
+};
+
+#endif
+
diff --git a/src/knowittray.cpp b/src/knowittray.cpp
new file mode 100644
index 0000000..b08703a
--- /dev/null
+++ b/src/knowittray.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ knowittray.cpp - description
+ -------------------
+ begin : czw lis 28 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include "knowittray.h"
+#include <kpopupmenu.h>
+#include <klocale.h>
+
+KnowitTray::KnowitTray (QWidget* parent, const char* name) :
+ KSystemTray(parent, name)
+{
+ contextMenu()->insertItem(i18n("&Undock"), parent,
+ SLOT(slotUndock()));
+}
+
+void KnowitTray::contextMenuAboutToShow (KPopupMenu* menu)
+{
+ menu->removeItemAt(menu->count()-1);
+ menu->insertItem(i18n("&Quit"), parent(), SLOT(slotFileQuit()));
+}
+
diff --git a/src/knowittray.h b/src/knowittray.h
new file mode 100644
index 0000000..023eef2
--- /dev/null
+++ b/src/knowittray.h
@@ -0,0 +1,31 @@
+/***************************************************************************
+ knowittray.h - description
+ -------------------
+ begin : czw lis 28 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef KNOWITTRAY_H
+#define KNOWITTRAY_H
+#include <ksystemtray.h>
+
+class KnowitTray : public KSystemTray
+{
+public:
+ KnowitTray(QWidget* parent=0, const char* name=0);
+protected:
+ virtual void contextMenuAboutToShow (KPopupMenu* menu);
+};
+
+#endif
+
diff --git a/src/knowittree.cpp b/src/knowittree.cpp
new file mode 100644
index 0000000..ad260fb
--- /dev/null
+++ b/src/knowittree.cpp
@@ -0,0 +1,146 @@
+/***************************************************************************
+ knowittree.cpp - description
+ -------------------
+ begin : sob gru 20 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <klocale.h>
+#include <qevent.h>
+#include <qdragobject.h>
+#include <qheader.h>
+#include <qwhatsthis.h>
+#include "knowittree.h"
+
+KnowitTree::KnowitTree(QWidget* parent, const char* name)
+ : KListView(parent, name)
+{
+ setMinimumSize(150, 150);
+ addColumn(i18n("Notes"));
+ setRootIsDecorated(true);
+ setItemsRenameable(true);
+ setDragEnabled(true);
+ setAcceptDrops(true);
+ setFullWidth(true);
+ setSorting(-1);
+ setDragAutoScroll(true);
+ prevItem = 0;
+ QWhatsThis::add(this, i18n("<h2>Notes hierarchy</h2>"
+ "Here you can browse notes tree. "
+ "You can also add notes using right-click menu, or reorganize them using "
+ "drag and drop."));
+}
+
+
+void KnowitTree::takeNode(QListViewItem* item)
+{
+ if (item->parent())
+ item->parent()->takeItem(item);
+ else
+ takeItem(item);
+}
+
+void KnowitTree::insertNode(QListViewItem* parent, QListViewItem* item, QListViewItem* after)
+{
+ if (parent)
+ parent->insertItem(item);
+ else
+ insertItem(item);
+ if (after)
+ item->moveItem(after);
+}
+
+
+void KnowitTree::contentsDragMoveEvent(QDragMoveEvent* event)
+{
+ QListViewItem* item = itemAt(event->pos());
+ /* check if on root decoration */
+ if (!item || event->pos().x() > header()->cellPos(header()->mapToActual(0)) +
+ treeStepSize() * (item->depth() + 1) + itemMargin() ||
+ event->pos().x() < header()->cellPos(header()->mapToActual(0)))
+ return;
+ if (item && item->childCount() && !item->isOpen())
+ item->setOpen(true);
+}
+
+void KnowitTree::slotCollapseAll()
+{
+ QListViewItem* it = firstChild();
+ while(it) {
+ it->setOpen(false);
+ it = it->nextSibling();
+ }
+}
+
+void KnowitTree::slotCollapse()
+{
+ if (currentItem())
+ currentItem()->setOpen(false);
+}
+
+
+void KnowitTree::slotExpandAll()
+{
+ QListViewItem* it = firstChild();
+ while(it) {
+ it->setOpen(true);
+ it = it->nextSibling();
+ }
+}
+
+void KnowitTree::slotExpand()
+{
+ if (currentItem())
+ currentItem()->setOpen(true);
+}
+
+void KnowitTree::slotItemUp()
+{
+ if (currentItem())
+ setCurrentItem(currentItem()->itemAbove());
+}
+
+void KnowitTree::slotItemDown()
+{
+ if (currentItem())
+ setCurrentItem(currentItem()->itemBelow());
+}
+
+void KnowitTree::slotItemBegin()
+{
+ setCurrentItem(firstChild());
+}
+
+void KnowitTree::slotItemEnd()
+{
+ QListViewItem* elt = firstChild();
+ if (elt)
+ while (elt->itemBelow())
+ elt = elt->itemBelow();
+ setCurrentItem(elt);
+}
+
+void KnowitTree::slotItemLeft()
+{
+ if (currentItem())
+ setCurrentItem(currentItem()->parent());
+}
+
+void KnowitTree::slotItemRight()
+{
+ if (currentItem())
+ setCurrentItem(currentItem()->firstChild());
+}
+
+
+
diff --git a/src/knowittree.h b/src/knowittree.h
new file mode 100644
index 0000000..85ba50c
--- /dev/null
+++ b/src/knowittree.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ knowittree.h - description
+ -------------------
+ begin : sob gru 20 2003
+ copyright : (C) 2003 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef __KNOWIT_TREE_H__
+#define __KNOWIT_TREE_H__
+#include <klistview.h>
+class QDragMoveEvent;
+class KnowitTree : public KListView
+{
+ Q_OBJECT
+public:
+ KnowitTree(QWidget* parent=0, const char* name = 0);
+ QListViewItem* prevItem;
+ void takeNode(QListViewItem* item);
+ void insertNode(QListViewItem* parent, QListViewItem* item, QListViewItem* after = 0);
+protected:
+ virtual void contentsDragMoveEvent(QDragMoveEvent* event);
+public slots:
+ /** Shows only first-level notes */
+ void slotCollapseAll();
+ /** Shows only root of selected tree */
+ void slotCollapse();
+ /** Shows all notes */
+ void slotExpandAll();
+ /** Shows all notes of selected tree */
+ void slotExpand();
+ /** Move note up */
+ void slotItemUp();
+ /** Move note down */
+ void slotItemDown();
+ /** Move note at the beginning of current list */
+ void slotItemBegin();
+ /** Move note at the end of current list */
+ void slotItemEnd();
+ /** Move note level up */
+ void slotItemLeft();
+ /** Move note level down */
+ void slotItemRight();
+};
+
+#endif
+
diff --git a/src/knowitui.rc b/src/knowitui.rc
new file mode 100644
index 0000000..10d0aef
--- /dev/null
+++ b/src/knowitui.rc
@@ -0,0 +1,187 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui name="knowit" version="1.3">
+ <MenuBar>
+ <Menu name="file">
+ <Action name="file_export_html" />
+ <Action name="file_info" />
+ </Menu>
+ <Menu name="edit">
+ <Separator />
+ <Menu name="font" icon="fonts">
+ <text>&amp;Font</text>
+ <Action name="edit_bold"/>
+ <Action name="edit_italic"/>
+ <Action name="edit_underline"/>
+ <Action name="edit_color"/>
+ <Separator/>
+ <Action name="edit_superscript"/>
+ <Action name="edit_subscript"/>
+ <Action name="edit_align_normal"/>
+ </Menu>
+ <Menu name="align">
+ <text>&amp;Paragraph</text>
+ <Action name="edit_align_left"/>
+ <Action name="edit_align_right"/>
+ <Action name="edit_align_center"/>
+ <Action name="edit_align_justify"/>
+ </Menu>
+ <Menu name="list">
+ <text>&amp;List</text>
+ <Action name="list_bullet"/>
+ <Action name="list_number"/>
+ <Action name="list_upper"/>
+ <Action name="list_lower"/>
+ <Separator />
+ <Action name="list_none"/>
+ </Menu>
+ <Action name="goto_note"/>
+ <Action name="edit_insert_date"/>
+ <Action name="edit_insert_file"/>
+ <Action name="edit_raw_text"/>
+ </Menu>
+ <Menu name="notes">
+ <text>&amp;Notes</text>
+ <Action name="note_add"/>
+ <Action name="note_add_child"/>
+ <Action name="note_delete"/>
+ <Action name="note_rename"/>
+ <Menu name="position">
+ <text>&amp;Position</text>
+ <Action name="note_move_up" />
+ <Action name="note_move_down" />
+ <Action name="note_move_left" />
+ <Action name="note_move_right" />
+ <Action name="note_move_begin" />
+ <Action name="note_move_end" />
+ <Action name="note_sort" />
+ </Menu>
+ <Menu name="tree">
+ <text>&amp;Tree</text>
+ <Action name="note_expand_all"/>
+ <Action name="note_expand"/>
+ <Action name="note_collapse_all"/>
+ <Action name="note_collapse"/>
+ </Menu>
+ </Menu>
+ <Menu name="links">
+ <text>&amp;Links</text>
+ <Action name="link_add"/>
+ <Action name="link_remove"/>
+ <Action name="link_open"/>
+ <Action name="link_open_with"/>
+ <Action name="link_modify"/>
+ <Action name="link_description"/>
+ <Action name="link_copy"/>
+ </Menu>
+ <Menu name="settings">
+ </Menu>
+ <Menu name="help">
+ <Action name="help_tip" />
+ </Menu>
+ </MenuBar>
+ <Menu name="links_popup">
+ <text>&amp;Links</text>
+ <Action name="link_add"/>
+ <Action name="link_remove"/>
+ <Action name="link_open"/>
+ <Action name="link_open_with"/>
+ <Action name="link_modify"/>
+ <Action name="link_copy"/>
+ </Menu>
+ <Menu name="notes_popup">
+ <text>&amp;Notes</text>
+ <Action name="note_add"/>
+ <Action name="note_add_child"/>
+ <Action name="note_delete"/>
+ <Action name="note_rename"/>
+ <Menu name="position">
+ <text>&amp;Position</text>
+ <Action name="note_move_up" />
+ <Action name="note_move_down" />
+ <Action name="note_move_left" />
+ <Action name="note_move_right" />
+ <Action name="note_move_begin" />
+ <Action name="note_move_end" />
+ <Action name="note_sort" />
+ </Menu>
+ <Menu name="tree">
+ <text>&amp;Tree</text>
+ <Action name="note_expand_all"/>
+ <Action name="note_expand"/>
+ <Action name="note_collapse_all"/>
+ <Action name="note_collapse"/>
+ </Menu>
+ </Menu>
+ <ToolBar name="edit">
+ <text>Edit toolbar</text>
+ <Action name="edit_bold"/>
+ <Action name="edit_italic"/>
+ <Action name="edit_underline"/>
+ <Action name="edit_color"/>
+ <Separator />
+ <Action name="edit_align_left"/>
+ <Action name="edit_align_right"/>
+ <Action name="edit_align_center"/>
+ <Action name="edit_align_justify"/>
+ </ToolBar>
+ <ToolBar name="note">
+ <text>Notes toolbar</text>
+ <Action name="note_move_up" />
+ <Action name="note_move_down" />
+ <Action name="note_move_left" />
+ <Action name="note_move_right" />
+ <Action name="note_move_begin" />
+ <Action name="note_move_end" />
+ </ToolBar>
+ <ToolBar name="link">
+ <text>Links toolbar</text>
+ <Action name="link_add" />
+ <Action name="link_open" />
+ </ToolBar>
+ <State name="notesPresent">
+ <Enable>
+ <Action name="file_export_html" />
+ <Action name="file_info" />
+ <Action name="edit_bold"/>
+ <Action name="edit_italic"/>
+ <Action name="edit_underline"/>
+ <Action name="edit_color"/>
+ <Action name="edit_superscript"/>
+ <Action name="edit_subscript"/>
+ <Action name="edit_align_normal"/>
+ <Action name="edit_align_left"/>
+ <Action name="edit_align_right"/>
+ <Action name="edit_align_center"/>
+ <Action name="edit_align_justify"/>
+ <Action name="goto_note"/>
+ <Action name="edit_insert_date"/>
+ <Action name="edit_insert_file"/>
+ <Action name="edit_raw_text"/>
+ <Action name="note_add_child"/>
+ <Action name="note_delete"/>
+ <Action name="note_rename"/>
+ <Action name="note_move_up" />
+ <Action name="note_move_down" />
+ <Action name="note_move_left" />
+ <Action name="note_move_right" />
+ <Action name="note_move_begin" />
+ <Action name="note_move_end" />
+ <Action name="note_sort" />
+ <Action name="note_expand_all"/>
+ <Action name="note_expand"/>
+ <Action name="note_collapse_all"/>
+ <Action name="note_collapse"/>
+ <Action name="link_add"/>
+ <Action name="link_remove"/>
+ <Action name="link_open"/>
+ <Action name="link_open_with"/>
+ <Action name="link_modify"/>
+ <Action name="link_copy"/>
+ <Action name="edit_copy" />
+ <Action name="edit_cut" />
+ <Action name="edit_paste" />
+ <Action name="edit_find" />
+ <Action name="edit_find_next" />
+ </Enable>
+ </State>
+</kpartgui>
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..14734b7
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,51 @@
+/***************************************************************************
+ main.cpp - description
+ -------------------
+ begin : czw wrz 26 08:27:40 CEST 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <klocale.h>
+#include "knowit.h"
+#include "knowitapp.h"
+
+static const char *description =
+ I18N_NOOP("KnowIt - notes management utility");
+
+
+static KCmdLineOptions options[] =
+{
+ { "+file", I18N_NOOP("Document to open"), 0 },
+ { 0, 0, 0 }
+};
+
+int main(int argc, char *argv[])
+{
+ KAboutData aboutData( "knowit", I18N_NOOP("KnowIt"),
+ VERSION, description, KAboutData::License_GPL,
+ "(C) 2002-2004 Michal Rudolf", 0, 0, "mrudolf@kdewebdev.org");
+ aboutData.addAuthor("Michal Rudolf",0, "mrudolf@kdewebdev.org");
+ aboutData.setTranslator (I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"),
+ I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails"));
+
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options );
+
+ KnowitApplication a(true, true);
+
+ Knowit *knowit = new Knowit(0, "KnowIt");
+ a.setMainWidget(knowit);
+ return a.exec();
+}
diff --git a/src/notes.cpp b/src/notes.cpp
new file mode 100644
index 0000000..0c53883
--- /dev/null
+++ b/src/notes.cpp
@@ -0,0 +1,432 @@
+/***************************************************************************
+ notes.cpp - description
+ -------------------
+ begin : sob lis 16 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "notes.h"
+#include <qstringlist.h>
+#include <qfile.h>
+#include <qdatetime.h>
+#include <qtextstream.h>
+#include <qtextcodec.h>
+#include <klocale.h>
+#include <klistview.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <kmimetype.h>
+#include <krun.h>
+#include <kurl.h>
+#include <klistview.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#define VERSION "?"
+#endif
+
+
+void TNoteLink::save(QTextStream& ts) const
+{
+ if (!link.isEmpty()) {
+ ts << "\\Link " << link << "\n";
+ if (!description.isEmpty())
+ ts << "\\Descr " << description << "\n";
+ }
+}
+
+QString TNoteLink::text(int fmt) const
+{
+ if (fmt == LinkOnly || description.isEmpty()) return link;
+ else if (fmt == DescriptionOnly) return description;
+ else if (fmt == LinkDescription)
+ return QString("%1 (%2)").arg(link).arg(description);
+ else return QString("%1 (%2)").arg(description).arg(link);
+}
+
+QPixmap TNoteLink::icon() const
+{
+ return KGlobal::iconLoader()->loadIcon(KMimeType::iconForURL(KURL(link)),
+ KIcon::Small);
+}
+
+void TNoteLink::open() const
+{
+ if (!isLocalReference())
+ new KRun(KURL(link), 0, false, true);
+}
+
+void TNoteLink::openWith() const
+{
+ if (!isLocalReference())
+ KRun::displayOpenWithDialog(KURL(link));
+}
+
+bool TNoteLink::isLocalReference() const
+{
+ KURL url(link);
+ return url.protocol() == "knowit";
+}
+
+
+
+
+
+TNotesCollection::TNotesCollection()
+{
+ Pixmaps[0] = KGlobal::iconLoader()->loadIcon("ascii", KIcon::Small);
+ Pixmaps[1] = KGlobal::iconLoader()->loadIcon("txt", KIcon::Small);
+ Pixmaps[2] = KGlobal::iconLoader()->loadIcon("folder", KIcon::Small);
+ Pixmaps[3] = KGlobal::iconLoader()->loadIcon("folder_txt", KIcon::Small);
+ modified = false;
+ autoUpdate = true;
+}
+
+
+
+TNotesCollection::~TNotesCollection()
+{}
+
+void TNotesCollection::addNote(QListViewItem* item)
+{
+ insert(item, new TNote(item, this));
+ QListViewItem* parent = item->parent();
+ if (parent) find(parent)->updateView();
+ modified = true;
+}
+
+void TNotesCollection::addNote(QListViewItem* item, const QString& s)
+{
+ insert(item, new TNote(item, this, s));
+ QListViewItem* parent = item->parent();
+ if (parent) find(parent)->updateView();
+ modified = true;
+}
+
+void TNotesCollection::removeNote(QListViewItem* item)
+{
+ TNote* note = find(item);
+ if (!note) qWarning("Internal error while removing note\n");
+ else {
+ QListViewItem* parent = item->parent();
+ for (QListViewItemIterator it(item); it.current() &&
+ (it.current() == item || it.current()->depth() > item->depth()); ++it)
+ find(it.current())->destroy();
+ delete item;
+ if (parent) find(parent)->updateView();
+ modified = true;
+ }
+}
+
+bool TNotesCollection::changeNote(QListViewItem* item, const QString& s)
+{
+ TNote* changed = find(item);
+ if (!changed) {
+ qWarning("Internal error while changing note\n");
+ return false;
+ }
+ if (changed->change(s))
+ return modified = true;
+ else
+ return false;
+}
+
+void TNotesCollection::clearNotes()
+{
+ setAutoDelete(true);
+ clear();
+ setAutoDelete(false);
+}
+
+const QString& TNotesCollection::text(QListViewItem* item)
+{
+ TNote* note = find(item);
+ if (!note)
+ qFatal("Internal error while accessing note text\n");
+ return note->text;
+}
+
+void TNotesCollection::updateNotesView()
+{
+ for (QPtrDictIterator<TNote> it(*this); it.current(); ++it)
+ it.current()->updateView();
+}
+
+
+
+
+
+TNote::TNote(QListViewItem* i, TNotesCollection* coll) : text()
+{
+ collection = coll;
+ item = i;
+ updateView();
+}
+
+TNote::TNote(QListViewItem* i, TNotesCollection* coll, const QString& s) :
+ text(s)
+{
+ collection = coll;
+ item = i;
+ updateView();
+}
+
+bool TNote::isEmpty()
+{
+ return !text.length();
+}
+
+bool TNote::contains(const QString& sought, bool case_sensitive)
+{
+ return text.contains(sought, case_sensitive);
+}
+
+
+TNote::~TNote()
+{
+}
+
+void TNote::destroy()
+{
+ collection->remove(item);
+ delete this;
+}
+
+bool TNote::change(const QString& s)
+{
+ if (text == s)
+ return false;
+ text = s;
+ updateView();
+ return true;
+}
+
+TNote::State TNote::state()
+{
+ if (text.stripWhiteSpace().isEmpty())
+ return (item->childCount()) ? EmptyParent : Empty;
+ else
+ return (item->childCount()) ? TextParent : Text;
+}
+
+void TNote::updateView()
+{
+ if (collection->autoUpdate)
+ item->setPixmap(0, collection->Pixmaps[state()]);
+}
+
+bool TNote::saveHTML(const KURL& fname, const QString& origname, const QString& style,
+ int flags)
+{
+ QFile file(fname.path());
+ if (!file.open( IO_WriteOnly))
+ return false;
+ QTextStream ts(&file);
+ if (flags & UseUTF8) ts.setEncoding(QTextStream::UnicodeUTF8);
+ else ts.setEncoding(QTextStream::Locale);
+ ts << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
+ "<html>\n<head>\n <title>" << i18n("KnowIt document") <<
+ QString("</title>\n <meta http-equiv=\"Content-Type\" "
+ "content=\"text/html; charset=%1\">\n").arg(ts.codec()->mimeName());
+ if (!style.isEmpty())
+ ts << " <style type=\"text/css\">\n " << style << "\n </style>\n";
+ ts << "</head>\n\n<body>\n";
+
+ QValueVector<int> Depths;
+ Depths.append(0);
+ if (flags & TOC) {
+ ts << QString("<h1>%1</h1>\n").arg(i18n("Table of contents"));
+ saveHTMLTocEntry(ts, Depths, flags);
+ ts << "\n\n";
+ }
+
+ Depths.clear();
+ Depths.append(0);
+ saveHTMLBuf(ts, Depths, flags);
+
+ QString epilog = i18n("Exported from %1 by KnowIt %2, %3.");
+ ts << "<br><br><br><small>" << epilog.arg(origname)
+ .arg(VERSION)
+ .arg(QDateTime::currentDateTime().toString()) << "</small>\n\n";
+ ts << "</body>\n</html>\n\n";
+ return true;
+}
+
+bool TNote::saveHTMLBuf(QTextStream& ts, QValueVector<int>& depths,
+ int flags)
+{
+ int hlevel = depths.count();
+ depths.last() = depths.last()+1;
+ if (hlevel < 1) hlevel = 1;
+ else if (hlevel > 3) hlevel = 3;
+ QString id, number;
+ for (uint i=0; i<depths.count(); i++)
+ id += QString("%1.").arg(depths[i]);
+ if (flags & Enumerate)
+ number = id + " ";
+
+ ts << QString("<h%1 id=\"S%2\">%3%4</h%5>").arg(hlevel).arg(id).arg(number)
+ .arg(item->text(0)).arg(hlevel);
+ QString htmltext = text;
+ int begin = htmltext.find("<body");
+ if (begin >= 0) begin = htmltext.find(">", begin);
+ int end = htmltext.find("</body>");
+ if (begin < 0) begin = 0;
+ if (end <= begin) end = htmltext.length();
+ ts << htmltext.mid(begin+1, end-begin-1);
+
+ /* save links */
+ for (QValueList<TNoteLink>::Iterator LinkList = links.begin();
+ LinkList != links.end(); ++LinkList)
+ ts << QString("<a href=\"%1\">%2</a><br>\n").arg((*LinkList).link)
+ .arg((*LinkList).text(TNoteLink::DescriptionOnly));
+
+ /* save rule */
+ if (flags & AddRule) ts << "<hr size=\"1\" noshade>\n\n";
+ else ts << "\n\n";
+
+ /* save children */
+ if ((SaveSubnotes | SaveAll) & flags && item->childCount()) {
+ depths.append(0);
+ collection->find(item->firstChild())->saveHTMLBuf(ts, depths, flags);
+ }
+ if ((SaveSubnotes | SaveAll) & flags && item->nextSibling())
+ collection->find(item->nextSibling())->saveHTMLBuf(ts, depths, flags);
+
+ if (!item->nextSibling()) depths.pop_back();
+ return true;
+}
+
+bool TNote::saveHTMLTocEntry(QTextStream& ts, QValueVector<int>& depths, int flags)
+{
+ QString space;
+ space.fill(' ', depths.count());
+ depths.last() = depths.last()+1;
+ if (depths.last() == 1) {
+ ts << space;
+ if (depths.count() != 1) ts << "<dd>";
+ ts << "<dl>\n";
+ }
+
+ QString id, number;
+ for (uint i=0; i<depths.count(); i++)
+ id += QString("%1.").arg(depths[i]);
+ if (flags & Enumerate) number = id + " ";
+
+ ts << space;
+ ts << QString("<dt><a href=\"#S%1\">%2%3</a></dt>\n").arg(id).arg(number).
+ arg(item->text(0));
+ if ((SaveSubnotes | SaveAll) & flags && item->childCount()) {
+ depths.append(0);
+ collection->find(item->firstChild())->saveHTMLTocEntry(ts, depths, flags);
+ }
+ if ((SaveSubnotes | SaveAll) & flags && item->nextSibling())
+ collection->find(item->nextSibling())->saveHTMLTocEntry(ts, depths, flags);
+ if (!item->nextSibling()) {
+ depths.pop_back();
+ ts << space;
+ ts << "</dl>";
+ if (depths.count()) ts << "</dd>";
+ ts << "\n";
+ }
+ return true;
+}
+
+void TNote::addLink(const QString& s)
+{
+ links.append(TNoteLink(s));
+ collection->modified = true;
+}
+
+void TNote::addLink(const TNoteLink& l)
+{
+ links.append(l);
+ collection->modified = true;
+}
+
+void TNote::removeLink(int i)
+{
+ links.remove(links[i]);
+ collection->modified = true;
+}
+
+void TNote::modifyLink(int i, const QString& s)
+{
+ links[i].link = s;
+ collection->modified = true;
+}
+
+void TNote::modifyLink(int i, TNoteLink& l)
+{
+ if (l != links[i])
+ collection->modified = true;
+ links[i] = l;
+}
+
+void TNote::modifyLinkDescription(int i, const QString& s)
+{
+ links[i].description = s;
+ collection->modified = true;
+}
+
+int TNote::linkCount() const
+{
+ return links.count();
+}
+
+const TNoteLink& TNote::link(int i) const
+{
+ return links[i];
+}
+
+
+void TNote::save(QTextStream& ts, bool current)
+{
+ const QString header = "\\NewEntry %1 %2\n";
+ const QString activeheader = "\\CurrentEntry %1 %2\n";
+
+ if (current)
+ ts << activeheader.arg(item->depth()).arg(item->text(0));
+ else
+ ts << header.arg(item->depth()).arg(item->text(0));
+ for (QValueList<TNoteLink>::Iterator LinkList = links.begin();
+ LinkList != links.end(); ++LinkList)
+ (*LinkList).save(ts);
+ ts << text;
+ if (!text.isEmpty())
+ ts << '\n';
+ ts << '\n';
+}
+
+void TNote::open(QTextStream& ts)
+{
+ QString s;
+ text = "";
+ links.clear();
+
+ while (true) {
+ s = ts.readLine();
+ if (s.isNull() || s.isEmpty())
+ break;
+ if (s.left(6) == "\\Link ")
+ addLink(s.mid(6));
+ else if (s.left(7) == "\\Descr " && links.count())
+ modifyLinkDescription(links.count()-1, s.mid(7));
+ else {
+ if (text.length())
+ text += '\n';
+ text += s;
+ }
+ }
+}
diff --git a/src/notes.h b/src/notes.h
new file mode 100644
index 0000000..e91c7e1
--- /dev/null
+++ b/src/notes.h
@@ -0,0 +1,106 @@
+/***************************************************************************
+ notes.h - description
+ -------------------
+ begin : sob lis 16 2002
+ copyright : (C) 2002-2004 by Micha³ Rudolf
+ email : mrudolf@kdewebdev.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef KNOWIT_NOTES_H
+#define KNOWIT_NOTES_H
+
+#include <qstring.h>
+#include <qpixmap.h>
+#include <qvaluelist.h>
+#include <qvaluevector.h>
+#include <qptrdict.h>
+class QTextStream;
+class QListViewItem;
+class KURL;
+
+class TNote;
+
+class TNoteLink
+{
+public:
+ enum {DescriptionLink, LinkDescription, LinkOnly, DescriptionOnly};
+ QString link;
+ QString description;
+ TNoteLink() {}
+ TNoteLink(const QString& s) {link = s;}
+ TNoteLink(const QString& s1, const QString& s2) {link = s1; description = s2;}
+ int operator==(const TNoteLink& N) const {return link == N.link &&
+ description == N.description;}
+ int operator!=(const TNoteLink& N) const {return link != N.link ||
+ description != N.description;}
+ void save(QTextStream& ts) const;
+ void open() const;
+ void openWith() const;
+ QString text(int fmt = DescriptionLink) const;
+ QPixmap icon() const;
+ bool isLocalReference() const;
+};
+
+
+class TNotesCollection : public QPtrDict<TNote> {
+public:
+ QPixmap Pixmaps[4];
+ TNotesCollection();
+ ~TNotesCollection();
+ void addNote(QListViewItem* item);
+ void addNote(QListViewItem* item, const QString& s);
+ void removeNote(QListViewItem* item);
+ bool changeNote(QListViewItem* item, const QString& s);
+ void clearNotes();
+ void updateNotesView();
+ bool modified;
+ bool autoUpdate;
+ const QString& text(QListViewItem* item);
+};
+
+
+class TNote {
+private:
+ QValueList<TNoteLink> links;
+ TNotesCollection* collection;
+ bool saveHTMLBuf(QTextStream& ts, QValueVector<int>& depths,
+ int flags = SaveAll);
+ bool saveHTMLTocEntry(QTextStream& ts, QValueVector<int>& depths, int flags);
+public:
+ typedef enum {Empty, Text, EmptyParent, TextParent} State;
+ enum {SaveCurrent = 0, SaveSubnotes = 0x0001, SaveAll = 0x0002, UseUTF8 = 0x0040,
+ Enumerate = 0x0080, AddRule = 0x0100, Style = 0x0200, TOC = 0x0400};
+ QListViewItem* item;
+ QString text;
+ bool isEmpty();
+ bool contains(const QString& sought, bool case_sensitive = false);
+ bool change(const QString& s);
+ void destroy();
+ void updateView();
+ State state();
+ void open(QTextStream& ts);
+ void save(QTextStream& ts, bool current = false);
+ bool saveHTML(const KURL& fname, const QString& origname, const QString& style,
+ int flags = SaveAll);
+ void addLink(const QString& s);
+ void addLink(const TNoteLink& l);
+ int linkCount() const;
+ const TNoteLink& link(int i) const;
+ void removeLink(int i);
+ void modifyLink(int i, const QString& s);
+ void modifyLink(int i, TNoteLink& l);
+ void modifyLinkDescription(int i, const QString& s);
+ TNote(QListViewItem* i, TNotesCollection* coll);
+ TNote(QListViewItem* i, TNotesCollection* coll, const QString& s);
+ ~TNote();
+};
+#endif
+
diff --git a/src/tips b/src/tips
new file mode 100644
index 0000000..b0be289
--- /dev/null
+++ b/src/tips
@@ -0,0 +1,63 @@
+<tip category="Editor">
+<html>
+<p>...that you can insert a breakline using <tt>Control+Enter</tt>?
+</html>
+</tip>
+
+<tip category="Application">
+<html>
+<p>...that you can create list, starting lines with <tt>*</tt>
+or <tt>-<tt>?
+</html>
+</tip>
+
+<tip category="Application">
+<html>
+<p>...that if KnowIt is docked on logout, it would be reopen and
+docked next time you start KDE?
+</html>
+</tip>
+
+<tip category="Application">
+<html>
+<p>...that you can disable toolbar using Options->Configure...?
+</html>
+</tip>
+
+<tip category="Application">
+<html>
+<p>...that you can configure all shortcuts using
+Options->Configure shortcuts?
+</html>
+</tip>
+
+<tip category="Application">
+<html>
+<p>...that you can always invoke Tip window using Help menu?
+</html>
+</tip>
+
+<tip category="Notes">
+<html>
+<p>...that you can change current note with <tt>Alt+Up</tt>,
+<tt>Alt+Down</tt>, <tt>Alt+Left</tt>, <tt>Alt+Right</tt>,
+<tt>Alt+Home</tt> and <tt>Alt+End</tt>, even if editor is active?
+</html>
+</tip>
+
+<tip category="Notes">
+<html>
+<p>...that you can move current note with <tt>Alt+Shift+Up</tt>,
+<tt>Alt+Shift+Down</tt>, <tt>Alt+Shift+Left</tt>, <tt>Alt+Shift+Right</tt>,
+<tt>Alt+Shift+Home</tt> and <tt>Alt+Shift+End</tt>, even if editor is active?
+</html>
+</tip>
+
+<tip category="Editor">
+<html>
+<p>...that you can toggle Insert Mode from normal insert to overwrite
+by either pressing <tt>Insert</tt> button or by clicking on the status
+in the status bar?
+</html>
+</tip>
+
diff --git a/src/x-knowit.desktop b/src/x-knowit.desktop
new file mode 100644
index 0000000..e060ac5
--- /dev/null
+++ b/src/x-knowit.desktop
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Comment=KnowIt
+Icon=knowit
+MimeType=application/x-knowit
+Patterns=*.kno;
+Type=MimeType