From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- knotes/.emacs-dirvars | 7 + knotes/AUTHORS | 20 + knotes/ChangeLog | 935 ++++++++++++++ knotes/KNotesAppIface.h | 215 ++++ knotes/KNotesIface.h | 103 ++ knotes/Makefile.am | 59 + knotes/README | 63 + knotes/TODO | 77 ++ knotes/icons/Makefile.am | 2 + knotes/icons/cr16-action-enum_list.png | Bin 0 -> 145 bytes knotes/icons/cr16-action-format_decreaseindent.png | Bin 0 -> 220 bytes knotes/icons/cr16-action-format_increaseindent.png | Bin 0 -> 221 bytes knotes/icons/cr16-action-knotes_alarm.png | Bin 0 -> 865 bytes knotes/icons/cr16-action-knotes_close.png | Bin 0 -> 275 bytes knotes/icons/cr16-action-knotes_date.png | Bin 0 -> 1006 bytes knotes/icons/cr16-action-knotes_delete.png | Bin 0 -> 892 bytes knotes/icons/cr16-action-text_sub.png | Bin 0 -> 195 bytes knotes/icons/cr16-action-text_super.png | Bin 0 -> 186 bytes knotes/knote.cpp | 1339 ++++++++++++++++++++ knotes/knote.h | 175 +++ knotes/knotealarmdlg.cpp | 152 +++ knotes/knotealarmdlg.h | 68 + knotes/knotebutton.cpp | 111 ++ knotes/knotebutton.h | 51 + knotes/knoteconfig.kcfg | 84 ++ knotes/knoteconfig.kcfgc | 3 + knotes/knoteconfigdlg.cpp | 245 ++++ knotes/knoteconfigdlg.h | 51 + knotes/knoteedit.cpp | 495 ++++++++ knotes/knoteedit.h | 121 ++ knotes/knotehostdlg.cpp | 90 ++ knotes/knotehostdlg.h | 60 + knotes/knoteprinter.cpp | 153 +++ knotes/knoteprinter.h | 53 + knotes/knotes.desktop | 91 ++ knotes/knotes_manager.desktop | 63 + knotes/knotesalarm.cpp | 78 ++ knotes/knotesalarm.h | 59 + knotes/knotesapp.cpp | 750 +++++++++++ knotes/knotesapp.h | 163 +++ knotes/knotesappui.rc | 35 + knotes/knotesglobalconfig.kcfg | 44 + knotes/knotesglobalconfig.kcfgc | 6 + knotes/knoteslegacy.cpp | 270 ++++ knotes/knoteslegacy.h | 46 + knotes/knotesnetrecv.cpp | 152 +++ knotes/knotesnetrecv.h | 69 + knotes/knotesnetsend.cpp | 104 ++ knotes/knotesnetsend.h | 66 + knotes/knotesui.rc | 59 + knotes/local.desktop | 59 + knotes/main.cpp | 132 ++ knotes/main.h | 41 + knotes/mig_knotes.pl | 127 ++ knotes/pics/Makefile.am | 1 + knotes/pics/hi128-app-knotes.png | Bin 0 -> 18237 bytes knotes/pics/hi16-app-knotes.png | Bin 0 -> 778 bytes knotes/pics/hi22-app-knotes.png | Bin 0 -> 1242 bytes knotes/pics/hi32-app-knotes.png | Bin 0 -> 2740 bytes knotes/pics/hi48-app-knotes.png | Bin 0 -> 5229 bytes knotes/pics/hi64-app-knotes.png | Bin 0 -> 7417 bytes knotes/pushpin.xpm | 396 ++++++ knotes/resourcelocal.cpp | 132 ++ knotes/resourcelocal.h | 75 ++ knotes/resourcelocal_plugin.cpp | 68 + knotes/resourcelocalconfig.cpp | 68 + knotes/resourcelocalconfig.h | 43 + knotes/resourcemanager.cpp | 156 +++ knotes/resourcemanager.h | 82 ++ knotes/resourcenotes.cpp | 45 + knotes/resourcenotes.h | 84 ++ knotes/version.h | 2 + 72 files changed, 8298 insertions(+) create mode 100644 knotes/.emacs-dirvars create mode 100644 knotes/AUTHORS create mode 100644 knotes/ChangeLog create mode 100644 knotes/KNotesAppIface.h create mode 100644 knotes/KNotesIface.h create mode 100644 knotes/Makefile.am create mode 100644 knotes/README create mode 100644 knotes/TODO create mode 100644 knotes/icons/Makefile.am create mode 100644 knotes/icons/cr16-action-enum_list.png create mode 100644 knotes/icons/cr16-action-format_decreaseindent.png create mode 100644 knotes/icons/cr16-action-format_increaseindent.png create mode 100644 knotes/icons/cr16-action-knotes_alarm.png create mode 100644 knotes/icons/cr16-action-knotes_close.png create mode 100644 knotes/icons/cr16-action-knotes_date.png create mode 100644 knotes/icons/cr16-action-knotes_delete.png create mode 100644 knotes/icons/cr16-action-text_sub.png create mode 100644 knotes/icons/cr16-action-text_super.png create mode 100644 knotes/knote.cpp create mode 100644 knotes/knote.h create mode 100644 knotes/knotealarmdlg.cpp create mode 100644 knotes/knotealarmdlg.h create mode 100644 knotes/knotebutton.cpp create mode 100644 knotes/knotebutton.h create mode 100644 knotes/knoteconfig.kcfg create mode 100644 knotes/knoteconfig.kcfgc create mode 100644 knotes/knoteconfigdlg.cpp create mode 100644 knotes/knoteconfigdlg.h create mode 100644 knotes/knoteedit.cpp create mode 100644 knotes/knoteedit.h create mode 100644 knotes/knotehostdlg.cpp create mode 100644 knotes/knotehostdlg.h create mode 100644 knotes/knoteprinter.cpp create mode 100644 knotes/knoteprinter.h create mode 100644 knotes/knotes.desktop create mode 100644 knotes/knotes_manager.desktop create mode 100644 knotes/knotesalarm.cpp create mode 100644 knotes/knotesalarm.h create mode 100644 knotes/knotesapp.cpp create mode 100644 knotes/knotesapp.h create mode 100644 knotes/knotesappui.rc create mode 100644 knotes/knotesglobalconfig.kcfg create mode 100644 knotes/knotesglobalconfig.kcfgc create mode 100644 knotes/knoteslegacy.cpp create mode 100644 knotes/knoteslegacy.h create mode 100644 knotes/knotesnetrecv.cpp create mode 100644 knotes/knotesnetrecv.h create mode 100644 knotes/knotesnetsend.cpp create mode 100644 knotes/knotesnetsend.h create mode 100644 knotes/knotesui.rc create mode 100644 knotes/local.desktop create mode 100644 knotes/main.cpp create mode 100644 knotes/main.h create mode 100644 knotes/mig_knotes.pl create mode 100644 knotes/pics/Makefile.am create mode 100644 knotes/pics/hi128-app-knotes.png create mode 100644 knotes/pics/hi16-app-knotes.png create mode 100644 knotes/pics/hi22-app-knotes.png create mode 100644 knotes/pics/hi32-app-knotes.png create mode 100644 knotes/pics/hi48-app-knotes.png create mode 100644 knotes/pics/hi64-app-knotes.png create mode 100644 knotes/pushpin.xpm create mode 100644 knotes/resourcelocal.cpp create mode 100644 knotes/resourcelocal.h create mode 100644 knotes/resourcelocal_plugin.cpp create mode 100644 knotes/resourcelocalconfig.cpp create mode 100644 knotes/resourcelocalconfig.h create mode 100644 knotes/resourcemanager.cpp create mode 100644 knotes/resourcemanager.h create mode 100644 knotes/resourcenotes.cpp create mode 100644 knotes/resourcenotes.h create mode 100644 knotes/version.h (limited to 'knotes') diff --git a/knotes/.emacs-dirvars b/knotes/.emacs-dirvars new file mode 100644 index 000000000..5c1144385 --- /dev/null +++ b/knotes/.emacs-dirvars @@ -0,0 +1,7 @@ +;; -*- emacs-lisp -*- +;; +;; This file is processed by the dirvars emacs package. Each variable +;; setting below is performed when this dirvars file is loaded. +;; +indent-tabs-mode: nil +c-basic-offset: 4 diff --git a/knotes/AUTHORS b/knotes/AUTHORS new file mode 100644 index 000000000..8b0570b2c --- /dev/null +++ b/knotes/AUTHORS @@ -0,0 +1,20 @@ +Current maintainer: + Michael Brade + +Started by: + Bernd Johannes Wuebben , + +Ported to KDE 2 by: + Wynn Wilkes + +Contributions from: + Matthias Ettrich + David Faure + Matthias Kiefer + Luboš Luňák + Laurent Montel + Dirk A. Mueller + Carsten Pfeiffer + Harri Porten + Espen Sand + Bo Thorsen diff --git a/knotes/ChangeLog b/knotes/ChangeLog new file mode 100644 index 000000000..c5cfb84f0 --- /dev/null +++ b/knotes/ChangeLog @@ -0,0 +1,935 @@ +ChangeLog for KNotes +==================== + +2006/07/10 Michael Brade + + * added DCOP methods to get and change geometry: + height(), width(), move(), resize() + +2006/06/10 Michael Brade + + * added DCOP methods to get and change the color of a note + +2006/02/20 Michael Brade + + * fixed #115009: since it doesn't seem clearly visible that the "Lock" menu + item is down after clicking on it a different checked state and display a + different text ("Unlock") and a different icon. + +2006/01/16 Michael Brade + + * fixed #119980: the knotes directory wasn't created in Kontact/KNotes + * new version number: 3.6 + +2006/01/09 Michael Brade + + rewrote the networking code to use KNetwork: + * fixed #110915: KNetwork has better error reporting than the previous + code, now it says "connection actively refused" instead of "No such + file or directory" + * fixed #110838: this one was caused by an uninitialize variable, so it + wasn't reproducible + +2006/01/07 Michael Brade + + * fixed #103780: separate "Clear" action visually from Cut/Copy/Paste + since it's not doing anything with the clipboard + * fixed #110672: added a "Do not show again" box to the delete note dialog + * fixed #113223: actually set the "Keep Above/Below" bit when creating a + note on startup + +2006/01/06 Michael Brade + + * fix enabling/disabling of font and font size combos. Needed especially + for Kontact where the toolbar is not hidden for non-RichText notes. + +2006/01/04 Michael Brade + + * never show the text of the tool buttons + * don't accept color drops on a locked note + +2005/12/30 Michael Brade + + * more correct enabling of edit actions when (un)locking a note + +2005/09/06 Michael Brade + + * make note colors in Kicker work again for new notes and on start-up. + +2005/09/06 Michael Brade + + * fixed #106724: don't overwrite files without asking for confirmation + first + +2005/08/17 Alejandro Exojo + + * Allow the selection of the file where the file resource should store the + notes. If no file is found in the config, fall back to the standard one. + +2005/05/30 Michael Brade + + * wish #99853: give KNotes a new and fancy style, configurable in the + global settings. Thanks to Bera Debajyoti for the initial patch and + the idea! + +2005/04/13 Michael Brade + + * fixed #103777: save note as plain text actually saved it as richt text + and vice versa + +2005/04/11 Michael Brade + + * fixed #101875: also save the note's position when hiding it + * fixed #102546: don't write the global config file every 60 seconds, + do it only when the notes are saved as well + +2005/02/21 Michael Brade + + * fixed #93001: strikeout text now actually works for multiple paragraphs + as well. + * fixed #18059: finished implementation of alarms for the notes + +2005/02/05 Michael Brade + + * fixed crash when deleting a note + * KNotes startup much faster + +2005/02/02 Michael Brade + + * implemented #69137: read-only support for the notes, i.e. the ability to + lock a note from being modified. + +2005/01/16 Michael Brade + + * read the most recent instead of always taking the local knotesui.rc file + * started implementing alarms for the notes + +2005/01/09 Michael Brade + + * fixed #76435: most wanted feature: find function for the notes. + At the moment the shortcut doesn't work. + +2004/11/28 Michael Brade + + * fixed #90744, #91702, #92596, #93499: save modified notes on quit, may + not have happened when the note still had focus. Also, the problem + with knotesnotes.ics is gone now. + +2004/09/27 Michael Brade + + * no compile-time dependency on kdebase allowed, so read kwinrc directly + +2004/08/31 Michael Brade + + * now KNotes always saves the desktop of its notes since this is what one + would expect, I guess. Visible change: if you hide a note, change to + another desktop and show it again, the note will be shown on the desktop + where it has been hidden. And more important, if a note is sticky it will + still be sticky after it is first hidden and then shown again. Let's see + what the users' feedback will be. + + This will also make it possible to properly implement the often requested + hide all/show all notes feature. + * fixed #29242, #44761, #65090: implemented Show All/Hide All Notes and + added a global shortcut for both actions. Thanks to Jakob Schroeter for + the initial patch on which this is based and the idea to add the global + shortcut. With my previous patch to properly store the desktop this + feature is now usable. + +2004/08/29 Michael Brade + + * fixed #77202: removing the global event filter where I not only returned + the proper boolean value but also (incorrectly) changed the accept/ignore + flag of key events fixed the endless loop that caused the stack overflow. + * fixed #68031, #81888: configuring shortcuts is possible now and changes + are preserved between several KNotes sessions. All possible interactions + with KNotes can have custom shortcuts, there are no hidden features + anymore. + +2004/08/28 Michael Brade + + * fixed #71593, #86711: add the possibility to save a note to a file, either + in plain text or rich text format. Initial patch by Jakob Schroeter, + js AT camaya DOT net, thanks! + +2004/08/27 Michael Brade + + * fixed #50104, #75485: finally (!) use KWin to move the note windows. Thanks + to Luboš for telling me that just the XUngrabPointer line was missing to + make it work. + This enables the active desktop borders and snap zones for KNotes. + * fixed #68481: Also using a tip from Luboš I made KNotes put its close + button where all the other windows have it as well. KNotes needs to be + restarted though to make a change take effect. Needs a fix. + +2004/08/26 Michael Brade + + * fixed jumping/moving of the title text on focusIn/Out events, still not + perfect + +2004/08/25 Michael Brade + + * split KNotes into 5 static libraries to provide for reusability of parts + of KNotes. + +2004/08/22 Michael Brade + + * fixed #81672: when there are no notes don't put the toolbar in the system + tray *blush* by splitting the XMLGUI file for the system tray and the + notes + * still share the parsed note xmlgui file between the notes by parsing it + and creating a QDomDocument in KNotesApp already + * when there is no note after restoring a session, still show the "No Notes" + item in the notes menu + * each note now has its own KXMLGUIBilder to get rid of the reparent-call, + the builder's parent will be the widgets' parent + * fixed #87696: allow default sizes as small as 50x50 pixels + +2004/08/20 Michael Brade + + * fixed #85973: respect newlines when switching from plain text to + rich text + * fixed #87266 by making sure that at least 10 pixels of a note are visible + +2004/05/02 Michael Brade + + * Security: listening on the network for new notes is now off by default + +2004/05/02 Michael Brade + + * Most probably fix a bug that freezed KNotes every now and then: file_copy + was called twice for some reason. Remove it altogether since ICalFormat + does backups for about a year already. Thanks to David for the hint! + +2004/04/27 Michael Brade + + * more work on networking: send and receive note titles and sender name, + compatible with ATnotes. New config option to set the sender id. + +2004/04/24 Michael Brade + + * made the note icons in the taskbar represent the note color, used the + same icons in the menu with the notes list + +2004/04/24 Michael Brade + + * streamlined the config dialogs, reflect that only some dialogs are defaults, + others are global settings + +2004/04/23 Michael Brade + + * fixed adding a new resource every start of KNotes. Please delete + your .kde/share/config/kresources/notes/stdrc file to make KNotes start + fast again. KNotes is ready for release now :) + +2004/04/21 Michael Brade + + * fixed #78362: accept color drops and change background color accordingly + * fixed being able to uncheck all text format buttons in RT mode + +2004/04/20 Michael Brade + + * revert dependency on kdelibs-HEAD, we need KDE 3.2.x for the KDE PIM 3.3 + release + * add a hack to work around inconsistency/limitation in KConfig XT: + it is not possible to make one KCXT-generated class inherit another + one due to CTOR-incompatibilites. The hack installs a CustomAddition + and simply provides a copied&pasted CTOR from the generated code with + adapted arguments (none, actually). + * so now KNotesGlobalConfig inherits KNoteConfig and the global config + dialog needs only one KConfigSkeleton---the former one + * due to the last point it is now possible (and needed) to not simply copy + the knotesrc for new notes but rather just copy part of KNotesGlobalConfig + into the new KNoteConfig object. And boy, this makes creation of new notes + *heaps* faster, even on my PIV1800! (I guess everything has its good side) + * and last, another good thing about this: knotesglobalrc is dead and the + MailAction is back to knotesrc again, so no incompatibilites with "old" + KNotes versions :) + +2004/04/19 Michael Brade + + * added configuration of network settings: + - enable/disable listening for new notes + - set the port used for sending and receiving notes + * added a second config file, knotesglobalrc, since network settings + are not local to every note and should not sit in every note's (display) + config file + * moved MailAction to the global config file as well + * now actually save the recent hosts as well. + +2004/04/14 Michael Brade + + * use a KHistoryCombo for the KNoteHostDlg. This prevents the possibility + to send a note to more than one host at once, so keep only the list of + recent hosts without weighting for compatibility in case this feature is + requested later + +2004/03/31 Michael Brade + + * hmm, wasn't such a good idea to set a default desktop in KConfig XT - only + changes will actually be saved and thus every new note that is not moved + to a different desktop after creation appeared on the desktop KNotes was + started on. Fixed. + +2004/03/24 Michael Brade + + * fixed #71685: again a libical bug, it did not encode '\' at all so it was + possible to write control sequences in KNotes, e.g. \n. + +2004/03/23 Michael Brade + + * optimized networking code, merged KNotesNetworkListener and KNotesApp + +2004/03/23 Michael Brade + + * adapted and applied patch from Daniel Martin to enable communication of + KNotes with ATnotes on Windows machines and other network-enabled + KNotes. Notes can be sent and received over the network. Thanks to + Daniel's excellent code only a minimal set of lines in KNotes itself + had to be touched. (also fixes #57196) + +2004/03/23 Michael Brade + + * Thanks to Luboš for his function that removes sm from the client + leader KNotes is not managed anymore by KWin (again) and is now + thus able to restore its notes properly on login with manually saved + sessions. + * fixed 75341: implemented support for the "strike out" text property + +2004/03/21 Michael Brade + + * fixed Tab key handling in RT mode: do not give away focus to the font + combo box (in fact, not to anything) + +2004/03/19 Michael Brade + + * fixed updating the icon in the notes menu after a color change + * fixed change of font family in richt text mode + * fixed updating of font and font size combo box + * fixed bug that made the html source show up in a text note when switching + from rich text to plain text and then restarting KNotes + * make KNotes interpret the text as rich text when switching from pain text + to rich text + * moved the rich text -> plain text conversion to KNoteEdit + * finally switched rich text toolbar to XMLGUI as well + * fixed #60841: include the title as subject by default when mailing a note + * make mailing a note possible again at all - KMail now needs --body and not + --msg as argument + * convert rich text notes to plain text before emailing them + * fixed #75793: notes should not resize in RT mode, moved to the bottom of + the note + +2004/03/17 Michael Brade + + * set an appropriate caption icon for the config dialog + * make the config dialogs non-modal, put the nodeId as widget name so that + we can cache the dialog and open more than one at once + * fixed #72657: Show note in taskbar did not work properly due to + KWin not preserving NET::SkipTaskbar for hidden windows + * fixed a bug that changes in the note default configuration will + never be used (use KStandardDirs::saveLocation() instead of + KStandardDirs::findResource()) + +2004/03/16 Tobias Koenig + + * fixed bug that removed/added notes are/aren't visible in the LMB menu, + we need to keep the KXMLGUIFactory around if the menu is to be changed + later + +2004/03/16 Michael Brade + + * adapt to new KWin: s/Always on Top/Keep Above Others/g and added + Keep Below Others; furthermore use the corresponding new NET::State flags + * completely rewrote the config dialog, make it inherit KConfigDialog + * ported KNotes to KConfig XT, had to change the config file format: + removed "state" entry and added "KeepAbove", "KeepBelow", "ShowInTaskbar" + +2004/03/15 Michael Brade + + * removed const from KNotesApp::slotPreferences to make it possible to + set KNotesApp as parent of the config dialog -> fixes jumping to another + desktop when opening the config dialog + +2004/03/13 Michael Brade + + * s/ResourceManager/KNotesResourceManager/g + +2004/03/11 Michael Brade + + * massive internal improvements, no hacks anymore, only beautiful and + clean code left :-) + * ResourceManager now solely responsible for loading and saving the + journals and the resources + * KNotesApp provides the GUI for managing the KNote objects and KNote is the + only class dealing with the display of a particular note including config + file handling + * no attachments anymore - notes carry their uid and that is the config file + name anyway. Dunno why I introduced the attachments at all in the first + place... + * KNotes is now "network-enabled" regarding config files: it now only uses + KIO::NetAccess for the file handling. + +2004/03/09 Michael Brade + + * fixed #68127: notes are not really deleted if deleting is the last + action before quitting KNotes + * fixed #72888, #73404, #75558: much more robust conversion of old config + files, now hopefully absolutely no black notes anymore + +2004/03/08 Michael Brade + + * new version: 3.1 + +2004/03/06 Michael Brade + + * fixed #72818: add a tooltip + * fixed #74469: RMB menu locks whole desktop if opened on a modified note + * fixed #75507, #76126: handle (load) tabs correctly, fix in libical + * removed hack for the fix for #57367 + +2004/02/24 Michael Brade + + * finished rich text mode, now using actions + +2004/01/28 Bo Thorsen + + * make KNotes use the KDE Resource Framework + +2004/01/18 Laurent Montel + + * if launching KNotes agin when already running, make it create a new note + +2004/01/11 Michael Brade + + * fixed MMB click on note title to put note really back + * started conversion to using actions in rich text mode (finally!) + +2003/10/21 Michael Brade + + * fixed dropping of urls + +2003/06/28 Michael Brade + + * fixed #54293: sort note titles in the notes menu + +2003/06/22 Michael Brade + + * fixed #42088: don't loose notes if HD is full, always keep a backup + * make it possible to select skip taskbar/not to skip taskbar on a + per-note basis + +2003/06/17 Michael Brade + + * fixed #58338: show note title in taskbar + * various code and style optimisations + +2003/06/13 Maks Orlovich + + * fixed #59028: if title is too long to fit, left-align it, so we don't + end up showing its middle + +2003/04/25 Michael Brade + + * HACK to fix #57367: Always On Top property lost when hide->show a note + +2003/04/04 Luboš Luňák + + * fixed #56625: compensate for the menu separator when using the index + +2003/02/06 Stephan Binner + + * fixed #54108: "&" in note tile will be displayed as underscore in the menu + +2003/01/26 Michael Brade + + * use libkcals new Attachment class + * the config file attachments have "application/x-knotes-config" mime type + +2002/11/05 Michael Brade + + * need to write the KNotes version to knotesrc, otherwise we'll get + an additional new note the next startup + +2002/11/03 Michael Brade + + * found a nice way to prevent loosing focus when opening the RMB menu + +2002/11/01 Michael Brade + + * use iCalendar's uids as note ids, saves quite some code and adds the + possibility to have more that one note using the same title. Also, now + a note will never change its id again. + +2002/10/31 Michael Brade + + * faster shutdown + +2002/10/30 Michael Brade + + * faster startup + * support for loading KOrganizer's journals: + - use default config + - set the start date as summary + * support for a note on different desktops: check position and let KWin do + the placement if it is illegal + * fixed small bug in attachments path + +2002/10/21 Michael Brade + + * new version number, we now have KNotes 3.0 + * finished iCalendar code, KNotes is now fully working with libkcal - theoretically, + as attachments aren't implemented in libkcal yet + +2002/10/20 Michael Brade + + * new class KNotesLegacy which stores all the code dealing with + outdated config files + * fixed some bugs I found while rewriting the config stuff + * newNote and newNoteFromClipboard now take a "const QString& name" + * new subdirectory "icons" to make KIconLoader apply its effects to all + KNotes icons + +2002/10/17 Michael Brade + + * first steps to make KNotes save its data to iCal + +2002/10/16 Michael Brade + + * moved icons into their own subdirectory + * removed really old icons + * made KNoteButtons always square + * show the rich text actions only for actual rich text notes + * don't emit the bold/italic/underline signals when moving the cursor + or selecting text, otherwise this will change the selected text! + +2002/10/15 Michael Brade + + * rewrote KNoteButton (code was from the last stone age ;) + +2002/10/15 Michael Brade + + * added basic gui for rich text support, needs polishing + (too bad I can't use actions yet!) + +2002/10/04 Michael Brade + + * fixed cut, paste, undo and redo activation + +2002/09/30 Michael Brade + + * fixed mouse behaviour to be like kwin: + - raise() and lower() windows already on mouse button press, + not on mouse button release + - MMB moves notes as well + * reduced code duplication (setColor, updateFocus) + * fixed some consts + +2002/09/28 Michael Brade + + * finally fixed the session management bug (remove the sessionId from + all notes => KWin will ignore them) + +2002/09/26 Michael Brade + + * new version number + +2002/09/25 Michael Brade + + * patch from Matthias Kiefer: + - add DCOP call hideNote() + - add new action "New Note from Clipboard" + - nice icon for the "Insert Date" action + - global shortcuts for "New Note" and "New Note from Clipboard" + * changed some actions to KStdActions + * removed the "Notes" sub-menu from the RMB menu + +2002/09/24 Michael Brade + + * fixed printing: + - do not use private Qt headers + - use the correct font + +2002/09/21 Michael Brade + + * inherit KTextEdit instead of QTextEdit + * fixed drag and drop of text and URLs + * fixed changing of font size/family/style + +2002/09/10 Michael Brade + + * fixed one more readNumEntry, thanks to Matthias Kiefer + +2002/06/17 Wynn Wilkes + + * fixed a bug where new notes with the version of 2.2 were seen as old notes + and were converted which led to bad note config files and a big black screen + + * fixed the note conversion code to use KNOTES_VERSION + +2002/05/10 Michael Brade + + * fixed crash on exit due to wrong deletion order + * fixed #42437: preferences never got saved (whoops!!) + +2002/03/08 Michael Brade + + * fixed #38958: Show note color in notes menu + +2002/01/23 Michael Brade + + * fixed #36376, #36799: MMB for new note + +2002/01/22 Michael Brade + + * fixed #37222: Alt-F4 "deletes" note + * fixed #37176: ask for confirmation before deleting a note + * fixed #36374: double click to rename a note + * email updates + +2001/09/09 Michael Brade + + * improved the config dialog + * almost finished rich text notes + +2001/09/08 Michael Brade + + * bugfixes to make KNotes work with Qt3 + +2001/09/04 Michael Brade + + * compile with Qt3 + * started some work on rich text notes (no GUI yet) + +2001/07/13 Michael Brade + + * fixed #28879 (titles were not centered) + +2001/07/11 Michael Brade + + * fixed #28627 (%t in Mail Action) + * started to fix #23567 (printing) + +2001/07/09 Michael Brade + + * don't reread the knotesui.rc all the time a new note is created + +2001/06/23 Michael Brade + + * fixed #18086 (add a size grip for the notes) + * update the title layout if the font was changed + +2001/06/17 Michael Brade + + * finished porting KNotes to the XMLGUI framework + * fixed auto-indent + * fixed the RMB menu + +2001/06/11 Michael Brade + + * improved Configdialog: + - use nicer and bigger icons + - removed the size setting from the local note config dialog + - #20172: separate font settings for title and body + * don't reload the display setting if changing e.g. only the color - + the note's geometry could have been changed already + * fixed some bugs introduced by the QTextEdit port + +2001/06/10 Michael Brade + + * if there's only one note jump to it immediately instead of + showing the LMB menu + +2001/06/10 Michael Brade + + * small bugfix: display "No notes" instead of nothing in the LMB + menu if there are no notes anymore. + +2001/06/10 Michael Brade + + * ported to QTextEdit + * updated actions, removed the ActionProperties section for now + +2001/06/05 Michael Brade + + * started to port KNotes to the XMLGUI framework (50% done) + * dropped KSystemTray inheritance + +2001/05/19 Michael Brade + + * fixed the session management bug (#22844) + * added two more icons to the context menu + * fixed the undo/redo: no more undo right after startup possible + * improved the code for saving the notes a lot, saved a little + memory by removing a now unneeded variable + +2001/05/06 Michael Brade + + * made the notes look 3d + * added a small border to the text + * change the color of the title to show the focus state + +2001/04/25 Michael Brade + + Updated this file! It's time now, after one and a half years... + +2001/04/25 Michael Brade + + Fixed the DCOP interface, no overloaded methods anymore. + +2001/03/29 Nikolas Zimmermann + + converted to KPrinter + +2001/03/29 Michael Brade + + Focus updates. Fix for BR2333, it's time now ;-) + + GUI: Esc closes the current note, Shift-Tab cycles through the notes. + TODO: make this configureable + +2001/03/25 Michael Brade + + * Some internal redesign + * the notes are now saved on FocusOutEvent to reduce the possibility + of data loss (Bug#19851) + * restructured the menu + * most important: rewrote and extended the DCOP interface. KNotes now + provides methods to work fine with PDA sync utils, ATM that's KPilot. + The number of apps that can sync with KNotes is not limited. + +2001/02/04 Michael Brade + + The fix for the broken config files. Enabled the "Stays On Top" option + as well. + +2001/01/18 Matthias Kiefer + + desktop names are encoded in utf8 + +2000/12/19 Wynn Wilkes + + Added support for two dcop calls, rereadNoteDirectory and addNote + The addNote doesn't work yet - there's some problem with the DCOP + when I've tested from the command line. + + Cleaned up the internal code to use new private functions that handle + the different cases. + +2000/12/19 Adriaan de Groot + + Added DCOP calls to manipulate notes (intended for KPilot) + +2000/10/15 Antonio Larrosa Jimenez + + The patch by Michael Brade + posted on kde-core-devel some days ago. Partly reviewed by Wynn Wilkes. + +2000/10/04 David Faure + + Patch from Wynn Wilkes, reviewed by Michael Brade, approved by Matthias Elter. + It fixes the following problems: + "There are some bad memory leaks in the current cvs, and the note data is not + saved on a session shutdown. The patch fixes those and adds some workarounds + for some weird behavior in the QMultiLineEdit widget which adds some phantom + lines to your text now and then. It also reduces the memory usage by not + keeping a KConfig object open for each note all the time - it just creates + them when saving new changes to the note settings." + +2000/09/24 Dirk Müller + + - first attempt fixing the blatant memory leaks in this app. + it still does a lot of crazy things, like keeping all kinds of KSimpleConfig + objects open all the time and writing new coordinates to it in the ::resizeEvent. + it still leaks as the KNote objects are not deleted. this needs more work + - code cleanup. use KWin convenience functions instead of hacking + our own NetWM queries. tested by myself. This simple code is probably + example code for other developers, so its important that it isn't + totally screwed up. + - removed unnecessary header file. + - fixed a few uninitialized variable reads that could lead to a crash + approved by insure++ + +2000/09/23 Matthias Ettrich + + removed unused (but linked) file. Show nodelist on LMB as it was in KDE1 + +2000/09/14 Wynn Wilkes + + Tons of fixes: + - Window Manager integration readded + - Notes don't appear on the taskbar + - Printing works + - Notes can be sticky + - Added good defaults to config reading - so no albino notes + +2000/08/18 Waldo Bastian + + Adjust size of header to size of font. + +2000/08/11 Wynn Wilkes + + * Fixed mail action to use a generic mail command with %f as the file. + * Fixed the mail action to use full path names- that's all kmail works with + currently. + * fixed the action page of the config dialog to provide an edit box for + the mail command, took out label for printing since it won't be done.. + +2000/07/31 Stefan Schimanski <1Stein@gmx.de> + + Rename bug #5858 fixed. + +2000/07/28 Wynn Wilkes + + Config dialog: + * start putting in support for action configuration, waiting to hear from + kmail guys about --msg option + * Changed to be a modal dialog + +2000/07/14 Wynn Wilkes + + removed WABA's net entry for removing window borders... + KWin is respecting the Qt flags again it seems, it works without this now + +2000/07/06 Waldo Bastian + + + //WABA: Get rid of decorations. I can hardly imagine that + + //this is "The Right Way" of doing that. + + KWin::setType( winId(), NET::Toolbar); + +2000/06/21 Wynn Wilkes + + Almost done with the config dialog + Fixed knotesrc problem with session management + +2000/06/13 Wynn Wilkes + + updated for change in file structure- removed old dockwidget code + + Further progress on porting, configure dialog almost done + +2000/05/30 Wynn Wilkes + + KNotes rewrite: + - changed config file to use KConfig + - use KDockWindow and KUniqueApplication + - Changed structure to make smaller files + +2000/01/30 Charles Samuels + + This is my daily huge commit for KAboutData. There are also patches for + KCmdLineArgs (so it works). Ktop is really doing bad folks. + +2000/01/03 Espen Sand + + Using KContextMenuManager to decide when to display popup menus. + I do this for the popup menu in the taskbar as well. I assume this + is correct? + + Replaced QPopupMenu with KPopupMenu in the taskbar widget. + +1999/12/30 Espen Sand + + * Every dialog ported to KDialogBase by translator + requests (fixed sizes removed). + + * Undo/Redo! A no-brainer because of QMultiLineEdit. + + * Some cleanup and rearrangement of popup dialogs. + + Todo + ----- + I think the docking pixmap has a wrong size. It + is not aligned with the Display Property pixmap in kicker. + + + +Old KNotes ChangeLog (KDE 1.x): +=============================== + +1999-10-16 Harri Porten + + * knotes.cpp: applied Unicode patch from Ming-Che Chuang + + +1999-09-25 Harri Porten + + * alarm.cpp: remove (A) from lable when unsetting alarm + (patch by Michael Haeckel + +Tue Aug 3 02:23:09 1999 Carsten Pfeiffer + + * added standard accelerator keys (new, print, save, help, close, quit) + * added "always on top", configurable in the popupmenu + * added possibility to play a sound when an alarm is activated, + configurable in the defaults dialog + * replaced the custom spinboxes with QSpinBoxes and made the dialog use + layout management (still not perfect, yet) + +1999-06-07 Petter Reinholdtsen + * knotes.cpp: Changed text Quit to Exit to match KDE style guide. + +1999-05-22 Dirk A. Mueller + + * Ported to the Qt DND classes. It accepts QTextDrag, handled by + QMultiLineEdit and QUrlDrag. + +1999-03-07 Harri Porten + + * make it compile with Qt 2.0. + * knotes.cpp: adapt to different id numbering of QPopupMenu + * docking.cpp: get along without the PMERROR macro whose i18n() did not + get parsed by msgfmt. + +Tue Feb 16 09:34:25 1999 David Faure + + * Added option "dock in panel" (to disable docking) + Docking is automatically re-enabled if the last note is deleted + * Move options submenu to toplevel RMB menu (too many submenus!) + * Re-added "Quit" menu entry (in order to quit when docking is off) + +1999-02-16 Harri Porten + + * fixed SIGSEV caused by double-clicking on empty places. + * introduced a simple sessionWidget that will catch the + saveYourself() signal from the session manager and invoke saving all + data. This is more robust than having concurring methods in every + widget and works without the saved_already_for_session_management + variable that was NOT unset if the user canceled the shutdown (bug !) + * renaming: missing slash broke renaming. + * set atomic flag in cleanup(). Hope to have avoided occasional crash + leading to data loss. + * Replaced ~/.kde with KApplication::localkdedir() + * option menu: disabled illogical switch between "3D frame" and + "no frame" label. It is a checkable entry! + +Fri May 29 05:36:36 1998 Bernd Johannes Wuebben + + * KNotes are now automatically saved all 15 minutes. + * added explicit save command on request. + +Thu Apr 9 03:21:54 1998 Bernd Johannes Wuebben + + * knotes recognizes urls now. + * Fixed up knotes and implemented docking properly + +Thu Aug 7 18:50:59 1997 Bernd Johannes Wuebben + + * knotes.cpp: knotes now save themselves on X sever exit + +Mon Nov 17 21:32:28 1997 Didier Belot + + * added all necessary stuff for locale (klocale->translate()) + +Sat Nov 22 13:13:05 1997 Matthias Ettrich + + * sessionmanagement: uses kwm properties now, not only geometry info + * look: pretty thin border. KPostit does no longer inherit QMultiline + but simply QFrame. New class: KPostitMultilineEdit. + New QMessage box for warning. Icon+Miniicon. + * feel: moving possible with the label, rmb menu contains toDesktop + and sticky, notes are activated not only raised. Alt-F4 + can remove a note now. + * invocation: change: siguser1 will give you a new knote (like + taking a new paper from a block). + "-knotes_restore" used for session management. + Do NOT use "-restore" since kapplication filters this! diff --git a/knotes/KNotesAppIface.h b/knotes/KNotesAppIface.h new file mode 100644 index 000000000..f97776fdb --- /dev/null +++ b/knotes/KNotesAppIface.h @@ -0,0 +1,215 @@ +/******************************************************************* + KNotesIface.h -- This file defines the DCOP interface for KNotes. + + Copyright (C) 2004 by Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef __KNotesAppIface_h__ +#define __KNotesAppIface_h__ + +#include +#include + +#include + + +class KNotesAppIface : virtual public DCOPObject +{ + K_DCOP +k_dcop: + /** + * Create a new note. + * @param name the name (title) of the new note, if it is empty, + * KNotes will choose an appropriate name + * @param text the body of the new note + * @return the new notes' id + */ + virtual QString newNote( const QString& name = QString::null, + const QString& text = QString::null ) = 0; + + /** + * Create a new note and inserts the current text in the clipboard + * as text. + * + * @param name the name (title) of the new note, if it is empty, + * KNotes will choose an appropriate name + * @return the new notes' id + */ + virtual QString newNoteFromClipboard( const QString& name = QString::null ) = 0; + + /** + * Deletes a note forever. + * @param noteId the id of the note to kill + */ + virtual ASYNC killNote( const QString& noteId ) = 0; + + /** + * Deletes a note forever. + * @param noteId the id of the note to kill + * @param force do not request confirmation + */ + virtual ASYNC killNote( const QString& noteId, bool force ) = 0; + + /** + * Get all the notes including their ids. + * @return a QMap that maps the id of a note to its name + */ + virtual QMap notes() const = 0; + + /** + * Changes the title/name of a note. + * @param noteId the id of the note to be modified + * @param newName the new title + */ + virtual ASYNC setName( const QString& noteId, const QString& newName ) = 0; + + /** + * Sets the text of a note. This will delete the old text! + * @param noteId the id of the note + * @param newText the new text for the note + */ + virtual ASYNC setText( const QString& noteId, const QString& newText ) = 0; + + /** + * Returns the foreground/text color of a note. + * @param noteId the id of the note in question + * @return the foreground/text color as a QString + */ + virtual QString fgColor( const QString& noteId ) const = 0; + + /** + * Returns the background color of a note. + * @param noteId the id of the note in question + * @return the background color as a QString + */ + virtual QString bgColor( const QString& noteId ) const = 0; + + /** + * Sets the color (foreground and background color) of a note. + * @param noteId the id of the note + * @param fgColor the new text color for the note + * @param bgColor the new background color for the note + */ + virtual ASYNC setColor( const QString& noteId, const QString& fgColor, + const QString& bgColor ) = 0; + + /** + * Returns the title/name of a note. + * @param noteId the id of the note in question + * @return the name as a QString + */ + virtual QString name( const QString& noteId ) const = 0; + + /** + * Returns the text of a note. + * @param noteId the id of the note in question + * @return the body as a QString + */ + virtual QString text( const QString& noteId ) const = 0; + + + /******** HERE STARTS THE KNotesAppIface DCOP INTERFACE EXTENSION ********/ + + /** + * Show a note as if it had been selected from the "notes" menu. + * @param noteId the id of the note to show + */ + virtual ASYNC showNote( const QString& noteId ) const = 0; + + /** + * Hide a note. + * @param noteId the id of the note to hide + */ + virtual ASYNC hideNote( const QString& noteId ) const = 0; + + /** + * Show all notes on their respective desktops. + */ + virtual ASYNC showAllNotes() const = 0; + + /** + * Hide all notes. + */ + virtual ASYNC hideAllNotes() const = 0; + + /** + * Returns the width of a note. + * @param noteId the id of the note in question + * @return the width as a uint + */ + virtual int width( const QString& noteId ) const = 0; + + /** + * Returns the height of a note. + * @param noteId the id of the note in question + * @return the height as a uint + */ + virtual int height( const QString& noteId ) const = 0; + + /** + * Repositions a note. + * @param noteId the id of the note to be moved + * @param x the new x-coordinate of the note + * @param y the new y-coordinate of the note + */ + virtual ASYNC move( const QString& noteId, int x, int y ) const = 0; + + /** + * Changes the size of a note. + * @param noteId the id of the note to be resized + * @param width the new width of the note + * @param height the new height of the note + */ + virtual ASYNC resize( const QString& noteId, int width, int height ) const = 0; + + /** + * This tells KNotes that a specific app has synchronized with all the notes. + * @param app the app that has synced with KNotes + */ + virtual ASYNC sync( const QString& app ) = 0; + + /** + * Test if a note was created new after the last sync. + * @param app the app that wants to get the status since the last sync + * @param noteId the id of the note + * @return true if the note is new, false if not or if the note does + * not exist + */ + virtual bool isNew( const QString& app, const QString& noteId ) const = 0; + + /** + * Test if a note was modified since the last sync. + * @param app the app that wants to get the status since the last sync + * @param noteId the id of the note + * @return true if modified (note that this will return true if the note is + * new as well!) and false if the note is not modified or doesn't exist + */ + virtual bool isModified( const QString& app, const QString& noteId ) const = 0; +}; + +#endif diff --git a/knotes/KNotesIface.h b/knotes/KNotesIface.h new file mode 100644 index 000000000..b1d22de3a --- /dev/null +++ b/knotes/KNotesIface.h @@ -0,0 +1,103 @@ +/******************************************************************* + KNotesIface.h -- This file defines the DCOP interface for KNotes. + + Copyright (C) 2000 by Adriaan de Groot + 2001-2004 by Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#ifndef __KNotesIface_h__ +#define __KNotesIface_h__ + +#include +#include + +#include + + +class KNotesIface : virtual public DCOPObject +{ + K_DCOP +k_dcop: + /** + * Create a new note. + * @param name the name (title) of the new note, if it is empty, + * KNotes will choose an appropriate name + * @param text the body of the new note + * @return the new notes' id + */ + virtual QString newNote( const QString& name = QString::null, + const QString& text = QString::null ) = 0; + + /** + * Create a new note and inserts the current text in the clipboard + * as text. + * + * @param name the name (title) of the new note, if it is empty, + * KNotes will choose an appropriate name + * @return the new notes' id + */ + virtual QString newNoteFromClipboard( const QString& name = QString::null ) = 0; + + /** + * Deletes a note forever. + * @param noteId the id of the note to kill + */ + virtual ASYNC killNote( const QString& noteId ) = 0; + + /** + * Deletes a note forever. + * @param noteId the id of the note to kill + * @param force do not request confirmation + */ + virtual ASYNC killNote( const QString& noteId, bool force ) = 0; + + /** + * Get all the notes including their ids. + * @return a QMap that maps the id of a note to its name + */ + virtual QMap notes() const = 0; + + /** + * Changes the title/name of a note. + * @param noteId the id of the note to be modified + * @param newName the new title + */ + virtual ASYNC setName( const QString& noteId, const QString& newName ) = 0; + + /** + * Sets the text of a note. This will delete the old text! + * @param noteId the id of the note + * @param newText the new text for the note + */ + virtual ASYNC setText( const QString& noteId, const QString& newText ) = 0; + + /** + * Returns the title/name of a note. + * @param noteId the id of the note in question + * @return the name as a QString + */ + virtual QString name( const QString& noteId ) const = 0; + + /** + * Returns the text of a note. + * @param noteId the id of the note in question + * @return the body as a QString + */ + virtual QString text( const QString& noteId ) const = 0; +}; + +#endif diff --git a/knotes/Makefile.am b/knotes/Makefile.am new file mode 100644 index 000000000..73f678a18 --- /dev/null +++ b/knotes/Makefile.am @@ -0,0 +1,59 @@ +INCLUDES = -I$(top_srcdir) $(all_includes) + +SUBDIRS = . pics icons + +bin_PROGRAMS = knotes + +include_HEADERS = KNotesIface.h KNotesAppIface.h +noinst_HEADERS = knotesapp.h knote.h knoteedit.h knotebutton.h \ + knoteconfigdlg.h knoteslegacy.h resourcemanager.h \ + resourcenotes.h resourcelocal.h resourcelocalconfig.h \ + knotesnetrecv.h knotesnetsend.h knotehostdlg.h \ + knotealarmdlg.h knotesalarm.h + +noinst_LTLIBRARIES = libknote.la libknoteseditor.la libknoteslegacy.la libknotesconfig.la \ + libknotesresources.la libknotesnetwork.la libknotesprinting.la + +libknoteslegacy_la_SOURCES = knoteslegacy.cpp +libknotesconfig_la_SOURCES = knoteconfig.kcfgc knotesglobalconfig.kcfgc +libknoteseditor_la_SOURCES = knoteedit.cpp +libknotesprinting_la_SOURCES = knoteprinter.cpp +libknotesnetwork_la_SOURCES = knotesnetrecv.cpp knotesnetsend.cpp +libknotesresources_la_SOURCES = resourcemanager.cpp resourcenotes.cpp \ + resourcelocal.cpp resourcelocalconfig.cpp +libknote_la_SOURCES = knote.cpp knotebutton.cpp knoteconfigdlg.cpp knotehostdlg.cpp \ + knotealarmdlg.cpp knotesalarm.cpp + +knotes_SOURCES = main.cpp knotesapp.cpp KNotesAppIface.skel +knotes_LDADD = libknote.la libknoteseditor.la libknotesnetwork.la libknotesresources.la \ + libknoteslegacy.la libknotesconfig.la libknotesprinting.la $(top_builddir)/libkcal/libkcal.la \ + $(top_builddir)/libkdepim/libkdepim.la $(LIB_KIO) -lkresources -lkdeprint -lkutils +knotes_LDFLAGS = $(all_libraries) $(KDE_RPATH) +knotes_COMPILE_FIRST = knoteconfig.h + +kde_module_LTLIBRARIES = knotes_local.la +knotes_local_la_SOURCES = resourcelocal_plugin.cpp +knotes_local_la_LDFLAGS = $(KDE_LDFLAGS) $(all_libraries) -module $(KDE_PLUGIN) +knotes_local_la_LIBADD = libknotesresources.la libknotesconfig.la libknotesprinting.la \ + $(top_builddir)/libkcal/libkcal.la -lkdeprint + +METASOURCES = AUTO + +xdg_apps_DATA = knotes.desktop +kde_kcfg_DATA = knoteconfig.kcfg knotesglobalconfig.kcfg + +ui_DATA = knotesappui.rc knotesui.rc +uidir = $(kde_datadir)/knotes + +service_DATA = local.desktop +servicedir = $(kde_servicesdir)/kresources/knotes + +manager_DATA = knotes_manager.desktop +managerdir = $(kde_servicesdir)/kresources + +KDE_OPTIONS = nofinal + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/knotes.pot + +include $(top_srcdir)/admin/Doxyfile.am diff --git a/knotes/README b/knotes/README new file mode 100644 index 000000000..19dfa7ca4 --- /dev/null +++ b/knotes/README @@ -0,0 +1,63 @@ +KNotes -- Notes for the K Desktop Environment +============================================= + +KNotes aims to be a useful and full featured notes application for +the KDE project. It tries to be as fast and lightweight as +possible although including some advanced features. + +KNotes has already reached its second stage and I'm currently +developing the third and probably last one. + +The second stage was the complete integration with the new KDE 2. +The third stage will include adding the rest of the features from KDE 1's +KNotes not yet ported and the possibility to edit rich text in all +the notes. + +I try to provide code that is very clear and easy to understand and +that can serve as a good example how to use KDE's windowmanager, KWin, +the session management, the XMLGUI and the printing framework. + +KNotes can: + + * accept drag and drop (even from a remote ftp site) + * mail your note + * print your note (not yet perfect) + * insert the current date + * have arbitrary colors for background and text + * have arbitrary sized notes + * use an arbitrary font for the body and the title + * do auto-indentation + +and remembers all this on a per note basis on exit. + +To get started, point the mouse pointer on a KNotes note and use the right +mouse button to bring up the KNotes pop-up menu. + +A little history: +KNotes was originally started by Bernd Wuebben for KDE 1. The goal was mainly +to test and extend the kwm communications protocol as it was quite limited by +that time. + +Wynn Wilkes then did the initial port of KNotes to the next generation of KDE, +KDE 2. Some (hopefully rarely used) features are still not ported yet, see below +for the list. + +Because I was using KNotes daily (and still do so - of course ;) I sent in a +bugreport and got to test the fix for KDE 2.0. Since then I got really addicted +to KNotes' code which is expressed by the fact that I'm the maintainer now :-)) + +Known issues: + * printing is not fully implemented yet + +Features not (yet?) ported from KNotes 1.x: + * do two different frame styles + * associate an alarm timer to a note and notify you on expiry + +If you have any feedback, suggestions, new features or little enhancements, +please don't hesitate to drop me a mail. I still didn't find the patch of how +to read the users' mind ;-)) + +Have fun! + +Best Regards, + Michael diff --git a/knotes/TODO b/knotes/TODO new file mode 100644 index 000000000..bc2f5c570 --- /dev/null +++ b/knotes/TODO @@ -0,0 +1,77 @@ +TODO for KNotes +=============== + +features: + * alarms for the notes + * categories, subfolders, templates for new notes + - assign a color, size, font to a template + - categories with special colors? configurable? + * define a set of colors for the notes - could this be a category then? + * improve printing: + - width of the text on the paper should fit note width if not bigger + than the paper width + - print the note title as well + * the config dialog: + - make the frame configurable (3d -> normal) + - make the keybindings configurable + * support images + * support urls + * save cursor and scrollbar postion + * steal some ideas from Stickies (Mac OS X) + * steal some ideas from ATNotes (Win) + + * once we have more session configs make KNotes save its notes in + .kde/share/apps/knotes// + +bugs: + * fix shortcuts + * if the window state is changed from outside KNotes the buttons do not + reflect that + +TODO: + * F1 should open Help + * do not copy the knotesrc file anymore + => use the static KNotesGlobalConfig object and copy the important stuff over + Disadv: some keys and defaults must be defined in both config files + (and thus, KConfig XT specs) + => how about one kconfig Xt spec and inheriting from the KConfigSkeleton or make the + KConfigSkeleton inherit something? + * global config dialog: use "Defaults" in the side bar and add a page with two tabs, + Display and Editor, respectively + * call m_calendar.update( this ) in knotesapp after saving/changing a note? + * implement removal of resources, i.e. deleting of KNotes without removing config files + (KNotesApp::removeNote()?) + * we can use CustomAdditions=true and add a file _addons.h with methods like + size() and call that instead of width() and height(). + * find out how to avoid the reparent call in KNote + * in rich text mode: what should happen to the font setting in the config dialog? + * use KWinDecorations instead of home-made decoration + * add ToolTips everywhere + * update the date icon, either from crystal or Matthias Kiefer + * use KWin::setIcons for the notes windows, either to put the color or change + the color of the notes icon if possible + * ensure the knotes settings dialog has a unique name with regard to the notes config + dialogs + +perhaps: + * transparent notes + * shadow for the notes + * icons for the notes (small, put in the note menu and note title) + * background images (maybe even SVG) + * action to keep all notes on top + * write an IMAP resource that works without kolab? + +older TODOs from Wynn: + * inserting calendar + * hide/unhide all/some/one ? + * better pipe error checking + * standart error redirection in piping + * changing icon -- empty / non empty + * handle KNotes files of which all/some may reside on the desktop? + (means that there must be an extension for note files...) + +always open TODO: + * make the code as perfect and clean as possible!! + + +-- Michael Brade 21-04-2004 diff --git a/knotes/icons/Makefile.am b/knotes/icons/Makefile.am new file mode 100644 index 000000000..8e1e5bd3b --- /dev/null +++ b/knotes/icons/Makefile.am @@ -0,0 +1,2 @@ +knotesdir = $(kde_datadir)/knotes/icons +knotes_ICON = AUTO diff --git a/knotes/icons/cr16-action-enum_list.png b/knotes/icons/cr16-action-enum_list.png new file mode 100644 index 000000000..101a736e0 Binary files /dev/null and b/knotes/icons/cr16-action-enum_list.png differ diff --git a/knotes/icons/cr16-action-format_decreaseindent.png b/knotes/icons/cr16-action-format_decreaseindent.png new file mode 100644 index 000000000..953131101 Binary files /dev/null and b/knotes/icons/cr16-action-format_decreaseindent.png differ diff --git a/knotes/icons/cr16-action-format_increaseindent.png b/knotes/icons/cr16-action-format_increaseindent.png new file mode 100644 index 000000000..618dab712 Binary files /dev/null and b/knotes/icons/cr16-action-format_increaseindent.png differ diff --git a/knotes/icons/cr16-action-knotes_alarm.png b/knotes/icons/cr16-action-knotes_alarm.png new file mode 100644 index 000000000..ae4234de7 Binary files /dev/null and b/knotes/icons/cr16-action-knotes_alarm.png differ diff --git a/knotes/icons/cr16-action-knotes_close.png b/knotes/icons/cr16-action-knotes_close.png new file mode 100644 index 000000000..3e2e5c3ee Binary files /dev/null and b/knotes/icons/cr16-action-knotes_close.png differ diff --git a/knotes/icons/cr16-action-knotes_date.png b/knotes/icons/cr16-action-knotes_date.png new file mode 100644 index 000000000..08b0c2416 Binary files /dev/null and b/knotes/icons/cr16-action-knotes_date.png differ diff --git a/knotes/icons/cr16-action-knotes_delete.png b/knotes/icons/cr16-action-knotes_delete.png new file mode 100644 index 000000000..6d0d29d76 Binary files /dev/null and b/knotes/icons/cr16-action-knotes_delete.png differ diff --git a/knotes/icons/cr16-action-text_sub.png b/knotes/icons/cr16-action-text_sub.png new file mode 100644 index 000000000..a1bec914c Binary files /dev/null and b/knotes/icons/cr16-action-text_sub.png differ diff --git a/knotes/icons/cr16-action-text_super.png b/knotes/icons/cr16-action-text_super.png new file mode 100644 index 000000000..05d90d596 Binary files /dev/null and b/knotes/icons/cr16-action-text_super.png differ diff --git a/knotes/knote.cpp b/knotes/knote.cpp new file mode 100644 index 000000000..795da8a16 --- /dev/null +++ b/knotes/knote.cpp @@ -0,0 +1,1339 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2006, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "knote.h" +#include "knotebutton.h" +#include "knoteedit.h" +#include "knoteconfig.h" +#include "knotesglobalconfig.h" +#include "knoteconfigdlg.h" +#include "knotealarmdlg.h" +#include "knotehostdlg.h" +#include "knotesnetsend.h" +#include "knoteprinter.h" +#include "version.h" + +#include "pushpin.xpm" + +#include +#include + +#include + +using namespace KCal; + +extern Time qt_x_time; + +int KNote::s_ppOffset = 0; + +KNote::KNote( QDomDocument buildDoc, Journal *j, QWidget *parent, const char *name ) + : QFrame( parent, name, WStyle_Customize | WStyle_NoBorder | WDestructiveClose ), + m_label( 0 ), m_pushpin( 0 ), m_fold( 0 ), m_button( 0 ), m_tool( 0 ), m_editor( 0 ), + m_config( 0 ), m_journal( j ), m_find( 0 ), + m_kwinConf( KSharedConfig::openConfig( "kwinrc", true ) ) +{ + setAcceptDrops( true ); + actionCollection()->setWidget( this ); + + setDOMDocument( buildDoc ); + + // just set the name of the file to save the actions to, do NOT reparse it + setXMLFile( instance()->instanceName() + "ui.rc", false, false ); + + // if there is no title yet, use the start date if valid + // (KOrganizer's journals don't have titles but a valid start date) + if ( m_journal->summary().isNull() && m_journal->dtStart().isValid() ) + { + QString s = KGlobal::locale()->formatDateTime( m_journal->dtStart() ); + m_journal->setSummary( s ); + } + + // create the menu items for the note - not the editor... + // rename, mail, print, save as, insert date, alarm, close, delete, new note + new KAction( i18n("New"), "filenew", 0, + this, SIGNAL(sigRequestNewNote()), actionCollection(), "new_note" ); + new KAction( i18n("Rename..."), "text", 0, + this, SLOT(slotRename()), actionCollection(), "rename_note" ); + m_readOnly = new KToggleAction( i18n("Lock"), "lock" , 0, + this, SLOT(slotUpdateReadOnly()), actionCollection(), "lock_note" ); + m_readOnly->setCheckedState( KGuiItem( i18n("Unlock"), "unlock" ) ); + new KAction( i18n("Hide"), "fileclose" , Key_Escape, + this, SLOT(slotClose()), actionCollection(), "hide_note" ); + new KAction( i18n("Delete"), "knotes_delete", 0, + this, SLOT(slotKill()), actionCollection(), "delete_note" ); + + new KAction( i18n("Insert Date"), "knotes_date", 0 , + this, SLOT(slotInsDate()), actionCollection(), "insert_date" ); + new KAction( i18n("Set Alarm..."), "knotes_alarm", 0 , + this, SLOT(slotSetAlarm()), actionCollection(), "set_alarm" ); + + new KAction( i18n("Send..."), "network", 0, + this, SLOT(slotSend()), actionCollection(), "send_note" ); + new KAction( i18n("Mail..."), "mail_send", 0, + this, SLOT(slotMail()), actionCollection(), "mail_note" ); + new KAction( i18n("Save As..."), "filesaveas", 0, + this, SLOT(slotSaveAs()), actionCollection(), "save_note" ); + KStdAction::print( this, SLOT(slotPrint()), actionCollection(), "print_note" ); + new KAction( i18n("Preferences..."), "configure", 0, + this, SLOT(slotPreferences()), actionCollection(), "configure_note" ); + + m_keepAbove = new KToggleAction( i18n("Keep Above Others"), "up", 0, + this, SLOT(slotUpdateKeepAboveBelow()), actionCollection(), "keep_above" ); + m_keepAbove->setExclusiveGroup( "keepAB" ); + + m_keepBelow = new KToggleAction( i18n("Keep Below Others"), "down", 0, + this, SLOT(slotUpdateKeepAboveBelow()), actionCollection(), "keep_below" ); + m_keepBelow->setExclusiveGroup( "keepAB" ); + + m_toDesktop = new KListAction( i18n("To Desktop"), 0, + this, SLOT(slotPopupActionToDesktop(int)), actionCollection(), "to_desktop" ); + connect( m_toDesktop->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(slotUpdateDesktopActions()) ); + + // invisible action to walk through the notes to make this configurable + new KAction( i18n("Walk Through Notes"), 0, SHIFT+Key_BackTab, + this, SIGNAL(sigShowNextNote()), actionCollection(), "walk_notes" ); + + // create the note header, button and label... + m_label = new QLabel( this ); + m_label->setFrameStyle( NoFrame ); + m_label->setLineWidth( 0 ); + m_label->installEventFilter( this ); // receive events (for dragging & action menu) + setName( m_journal->summary() ); // don't worry, no signals are connected at this stage yet + + m_button = new KNoteButton( "knotes_close", this ); + connect( m_button, SIGNAL(clicked()), this, SLOT(slotClose()) ); + + // create the note editor + m_editor = new KNoteEdit( actionCollection(), this ); + m_editor->installEventFilter( this ); // receive events (for modified) + m_editor->viewport()->installEventFilter( this ); + connect( m_editor, SIGNAL(contentsMoving( int, int )), this, SLOT(slotUpdateViewport( int, int ))); + + KXMLGUIBuilder builder( this ); + KXMLGUIFactory factory( &builder, this ); + factory.addClient( this ); + + m_menu = dynamic_cast(factory.container( "note_context", this )); + m_edit_menu = dynamic_cast(factory.container( "note_edit", this )); + m_tool = dynamic_cast(factory.container( "note_tool", this )); + + if ( m_tool ) { + m_tool->setIconSize( 10 ); + m_tool->setFixedHeight( 16 ); + m_tool->setIconText( KToolBar::IconOnly ); + + // if there was just a way of making KComboBox adhere the toolbar height... + QObjectList *list = m_tool->queryList( "KComboBox" ); + QObjectListIt it( *list ); + while ( it.current() != 0 ) + { + KComboBox *combo = (KComboBox *)it.current(); + QFont font = combo->font(); + font.setPointSize( 7 ); + combo->setFont( font ); + combo->setFixedHeight( 14 ); + ++it; + } + delete list; + + m_tool->hide(); + } + + setFocusProxy( m_editor ); + + // create the resize handle + m_editor->setCornerWidget( new QSizeGrip( this ) ); + uint width = m_editor->cornerWidget()->width(); + uint height = m_editor->cornerWidget()->height(); + QBitmap mask; + mask.resize( width, height ); + mask.fill( color0 ); + QPointArray array; + array.setPoints( 3, 0, height, width, height, width, 0 ); + QPainter p; + p.begin( &mask ); + p.setBrush( color1 ); + p.drawPolygon( array ); + p.end(); + m_editor->cornerWidget()->setMask( mask ); + m_editor->cornerWidget()->setBackgroundMode( PaletteBase ); + + // the config file location + QString configFile = KGlobal::dirs()->saveLocation( "appdata", "notes/" ); + configFile += m_journal->uid(); + + // no config file yet? -> use the default display config if available + // we want to write to configFile, so use "false" + bool newNote = !KIO::NetAccess::exists( KURL::fromPathOrURL( configFile ), false, 0 ); + + m_config = new KNoteConfig( KSharedConfig::openConfig( configFile, false, false ) ); + m_config->readConfig(); + m_config->setVersion( KNOTES_VERSION ); + + if ( newNote ) + { + // until kdelibs provides copying of KConfigSkeletons (KDE 3.4) + KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self(); + m_config->setBgColor( globalConfig->bgColor() ); + m_config->setFgColor( globalConfig->fgColor() ); + m_config->setWidth( globalConfig->width() ); + m_config->setHeight( globalConfig->height() ); + + m_config->setFont( globalConfig->font() ); + m_config->setTitleFont( globalConfig->titleFont() ); + m_config->setAutoIndent( globalConfig->autoIndent() ); + m_config->setRichText( globalConfig->richText() ); + m_config->setTabSize( globalConfig->tabSize() ); + m_config->setReadOnly( globalConfig->readOnly() ); + + m_config->setDesktop( globalConfig->desktop() ); + m_config->setHideNote( globalConfig->hideNote() ); + m_config->setPosition( globalConfig->position() ); + m_config->setShowInTaskbar( globalConfig->showInTaskbar() ); + m_config->setKeepAbove( globalConfig->keepAbove() ); + m_config->setKeepBelow( globalConfig->keepBelow() ); + + m_config->writeConfig(); + } + + // set up the look&feel of the note + setMinimumSize( 20, 20 ); + setLineWidth( 1 ); + setMargin( 0 ); + + m_editor->setMargin( 0 ); + m_editor->setFrameStyle( NoFrame ); + m_editor->setBackgroundOrigin( WindowOrigin ); + + // can be done here since this doesn't pick up changes while KNotes is running anyway + bool closeLeft = false; + m_kwinConf->setGroup( "Style" ); + if ( m_kwinConf->readBoolEntry( "CustomButtonPositions" ) ) + closeLeft = m_kwinConf->readEntry( "ButtonsOnLeft" ).find( 'X' ) > -1; + + QPixmap pushpin_pix; + if ( closeLeft ) + pushpin_pix = QPixmap( QPixmap( pushpin_xpm ).convertToImage().mirror( true, false ) ); + else + pushpin_pix = QPixmap( pushpin_xpm ); + + // the pushpin label at the top left or right corner + m_pushpin = new QLabel( this ); + m_pushpin->setScaledContents( true ); + m_pushpin->setBackgroundMode( NoBackground ); + m_pushpin->setPixmap( pushpin_pix ); + m_pushpin->resize( pushpin_pix.size() ); + + // fold label at bottom right corner + m_fold = new QLabel( this ); + m_fold->setScaledContents( true ); + m_fold->setBackgroundMode( NoBackground ); + + // load the display configuration of the note + width = m_config->width(); + height = m_config->height(); + resize( width, height ); + + // let KWin do the placement if the position is illegal--at least 10 pixels + // of a note need to be visible + const QPoint& position = m_config->position(); + QRect desk = kapp->desktop()->rect(); + desk.addCoords( 10, 10, -10, -10 ); + if ( desk.intersects( QRect( position, QSize( width, height ) ) ) ) + move( position ); // do before calling show() to avoid flicker + + // config items in the journal have priority + QString property = m_journal->customProperty( "KNotes", "FgColor" ); + if ( !property.isNull() ) + m_config->setFgColor( QColor( property ) ); + else + m_journal->setCustomProperty( "KNotes", "FgColor", m_config->fgColor().name() ); + + property = m_journal->customProperty( "KNotes", "BgColor" ); + if ( !property.isNull() ) + m_config->setBgColor( QColor( property ) ); + else + m_journal->setCustomProperty( "KNotes", "BgColor", m_config->bgColor().name() ); + + property = m_journal->customProperty( "KNotes", "RichText" ); + if ( !property.isNull() ) + m_config->setRichText( property == "true" ? true : false ); + else + m_journal->setCustomProperty( "KNotes", "RichText", m_config->richText() ? "true" : "false" ); + + // read configuration settings... + slotApplyConfig(); + + // create the mask for the fold---to be done after slotApplyConfig(), + // which calls createFold() + m_fold->setMask( QRegion( m_fold->pixmap()->createHeuristicMask() ) ); + + // if this is a new note put on current desktop - we can't use defaults + // in KConfig XT since only _changes_ will be stored in the config file + int desktop = m_config->desktop(); + if ( desktop < 0 && desktop != NETWinInfo::OnAllDesktops ) + desktop = KWin::currentDesktop(); + + // show the note if desired + if ( desktop != 0 && !m_config->hideNote() ) + { + // to avoid flicker, call this before show() + toDesktop( desktop ); + show(); + + // because KWin forgets about that for hidden windows + if ( desktop == NETWinInfo::OnAllDesktops ) + toDesktop( desktop ); + } + + m_editor->setText( m_journal->description() ); + m_editor->setModified( false ); + + m_readOnly->setChecked( m_config->readOnly() ); + slotUpdateReadOnly(); + + if ( m_config->keepAbove() ) + m_keepAbove->setChecked( true ); + else if ( m_config->keepBelow() ) + m_keepBelow->setChecked( true ); + else + { + m_keepAbove->setChecked( false ); + m_keepBelow->setChecked( false ); + } + slotUpdateKeepAboveBelow(); + + // HACK: update the icon color - again after showing the note, to make kicker aware of the new colors + KIconEffect effect; + QPixmap icon = effect.apply( kapp->icon(), KIconEffect::Colorize, 1, m_config->bgColor(), false ); + QPixmap miniIcon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1, m_config->bgColor(), false ); + KWin::setIcons( winId(), icon, miniIcon ); +} + +KNote::~KNote() +{ + delete m_config; +} + + +// -------------------- public slots -------------------- // + +void KNote::slotKill( bool force ) +{ + if ( !force && + KMessageBox::warningContinueCancel( this, + i18n("Do you really want to delete note %1?").arg( m_label->text() ), + i18n("Confirm Delete"), KGuiItem( i18n("&Delete"), "editdelete" ), + "ConfirmDeleteNote" + ) + != KMessageBox::Continue ) + { + return; + } + + // delete the configuration first, then the corresponding file + delete m_config; + m_config = 0; + + QString configFile = KGlobal::dirs()->saveLocation( "appdata", "notes/" ); + configFile += m_journal->uid(); + + if ( !KIO::NetAccess::del( KURL::fromPathOrURL( configFile ), this ) ) + kdError(5500) << "Can't remove the note config: " << configFile << endl; + + emit sigKillNote( m_journal ); +} + + +// -------------------- public member functions -------------------- // + +void KNote::saveData() +{ + m_journal->setSummary( m_label->text() ); + m_journal->setDescription( m_editor->text() ); + m_journal->setCustomProperty( "KNotes", "FgColor", m_config->fgColor().name() ); + m_journal->setCustomProperty( "KNotes", "BgColor", m_config->bgColor().name() ); + m_journal->setCustomProperty( "KNotes", "RichText", m_config->richText() ? "true" : "false" ); + + emit sigDataChanged(); + m_editor->setModified( false ); +} + +void KNote::saveConfig() const +{ + m_config->setWidth( width() ); + if ( m_tool ) + m_config->setHeight( height() - (m_tool->isHidden() ? 0 : m_tool->height()) ); + else + m_config->setHeight( 0 ); + m_config->setPosition( pos() ); + + NETWinInfo wm_client( qt_xdisplay(), winId(), qt_xrootwin(), NET::WMDesktop ); + if ( wm_client.desktop() == NETWinInfo::OnAllDesktops || wm_client.desktop() > 0 ) + m_config->setDesktop( wm_client.desktop() ); + + // actually store the config on disk + m_config->writeConfig(); +} + +QString KNote::noteId() const +{ + return m_journal->uid(); +} + +QString KNote::name() const +{ + return m_label->text(); +} + +QString KNote::text() const +{ + return m_editor->text(); +} + +QString KNote::plainText() const +{ + if ( m_editor->textFormat() == RichText ) + { + QTextEdit conv; + conv.setTextFormat( RichText ); + conv.setText( m_editor->text() ); + conv.setTextFormat( PlainText ); + return conv.text(); + } + else + return m_editor->text(); +} + +void KNote::setName( const QString& name ) +{ + m_label->setText( name ); + updateLabelAlignment(); + + if ( m_editor ) // not called from CTOR? + saveData(); + + // set the window's name for the taskbar entry to be more helpful (#58338) + NETWinInfo note_win( qt_xdisplay(), winId(), qt_xrootwin(), NET::WMDesktop ); + note_win.setName( name.utf8() ); + + emit sigNameChanged(); +} + +void KNote::setText( const QString& text ) +{ + m_editor->setText( text ); + saveData(); +} + +QColor KNote::fgColor() const +{ + return m_config->fgColor(); +} + +QColor KNote::bgColor() const +{ + return m_config->bgColor(); +} + +void KNote::setColor( const QColor& fg, const QColor& bg ) +{ + m_journal->setCustomProperty( "KNotes", "FgColor", fg.name() ); + m_journal->setCustomProperty( "KNotes", "BgColor", bg.name() ); + m_config->setFgColor( fg ); + m_config->setBgColor( bg ); + + m_journal->updated(); // because setCustomProperty() doesn't call it!! + emit sigDataChanged(); + m_config->writeConfig(); + + QPalette newpalette = palette(); + newpalette.setColor( QColorGroup::Background, bg ); + newpalette.setColor( QColorGroup::Foreground, fg ); + newpalette.setColor( QColorGroup::Base, bg ); // text background + newpalette.setColor( QColorGroup::Text, fg ); // text color + newpalette.setColor( QColorGroup::Button, bg ); + newpalette.setColor( QColorGroup::ButtonText, fg ); + +// newpalette.setColor( QColorGroup::Highlight, bg ); +// newpalette.setColor( QColorGroup::HighlightedText, fg ); + + // the shadow + newpalette.setColor( QColorGroup::Midlight, bg.light(150) ); + newpalette.setColor( QColorGroup::Shadow, bg.dark(116) ); + newpalette.setColor( QColorGroup::Light, bg.light(180) ); + if ( s_ppOffset ) + newpalette.setColor( QColorGroup::Dark, bg.dark(200) ); + else + newpalette.setColor( QColorGroup::Dark, bg.dark(108) ); + setPalette( newpalette ); + + // set the text color + m_editor->setTextColor( fg ); + + // set the background color or gradient + updateBackground(); + + // set darker value for the hide button... + QPalette darker = palette(); + darker.setColor( QColorGroup::Button, bg.dark(116) ); + m_button->setPalette( darker ); + + // update the icon color + KIconEffect effect; + QPixmap icon = effect.apply( kapp->icon(), KIconEffect::Colorize, 1, bg, false ); + QPixmap miniIcon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1, bg, false ); + KWin::setIcons( winId(), icon, miniIcon ); + + // set the color for the selection used to highlight the find stuff + QColor sel = palette().color( QPalette::Active, QColorGroup::Base ).dark(); + if ( sel == Qt::black ) + sel = palette().color( QPalette::Active, QColorGroup::Base ).light(); + + m_editor->setSelectionAttributes( 1, sel, true ); + + // update the color of the fold + createFold(); + + // update the color of the title + updateFocus(); + emit sigColorChanged(); +} + +void KNote::find( const QString& pattern, long options ) +{ + delete m_find; + m_find = new KFind( pattern, options, this ); + + connect( m_find, SIGNAL(highlight( const QString &, int, int )), + this, SLOT(slotHighlight( const QString &, int, int )) ); + connect( m_find, SIGNAL(findNext()), this, SLOT(slotFindNext()) ); + + m_find->setData( plainText() ); + slotFindNext(); +} + +void KNote::slotFindNext() +{ + // TODO: honor FindBackwards + // TODO: dialogClosed() -> delete m_find + + // Let KFind inspect the text fragment, and display a dialog if a match is found + KFind::Result res = m_find->find(); + + if ( res == KFind::NoMatch ) // i.e. at end-pos + { + m_editor->removeSelection( 1 ); + emit sigFindFinished(); + delete m_find; + m_find = 0; + } + else + { + show(); + KWin::setCurrentDesktop( KWin::windowInfo( winId() ).desktop() ); + } +} + +void KNote::slotHighlight( const QString& str, int idx, int len ) +{ + int paraFrom = 0, idxFrom = 0, p = 0; + for ( ; p < idx; ++p ) + if ( str[p] == '\n' ) + { + ++paraFrom; + idxFrom = 0; + } + else + ++idxFrom; + + int paraTo = paraFrom, idxTo = idxFrom; + + for ( ; p < idx + len; ++p ) + { + if ( str[p] == '\n' ) + { + ++paraTo; + idxTo = 0; + } + else + ++idxTo; + } + + m_editor->setSelection( paraFrom, idxFrom, paraTo, idxTo, 1 ); +} + +bool KNote::isModified() const +{ + return m_editor->isModified(); +} + +// FIXME KDE 4.0: remove sync(), isNew() and isModified() +void KNote::sync( const QString& app ) +{ + QByteArray sep( 1 ); + sep[0] = '\0'; + + KMD5 hash; + QCString result; + + hash.update( m_label->text().utf8() ); + hash.update( sep ); + hash.update( m_editor->text().utf8() ); + hash.hexDigest( result ); + + // hacky... not possible with KConfig XT + KConfig *config = m_config->config(); + config->setGroup( "Synchronisation" ); + config->writeEntry( app, result.data() ); +} + +bool KNote::isNew( const QString& app ) const +{ + KConfig *config = m_config->config(); + config->setGroup( "Synchronisation" ); + QString hash = config->readEntry( app ); + return hash.isEmpty(); +} + +bool KNote::isModified( const QString& app ) const +{ + QByteArray sep( 1 ); + sep[0] = '\0'; + + KMD5 hash; + hash.update( m_label->text().utf8() ); + hash.update( sep ); + hash.update( m_editor->text().utf8() ); + hash.hexDigest(); + + KConfig *config = m_config->config(); + config->setGroup( "Synchronisation" ); + QString orig = config->readEntry( app ); + + if ( hash.verify( orig.utf8() ) ) // returns false on error! + return false; + else + return true; +} + +void KNote::setStyle( int style ) +{ + if ( style == KNotesGlobalConfig::EnumStyle::Plain ) + s_ppOffset = 0; + else + s_ppOffset = 12; +} + + +// ------------------ private slots (menu actions) ------------------ // + +void KNote::slotRename() +{ + // pop up dialog to get the new name + bool ok; + QString newName = KInputDialog::getText( QString::null, + i18n("Please enter the new name:"), m_label->text(), &ok, this ); + if ( !ok ) // handle cancel + return; + + setName( newName ); +} + +void KNote::slotUpdateReadOnly() +{ + const bool readOnly = m_readOnly->isChecked(); + + m_editor->setReadOnly( readOnly ); + m_config->setReadOnly( readOnly ); + + // Enable/disable actions accordingly + actionCollection()->action( "configure_note" )->setEnabled( !readOnly ); + actionCollection()->action( "insert_date" )->setEnabled( !readOnly ); + actionCollection()->action( "delete_note" )->setEnabled( !readOnly ); + + actionCollection()->action( "edit_undo" )->setEnabled( !readOnly && m_editor->isUndoAvailable() ); + actionCollection()->action( "edit_redo" )->setEnabled( !readOnly && m_editor->isRedoAvailable() ); + actionCollection()->action( "edit_cut" )->setEnabled( !readOnly && m_editor->hasSelectedText() ); + actionCollection()->action( "edit_paste" )->setEnabled( !readOnly ); + actionCollection()->action( "edit_clear" )->setEnabled( !readOnly ); + + updateFocus(); +} + +void KNote::slotClose() +{ + NETWinInfo wm_client( qt_xdisplay(), winId(), qt_xrootwin(), NET::WMDesktop ); + if ( wm_client.desktop() == NETWinInfo::OnAllDesktops || wm_client.desktop() > 0 ) + m_config->setDesktop( wm_client.desktop() ); + + m_editor->clearFocus(); + m_config->setHideNote( true ); + m_config->setPosition( pos() ); + + // just hide the note so it's still available from the dock window + hide(); +} + +void KNote::slotInsDate() +{ + m_editor->insert( KGlobal::locale()->formatDateTime(QDateTime::currentDateTime()) ); +} + +void KNote::slotSetAlarm() +{ + KNoteAlarmDlg dlg( name(), this ); + dlg.setIncidence( m_journal ); + + if ( dlg.exec() == QDialog::Accepted ) + emit sigDataChanged(); +} + +void KNote::slotPreferences() +{ + // reuse if possible + if ( KNoteConfigDlg::showDialog( noteId().utf8() ) ) + return; + + // create a new preferences dialog... + KNoteConfigDlg *dialog = new KNoteConfigDlg( m_config, name(), this, noteId().utf8() ); + connect( dialog, SIGNAL(settingsChanged()), this, SLOT(slotApplyConfig()) ); + connect( this, SIGNAL(sigNameChanged()), dialog, SLOT(slotUpdateCaption()) ); + dialog->show(); +} + +void KNote::slotSend() +{ + // pop up dialog to get the IP + KNoteHostDlg hostDlg( i18n("Send \"%1\"").arg( name() ), this ); + bool ok = (hostDlg.exec() == QDialog::Accepted); + QString host = hostDlg.host(); + + if ( !ok ) // handle cancel + return; + + if ( host.isEmpty() ) + { + KMessageBox::sorry( this, i18n("The host cannot be empty.") ); + return; + } + + // Send the note + KNotesNetworkSender *sender = new KNotesNetworkSender( host, KNotesGlobalConfig::port() ); + sender->setSenderId( KNotesGlobalConfig::senderID() ); + sender->setNote( name(), text() ); + sender->connect(); +} + +void KNote::slotMail() +{ + // get the mail action command + QStringList cmd_list = QStringList::split( QChar(' '), KNotesGlobalConfig::mailAction() ); + + KProcess mail; + for ( QStringList::Iterator it = cmd_list.begin(); + it != cmd_list.end(); ++it ) + { + if ( *it == "%f" ) + mail << plainText().local8Bit(); // convert rich text to plain text + else if ( *it == "%t" ) + mail << m_label->text().local8Bit(); + else + mail << (*it).local8Bit(); + } + + if ( !mail.start( KProcess::DontCare ) ) + KMessageBox::sorry( this, i18n("Unable to start the mail process.") ); +} + +void KNote::slotPrint() +{ + saveData(); + + QString content; + if ( m_editor->textFormat() == PlainText ) + content = QStyleSheet::convertFromPlainText( m_editor->text() ); + else + content = m_editor->text(); + + KNotePrinter printer; + printer.setMimeSourceFactory( m_editor->mimeSourceFactory() ); + printer.setFont( m_config->font() ); + printer.setContext( m_editor->context() ); + printer.setStyleSheet( m_editor->styleSheet() ); + printer.setColorGroup( colorGroup() ); + printer.printNote( QString(), content ); +} + +void KNote::slotSaveAs() +{ + QCheckBox *convert = 0; + + if ( m_editor->textFormat() == RichText ) + { + convert = new QCheckBox( 0 ); + convert->setText( i18n("Save note as plain text") ); + } + + KFileDialog dlg( QString::null, QString::null, this, "filedialog", true, convert ); + dlg.setOperationMode( KFileDialog::Saving ); + dlg.setCaption( i18n("Save As") ); + dlg.exec(); + + QString fileName = dlg.selectedFile(); + if ( fileName.isEmpty() ) + return; + + QFile file( fileName ); + + if ( file.exists() && + KMessageBox::warningContinueCancel( this, i18n("A file named %1 already exists.
" + "Are you sure you want to overwrite it?
").arg( QFileInfo(file).fileName() ) ) + != KMessageBox::Continue ) + { + return; + } + + if ( file.open( IO_WriteOnly ) ) + { + QTextStream stream( &file ); + // convert rich text to plain text first + if ( convert && convert->isChecked() ) + stream << plainText(); + else + stream << text(); + } +} + +void KNote::slotPopupActionToDesktop( int id ) +{ + toDesktop( id - 1 ); // compensate for the menu separator, -1 == all desktops +} + + +// ------------------ private slots (configuration) ------------------ // + +void KNote::slotApplyConfig() +{ + if ( m_config->richText() ) + m_editor->setTextFormat( RichText ); + else + m_editor->setTextFormat( PlainText ); + + m_label->setFont( m_config->titleFont() ); + m_editor->setTextFont( m_config->font() ); + m_editor->setTabStop( m_config->tabSize() ); + m_editor->setAutoIndentMode( m_config->autoIndent() ); + + // if called as a slot, save the text, we might have changed the + // text format - otherwise the journal will not be updated + if ( sender() ) + saveData(); + + setColor( m_config->fgColor(), m_config->bgColor() ); + + updateLabelAlignment(); + slotUpdateShowInTaskbar(); +} + +void KNote::slotUpdateKeepAboveBelow() +{ + KWin::WindowInfo info( KWin::windowInfo( winId() ) ); + + if ( m_keepAbove->isChecked() ) + { + m_config->setKeepAbove( true ); + m_config->setKeepBelow( false ); + KWin::setState( winId(), info.state() | NET::KeepAbove ); + } + else if ( m_keepBelow->isChecked() ) + { + m_config->setKeepAbove( false ); + m_config->setKeepBelow( true ); + KWin::setState( winId(), info.state() | NET::KeepBelow ); + } + else + { + m_config->setKeepAbove( false ); + KWin::clearState( winId(), NET::KeepAbove ); + + m_config->setKeepBelow( false ); + KWin::clearState( winId(), NET::KeepBelow ); + } +} + +void KNote::slotUpdateShowInTaskbar() +{ + if ( !m_config->showInTaskbar() ) + KWin::setState( winId(), KWin::windowInfo(winId()).state() | NET::SkipTaskbar ); + else + KWin::clearState( winId(), NET::SkipTaskbar ); +} + +void KNote::slotUpdateDesktopActions() +{ + NETRootInfo wm_root( qt_xdisplay(), NET::NumberOfDesktops | NET::DesktopNames ); + NETWinInfo wm_client( qt_xdisplay(), winId(), qt_xrootwin(), NET::WMDesktop ); + + QStringList desktops; + desktops.append( i18n("&All Desktops") ); + desktops.append( QString::null ); // Separator + + int count = wm_root.numberOfDesktops(); + for ( int n = 1; n <= count; n++ ) + desktops.append( QString("&%1 %2").arg( n ).arg( QString::fromUtf8(wm_root.desktopName( n )) ) ); + + m_toDesktop->setItems( desktops ); + + if ( wm_client.desktop() == NETWinInfo::OnAllDesktops ) + m_toDesktop->setCurrentItem( 0 ); + else + m_toDesktop->setCurrentItem( wm_client.desktop() + 1 ); // compensate for separator (+1) +} + +void KNote::slotUpdateViewport( int /*x*/, int y ) +{ + if ( s_ppOffset ) + updateBackground( y ); +} + +// -------------------- private methods -------------------- // + +void KNote::toDesktop( int desktop ) +{ + if ( desktop == 0 ) + return; + + if ( desktop == NETWinInfo::OnAllDesktops ) + KWin::setOnAllDesktops( winId(), true ); + else + KWin::setOnDesktop( winId(), desktop ); +} + +void KNote::createFold() +{ + QPixmap fold( 15, 15 ); + QPainter foldp( &fold ); + foldp.setPen( Qt::NoPen ); + foldp.setBrush( palette().active().dark() ); + QPointArray foldpoints( 3 ); + foldpoints.putPoints( 0, 3, 0, 0, 14, 0, 0, 14 ); + foldp.drawPolygon( foldpoints ); + foldp.end(); + m_fold->setPixmap( fold ); +} + +void KNote::updateLabelAlignment() +{ + // if the name is too long to fit, left-align it, otherwise center it (#59028) + QString labelText = m_label->text(); + if ( m_label->fontMetrics().boundingRect( labelText ).width() > m_label->width() ) + m_label->setAlignment( AlignLeft ); + else + m_label->setAlignment( AlignHCenter ); +} + +void KNote::updateFocus() +{ + if ( hasFocus() ) + { + m_label->setBackgroundColor( palette().active().shadow() ); + m_button->show(); + m_editor->cornerWidget()->show(); + + if ( !m_editor->isReadOnly() ) + { + if ( m_tool && m_tool->isHidden() && m_editor->textFormat() == QTextEdit::RichText ) + { + m_tool->show(); + setGeometry( x(), y(), width(), height() + m_tool->height() ); + } + } + else if ( m_tool && !m_tool->isHidden() ) + { + m_tool->hide(); + setGeometry( x(), y(), width(), height() - m_tool->height() ); + updateLayout(); // to update the minimum height + } + + m_fold->hide(); + } + else + { + m_button->hide(); + m_editor->cornerWidget()->hide(); + + if ( m_tool && !m_tool->isHidden() ) + { + m_tool->hide(); + setGeometry( x(), y(), width(), height() - m_tool->height() ); + updateLayout(); // to update the minimum height + } + + if ( s_ppOffset ) + { + m_label->setBackgroundColor( palette().active().midlight() ); + m_fold->show(); + } + else + m_label->setBackgroundColor( palette().active().background() ); + } +} + +void KNote::updateMask() +{ + if ( !s_ppOffset ) + { + clearMask(); + return; + } + + int w = width(); + int h = height(); + QRegion reg( 0, s_ppOffset, w, h - s_ppOffset ); + + const QBitmap *pushpin_bitmap = m_pushpin->pixmap()->mask(); + QRegion pushpin_reg( *pushpin_bitmap ); + m_pushpin->setMask( pushpin_reg ); + pushpin_reg.translate( m_pushpin->x(), m_pushpin->y() ); + + if ( !hasFocus() ) + { + QPointArray foldpoints( 3 ); + foldpoints.putPoints( 0, 3, w-15, h, w, h-15, w, h ); + QRegion fold( foldpoints, false ); + setMask( reg.unite( pushpin_reg ).subtract( fold ) ); + } + else + setMask( reg.unite( pushpin_reg ) ); +} + +void KNote::updateBackground( int y_offset ) +{ + if ( !s_ppOffset ) + { + m_editor->setPaper( QBrush( colorGroup().background() ) ); + return; + } + + int w = m_editor->visibleWidth(); + int h = m_editor->visibleHeight(); + + // in case y_offset is not set, calculate y_offset as the content + // y-coordinate of the top-left point of the viewport - which is essentially + // the vertical scroll amount + if ( y_offset == -1 ) + y_offset = m_editor->contentsY(); + + y_offset = y_offset % h; + + QImage grad_img( w, h, 32 ); + QRgb rgbcol; + QColor bg = palette().active().background(); + + for ( int i = 0; i < h; ++i ) + { + // if the scrollbar has moved, then adjust the gradient by the amount the + // scrollbar moved -- so that the background gradient looks ok when tiled + + // the lightness is calculated as follows: + // if i >= y, then lightness = 150 - (i-y)*75/h; + // if i < y, then lightness = 150 - (i+h-y)*75/h + + int i_1 = 150 - 75 * ((i - y_offset + h) % h) / h; + rgbcol = bg.light( i_1 ).rgb(); + for ( int j = 0; j < w; ++j ) + grad_img.setPixel( j, i, rgbcol ); + } + + // setPaletteBackgroundPixmap makes QTextEdit::color() stop working!! + m_editor->setPaper( QBrush( Qt::black, QPixmap( grad_img ) ) ); +} + +void KNote::updateLayout() +{ + const int headerHeight = m_label->sizeHint().height(); + const int margin = m_editor->margin(); + bool closeLeft = false; + + m_kwinConf->setGroup( "Style" ); + if ( m_kwinConf->readBoolEntry( "CustomButtonPositions" ) ) + closeLeft = m_kwinConf->readEntry( "ButtonsOnLeft" ).find( 'X' ) > -1; + + if ( s_ppOffset ) + { + if ( !m_editor->paper().pixmap() ) // just changed the style + setColor( palette().active().foreground(), palette().active().background() ); + + m_pushpin->show(); + setFrameStyle( Panel | Raised ); + + if ( closeLeft ) + m_pushpin->move( width() - m_pushpin->width(), 0 ); + else + m_pushpin->move( 0, 0 ); + } + else + { + if ( m_editor->paper().pixmap() ) // just changed the style + setColor( palette().active().foreground(), palette().active().background() ); + + setFrameStyle( WinPanel | Raised ); + m_pushpin->hide(); + m_fold->hide(); + } + + m_button->setGeometry( + closeLeft ? contentsRect().x() : contentsRect().width() - headerHeight, + contentsRect().y() + s_ppOffset, + headerHeight, + headerHeight + ); + + m_label->setGeometry( + contentsRect().x(), contentsRect().y() + s_ppOffset, + contentsRect().width(), headerHeight + ); + + m_editor->setGeometry( QRect( + QPoint( contentsRect().x(), + contentsRect().y() + headerHeight + s_ppOffset ), + QPoint( contentsRect().right(), + contentsRect().bottom() - ( m_tool ? (m_tool->isHidden() ? 0 : m_tool->height()) : 0 ) ) + ) ); + + if( m_tool ) { + m_tool->setGeometry( + contentsRect().x(), + contentsRect().bottom() - m_tool->height() + 1, + contentsRect().width(), + m_tool->height() + ); + } + + if ( s_ppOffset ) + m_fold->move( width() - 15, height() - 15 ); + + setMinimumSize( + m_editor->cornerWidget()->width() + margin*2, + headerHeight + s_ppOffset + ( m_tool ? (m_tool->isHidden() ? 0 : m_tool->height() ) : 0 ) + + m_editor->cornerWidget()->height() + margin*2 + ); + + updateLabelAlignment(); + updateMask(); + updateBackground(); +} + +// -------------------- protected methods -------------------- // + +void KNote::drawFrame( QPainter *p ) +{ + QRect r = frameRect(); + r.setTop( s_ppOffset ); + if ( s_ppOffset ) + qDrawShadePanel( p, r, colorGroup(), false, lineWidth() ); + else + qDrawWinPanel( p, r, colorGroup(), false ); +} + +void KNote::showEvent( QShowEvent * ) +{ + if ( m_config->hideNote() ) + { + // KWin does not preserve these properties for hidden windows + slotUpdateKeepAboveBelow(); + slotUpdateShowInTaskbar(); + toDesktop( m_config->desktop() ); + move( m_config->position() ); + m_config->setHideNote( false ); + } +} + +void KNote::resizeEvent( QResizeEvent *qre ) +{ + QFrame::resizeEvent( qre ); + updateLayout(); +} + +void KNote::closeEvent( QCloseEvent * ) +{ + slotClose(); +} + +void KNote::dragEnterEvent( QDragEnterEvent *e ) +{ + if ( !m_config->readOnly() ) + e->accept( KColorDrag::canDecode( e ) ); +} + +void KNote::dropEvent( QDropEvent *e ) +{ + if ( m_config->readOnly() ) + return; + + QColor bg; + if ( KColorDrag::decode( e, bg ) ) + setColor( paletteForegroundColor(), bg ); +} + +bool KNote::focusNextPrevChild( bool ) +{ + return true; +} + +bool KNote::event( QEvent *ev ) +{ + if ( ev->type() == QEvent::LayoutHint ) + { + updateLayout(); + return true; + } + else + return QFrame::event( ev ); +} + +bool KNote::eventFilter( QObject *o, QEvent *ev ) +{ + if ( ev->type() == QEvent::DragEnter && + KColorDrag::canDecode( static_cast(ev) ) ) + { + dragEnterEvent( static_cast(ev) ); + return true; + } + + if ( ev->type() == QEvent::Drop && + KColorDrag::canDecode( static_cast(ev) ) ) + { + dropEvent( static_cast(ev) ); + return true; + } + + if ( o == m_label ) + { + QMouseEvent *e = (QMouseEvent *)ev; + + if ( ev->type() == QEvent::MouseButtonDblClick ) + slotRename(); + + if ( ev->type() == QEvent::MouseButtonPress && + (e->button() == LeftButton || e->button() == MidButton)) + { + e->button() == LeftButton ? KWin::raiseWindow( winId() ) + : KWin::lowerWindow( winId() ); + + XUngrabPointer( qt_xdisplay(), qt_x_time ); + NETRootInfo wm_root( qt_xdisplay(), NET::WMMoveResize ); + wm_root.moveResizeRequest( winId(), e->globalX(), e->globalY(), NET::Move ); + return true; + } + +#if KDE_IS_VERSION( 3, 5, 1 ) + if ( ev->type() == QEvent::MouseButtonRelease ) + { + NETRootInfo wm_root( qt_xdisplay(), NET::WMMoveResize ); + wm_root.moveResizeRequest( winId(), e->globalX(), e->globalY(), NET::MoveResizeCancel ); + return false; + } +#endif + + if ( m_menu && ( ev->type() == QEvent::MouseButtonPress ) + && ( e->button() == RightButton ) ) + { + m_menu->popup( QCursor::pos() ); + return true; + } + + return false; + } + + if ( o == m_editor ) + { + if ( ev->type() == QEvent::FocusOut ) + { + QFocusEvent *fe = static_cast(ev); + if ( fe->reason() != QFocusEvent::Popup && + fe->reason() != QFocusEvent::Mouse ) + { + updateFocus(); + if ( m_editor->isModified() ) + saveData(); + } + } + else if ( ev->type() == QEvent::FocusIn ) + updateFocus(); + + return false; + } + + if ( o == m_editor->viewport() ) + { + if ( m_edit_menu && + ev->type() == QEvent::MouseButtonPress && + ((QMouseEvent *)ev)->button() == RightButton ) + { + m_edit_menu->popup( QCursor::pos() ); + return true; + } + } + + return false; +} + + +#include "knote.moc" +#include "knotebutton.moc" diff --git a/knotes/knote.h b/knotes/knote.h new file mode 100644 index 000000000..0309f59d7 --- /dev/null +++ b/knotes/knote.h @@ -0,0 +1,175 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2006, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#ifndef KNOTE_H +#define KNOTE_H + +#include +#include +#include +#include +#include + +#include +#include + +class QLabel; + +class KXMLGUIBuilder; + +class KFind; +class KPopupMenu; +class KNoteButton; +class KNoteEdit; +class KNoteConfig; +class KToolBar; +class KListAction; +class KToggleAction; + +namespace KCal { + class Journal; +} + + +class KNote : public QFrame, virtual public KXMLGUIClient +{ + Q_OBJECT +public: + KNote( QDomDocument buildDoc, KCal::Journal *journal, QWidget *parent = 0, + const char *name = 0 ); + ~KNote(); + + void saveData(); + void saveConfig() const; + + QString noteId() const; + + QString name() const; + QString text() const; + QString plainText() const; + + void setName( const QString& name ); + void setText( const QString& text ); + + QColor fgColor() const; + QColor bgColor() const; + void setColor( const QColor& fg, const QColor& bg ); + + void find( const QString& pattern, long options ); + + bool isModified() const; + + void sync( const QString& app ); + bool isNew( const QString& app ) const; + bool isModified( const QString& app ) const; + + static void setStyle( int style ); + +public slots: + void slotKill( bool force = false ); + +signals: + void sigRequestNewNote(); + void sigShowNextNote(); + void sigNameChanged(); + void sigDataChanged(); + void sigColorChanged(); + void sigKillNote( KCal::Journal* ); + + void sigFindFinished(); + +protected: + virtual void drawFrame( QPainter* ); + virtual void showEvent( QShowEvent* ); + virtual void resizeEvent( QResizeEvent* ); + virtual void closeEvent( QCloseEvent* ); + virtual void dropEvent( QDropEvent* ); + virtual void dragEnterEvent( QDragEnterEvent* ); + + virtual bool event( QEvent* ); + virtual bool eventFilter( QObject*, QEvent* ); + + virtual bool focusNextPrevChild( bool ); + +private slots: + void slotRename(); + void slotUpdateReadOnly(); + void slotClose(); + + void slotSend(); + void slotMail(); + void slotPrint(); + void slotSaveAs(); + + void slotInsDate(); + void slotSetAlarm(); + + void slotPreferences(); + void slotPopupActionToDesktop( int id ); + + void slotFindNext(); + void slotHighlight( const QString& txt, int idx, int len ); + + void slotApplyConfig(); + void slotUpdateKeepAboveBelow(); + void slotUpdateShowInTaskbar(); + void slotUpdateDesktopActions(); + + void slotUpdateViewport( int, int ); + +private: + void updateFocus(); + void updateMask(); + void updateLayout(); + void updateLabelAlignment(); + void updateBackground( int offset = -1 ); + + void createFold(); + + void toDesktop( int desktop ); + + QString toPlainText( const QString& ); + +private: + QLabel *m_label, *m_pushpin, *m_fold; + KNoteButton *m_button; + KToolBar *m_tool; + KNoteEdit *m_editor; + + KNoteConfig *m_config; + KCal::Journal *m_journal; + + KFind *m_find; + + KPopupMenu *m_menu; + KPopupMenu *m_edit_menu; + + KToggleAction *m_readOnly; + + KListAction *m_toDesktop; + KToggleAction *m_keepAbove; + KToggleAction *m_keepBelow; + + KSharedConfig::Ptr m_kwinConf; + + static int s_ppOffset; +}; + +#endif diff --git a/knotes/knotealarmdlg.cpp b/knotes/knotealarmdlg.cpp new file mode 100644 index 000000000..0acd44214 --- /dev/null +++ b/knotes/knotealarmdlg.cpp @@ -0,0 +1,152 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2005, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include "knotealarmdlg.h" + + +KNoteAlarmDlg::KNoteAlarmDlg( const QString& caption, QWidget *parent, const char *name ) + : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok ) +{ + QVBox *page = makeVBoxMainWidget(); + QGroupBox *group = new QGroupBox( 3, Vertical, i18n("Scheduled Alarm"), page ); + m_buttons = new QButtonGroup( page ); + m_buttons->hide(); + + QRadioButton *none = new QRadioButton( i18n("&No alarm"), group ); + m_buttons->insert( none ); + + QHBox *at = new QHBox( group ); + QRadioButton *label_at = new QRadioButton( i18n("Alarm &at:"), at ); + m_buttons->insert( label_at ); + m_atDate = new KDateEdit( at ); + m_atTime = new KTimeEdit( at ); + at->setStretchFactor( m_atDate, 1 ); + + QHBox *in = new QHBox( group ); + QRadioButton *label_in = new QRadioButton( i18n("Alarm &in:"), in ); + m_buttons->insert( label_in ); + m_inTime = new KTimeEdit( in ); + QLabel *in_min = new QLabel( i18n("hours/minutes"), in ); + + label_in->setEnabled( false ); // TODO + + connect( m_buttons, SIGNAL(clicked( int )), SLOT(slotButtonChanged( int )) ); +} + + +void KNoteAlarmDlg::setIncidence( KCal::Journal *journal ) +{ + m_journal = journal; + + if ( !m_journal->alarms().isEmpty() ) + { + KCal::Alarm *alarm = m_journal->alarms().first(); + if ( alarm->hasTime() ) + { + m_buttons->setButton( 1 ); + m_atDate->setDate( alarm->time().date() ); + m_atTime->setTime( alarm->time().time() ); + } + else if ( alarm->hasStartOffset() ) + m_buttons->setButton( 2 ); + else + m_buttons->setButton( 0 ); + } + else + m_buttons->setButton( 0 ); + + slotButtonChanged( m_buttons->selectedId() ); +} + +void KNoteAlarmDlg::slotButtonChanged( int id ) +{ + switch ( id ) + { + case 0: + m_atDate->setEnabled( false ); + m_atTime->setEnabled( false ); + m_inTime->setEnabled( false ); + break; + case 1: + m_atDate->setEnabled( true ); + m_atTime->setEnabled( true ); + m_inTime->setEnabled( false ); + break; + case 2: + m_atDate->setEnabled( false ); + m_atTime->setEnabled( false ); + m_inTime->setEnabled( true ); + } +} + +void KNoteAlarmDlg::slotOk() +{ + if ( m_buttons->selectedId() == 0 ) + { + m_journal->clearAlarms(); + KDialogBase::slotOk(); + return; + } + + KCal::Alarm *alarm; + if ( m_journal->alarms().isEmpty() ) + { + alarm = m_journal->newAlarm(); + alarm->setEnabled( true ); + alarm->setType( KCal::Alarm::Display ); + } + else + alarm = m_journal->alarms().first(); + + if ( m_buttons->selectedId() == 1 ) + alarm->setTime( QDateTime( m_atDate->date(), m_atTime->getTime() ) ); + else + { + // TODO + } + + KDialogBase::slotOk(); +} + +#include "knotealarmdlg.moc" diff --git a/knotes/knotealarmdlg.h b/knotes/knotealarmdlg.h new file mode 100644 index 000000000..e39f81869 --- /dev/null +++ b/knotes/knotealarmdlg.h @@ -0,0 +1,68 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2005, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef KNOTEALARMDLG_H +#define KNOTEALARMDLG_H + +#include + +class QButtonGroup; +class KDateEdit; +class KTimeEdit; + +namespace KCal { + class Journal; +} + + +class KNoteAlarmDlg : public KDialogBase +{ + Q_OBJECT +public: + KNoteAlarmDlg( const QString& caption, QWidget *parent=0, const char *name=0 ); + + void setIncidence( KCal::Journal *journal ); + +protected: + virtual void slotOk(); + +private slots: + void slotButtonChanged( int id ); + +private: + QButtonGroup *m_buttons; + KCal::Journal *m_journal; + + KDateEdit *m_atDate; + KTimeEdit *m_atTime, *m_inTime; +}; + +#endif diff --git a/knotes/knotebutton.cpp b/knotes/knotebutton.cpp new file mode 100644 index 000000000..372510010 --- /dev/null +++ b/knotes/knotebutton.cpp @@ -0,0 +1,111 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2002-2004, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#include +#include +#include +#include + +#include +#include +#include + +#include "knotebutton.h" + + +KNoteButton::KNoteButton( const QString& icon, QWidget *parent, const char *name ) + : QPushButton( parent, name ) +{ + setFocusPolicy( NoFocus ); + setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + + m_flat = true; + + if ( !icon.isEmpty() ) + setIconSet( KGlobal::iconLoader()->loadIconSet( icon, KIcon::Small, 10 ) ); +} + +KNoteButton::~KNoteButton() +{ +} + +void KNoteButton::enterEvent( QEvent * ) +{ + m_flat = false; + repaint( false ); +} + +void KNoteButton::leaveEvent( QEvent * ) +{ + m_flat = true; + repaint(); +} + +QSize KNoteButton::sizeHint() const +{ + return QSize( QPushButton::sizeHint().height(), QPushButton::sizeHint().height() ); +} + +void KNoteButton::drawButton( QPainter* p ) +{ + QStyle::SFlags flags = QStyle::Style_Default; + + if ( isEnabled() ) + flags |= QStyle::Style_Enabled; + if ( isDown() ) + flags |= QStyle::Style_Down; + if ( isOn() ) + flags |= QStyle::Style_On; + if ( !isFlat() && !isDown() ) + flags |= QStyle::Style_Raised; + if ( !m_flat ) + flags |= QStyle::Style_MouseOver; + + style().drawPrimitive( QStyle::PE_ButtonTool, p, rect(), colorGroup(), flags ); + drawButtonLabel( p ); +} + +void KNoteButton::drawButtonLabel( QPainter* p ) +{ + if ( iconSet() && !iconSet()->isNull() ) + { + QIconSet::Mode mode = QIconSet::Disabled; + QIconSet::State state = QIconSet::Off; + + if ( isEnabled() ) + mode = hasFocus() ? QIconSet::Active : QIconSet::Normal; + if ( isToggleButton() && isOn() ) + state = QIconSet::On; + + QPixmap pix = iconSet()->pixmap( QIconSet::Small, mode, state ); + + int dx = ( width() - pix.width() ) / 2; + int dy = ( height() - pix.height() ) / 2; + + // Shift button contents if pushed. + if ( isOn() || isDown() ) + { + dx += style().pixelMetric( QStyle::PM_ButtonShiftHorizontal, this ); + dy += style().pixelMetric( QStyle::PM_ButtonShiftVertical, this ); + } + + p->drawPixmap( dx, dy, pix ); + } +} diff --git a/knotes/knotebutton.h b/knotes/knotebutton.h new file mode 100644 index 000000000..9d0d2baa6 --- /dev/null +++ b/knotes/knotebutton.h @@ -0,0 +1,51 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2004, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#ifndef KNOTEBUTTON_H +#define KNOTEBUTTON_H + +#include + +class QPainter; +class QEvent; +class QResizeEvent; + + +class KNoteButton: public QPushButton +{ + Q_OBJECT +public: + KNoteButton( const QString& icon, QWidget *parent=0, const char *name=0 ); + ~KNoteButton(); + + virtual QSize sizeHint() const; + +protected: + virtual void enterEvent( QEvent * ); + virtual void leaveEvent( QEvent * ); + + virtual void drawButton( QPainter *p ); + virtual void drawButtonLabel( QPainter *p ); + +private: + bool m_flat; +}; + +#endif diff --git a/knotes/knoteconfig.kcfg b/knotes/knoteconfig.kcfg new file mode 100644 index 000000000..18a8c636c --- /dev/null +++ b/knotes/knoteconfig.kcfg @@ -0,0 +1,84 @@ + + + + + + + yellow + + + + black + + + + 200 + + + + 200 + + + + + + KGlobalSettings::generalFont() + + + + KGlobalSettings::windowTitleFont() + + + + true + + + + false + + + + 4 + + + + false + + + + + + + + + + + + -10 + + + + false + + + + QPoint( -10000, -10000 ) + + + + false + + + + false + + + + false + + + diff --git a/knotes/knoteconfig.kcfgc b/knotes/knoteconfig.kcfgc new file mode 100644 index 000000000..a0c69514a --- /dev/null +++ b/knotes/knoteconfig.kcfgc @@ -0,0 +1,3 @@ +File=knoteconfig.kcfg +ClassName=KNoteConfig +Mutators=true diff --git a/knotes/knoteconfigdlg.cpp b/knotes/knoteconfigdlg.cpp new file mode 100644 index 000000000..334ec37bd --- /dev/null +++ b/knotes/knoteconfigdlg.cpp @@ -0,0 +1,245 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2005, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "knote.h" +#include "knoteconfigdlg.h" +#include "knotesglobalconfig.h" +#include "version.h" + + +KNoteConfigDlg::KNoteConfigDlg( KNoteConfig *config, const QString& title, + QWidget *parent, const char *name ) + : KConfigDialog( parent, name, config ? config : KNotesGlobalConfig::self(), IconList, + config ? Default|Ok|Apply|Cancel : Default|Ok|Cancel, Ok ) +{ + setCaption( title ); + KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() ); + + setIconListAllVisible( true ); + enableButtonSeparator( true ); + + if ( config ) + { + addPage( makeDisplayPage( false ), i18n("Display"), "knotes", + i18n("Display Settings") ); + addPage( makeEditorPage( false ), i18n("Editor"), "edit", + i18n("Editor Settings") ); + } + else + { + config = KNotesGlobalConfig::self(); + addPage( makeDefaultsPage(), i18n("Defaults"), "knotes", + i18n("Default Settings for New Notes") ); + addPage( makeActionsPage(), i18n("Actions"), "misc", + i18n("Action Settings") ); + addPage( makeNetworkPage(), i18n("Network"), "network", + i18n("Network Settings") ); + addPage( makeStylePage(), i18n("Style"), "style", + i18n("Style Settings") ); + } + + config->setVersion( KNOTES_VERSION ); +} + +KNoteConfigDlg::~KNoteConfigDlg() +{ +} + +void KNoteConfigDlg::slotUpdateCaption() +{ + KNote *note = ::qt_cast(sender()); + if ( note ) + setCaption( note->name() ); +} + +QWidget *KNoteConfigDlg::makeDisplayPage( bool defaults ) +{ + QWidget *displayPage = new QWidget(); + QGridLayout *layout = new QGridLayout( displayPage, 2, 2, + defaults ? marginHint() : 0, spacingHint() ); + + QLabel *label_FgColor = new QLabel( i18n("&Text color:"), displayPage, "label_FgColor" ); + layout->addWidget( label_FgColor, 0, 0 ); + + KColorButton *kcfg_FgColor = new KColorButton( displayPage, "kcfg_FgColor" ); + label_FgColor->setBuddy( kcfg_FgColor ); + layout->addWidget( kcfg_FgColor, 0, 1 ); + + QLabel *label_BgColor = new QLabel( i18n("&Background color:"), displayPage, "label_BgColor" ); + layout->addWidget( label_BgColor, 1, 0 ); + + KColorButton *kcfg_BgColor = new KColorButton( displayPage, "kcfg_BgColor" ); + label_BgColor->setBuddy( kcfg_BgColor ); + layout->addWidget( kcfg_BgColor, 1, 1 ); + + QCheckBox *kcfg_ShowInTaskbar = new QCheckBox( i18n("&Show note in taskbar"), + displayPage, "kcfg_ShowInTaskbar" ); + + if ( defaults ) + { + QLabel *label_Width = new QLabel( i18n("Default &width:"), displayPage, "label_Width" ); + layout->addWidget( label_Width, 2, 0 ); + + KIntNumInput *kcfg_Width = new KIntNumInput( displayPage, "kcfg_Width" ); + label_Width->setBuddy( kcfg_Width ); + kcfg_Width->setRange( 50, 2000, 10, false ); + layout->addWidget( kcfg_Width, 2, 1 ); + + QLabel *label_Height = new QLabel( i18n("Default &height:"), displayPage, "label_Height" ); + layout->addWidget( label_Height, 3, 0 ); + + KIntNumInput *kcfg_Height = new KIntNumInput( displayPage, "kcfg_Height" ); + kcfg_Height->setRange( 50, 2000, 10, false ); + label_Height->setBuddy( kcfg_Height ); + layout->addWidget( kcfg_Height, 3, 1 ); + + layout->addWidget( kcfg_ShowInTaskbar, 4, 0 ); + } + else + layout->addWidget( kcfg_ShowInTaskbar, 2, 0 ); + + return displayPage; +} + +QWidget *KNoteConfigDlg::makeEditorPage( bool defaults ) +{ + QWidget *editorPage = new QWidget(); + QGridLayout *layout = new QGridLayout( editorPage, 4, 3, + defaults ? marginHint() : 0, spacingHint() ); + + QLabel *label_TabSize = new QLabel( i18n( "&Tab size:" ), editorPage, "label_TabSize" ); + layout->addMultiCellWidget( label_TabSize, 0, 0, 0, 1 ); + + KIntNumInput *kcfg_TabSize = new KIntNumInput( editorPage, "kcfg_TabSize" ); + kcfg_TabSize->setRange( 0, 40, 1, false ); + label_TabSize->setBuddy( kcfg_TabSize ); + layout->addWidget( kcfg_TabSize, 0, 2 ); + + QCheckBox *kcfg_AutoIndent = new QCheckBox( i18n("Auto &indent"), editorPage, "kcfg_AutoIndent" ); + layout->addMultiCellWidget( kcfg_AutoIndent, 1, 1, 0, 1 ); + + QCheckBox *kcfg_RichText = new QCheckBox( i18n("&Rich text"), editorPage, "kcfg_RichText" ); + layout->addWidget( kcfg_RichText, 1, 2 ); + + QLabel *label_Font = new QLabel( i18n("Text font:"), editorPage, "label_Font" ); + layout->addWidget( label_Font, 3, 0 ); + + KFontRequester *kcfg_Font = new KFontRequester( editorPage, "kcfg_Font" ); + kcfg_Font->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) ); + layout->addMultiCellWidget( kcfg_Font, 3, 3, 1, 2 ); + + QLabel *label_TitleFont = new QLabel( i18n("Title font:"), editorPage, "label_TitleFont" ); + layout->addWidget( label_TitleFont, 2, 0 ); + + KFontRequester *kcfg_TitleFont = new KFontRequester( editorPage, "kcfg_TitleFont" ); + kcfg_TitleFont->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) ); + layout->addMultiCellWidget( kcfg_TitleFont, 2, 2, 1, 2 ); + + return editorPage; +} + +QWidget *KNoteConfigDlg::makeDefaultsPage() +{ + QTabWidget *defaultsPage = new QTabWidget(); + defaultsPage->addTab( makeDisplayPage( true ), SmallIconSet( "knotes" ), i18n("Displa&y") ); + defaultsPage->addTab( makeEditorPage( true ), SmallIconSet( "edit" ), i18n("&Editor") ); + + return defaultsPage; +} + +QWidget *KNoteConfigDlg::makeActionsPage() +{ + QWidget *actionsPage = new QWidget(); + QGridLayout *layout = new QGridLayout( actionsPage, 2, 2, 0, spacingHint() ); + + QLabel *label_MailAction = new QLabel( i18n("&Mail action:"), actionsPage, "label_MailAction" ); + layout->addWidget( label_MailAction, 0, 0 ); + + KLineEdit *kcfg_MailAction = new KLineEdit( actionsPage, "kcfg_MailAction" ); + label_MailAction->setBuddy( kcfg_MailAction ); + layout->addWidget( kcfg_MailAction, 0, 1 ); + + return actionsPage; +} + +QWidget *KNoteConfigDlg::makeNetworkPage() +{ + QWidget *networkPage = new QWidget(); + QGridLayout *layout = new QGridLayout( networkPage, 4, 2, 0, spacingHint() ); + + QGroupBox *incoming = new QHGroupBox( i18n("Incoming Notes"), networkPage ); + layout->addMultiCellWidget( incoming, 0, 0, 0, 1 ); + + new QCheckBox( i18n("Accept incoming notes"), incoming, "kcfg_ReceiveNotes" ); + + QGroupBox *outgoing = new QHGroupBox( i18n("Outgoing Notes"), networkPage ); + layout->addMultiCellWidget( outgoing, 1, 1, 0, 1 ); + + QLabel *label_SenderID = new QLabel( i18n("&Sender ID:"), outgoing, "label_SenderID" ); + KLineEdit *kcfg_SenderID = new KLineEdit( outgoing, "kcfg_SenderID" ); + label_SenderID->setBuddy( kcfg_SenderID ); + + QLabel *label_Port = new QLabel( i18n("&Port:"), networkPage, "label_Port" ); + layout->addWidget( label_Port, 2, 0 ); + + KIntNumInput *kcfg_Port = new KIntNumInput( networkPage, "kcfg_Port" ); + kcfg_Port->setRange( 0, 65535, 1, false ); + label_Port->setBuddy( kcfg_Port ); + layout->addWidget( kcfg_Port, 2, 1 ); + + return networkPage; +} + +QWidget *KNoteConfigDlg::makeStylePage() +{ + QWidget *stylePage = new QWidget(); + QGridLayout *layout = new QGridLayout( stylePage, 2, 2, 0, spacingHint() ); + + QLabel *label_Style = new QLabel( i18n("&Style:"), stylePage, "label_Style" ); + layout->addWidget( label_Style, 0, 0 ); + + QComboBox *kcfg_Style = new QComboBox( stylePage, "kcfg_Style" ); + QStringList list; + list << "Plain" << "Fancy"; + kcfg_Style->insertStringList( list ); + label_Style->setBuddy( kcfg_Style ); + layout->addWidget( kcfg_Style, 0, 1 ); + + return stylePage; +} + +#include "knoteconfigdlg.moc" diff --git a/knotes/knoteconfigdlg.h b/knotes/knoteconfigdlg.h new file mode 100644 index 000000000..2232b5e93 --- /dev/null +++ b/knotes/knoteconfigdlg.h @@ -0,0 +1,51 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2005, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#ifndef KNOTECONFIGDLG_H +#define KNOTECONFIGDLG_H + +#include + +class QString; +class KNoteConfig; + + +class KNoteConfigDlg : public KConfigDialog +{ + Q_OBJECT +public: + KNoteConfigDlg( KNoteConfig *config, const QString &title, + QWidget *parent=0, const char *name=0 ); + ~KNoteConfigDlg(); + +public slots: + void slotUpdateCaption(); + +protected: + QWidget *makeDisplayPage( bool ); + QWidget *makeEditorPage( bool ); + + QWidget *makeDefaultsPage(); + QWidget *makeActionsPage(); + QWidget *makeNetworkPage(); + QWidget *makeStylePage(); +}; + +#endif diff --git a/knotes/knoteedit.cpp b/knotes/knoteedit.cpp new file mode 100644 index 000000000..2398df19f --- /dev/null +++ b/knotes/knoteedit.cpp @@ -0,0 +1,495 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2005, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "knoteedit.h" + +static const short SEP = 5; +static const short ICON_SIZE = 10; + + +KNoteEdit::KNoteEdit( KActionCollection *actions, QWidget *parent, const char *name ) + : KTextEdit( parent, name ) +{ + setAcceptDrops( true ); + setWordWrap( WidgetWidth ); + setWrapPolicy( AtWhiteSpace ); + setLinkUnderline( true ); + + // create the actions for the RMB menu + KAction* undo = KStdAction::undo( this, SLOT(undo()), actions ); + KAction* redo = KStdAction::redo( this, SLOT(redo()), actions ); + undo->setEnabled( isUndoAvailable() ); + redo->setEnabled( isRedoAvailable() ); + + m_cut = KStdAction::cut( this, SLOT(cut()), actions ); + m_copy = KStdAction::copy( this, SLOT(copy()), actions ); + m_paste = KStdAction::paste( this, SLOT(paste()), actions ); + + m_cut->setEnabled( false ); + m_copy->setEnabled( false ); + m_paste->setEnabled( true ); + + connect( this, SIGNAL(undoAvailable(bool)), undo, SLOT(setEnabled(bool)) ); + connect( this, SIGNAL(redoAvailable(bool)), redo, SLOT(setEnabled(bool)) ); + + connect( this, SIGNAL(copyAvailable(bool)), m_cut, SLOT(setEnabled(bool)) ); + connect( this, SIGNAL(copyAvailable(bool)), m_copy, SLOT(setEnabled(bool)) ); + + new KAction( KStdGuiItem::clear(), 0, this, SLOT(clear()), actions, "edit_clear" ); + KStdAction::selectAll( this, SLOT(selectAll()), actions ); + + // create the actions modifying the text format + m_textBold = new KToggleAction( i18n("Bold"), "text_bold", CTRL + Key_B, 0, 0, + actions, "format_bold" ); + m_textItalic = new KToggleAction( i18n("Italic"), "text_italic", CTRL + Key_I, 0, 0, + actions, "format_italic" ); + m_textUnderline = new KToggleAction( i18n("Underline"), "text_under", CTRL + Key_U, 0, 0, + actions, "format_underline" ); + m_textStrikeOut = new KToggleAction( i18n("Strike Out"), "text_strike", CTRL + Key_S, 0, 0, + actions, "format_strikeout" ); + + connect( m_textBold, SIGNAL(toggled(bool)), SLOT(setBold(bool)) ); + connect( m_textItalic, SIGNAL(toggled(bool)), SLOT(setItalic(bool)) ); + connect( m_textUnderline, SIGNAL(toggled(bool)), SLOT(setUnderline(bool)) ); + connect( m_textStrikeOut, SIGNAL(toggled(bool)), SLOT(textStrikeOut(bool)) ); + + m_textAlignLeft = new KToggleAction( i18n("Align Left"), "text_left", ALT + Key_L, + this, SLOT(textAlignLeft()), + actions, "format_alignleft" ); + m_textAlignLeft->setChecked( true ); // just a dummy, will be updated later + m_textAlignCenter = new KToggleAction( i18n("Align Center"), "text_center", ALT + Key_C, + this, SLOT(textAlignCenter()), + actions, "format_aligncenter" ); + m_textAlignRight = new KToggleAction( i18n("Align Right"), "text_right", ALT + Key_R, + this, SLOT(textAlignRight()), + actions, "format_alignright" ); + m_textAlignBlock = new KToggleAction( i18n("Align Block"), "text_block", ALT + Key_B, + this, SLOT(textAlignBlock()), + actions, "format_alignblock" ); + + m_textAlignLeft->setExclusiveGroup( "align" ); + m_textAlignCenter->setExclusiveGroup( "align" ); + m_textAlignRight->setExclusiveGroup( "align" ); + m_textAlignBlock->setExclusiveGroup( "align" ); + + m_textList = new KToggleAction( i18n("List"), "enum_list", 0, + this, SLOT(textList()), + actions, "format_list" ); + + m_textList->setExclusiveGroup( "style" ); + + m_textSuper = new KToggleAction( i18n("Superscript"), "text_super", 0, + this, SLOT(textSuperScript()), + actions, "format_super" ); + m_textSub = new KToggleAction( i18n("Subscript"), "text_sub", 0, + this, SLOT(textSubScript()), + actions, "format_sub" ); + + m_textSuper->setExclusiveGroup( "valign" ); + m_textSub->setExclusiveGroup( "valign" ); + +// There is no easy possibility to implement text indenting with QTextEdit +// +// m_textIncreaseIndent = new KAction( i18n("Increase Indent"), "format_increaseindent", 0, +// this, SLOT(textIncreaseIndent()), +// actions, "format_increaseindent" ); +// +// m_textDecreaseIndent = new KAction( i18n("Decrease Indent"), "format_decreaseindent", 0, +// this, SLOT(textDecreaseIndent()), +// actions, "format_decreaseindent" ); + + QPixmap pix( ICON_SIZE, ICON_SIZE ); + pix.fill( black ); // just a dummy, gets updated before widget is shown + m_textColor = new KAction( i18n("Text Color..."), pix, 0, this, + SLOT(textColor()), actions, "format_color" ); + + m_textFont = new KFontAction( i18n("Text Font"), "text", KKey(), + actions, "format_font" ); + connect( m_textFont, SIGNAL(activated( const QString & )), + this, SLOT(setFamily( const QString & )) ); + + m_textSize = new KFontSizeAction( i18n("Text Size"), KKey(), + actions, "format_size" ); + connect( m_textSize, SIGNAL(fontSizeChanged( int )), + this, SLOT(setPointSize( int )) ); + + // QTextEdit connections + connect( this, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect( this, SIGNAL(currentFontChanged( const QFont & )), + this, SLOT(fontChanged( const QFont & )) ); + connect( this, SIGNAL(currentColorChanged( const QColor & )), + this, SLOT(colorChanged( const QColor & )) ); + connect( this, SIGNAL(currentAlignmentChanged( int )), + this, SLOT(alignmentChanged( int )) ); + connect( this, SIGNAL(currentVerticalAlignmentChanged( VerticalAlignment )), + this, SLOT(verticalAlignmentChanged( VerticalAlignment )) ); +} + +KNoteEdit::~KNoteEdit() +{ +} + +void KNoteEdit::setText( const QString& text ) +{ + // to update the font and font size combo box - QTextEdit stopped + // emitting the currentFontChanged signal with the new optimizations + KTextEdit::setText( text ); + fontChanged( currentFont() ); +} + +void KNoteEdit::setTextFont( const QFont& font ) +{ + if ( textFormat() == PlainText ) + setFont( font ); + else + setCurrentFont( font ); +} + +void KNoteEdit::setTextColor( const QColor& color ) +{ + setColor( color ); + colorChanged( color ); +} + +void KNoteEdit::setTabStop( int tabs ) +{ + QFontMetrics fm( font() ); + setTabStopWidth( fm.width( 'x' ) * tabs ); +} + +void KNoteEdit::setAutoIndentMode( bool newmode ) +{ + m_autoIndentMode = newmode; +} + + +/** public slots **/ + +void KNoteEdit::setTextFormat( TextFormat f ) +{ + if ( f == textFormat() ) + return; + + if ( f == RichText ) + { + QString t = text(); + KTextEdit::setTextFormat( f ); + + // if the note contains html/xml source try to display it, otherwise + // get the modified text again and set it to preserve newlines + if ( QStyleSheet::mightBeRichText( t ) ) + setText( t ); + else + setText( text() ); + + enableRichTextActions(); + } + else + { + KTextEdit::setTextFormat( f ); + QString t = text(); + setText( t ); + + disableRichTextActions(); + } +} + +void KNoteEdit::textStrikeOut( bool s ) +{ + // QTextEdit does not support stroke out text (no saving, + // no changing of more than one selected character) + QFont font; + + if ( !hasSelectedText() ) + { + font = currentFont(); + font.setStrikeOut( s ); + setCurrentFont( font ); + } + else + { + int pFrom, pTo, iFrom, iTo, iF, iT; + int cp, ci; + + getSelection( &pFrom, &iFrom, &pTo, &iTo ); + getCursorPosition( &cp, &ci ); + + for ( int p = pFrom; p <= pTo; p++ ) + { + iF = 0; + iT = paragraphLength( p ); + + if ( p == pFrom ) + iF = iFrom; + + if ( p == pTo ) + iT = iTo; + + for ( int i = iF; i < iT; i++ ) + { + setCursorPosition( p, i + 1 ); + setSelection( p, i, p, i + 1 ); + font = currentFont(); + font.setStrikeOut( s ); + setCurrentFont( font ); + } + } + + setSelection( pFrom, iFrom, pTo, iTo ); + setCursorPosition( cp, ci ); + } +} + +void KNoteEdit::textColor() +{ + QColor c = color(); + int ret = KColorDialog::getColor( c, this ); + if ( ret == QDialog::Accepted ) + setTextColor( c ); +} + +void KNoteEdit::textAlignLeft() +{ + setAlignment( AlignLeft ); + m_textAlignLeft->setChecked( true ); +} + +void KNoteEdit::textAlignCenter() +{ + setAlignment( AlignCenter ); + m_textAlignCenter->setChecked( true ); +} + +void KNoteEdit::textAlignRight() +{ + setAlignment( AlignRight ); + m_textAlignRight->setChecked( true ); +} + +void KNoteEdit::textAlignBlock() +{ + setAlignment( AlignJustify ); + m_textAlignBlock->setChecked( true ); +} + +void KNoteEdit::textList() +{ + if ( m_textList->isChecked() ) + setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc ); + else + setParagType( QStyleSheetItem::DisplayBlock, QStyleSheetItem::ListDisc ); +} + +void KNoteEdit::textSuperScript() +{ + if ( m_textSuper->isChecked() ) + setVerticalAlignment( AlignSuperScript ); + else + setVerticalAlignment( AlignNormal ); +} + +void KNoteEdit::textSubScript() +{ + if ( m_textSub->isChecked() ) + setVerticalAlignment( AlignSubScript ); + else + setVerticalAlignment( AlignNormal ); +} + +//void KNoteEdit::textIncreaseIndent() +//{ +//} + +//void KNoteEdit::textDecreaseIndent() +//{ +//} + + +/** protected methods **/ + +void KNoteEdit::contentsDragEnterEvent( QDragEnterEvent *e ) +{ + if ( KURLDrag::canDecode( e ) ) + e->accept(); + else + KTextEdit::contentsDragEnterEvent( e ); +} + +void KNoteEdit::contentsDropEvent( QDropEvent *e ) +{ + KURL::List list; + + if ( KURLDrag::decode( e, list ) ) + for ( KURL::List::Iterator it = list.begin(); it != list.end(); ++it ) + { + if ( it != list.begin() ) + insert( ", " ); + + insert( (*it).prettyURL() ); + } + else + KTextEdit::contentsDropEvent( e ); +} + +/** private slots **/ + +void KNoteEdit::slotReturnPressed() +{ + if ( m_autoIndentMode ) + autoIndent(); +} + +void KNoteEdit::fontChanged( const QFont &f ) +{ + m_textFont->setFont( f.family() ); + m_textSize->setFontSize( f.pointSize() ); + + m_textBold->setChecked( f.bold() ); + m_textItalic->setChecked( f.italic() ); + m_textUnderline->setChecked( f.underline() ); + m_textStrikeOut->setChecked( f.strikeOut() ); +} + +void KNoteEdit::colorChanged( const QColor &c ) +{ + QPixmap pix( ICON_SIZE, ICON_SIZE ); + pix.fill( c ); + m_textColor->setIconSet( pix ); +} + +void KNoteEdit::alignmentChanged( int a ) +{ + // TODO: AlignAuto + if ( ( a == AlignAuto ) || ( a & AlignLeft ) ) + m_textAlignLeft->setChecked( true ); + else if ( ( a & AlignHCenter ) ) + m_textAlignCenter->setChecked( true ); + else if ( ( a & AlignRight ) ) + m_textAlignRight->setChecked( true ); + else if ( ( a & AlignJustify ) ) + m_textAlignBlock->setChecked( true ); +} + +void KNoteEdit::verticalAlignmentChanged( VerticalAlignment a ) +{ + if ( a == AlignNormal ) + { + m_textSuper->setChecked( false ); + m_textSub->setChecked( false ); + } + else if ( a == AlignSuperScript ) + m_textSuper->setChecked( true ); + else if ( a == AlignSubScript ) + m_textSub->setChecked( true ); +} + + +/** private methods **/ + +void KNoteEdit::autoIndent() +{ + int para, index; + QString string; + getCursorPosition( ¶, &index ); + while ( para > 0 && string.stripWhiteSpace().isEmpty() ) + string = text( --para ); + + if ( string.stripWhiteSpace().isEmpty() ) + return; + + // This routine returns the whitespace before the first non white space + // character in string. + // It is assumed that string contains at least one non whitespace character + // ie \n \r \t \v \f and space + QString indentString; + + int len = string.length(); + int i = 0; + while ( i < len && string.at(i).isSpace() ) + indentString += string.at( i++ ); + + if ( !indentString.isEmpty() ) + insert( indentString ); +} + +void KNoteEdit::emitLinkClicked( const QString &s ) +{ + kdDebug(5500) << k_funcinfo << s << endl; +} + +void KNoteEdit::enableRichTextActions() +{ + m_textColor->setEnabled( true ); + m_textFont->setEnabled( true ); + m_textSize->setEnabled( true ); + + m_textBold->setEnabled( true ); + m_textItalic->setEnabled( true ); + m_textUnderline->setEnabled( true ); + m_textStrikeOut->setEnabled( true ); + + m_textAlignLeft->setEnabled( true ); + m_textAlignCenter->setEnabled( true ); + m_textAlignRight->setEnabled( true ); + m_textAlignBlock->setEnabled( true ); + + m_textList->setEnabled( true ); + m_textSuper->setEnabled( true ); + m_textSub->setEnabled( true ); + +// m_textIncreaseIndent->setEnabled( true ); +// m_textDecreaseIndent->setEnabled( true ); +} + +void KNoteEdit::disableRichTextActions() +{ + m_textColor->setEnabled( false ); + m_textFont->setEnabled( false ); + m_textSize->setEnabled( false ); + + m_textBold->setEnabled( false ); + m_textItalic->setEnabled( false ); + m_textUnderline->setEnabled( false ); + m_textStrikeOut->setEnabled( false ); + + m_textAlignLeft->setEnabled( false ); + m_textAlignCenter->setEnabled( false ); + m_textAlignRight->setEnabled( false ); + m_textAlignBlock->setEnabled( false ); + + m_textList->setEnabled( false ); + m_textSuper->setEnabled( false ); + m_textSub->setEnabled( false ); + +// m_textIncreaseIndent->setEnabled( false ); +// m_textDecreaseIndent->setEnabled( false ); +} + +#include "knoteedit.moc" diff --git a/knotes/knoteedit.h b/knotes/knoteedit.h new file mode 100644 index 000000000..94760f3a7 --- /dev/null +++ b/knotes/knoteedit.h @@ -0,0 +1,121 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2004, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#ifndef KNOTEEDIT_H +#define KNOTEEDIT_H + +#include + +#include + +class QFont; +class QColor; +class QPushButton; +class KAction; +class KActionCollection; +class KToggleAction; +class KFontAction; +class KFontSizeAction; + + +class KNoteEdit : public KTextEdit +{ + Q_OBJECT +public: + KNoteEdit( KActionCollection *actions, QWidget *parent=0, const char *name=0 ); + ~KNoteEdit(); + + void setText( const QString& text ); + void setTextFont( const QFont& font ); + void setTextColor( const QColor& color ); + void setTabStop( int tabs ); + void setAutoIndentMode( bool newmode ); + +public slots: + virtual void setTextFormat( TextFormat f ); + + void textStrikeOut( bool ); + + void textColor(); + + void textAlignLeft(); + void textAlignCenter(); + void textAlignRight(); + void textAlignBlock(); + + void textList(); + + void textSuperScript(); + void textSubScript(); + + //void textIncreaseIndent(); + //void textDecreaseIndent(); + +protected: + virtual void contentsDragEnterEvent( QDragEnterEvent *e ); + virtual void contentsDropEvent( QDropEvent *e ); + +private slots: + void slotReturnPressed(); + + void fontChanged( const QFont &f ); + void colorChanged( const QColor &c ); + void alignmentChanged( int a ); + void verticalAlignmentChanged( VerticalAlignment a ); + +private: + void autoIndent(); + + virtual bool linksEnabled() const { return true; } + virtual void emitLinkClicked( const QString &s ); + + void enableRichTextActions(); + void disableRichTextActions(); + +private: + KAction *m_cut; + KAction *m_copy; + KAction *m_paste; + + KToggleAction *m_textBold; + KToggleAction *m_textItalic; + KToggleAction *m_textUnderline; + KToggleAction *m_textStrikeOut; + + KToggleAction *m_textAlignLeft; + KToggleAction *m_textAlignCenter; + KToggleAction *m_textAlignRight; + KToggleAction *m_textAlignBlock; + + KToggleAction *m_textList; + KToggleAction *m_textSuper; + KToggleAction *m_textSub; + + //KAction *m_textIncreaseIndent; + //KAction *m_textDecreaseIndent; + + KAction *m_textColor; + KFontAction *m_textFont; + KFontSizeAction *m_textSize; + + bool m_autoIndentMode; +}; + +#endif diff --git a/knotes/knotehostdlg.cpp b/knotes/knotehostdlg.cpp new file mode 100644 index 000000000..7045c465c --- /dev/null +++ b/knotes/knotehostdlg.cpp @@ -0,0 +1,90 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2003, Daniel Martin + 2004, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "knotehostdlg.h" +#include "knotesglobalconfig.h" + + +KNoteHostDlg::KNoteHostDlg( const QString &caption, QWidget *parent, const char *name ) + : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok, true ) +{ + QVBox *page = makeVBoxMainWidget(); + (void)new QLabel( i18n("Hostname or IP address:"), page ); + + m_hostCombo = new KHistoryCombo( true, page ); + m_hostCombo->setMinimumWidth( fontMetrics().maxWidth() * 15 ); + m_hostCombo->setDuplicatesEnabled( false ); + + // Read known hosts from configfile + m_hostCombo->setHistoryItems( KNotesGlobalConfig::knownHosts(), true ); + m_hostCombo->setFocus(); + //m_hostCombo->completionObject()->setItems( KNotesGlobalConfig::hostCompletions() ); + connect( m_hostCombo->lineEdit(), SIGNAL( textChanged ( const QString & ) ), + this, SLOT( slotTextChanged( const QString & ) ) ); + slotTextChanged( m_hostCombo->lineEdit()->text() ); +} + +KNoteHostDlg::~KNoteHostDlg() +{ + if ( result() == Accepted ) + m_hostCombo->addToHistory( m_hostCombo->currentText().stripWhiteSpace() ); + + // Write known hosts to configfile + KNotesGlobalConfig::setKnownHosts( m_hostCombo->historyItems() ); + //KNotesGlobalConfig::setHostCompletions( m_hostCombo->completionObject()->items() ); + KNotesGlobalConfig::writeConfig(); +} + +void KNoteHostDlg::slotTextChanged( const QString& text ) +{ + enableButtonOK( !text.isEmpty() ); +} + +QString KNoteHostDlg::host() const +{ + return m_hostCombo->currentText(); +} + + +#include "knotehostdlg.moc" diff --git a/knotes/knotehostdlg.h b/knotes/knotehostdlg.h new file mode 100644 index 000000000..a48be2fb4 --- /dev/null +++ b/knotes/knotehostdlg.h @@ -0,0 +1,60 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2003, Daniel Martin + 2004, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef KNOTEHOSTDLG_H +#define KNOTEHOSTDLG_H + +#include + +class KHistoryCombo; + + +/** + * A dialog to request a hostname or IP address. + */ +class KNoteHostDlg : public KDialogBase +{ + Q_OBJECT +public: + KNoteHostDlg( const QString& caption, QWidget *parent=0, const char *name=0 ); + ~KNoteHostDlg(); + + QString host() const; + +private slots: + void slotTextChanged( const QString & ); + +private: + KHistoryCombo *m_hostCombo; +}; + +#endif diff --git a/knotes/knoteprinter.cpp b/knotes/knoteprinter.cpp new file mode 100644 index 000000000..d1e6ffd59 --- /dev/null +++ b/knotes/knoteprinter.cpp @@ -0,0 +1,153 @@ +#include "knoteprinter.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +KNotePrinter::KNotePrinter() : m_styleSheet( 0 ), m_mimeSourceFactory( 0 ) +{ +} + +void KNotePrinter::setContext( const QString& context ) +{ + m_context = context; +} + +QString KNotePrinter::context() const +{ + return m_context; +} + +void KNotePrinter::setMimeSourceFactory( QMimeSourceFactory* factory ) +{ + m_mimeSourceFactory = factory; +} + +QMimeSourceFactory* KNotePrinter::mimeSourceFactory() const +{ + return m_mimeSourceFactory; +} + +void KNotePrinter::setFont( const QFont& font ) +{ + m_font = font; +} + +QFont KNotePrinter::font() const +{ + return m_font; +} + +void KNotePrinter::setColorGroup( const QColorGroup& colorGroup ) +{ + m_colorGroup = colorGroup; +} + +QColorGroup KNotePrinter::colorGroup() const +{ + return m_colorGroup; +} + +void KNotePrinter::setStyleSheet( QStyleSheet* styleSheet ) +{ + m_styleSheet = styleSheet; +} + +QStyleSheet* KNotePrinter::styleSheet() const +{ + return m_styleSheet; +} + +void KNotePrinter::doPrint( KPrinter& printer, QPainter& painter, + const QString& content ) const +{ + const int margin = 40; // pt + + QPaintDeviceMetrics metrics( painter.device() ); + int marginX = margin * metrics.logicalDpiX() / 72; + int marginY = margin * metrics.logicalDpiY() / 72; + + QRect body( marginX, marginY, + metrics.width() - marginX * 2, + metrics.height() - marginY * 2 ); + + QSimpleRichText text( content, m_font, m_context, + m_styleSheet, m_mimeSourceFactory, + body.height() /*, linkColor, linkUnderline? */ ); + + text.setWidth( &painter, body.width() ); + QRect view( body ); + + int page = 1; + + for (;;) + { + text.draw( &painter, body.left(), body.top(), view, m_colorGroup ); + view.moveBy( 0, body.height() ); + painter.translate( 0, -body.height() ); + + // page numbers + painter.setFont( m_font ); + painter.drawText( + view.right() - painter.fontMetrics().width( QString::number( page ) ), + view.bottom() + painter.fontMetrics().ascent() + 5, QString::number( page ) + ); + + if ( view.top() >= text.height() ) + break; + + printer.newPage(); + page++; + } +} + +void KNotePrinter::printNote( const QString& name, const QString& content ) const +{ + KPrinter printer; + printer.setFullPage( true ); + + if ( !printer.setup( 0, i18n("Print %1").arg(name) ) ) + return; + QPainter painter; + painter.begin( &printer ); + doPrint( printer, painter, content ); + painter.end(); +} + +void KNotePrinter::printNotes( const QValueList& journals ) const +{ + if ( journals.isEmpty() ) + return; + + KPrinter printer; + printer.setFullPage( true ); + + if ( !printer.setup( 0, i18n("Print Note", "Print %n notes", journals.count() ) ) ) + return; + + QPainter painter; + painter.begin( &printer ); + QString content; + QValueListConstIterator it( journals.begin() ); + QValueListConstIterator end( journals.end() ); + while ( it != end ) { + KCal::Journal *j = *it; + it++; + content += "

" + j->summary() + "

"; + content += j->description(); + if ( it != end ) + content += "
"; + } + doPrint( printer, painter, content ); + painter.end(); +} + + diff --git a/knotes/knoteprinter.h b/knotes/knoteprinter.h new file mode 100644 index 000000000..8ce3dc763 --- /dev/null +++ b/knotes/knoteprinter.h @@ -0,0 +1,53 @@ +#ifndef KNOTEPRINTER_H +#define KNOTEPRINTER_H + +#include +#include +#include + +class QMimeSourceFactory; +class QStyleSheet; +template class QValueList; +class KPrinter; + +namespace KCal { + class Journal; +} + +class KNotePrinter { +public: + + KNotePrinter(); + + void printNote( const QString& name, + const QString& content ) const; + + void printNotes( const QValueList& journals ) const; + + void setFont( const QFont& font ); + QFont font() const; + + void setColorGroup( const QColorGroup& colorGroup ); + QColorGroup colorGroup() const; + + void setStyleSheet( QStyleSheet* styleSheet ); + QStyleSheet* styleSheet() const; + + void setContext( const QString& context ); + QString context() const; + + void setMimeSourceFactory( QMimeSourceFactory* factory ); + QMimeSourceFactory* mimeSourceFactory() const; + +private: + void doPrint( KPrinter& printer, QPainter& painter, + const QString& content ) const; + + QColorGroup m_colorGroup; + QFont m_font; + QStyleSheet* m_styleSheet; + QMimeSourceFactory* m_mimeSourceFactory; + QString m_context; +}; + +#endif // KNOTEPRINTER diff --git a/knotes/knotes.desktop b/knotes/knotes.desktop new file mode 100644 index 000000000..a455e07da --- /dev/null +++ b/knotes/knotes.desktop @@ -0,0 +1,91 @@ +[Desktop Entry] +DocPath=knotes/index.html +Exec=knotes +Icon=knotes +Terminal=false +Type=Application + +GenericName=Popup Notes +GenericName[af]=Opspring Notas +GenericName[ar]=الملاحظات المنبثقة +GenericName[bg]=Лепящи се бележки +GenericName[bs]=Popup bilješke +GenericName[ca]=Notes emergents +GenericName[cs]=Vyskakovací poznámky +GenericName[cy]=Naid-nodiadau +GenericName[da]=Popop-noter +GenericName[de]=Haftnotizen +GenericName[el]=Αναδυόμενες σημειώσεις +GenericName[eo]=Glunotoj +GenericName[es]=Notas emergentes +GenericName[et]=Hüpikmärkmed +GenericName[eu]=Laster-lehio oharrak +GenericName[fa]=یادداشتهای بالاپر +GenericName[fi]=Muistilaput +GenericName[fr]=Éditeur de petites notes +GenericName[fy]=Notysjes +GenericName[gl]=Notas Emerxentes +GenericName[he]=פתקים מוקפצים +GenericName[hi]=पॉप-अप टीप +GenericName[hr]=Skočne bilješke +GenericName[hu]=Jegyzettömb +GenericName[is]=Litlir gulir miðar +GenericName[it]=Note a comparsa +GenericName[ja]=ポップアップメモ +GenericName[ka]=მოტივტივე შენიშვნები +GenericName[kk]=Қалқымалы жазбалар +GenericName[km]=ចំណាំ​លេចឡើង +GenericName[lt]=Pastabos lapeliuose +GenericName[lv]=Izlecošās Piezīmes +GenericName[mk]=Скок-белешки +GenericName[ms]=Nota Popup +GenericName[mt]=Noti żgħar +GenericName[nb]=Sprettopp-notater +GenericName[nds]=Opduk-Notizen +GenericName[ne]=पपअप टिपोट +GenericName[nl]=Notities +GenericName[nn]=Sprettoppnotat +GenericName[nso]=Ditshwao tsa Thlarogo +GenericName[pl]=Żółte karteczki +GenericName[pt]=Notas +GenericName[pt_BR]=Notas instantâneas +GenericName[ro]=Notiţe personale +GenericName[ru]=Всплывающие заметки +GenericName[sk]=Vyskakujúce poznámky +GenericName[sl]=Prilepljajoče se notice +GenericName[sr]=Искачуће напомене +GenericName[sr@Latn]=Iskačuće napomene +GenericName[sv]=Anteckningslappar +GenericName[ta]=தோன்றும் குறிப்புகள் +GenericName[tg]=Хабарҳои ошкоршаванда +GenericName[th]=บันทึกช่วยจำแบบป๊อพอัพ +GenericName[tr]=Seyyar Notlar +GenericName[uk]=Вигулькні нотатки +GenericName[vi]=Ghi chép Popup +GenericName[xh]=Ivelisa iincwadana +GenericName[zh_CN]=弹出式记事本 +GenericName[zh_TW]=彈出式筆記本 +GenericName[zu]=Amapheshana Abhaliwe Aziphumelayo + +Name=KNotes +Name[af]=Knotas +Name[be]=K Нататкі +Name[cy]=KNodiadau +Name[eo]=Notoj +Name[hi]=के-नोट्स +Name[hr]=Bilješka +Name[lv]=KPiezīmes +Name[mk]=КБелешки +Name[ne]=केडीई टिपोट +Name[nso]=KDitshwao +Name[pl]=Notatki +Name[ro]=Notiţe +Name[sl]=KNotice +Name[sv]=Knotes +Name[ta]=கேகுறிப்புகள் +Name[th]=บันทึกช่วยจำ +Name[zh_TW]=KNotes 便利貼 + +X-KDE-StartupNotify=true +X-DCOP-ServiceType=Unique +Categories=Qt;KDE;Utility;X-KDE-Utilities-Desktop;Office; diff --git a/knotes/knotes_manager.desktop b/knotes/knotes_manager.desktop new file mode 100644 index 000000000..adce2afb5 --- /dev/null +++ b/knotes/knotes_manager.desktop @@ -0,0 +1,63 @@ +# KDE Config File +[Desktop Entry] +Name=Notes +Name[af]=Notas +Name[ar]=الملاحظات +Name[be]=Нататкі +Name[bg]=Бележки +Name[br]=Notennoù +Name[bs]=Bilješke +Name[cs]=Poznámky +Name[cy]=Nodiadau +Name[da]=Noter +Name[de]=Notizen +Name[el]=Σημειώσεις +Name[eo]=Notoj +Name[es]=Notas +Name[et]=Märkmed +Name[eu]=Oharrak +Name[fa]=یادداشتها +Name[fi]=Muistio +Name[fy]=Notysjes +Name[ga]=Nótaí +Name[gl]=Notas +Name[he]=פתקים +Name[hi]=टीप +Name[hu]=Feljegyzések +Name[is]=Minnismiðar +Name[it]=Note +Name[ja]=メモ +Name[ka]=ჩანიშვნები +Name[kk]=Жазбалар +Name[km]=ចំណាំ +Name[lt]=Užrašai +Name[mk]=Белешки +Name[ms]=Nota +Name[nds]=Notizen +Name[ne]=टिपोट +Name[nl]=Notities +Name[nn]=Notat +Name[pl]=Notatki +Name[pt]=Notas +Name[pt_BR]=Notas +Name[ro]=Notiţe +Name[ru]=Заметки +Name[se]=Nohtat +Name[sk]=Poznámky +Name[sl]=Notice +Name[sr]=Белешке +Name[sr@Latn]=Beleške +Name[sv]=Anteckningar +Name[ta]=குறிப்புகள் +Name[tg]=Ахборот +Name[th]=บันทึกช่วยจำ +Name[tr]=Notlar +Name[uk]=Примітки +Name[uz]=Yozma xotira +Name[uz@cyrillic]=Ёзма хотира +Name[zh_CN]=便笺 +Name[zh_TW]=備忘錄 +Type=Service +ServiceTypes=KResources/Manager + +X-KDE-ResourceFamily=notes diff --git a/knotes/knotesalarm.cpp b/knotes/knotesalarm.cpp new file mode 100644 index 000000000..056c448ed --- /dev/null +++ b/knotes/knotesalarm.cpp @@ -0,0 +1,78 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2005, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include + +#include +#include + +#include + +#include "knotes/resourcemanager.h" + +#include "knotesalarm.h" +#include "knotesglobalconfig.h" + + +KNotesAlarm::KNotesAlarm( KNotesResourceManager *manager, QObject *parent, const char *name ) + : QObject( parent, name ), + m_manager( manager ), + m_checkTimer( 0, "m_checkTimer" ) +{ + // TODO: fix timezone stuff? + + connect( &m_checkTimer, SIGNAL(timeout()), SLOT(checkAlarms()) ); + m_checkTimer.start( 1000 * KNotesGlobalConfig::self()->checkInterval() ); // interval in seconds +} + +void KNotesAlarm::checkAlarms() +{ + QDateTime from = KNotesGlobalConfig::self()->alarmsLastChecked().addSecs( 1 ); + if ( !from.isValid() ) + from.setTime_t( 0 ); + + KNotesGlobalConfig::self()->setAlarmsLastChecked( QDateTime::currentDateTime() ); + QValueList alarms = m_manager->alarms( from, KNotesGlobalConfig::self()->alarmsLastChecked() ); + + QStringList notes; + QValueList::ConstIterator it; + for ( it = alarms.begin(); it != alarms.end(); ++it ) + { + KCal::Incidence *incidence = (*it)->parent(); + notes += incidence->summary(); + } + + if ( !notes.isEmpty() ) + KMessageBox::informationList( 0, i18n("The following notes triggered alarms:"), notes, i18n("Alarm") ); +} + + +#include "knotesalarm.moc" diff --git a/knotes/knotesalarm.h b/knotes/knotesalarm.h new file mode 100644 index 000000000..3845c9660 --- /dev/null +++ b/knotes/knotesalarm.h @@ -0,0 +1,59 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2005, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef KNOTESALARM_H +#define KNOTESALARM_H + +#include +#include + +class KNotesResourceManager; + +namespace KCal { + class Incidence; +} + + +class KNotesAlarm : public QObject +{ + Q_OBJECT +public: + KNotesAlarm( KNotesResourceManager *manager, QObject *parent = 0, const char *name = 0 ); + +private slots: + void checkAlarms(); + +private: + KNotesResourceManager *m_manager; + QTimer m_checkTimer; +}; + +#endif diff --git a/knotes/knotesapp.cpp b/knotes/knotesapp.cpp new file mode 100644 index 000000000..80bf1f086 --- /dev/null +++ b/knotes/knotesapp.cpp @@ -0,0 +1,750 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2006, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "knotesapp.h" +#include "knote.h" +#include "knotesalarm.h" +#include "knoteconfigdlg.h" +#include "knotesglobalconfig.h" +#include "knoteslegacy.h" +#include "knotesnetrecv.h" + +#include "knotes/resourcemanager.h" + +using namespace KNetwork; + + +class KNotesKeyDialog : public KDialogBase +{ +public: + KNotesKeyDialog( KGlobalAccel *globals, QWidget *parent, const char* name = 0 ) + : KDialogBase( parent, name, true, i18n("Configure Shortcuts"), Default|Ok|Cancel, Ok ) + { + m_keyChooser = new KKeyChooser( globals, this ); + setMainWidget( m_keyChooser ); + connect( this, SIGNAL(defaultClicked()), m_keyChooser, SLOT(allDefault()) ); + } + + void insert( KActionCollection *actions ) + { + m_keyChooser->insert( actions, i18n("Note Actions") ); + } + + void configure() + { + if ( exec() == Accepted ) + m_keyChooser->save(); + } + +private: + KKeyChooser *m_keyChooser; +}; + + +int KNotesApp::KNoteActionList::compareItems( QPtrCollection::Item s1, QPtrCollection::Item s2 ) +{ + if ( ((KAction*)s1)->text() == ((KAction*)s2)->text() ) + return 0; + return ( ((KAction*)s1)->text() < ((KAction*)s2)->text() ? -1 : 1 ); +} + + +KNotesApp::KNotesApp() + : DCOPObject("KNotesIface"), QLabel( 0, 0, WType_TopLevel ), + m_alarm( 0 ), m_listener( 0 ), m_find( 0 ), m_findPos( 0 ) +{ + connect( kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()) ); + + m_noteList.setAutoDelete( true ); + m_noteActions.setAutoDelete( true ); + + // create the dock widget... + KWin::setSystemTrayWindowFor( winId(), qt_xrootwin() ); + QToolTip::add( this, i18n( "KNotes: Sticky notes for KDE" ) ); + setBackgroundMode( X11ParentRelative ); + setPixmap( KSystemTray::loadIcon( "knotes" ) ); + + // set the initial style + KNote::setStyle( KNotesGlobalConfig::style() ); + + // create the GUI... + new KAction( i18n("New Note"), "filenew", 0, + this, SLOT(newNote()), actionCollection(), "new_note" ); + new KAction( i18n("New Note From Clipboard"), "editpaste", 0, + this, SLOT(newNoteFromClipboard()), actionCollection(), "new_note_clipboard" ); + new KAction( i18n("Show All Notes"), "knotes", 0, + this, SLOT(showAllNotes()), actionCollection(), "show_all_notes" ); + new KAction( i18n("Hide All Notes"), "fileclose", 0, + this, SLOT(hideAllNotes()), actionCollection(), "hide_all_notes" ); + new KHelpMenu( this, kapp->aboutData(), false, actionCollection() ); + + KStdAction::find( this, SLOT(slotOpenFindDialog()), actionCollection() ); + KStdAction::preferences( this, SLOT(slotPreferences()), actionCollection() ); + KStdAction::keyBindings( this, SLOT(slotConfigureAccels()), actionCollection() ); + //FIXME: no shortcut removing!? + KStdAction::quit( this, SLOT(slotQuit()), actionCollection() )->setShortcut( 0 ); + + setXMLFile( instance()->instanceName() + "appui.rc" ); + + m_guiBuilder = new KXMLGUIBuilder( this ); + m_guiFactory = new KXMLGUIFactory( m_guiBuilder, this ); + m_guiFactory->addClient( this ); + + m_context_menu = static_cast(m_guiFactory->container( "knotes_context", this )); + m_note_menu = static_cast(m_guiFactory->container( "notes_menu", this )); + + // get the most recent XML UI file + QString xmlFileName = instance()->instanceName() + "ui.rc"; + QString filter = QString::fromLatin1( instance()->instanceName() + '/' ) + xmlFileName; + QStringList fileList = instance()->dirs()->findAllResources( "data", filter ) + + instance()->dirs()->findAllResources( "data", xmlFileName ); + + QString doc; + KXMLGUIClient::findMostRecentXMLFile( fileList, doc ); + m_noteGUI.setContent( doc ); + + // create accels for global shortcuts + m_globalAccel = new KGlobalAccel( this, "global accel" ); + m_globalAccel->insert( "global_new_note", i18n("New Note"), "", + ALT+SHIFT+Key_N, ALT+SHIFT+Key_N , + this, SLOT(newNote()), true, true ); + m_globalAccel->insert( "global_new_note_clipboard", i18n("New Note From Clipboard"), "", + ALT+SHIFT+Key_C, ALT+SHIFT+Key_C, + this, SLOT(newNoteFromClipboard()), true, true ); + m_globalAccel->insert( "global_hide_all_notes", i18n("Hide All Notes"), "", + ALT+SHIFT+Key_H, ALT+SHIFT+Key_H , + this, SLOT(hideAllNotes()), true, true ); + m_globalAccel->insert( "global_show_all_notes", i18n("Show All Notes"), "", + ALT+SHIFT+Key_S, ALT+SHIFT+Key_S, + this, SLOT(showAllNotes()), true, true ); + + m_globalAccel->readSettings(); + + KConfig *config = KGlobal::config(); + config->setGroup( "Global Keybindings" ); + m_globalAccel->setEnabled( config->readBoolEntry( "Enabled", true ) ); + + updateGlobalAccels(); + + // clean up old config files + KNotesLegacy::cleanUp(); + + // create the resource manager + m_manager = new KNotesResourceManager(); + connect( m_manager, SIGNAL(sigRegisteredNote( KCal::Journal * )), + this, SLOT(createNote( KCal::Journal * )) ); + connect( m_manager, SIGNAL(sigDeregisteredNote( KCal::Journal * )), + this, SLOT(killNote( KCal::Journal * )) ); + + // read the notes + m_manager->load(); + + // read the old config files, convert and add them + KCal::CalendarLocal calendar( QString::fromLatin1( "UTC" ) ); + if ( KNotesLegacy::convert( &calendar ) ) + { + KCal::Journal::List notes = calendar.journals(); + KCal::Journal::List::ConstIterator it; + for ( it = notes.begin(); it != notes.end(); ++it ) + m_manager->addNewNote( *it ); + + m_manager->save(); + } + + // set up the alarm reminder - do it after loading the notes because this + // is used as a check if updateNoteActions has to be called for a new note + m_alarm = new KNotesAlarm( m_manager, this ); + + // create the socket and possibly start listening for connections + m_listener = new KServerSocket(); + m_listener->setResolutionEnabled( true ); + connect( m_listener, SIGNAL(readyAccept()), SLOT(acceptConnection()) ); + updateNetworkListener(); + + if ( m_noteList.count() == 0 && !kapp->isRestored() ) + newNote(); + + updateNoteActions(); +} + +KNotesApp::~KNotesApp() +{ + saveNotes(); + + blockSignals( true ); + m_noteList.clear(); + blockSignals( false ); + + delete m_listener; + delete m_manager; + delete m_guiBuilder; +} + +bool KNotesApp::commitData( QSessionManager& ) +{ + saveConfigs(); + return true; +} + +// -------------------- public DCOP interface -------------------- // + +QString KNotesApp::newNote( const QString& name, const QString& text ) +{ + // create the new note + KCal::Journal *journal = new KCal::Journal(); + + // new notes have the current date/time as title if none was given + if ( !name.isEmpty() ) + journal->setSummary( name ); + else + journal->setSummary( KGlobal::locale()->formatDateTime( QDateTime::currentDateTime() ) ); + + // the body of the note + journal->setDescription( text ); + + m_manager->addNewNote( journal ); + + showNote( journal->uid() ); + + return journal->uid(); +} + +QString KNotesApp::newNoteFromClipboard( const QString& name ) +{ + const QString& text = KApplication::clipboard()->text(); + return newNote( name, text ); +} + +void KNotesApp::hideAllNotes() const +{ + QDictIterator it( m_noteList ); + for ( ; *it; ++it ) + (*it)->close(); +} + +void KNotesApp::showAllNotes() const +{ + QDictIterator it( m_noteList ); + for ( ; *it; ++it ) + { + (*it)->show(); + (*it)->setFocus(); + } +} + +void KNotesApp::showNote( const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + showNote( note ); + else + kdWarning(5500) << "showNote: no note with id: " << id << endl; +} + +void KNotesApp::hideNote( const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + note->hide(); + else + kdWarning(5500) << "hideNote: no note with id: " << id << endl; +} + +void KNotesApp::killNote( const QString& id, bool force ) +{ + KNote* note = m_noteList[id]; + if ( note ) + note->slotKill( force ); + else + kdWarning(5500) << "killNote: no note with id: " << id << endl; +} + +// "bool force = false" doesn't work with dcop +void KNotesApp::killNote( const QString& id ) +{ + killNote( id, false ); +} + +QMap KNotesApp::notes() const +{ + QMap notes; + QDictIterator it( m_noteList ); + + for ( ; it.current(); ++it ) + notes.insert( it.current()->noteId(), it.current()->name() ); + + return notes; +} + +QString KNotesApp::name( const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->name(); + else + return QString::null; +} + +QString KNotesApp::text( const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->text(); + else + return QString::null; +} + +void KNotesApp::setName( const QString& id, const QString& newName ) +{ + KNote* note = m_noteList[id]; + if ( note ) + note->setName( newName ); + else + kdWarning(5500) << "setName: no note with id: " << id << endl; +} + +void KNotesApp::setText( const QString& id, const QString& newText ) +{ + KNote* note = m_noteList[id]; + if ( note ) + note->setText( newText ); + else + kdWarning(5500) << "setText: no note with id: " << id << endl; +} + +QString KNotesApp::fgColor( const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->fgColor().name(); + else + return QString::null; +} + +QString KNotesApp::bgColor( const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->bgColor().name(); + else + return QString::null; +} + +void KNotesApp::setColor( const QString& id, const QString& fgColor, const QString& bgColor ) +{ + KNote* note = m_noteList[id]; + if ( note ) + note->setColor( QColor( fgColor ), QColor( bgColor ) ); + else + kdWarning(5500) << "setColor: no note with id: " << id << endl; +} + +int KNotesApp::width( const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->width(); + else + return 0; +} + +int KNotesApp::height( const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->height(); + else + return 0; +} + +void KNotesApp::move( const QString& id, int x, int y ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->move( x, y ); + else + kdWarning(5500) << "move: no note with id: " << id << endl; +} + +void KNotesApp::resize( const QString& id, int width, int height ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->resize( width, height ); + else + kdWarning(5500) << "resize: no note with id: " << id << endl; +} + +void KNotesApp::sync( const QString& app ) +{ + QDictIterator it( m_noteList ); + + for ( ; it.current(); ++it ) + it.current()->sync( app ); +} + +bool KNotesApp::isNew( const QString& app, const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->isNew( app ); + else + return false; +} + +bool KNotesApp::isModified( const QString& app, const QString& id ) const +{ + KNote* note = m_noteList[id]; + if ( note ) + return note->isModified( app ); + else + return false; +} + + +// ------------------- protected methods ------------------- // + +void KNotesApp::mousePressEvent( QMouseEvent* e ) +{ + if ( !rect().contains( e->pos() ) ) + return; + + switch ( e->button() ) + { + case LeftButton: + if ( m_noteList.count() == 1 ) + { + QDictIterator it( m_noteList ); + showNote( it.toFirst() ); + } + else if ( m_note_menu->count() > 0 ) + m_note_menu->popup( e->globalPos() ); + break; + case MidButton: + newNote(); + break; + case RightButton: + m_context_menu->popup( e->globalPos() ); + default: break; + } +} + +// -------------------- protected slots -------------------- // + +void KNotesApp::slotShowNote() +{ + // tell the WM to give this note focus + showNote( QString::fromUtf8( sender()->name() ) ); +} + +void KNotesApp::slotWalkThroughNotes() +{ + // show next note + QDictIterator it( m_noteList ); + KNote *first = it.toFirst(); + for ( ; *it; ++it ) + if ( (*it)->hasFocus() ) + { + if ( ++it ) + showNote( *it ); + else + showNote( first ); + break; + } +} + +void KNotesApp::slotOpenFindDialog() +{ + KFindDialog findDia( this, "find_dialog" ); + findDia.setHasSelection( false ); + findDia.setHasCursor( false ); + findDia.setSupportsBackwardsFind( false ); + + if ( findDia.exec() != QDialog::Accepted ) + return; + + delete m_findPos; + m_findPos = new QDictIterator( m_noteList ); + + // this could be in an own method if searching without a dialog should be possible + delete m_find; + m_find = new KFind( findDia.pattern(), findDia.options(), this ); + + slotFindNext(); +} + +void KNotesApp::slotFindNext() +{ + if ( **m_findPos ) + { + KNote *note = **m_findPos; + ++*m_findPos; + note->find( m_find->pattern(), m_find->options() ); + } + else + { + m_find->displayFinalDialog(); + delete m_find; + m_find = 0; + delete m_findPos; + m_findPos = 0; + } +} + +void KNotesApp::slotPreferences() +{ + // reuse the dialog if possible + if ( KNoteConfigDlg::showDialog( "KNotes Default Settings" ) ) + return; + + // create a new preferences dialog... + KNoteConfigDlg *dialog = new KNoteConfigDlg( 0, i18n("Settings"), this, + "KNotes Settings" ); + connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateNetworkListener()) ); + connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateStyle()) ); + dialog->show(); +} + +void KNotesApp::slotConfigureAccels() +{ + KNotesKeyDialog keys( m_globalAccel, this ); + QDictIterator notes( m_noteList ); + if ( !m_noteList.isEmpty() ) + keys.insert( (*notes)->actionCollection() ); + keys.configure(); + + m_globalAccel->writeSettings(); + updateGlobalAccels(); + + // update GUI doc for new notes + m_noteGUI.setContent( + KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() ) + ); + + if ( m_noteList.isEmpty() ) + return; + + notes.toFirst(); + QValueList list = (*notes)->actionCollection()->actions(); + for ( QValueList::iterator it = list.begin(); it != list.end(); ++it ) + { + notes.toFirst(); + for ( ++notes; *notes; ++notes ) + { + KAction *toChange = (*notes)->actionCollection()->action( (*it)->name() ); + if ( toChange->shortcut() != (*it)->shortcut() ) + toChange->setShortcut( (*it)->shortcut() ); + } + } +} + +void KNotesApp::slotNoteKilled( KCal::Journal *journal ) +{ + m_manager->deleteNote( journal ); + saveNotes(); +} + +void KNotesApp::slotQuit() +{ + QDictIterator it( m_noteList ); + + for ( ; *it; ++it ) + if ( (*it)->isModified() ) + (*it)->saveData(); + + saveConfigs(); + kapp->quit(); +} + + +// -------------------- private methods -------------------- // + +void KNotesApp::showNote( KNote* note ) const +{ + note->show(); + KWin::setCurrentDesktop( KWin::windowInfo( note->winId() ).desktop() ); + KWin::forceActiveWindow( note->winId() ); + note->setFocus(); +} + +void KNotesApp::createNote( KCal::Journal *journal ) +{ + KNote *newNote = new KNote( m_noteGUI, journal, 0, journal->uid().utf8() ); + m_noteList.insert( newNote->noteId(), newNote ); + + connect( newNote, SIGNAL(sigRequestNewNote()), SLOT(newNote()) ); + connect( newNote, SIGNAL(sigShowNextNote()), SLOT(slotWalkThroughNotes()) ); + connect( newNote, SIGNAL(sigKillNote( KCal::Journal* )), + SLOT(slotNoteKilled( KCal::Journal* )) ); + connect( newNote, SIGNAL(sigNameChanged()), SLOT(updateNoteActions()) ); + connect( newNote, SIGNAL(sigDataChanged()), SLOT(saveNotes()) ); + connect( newNote, SIGNAL(sigColorChanged()), SLOT(updateNoteActions()) ); + connect( newNote, SIGNAL(sigFindFinished()), SLOT(slotFindNext()) ); + + // don't call this during startup for each and every loaded note + if ( m_alarm ) + updateNoteActions(); +} + +void KNotesApp::killNote( KCal::Journal *journal ) +{ + // this kills the KNote object + m_noteList.remove( journal->uid() ); + updateNoteActions(); +} + +void KNotesApp::acceptConnection() +{ + // Accept the connection and make KNotesNetworkReceiver do the job + KBufferedSocket *s = static_cast(m_listener->accept()); + if ( s ) + { + KNotesNetworkReceiver *recv = new KNotesNetworkReceiver( s ); + connect( recv, SIGNAL(sigNoteReceived( const QString &, const QString & )), + this, SLOT(newNote( const QString &, const QString & )) ); + } +} + +void KNotesApp::saveNotes() +{ + KNotesGlobalConfig::writeConfig(); + m_manager->save(); +} + +void KNotesApp::saveConfigs() +{ + QDictIterator it( m_noteList ); + for ( ; it.current(); ++it ) + it.current()->saveConfig(); +} + +void KNotesApp::updateNoteActions() +{ + unplugActionList( "notes" ); + m_noteActions.clear(); + + for ( QDictIterator it( m_noteList ); it.current(); ++it ) + { + KAction *action = new KAction( it.current()->name().replace("&", "&&"), + KShortcut(), this, SLOT(slotShowNote()), + (QObject *)0, + it.current()->noteId().utf8() ); + KIconEffect effect; + QPixmap icon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1, + it.current()->paletteBackgroundColor(), false ); + action->setIconSet( icon ); + m_noteActions.append( action ); + } + + m_noteActions.sort(); + + if ( m_noteActions.isEmpty() ) + { + KAction *action = new KAction( i18n("No Notes") ); + m_noteActions.append( action ); + } + + plugActionList( "notes", m_noteActions ); +} + +void KNotesApp::updateGlobalAccels() +{ + if ( m_globalAccel->isEnabled() ) + { + KAction *action = actionCollection()->action( "new_note" ); + if ( action ) + action->setShortcut( m_globalAccel->shortcut( "global_new_note" ) ); + action = actionCollection()->action( "new_note_clipboard" ); + if ( action ) + action->setShortcut( m_globalAccel->shortcut( "global_new_note_clipboard" ) ); + action = actionCollection()->action( "hide_all_notes" ); + if ( action ) + action->setShortcut( m_globalAccel->shortcut( "global_hide_all_notes" ) ); + action = actionCollection()->action( "show_all_notes" ); + if ( action ) + action->setShortcut( m_globalAccel->shortcut( "global_show_all_notes" ) ); + + m_globalAccel->updateConnections(); + } + else + { + KAction *action = actionCollection()->action( "new_note" ); + if ( action ) + action->setShortcut( 0 ); + action = actionCollection()->action( "new_note_clipboard" ); + if ( action ) + action->setShortcut( 0 ); + action = actionCollection()->action( "hide_all_notes" ); + if ( action ) + action->setShortcut( 0 ); + action = actionCollection()->action( "show_all_notes" ); + if ( action ) + action->setShortcut( 0 ); + } +} + +void KNotesApp::updateNetworkListener() +{ + m_listener->close(); + + if ( KNotesGlobalConfig::receiveNotes() ) + { + m_listener->setAddress( QString::number( KNotesGlobalConfig::port() ) ); + m_listener->bind(); + m_listener->listen(); + } +} + +void KNotesApp::updateStyle() +{ + KNote::setStyle( KNotesGlobalConfig::style() ); + + QDictIterator it( m_noteList ); + for ( ; it.current(); ++it ) + QApplication::postEvent( *it, new QEvent( QEvent::LayoutHint ) ); +} + +#include "knotesapp.moc" diff --git a/knotes/knotesapp.h b/knotes/knotesapp.h new file mode 100644 index 000000000..f0cf8551b --- /dev/null +++ b/knotes/knotesapp.h @@ -0,0 +1,163 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2006, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#ifndef KNOTESAPP_H +#define KNOTESAPP_H + +#include +#include +#include +#include +#include + +#include +#include + +#include "KNotesAppIface.h" + +class KFind; +class KNote; +class KPopupMenu; +class KAction; +class KActionMenu; +class KGlobalAccel; +class KXMLGUIFactory; +class KXMLGUIBuilder; +class KNotesAlarm; +class KNotesResourceManager; + +namespace KCal { + class Journal; +} + +namespace KNetwork { + class KServerSocket; +} + + +class KNotesApp : public QLabel, public KSessionManaged, virtual public KXMLGUIClient, + virtual public KNotesAppIface +{ + Q_OBJECT +public: + KNotesApp(); + ~KNotesApp(); + + void showNote( const QString& id ) const; + void hideNote( const QString& id ) const; + + void killNote( const QString& id ); + void killNote( const QString& id, bool force ); + + QString name( const QString& id ) const; + QString text( const QString& id ) const; + + void setName( const QString& id, const QString& newName ); + void setText( const QString& id, const QString& newText ); + + QString fgColor( const QString& id ) const; + QString bgColor( const QString& id ) const; + + void setColor( const QString& id, const QString& fgColor, + const QString& bgColor ); + + QMap notes() const; + + int width( const QString& noteId ) const; + int height( const QString& noteId ) const; + + void move( const QString& noteId, int x, int y ) const; + void resize( const QString& noteId, int width, int height ) const; + + void sync( const QString& app ); + bool isNew( const QString& app, const QString& id ) const; + bool isModified( const QString& app, const QString& id ) const; + + bool commitData( QSessionManager& ); + +public slots: + QString newNote( const QString& name = QString::null, + const QString& text = QString::null ); + QString newNoteFromClipboard( const QString& name = QString::null ); + + void hideAllNotes() const; + void showAllNotes() const; + +protected: + void mousePressEvent( QMouseEvent* ); + +protected slots: + void slotShowNote(); + void slotWalkThroughNotes(); + + void slotOpenFindDialog(); + void slotFindNext(); + + void slotPreferences(); + void slotConfigureAccels(); + + void slotNoteKilled( KCal::Journal *journal ); + + void slotQuit(); + +private: + void showNote( KNote *note ) const; + void saveConfigs(); + +private slots: + void acceptConnection(); + void saveNotes(); + void updateNoteActions(); + void updateGlobalAccels(); + void updateNetworkListener(); + void updateStyle(); + + void createNote( KCal::Journal *journal ); + void killNote( KCal::Journal *journal ); + +private: + class KNoteActionList : public QPtrList + { + public: + virtual int compareItems( QPtrCollection::Item s1, QPtrCollection::Item s2 ); + }; + + KNotesResourceManager *m_manager; + + KNotesAlarm *m_alarm; + KNetwork::KServerSocket *m_listener; + + QDict m_noteList; + KNoteActionList m_noteActions; + + KFind *m_find; + QDictIterator *m_findPos; + + KPopupMenu *m_note_menu; + KPopupMenu *m_context_menu; + + KGlobalAccel *m_globalAccel; + KXMLGUIFactory *m_guiFactory; + KXMLGUIBuilder *m_guiBuilder; + + QDomDocument m_noteGUI; +}; + +#endif diff --git a/knotes/knotesappui.rc b/knotes/knotesappui.rc new file mode 100644 index 000000000..d5d682733 --- /dev/null +++ b/knotes/knotesappui.rc @@ -0,0 +1,35 @@ + + + + +KNotes + KNotes + + + + + + + + + + + + &Help + + + + + + + + + + + +Notes + Notes + + + + diff --git a/knotes/knotesglobalconfig.kcfg b/knotes/knotesglobalconfig.kcfg new file mode 100644 index 000000000..e6a16b373 --- /dev/null +++ b/knotes/knotesglobalconfig.kcfg @@ -0,0 +1,44 @@ + + + + + kmail --subject %t --body %f + + + + + + 60 + + + + + + + + false + + + + + 24837 + + + + + + + + + + Fancy + + + + + + + diff --git a/knotes/knotesglobalconfig.kcfgc b/knotes/knotesglobalconfig.kcfgc new file mode 100644 index 000000000..53d403698 --- /dev/null +++ b/knotes/knotesglobalconfig.kcfgc @@ -0,0 +1,6 @@ +File=knotesglobalconfig.kcfg +ClassName=KNotesGlobalConfig +Mutators=true +Singleton=true +IncludeFiles=knoteconfig.h +Inherits=KNoteConfig diff --git a/knotes/knoteslegacy.cpp b/knotes/knoteslegacy.cpp new file mode 100644 index 000000000..1d239d2d6 --- /dev/null +++ b/knotes/knoteslegacy.cpp @@ -0,0 +1,270 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2002-2004, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "knoteslegacy.h" +#include "knoteconfig.h" +#include "version.h" + +#include "libkcal/calendarlocal.h" +#include "libkcal/journal.h" + +#include + +using namespace KCal; + + +void KNotesLegacy::cleanUp() +{ + // remove old (KDE 1.x) local config file if it still exists + QString configfile = KGlobal::dirs()->saveLocation( "config" ) + "knotesrc"; + if ( QFile::exists( configfile ) ) { + KSimpleConfig *test = new KSimpleConfig( configfile ); + test->setGroup( "General" ); + double version = test->readDoubleNumEntry( "version", 1.0 ); + delete test; + + if ( version == 1.0 ) { + if ( !( checkAccess( configfile, W_OK ) && + QFile::remove( configfile ) ) ) + { + kdError(5500) << k_funcinfo << "Could not delete old config file " << configfile << endl; + } + } + } +} + +bool KNotesLegacy::convert( CalendarLocal *calendar ) +{ + bool converted = false; + + QDir noteDir( KGlobal::dirs()->saveLocation( "appdata", "notes/" ) ); + QStringList notes = noteDir.entryList( QDir::Files, QDir::Name ); + for ( QStringList::Iterator note = notes.begin(); note != notes.end(); note++ ) + { + QString file = noteDir.absFilePath( *note ); + KSimpleConfig* test = new KSimpleConfig( file ); + test->setGroup( "General" ); + double version = test->readDoubleNumEntry( "version", 1.0 ); + + if ( version < 3.0 ) + { + delete test; + + // create the new note + Journal *journal = new Journal(); + bool success; + + if ( version < 2.0 ) + success = convertKNotes1Config( journal, noteDir, *note ); + else + success = convertKNotes2Config( journal, noteDir, *note ); + + // could not convert file => do not add a new note + if ( !success ) + delete journal; + else + { + calendar->addJournal( journal ); + converted = true; + } + } + // window state changed for version 3.2 + else if ( version < 3.2 ) + { + uint state = test->readUnsignedLongNumEntry( "state", NET::SkipTaskbar ); + test->writeEntry( "ShowInTaskbar", (state & NET::SkipTaskbar) ? false : true ); + test->writeEntry( "KeepAbove", (state & NET::KeepAbove) ? true : false ); + test->deleteEntry( "state" ); + delete test; + } + } + + return converted; +} + +bool KNotesLegacy::convertKNotes1Config( Journal *journal, QDir& noteDir, + const QString& file ) +{ + QFile infile( noteDir.absFilePath( file ) ); + if ( !infile.open( IO_ReadOnly ) ) + { + kdError(5500) << k_funcinfo << "Could not open input file: \"" + << infile.name() << "\"" << endl; + return false; + } + + QTextStream input( &infile ); + + // get the name + journal->setSummary( input.readLine() ); + + QStringList props = QStringList::split( '+', input.readLine() ); + + // robustness + if ( props.count() != 13 ) + { + kdWarning(5500) << k_funcinfo << "The file \"" << infile.name() + << "\" lacks version information but is not a valid " + << "KNotes 1 config file either!" << endl; + return false; + } + + // the new configfile's name + QString configFile = noteDir.absFilePath( journal->uid() ); + + // set the defaults + KIO::NetAccess::copy( + KURL( KGlobal::dirs()->saveLocation( "config" ) + "knotesrc" ), + KURL( configFile ), + 0 + ); + + KNoteConfig config( KSharedConfig::openConfig( configFile, false, false ) ); + config.readConfig(); + config.setVersion( KNOTES_VERSION ); + + // get the geometry + config.setWidth( props[3].toUInt() ); + config.setHeight( props[4].toUInt() ); + + // get the background color + uint red = input.readLine().toUInt(); + uint green = input.readLine().toUInt(); + uint blue = input.readLine().toUInt(); + config.setBgColor( QColor( red, green, blue ) ); + + // get the foreground color + red = input.readLine().toUInt(); + green = input.readLine().toUInt(); + blue = input.readLine().toUInt(); + config.setFgColor( QColor( red, green, blue ) ); + + // get the font + QString fontfamily = input.readLine(); + if ( fontfamily.isEmpty() ) + fontfamily = QString( "Sans Serif" ); + uint size = input.readLine().toUInt(); + size = QMAX( size, 4 ); + uint weight = input.readLine().toUInt(); + bool italic = ( input.readLine().toUInt() == 1 ); + QFont font( fontfamily, size, weight, italic ); + + config.setTitleFont( font ); + config.setFont( font ); + + // 3d frame? Not supported yet! + input.readLine(); + + // autoindent + config.setAutoIndent( input.readLine().toUInt() == 1 ); + + // KNotes 1 never had rich text + config.setRichText( false ); + + int note_desktop = props[0].toUInt(); + + // hidden or on all desktops? + if ( input.readLine().toUInt() == 1 ) + note_desktop = 0; + else if ( props[11].toUInt() == 1 ) + note_desktop = NETWinInfo::OnAllDesktops; + + config.setDesktop( note_desktop ); + config.setPosition( QPoint( props[1].toUInt(), props[2].toUInt() ) ); + config.setKeepAbove( props[12].toUInt() & 2048 ); + + config.writeConfig(); + + // get the text + QString text; + while ( !input.atEnd() ) + { + text.append( input.readLine() ); + if ( !input.atEnd() ) + text.append( '\n' ); + } + + journal->setDescription( text ); + + if ( !infile.remove() ) + kdWarning(5500) << k_funcinfo << "Could not delete input file: \"" << infile.name() << "\"" << endl; + + return true; +} + +bool KNotesLegacy::convertKNotes2Config( Journal *journal, QDir& noteDir, + const QString& file ) +{ + QString configFile = noteDir.absFilePath( journal->uid() ); + + // new name for config file + if ( !noteDir.rename( file, journal->uid() ) ) + { + kdError(5500) << k_funcinfo << "Could not rename input file: \"" + << noteDir.absFilePath( file ) << "\" to \"" + << configFile << "\"!" << endl; + return false; + } + + // update the config + KConfig config( configFile ); + config.setGroup( "Data" ); + journal->setSummary( config.readEntry( "name" ) ); + config.deleteGroup( "Data", true ); + config.setGroup( "General" ); + config.writeEntry( "version", KNOTES_VERSION ); + config.setGroup( "WindowDisplay" ); + uint state = config.readUnsignedLongNumEntry( "state", NET::SkipTaskbar ); + config.writeEntry( "ShowInTaskbar", (state & NET::SkipTaskbar) ? false : true ); + config.writeEntry( "KeepAbove", (state & NET::KeepAbove) ? true : false ); + config.deleteEntry( "state" ); + + // load the saved text and put it in the journal + QFile infile( noteDir.absFilePath( "." + file + "_data" ) ); + if ( infile.open( IO_ReadOnly ) ) + { + QTextStream input( &infile ); + input.setEncoding( QTextStream::UnicodeUTF8 ); + journal->setDescription( input.read() ); + if ( !infile.remove() ) + kdWarning(5500) << k_funcinfo << "Could not delete data file: \"" << infile.name() << "\"" << endl; + } + else + kdWarning(5500) << k_funcinfo << "Could not open data file: \"" << infile.name() << "\"" << endl; + + return true; +} diff --git a/knotes/knoteslegacy.h b/knotes/knoteslegacy.h new file mode 100644 index 000000000..84ee0fc80 --- /dev/null +++ b/knotes/knoteslegacy.h @@ -0,0 +1,46 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2002-2004, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#ifndef KNOTESLEGACY_H +#define KNOTESLEGACY_H + +#include +#include + +namespace KCal { + class CalendarLocal; + class Journal; +} + + +/** + * This converts and removes old note storage and config files. + */ +class KNotesLegacy +{ +public: + static void cleanUp(); + static bool convert( KCal::CalendarLocal *calendar ); +private: + static bool convertKNotes1Config( KCal::Journal *j, QDir& dir, const QString& file ); + static bool convertKNotes2Config( KCal::Journal *j, QDir& dir, const QString& file ); +}; + +#endif diff --git a/knotes/knotesnetrecv.cpp b/knotes/knotesnetrecv.cpp new file mode 100644 index 000000000..65edb2cb5 --- /dev/null +++ b/knotes/knotesnetrecv.cpp @@ -0,0 +1,152 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2003, Daniel Martin + 2004, 2006, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "knotesnetrecv.h" + +// Maximum note size in chars we are going to accept, +// to prevent "note floods". +#define MAXBUFFER 4096 + +// Maximum time we are going to wait between data receptions, +// to prevent memory and connection floods. In milliseconds. +#define MAXTIME 10000 + +// Small buffer's size +#define SBSIZE 512 + +using namespace KNetwork; + + +KNotesNetworkReceiver::KNotesNetworkReceiver( KBufferedSocket *s ) + : QObject(), + m_buffer( new QByteArray() ), m_sock( s ) +{ + QString date = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime(), true, false ); + + // Add the remote IP or hostname and the date to the title, to help the + // user guess who wrote it. + m_titleAddon = QString(" [%1, %2]") + .arg( m_sock->peerAddress().nodeName() ) + .arg( date ); + + // Setup the communications + connect( m_sock, SIGNAL(readyRead()), SLOT(slotDataAvailable()) ); + connect( m_sock, SIGNAL(closed()), SLOT(slotConnectionClosed()) ); + connect( m_sock, SIGNAL(gotError( int )), SLOT(slotError( int )) ); + + m_sock->enableRead( true ); + + // Setup the timer + m_timer = new QTimer( this, "m_timer" ); + connect( m_timer, SIGNAL(timeout()), SLOT(slotReceptionTimeout()) ); + m_timer->start( MAXTIME, true ); +} + +KNotesNetworkReceiver::~KNotesNetworkReceiver() +{ + delete m_buffer; + delete m_sock; +} + +void KNotesNetworkReceiver::slotDataAvailable() +{ + char smallBuffer[SBSIZE]; + int smallBufferLen; + + do + { + // Append to "big buffer" only if we have some space left. + int curLen = m_buffer->count(); + + smallBufferLen = m_sock->readBlock( smallBuffer, SBSIZE ); + + // Limit max transfer over buffer, to avoid overflow. + smallBufferLen = kMin( smallBufferLen, MAXBUFFER - curLen ); + + if ( smallBufferLen > 0 ) + { + m_buffer->resize( curLen + smallBufferLen ); + memcpy( m_buffer->data() + curLen, smallBuffer, smallBufferLen ); + } + } + while ( smallBufferLen == SBSIZE ); + + // If we are overflowing, close connection. + if ( m_buffer->count() == MAXBUFFER ) + m_sock->close(); + else + m_timer->changeInterval( MAXTIME ); +} + +void KNotesNetworkReceiver::slotReceptionTimeout() +{ + m_sock->close(); +} + +void KNotesNetworkReceiver::slotConnectionClosed() +{ + if ( m_timer->isActive() ) + { + QString noteText = QString( *m_buffer ).stripWhiteSpace(); + + // First line is the note title or, in case of ATnotes, the id + int pos = noteText.find( QRegExp("[\r\n]") ); + QString noteTitle = noteText.left( pos ).stripWhiteSpace() + m_titleAddon; + + noteText = noteText.mid( pos ).stripWhiteSpace(); + + if ( !noteText.isEmpty() ) + emit sigNoteReceived( noteTitle, noteText ); + } + + deleteLater(); +} + +void KNotesNetworkReceiver::slotError( int err ) +{ + kdWarning() << k_funcinfo + << m_sock->errorString( static_cast(err) ) + << endl; +} + +#include "knotesnetrecv.moc" diff --git a/knotes/knotesnetrecv.h b/knotes/knotesnetrecv.h new file mode 100644 index 000000000..105aa6461 --- /dev/null +++ b/knotes/knotesnetrecv.h @@ -0,0 +1,69 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2003, Daniel Martin + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef KNOTESNETRECV_H +#define KNOTESNETRECV_H + +#include + +class QTimer; + +namespace KNetwork { + class KBufferedSocket; +} + + +class KNotesNetworkReceiver : public QObject +{ + Q_OBJECT +public: + KNotesNetworkReceiver( KNetwork::KBufferedSocket * ); + ~KNotesNetworkReceiver(); + +signals: + void sigNoteReceived( const QString &, const QString & ); + +private slots: + void slotDataAvailable(); + void slotReceptionTimeout(); + void slotConnectionClosed(); + void slotError( int err ); + +private: + QTimer *m_timer; // to avoid memory and connection floods + + QByteArray *m_buffer; + KNetwork::KBufferedSocket *m_sock; + + QString m_titleAddon; +}; + +#endif diff --git a/knotes/knotesnetsend.cpp b/knotes/knotesnetsend.cpp new file mode 100644 index 000000000..7cf7567e4 --- /dev/null +++ b/knotes/knotesnetsend.cpp @@ -0,0 +1,104 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2003, Daniel Martin + 2004, 2006, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include +#include + +#include "knotesnetsend.h" + +#define CONNECT_TIMEOUT 10000 + + +KNotesNetworkSender::KNotesNetworkSender( const QString& hostname, int port ) + : KBufferedSocket( hostname, QString::number( port ) ), + m_note( 0 ), m_title( 0 ), m_sender( 0 ), m_index( 0 ) +{ + enableRead( false ); + enableWrite( false ); + setTimeout( CONNECT_TIMEOUT ); + + // QObject:: prefix needed, otherwise the KStreamSocket::connect() + // mehtod is called!!! + QObject::connect( this, SIGNAL(connected( const KResolverEntry& )), + SLOT(slotConnected( const KResolverEntry& )) ); + QObject::connect( this, SIGNAL(gotError( int )), SLOT(slotError( int )) ); + QObject::connect( this, SIGNAL(closed()), SLOT(slotClosed()) ); + QObject::connect( this, SIGNAL(readyWrite()), SLOT(slotReadyWrite()) ); +} + +void KNotesNetworkSender::setSenderId( const QString& sender ) +{ + m_sender = sender.ascii(); +} + +void KNotesNetworkSender::setNote( const QString& title, const QString& text ) +{ + // TODO: support for unicode and rich text. + // Mmmmmm... how to behave with such heterogeneous environment? + // AFAIK, ATnotes does not allow UNICODE. + m_title = title.ascii(); + m_note = text.ascii(); +} + +void KNotesNetworkSender::slotConnected( const KResolverEntry& ) +{ + if ( m_sender.isEmpty() ) + m_note.prepend( m_title + "\n"); + else + m_note.prepend( m_title + " (" + m_sender + ")\n" ); + + enableWrite( true ); +} + +void KNotesNetworkSender::slotReadyWrite() +{ + m_index += writeBlock( m_note.data() + m_index, m_note.length() - m_index ); + + // If end of text reached, close connection + if ( m_index == m_note.length() ) + close(); +} + +void KNotesNetworkSender::slotError( int err ) +{ + KMessageBox::sorry( 0, i18n("Communication error: %1") + .arg( errorString( static_cast(err) ) ) + ); + slotClosed(); +} + +void KNotesNetworkSender::slotClosed() +{ + deleteLater(); +} + +#include "knotesnetsend.moc" diff --git a/knotes/knotesnetsend.h b/knotes/knotesnetsend.h new file mode 100644 index 000000000..1c3e42b29 --- /dev/null +++ b/knotes/knotesnetsend.h @@ -0,0 +1,66 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 2003, Daniel Martin + 2004, 2006, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef KNOTESNETSEND_H +#define KNOTESNETSEND_H + +#include + +#include +#include + +using namespace KNetwork; + +class KNotesNetworkSender : public KNetwork::KBufferedSocket +{ + Q_OBJECT +public: + KNotesNetworkSender( const QString& host, int port ); + + void setSenderId( const QString& sender ); + void setNote( const QString& title, const QString& text ); + +protected slots: + void slotConnected( const KResolverEntry& ); + void slotError( int ); + void slotClosed(); + + void slotReadyWrite(); + +private: + QCString m_note; + QCString m_title; + QCString m_sender; + uint m_index; +}; + +#endif diff --git a/knotes/knotesui.rc b/knotes/knotesui.rc new file mode 100644 index 000000000..17e66d43d --- /dev/null +++ b/knotes/knotesui.rc @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/knotes/local.desktop b/knotes/local.desktop new file mode 100644 index 000000000..514145a81 --- /dev/null +++ b/knotes/local.desktop @@ -0,0 +1,59 @@ +[Desktop Entry] +Name=Notes in Local File +Name[af]=Notas in plaaslike lêer +Name[ar]=الملاحظات في الملف المحلّي +Name[be]=Нататкі ў лякальным файле +Name[bg]=Бележки в локален файл +Name[br]=Notennoù e rstr lec'hel +Name[bs]=Bilješke u lokalnoj datoteci +Name[ca]=Notes en fitxer local +Name[cs]=Poznámky v lokálním souboru +Name[da]=Noter i lokal fil +Name[de]=Notizen in lokaler Datei +Name[el]=Σημειώσεις σε τοπικό αρχείο +Name[eo]=Notoj en loka dosiero +Name[es]=Avisos sobre el archivo local +Name[et]=Märkmed kohalikus failis +Name[eu]=Oharrak fitxategi lokalean +Name[fa]=یادداشتها در پروندۀ محلی +Name[fi]=Muistiot paikallisessa tiedostossa +Name[fr]=Notes dans un fichier local +Name[fy]=Notysjes yn lokale triem +Name[ga]=Nótaí i gComhad Logánta +Name[gl]=Notas en Ficheiro Local +Name[he]=פתקים בקובץ מקומי +Name[hu]=Helyi fájlban tárolt feljegyzések +Name[is]=Minnismiðar í staðbundinni skrá +Name[it]=Note in file locale +Name[ja]=ローカルファイルのメモ +Name[ka]=ჩანიშვნები ლოკალურ ფაილში +Name[kk]=Жергілікті файлдағы жазбалар +Name[km]=ចំណាំ​ក្នុង​ឯកសារ​មូលដ្ឋាន +Name[lt]=Užrašai vietinėje byloje +Name[mk]=Белешки во локална датотека +Name[ms]=Nota dalam fail setempat +Name[nb]=Notater i lokal fil +Name[nds]=Notizen in lokaal Datei +Name[ne]=स्थानीय फाइलका टिपोट +Name[nl]=Notities in lokaal bestand +Name[nn]=Notat i lokal fil +Name[pl]=Notatki w pliku lokalnym +Name[pt]=Notas num Ficheiro Local +Name[pt_BR]=Notas em Arquivo Local +Name[ru]=Заметки в локальном файле +Name[sk]=Poznámky v lokálnom súbore +Name[sl]=Notice v krajevni datoteki +Name[sr]=Забелешке у локалном фајлу +Name[sr@Latn]=Zabeleške u lokalnom fajlu +Name[sv]=Anteckningar i lokal fil +Name[ta]=உள் கோப்பில் உள்ள குறிப்புகள் +Name[tg]=Хабарҳо дар файли локалӣ +Name[tr]=Yerel Dosyadaki Notlar +Name[uk]=Нотатки у локальному файлі +Name[zh_CN]=本地文件中的便笺 +Name[zh_TW]=本地檔備忘錄 +X-KDE-Library=knotes_local +Type=Service +ServiceTypes=KResources/Plugin +X-KDE-ResourceFamily=notes +X-KDE-ResourceType=file diff --git a/knotes/main.cpp b/knotes/main.cpp new file mode 100644 index 000000000..682bbb792 --- /dev/null +++ b/knotes/main.cpp @@ -0,0 +1,132 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2006, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#include +#include +#include +#include +#include + +#include +#include + +#include "knotesapp.h" +#include "version.h" +#include "main.h" + + +void remove_sm_from_client_leader() +{ + Atom type; + int format, status; + unsigned long nitems = 0; + unsigned long extra = 0; + unsigned char *data = 0; + + Atom atoms[ 2 ]; + char *atom_names[ 2 ] = { (char*)"WM_CLIENT_LEADER", (char*)"SM_CLIENT_ID" }; + + XInternAtoms( qt_xdisplay(), atom_names, 2, False, atoms ); + + QWidget w; + KXErrorHandler handler; // ignore X errors + status = XGetWindowProperty( qt_xdisplay(), w.winId(), atoms[ 0 ], 0, 10000, + FALSE, XA_WINDOW, &type, &format, + &nitems, &extra, &data ); + + if (status == Success && !handler.error( false )) + { + if (data && nitems > 0) + { + Window leader = *((Window*) data); + XDeleteProperty( qt_xdisplay(), leader, atoms[ 1 ] ); + } + XFree(data); + } +} + + +Application::Application() + : KUniqueApplication(), mMainWindow( 0 ) +{ +} + +Application::~Application() +{ + delete mMainWindow; +} + +int Application::newInstance() +{ + if ( !mMainWindow ) + { + mMainWindow = new KNotesApp(); + mMainWindow->show(); + } + else + mMainWindow->newNote(); + + return KUniqueApplication::newInstance(); +} + +int main( int argc, char* argv[] ) +{ + QString version = QString::number( KNOTES_VERSION ); + + KAboutData aboutData( + "knotes", + I18N_NOOP("KNotes"), + version.latin1(), + I18N_NOOP( "KDE Notes" ), + KAboutData::License_GPL, + I18N_NOOP("(c) 1997-2006, The KNotes Developers") + ); + + aboutData.addAuthor("Michael Brade", I18N_NOOP("Maintainer"), "brade@kde.org"); + aboutData.addAuthor("Bernd Johannes Wuebben", I18N_NOOP("Original KNotes Author"), "wuebben@kde.org"); + aboutData.addAuthor("Wynn Wilkes", I18N_NOOP("Ported KNotes to KDE 2"), "wynnw@calderasystems.com"); + aboutData.addAuthor("Daniel Martin", I18N_NOOP("Network Interface"), "daniel.martin@pirack.com"); + aboutData.addAuthor("Bo Thorsen", I18N_NOOP("Started KDE Resource Framework Integration"), "bo@sonofthor.dk"); + + aboutData.addCredit("Bera Debajyoti", I18N_NOOP("Idea and initial code for the new look&feel"), + "debajyotibera@gmail.com"); + aboutData.addCredit("Matthias Ettrich", 0, "ettrich@kde.org"); + aboutData.addCredit("David Faure", 0, "faure@kde.org"); + aboutData.addCredit("Matthias Kiefer", 0, "kiefer@kde.org"); + aboutData.addCredit("Luboš Luňák", 0, "l.lunak@kde.org"); + aboutData.addCredit("Laurent Montel", 0, "montel@kde.org"); + aboutData.addCredit("Dirk A. Mueller", 0, "dmuell@gmx.net"); + aboutData.addCredit("Carsten Pfeiffer", 0, "pfeiffer@kde.org"); + aboutData.addCredit("Harri Porten", 0, "porten@kde.org"); + aboutData.addCredit("Espen Sand", 0, "espen@kde.org"); + + KCmdLineArgs::init( argc, argv, &aboutData ); + + KUniqueApplication::addCmdLineOptions(); + + Application app; + app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); + + remove_sm_from_client_leader(); + + int rval = app.exec(); + + return rval; +} diff --git a/knotes/main.h b/knotes/main.h new file mode 100644 index 000000000..7e7af1052 --- /dev/null +++ b/knotes/main.h @@ -0,0 +1,41 @@ +/******************************************************************* + KNotes -- Notes for the KDE project + + Copyright (c) 1997-2005, The KNotes Developers + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*******************************************************************/ + +#ifndef MAIN_H +#define MAIN_H + +#include + +class KNotesApp; + + +class Application : public KUniqueApplication +{ +public: + Application(); + ~Application(); + + virtual int newInstance(); + +private: + KNotesApp *mMainWindow; +}; + +#endif diff --git a/knotes/mig_knotes.pl b/knotes/mig_knotes.pl new file mode 100644 index 000000000..3cce6f9dc --- /dev/null +++ b/knotes/mig_knotes.pl @@ -0,0 +1,127 @@ +#! /usr/bin/perl + +# mig_knotes.pl +# Dieses Programm erzeugt aus einem notes.ics- file (KDE >3) +# pro Note eine Datei (KDE <3). +# +# Der ics- File beinhaltet die Abschnitte "Description" (=Notizen) +# und "Summary" (=Titel der Note) +# +# Es wird pro Note ein file .KNotes *n*_data (Notizen) sowie +# KNote*n* (Steuerdatei) erzeugt. +# +# Das Programm ist "auf die Schnelle" geschrieben. +# Es ist nicht empfehlenswert -w oder :use_strict einzuschalten. +# +# Wer es benutzt und Verbesserungen vornimmt, kann mir freundlicherweise +# eine Kopie schicken. +# +# chaeffne@web.de, Mai 2005 +# +# +# +# Folgende Pfade muessen individuell gesetzt werden: + +$imp = "/pfad/zum/importfile/notes.ics"; # Importfile +$verz = "/pfad/zum/export-verzeichnis/tmp"; # Exportverzeichnis +$steuerdatei = "/pfad/zu/einer/steuerdatei/KNote"; # KNotes- Steuerdatei KDE <3; + # wird als Vorlage fuer + # die neuen verwendet. +#################################### +# Beginn des Programms ############# +#################################### +# +# 1. Abschnitt +# In diesem Abschnitt werden die "Descriptions" in notes.ics gezaehlt (=Dateianzahl), +# die Anfangs- und Endzeile der Description bestimmt, sowie der Titel der +# Notes (=Summary) extrahiert. +open (IMP,"$imp"); +$zz = 1; #Zeilenzaehler +$fc = 1; #Filecounter +while ($_ = ){ + +$all{$zz} = $_; # alle Zeilen in ein assoziatives Array schreiben + + if ($_ =~ /^DESCRIPTION/){ # Nach "Description" am Anfang suchen + $anfang{$fc} = $zz; # Anfang: Ein Wertepaearchen aus filecounter und Zeilenzaehler erzeugen + } + elsif ($_ =~ /^SUMMARY/){ # Nach Summary am Anfang suchen + $ende{$fc} = $zz-1; # Ende: Ein Wertepaearchen aus filecounter und Zeilenzaehler erzeugen + $ttt = $_; # Titel + $ttt =~ s/SUMMARY://; + $title{$fc} = $ttt; # Den aktuellen Titel mit dem filecounter assozieren + $fc++; + } +$zz++; +} # Ende 1. Abschnitt +close(IMP); + +# 2. Abschnitt +# +# In diesem Abschnitt werden die Files erzeugt und die oben gewonnenen Daten verarbeitet. +$fc2 = 1; # filecounter2 +while ($fc2 <= $fc) { + + # Datendatei (= Notiz) + $filename = "$verz/.KNote ".$fc2."_data"; + open(EXP,">$filename"); + + $zz = 0; + $anzahl = $ende{$fc2}-$anfang{$fc2}; # Anzahl der Zeilen + while ($zz <= $anzahl) { # fuer alle betroffenen Zeilen durchlaufen + $line = $all{$anfang{$fc2}+$zz}; # die aktuelle Zeile + $line =~ chop($line); # letztes Zeichen (=new line) abschneiden + $line =~ s/DESCRIPTION://; # das Wort rausschneiden + @line = split(/\\n/,$line); # die Zeile nach new lines teilen (=Steuerzeichen im ics-file) + $anz = @line; # die Anzahl im array + + $zz2 = 1; + foreach $nl(@line) { # fuer jeden Wert im Array + $nl =~ s/\\t/ /g;# Tabs durch Leerzeichen ersetzen + $nl =~ s/\\//g;# \ (als Escape verwendet zB. vor ",;") entfernen + # eine neue Zeile? + if ( $zz2 < $anz or $anz == 1 ) { + print EXP "$nl
"; + } + else { + print EXP $nl; + } + $zz2++; + } + + $zz++; + } + + # Steuerdatei + $filename2 = "$verz/KNote ".$fc2; + open (IMP2,"$steuerdatei"); + # eine Beispieldatei, die fuer alle Notes verwendet wird. + open(EXP2,">$filename2"); + while ($_ = ) { + if ($_ =~ /^name/) { + print EXP2 "name=$title{$fc2}\n"; + } + else{ + print EXP2 $_; + } + } +$fc2++; +} # Ende 2. Abschnitt +close(EXP); +close(EXP2); +close(IMP2); +# Ende mig_knotes.pl + + + + + + + + + + + + + + diff --git a/knotes/pics/Makefile.am b/knotes/pics/Makefile.am new file mode 100644 index 000000000..e5515a859 --- /dev/null +++ b/knotes/pics/Makefile.am @@ -0,0 +1 @@ +KDE_ICON = AUTO diff --git a/knotes/pics/hi128-app-knotes.png b/knotes/pics/hi128-app-knotes.png new file mode 100644 index 000000000..c02b59b67 Binary files /dev/null and b/knotes/pics/hi128-app-knotes.png differ diff --git a/knotes/pics/hi16-app-knotes.png b/knotes/pics/hi16-app-knotes.png new file mode 100644 index 000000000..fd7ad3aa4 Binary files /dev/null and b/knotes/pics/hi16-app-knotes.png differ diff --git a/knotes/pics/hi22-app-knotes.png b/knotes/pics/hi22-app-knotes.png new file mode 100644 index 000000000..8ad581746 Binary files /dev/null and b/knotes/pics/hi22-app-knotes.png differ diff --git a/knotes/pics/hi32-app-knotes.png b/knotes/pics/hi32-app-knotes.png new file mode 100644 index 000000000..73b1da53a Binary files /dev/null and b/knotes/pics/hi32-app-knotes.png differ diff --git a/knotes/pics/hi48-app-knotes.png b/knotes/pics/hi48-app-knotes.png new file mode 100644 index 000000000..a83298814 Binary files /dev/null and b/knotes/pics/hi48-app-knotes.png differ diff --git a/knotes/pics/hi64-app-knotes.png b/knotes/pics/hi64-app-knotes.png new file mode 100644 index 000000000..80cbca213 Binary files /dev/null and b/knotes/pics/hi64-app-knotes.png differ diff --git a/knotes/pushpin.xpm b/knotes/pushpin.xpm new file mode 100644 index 000000000..4aef6adf9 --- /dev/null +++ b/knotes/pushpin.xpm @@ -0,0 +1,396 @@ +/* Pushpin XPM (courtsey google image search) [copyright :O ???] */ + +static char *pushpin_xpm[] = { +"27 29 363 2", +" c None", +". c #F60404", +"+ c #F21A1C", +"@ c #F3080A", +"# c #E90F11", +"$ c #EB1E26", +"% c #F9060B", +"& c #FB0604", +"* c #FB0503", +"= c #DA090B", +"- c #AA1615", +"; c #F2171D", +"> c #F70504", +", c #FD0D07", +"' c #EE0402", +") c #E60405", +"! c #980505", +"~ c #985150", +"{ c #F21622", +"] c #FB0200", +"^ c #FD0302", +"/ c #E60908", +"( c #9F0803", +"_ c #750201", +": c #7D2727", +"< c #F1211F", +"[ c #F40301", +"} c #FC0302", +"| c #F70202", +"1 c #DB0608", +"2 c #900101", +"3 c #6B0401", +"4 c #850301", +"5 c #9A0A0C", +"6 c #A73138", +"7 c #E30607", +"8 c #F40900", +"9 c #AB0203", +"0 c #700903", +"a c #610501", +"b c #870206", +"c c #A90203", +"d c #C20306", +"e c #B00303", +"f c #A7413A", +"g c #490605", +"h c #440503", +"i c #7C0401", +"j c #AF0403", +"k c #C80006", +"l c #C60502", +"m c #C00900", +"n c #A20C09", +"o c #AC5051", +"p c #A2090A", +"q c #30080C", +"r c #6A0109", +"s c #A40404", +"t c #A90600", +"u c #C30105", +"v c #BB0602", +"w c #BB0701", +"x c #BF0101", +"y c #A5151A", +"z c #C07B79", +"A c #5B312F", +"B c #4D0402", +"C c #840705", +"D c #AA0105", +"E c #B30003", +"F c #BF0405", +"G c #C70102", +"H c #CD0409", +"I c #AD0507", +"J c #A31A18", +"K c #E16367", +"L c #6D6564", +"M c #311A16", +"N c #580904", +"O c #8C0504", +"P c #A30705", +"Q c #B70102", +"R c #C80002", +"S c #C70205", +"T c #B60101", +"U c #B20104", +"V c #A0333A", +"W c #787979", +"X c #6B6A6B", +"Y c #514745", +"Z c #3D0909", +"` c #680304", +" . c #900302", +".. c #AB0000", +"+. c #C20001", +"@. c #C90304", +"#. c #C10303", +"$. c #BC0001", +"%. c #B00908", +"&. c #AB4A45", +"*. c #666565", +"=. c #6A696C", +"-. c #676868", +";. c #4E3736", +">. c #450E0F", +",. c #700201", +"'. c #9C0203", +"). c #B50002", +"!. c #C10101", +"~. c #C70303", +"{. c #C90102", +"]. c #C30000", +"^. c #9D0E0C", +"/. c #B33B3A", +"(. c #EF6B74", +"_. c #FB7A87", +":. c #F4CBC4", +"<. c #686A69", +"[. c #6C686C", +"}. c #686369", +"|. c #616668", +"1. c #666768", +"2. c #443437", +"3. c #450607", +"4. c #720102", +"5. c #9A0104", +"6. c #B00101", +"7. c #BF0100", +"8. c #CA0101", +"9. c #C10406", +"0. c #B7050B", +"a. c #BF0208", +"b. c #E70404", +"c. c #FC070B", +"d. c #FC0C16", +"e. c #EB3432", +"f. c #E85456", +"g. c #DC9395", +"h. c #EAF5FB", +"i. c #66696B", +"j. c #68656A", +"k. c #6F666C", +"l. c #656567", +"m. c #636A69", +"n. c #605E60", +"o. c #3E2625", +"p. c #4C0607", +"q. c #770103", +"r. c #9E0504", +"s. c #AF0100", +"t. c #BE0000", +"u. c #C00506", +"v. c #C10106", +"w. c #D50105", +"x. c #F70801", +"y. c #FE0900", +"z. c #F90300", +"A. c #FA0404", +"B. c #ED0608", +"C. c #BF2D2C", +"D. c #D18A84", +"E. c #63686B", +"F. c #656268", +"G. c #70656A", +"H. c #686465", +"I. c #606562", +"J. c #656664", +"K. c #555654", +"L. c #421C1B", +"M. c #580101", +"N. c #860302", +"O. c #A10200", +"P. c #B80303", +"Q. c #C50404", +"R. c #D60205", +"S. c #EC0105", +"T. c #FD0401", +"U. c #FE0502", +"V. c #F90206", +"W. c #F30505", +"X. c #FB0303", +"Y. c #E60605", +"Z. c #CC4E45", +"`. c #666666", +" + c #676767", +".+ c #69696C", +"++ c #51534E", +"@+ c #461A16", +"#+ c #5E0201", +"$+ c #820806", +"%+ c #B50309", +"&+ c #CD1E24", +"*+ c #EB3031", +"=+ c #FA1C1B", +"-+ c #FD0304", +";+ c #FF0404", +">+ c #FC0204", +",+ c #FC020C", +"'+ c #FC0700", +")+ c #C93433", +"!+ c #707070", +"~+ c #6E6E6E", +"{+ c #696969", +"]+ c #616768", +"^+ c #66625A", +"/+ c #742A28", +"(+ c #8B0303", +"_+ c #A30200", +":+ c #D30407", +"<+ c #F53738", +"[+ c #FF5554", +"}+ c #FE4445", +"|+ c #F41216", +"1+ c #FB0305", +"2+ c #FE0301", +"3+ c #F90205", +"4+ c #FA0600", +"5+ c #F40302", +"6+ c #D83F45", +"7+ c #6D6D6D", +"8+ c #656565", +"9+ c #6B6B6B", +"0+ c #696368", +"a+ c #775754", +"b+ c #A22025", +"c+ c #DD020A", +"d+ c #F20303", +"e+ c #FB0401", +"f+ c #F9201B", +"g+ c #FF4F4C", +"h+ c #FA5C5D", +"i+ c #EF3239", +"j+ c #F91314", +"k+ c #FE0802", +"l+ c #F80400", +"m+ c #FE0601", +"n+ c #E2090A", +"o+ c #D86B70", +"p+ c #61696B", +"q+ c #695A51", +"r+ c #9D211E", +"s+ c #EA0406", +"t+ c #FD0602", +"u+ c #FC0300", +"v+ c #FD0C08", +"w+ c #FE3B37", +"x+ c #FF5D5D", +"y+ c #FD464C", +"z+ c #FE1C1D", +"A+ c #FC0402", +"B+ c #F80901", +"C+ c #FB0202", +"D+ c #D02729", +"E+ c #E1B0AC", +"F+ c #7F7F7F", +"G+ c #746B74", +"H+ c #745854", +"I+ c #A11C1B", +"J+ c #EC0101", +"K+ c #FE0100", +"L+ c #FF0500", +"M+ c #F91C18", +"N+ c #FD3A37", +"O+ c #FF3437", +"P+ c #FF1518", +"Q+ c #FB0304", +"R+ c #F50305", +"S+ c #E80F12", +"T+ c #D66B69", +"U+ c #979BA1", +"V+ c #717067", +"W+ c #812921", +"X+ c #D00306", +"Y+ c #F20504", +"Z+ c #EB0200", +"`+ c #FD0404", +" @ c #FA0704", +".@ c #FB150F", +"+@ c #FE1412", +"@@ c #FA060A", +"#@ c #F50308", +"$@ c #E71318", +"%@ c #DE5A52", +"&@ c #F6D6C6", +"*@ c #7E7A75", +"=@ c #67312D", +"-@ c #9F0409", +";@ c #E00205", +">@ c #EC0501", +",@ c #F30406", +"'@ c #F90201", +")@ c #FD0601", +"!@ c #F60803", +"~@ c #E80203", +"{@ c #DC070D", +"]@ c #B43C3C", +"^@ c #EBB4AB", +"/@ c #73817A", +"(@ c #5C4841", +"_@ c #750B0D", +":@ c #AB0101", +"<@ c #C80301", +"[@ c #D30801", +"}@ c #E40300", +"|@ c #EF0001", +"1@ c #DB0709", +"2@ c #C12320", +"3@ c #AE443C", +"4@ c #714A40", +"5@ c #9C9B8E", +"6@ c #C9C3C9", +"7@ c #757D7B", +"8@ c #62655F", +"9@ c #613936", +"0@ c #731A19", +"a@ c #7F0D0B", +"b@ c #A30B0D", +"c@ c #A80C10", +"d@ c #A8181E", +"e@ c #A34447", +"f@ c #9B7974", +"g@ c #949F94", +"h@ c #82847F", +"i@ c #68706C", +"j@ c #B9BBBD", +"k@ c #D2BFC5", +"l@ c #7D7579", +"m@ c #656768", +"n@ c #64615D", +"o@ c #66524C", +"p@ c #66433C", +"q@ c #724141", +"r@ c #754F4D", +"s@ c #866F6E", +"t@ c #B1A8AA", +"u@ c #CECBD3", +"v@ c #D3D4DD", +"w@ c #C6C1C4", +"x@ c #AEA6AB", +"y@ c #A79BA1", +"z@ c #E2D6DC", +"A@ c #CCCDC7", +"B@ c #868281", +"C@ c #6A6769", +"D@ c #606764", +"E@ c #6A6B67", +"F@ c #6D7875", +"G@ c #919F9B", +"H@ c #B2C2C0", +"I@ c #D9E2E3", +"J@ c #E4E3E2", +"K@ c #CADDCF", +"L@ c #AEB0AD", +"M@ c #8F8C8D", +"N@ c #7C7D7F", +"O@ c #6D7171", +"P@ c #818282", +"Q@ c #B3B1B3", +"R@ c #D5CED2", +"S@ c #C7C7C7", +"T@ c #BBBBBB", +"U@ c #A7A7A7", +"V@ c #BEBEBE", +" . . . ", +" . . + @ # . ", +" . $ % & * = - ", +" . ; > , ' ) ! ~ ", +" . { . ] ^ / ( _ : ", +" . < [ } | 1 2 3 4 5 6 ", +" - 7 8 7 9 0 a b c d e f ", +" - 7 7 7 g h i j k l m n o ", +" 0 p 0 p q r s t u v w x y z ", +" A B C D E F G H I J K ", +" L M N O P Q R S T U V K ", +" W X Y Z ` ...+.@.#.$.%.&.K ", +" *.=.-.;.>.,.'.).!.~.{.].^./.K (._.:. ", +" <.[.}.|.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g. h.", +" i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.A.B.C.D. ", +" E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z. ", +" `. + +`.`. +.+++@+#+$+%+&+*+=+-+;+>+,+'+[ )+ ", +" !+~+{+ + +`.]+^+/+(+_+:+<+[+}+|+1+2+3+4+5+6+ ", +" 7+8+9+ +0+a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+ ", +" {+8+p+q+r+s+t+u+v+w+x+y+z+A+B+C+D+E+ ", +" F+G+H+I+J+K+L+} M+N+O+P+Q+R+S+T+ ", +" U+V+W+X+Y+Z+`+ @.@+@@@#@$@%@&@ ", +" *@=@-@;@>@,@'@)@!@~@{@]@^@ ", +" /@(@_@:@<@[@}@|@1@2@3@4@5@ ", +" 6@7@8@9@0@a@b@c@d@e@f@g@h@i@j@ ", +" k@l@m@n@o@p@q@r@s@t@u@v@w@x@y@z@ ", +" A@B@C@m.D@E@F@G@H@I@ J@ ", +" K@L@M@N@O@P@Q@R@ ", +" S@T@U@V@ "}; diff --git a/knotes/resourcelocal.cpp b/knotes/resourcelocal.cpp new file mode 100644 index 000000000..194afb6f0 --- /dev/null +++ b/knotes/resourcelocal.cpp @@ -0,0 +1,132 @@ +/******************************************************************* + This file is part of KNotes. + + Copyright (c) 2004, Bo Thorsen + 2004-2006, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include +#include +#include + +#include + +#include "knotes/resourcelocal.h" +#include "knotes/resourcelocalconfig.h" +#include "knotes/resourcemanager.h" +#include "knotes/resourcenotes.h" + + + +ResourceLocal::ResourceLocal( const KConfig *config ) + : ResourceNotes( config ), mCalendar( QString::fromLatin1( "UTC" ) ) +{ + kdDebug(5500) << "ResourceLocal::ResourceLocal()" << endl; + setType( "file" ); + mURL = KGlobal::dirs()->saveLocation( "data", "knotes/" ) + "notes.ics"; + + if ( config ) + { + KURL u = config->readPathEntry( "NotesURL" ); + if ( !u.isEmpty() ) + mURL = u; + } +} + +ResourceLocal::~ResourceLocal() +{ +} + +void ResourceLocal::writeConfig( KConfig *config ) +{ + KRES::Resource::writeConfig( config ); + config->writePathEntry( "NotesURL", mURL.prettyURL() ); +} + +bool ResourceLocal::load() +{ + mCalendar.load( mURL.path() ); + + KCal::Journal::List notes = mCalendar.journals(); + KCal::Journal::List::ConstIterator it; + for ( it = notes.begin(); it != notes.end(); ++it ) + manager()->registerNote( this, *it ); + + return true; +} + +bool ResourceLocal::save() +{ + if ( !mCalendar.save( mURL.path(), new KCal::ICalFormat() ) ) + { + KMessageBox::error( 0, + i18n("Unable to save the notes to %1. " + "Check that there is sufficient disk space." + "
There should be a backup in the same directory " + "though.
").arg( mURL.path() ) ); + return false; + } + + return true; +} + +bool ResourceLocal::addNote( KCal::Journal *journal ) +{ + mCalendar.addJournal( journal ); + return true; +} + +bool ResourceLocal::deleteNote( KCal::Journal *journal ) +{ + mCalendar.deleteJournal( journal ); + return true; +} + +KCal::Alarm::List ResourceLocal::alarms( const QDateTime& from, const QDateTime& to ) +{ + KCal::Alarm::List alarms; + KCal::Journal::List notes = mCalendar.journals(); + KCal::Journal::List::ConstIterator note; + for ( note = notes.begin(); note != notes.end(); ++note ) + { + QDateTime preTime = from.addSecs( -1 ); + KCal::Alarm::List::ConstIterator it; + for( it = (*note)->alarms().begin(); it != (*note)->alarms().end(); ++it ) + { + if ( (*it)->enabled() ) + { + QDateTime dt = (*it)->nextRepetition( preTime ); + if ( dt.isValid() && dt <= to ) + alarms.append( *it ); + } + } + } + + return alarms; +} diff --git a/knotes/resourcelocal.h b/knotes/resourcelocal.h new file mode 100644 index 000000000..da318727a --- /dev/null +++ b/knotes/resourcelocal.h @@ -0,0 +1,75 @@ +/******************************************************************* + This file is part of KNotes. + + Copyright (c) 2004, Bo Thorsen + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef RESOURCELOCAL_H +#define RESOURCELOCAL_H + +#include "resourcenotes.h" + +#include + +#include + + +class ResourceLocal : public ResourceNotes +{ +public: + ResourceLocal( const KConfig* ); + virtual ~ResourceLocal(); + + virtual void writeConfig( KConfig *config ); + + /** + * Load resource data. + */ + virtual bool load(); + + /** + * Save resource data. + */ + virtual bool save(); + + virtual KURL url() const { return mURL; } ; + virtual void setURL(const KURL& url) { mURL = url; } ; + + virtual bool addNote( KCal::Journal* ); + virtual bool deleteNote( KCal::Journal* ); + + virtual KCal::Alarm::List alarms( const QDateTime& from, const QDateTime& to ); + +protected: + KCal::CalendarLocal mCalendar; + KURL mURL; +}; + + +#endif // RESOURCELOCAL_H diff --git a/knotes/resourcelocal_plugin.cpp b/knotes/resourcelocal_plugin.cpp new file mode 100644 index 000000000..352a4c68e --- /dev/null +++ b/knotes/resourcelocal_plugin.cpp @@ -0,0 +1,68 @@ +/******************************************************************* + This file is part of KNotes. + + Copyright (c) 2004, Bo Thorsen + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include "resourcelocal.h" +#include "resourcelocalconfig.h" + + +class LocalNotesFactory + : public KRES::PluginFactoryBase +{ +public: + KRES::Resource *resource( const KConfig *config ) + { + return new ResourceLocal( config ); + } + + KRES::ConfigWidget *configWidget( QWidget *parent ) + { + return new ResourceLocalConfig(parent); + } +}; + +extern "C" +{ + void *init_knotes_local() + { + return new LocalNotesFactory(); + } + + KRES::ConfigWidget *config_widget( QWidget* parent ) + { + return new ResourceLocalConfig( parent, "Configure Local Resource" ); + } + + KRES::Resource *resource( const KConfig* config ) + { + return new ResourceLocal( config ); + } +} diff --git a/knotes/resourcelocalconfig.cpp b/knotes/resourcelocalconfig.cpp new file mode 100644 index 000000000..18e72c053 --- /dev/null +++ b/knotes/resourcelocalconfig.cpp @@ -0,0 +1,68 @@ +/******************************************************************* + Copyright (c) 2005, The KNotes Developers + + This file is part of KNotes. + + KNotes 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. + + KNotes is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KNotes; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*******************************************************************/ + +#include +#include + +#include +#include +#include +#include + +#include "resourcelocal.h" +#include "resourcelocalconfig.h" + +ResourceLocalConfig::ResourceLocalConfig( QWidget *parent, const char *name ) + : KRES::ConfigWidget( parent, name ) +{ + QHBoxLayout *layout = new QHBoxLayout( this ); + + QLabel *label = new QLabel( i18n( "Location:" ), this ); + mURL = new KURLRequester( this ); + KFile::Mode mode = static_cast( KFile::File | + KFile::LocalOnly ); + mURL->setMode( mode ); + layout->addWidget( label ); + layout->addWidget( mURL ); +} + +ResourceLocalConfig::~ResourceLocalConfig() +{ +} + +void ResourceLocalConfig::loadSettings( KRES::Resource *resource ) +{ + ResourceLocal *res = dynamic_cast( resource ); + if ( res ) + mURL->setURL( res->url().prettyURL() ); + else + kdDebug() << "ERROR: ResourceLocalConfig::loadSettings(): no ResourceLocal, cast failed" << endl; +} + +void ResourceLocalConfig::saveSettings( KRES::Resource *resource ) +{ + ResourceLocal *res = dynamic_cast( resource ); + if ( res ) + res->setURL( mURL->url() ); + else + kdDebug() << "ERROR: ResourceLocalConfig::saveSettings(): no ResourceLocal, cast failed" << endl; +} + +#include "resourcelocalconfig.moc" diff --git a/knotes/resourcelocalconfig.h b/knotes/resourcelocalconfig.h new file mode 100644 index 000000000..9a691853b --- /dev/null +++ b/knotes/resourcelocalconfig.h @@ -0,0 +1,43 @@ +/******************************************************************* + Copyright (c) 2005, The KNotes Developers + + This file is part of KNotes. + + KNotes 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. + + KNotes is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KNotes; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*******************************************************************/ + +#ifndef RESOURCELOCALCONFIG_H +#define RESOURCELOCALCONFIG_H + +#include + +class KURLRequester; + +class ResourceLocalConfig : public KRES::ConfigWidget +{ + Q_OBJECT + public: + ResourceLocalConfig( QWidget *parent = 0, const char *name = 0 ); + virtual ~ResourceLocalConfig(); + + public slots: + virtual void loadSettings( KRES::Resource* resource ); + virtual void saveSettings( KRES::Resource* resource ); + + private: + KURLRequester *mURL; +}; + +#endif diff --git a/knotes/resourcemanager.cpp b/knotes/resourcemanager.cpp new file mode 100644 index 000000000..aa73fc06c --- /dev/null +++ b/knotes/resourcemanager.cpp @@ -0,0 +1,156 @@ +/******************************************************************* + This file is part of KNotes. + + Copyright (c) 2004, Bo Thorsen + 2004, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include "knotes/resourcemanager.h" +#include "knotes/resourcelocal.h" + +#include + + +KNotesResourceManager::KNotesResourceManager() + : QObject( 0, "KNotes Resource Manager" ) +{ + m_manager = new KRES::Manager( "notes" ); + m_manager->addObserver( this ); + m_manager->readConfig(); +} + +KNotesResourceManager::~KNotesResourceManager() +{ + delete m_manager; +} + +void KNotesResourceManager::load() +{ + if ( !m_manager->standardResource() ) + { + kdWarning(5500) << "No standard resource yet." << endl; + ResourceNotes *resource = new ResourceLocal( 0 ); + m_manager->add( resource ); + m_manager->setStandardResource( resource ); + } + + // Open all active resources + KRES::Manager::ActiveIterator it; + for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it ) + { + kdDebug(5500) << "Opening resource " + (*it)->resourceName() << endl; + (*it)->setManager( this ); + if ( (*it)->open() ) + (*it)->load(); + } +} + +void KNotesResourceManager::save() +{ + KRES::Manager::ActiveIterator it; + for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it ) + (*it)->save(); +} + +// when adding a new note, make sure a config file exists!! + +void KNotesResourceManager::addNewNote( KCal::Journal *journal ) +{ + // TODO: Make this configurable + ResourceNotes *resource = m_manager->standardResource(); + if ( resource ) + { + resource->addNote( journal ); + registerNote( resource, journal ); + } + else + kdWarning(5500) << k_funcinfo << "no resource!" << endl; +} + +void KNotesResourceManager::registerNote( ResourceNotes *resource, + KCal::Journal *journal ) +{ + // TODO: only emit the signal if the journal is new? + m_resourceMap.insert( journal->uid(), resource ); + emit sigRegisteredNote( journal ); +} + +void KNotesResourceManager::deleteNote( KCal::Journal *journal ) +{ + QString uid = journal->uid(); + + // Remove the journal from the resource it came from + m_resourceMap[ uid ]->deleteNote( journal ); + m_resourceMap.remove( uid ); + + // libkcal does not delete the journal immediately, therefore it is ok to + // emit the journal here + emit sigDeregisteredNote( journal ); +} + +KCal::Alarm::List KNotesResourceManager::alarms( const QDateTime& from, const QDateTime& to ) +{ + KCal::Alarm::List result; + + KRES::Manager::ActiveIterator it; + for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it ) + { + KCal::Alarm::List list = (*it)->alarms( from, to ); + KCal::Alarm::List::Iterator it; + for ( it = list.begin(); it != list.end(); ++it ) + result.append( *it ); + } + + return result; +} + +void KNotesResourceManager::resourceAdded( ResourceNotes *resource ) +{ + kdDebug(5500) << "Resource added: " << resource->resourceName() << endl; + + if ( !resource->isActive() ) + return; + + resource->setManager( this ); + if ( resource->open() ) + resource->load(); +} + +void KNotesResourceManager::resourceModified( ResourceNotes *resource ) +{ + kdDebug(5500) << "Resource modified: " << resource->resourceName() << endl; +} + +void KNotesResourceManager::resourceDeleted( ResourceNotes *resource ) +{ + kdDebug(5500) << "Resource deleted: " << resource->resourceName() << endl; +} + + +#include "resourcemanager.moc" diff --git a/knotes/resourcemanager.h b/knotes/resourcemanager.h new file mode 100644 index 000000000..b32e0f52a --- /dev/null +++ b/knotes/resourcemanager.h @@ -0,0 +1,82 @@ +/******************************************************************* + This file is part of KNotes. + + Copyright (c) 2004, Bo Thorsen + 2004, Michael Brade + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef KNOTES_RESOURCEMANAGER_H +#define KNOTES_RESOURCEMANAGER_H + +#include +#include + +#include + +class KNotesApp; +class KNote; + +namespace KCal { + class Journal; +} + + +class KNotesResourceManager : public QObject, public KRES::ManagerObserver +{ + Q_OBJECT +public: + KNotesResourceManager(); + virtual ~KNotesResourceManager(); + + void load(); + void save(); + + void addNewNote( KCal::Journal *journal ); + void registerNote( ResourceNotes *resource, KCal::Journal *journal ); + + void deleteNote( KCal::Journal *journal ); + + KCal::Alarm::List alarms( const QDateTime& from, const QDateTime& to ); + + // from the ManagerObserver interface + virtual void resourceAdded( ResourceNotes *resource ); + virtual void resourceModified( ResourceNotes *resource ); + virtual void resourceDeleted( ResourceNotes *resource ); + +signals: + void sigRegisteredNote( KCal::Journal *journal ); + void sigDeregisteredNote( KCal::Journal *journal ); + +private: + KRES::Manager *m_manager; + QDict m_resourceMap; +}; + + +#endif // RESOURCEMANAGER_H diff --git a/knotes/resourcenotes.cpp b/knotes/resourcenotes.cpp new file mode 100644 index 000000000..4295396c3 --- /dev/null +++ b/knotes/resourcenotes.cpp @@ -0,0 +1,45 @@ +/******************************************************************* + This file is part of KNotes. + + Copyright (c) 2004, Bo Thorsen + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#include "resourcenotes.h" + + +ResourceNotes::ResourceNotes( const KConfig *config ) + : KRES::Resource( config ), mManager( 0 ) +{ + if ( !config ) + setResourceName( "Notes" ); +} + +ResourceNotes::~ResourceNotes() +{ +} diff --git a/knotes/resourcenotes.h b/knotes/resourcenotes.h new file mode 100644 index 000000000..a1c2f67b8 --- /dev/null +++ b/knotes/resourcenotes.h @@ -0,0 +1,84 @@ +/******************************************************************* + This file is part of KNotes. + + Copyright (c) 2004, Bo Thorsen + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*******************************************************************/ + +#ifndef RESOURCENOTES_H +#define RESOURCENOTES_H + +#include +#include +#include + +class KConfig; +class KNotesResourceManager; + +namespace KCal { + class Journal; +} + + +/** + * This class provides the interfaces for a KNotes resource. It makes use of + * the kresources framework. + * + * \warning This code is still under heavy development. Don't expect source or + * binary compatibility in future versions. + */ +class KDE_EXPORT ResourceNotes : public KRES::Resource +{ +public: + ResourceNotes( const KConfig * ); + virtual ~ResourceNotes(); + + /** + * Load resource data. + */ + virtual bool load() = 0; + + /** + * Save resource data. + */ + virtual bool save() = 0; + + virtual bool addNote( KCal::Journal * ) = 0; + virtual bool deleteNote( KCal::Journal * ) = 0; + + virtual KCal::Alarm::List alarms( const QDateTime& from, const QDateTime& to ) = 0; + + void setManager( KNotesResourceManager *manager ) { mManager = manager; } + KNotesResourceManager *manager() const { return mManager; } + +protected: + KNotesResourceManager *mManager; +}; + + +#endif // RESOURCENOTES_H diff --git a/knotes/version.h b/knotes/version.h new file mode 100644 index 000000000..52bee95b2 --- /dev/null +++ b/knotes/version.h @@ -0,0 +1,2 @@ +// The version has to be a double! +#define KNOTES_VERSION 3.6 -- cgit v1.2.1