From 2c2fbd828ca474671bb9e03681b30b115d8d6035 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 6 Nov 2011 15:57:02 -0600 Subject: Actually move the kde files that were renamed in the last commit --- kdepim.lsm | 12 - libkdepim/CMakeLists.txt | 108 -- libkdepim/ConfigureChecks.cmake | 10 - libkdepim/Makefile.am | 71 -- libkdepim/README | 36 - libkdepim/TODO | 10 - libkdepim/about/CMakeLists.txt | 19 - libkdepim/about/Makefile.am | 9 - libkdepim/about/bar-bottom-left.png | Bin 369 -> 0 bytes libkdepim/about/bar-bottom-middle.png | Bin 160 -> 0 bytes libkdepim/about/bar-bottom-right.png | Bin 346 -> 0 bytes libkdepim/about/bar-middle-left.png | Bin 126 -> 0 bytes libkdepim/about/bar-middle-right.png | Bin 123 -> 0 bytes libkdepim/about/bar-top-left.png | Bin 358 -> 0 bytes libkdepim/about/bar-top-middle.png | Bin 145 -> 0 bytes libkdepim/about/bar-top-right.png | Bin 359 -> 0 bytes libkdepim/about/bottom-left.png | Bin 665 -> 0 bytes libkdepim/about/bottom-middle.png | Bin 174 -> 0 bytes libkdepim/about/bottom-right.png | Bin 4922 -> 0 bytes libkdepim/about/box-bottom-left.png | Bin 713 -> 0 bytes libkdepim/about/box-bottom-middle.png | Bin 171 -> 0 bytes libkdepim/about/box-bottom-right.png | Bin 675 -> 0 bytes libkdepim/about/box-middle-left.png | Bin 157 -> 0 bytes libkdepim/about/box-middle-right.png | Bin 161 -> 0 bytes libkdepim/about/box-top-left.png | Bin 2311 -> 0 bytes libkdepim/about/box-top-middle.png | Bin 153 -> 0 bytes libkdepim/about/box-top-right.png | Bin 2311 -> 0 bytes libkdepim/about/kde_infopage.css | 239 ---- libkdepim/about/kde_infopage_rtl.css | 11 - libkdepim/about/top-left.png | Bin 15484 -> 0 bytes libkdepim/about/top-middle.png | Bin 233 -> 0 bytes libkdepim/addresseediffalgo.cpp | 146 --- libkdepim/addresseediffalgo.h | 50 - libkdepim/addresseeemailselection.cpp | 264 ---- libkdepim/addresseeemailselection.h | 148 --- libkdepim/addresseelineedit.cpp | 1285 -------------------- libkdepim/addresseelineedit.h | 183 --- libkdepim/addresseeselector.cpp | 581 --------- libkdepim/addresseeselector.h | 234 ---- libkdepim/addresseeview.cpp | 792 ------------ libkdepim/addresseeview.h | 205 ---- libkdepim/addressesdialog.cpp | 1197 ------------------ libkdepim/addressesdialog.h | 223 ---- libkdepim/addresspicker.ui | 327 ----- libkdepim/alarmclient.cpp | 60 - libkdepim/alarmclient.h | 44 - libkdepim/broadcaststatus.cpp | 165 --- libkdepim/broadcaststatus.h | 94 -- libkdepim/calendardiffalgo.cpp | 213 ---- libkdepim/calendardiffalgo.h | 54 - libkdepim/categoryeditdialog.cpp | 193 --- libkdepim/categoryeditdialog.h | 67 - libkdepim/categoryeditdialog_base.ui | 107 -- libkdepim/categoryselectdialog.cpp | 146 --- libkdepim/categoryselectdialog.h | 72 -- libkdepim/categoryselectdialog_base.ui | 101 -- libkdepim/cfgc/Makefile.am | 14 - libkdepim/cfgc/README | 6 - libkdepim/cfgc/autoexample.cpp | 66 - libkdepim/cfgc/example.cfg | 40 - libkdepim/cfgc/example.cpp | 55 - libkdepim/cfgc/exampleprefs_base.kcfg | 42 - libkdepim/cfgc/exampleprefs_base.kcfgc | 11 - libkdepim/cfgc/general_base.ui | 46 - libkdepim/cfgc/myoptions_base.ui | 46 - libkdepim/clicklineedit.cpp | 85 -- libkdepim/clicklineedit.h | 65 - libkdepim/collectingprocess.cpp | 140 --- libkdepim/collectingprocess.h | 79 -- libkdepim/completionordereditor.cpp | 307 ----- libkdepim/completionordereditor.h | 93 -- libkdepim/configmanager.cpp | 35 - libkdepim/configmanager.h | 55 - libkdepim/configure.in.in | 14 - libkdepim/csshelper.cpp | 647 ---------- libkdepim/csshelper.h | 111 -- libkdepim/designerfields.cpp | 251 ---- libkdepim/designerfields.h | 75 -- libkdepim/diffalgo.cpp | 85 -- libkdepim/diffalgo.h | 138 --- libkdepim/distributionlist.cpp | 223 ---- libkdepim/distributionlist.h | 140 --- libkdepim/embeddedurlpage.cpp | 71 -- libkdepim/embeddedurlpage.h | 54 - libkdepim/groupwarejob.cpp | 47 - libkdepim/groupwarejob.h | 37 - libkdepim/htmldiffalgodisplay.cpp | 97 -- libkdepim/htmldiffalgodisplay.h | 54 - libkdepim/icons/CMakeLists.txt | 12 - libkdepim/icons/Makefile.am | 2 - libkdepim/icons/cr22-action-button_fewer.png | Bin 883 -> 0 bytes libkdepim/icons/cr22-action-button_more.png | Bin 769 -> 0 bytes libkdepim/infoextension.cpp | 38 - libkdepim/infoextension.h | 62 - libkdepim/interfaces/AddressBookServiceIface.h | 59 - libkdepim/interfaces/MailTransportServiceIface.h | 93 -- libkdepim/interfaces/Makefile.am | 0 libkdepim/kabcresourcecached.cpp | 417 ------- libkdepim/kabcresourcecached.h | 195 --- libkdepim/kabcresourcenull.h | 46 - libkdepim/kaccount.cpp | 62 - libkdepim/kaccount.h | 92 -- libkdepim/kaddrbook.cpp | 285 ----- libkdepim/kaddrbook.h | 45 - libkdepim/kcmdesignerfields.cpp | 430 ------- libkdepim/kcmdesignerfields.h | 81 -- libkdepim/kconfigpropagator.cpp | 289 ----- libkdepim/kconfigpropagator.h | 165 --- libkdepim/kconfigwizard.cpp | 197 --- libkdepim/kconfigwizard.h | 110 -- libkdepim/kdateedit.cpp | 364 ------ libkdepim/kdateedit.h | 150 --- libkdepim/kdatepickerpopup.cpp | 123 -- libkdepim/kdatepickerpopup.h | 104 -- libkdepim/kdepim.widgets | 29 - libkdepim/kdepimmacros.h | 35 - libkdepim/kdepimprotocols.h | 32 - libkdepim/kfileio.cpp | 390 ------ libkdepim/kfileio.h | 105 -- libkdepim/kfoldertree.cpp | 542 --------- libkdepim/kfoldertree.h | 319 ----- libkdepim/kimportdialog.cpp | 767 ------------ libkdepim/kimportdialog.h | 137 --- libkdepim/kincidencechooser.cpp | 326 ----- libkdepim/kincidencechooser.h | 84 -- libkdepim/kmailcompletion.cpp | 103 -- libkdepim/kmailcompletion.h | 79 -- libkdepim/komposer/Makefile.am | 1 - libkdepim/komposer/core/Makefile.am | 28 - libkdepim/komposer/core/attachment.cpp | 112 -- libkdepim/komposer/core/attachment.h | 61 - libkdepim/komposer/core/core.cpp | 357 ------ libkdepim/komposer/core/core.h | 108 -- libkdepim/komposer/core/corewidget.cpp | 32 - libkdepim/komposer/core/corewidget.h | 49 - libkdepim/komposer/core/editor.cpp | 51 - libkdepim/komposer/core/editor.h | 105 -- libkdepim/komposer/core/komposer.kcfg | 26 - libkdepim/komposer/core/komposerIface.h | 85 -- libkdepim/komposer/core/komposerconfig.desktop | 56 - libkdepim/komposer/core/komposereditor.desktop | 56 - libkdepim/komposer/core/komposerplugin.desktop | 59 - libkdepim/komposer/core/komposerui.rc | 51 - libkdepim/komposer/core/plugin.cpp | 80 -- libkdepim/komposer/core/plugin.h | 76 -- libkdepim/komposer/core/pluginmanager.cpp | 489 -------- libkdepim/komposer/core/pluginmanager.h | 252 ---- libkdepim/komposer/core/prefsmodule.cpp | 142 --- libkdepim/komposer/core/prefsmodule.h | 72 -- libkdepim/komposer/core/settings.kcfgc | 9 - libkdepim/komposer/core/tests/Makefile.am | 20 - libkdepim/komposer/core/tests/main.cpp | 52 - libkdepim/komposer/core/tests/managertest.cpp | 43 - libkdepim/komposer/core/tests/managertest.h | 45 - libkdepim/komposer/core/tests/tester.cpp | 30 - libkdepim/komposer/core/tests/tester.h | 71 -- libkdepim/komposer/core/tests/testfactory.h | 71 -- libkdepim/komposer/core/tests/testkomposer.cpp | 18 - libkdepim/komposer/core/tests/testmanager.cpp | 53 - libkdepim/komposer/core/tests/testmanager.h | 26 - libkdepim/komposer/plugins/Makefile.am | 1 - libkdepim/komposer/plugins/default/Makefile.am | 15 - .../komposer/plugins/default/defaulteditor.cpp | 361 ------ .../komposer/plugins/default/defaulteditor.desktop | 109 -- libkdepim/komposer/plugins/default/defaulteditor.h | 118 -- .../komposer/plugins/default/defaulteditorui.rc | 90 -- libkdepim/komposer/test/Makefile.am | 7 - libkdepim/komposer/test/test.cpp | 56 - libkdepim/kpartsdesignerplugin/CMakeLists.txt | 32 - libkdepim/kpartsdesignerplugin/Makefile.am | 8 - libkdepim/kpartsdesignerplugin/README | 2 - .../kpartsdesignerplugin/kpartsdesignerplugin.cpp | 117 -- .../kpartsdesignerplugin/kpartsdesignerplugin.h | 71 -- libkdepim/kpimprefs.cpp | 187 --- libkdepim/kpimprefs.h | 86 -- libkdepim/kpimurlrequesterdlg.cpp | 41 - libkdepim/kpimurlrequesterdlg.h | 47 - libkdepim/kpixmapregionselectordialog.cpp | 131 -- libkdepim/kpixmapregionselectordialog.h | 112 -- libkdepim/kpixmapregionselectorwidget.cpp | 454 ------- libkdepim/kpixmapregionselectorwidget.h | 176 --- libkdepim/kprefsdialog.cpp | 907 -------------- libkdepim/kprefsdialog.h | 798 ------------ libkdepim/kregexp3.cpp | 183 --- libkdepim/kregexp3.h | 111 -- libkdepim/kresourceprefs.cpp | 38 - libkdepim/kresourceprefs.h | 49 - libkdepim/krsqueezedtextlabel.cpp | 86 -- libkdepim/krsqueezedtextlabel.h | 75 -- libkdepim/kscoring.cpp | 1234 ------------------- libkdepim/kscoring.h | 429 ------- libkdepim/kscoringeditor.cpp | 1029 ---------------- libkdepim/kscoringeditor.h | 317 ----- libkdepim/ksubscription.cpp | 793 ------------ libkdepim/ksubscription.h | 382 ------ libkdepim/ktimeedit.cpp | 292 ----- libkdepim/ktimeedit.h | 96 -- libkdepim/kvcarddrag.cpp | 101 -- libkdepim/kvcarddrag.h | 95 -- libkdepim/kwidgetlister.cpp | 178 --- libkdepim/kwidgetlister.h | 154 --- libkdepim/kxface.cpp | 729 ----------- libkdepim/kxface.h | 594 --------- libkdepim/ldapclient.cpp | 613 ---------- libkdepim/ldapclient.h | 300 ----- libkdepim/ldapsearchdialog.cpp | 480 -------- libkdepim/ldapsearchdialog.h | 93 -- libkdepim/linklocator.cpp | 466 ------- libkdepim/linklocator.h | 190 --- libkdepim/maillistdrag.cpp | 259 ---- libkdepim/maillistdrag.h | 135 -- libkdepim/overlaywidget.cpp | 92 -- libkdepim/overlaywidget.h | 70 -- libkdepim/pics/CMakeLists.txt | 15 - libkdepim/pics/Makefile.am | 6 - libkdepim/pics/addresseelineedit.png | Bin 1170 -> 0 bytes libkdepim/pics/clicklineedit.png | Bin 1236 -> 0 bytes libkdepim/pics/kdateedit.png | Bin 1232 -> 0 bytes libkdepim/pics/ktimeedit.png | Bin 818 -> 0 bytes libkdepim/pimemoticons.kcfg | 178 --- libkdepim/pimemoticons.kcfgc | 5 - libkdepim/pluginloader.h | 135 -- libkdepim/pluginloaderbase.cpp | 159 --- libkdepim/pluginloaderbase.h | 86 -- libkdepim/progressdialog.cpp | 437 ------- libkdepim/progressdialog.h | 160 --- libkdepim/progressmanager.cpp | 248 ---- libkdepim/progressmanager.h | 438 ------- libkdepim/qutf7codec.cpp | 550 --------- libkdepim/qutf7codec.h | 96 -- libkdepim/qutf7codecplugin.cpp | 62 - libkdepim/recentaddresses.cpp | 181 --- libkdepim/recentaddresses.h | 132 -- libkdepim/resourceabc.cpp | 38 - libkdepim/resourceabc.h | 116 -- libkdepim/sendsmsdialog.cpp | 85 -- libkdepim/sendsmsdialog.h | 50 - libkdepim/sidebarextension.cpp | 40 - libkdepim/sidebarextension.h | 69 -- libkdepim/spellingfilter.cpp | 220 ---- libkdepim/spellingfilter.h | 77 -- libkdepim/ssllabel.cpp | 97 -- libkdepim/ssllabel.h | 59 - libkdepim/statusbarprogresswidget.cpp | 296 ----- libkdepim/statusbarprogresswidget.h | 106 -- libkdepim/tests/Makefile.am | 35 - libkdepim/tests/myconfig.kcfgc | 11 - libkdepim/tests/propagator_test.kcfg | 44 - libkdepim/tests/test_kregexp.cpp | 16 - libkdepim/tests/testaddresseelineedit.cpp | 44 - libkdepim/tests/testaddresseeselector.cpp | 52 - libkdepim/tests/testdateedit.cpp | 68 -- libkdepim/tests/testdateedit.h | 39 - libkdepim/tests/testdistrlist.cpp | 332 ----- libkdepim/tests/testdistrlist.h | 47 - libkdepim/tests/testkincidencechooser.cpp | 45 - libkdepim/tests/testlinklocator.cpp | 114 -- libkdepim/tests/testutf7decoder.cpp | 26 - libkdepim/tests/testutf7encoder.cpp | 93 -- libkdepim/tests/testutf7encoder2.cpp | 45 - libkdepim/tests/testwizard.cpp | 100 -- libkdepim/weaver.cpp | 550 --------- libkdepim/weaver.h | 451 ------- libkdepim/weaverextensions.cpp | 62 - libkdepim/weaverextensions.h | 60 - libkdepim/weaverlogger.cpp | 60 - libkdepim/weaverlogger.h | 42 - libtdepim/CMakeLists.txt | 108 ++ libtdepim/ConfigureChecks.cmake | 10 + libtdepim/Makefile.am | 71 ++ libtdepim/README | 36 + libtdepim/TODO | 10 + libtdepim/about/CMakeLists.txt | 19 + libtdepim/about/Makefile.am | 9 + libtdepim/about/bar-bottom-left.png | Bin 0 -> 369 bytes libtdepim/about/bar-bottom-middle.png | Bin 0 -> 160 bytes libtdepim/about/bar-bottom-right.png | Bin 0 -> 346 bytes libtdepim/about/bar-middle-left.png | Bin 0 -> 126 bytes libtdepim/about/bar-middle-right.png | Bin 0 -> 123 bytes libtdepim/about/bar-top-left.png | Bin 0 -> 358 bytes libtdepim/about/bar-top-middle.png | Bin 0 -> 145 bytes libtdepim/about/bar-top-right.png | Bin 0 -> 359 bytes libtdepim/about/bottom-left.png | Bin 0 -> 665 bytes libtdepim/about/bottom-middle.png | Bin 0 -> 174 bytes libtdepim/about/bottom-right.png | Bin 0 -> 4922 bytes libtdepim/about/box-bottom-left.png | Bin 0 -> 713 bytes libtdepim/about/box-bottom-middle.png | Bin 0 -> 171 bytes libtdepim/about/box-bottom-right.png | Bin 0 -> 675 bytes libtdepim/about/box-middle-left.png | Bin 0 -> 157 bytes libtdepim/about/box-middle-right.png | Bin 0 -> 161 bytes libtdepim/about/box-top-left.png | Bin 0 -> 2311 bytes libtdepim/about/box-top-middle.png | Bin 0 -> 153 bytes libtdepim/about/box-top-right.png | Bin 0 -> 2311 bytes libtdepim/about/kde_infopage.css | 239 ++++ libtdepim/about/kde_infopage_rtl.css | 11 + libtdepim/about/top-left.png | Bin 0 -> 15484 bytes libtdepim/about/top-middle.png | Bin 0 -> 233 bytes libtdepim/addresseediffalgo.cpp | 146 +++ libtdepim/addresseediffalgo.h | 50 + libtdepim/addresseeemailselection.cpp | 264 ++++ libtdepim/addresseeemailselection.h | 148 +++ libtdepim/addresseelineedit.cpp | 1285 ++++++++++++++++++++ libtdepim/addresseelineedit.h | 183 +++ libtdepim/addresseeselector.cpp | 581 +++++++++ libtdepim/addresseeselector.h | 234 ++++ libtdepim/addresseeview.cpp | 792 ++++++++++++ libtdepim/addresseeview.h | 205 ++++ libtdepim/addressesdialog.cpp | 1197 ++++++++++++++++++ libtdepim/addressesdialog.h | 223 ++++ libtdepim/addresspicker.ui | 327 +++++ libtdepim/alarmclient.cpp | 60 + libtdepim/alarmclient.h | 44 + libtdepim/broadcaststatus.cpp | 165 +++ libtdepim/broadcaststatus.h | 94 ++ libtdepim/calendardiffalgo.cpp | 213 ++++ libtdepim/calendardiffalgo.h | 54 + libtdepim/categoryeditdialog.cpp | 193 +++ libtdepim/categoryeditdialog.h | 67 + libtdepim/categoryeditdialog_base.ui | 107 ++ libtdepim/categoryselectdialog.cpp | 146 +++ libtdepim/categoryselectdialog.h | 72 ++ libtdepim/categoryselectdialog_base.ui | 101 ++ libtdepim/cfgc/Makefile.am | 14 + libtdepim/cfgc/README | 6 + libtdepim/cfgc/autoexample.cpp | 66 + libtdepim/cfgc/example.cfg | 40 + libtdepim/cfgc/example.cpp | 55 + libtdepim/cfgc/exampleprefs_base.kcfg | 42 + libtdepim/cfgc/exampleprefs_base.kcfgc | 11 + libtdepim/cfgc/general_base.ui | 46 + libtdepim/cfgc/myoptions_base.ui | 46 + libtdepim/clicklineedit.cpp | 85 ++ libtdepim/clicklineedit.h | 65 + libtdepim/collectingprocess.cpp | 140 +++ libtdepim/collectingprocess.h | 79 ++ libtdepim/completionordereditor.cpp | 307 +++++ libtdepim/completionordereditor.h | 93 ++ libtdepim/configmanager.cpp | 35 + libtdepim/configmanager.h | 55 + libtdepim/configure.in.in | 14 + libtdepim/csshelper.cpp | 647 ++++++++++ libtdepim/csshelper.h | 111 ++ libtdepim/designerfields.cpp | 251 ++++ libtdepim/designerfields.h | 75 ++ libtdepim/diffalgo.cpp | 85 ++ libtdepim/diffalgo.h | 138 +++ libtdepim/distributionlist.cpp | 223 ++++ libtdepim/distributionlist.h | 140 +++ libtdepim/embeddedurlpage.cpp | 71 ++ libtdepim/embeddedurlpage.h | 54 + libtdepim/groupwarejob.cpp | 47 + libtdepim/groupwarejob.h | 37 + libtdepim/htmldiffalgodisplay.cpp | 97 ++ libtdepim/htmldiffalgodisplay.h | 54 + libtdepim/icons/CMakeLists.txt | 12 + libtdepim/icons/Makefile.am | 2 + libtdepim/icons/cr22-action-button_fewer.png | Bin 0 -> 883 bytes libtdepim/icons/cr22-action-button_more.png | Bin 0 -> 769 bytes libtdepim/infoextension.cpp | 38 + libtdepim/infoextension.h | 62 + libtdepim/interfaces/AddressBookServiceIface.h | 59 + libtdepim/interfaces/MailTransportServiceIface.h | 93 ++ libtdepim/interfaces/Makefile.am | 0 libtdepim/kabcresourcecached.cpp | 417 +++++++ libtdepim/kabcresourcecached.h | 195 +++ libtdepim/kabcresourcenull.h | 46 + libtdepim/kaccount.cpp | 62 + libtdepim/kaccount.h | 92 ++ libtdepim/kaddrbook.cpp | 285 +++++ libtdepim/kaddrbook.h | 45 + libtdepim/kcmdesignerfields.cpp | 430 +++++++ libtdepim/kcmdesignerfields.h | 81 ++ libtdepim/kconfigpropagator.cpp | 289 +++++ libtdepim/kconfigpropagator.h | 165 +++ libtdepim/kconfigwizard.cpp | 197 +++ libtdepim/kconfigwizard.h | 110 ++ libtdepim/kdateedit.cpp | 364 ++++++ libtdepim/kdateedit.h | 150 +++ libtdepim/kdatepickerpopup.cpp | 123 ++ libtdepim/kdatepickerpopup.h | 104 ++ libtdepim/kfileio.cpp | 390 ++++++ libtdepim/kfileio.h | 105 ++ libtdepim/kfoldertree.cpp | 542 +++++++++ libtdepim/kfoldertree.h | 319 +++++ libtdepim/kimportdialog.cpp | 767 ++++++++++++ libtdepim/kimportdialog.h | 137 +++ libtdepim/kincidencechooser.cpp | 326 +++++ libtdepim/kincidencechooser.h | 84 ++ libtdepim/kmailcompletion.cpp | 103 ++ libtdepim/kmailcompletion.h | 79 ++ libtdepim/komposer/Makefile.am | 1 + libtdepim/komposer/core/Makefile.am | 28 + libtdepim/komposer/core/attachment.cpp | 112 ++ libtdepim/komposer/core/attachment.h | 61 + libtdepim/komposer/core/core.cpp | 357 ++++++ libtdepim/komposer/core/core.h | 108 ++ libtdepim/komposer/core/corewidget.cpp | 32 + libtdepim/komposer/core/corewidget.h | 49 + libtdepim/komposer/core/editor.cpp | 51 + libtdepim/komposer/core/editor.h | 105 ++ libtdepim/komposer/core/komposer.kcfg | 26 + libtdepim/komposer/core/komposerIface.h | 85 ++ libtdepim/komposer/core/komposerconfig.desktop | 56 + libtdepim/komposer/core/komposereditor.desktop | 56 + libtdepim/komposer/core/komposerplugin.desktop | 59 + libtdepim/komposer/core/komposerui.rc | 51 + libtdepim/komposer/core/plugin.cpp | 80 ++ libtdepim/komposer/core/plugin.h | 76 ++ libtdepim/komposer/core/pluginmanager.cpp | 489 ++++++++ libtdepim/komposer/core/pluginmanager.h | 252 ++++ libtdepim/komposer/core/prefsmodule.cpp | 142 +++ libtdepim/komposer/core/prefsmodule.h | 72 ++ libtdepim/komposer/core/settings.kcfgc | 9 + libtdepim/komposer/core/tests/Makefile.am | 20 + libtdepim/komposer/core/tests/main.cpp | 52 + libtdepim/komposer/core/tests/managertest.cpp | 43 + libtdepim/komposer/core/tests/managertest.h | 45 + libtdepim/komposer/core/tests/tester.cpp | 30 + libtdepim/komposer/core/tests/tester.h | 71 ++ libtdepim/komposer/core/tests/testfactory.h | 71 ++ libtdepim/komposer/core/tests/testkomposer.cpp | 18 + libtdepim/komposer/core/tests/testmanager.cpp | 53 + libtdepim/komposer/core/tests/testmanager.h | 26 + libtdepim/komposer/plugins/Makefile.am | 1 + libtdepim/komposer/plugins/default/Makefile.am | 15 + .../komposer/plugins/default/defaulteditor.cpp | 361 ++++++ .../komposer/plugins/default/defaulteditor.desktop | 109 ++ libtdepim/komposer/plugins/default/defaulteditor.h | 118 ++ .../komposer/plugins/default/defaulteditorui.rc | 90 ++ libtdepim/komposer/test/Makefile.am | 7 + libtdepim/komposer/test/test.cpp | 56 + libtdepim/kpartsdesignerplugin/CMakeLists.txt | 32 + libtdepim/kpartsdesignerplugin/Makefile.am | 8 + libtdepim/kpartsdesignerplugin/README | 2 + .../kpartsdesignerplugin/kpartsdesignerplugin.cpp | 117 ++ .../kpartsdesignerplugin/kpartsdesignerplugin.h | 71 ++ libtdepim/kpimprefs.cpp | 187 +++ libtdepim/kpimprefs.h | 86 ++ libtdepim/kpimurlrequesterdlg.cpp | 41 + libtdepim/kpimurlrequesterdlg.h | 47 + libtdepim/kpixmapregionselectordialog.cpp | 131 ++ libtdepim/kpixmapregionselectordialog.h | 112 ++ libtdepim/kpixmapregionselectorwidget.cpp | 454 +++++++ libtdepim/kpixmapregionselectorwidget.h | 176 +++ libtdepim/kprefsdialog.cpp | 907 ++++++++++++++ libtdepim/kprefsdialog.h | 798 ++++++++++++ libtdepim/kregexp3.cpp | 183 +++ libtdepim/kregexp3.h | 111 ++ libtdepim/kresourceprefs.cpp | 38 + libtdepim/kresourceprefs.h | 49 + libtdepim/krsqueezedtextlabel.cpp | 86 ++ libtdepim/krsqueezedtextlabel.h | 75 ++ libtdepim/kscoring.cpp | 1234 +++++++++++++++++++ libtdepim/kscoring.h | 429 +++++++ libtdepim/kscoringeditor.cpp | 1029 ++++++++++++++++ libtdepim/kscoringeditor.h | 317 +++++ libtdepim/ksubscription.cpp | 793 ++++++++++++ libtdepim/ksubscription.h | 382 ++++++ libtdepim/ktimeedit.cpp | 292 +++++ libtdepim/ktimeedit.h | 96 ++ libtdepim/kvcarddrag.cpp | 101 ++ libtdepim/kvcarddrag.h | 95 ++ libtdepim/kwidgetlister.cpp | 178 +++ libtdepim/kwidgetlister.h | 154 +++ libtdepim/kxface.cpp | 729 +++++++++++ libtdepim/kxface.h | 594 +++++++++ libtdepim/ldapclient.cpp | 613 ++++++++++ libtdepim/ldapclient.h | 300 +++++ libtdepim/ldapsearchdialog.cpp | 480 ++++++++ libtdepim/ldapsearchdialog.h | 93 ++ libtdepim/linklocator.cpp | 466 +++++++ libtdepim/linklocator.h | 190 +++ libtdepim/maillistdrag.cpp | 259 ++++ libtdepim/maillistdrag.h | 135 ++ libtdepim/overlaywidget.cpp | 92 ++ libtdepim/overlaywidget.h | 70 ++ libtdepim/pics/CMakeLists.txt | 15 + libtdepim/pics/Makefile.am | 6 + libtdepim/pics/addresseelineedit.png | Bin 0 -> 1170 bytes libtdepim/pics/clicklineedit.png | Bin 0 -> 1236 bytes libtdepim/pics/kdateedit.png | Bin 0 -> 1232 bytes libtdepim/pics/ktimeedit.png | Bin 0 -> 818 bytes libtdepim/pimemoticons.kcfg | 178 +++ libtdepim/pimemoticons.kcfgc | 5 + libtdepim/pluginloader.h | 135 ++ libtdepim/pluginloaderbase.cpp | 159 +++ libtdepim/pluginloaderbase.h | 86 ++ libtdepim/progressdialog.cpp | 437 +++++++ libtdepim/progressdialog.h | 160 +++ libtdepim/progressmanager.cpp | 248 ++++ libtdepim/progressmanager.h | 438 +++++++ libtdepim/qutf7codec.cpp | 550 +++++++++ libtdepim/qutf7codec.h | 96 ++ libtdepim/qutf7codecplugin.cpp | 62 + libtdepim/recentaddresses.cpp | 181 +++ libtdepim/recentaddresses.h | 132 ++ libtdepim/resourceabc.cpp | 38 + libtdepim/resourceabc.h | 116 ++ libtdepim/sendsmsdialog.cpp | 85 ++ libtdepim/sendsmsdialog.h | 50 + libtdepim/sidebarextension.cpp | 40 + libtdepim/sidebarextension.h | 69 ++ libtdepim/spellingfilter.cpp | 220 ++++ libtdepim/spellingfilter.h | 77 ++ libtdepim/ssllabel.cpp | 97 ++ libtdepim/ssllabel.h | 59 + libtdepim/statusbarprogresswidget.cpp | 296 +++++ libtdepim/statusbarprogresswidget.h | 106 ++ libtdepim/tdepim.widgets | 29 + libtdepim/tdepimmacros.h | 35 + libtdepim/tdepimprotocols.h | 32 + libtdepim/tests/Makefile.am | 35 + libtdepim/tests/myconfig.kcfgc | 11 + libtdepim/tests/propagator_test.kcfg | 44 + libtdepim/tests/test_kregexp.cpp | 16 + libtdepim/tests/testaddresseelineedit.cpp | 44 + libtdepim/tests/testaddresseeselector.cpp | 52 + libtdepim/tests/testdateedit.cpp | 68 ++ libtdepim/tests/testdateedit.h | 39 + libtdepim/tests/testdistrlist.cpp | 332 +++++ libtdepim/tests/testdistrlist.h | 47 + libtdepim/tests/testkincidencechooser.cpp | 45 + libtdepim/tests/testlinklocator.cpp | 114 ++ libtdepim/tests/testutf7decoder.cpp | 26 + libtdepim/tests/testutf7encoder.cpp | 93 ++ libtdepim/tests/testutf7encoder2.cpp | 45 + libtdepim/tests/testwizard.cpp | 100 ++ libtdepim/weaver.cpp | 550 +++++++++ libtdepim/weaver.h | 451 +++++++ libtdepim/weaverextensions.cpp | 62 + libtdepim/weaverextensions.h | 60 + libtdepim/weaverlogger.cpp | 60 + libtdepim/weaverlogger.h | 42 + tdepim.lsm | 12 + 534 files changed, 39926 insertions(+), 39926 deletions(-) delete mode 100644 kdepim.lsm delete mode 100644 libkdepim/CMakeLists.txt delete mode 100644 libkdepim/ConfigureChecks.cmake delete mode 100644 libkdepim/Makefile.am delete mode 100644 libkdepim/README delete mode 100644 libkdepim/TODO delete mode 100644 libkdepim/about/CMakeLists.txt delete mode 100644 libkdepim/about/Makefile.am delete mode 100644 libkdepim/about/bar-bottom-left.png delete mode 100644 libkdepim/about/bar-bottom-middle.png delete mode 100644 libkdepim/about/bar-bottom-right.png delete mode 100644 libkdepim/about/bar-middle-left.png delete mode 100644 libkdepim/about/bar-middle-right.png delete mode 100644 libkdepim/about/bar-top-left.png delete mode 100644 libkdepim/about/bar-top-middle.png delete mode 100644 libkdepim/about/bar-top-right.png delete mode 100644 libkdepim/about/bottom-left.png delete mode 100644 libkdepim/about/bottom-middle.png delete mode 100644 libkdepim/about/bottom-right.png delete mode 100644 libkdepim/about/box-bottom-left.png delete mode 100644 libkdepim/about/box-bottom-middle.png delete mode 100644 libkdepim/about/box-bottom-right.png delete mode 100644 libkdepim/about/box-middle-left.png delete mode 100644 libkdepim/about/box-middle-right.png delete mode 100644 libkdepim/about/box-top-left.png delete mode 100644 libkdepim/about/box-top-middle.png delete mode 100644 libkdepim/about/box-top-right.png delete mode 100644 libkdepim/about/kde_infopage.css delete mode 100644 libkdepim/about/kde_infopage_rtl.css delete mode 100644 libkdepim/about/top-left.png delete mode 100644 libkdepim/about/top-middle.png delete mode 100644 libkdepim/addresseediffalgo.cpp delete mode 100644 libkdepim/addresseediffalgo.h delete mode 100644 libkdepim/addresseeemailselection.cpp delete mode 100644 libkdepim/addresseeemailselection.h delete mode 100644 libkdepim/addresseelineedit.cpp delete mode 100644 libkdepim/addresseelineedit.h delete mode 100644 libkdepim/addresseeselector.cpp delete mode 100644 libkdepim/addresseeselector.h delete mode 100644 libkdepim/addresseeview.cpp delete mode 100644 libkdepim/addresseeview.h delete mode 100644 libkdepim/addressesdialog.cpp delete mode 100644 libkdepim/addressesdialog.h delete mode 100644 libkdepim/addresspicker.ui delete mode 100644 libkdepim/alarmclient.cpp delete mode 100644 libkdepim/alarmclient.h delete mode 100644 libkdepim/broadcaststatus.cpp delete mode 100644 libkdepim/broadcaststatus.h delete mode 100644 libkdepim/calendardiffalgo.cpp delete mode 100644 libkdepim/calendardiffalgo.h delete mode 100644 libkdepim/categoryeditdialog.cpp delete mode 100644 libkdepim/categoryeditdialog.h delete mode 100644 libkdepim/categoryeditdialog_base.ui delete mode 100644 libkdepim/categoryselectdialog.cpp delete mode 100644 libkdepim/categoryselectdialog.h delete mode 100644 libkdepim/categoryselectdialog_base.ui delete mode 100644 libkdepim/cfgc/Makefile.am delete mode 100644 libkdepim/cfgc/README delete mode 100644 libkdepim/cfgc/autoexample.cpp delete mode 100644 libkdepim/cfgc/example.cfg delete mode 100644 libkdepim/cfgc/example.cpp delete mode 100644 libkdepim/cfgc/exampleprefs_base.kcfg delete mode 100644 libkdepim/cfgc/exampleprefs_base.kcfgc delete mode 100644 libkdepim/cfgc/general_base.ui delete mode 100644 libkdepim/cfgc/myoptions_base.ui delete mode 100644 libkdepim/clicklineedit.cpp delete mode 100644 libkdepim/clicklineedit.h delete mode 100644 libkdepim/collectingprocess.cpp delete mode 100644 libkdepim/collectingprocess.h delete mode 100644 libkdepim/completionordereditor.cpp delete mode 100644 libkdepim/completionordereditor.h delete mode 100644 libkdepim/configmanager.cpp delete mode 100644 libkdepim/configmanager.h delete mode 100644 libkdepim/configure.in.in delete mode 100644 libkdepim/csshelper.cpp delete mode 100644 libkdepim/csshelper.h delete mode 100644 libkdepim/designerfields.cpp delete mode 100644 libkdepim/designerfields.h delete mode 100644 libkdepim/diffalgo.cpp delete mode 100644 libkdepim/diffalgo.h delete mode 100644 libkdepim/distributionlist.cpp delete mode 100644 libkdepim/distributionlist.h delete mode 100644 libkdepim/embeddedurlpage.cpp delete mode 100644 libkdepim/embeddedurlpage.h delete mode 100644 libkdepim/groupwarejob.cpp delete mode 100644 libkdepim/groupwarejob.h delete mode 100644 libkdepim/htmldiffalgodisplay.cpp delete mode 100644 libkdepim/htmldiffalgodisplay.h delete mode 100644 libkdepim/icons/CMakeLists.txt delete mode 100644 libkdepim/icons/Makefile.am delete mode 100644 libkdepim/icons/cr22-action-button_fewer.png delete mode 100644 libkdepim/icons/cr22-action-button_more.png delete mode 100644 libkdepim/infoextension.cpp delete mode 100644 libkdepim/infoextension.h delete mode 100644 libkdepim/interfaces/AddressBookServiceIface.h delete mode 100644 libkdepim/interfaces/MailTransportServiceIface.h delete mode 100644 libkdepim/interfaces/Makefile.am delete mode 100644 libkdepim/kabcresourcecached.cpp delete mode 100644 libkdepim/kabcresourcecached.h delete mode 100644 libkdepim/kabcresourcenull.h delete mode 100644 libkdepim/kaccount.cpp delete mode 100644 libkdepim/kaccount.h delete mode 100644 libkdepim/kaddrbook.cpp delete mode 100644 libkdepim/kaddrbook.h delete mode 100644 libkdepim/kcmdesignerfields.cpp delete mode 100644 libkdepim/kcmdesignerfields.h delete mode 100644 libkdepim/kconfigpropagator.cpp delete mode 100644 libkdepim/kconfigpropagator.h delete mode 100644 libkdepim/kconfigwizard.cpp delete mode 100644 libkdepim/kconfigwizard.h delete mode 100644 libkdepim/kdateedit.cpp delete mode 100644 libkdepim/kdateedit.h delete mode 100644 libkdepim/kdatepickerpopup.cpp delete mode 100644 libkdepim/kdatepickerpopup.h delete mode 100644 libkdepim/kdepim.widgets delete mode 100644 libkdepim/kdepimmacros.h delete mode 100644 libkdepim/kdepimprotocols.h delete mode 100644 libkdepim/kfileio.cpp delete mode 100644 libkdepim/kfileio.h delete mode 100644 libkdepim/kfoldertree.cpp delete mode 100644 libkdepim/kfoldertree.h delete mode 100644 libkdepim/kimportdialog.cpp delete mode 100644 libkdepim/kimportdialog.h delete mode 100644 libkdepim/kincidencechooser.cpp delete mode 100644 libkdepim/kincidencechooser.h delete mode 100644 libkdepim/kmailcompletion.cpp delete mode 100644 libkdepim/kmailcompletion.h delete mode 100644 libkdepim/komposer/Makefile.am delete mode 100644 libkdepim/komposer/core/Makefile.am delete mode 100644 libkdepim/komposer/core/attachment.cpp delete mode 100644 libkdepim/komposer/core/attachment.h delete mode 100644 libkdepim/komposer/core/core.cpp delete mode 100644 libkdepim/komposer/core/core.h delete mode 100644 libkdepim/komposer/core/corewidget.cpp delete mode 100644 libkdepim/komposer/core/corewidget.h delete mode 100644 libkdepim/komposer/core/editor.cpp delete mode 100644 libkdepim/komposer/core/editor.h delete mode 100644 libkdepim/komposer/core/komposer.kcfg delete mode 100644 libkdepim/komposer/core/komposerIface.h delete mode 100644 libkdepim/komposer/core/komposerconfig.desktop delete mode 100644 libkdepim/komposer/core/komposereditor.desktop delete mode 100644 libkdepim/komposer/core/komposerplugin.desktop delete mode 100644 libkdepim/komposer/core/komposerui.rc delete mode 100644 libkdepim/komposer/core/plugin.cpp delete mode 100644 libkdepim/komposer/core/plugin.h delete mode 100644 libkdepim/komposer/core/pluginmanager.cpp delete mode 100644 libkdepim/komposer/core/pluginmanager.h delete mode 100644 libkdepim/komposer/core/prefsmodule.cpp delete mode 100644 libkdepim/komposer/core/prefsmodule.h delete mode 100644 libkdepim/komposer/core/settings.kcfgc delete mode 100644 libkdepim/komposer/core/tests/Makefile.am delete mode 100644 libkdepim/komposer/core/tests/main.cpp delete mode 100644 libkdepim/komposer/core/tests/managertest.cpp delete mode 100644 libkdepim/komposer/core/tests/managertest.h delete mode 100644 libkdepim/komposer/core/tests/tester.cpp delete mode 100644 libkdepim/komposer/core/tests/tester.h delete mode 100644 libkdepim/komposer/core/tests/testfactory.h delete mode 100644 libkdepim/komposer/core/tests/testkomposer.cpp delete mode 100644 libkdepim/komposer/core/tests/testmanager.cpp delete mode 100644 libkdepim/komposer/core/tests/testmanager.h delete mode 100644 libkdepim/komposer/plugins/Makefile.am delete mode 100644 libkdepim/komposer/plugins/default/Makefile.am delete mode 100644 libkdepim/komposer/plugins/default/defaulteditor.cpp delete mode 100644 libkdepim/komposer/plugins/default/defaulteditor.desktop delete mode 100644 libkdepim/komposer/plugins/default/defaulteditor.h delete mode 100644 libkdepim/komposer/plugins/default/defaulteditorui.rc delete mode 100644 libkdepim/komposer/test/Makefile.am delete mode 100644 libkdepim/komposer/test/test.cpp delete mode 100644 libkdepim/kpartsdesignerplugin/CMakeLists.txt delete mode 100644 libkdepim/kpartsdesignerplugin/Makefile.am delete mode 100644 libkdepim/kpartsdesignerplugin/README delete mode 100644 libkdepim/kpartsdesignerplugin/kpartsdesignerplugin.cpp delete mode 100644 libkdepim/kpartsdesignerplugin/kpartsdesignerplugin.h delete mode 100644 libkdepim/kpimprefs.cpp delete mode 100644 libkdepim/kpimprefs.h delete mode 100644 libkdepim/kpimurlrequesterdlg.cpp delete mode 100644 libkdepim/kpimurlrequesterdlg.h delete mode 100644 libkdepim/kpixmapregionselectordialog.cpp delete mode 100644 libkdepim/kpixmapregionselectordialog.h delete mode 100644 libkdepim/kpixmapregionselectorwidget.cpp delete mode 100644 libkdepim/kpixmapregionselectorwidget.h delete mode 100644 libkdepim/kprefsdialog.cpp delete mode 100644 libkdepim/kprefsdialog.h delete mode 100644 libkdepim/kregexp3.cpp delete mode 100644 libkdepim/kregexp3.h delete mode 100644 libkdepim/kresourceprefs.cpp delete mode 100644 libkdepim/kresourceprefs.h delete mode 100644 libkdepim/krsqueezedtextlabel.cpp delete mode 100644 libkdepim/krsqueezedtextlabel.h delete mode 100644 libkdepim/kscoring.cpp delete mode 100644 libkdepim/kscoring.h delete mode 100644 libkdepim/kscoringeditor.cpp delete mode 100644 libkdepim/kscoringeditor.h delete mode 100644 libkdepim/ksubscription.cpp delete mode 100644 libkdepim/ksubscription.h delete mode 100644 libkdepim/ktimeedit.cpp delete mode 100644 libkdepim/ktimeedit.h delete mode 100644 libkdepim/kvcarddrag.cpp delete mode 100644 libkdepim/kvcarddrag.h delete mode 100644 libkdepim/kwidgetlister.cpp delete mode 100644 libkdepim/kwidgetlister.h delete mode 100644 libkdepim/kxface.cpp delete mode 100644 libkdepim/kxface.h delete mode 100644 libkdepim/ldapclient.cpp delete mode 100644 libkdepim/ldapclient.h delete mode 100644 libkdepim/ldapsearchdialog.cpp delete mode 100644 libkdepim/ldapsearchdialog.h delete mode 100644 libkdepim/linklocator.cpp delete mode 100644 libkdepim/linklocator.h delete mode 100644 libkdepim/maillistdrag.cpp delete mode 100644 libkdepim/maillistdrag.h delete mode 100644 libkdepim/overlaywidget.cpp delete mode 100644 libkdepim/overlaywidget.h delete mode 100644 libkdepim/pics/CMakeLists.txt delete mode 100644 libkdepim/pics/Makefile.am delete mode 100644 libkdepim/pics/addresseelineedit.png delete mode 100644 libkdepim/pics/clicklineedit.png delete mode 100644 libkdepim/pics/kdateedit.png delete mode 100644 libkdepim/pics/ktimeedit.png delete mode 100644 libkdepim/pimemoticons.kcfg delete mode 100644 libkdepim/pimemoticons.kcfgc delete mode 100644 libkdepim/pluginloader.h delete mode 100644 libkdepim/pluginloaderbase.cpp delete mode 100644 libkdepim/pluginloaderbase.h delete mode 100644 libkdepim/progressdialog.cpp delete mode 100644 libkdepim/progressdialog.h delete mode 100644 libkdepim/progressmanager.cpp delete mode 100644 libkdepim/progressmanager.h delete mode 100644 libkdepim/qutf7codec.cpp delete mode 100644 libkdepim/qutf7codec.h delete mode 100644 libkdepim/qutf7codecplugin.cpp delete mode 100644 libkdepim/recentaddresses.cpp delete mode 100644 libkdepim/recentaddresses.h delete mode 100644 libkdepim/resourceabc.cpp delete mode 100644 libkdepim/resourceabc.h delete mode 100644 libkdepim/sendsmsdialog.cpp delete mode 100644 libkdepim/sendsmsdialog.h delete mode 100644 libkdepim/sidebarextension.cpp delete mode 100644 libkdepim/sidebarextension.h delete mode 100644 libkdepim/spellingfilter.cpp delete mode 100644 libkdepim/spellingfilter.h delete mode 100644 libkdepim/ssllabel.cpp delete mode 100644 libkdepim/ssllabel.h delete mode 100644 libkdepim/statusbarprogresswidget.cpp delete mode 100644 libkdepim/statusbarprogresswidget.h delete mode 100644 libkdepim/tests/Makefile.am delete mode 100644 libkdepim/tests/myconfig.kcfgc delete mode 100644 libkdepim/tests/propagator_test.kcfg delete mode 100644 libkdepim/tests/test_kregexp.cpp delete mode 100644 libkdepim/tests/testaddresseelineedit.cpp delete mode 100644 libkdepim/tests/testaddresseeselector.cpp delete mode 100644 libkdepim/tests/testdateedit.cpp delete mode 100644 libkdepim/tests/testdateedit.h delete mode 100644 libkdepim/tests/testdistrlist.cpp delete mode 100644 libkdepim/tests/testdistrlist.h delete mode 100644 libkdepim/tests/testkincidencechooser.cpp delete mode 100644 libkdepim/tests/testlinklocator.cpp delete mode 100644 libkdepim/tests/testutf7decoder.cpp delete mode 100644 libkdepim/tests/testutf7encoder.cpp delete mode 100644 libkdepim/tests/testutf7encoder2.cpp delete mode 100644 libkdepim/tests/testwizard.cpp delete mode 100644 libkdepim/weaver.cpp delete mode 100644 libkdepim/weaver.h delete mode 100644 libkdepim/weaverextensions.cpp delete mode 100644 libkdepim/weaverextensions.h delete mode 100644 libkdepim/weaverlogger.cpp delete mode 100644 libkdepim/weaverlogger.h create mode 100644 libtdepim/CMakeLists.txt create mode 100644 libtdepim/ConfigureChecks.cmake create mode 100644 libtdepim/Makefile.am create mode 100644 libtdepim/README create mode 100644 libtdepim/TODO create mode 100644 libtdepim/about/CMakeLists.txt create mode 100644 libtdepim/about/Makefile.am create mode 100644 libtdepim/about/bar-bottom-left.png create mode 100644 libtdepim/about/bar-bottom-middle.png create mode 100644 libtdepim/about/bar-bottom-right.png create mode 100644 libtdepim/about/bar-middle-left.png create mode 100644 libtdepim/about/bar-middle-right.png create mode 100644 libtdepim/about/bar-top-left.png create mode 100644 libtdepim/about/bar-top-middle.png create mode 100644 libtdepim/about/bar-top-right.png create mode 100644 libtdepim/about/bottom-left.png create mode 100644 libtdepim/about/bottom-middle.png create mode 100644 libtdepim/about/bottom-right.png create mode 100644 libtdepim/about/box-bottom-left.png create mode 100644 libtdepim/about/box-bottom-middle.png create mode 100644 libtdepim/about/box-bottom-right.png create mode 100644 libtdepim/about/box-middle-left.png create mode 100644 libtdepim/about/box-middle-right.png create mode 100644 libtdepim/about/box-top-left.png create mode 100644 libtdepim/about/box-top-middle.png create mode 100644 libtdepim/about/box-top-right.png create mode 100644 libtdepim/about/kde_infopage.css create mode 100644 libtdepim/about/kde_infopage_rtl.css create mode 100644 libtdepim/about/top-left.png create mode 100644 libtdepim/about/top-middle.png create mode 100644 libtdepim/addresseediffalgo.cpp create mode 100644 libtdepim/addresseediffalgo.h create mode 100644 libtdepim/addresseeemailselection.cpp create mode 100644 libtdepim/addresseeemailselection.h create mode 100644 libtdepim/addresseelineedit.cpp create mode 100644 libtdepim/addresseelineedit.h create mode 100644 libtdepim/addresseeselector.cpp create mode 100644 libtdepim/addresseeselector.h create mode 100644 libtdepim/addresseeview.cpp create mode 100644 libtdepim/addresseeview.h create mode 100644 libtdepim/addressesdialog.cpp create mode 100644 libtdepim/addressesdialog.h create mode 100644 libtdepim/addresspicker.ui create mode 100644 libtdepim/alarmclient.cpp create mode 100644 libtdepim/alarmclient.h create mode 100644 libtdepim/broadcaststatus.cpp create mode 100644 libtdepim/broadcaststatus.h create mode 100644 libtdepim/calendardiffalgo.cpp create mode 100644 libtdepim/calendardiffalgo.h create mode 100644 libtdepim/categoryeditdialog.cpp create mode 100644 libtdepim/categoryeditdialog.h create mode 100644 libtdepim/categoryeditdialog_base.ui create mode 100644 libtdepim/categoryselectdialog.cpp create mode 100644 libtdepim/categoryselectdialog.h create mode 100644 libtdepim/categoryselectdialog_base.ui create mode 100644 libtdepim/cfgc/Makefile.am create mode 100644 libtdepim/cfgc/README create mode 100644 libtdepim/cfgc/autoexample.cpp create mode 100644 libtdepim/cfgc/example.cfg create mode 100644 libtdepim/cfgc/example.cpp create mode 100644 libtdepim/cfgc/exampleprefs_base.kcfg create mode 100644 libtdepim/cfgc/exampleprefs_base.kcfgc create mode 100644 libtdepim/cfgc/general_base.ui create mode 100644 libtdepim/cfgc/myoptions_base.ui create mode 100644 libtdepim/clicklineedit.cpp create mode 100644 libtdepim/clicklineedit.h create mode 100644 libtdepim/collectingprocess.cpp create mode 100644 libtdepim/collectingprocess.h create mode 100644 libtdepim/completionordereditor.cpp create mode 100644 libtdepim/completionordereditor.h create mode 100644 libtdepim/configmanager.cpp create mode 100644 libtdepim/configmanager.h create mode 100644 libtdepim/configure.in.in create mode 100644 libtdepim/csshelper.cpp create mode 100644 libtdepim/csshelper.h create mode 100644 libtdepim/designerfields.cpp create mode 100644 libtdepim/designerfields.h create mode 100644 libtdepim/diffalgo.cpp create mode 100644 libtdepim/diffalgo.h create mode 100644 libtdepim/distributionlist.cpp create mode 100644 libtdepim/distributionlist.h create mode 100644 libtdepim/embeddedurlpage.cpp create mode 100644 libtdepim/embeddedurlpage.h create mode 100644 libtdepim/groupwarejob.cpp create mode 100644 libtdepim/groupwarejob.h create mode 100644 libtdepim/htmldiffalgodisplay.cpp create mode 100644 libtdepim/htmldiffalgodisplay.h create mode 100644 libtdepim/icons/CMakeLists.txt create mode 100644 libtdepim/icons/Makefile.am create mode 100644 libtdepim/icons/cr22-action-button_fewer.png create mode 100644 libtdepim/icons/cr22-action-button_more.png create mode 100644 libtdepim/infoextension.cpp create mode 100644 libtdepim/infoextension.h create mode 100644 libtdepim/interfaces/AddressBookServiceIface.h create mode 100644 libtdepim/interfaces/MailTransportServiceIface.h create mode 100644 libtdepim/interfaces/Makefile.am create mode 100644 libtdepim/kabcresourcecached.cpp create mode 100644 libtdepim/kabcresourcecached.h create mode 100644 libtdepim/kabcresourcenull.h create mode 100644 libtdepim/kaccount.cpp create mode 100644 libtdepim/kaccount.h create mode 100644 libtdepim/kaddrbook.cpp create mode 100644 libtdepim/kaddrbook.h create mode 100644 libtdepim/kcmdesignerfields.cpp create mode 100644 libtdepim/kcmdesignerfields.h create mode 100644 libtdepim/kconfigpropagator.cpp create mode 100644 libtdepim/kconfigpropagator.h create mode 100644 libtdepim/kconfigwizard.cpp create mode 100644 libtdepim/kconfigwizard.h create mode 100644 libtdepim/kdateedit.cpp create mode 100644 libtdepim/kdateedit.h create mode 100644 libtdepim/kdatepickerpopup.cpp create mode 100644 libtdepim/kdatepickerpopup.h create mode 100644 libtdepim/kfileio.cpp create mode 100644 libtdepim/kfileio.h create mode 100644 libtdepim/kfoldertree.cpp create mode 100644 libtdepim/kfoldertree.h create mode 100644 libtdepim/kimportdialog.cpp create mode 100644 libtdepim/kimportdialog.h create mode 100644 libtdepim/kincidencechooser.cpp create mode 100644 libtdepim/kincidencechooser.h create mode 100644 libtdepim/kmailcompletion.cpp create mode 100644 libtdepim/kmailcompletion.h create mode 100644 libtdepim/komposer/Makefile.am create mode 100644 libtdepim/komposer/core/Makefile.am create mode 100644 libtdepim/komposer/core/attachment.cpp create mode 100644 libtdepim/komposer/core/attachment.h create mode 100644 libtdepim/komposer/core/core.cpp create mode 100644 libtdepim/komposer/core/core.h create mode 100644 libtdepim/komposer/core/corewidget.cpp create mode 100644 libtdepim/komposer/core/corewidget.h create mode 100644 libtdepim/komposer/core/editor.cpp create mode 100644 libtdepim/komposer/core/editor.h create mode 100644 libtdepim/komposer/core/komposer.kcfg create mode 100644 libtdepim/komposer/core/komposerIface.h create mode 100644 libtdepim/komposer/core/komposerconfig.desktop create mode 100644 libtdepim/komposer/core/komposereditor.desktop create mode 100644 libtdepim/komposer/core/komposerplugin.desktop create mode 100644 libtdepim/komposer/core/komposerui.rc create mode 100644 libtdepim/komposer/core/plugin.cpp create mode 100644 libtdepim/komposer/core/plugin.h create mode 100644 libtdepim/komposer/core/pluginmanager.cpp create mode 100644 libtdepim/komposer/core/pluginmanager.h create mode 100644 libtdepim/komposer/core/prefsmodule.cpp create mode 100644 libtdepim/komposer/core/prefsmodule.h create mode 100644 libtdepim/komposer/core/settings.kcfgc create mode 100644 libtdepim/komposer/core/tests/Makefile.am create mode 100644 libtdepim/komposer/core/tests/main.cpp create mode 100644 libtdepim/komposer/core/tests/managertest.cpp create mode 100644 libtdepim/komposer/core/tests/managertest.h create mode 100644 libtdepim/komposer/core/tests/tester.cpp create mode 100644 libtdepim/komposer/core/tests/tester.h create mode 100644 libtdepim/komposer/core/tests/testfactory.h create mode 100644 libtdepim/komposer/core/tests/testkomposer.cpp create mode 100644 libtdepim/komposer/core/tests/testmanager.cpp create mode 100644 libtdepim/komposer/core/tests/testmanager.h create mode 100644 libtdepim/komposer/plugins/Makefile.am create mode 100644 libtdepim/komposer/plugins/default/Makefile.am create mode 100644 libtdepim/komposer/plugins/default/defaulteditor.cpp create mode 100644 libtdepim/komposer/plugins/default/defaulteditor.desktop create mode 100644 libtdepim/komposer/plugins/default/defaulteditor.h create mode 100644 libtdepim/komposer/plugins/default/defaulteditorui.rc create mode 100644 libtdepim/komposer/test/Makefile.am create mode 100644 libtdepim/komposer/test/test.cpp create mode 100644 libtdepim/kpartsdesignerplugin/CMakeLists.txt create mode 100644 libtdepim/kpartsdesignerplugin/Makefile.am create mode 100644 libtdepim/kpartsdesignerplugin/README create mode 100644 libtdepim/kpartsdesignerplugin/kpartsdesignerplugin.cpp create mode 100644 libtdepim/kpartsdesignerplugin/kpartsdesignerplugin.h create mode 100644 libtdepim/kpimprefs.cpp create mode 100644 libtdepim/kpimprefs.h create mode 100644 libtdepim/kpimurlrequesterdlg.cpp create mode 100644 libtdepim/kpimurlrequesterdlg.h create mode 100644 libtdepim/kpixmapregionselectordialog.cpp create mode 100644 libtdepim/kpixmapregionselectordialog.h create mode 100644 libtdepim/kpixmapregionselectorwidget.cpp create mode 100644 libtdepim/kpixmapregionselectorwidget.h create mode 100644 libtdepim/kprefsdialog.cpp create mode 100644 libtdepim/kprefsdialog.h create mode 100644 libtdepim/kregexp3.cpp create mode 100644 libtdepim/kregexp3.h create mode 100644 libtdepim/kresourceprefs.cpp create mode 100644 libtdepim/kresourceprefs.h create mode 100644 libtdepim/krsqueezedtextlabel.cpp create mode 100644 libtdepim/krsqueezedtextlabel.h create mode 100644 libtdepim/kscoring.cpp create mode 100644 libtdepim/kscoring.h create mode 100644 libtdepim/kscoringeditor.cpp create mode 100644 libtdepim/kscoringeditor.h create mode 100644 libtdepim/ksubscription.cpp create mode 100644 libtdepim/ksubscription.h create mode 100644 libtdepim/ktimeedit.cpp create mode 100644 libtdepim/ktimeedit.h create mode 100644 libtdepim/kvcarddrag.cpp create mode 100644 libtdepim/kvcarddrag.h create mode 100644 libtdepim/kwidgetlister.cpp create mode 100644 libtdepim/kwidgetlister.h create mode 100644 libtdepim/kxface.cpp create mode 100644 libtdepim/kxface.h create mode 100644 libtdepim/ldapclient.cpp create mode 100644 libtdepim/ldapclient.h create mode 100644 libtdepim/ldapsearchdialog.cpp create mode 100644 libtdepim/ldapsearchdialog.h create mode 100644 libtdepim/linklocator.cpp create mode 100644 libtdepim/linklocator.h create mode 100644 libtdepim/maillistdrag.cpp create mode 100644 libtdepim/maillistdrag.h create mode 100644 libtdepim/overlaywidget.cpp create mode 100644 libtdepim/overlaywidget.h create mode 100644 libtdepim/pics/CMakeLists.txt create mode 100644 libtdepim/pics/Makefile.am create mode 100644 libtdepim/pics/addresseelineedit.png create mode 100644 libtdepim/pics/clicklineedit.png create mode 100644 libtdepim/pics/kdateedit.png create mode 100644 libtdepim/pics/ktimeedit.png create mode 100644 libtdepim/pimemoticons.kcfg create mode 100644 libtdepim/pimemoticons.kcfgc create mode 100644 libtdepim/pluginloader.h create mode 100644 libtdepim/pluginloaderbase.cpp create mode 100644 libtdepim/pluginloaderbase.h create mode 100644 libtdepim/progressdialog.cpp create mode 100644 libtdepim/progressdialog.h create mode 100644 libtdepim/progressmanager.cpp create mode 100644 libtdepim/progressmanager.h create mode 100644 libtdepim/qutf7codec.cpp create mode 100644 libtdepim/qutf7codec.h create mode 100644 libtdepim/qutf7codecplugin.cpp create mode 100644 libtdepim/recentaddresses.cpp create mode 100644 libtdepim/recentaddresses.h create mode 100644 libtdepim/resourceabc.cpp create mode 100644 libtdepim/resourceabc.h create mode 100644 libtdepim/sendsmsdialog.cpp create mode 100644 libtdepim/sendsmsdialog.h create mode 100644 libtdepim/sidebarextension.cpp create mode 100644 libtdepim/sidebarextension.h create mode 100644 libtdepim/spellingfilter.cpp create mode 100644 libtdepim/spellingfilter.h create mode 100644 libtdepim/ssllabel.cpp create mode 100644 libtdepim/ssllabel.h create mode 100644 libtdepim/statusbarprogresswidget.cpp create mode 100644 libtdepim/statusbarprogresswidget.h create mode 100644 libtdepim/tdepim.widgets create mode 100644 libtdepim/tdepimmacros.h create mode 100644 libtdepim/tdepimprotocols.h create mode 100644 libtdepim/tests/Makefile.am create mode 100644 libtdepim/tests/myconfig.kcfgc create mode 100644 libtdepim/tests/propagator_test.kcfg create mode 100644 libtdepim/tests/test_kregexp.cpp create mode 100644 libtdepim/tests/testaddresseelineedit.cpp create mode 100644 libtdepim/tests/testaddresseeselector.cpp create mode 100644 libtdepim/tests/testdateedit.cpp create mode 100644 libtdepim/tests/testdateedit.h create mode 100644 libtdepim/tests/testdistrlist.cpp create mode 100644 libtdepim/tests/testdistrlist.h create mode 100644 libtdepim/tests/testkincidencechooser.cpp create mode 100644 libtdepim/tests/testlinklocator.cpp create mode 100644 libtdepim/tests/testutf7decoder.cpp create mode 100644 libtdepim/tests/testutf7encoder.cpp create mode 100644 libtdepim/tests/testutf7encoder2.cpp create mode 100644 libtdepim/tests/testwizard.cpp create mode 100644 libtdepim/weaver.cpp create mode 100644 libtdepim/weaver.h create mode 100644 libtdepim/weaverextensions.cpp create mode 100644 libtdepim/weaverextensions.h create mode 100644 libtdepim/weaverlogger.cpp create mode 100644 libtdepim/weaverlogger.h create mode 100644 tdepim.lsm diff --git a/kdepim.lsm b/kdepim.lsm deleted file mode 100644 index 22a6aba6c..000000000 --- a/kdepim.lsm +++ /dev/null @@ -1,12 +0,0 @@ -Begin4 -Title: tdepim -Version: 3.5.10 -Entered-date: 2008-08-26 -Description: PIM (Personal Information Management) programs - for the K Desktop Environment (KDE) -Keywords: KDE X11 desktop Qt -Author: http://bugs.kde.org/ (KDE Bugtracking System) -Primary-site: http://www.kde.org/download/ -Platforms: Unix, Qt -Copying-policy: GPL, Artistic -End diff --git a/libkdepim/CMakeLists.txt b/libkdepim/CMakeLists.txt deleted file mode 100644 index 19ca1d524..000000000 --- a/libkdepim/CMakeLists.txt +++ /dev/null @@ -1,108 +0,0 @@ -################################################# -# -# (C) 2010-2011 Serghei Amelian -# serghei (DOT) amelian (AT) gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# - -project( libtdepim ) - -include( ConfigureChecks.cmake ) - -tde_import( libkmime ) -tde_import( libkcal ) -tde_import( ktnef ) - -add_subdirectory( icons ) -add_subdirectory( pics ) -add_subdirectory( kpartsdesignerplugin ) -add_subdirectory( about ) - -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/libtdepim - ${TDE_INCLUDE_DIR} - ${TQT_INCLUDE_DIRS} -) - -link_directories( - ${TQT_LIBRARY_DIRS} -) - - -##### headers ################################### - -install( FILES - tdepimmacros.h kpimprefs.h - DESTINATION ${INCLUDE_INSTALL_DIR}/kde ) - - -##### other data ################################ - -install( FILES pimemoticons.kcfg DESTINATION ${KCFG_INSTALL_DIR} ) - - -##### tdepimwidgets (module) #################### - -add_custom_command( OUTPUT tdepimwidgets.cpp - COMMAND - ${KDE3_MAKEKDEWIDGETS_EXECUTABLE} - -o tdepimwidgets.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/tdepim.widgets - DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/tdepim.widgets ) - -set_source_files_properties( tdepimwidgets.cpp PROPERTIES COMPILE_FLAGS "-DQT_PLUGIN" ) - -tde_add_kpart( tdepimwidgets - SOURCES tdepimwidgets.cpp - LINK tdepim-shared - DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/designer -) - - -##### tdepim (shared) ########################### - -set( KDE3_DCOPIDL_EXECUTABLE ${KDE3_DCOPIDLNG_EXECUTABLE} ) - -tde_add_library( tdepim SHARED AUTOMOC - SOURCES - ktimeedit.cpp alarmclient.cpp kprefsdialog.cpp kpimprefs.cpp - categoryselectdialog_base.ui categoryselectdialog.cpp - categoryeditdialog_base.ui categoryeditdialog.cpp kdateedit.cpp - kimportdialog.cpp kvcarddrag.cpp sidebarextension.cpp - infoextension.cpp addressesdialog.cpp addresspicker.ui - addresseeview.cpp maillistdrag.cpp interfaces/MailTransportServiceIface.skel - interfaces/AddressBookServiceIface.skel kconfigpropagator.cpp kconfigwizard.cpp - weaver.cpp weaverextensions.cpp weaverlogger.cpp pluginloaderbase.cpp - addresseelineedit.cpp addresseelineedit.skel kdatepickerpopup.cpp - kfileio.cpp clicklineedit.cpp configmanager.cpp collectingprocess.cpp - ldapclient.cpp overlaywidget.cpp progressmanager.cpp progressdialog.cpp - statusbarprogresswidget.cpp ssllabel.cpp completionordereditor.cpp - resourceabc.cpp diffalgo.cpp addresseediffalgo.cpp calendardiffalgo.cpp - htmldiffalgodisplay.cpp ldapsearchdialog.cpp broadcaststatus.cpp - kresourceprefs.cpp kpixmapregionselectorwidget.cpp - kpixmapregionselectordialog.cpp kabcresourcecached.cpp - kxface.cpp kaccount.cpp kaddrbook.cpp kfoldertree.cpp kregexp3.cpp - kscoring.cpp kscoringeditor.cpp ksubscription.cpp kwidgetlister.cpp - linklocator.cpp qutf7codec.cpp recentaddresses.cpp spellingfilter.cpp - addresseeselector.cpp addresseeemailselection.cpp designerfields.cpp - kcmdesignerfields.cpp embeddedurlpage.cpp kincidencechooser.cpp - groupwarejob.cpp pimemoticons.kcfgc krsqueezedtextlabel.cpp - csshelper.cpp distributionlist.cpp kpimurlrequesterdlg.cpp - sendsmsdialog.cpp kmailcompletion.cpp - VERSION 1.0.0 - LINK kcal-shared kimproxy-shared kparts-shared qui - DESTINATION ${LIB_INSTALL_DIR} -) - - -##### install import cmake modules ############### - -tde_install_export( ) diff --git a/libkdepim/ConfigureChecks.cmake b/libkdepim/ConfigureChecks.cmake deleted file mode 100644 index 96e1e621a..000000000 --- a/libkdepim/ConfigureChecks.cmake +++ /dev/null @@ -1,10 +0,0 @@ -################################################# -# -# (C) 2010-2011 Serghei Amelian -# serghei (DOT) amelian (AT) gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# diff --git a/libkdepim/Makefile.am b/libkdepim/Makefile.am deleted file mode 100644 index b5db77f6f..000000000 --- a/libkdepim/Makefile.am +++ /dev/null @@ -1,71 +0,0 @@ -SUBDIRS = cfgc interfaces tests icons pics kpartsdesignerplugin about - -INCLUDES = -I$(top_srcdir) $(all_includes) - -lib_LTLIBRARIES = libtdepim.la -libtdepim_la_SOURCES = \ - ktimeedit.cpp \ - alarmclient.cpp \ - kprefsdialog.cpp kpimprefs.cpp \ - categoryselectdialog_base.ui categoryselectdialog.cpp \ - categoryeditdialog_base.ui categoryeditdialog.cpp \ - kdateedit.cpp kimportdialog.cpp kvcarddrag.cpp \ - sidebarextension.cpp infoextension.cpp \ - addressesdialog.cpp addresspicker.ui addresseeview.cpp \ - maillistdrag.cpp MailTransportServiceIface.skel \ - AddressBookServiceIface.skel \ - kconfigpropagator.cpp kconfigwizard.cpp \ - weaver.cpp weaverextensions.cpp weaverlogger.cpp \ - pluginloaderbase.cpp addresseelineedit.cpp addresseelineedit.skel \ - kdatepickerpopup.cpp kfileio.cpp \ - clicklineedit.cpp configmanager.cpp \ - collectingprocess.cpp ldapclient.cpp \ - overlaywidget.cpp progressmanager.cpp progressdialog.cpp \ - statusbarprogresswidget.cpp ssllabel.cpp completionordereditor.cpp \ - resourceabc.cpp diffalgo.cpp addresseediffalgo.cpp calendardiffalgo.cpp \ - htmldiffalgodisplay.cpp ldapsearchdialog.cpp broadcaststatus.cpp kresourceprefs.cpp \ - kpixmapregionselectorwidget.cpp kpixmapregionselectordialog.cpp \ - kabcresourcecached.cpp kxface.cpp \ - kaccount.cpp kaddrbook.cpp kfoldertree.cpp kregexp3.cpp \ - kscoring.cpp kscoringeditor.cpp ksubscription.cpp kwidgetlister.cpp \ - linklocator.cpp qutf7codec.cpp \ - recentaddresses.cpp spellingfilter.cpp \ - addresseeselector.cpp addresseeemailselection.cpp \ - designerfields.cpp kcmdesignerfields.cpp \ - embeddedurlpage.cpp kincidencechooser.cpp \ - groupwarejob.cpp pimemoticons.kcfgc \ - krsqueezedtextlabel.cpp csshelper.cpp distributionlist.cpp \ - kpimurlrequesterdlg.cpp sendsmsdialog.cpp kmailcompletion.cpp - -MailTransportServiceIface_DCOPIDLNG = true -MailTransportServiceIface_DIR = $(srcdir)/interfaces - -AddressBookServiceIface_DIR = $(srcdir)/interfaces - -libtdepim_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 1:0:0 $(LIB_QT) -ltdecore -libtdepim_la_LIBADD = $(top_builddir)/libkcal/libkcal.la \ - $(top_builddir)/libemailfunctions/libemailfunctions.la \ - $(LIB_KIO) $(LIB_KABC) $(LIB_KPARTS) $(LIB_KIMPROXY) $(LIB_POLL) -lqui -# $top_builddir)/libtdepim/resources/libkpimresources.la - -include_HEADERS = tdepimmacros.h kpimprefs.h - -AM_CXXFLAGS = -DQT_PLUGIN -kde_widget_LTLIBRARIES = tdepimwidgets.la -tdepimwidgets_la_LDFLAGS = $(KDE_PLUGIN) -module $(all_libraries) $(LIB_QT) -ltdecore -tdepimwidgets_la_LIBADD = $(LIB_KIO) libtdepim.la -tdepimwidgets_la_SOURCES = tdepimwidgets.cpp - -tdepimwidgets.cpp: $(srcdir)/tdepim.widgets - $(MAKEKDEWIDGETS) -o tdepimwidgets.cpp $(srcdir)/tdepim.widgets - -CLEANFILES = tdepimwidgets.cpp - -kde_kcfg_DATA = pimemoticons.kcfg - -METASOURCES = AUTO - -messages: rc.cpp - $(XGETTEXT) ../libkpimidentities/*.cpp ../libemailfunctions/*.cpp *.cpp -o $(podir)/libtdepim.pot - -include $(top_srcdir)/admin/Doxyfile.am diff --git a/libkdepim/README b/libkdepim/README deleted file mode 100644 index dfaefe79f..000000000 --- a/libkdepim/README +++ /dev/null @@ -1,36 +0,0 @@ -This directory contains the library for the kdenetwork package. - -Contents: - ksieve_* The beginning of a Sieve parser and interpreter - library. - Maintainer: Marc Mutz - License: GPL v2 - - kscoring/ scoring engine & rule editor - kscoringeditor Maintainer: Mathias Waack - License: GPL - - qutf7codec A QTextCodec for UTF-7. - Will hopefully be assimilated by the trolls. - Maintainer: Marc Mutz - License: GPL v2 - - kwidgetlister a small and nice widget which enables one to dynamically - add or delete widgets. Used by the filter and scoring - dialogs, which needs to display for instance a variable - number of conditions. - Maintainer: Marc Mutz - License: GPL v2 - - kregexp3 A KRegExp replacement based on QRegExp from Qt3.x - Maintainer: Marc Mutz - License: GPL - - kfoldertree/ Base classes for KNode's and KMail's folder lists, - ksubscription/ subscription dialogs and accounts. - kaccount Maintainer: Carsten Burghardt - License: LGPL v2 - - cryptplugwrapper* C++ wrapper around the CryptPlug interface. - Maintainer: Karl-Heinz Zimmer - License: GPL v2 diff --git a/libkdepim/TODO b/libkdepim/TODO deleted file mode 100644 index f6c5214c3..000000000 --- a/libkdepim/TODO +++ /dev/null @@ -1,10 +0,0 @@ -KConfigPropagator: - -- Title for all changes. -- Write DTD for extended kcfg file. -- Check validity of rules against the installed kcfg files. -- Turn public members of Change, Rule, Condition into proper accessors/mutators - -KConfigWizard: - -- More pretty changes view. diff --git a/libkdepim/about/CMakeLists.txt b/libkdepim/about/CMakeLists.txt deleted file mode 100644 index 97a53d764..000000000 --- a/libkdepim/about/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -################################################# -# -# (C) 2010-2011 Serghei Amelian -# serghei (DOT) amelian (AT) gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# - -install( FILES - bar-bottom-left.png bar-top-right.png bar-bottom-middle.png bottom-left.png - box-middle-left.png top-left.png bar-bottom-right.png bottom-middle.png - box-middle-right.png top-middle.png bar-middle-left.png bottom-right.png - box-top-left.png bar-middle-right.png box-bottom-left.png box-top-middle.png - bar-top-left.png box-bottom-middle.png box-top-right.png bar-top-middle.png - box-bottom-right.png kde_infopage.css kde_infopage_rtl.css - DESTINATION ${DATA_INSTALL_DIR}/libtdepim/about ) diff --git a/libkdepim/about/Makefile.am b/libkdepim/about/Makefile.am deleted file mode 100644 index 6481c5bcb..000000000 --- a/libkdepim/about/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ - -tdepim_infopage_datadir = $(kde_datadir)/libtdepim/about -tdepim_infopage_data_DATA = \ - bar-bottom-left.png bar-top-right.png bar-bottom-middle.png bottom-left.png \ - box-middle-left.png top-left.png bar-bottom-right.png bottom-middle.png \ - box-middle-right.png top-middle.png bar-middle-left.png bottom-right.png \ - box-top-left.png bar-middle-right.png box-bottom-left.png box-top-middle.png \ - bar-top-left.png box-bottom-middle.png box-top-right.png bar-top-middle.png \ - box-bottom-right.png kde_infopage.css kde_infopage_rtl.css diff --git a/libkdepim/about/bar-bottom-left.png b/libkdepim/about/bar-bottom-left.png deleted file mode 100644 index 30a323592..000000000 Binary files a/libkdepim/about/bar-bottom-left.png and /dev/null differ diff --git a/libkdepim/about/bar-bottom-middle.png b/libkdepim/about/bar-bottom-middle.png deleted file mode 100644 index b2ebbbed5..000000000 Binary files a/libkdepim/about/bar-bottom-middle.png and /dev/null differ diff --git a/libkdepim/about/bar-bottom-right.png b/libkdepim/about/bar-bottom-right.png deleted file mode 100644 index e664e1511..000000000 Binary files a/libkdepim/about/bar-bottom-right.png and /dev/null differ diff --git a/libkdepim/about/bar-middle-left.png b/libkdepim/about/bar-middle-left.png deleted file mode 100644 index 72fda9ec2..000000000 Binary files a/libkdepim/about/bar-middle-left.png and /dev/null differ diff --git a/libkdepim/about/bar-middle-right.png b/libkdepim/about/bar-middle-right.png deleted file mode 100644 index d482ab178..000000000 Binary files a/libkdepim/about/bar-middle-right.png and /dev/null differ diff --git a/libkdepim/about/bar-top-left.png b/libkdepim/about/bar-top-left.png deleted file mode 100644 index b05fd216c..000000000 Binary files a/libkdepim/about/bar-top-left.png and /dev/null differ diff --git a/libkdepim/about/bar-top-middle.png b/libkdepim/about/bar-top-middle.png deleted file mode 100644 index 387f81017..000000000 Binary files a/libkdepim/about/bar-top-middle.png and /dev/null differ diff --git a/libkdepim/about/bar-top-right.png b/libkdepim/about/bar-top-right.png deleted file mode 100644 index a552ff91d..000000000 Binary files a/libkdepim/about/bar-top-right.png and /dev/null differ diff --git a/libkdepim/about/bottom-left.png b/libkdepim/about/bottom-left.png deleted file mode 100644 index 78c9fece3..000000000 Binary files a/libkdepim/about/bottom-left.png and /dev/null differ diff --git a/libkdepim/about/bottom-middle.png b/libkdepim/about/bottom-middle.png deleted file mode 100644 index 41e52dd8a..000000000 Binary files a/libkdepim/about/bottom-middle.png and /dev/null differ diff --git a/libkdepim/about/bottom-right.png b/libkdepim/about/bottom-right.png deleted file mode 100644 index ef81b04a8..000000000 Binary files a/libkdepim/about/bottom-right.png and /dev/null differ diff --git a/libkdepim/about/box-bottom-left.png b/libkdepim/about/box-bottom-left.png deleted file mode 100644 index ef68ffa6a..000000000 Binary files a/libkdepim/about/box-bottom-left.png and /dev/null differ diff --git a/libkdepim/about/box-bottom-middle.png b/libkdepim/about/box-bottom-middle.png deleted file mode 100644 index 2bcd3ea03..000000000 Binary files a/libkdepim/about/box-bottom-middle.png and /dev/null differ diff --git a/libkdepim/about/box-bottom-right.png b/libkdepim/about/box-bottom-right.png deleted file mode 100644 index 993e1a6b0..000000000 Binary files a/libkdepim/about/box-bottom-right.png and /dev/null differ diff --git a/libkdepim/about/box-middle-left.png b/libkdepim/about/box-middle-left.png deleted file mode 100644 index 62a720178..000000000 Binary files a/libkdepim/about/box-middle-left.png and /dev/null differ diff --git a/libkdepim/about/box-middle-right.png b/libkdepim/about/box-middle-right.png deleted file mode 100644 index aa94c0c90..000000000 Binary files a/libkdepim/about/box-middle-right.png and /dev/null differ diff --git a/libkdepim/about/box-top-left.png b/libkdepim/about/box-top-left.png deleted file mode 100644 index 3825a7de4..000000000 Binary files a/libkdepim/about/box-top-left.png and /dev/null differ diff --git a/libkdepim/about/box-top-middle.png b/libkdepim/about/box-top-middle.png deleted file mode 100644 index 79e714cba..000000000 Binary files a/libkdepim/about/box-top-middle.png and /dev/null differ diff --git a/libkdepim/about/box-top-right.png b/libkdepim/about/box-top-right.png deleted file mode 100644 index 45ba201ea..000000000 Binary files a/libkdepim/about/box-top-right.png and /dev/null differ diff --git a/libkdepim/about/kde_infopage.css b/libkdepim/about/kde_infopage.css deleted file mode 100644 index 69085675e..000000000 --- a/libkdepim/about/kde_infopage.css +++ /dev/null @@ -1,239 +0,0 @@ - -/* - * text styles - */ - -img {margin: 0px; padding: 0px} -body {margin: 0px; padding: 0px; background-color: #418ade;} -.bar_text a {color: #008;} - -#subtext { - font-size: 10pt; - font-style: italic; -} - -#nextlink { - margin-bottom: 0px; - text-align: right; - font-size: 10pt; -} - -/* - * the header - */ - -#header { - background-image: url(top-middle.png); - width: 100%; - height: 131px; -} - -#headerL { - position: absolute; - background-image: url(top-left.png); - left: 0px; - height: 131px; - width: 147px; - z-index: 1; -} - -#headerR { - position: absolute; - right: 0px; -} - -/* title and tagline are part of the header diff */ -#title { - position: absolute; - top: 63px; - right: 100px; - margin-top: -1em; - text-align: right; - font-size: xx-large; - font-weight: bold; - text-shadow: #fff 0px 0px 5px; - color: #444; - z-index: 5; -} - -#tagline { - position: absolute; - top: 70px; - right: 100px; - text-align: right; - font-size: large; - font-weight: bold; - text-shadow: #fff 0px 0px 5px; - color: #444; - z-index: 5; -} - -/* - * the nav bar - */ - -#bar { - width: 100%; - background-color: #5babe5; - padding-top: 0.5ex; - border-bottom: 1px solid black; - padding-bottom: 0.5ex; -} - -#barCenter { - text-align: center; - color: #282828; - font-weight: bold; - font-size: small; -} - -#barCenter a.selected, #barCenter a.selected:hover { - color: #282828; - text-decoration: none; - text-shadow: #fff 0px 0px 5px; -} - - -#barCenter li a:link, #barCenter li a:visited, #barCenter li a:active { - color: #282828; - text-decoration: none; - text-shadow: none; -} - -#barCenter li a:hover { - color: #282828; - text-decoration: none; - text-shadow: #fff 0px 0px 6px; -} - -#barCenter ul { - margin: 0; - padding: 0; -} - -#barCenter li { - display: inline; -} - -#barCenter li:not(:first-child):before { /* Aren't css3 selectors great? */ - content: " · "; -} - -/* - * the main box - */ - -#box { - width: 90%; - margin-left: 5%; - margin-right: 5%; - margin-top: 10px; - margin-bottom: 10px; -} - -#boxT { - width: 100%; - height: 22px; -} - -#boxTL { - width: 25px; - height: 22px; - float: left; - background-image: url(box-top-left.png); -} - -#boxTR { - width: 25px; - height: 22px; - float: right; - background-image: url(box-top-right.png); -} - -#boxTC { - height: 22px; - margin-left: 25px; - margin-right: 25px; - background-image: url(box-top-middle.png); - background-repeat: repeat-x; -} - -#boxL { - background-image: url(box-middle-left.png); - background-repeat: repeat-y; - background-position: left; - padding-left: 20px; -} - -#boxCenter { - background-color: #dfe7f3; - background-position: center; - text-align: left; -} - -#boxR { - background-image: url(box-middle-right.png); - background-repeat: repeat-y; - background-position: right; - padding-right: 20px; -} - -#boxB { - width: 100%; - height: 22px; -} - -#boxBL { - width: 25px; - height: 22px; - float: left; - background-image: url(box-bottom-left.png); -} - -#boxBR { - width: 25px; - height: 22px; - float: right; - background-image: url(box-bottom-right.png); -} - -#boxBC { - height: 22px; - margin-left: 25px; - margin-right: 25px; - background-image: url(box-bottom-middle.png); - background-repeat: repeat-x; -} - -/* - * the footer - */ - -#footer { - position: fixed; - background-image: url(bottom-middle.png); - width: 100%; - height: 100px; - z-index: -2; - bottom:0; -} - -#footerL { - position: fixed; - background-image: url(bottom-left.png); - left: 0px; - width: 155px; - height: 100px; - z-index: -2; -} - -#footerR { - position: fixed; - background-image: url(bottom-right.png); - right: 0px; - width: 429px; - height: 100px; - z-index: -1; -} - -/* vim:set sw=2 et nocindent smartindent: */ diff --git a/libkdepim/about/kde_infopage_rtl.css b/libkdepim/about/kde_infopage_rtl.css deleted file mode 100644 index 003330196..000000000 --- a/libkdepim/about/kde_infopage_rtl.css +++ /dev/null @@ -1,11 +0,0 @@ -body {direction: rtl} - -#boxCenter { - text-align: right; -} - -#nextlink { - text-align: left; -} - -/* vim:set sw=2 et nocindent smartindent: */ diff --git a/libkdepim/about/top-left.png b/libkdepim/about/top-left.png deleted file mode 100644 index d7551c0d5..000000000 Binary files a/libkdepim/about/top-left.png and /dev/null differ diff --git a/libkdepim/about/top-middle.png b/libkdepim/about/top-middle.png deleted file mode 100644 index bb3fe7428..000000000 Binary files a/libkdepim/about/top-middle.png and /dev/null differ diff --git a/libkdepim/addresseediffalgo.cpp b/libkdepim/addresseediffalgo.cpp deleted file mode 100644 index d36b7ac94..000000000 --- a/libkdepim/addresseediffalgo.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "addresseediffalgo.h" - -using namespace KPIM; - -static bool compareString( const TQString &left, const TQString &right ) -{ - if ( left.isEmpty() && right.isEmpty() ) - return true; - else - return left == right; -} - -AddresseeDiffAlgo::AddresseeDiffAlgo( const KABC::Addressee &leftAddressee, - const KABC::Addressee &rightAddressee ) - : mLeftAddressee( leftAddressee ), mRightAddressee( rightAddressee ) -{ -} - -void AddresseeDiffAlgo::run() -{ - begin(); - - if ( !compareString( mLeftAddressee.uid(), mRightAddressee.uid() ) ) - conflictField( KABC::Addressee::uidLabel(), mLeftAddressee.uid(), mRightAddressee.uid() ); - - if ( !compareString( mLeftAddressee.name(), mRightAddressee.name() ) ) - conflictField( KABC::Addressee::nameLabel(), mLeftAddressee.name(), mRightAddressee.name() ); - - if ( !compareString( mLeftAddressee.formattedName(), mRightAddressee.formattedName() ) ) - conflictField( KABC::Addressee::formattedNameLabel(), mLeftAddressee.formattedName(), mRightAddressee.formattedName() ); - - if ( !compareString( mLeftAddressee.familyName(), mRightAddressee.familyName() ) ) - conflictField( KABC::Addressee::familyNameLabel(), mLeftAddressee.familyName(), mRightAddressee.familyName() ); - - if ( !compareString( mLeftAddressee.givenName(), mRightAddressee.givenName() ) ) - conflictField( KABC::Addressee::givenNameLabel(), mLeftAddressee.givenName(), mRightAddressee.givenName() ); - - if ( !compareString( mLeftAddressee.additionalName(), mRightAddressee.additionalName() ) ) - conflictField( KABC::Addressee::additionalNameLabel(), mLeftAddressee.additionalName(), mRightAddressee.additionalName() ); - - if ( !compareString( mLeftAddressee.prefix(), mRightAddressee.prefix() ) ) - conflictField( KABC::Addressee::prefixLabel(), mLeftAddressee.prefix(), mRightAddressee.prefix() ); - - if ( !compareString( mLeftAddressee.suffix(), mRightAddressee.suffix() ) ) - conflictField( KABC::Addressee::suffixLabel(), mLeftAddressee.suffix(), mRightAddressee.suffix() ); - - if ( !compareString( mLeftAddressee.nickName(), mRightAddressee.nickName() ) ) - conflictField( KABC::Addressee::nickNameLabel(), mLeftAddressee.nickName(), mRightAddressee.nickName() ); - - if ( mLeftAddressee.birthday() != mRightAddressee.birthday() ) - conflictField( KABC::Addressee::birthdayLabel(), mLeftAddressee.birthday().toString(), - mRightAddressee.birthday().toString() ); - - if ( !compareString( mLeftAddressee.mailer(), mRightAddressee.mailer() ) ) - conflictField( KABC::Addressee::mailerLabel(), mLeftAddressee.mailer(), mRightAddressee.mailer() ); - - if ( mLeftAddressee.timeZone() != mRightAddressee.timeZone() ) - conflictField( KABC::Addressee::timeZoneLabel(), mLeftAddressee.timeZone().asString(), mRightAddressee.timeZone().asString() ); - - if ( mLeftAddressee.geo() != mRightAddressee.geo() ) - conflictField( KABC::Addressee::geoLabel(), mLeftAddressee.geo().asString(), mRightAddressee.geo().asString() ); - - if ( !compareString( mLeftAddressee.title(), mRightAddressee.title() ) ) - conflictField( KABC::Addressee::titleLabel(), mLeftAddressee.title(), mRightAddressee.title() ); - - if ( !compareString( mLeftAddressee.role(), mRightAddressee.role() ) ) - conflictField( KABC::Addressee::roleLabel(), mLeftAddressee.role(), mRightAddressee.role() ); - - if ( !compareString( mLeftAddressee.organization(), mRightAddressee.organization() ) ) - conflictField( KABC::Addressee::organizationLabel(), mLeftAddressee.organization(), mRightAddressee.organization() ); - - if ( !compareString( mLeftAddressee.note(), mRightAddressee.note() ) ) - conflictField( KABC::Addressee::noteLabel(), mLeftAddressee.note(), mRightAddressee.note() ); - - if ( !compareString( mLeftAddressee.productId(), mRightAddressee.productId() ) ) - conflictField( KABC::Addressee::productIdLabel(), mLeftAddressee.productId(), mRightAddressee.productId() ); - - if ( !compareString( mLeftAddressee.sortString(), mRightAddressee.sortString() ) ) - conflictField( KABC::Addressee::sortStringLabel(), mLeftAddressee.sortString(), mRightAddressee.sortString() ); - - if ( mLeftAddressee.secrecy() != mRightAddressee.secrecy() ) { - conflictField( KABC::Addressee::secrecyLabel(), mLeftAddressee.secrecy().asString(), mRightAddressee.secrecy().asString() ); - } - if ( mLeftAddressee.url()!= mRightAddressee.url() ) - conflictField( KABC::Addressee::urlLabel(), mLeftAddressee.url().prettyURL(), - mRightAddressee.url().prettyURL() ); - - if ( mLeftAddressee.logo() != mRightAddressee.logo() ) { - } - - if ( mLeftAddressee.photo() != mRightAddressee.photo() ) { - } - - diffList( "emails", mLeftAddressee.emails(), mRightAddressee.emails() ); - - diffList( "Phone Numbers", mLeftAddressee.phoneNumbers(), mRightAddressee.phoneNumbers() ); - diffList( "Addresses", mLeftAddressee.addresses(), mRightAddressee.addresses() ); - - end(); -} - -TQString AddresseeDiffAlgo::toString( const KABC::PhoneNumber &number ) -{ - return number.number(); -} - -TQString AddresseeDiffAlgo::toString( const KABC::Address &addr ) -{ - return addr.formattedAddress(); -} - -template -void AddresseeDiffAlgo::diffList( const TQString &id, - const TQValueList &left, const TQValueList &right ) -{ - for ( uint i = 0; i < left.count(); ++i ) { - if ( right.find( left[ i ] ) == right.end() ) - additionalLeftField( id, toString( left[ i ] ) ); - } - - for ( uint i = 0; i < right.count(); ++i ) { - if ( left.find( right[ i ] ) == left.end() ) - additionalRightField( id, toString( right[ i ] ) ); - } -} diff --git a/libkdepim/addresseediffalgo.h b/libkdepim/addresseediffalgo.h deleted file mode 100644 index f3c6632a7..000000000 --- a/libkdepim/addresseediffalgo.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPIM_ADDRESSEEDIFFALGO_H -#define KPIM_ADDRESSEEDIFFALGO_H - -#include -#include - -namespace KPIM { - -class KDE_EXPORT AddresseeDiffAlgo : public DiffAlgo -{ - public: - AddresseeDiffAlgo( const KABC::Addressee &leftAddressee, const KABC::Addressee &rightAddressee ); - - void run(); - - private: - template - void diffList( const TQString &id, const TQValueList &left, const TQValueList &right ); - - TQString toString( const KABC::PhoneNumber &number ); - TQString toString( const KABC::Address &address ); - - KABC::Addressee mLeftAddressee; - KABC::Addressee mRightAddressee; -}; - -} - -#endif diff --git a/libkdepim/addresseeemailselection.cpp b/libkdepim/addresseeemailselection.cpp deleted file mode 100644 index dde8f7dd4..000000000 --- a/libkdepim/addresseeemailselection.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include "recentaddresses.h" - -#include "addresseeemailselection.h" - -using namespace KPIM; -using KRecentAddress::RecentAddresses; - -AddresseeEmailSelection::AddresseeEmailSelection() - : Selection() -{ -} - -uint AddresseeEmailSelection::fieldCount() const -{ - return 3; -} - -TQString AddresseeEmailSelection::fieldTitle( uint index ) const -{ - switch ( index ) { - case 0: - return i18n( "To" ); - break; - case 1: - return i18n( "Cc" ); - break; - case 2: - return i18n( "Bcc" ); - break; - default: - return TQString(); - } -} - -TQStringList AddresseeEmailSelection::to() const -{ - return mToEmailList; -} - -TQStringList AddresseeEmailSelection::cc() const -{ - return mCcEmailList; -} - -TQStringList AddresseeEmailSelection::bcc() const -{ - return mBccEmailList; -} - -KABC::Addressee::List AddresseeEmailSelection::toAddresses() const -{ - return mToAddresseeList; -} - -KABC::Addressee::List AddresseeEmailSelection::ccAddresses() const -{ - return mCcAddresseeList; -} - -KABC::Addressee::List AddresseeEmailSelection::bccAddresses() const -{ - return mBccAddresseeList; -} - -TQStringList AddresseeEmailSelection::toDistributionLists() const -{ - return mToDistributionList; -} - -TQStringList AddresseeEmailSelection::ccDistributionLists() const -{ - return mCcDistributionList; -} - -TQStringList AddresseeEmailSelection::bccDistributionLists() const -{ - return mBccDistributionList; -} - -void AddresseeEmailSelection::setSelectedTo( const TQStringList &emails ) -{ - setSelectedItem( 0, emails ); -} - -void AddresseeEmailSelection::setSelectedCC( const TQStringList &emails ) -{ - setSelectedItem( 1, emails ); -} - -void AddresseeEmailSelection::setSelectedBCC( const TQStringList &emails ) -{ - setSelectedItem( 2, emails ); -} - - -uint AddresseeEmailSelection::itemCount( const KABC::Addressee &addressee ) const -{ - return addressee.emails().count(); -} - -TQString AddresseeEmailSelection::itemText( const KABC::Addressee &addressee, uint index ) const -{ - return addressee.formattedName() + " " + email( addressee, index ); -} - -TQPixmap AddresseeEmailSelection::itemIcon( const KABC::Addressee &addressee, uint ) const -{ - if ( !addressee.photo().data().isNull() ) - return addressee.photo().data().smoothScale( 16, 16 ); - else - return KGlobal::iconLoader()->loadIcon( "personal", KIcon::Small ); -} - -bool AddresseeEmailSelection::itemEnabled( const KABC::Addressee &addressee, uint ) const -{ - return addressee.emails().count() != 0; -} - -bool AddresseeEmailSelection::itemMatches( const KABC::Addressee &addressee, uint index, const TQString &pattern ) const -{ - return addressee.formattedName().tqstartsWith( pattern, false ) || - email( addressee, index ).tqstartsWith( pattern, false ); -} - -bool AddresseeEmailSelection::itemEquals( const KABC::Addressee &addressee, uint index, const TQString &pattern ) const -{ - return (pattern == addressee.formattedName() + " " + email( addressee, index )) || - (addressee.emails().contains( pattern )); -} - -TQString AddresseeEmailSelection::distributionListText( const KABC::DistributionList *distributionList ) const -{ - return distributionList->name(); -} - -TQPixmap AddresseeEmailSelection::distributionListIcon( const KABC::DistributionList* ) const -{ - return KGlobal::iconLoader()->loadIcon( "kdmconfig", KIcon::Small ); -} - -bool AddresseeEmailSelection::distributionListEnabled( const KABC::DistributionList* ) const -{ - return true; -} - -bool AddresseeEmailSelection::distributionListMatches( const KABC::DistributionList *distributionList, - const TQString &pattern ) const -{ - // check whether the name of the distribution list matches the pattern or one of its entries. - bool ok = distributionList->name().tqstartsWith( pattern, false ); - - KABC::DistributionList::Entry::List entries = distributionList->entries(); - KABC::DistributionList::Entry::List::ConstIterator it; - for ( it = entries.begin(); it != entries.end(); ++it ) { - ok = ok || (*it).addressee.formattedName().tqstartsWith( pattern, false ) || - (*it).email.tqstartsWith( pattern, false ); - } - - return ok; -} - -uint AddresseeEmailSelection::addressBookCount() const -{ - // we provide the recent email addresses via the custom addressbooks - return 1; -} - -TQString AddresseeEmailSelection::addressBookTitle( uint index ) const -{ - if ( index == 0 ) - return i18n( "Recent Addresses" ); - else - return TQString(); -} - -KABC::Addressee::List AddresseeEmailSelection::addressBookContent( uint index ) const -{ - if ( index == 0 ) { - KConfig config( "kmailrc" ); - return RecentAddresses::self( &config )->kabcAddresses(); - } else { - return KABC::Addressee::List(); - } -} - -TQString AddresseeEmailSelection::email( const KABC::Addressee &addressee, uint index ) const -{ - return addressee.emails()[ index ]; -} - -void AddresseeEmailSelection::setSelectedItem( uint fieldIndex, const TQStringList &emails ) -{ - TQStringList::ConstIterator it; - for ( it = emails.begin(); it != emails.end(); ++it ) { - KABC::Addressee addr; - addr.insertEmail( *it, true ); - - selector()->setItemSelected( fieldIndex, addr, 0, *it ); - } -} - -void AddresseeEmailSelection::addSelectedAddressees( uint fieldIndex, const KABC::Addressee &addressee, uint itemIndex ) -{ - switch ( fieldIndex ) { - case 0: - mToAddresseeList.append( addressee ); - mToEmailList.append( email( addressee, itemIndex ) ); - break; - case 1: - mCcAddresseeList.append( addressee ); - mCcEmailList.append( email( addressee, itemIndex ) ); - break; - case 2: - mBccAddresseeList.append( addressee ); - mBccEmailList.append( email( addressee, itemIndex ) ); - break; - default: - // oops - break; - } -} - -void AddresseeEmailSelection::addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList *list ) -{ - switch ( fieldIndex ) { - case 0: - mToDistributionList.append( list->name() ); - break; - case 1: - mCcDistributionList.append( list->name() ); - break; - case 2: - mBccDistributionList.append( list->name() ); - break; - default: - // oops - break; - } -} diff --git a/libkdepim/addresseeemailselection.h b/libkdepim/addresseeemailselection.h deleted file mode 100644 index 4ecb946e3..000000000 --- a/libkdepim/addresseeemailselection.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPIM_ADDRESSEE_EMAILSELECTION_H -#define KPIM_ADDRESSEE_EMAILSELECTION_H - -#include - -namespace KPIM { - -class KDE_EXPORT AddresseeEmailSelection : public Selection -{ - public: - AddresseeEmailSelection(); - - /** - Returns the number of fields the selection offers. - */ - virtual uint fieldCount() const; - - /** - Returns the title for the field specified by index. - */ - virtual TQString fieldTitle( uint index ) const; - - /** - Returns the number of items for the given addressee. - */ - virtual uint itemCount( const KABC::Addressee &addresse ) const; - - /** - Returns the text that's used for the item specified by index. - */ - virtual TQString itemText( const KABC::Addressee &addresse, uint index ) const; - - /** - Returns the icon that's used for the item specified by index. - */ - virtual TQPixmap itemIcon( const KABC::Addressee &addresse, uint index ) const; - - /** - Returns whether the item specified by index is enabled. - */ - virtual bool itemEnabled( const KABC::Addressee &addresse, uint index ) const; - - /** - Returns whether the item specified by index matches the passed pattern. - */ - virtual bool itemMatches( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const; - - /** - Returns whether the item specified by index equals the passed pattern. - */ - virtual bool itemEquals( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const; - - /** - Returns the text that's used for the given distribution list. - */ - virtual TQString distributionListText( const KABC::DistributionList *distributionList ) const; - - /** - Returns the icon that's used for the given distribution list. - */ - virtual TQPixmap distributionListIcon( const KABC::DistributionList *distributionList ) const; - - /** - Returns whether the given distribution list is enabled. - */ - virtual bool distributionListEnabled( const KABC::DistributionList *distributionList ) const; - - /** - Returns whether the given distribution list matches the passed pattern. - */ - virtual bool distributionListMatches( const KABC::DistributionList *distributionList, - const TQString &pattern ) const; - - /** - Returns the number of additional address books. - */ - virtual uint addressBookCount() const; - - /** - Returns the title for an additional address book. - */ - virtual TQString addressBookTitle( uint index ) const; - - /** - Returns the content for an additional address book. - */ - virtual KABC::Addressee::List addressBookContent( uint index ) const; - - TQStringList to() const; - TQStringList cc() const; - TQStringList bcc() const; - - KABC::Addressee::List toAddresses() const; - KABC::Addressee::List ccAddresses() const; - KABC::Addressee::List bccAddresses() const; - - TQStringList toDistributionLists() const; - TQStringList ccDistributionLists() const; - TQStringList bccDistributionLists() const; - - void setSelectedTo( const TQStringList &emails ); - void setSelectedCC( const TQStringList &emails ); - void setSelectedBCC( const TQStringList &emails ); - - private: - virtual void addSelectedAddressees( uint fieldIndex, const KABC::Addressee&, uint itemIndex ); - virtual void addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList* ); - - TQString email( const KABC::Addressee&, uint ) const; - void setSelectedItem( uint fieldIndex, const TQStringList& ); - - KABC::Addressee::List mToAddresseeList; - KABC::Addressee::List mCcAddresseeList; - KABC::Addressee::List mBccAddresseeList; - - TQStringList mToEmailList; - TQStringList mCcEmailList; - TQStringList mBccEmailList; - - TQStringList mToDistributionList; - TQStringList mCcDistributionList; - TQStringList mBccDistributionList; -}; - -} - -#endif diff --git a/libkdepim/addresseelineedit.cpp b/libkdepim/addresseelineedit.cpp deleted file mode 100644 index 50d19e07b..000000000 --- a/libkdepim/addresseelineedit.cpp +++ /dev/null @@ -1,1285 +0,0 @@ -/* - This file is part of libtdepim. - Copyright (c) 2002 Helge Deller - 2002 Lubos Lunak - 2001,2003 Carsten Pfeiffer - 2001 Waldo Bastian - 2004 Daniel Molkentin - 2004 Karl-Heinz Zimmer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "addresseelineedit.h" - -#include "resourceabc.h" -#include "completionordereditor.h" -#include "ldapclient.h" - -#include - -#ifdef KDEPIM_NEW_DISTRLISTS -#include "distributionlist.h" -#else -#include -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace KPIM; - -KMailCompletion * AddresseeLineEdit::s_completion = 0L; -KPIM::CompletionItemsMap* AddresseeLineEdit::s_completionItemMap = 0L; -TQStringList* AddresseeLineEdit::s_completionSources = 0L; -bool AddresseeLineEdit::s_addressesDirty = false; -TQTimer* AddresseeLineEdit::s_LDAPTimer = 0L; -KPIM::LdapSearch* AddresseeLineEdit::s_LDAPSearch = 0L; -TQString* AddresseeLineEdit::s_LDAPText = 0L; -AddresseeLineEdit* AddresseeLineEdit::s_LDAPLineEdit = 0L; - -// The weights associated with the completion sources in s_completionSources. -// Both are maintained by addCompletionSource(), don't attempt to modifiy those yourself. -TQMap* s_completionSourceWeights = 0; - -// maps LDAP client indices to completion source indices -// the assumption that they are always the first n indices in s_completion -// does not hold when clients are added later on -TQMap* AddresseeLineEdit::s_ldapClientToCompletionSourceMap = 0; - -static KStaticDeleter completionDeleter; -static KStaticDeleter completionItemsDeleter; -static KStaticDeleter ldapTimerDeleter; -static KStaticDeleter ldapSearchDeleter; -static KStaticDeleter ldapTextDeleter; -static KStaticDeleter completionSourcesDeleter; -static KStaticDeleter > completionSourceWeightsDeleter; -static KStaticDeleter > ldapClientToCompletionSourceMapDeleter; - -// needs to be unique, but the actual name doesn't matter much -static TQCString newLineEditDCOPObjectName() -{ - static int s_count = 0; - TQCString name( "KPIM::AddresseeLineEdit" ); - if ( s_count++ ) { - name += '-'; - name += TQCString().setNum( s_count ); - } - return name; -} - -static const TQString s_completionItemIndentString = " "; - -static bool itemIsHeader( const TQListBoxItem* item ) -{ - return item && !item->text().startsWith( s_completionItemIndentString ); -} - - - -AddresseeLineEdit::AddresseeLineEdit( TQWidget* parent, bool useCompletion, - const char *name ) - : ClickLineEdit( parent, TQString(), name ), DCOPObject( newLineEditDCOPObjectName() ), - m_useSemiColonAsSeparator( false ), m_allowDistLists( true ) -{ - m_useCompletion = useCompletion; - m_completionInitialized = false; - m_smartPaste = false; - m_addressBookConnected = false; - m_searchExtended = false; - - init(); - - if ( m_useCompletion ) - s_addressesDirty = true; -} - -void AddresseeLineEdit::updateLDAPWeights() -{ - /* Add completion sources for all ldap server, 0 to n. Added first so - * that they map to the ldapclient::clientNumber() */ - s_LDAPSearch->updateCompletionWeights(); - TQValueList< LdapClient* > clients = s_LDAPSearch->clients(); - int clientIndex = 0; - for ( TQValueList::iterator it = clients.begin(); it != clients.end(); ++it, ++clientIndex ) { - const int sourceIndex = addCompletionSource( "LDAP server: " + (*it)->server().host(), (*it)->completionWeight() ); - s_ldapClientToCompletionSourceMap->insert( clientIndex, sourceIndex ); - } -} - -void AddresseeLineEdit::init() -{ - if ( !s_completion ) { - completionDeleter.setObject( s_completion, new KMailCompletion() ); - s_completion->setOrder( completionOrder() ); - s_completion->setIgnoreCase( true ); - - completionItemsDeleter.setObject( s_completionItemMap, new KPIM::CompletionItemsMap() ); - completionSourcesDeleter.setObject( s_completionSources, new TQStringList() ); - completionSourceWeightsDeleter.setObject( s_completionSourceWeights, new TQMap ); - ldapClientToCompletionSourceMapDeleter.setObject( s_ldapClientToCompletionSourceMap, new TQMap ); - } -// connect( s_completion, TQT_SIGNAL( match( const TQString& ) ), -// this, TQT_SLOT( slotMatched( const TQString& ) ) ); - - if ( m_useCompletion ) { - if ( !s_LDAPTimer ) { - ldapTimerDeleter.setObject( s_LDAPTimer, new TQTimer( 0, "ldapTimerDeleter" ) ); - ldapSearchDeleter.setObject( s_LDAPSearch, new KPIM::LdapSearch ); - ldapTextDeleter.setObject( s_LDAPText, new TQString ); - } - - updateLDAPWeights(); - - if ( !m_completionInitialized ) { - setCompletionObject( s_completion, false ); - connect( this, TQT_SIGNAL( completion( const TQString& ) ), - this, TQT_SLOT( slotCompletion() ) ); - connect( this, TQT_SIGNAL( returnPressed( const TQString& ) ), - this, TQT_SLOT( slotReturnPressed( const TQString& ) ) ); - - KCompletionBox *box = completionBox(); - connect( box, TQT_SIGNAL( highlighted( const TQString& ) ), - this, TQT_SLOT( slotPopupCompletion( const TQString& ) ) ); - connect( box, TQT_SIGNAL( userCancelled( const TQString& ) ), - TQT_SLOT( slotUserCancelled( const TQString& ) ) ); - - // The emitter is always called KPIM::IMAPCompletionOrder by contract - if ( !connectDCOPSignal( 0, "KPIM::IMAPCompletionOrder", "orderChanged()", - "slotIMAPCompletionOrderChanged()", false ) ) - kdError() << "AddresseeLineEdit: connection to orderChanged() failed" << endl; - - connect( s_LDAPTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotStartLDAPLookup() ) ); - connect( s_LDAPSearch, TQT_SIGNAL( searchData( const KPIM::LdapResultList& ) ), - TQT_SLOT( slotLDAPSearchData( const KPIM::LdapResultList& ) ) ); - - m_completionInitialized = true; - } - } -} - -AddresseeLineEdit::~AddresseeLineEdit() -{ - if ( s_LDAPSearch && s_LDAPLineEdit == this ) - stopLDAPLookup(); -} - -void AddresseeLineEdit::setFont( const TQFont& font ) -{ - KLineEdit::setFont( font ); - if ( m_useCompletion ) - completionBox()->setFont( font ); -} - -void AddresseeLineEdit::allowSemiColonAsSeparator( bool useSemiColonAsSeparator ) -{ - m_useSemiColonAsSeparator = useSemiColonAsSeparator; -} - -void AddresseeLineEdit::allowDistributionLists( bool allowDistLists ) -{ - m_allowDistLists = allowDistLists; -} - -void AddresseeLineEdit::keyPressEvent( TQKeyEvent *e ) -{ - bool accept = false; - - if ( KStdAccel::shortcut( KStdAccel::SubstringCompletion ).contains( KKey( e ) ) ) { - //TODO: add LDAP substring lookup, when it becomes available in KPIM::LDAPSearch - updateSearchString(); - doCompletion( true ); - accept = true; - } else if ( KStdAccel::shortcut( KStdAccel::TextCompletion ).contains( KKey( e ) ) ) { - int len = text().length(); - - if ( len == cursorPosition() ) { // at End? - updateSearchString(); - doCompletion( true ); - accept = true; - } - } - - const TQString oldContent = text(); - if ( !accept ) - KLineEdit::keyPressEvent( e ); - - // if the text didn't change (eg. because a cursor navigation key was pressed) - // we don't need to trigger a new search - if ( oldContent == text() ) - return; - - if ( e->isAccepted() ) { - updateSearchString(); - TQString searchString( m_searchString ); - //LDAP does not know about our string manipulation, remove it - if ( m_searchExtended ) - searchString = m_searchString.mid( 1 ); - - if ( m_useCompletion && s_LDAPTimer != NULL ) { - if ( *s_LDAPText != searchString || s_LDAPLineEdit != this ) - stopLDAPLookup(); - - *s_LDAPText = searchString; - s_LDAPLineEdit = this; - s_LDAPTimer->start( 500, true ); - } - } -} - -void AddresseeLineEdit::insert( const TQString &t ) -{ - if ( !m_smartPaste ) { - KLineEdit::insert( t ); - return; - } - - //kdDebug(5300) << " AddresseeLineEdit::insert( \"" << t << "\" )" << endl; - - TQString newText = t.stripWhiteSpace(); - if ( newText.isEmpty() ) - return; - - // remove newlines in the to-be-pasted string - TQStringList lines = TQStringList::split( TQRegExp("\r?\n"), newText, false ); - for ( TQStringList::iterator it = lines.begin(); - it != lines.end(); ++it ) { - // remove trailing commas and whitespace - (*it).remove( TQRegExp(",?\\s*$") ); - } - newText = lines.join( ", " ); - - if ( newText.startsWith("mailto:") ) { - KURL url( newText ); - newText = url.path(); - } - else if ( newText.find(" at ") != -1 ) { - // Anti-spam stuff - newText.replace( " at ", "@" ); - newText.replace( " dot ", "." ); - } - else if ( newText.find("(at)") != -1 ) { - newText.replace( TQRegExp("\\s*\\(at\\)\\s*"), "@" ); - } - - TQString contents = text(); - int start_sel = 0; - int pos = cursorPosition( ); - - if ( hasSelectedText() ) { - // Cut away the selection. - start_sel = selectionStart(); - pos = start_sel; - contents = contents.left( start_sel ) + contents.mid( start_sel + selectedText().length() ); - } - - int eot = contents.length(); - while ( ( eot > 0 ) && contents[ eot - 1 ].isSpace() ) { - eot--; - } - if ( eot == 0 ) { - contents = TQString(); - } else if ( pos >= eot ) { - if ( contents[ eot - 1 ] == ',' ) { - eot--; - } - contents.truncate( eot ); - contents += ", "; - pos = eot + 2; - } - - contents = contents.left( pos ) + newText + contents.mid( pos ); - setText( contents ); - setEdited( true ); - setCursorPosition( pos + newText.length() ); -} - -void AddresseeLineEdit::setText( const TQString & text ) -{ - ClickLineEdit::setText( text.stripWhiteSpace() ); -} - -void AddresseeLineEdit::paste() -{ - if ( m_useCompletion ) - m_smartPaste = true; - - KLineEdit::paste(); - m_smartPaste = false; -} - -void AddresseeLineEdit::mouseReleaseEvent( TQMouseEvent *e ) -{ - // reimplemented from TQLineEdit::mouseReleaseEvent() - if ( m_useCompletion - && TQApplication::tqclipboard()->supportsSelection() - && !isReadOnly() - && e->button() == Qt::MidButton ) { - m_smartPaste = true; - } - - KLineEdit::mouseReleaseEvent( e ); - m_smartPaste = false; -} - -void AddresseeLineEdit::dropEvent( TQDropEvent *e ) -{ - KURL::List uriList; - if ( !isReadOnly() ) { - if ( KURLDrag::canDecode(e) && KURLDrag::decode( e, uriList ) ) { - TQString contents = text(); - // remove trailing white space and comma - int eot = contents.length(); - while ( ( eot > 0 ) && contents[ eot - 1 ].isSpace() ) - eot--; - if ( eot == 0 ) - contents = TQString(); - else if ( contents[ eot - 1 ] == ',' ) { - eot--; - contents.truncate( eot ); - } - bool mailtoURL = false; - // append the mailto URLs - for ( KURL::List::Iterator it = uriList.begin(); - it != uriList.end(); ++it ) { - if ( !contents.isEmpty() ) - contents.append( ", " ); - KURL u( *it ); - if ( u.protocol() == "mailto" ) { - mailtoURL = true; - contents.append( (*it).path() ); - } - } - if ( mailtoURL ) { - setText( contents ); - setEdited( true ); - return; - } - } else { - // Let's see if this drop contains a comma separated list of emails - TQString dropData = TQString::fromUtf8( e->tqencodedData( "text/plain" ) ); - TQStringList addrs = splitEmailAddrList( dropData ); - if ( addrs.count() > 0 ) { - setText( normalizeAddressesAndDecodeIDNs( dropData ) ); - setEdited( true ); - return; - } - } - } - - if ( m_useCompletion ) - m_smartPaste = true; - TQLineEdit::dropEvent( e ); - m_smartPaste = false; -} - -void AddresseeLineEdit::cursorAtEnd() -{ - setCursorPosition( text().length() ); -} - -void AddresseeLineEdit::enableCompletion( bool enable ) -{ - m_useCompletion = enable; -} - -void AddresseeLineEdit::doCompletion( bool ctrlT ) -{ - m_lastSearchMode = ctrlT; - - KGlobalSettings::Completion mode = completionMode(); - - if ( mode == KGlobalSettings::CompletionNone ) - return; - - if ( s_addressesDirty ) { - loadContacts(); // read from local address book - s_completion->setOrder( completionOrder() ); - } - - // cursor at end of string - or Ctrl+T pressed for substring completion? - if ( ctrlT ) { - const TQStringList completions = getAdjustedCompletionItems( false ); - - if ( completions.count() > 1 ) - ; //m_previousAddresses = prevAddr; - else if ( completions.count() == 1 ) - setText( m_previousAddresses + completions.first().stripWhiteSpace() ); - - setCompletedItems( completions, true ); // this makes sure the completion popup is closed if no matching items were found - - cursorAtEnd(); - setCompletionMode( mode ); //set back to previous mode - return; - } - - - switch ( mode ) { - case KGlobalSettings::CompletionPopupAuto: - { - if ( m_searchString.isEmpty() ) - break; - } - - case KGlobalSettings::CompletionPopup: - { - const TQStringList items = getAdjustedCompletionItems( true ); - setCompletedItems( items, false ); - break; - } - - case KGlobalSettings::CompletionShell: - { - TQString match = s_completion->makeCompletion( m_searchString ); - if ( !match.isNull() && match != m_searchString ) { - setText( m_previousAddresses + match ); - setEdited( true ); - cursorAtEnd(); - } - break; - } - - case KGlobalSettings::CompletionMan: // Short-Auto in fact - case KGlobalSettings::CompletionAuto: - { - //force autoSuggest in KLineEdit::keyPressed or setCompletedText will have no effect - setCompletionMode( completionMode() ); - - if ( !m_searchString.isEmpty() ) { - - //if only our \" is left, remove it since user has not typed it either - if ( m_searchExtended && m_searchString == "\"" ){ - m_searchExtended = false; - m_searchString = TQString(); - setText( m_previousAddresses ); - break; - } - - TQString match = s_completion->makeCompletion( m_searchString ); - - if ( !match.isEmpty() ) { - if ( match != m_searchString ) { - TQString adds = m_previousAddresses + match; - setCompletedText( adds ); - } - } else { - if ( !m_searchString.startsWith( "\"" ) ) { - //try with quoted text, if user has not type one already - match = s_completion->makeCompletion( "\"" + m_searchString ); - if ( !match.isEmpty() && match != m_searchString ) { - m_searchString = "\"" + m_searchString; - m_searchExtended = true; - setText( m_previousAddresses + m_searchString ); - setCompletedText( m_previousAddresses + match ); - } - } else if ( m_searchExtended ) { - //our added \" does not work anymore, remove it - m_searchString = m_searchString.mid( 1 ); - m_searchExtended = false; - setText( m_previousAddresses + m_searchString ); - //now try again - match = s_completion->makeCompletion( m_searchString ); - if ( !match.isEmpty() && match != m_searchString ) { - TQString adds = m_previousAddresses + match; - setCompletedText( adds ); - } - } - } - } - break; - } - - case KGlobalSettings::CompletionNone: - default: // fall through - break; - } -} - -void AddresseeLineEdit::slotPopupCompletion( const TQString& completion ) -{ - setText( m_previousAddresses + completion.stripWhiteSpace() ); - cursorAtEnd(); -// slotMatched( m_previousAddresses + completion ); - updateSearchString(); -} - -void AddresseeLineEdit::slotReturnPressed( const TQString& item ) -{ - Q_UNUSED( item ); - TQListBoxItem* i = completionBox()->selectedItem(); - if ( i != 0 ) - slotPopupCompletion( i->text() ); -} - -void AddresseeLineEdit::loadContacts() -{ - s_completion->clear(); - s_completionItemMap->clear(); - s_addressesDirty = false; - //m_contactMap.clear(); - - TQApplication::setOverrideCursor( KCursor::waitCursor() ); // loading might take a while - - KConfig config( "kpimcompletionorder" ); // The weights for non-imap kabc resources is there. - config.setGroup( "CompletionWeights" ); - - KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); - // Can't just use the addressbook's iterator, we need to know which subresource - // is behind which contact. - TQPtrList resources( addressBook->resources() ); - for( TQPtrListIterator resit( resources ); *resit; ++resit ) { - KABC::Resource* resource = *resit; - KPIM::ResourceABC* resabc = dynamic_cast( resource ); - if ( resabc ) { // IMAP KABC resource; need to associate each contact with the subresource - const TQMap uidToResourceMap = resabc->uidToResourceMap(); - KABC::Resource::Iterator it; - for ( it = resource->begin(); it != resource->end(); ++it ) { - TQString uid = (*it).uid(); - TQMap::const_iterator wit = uidToResourceMap.find( uid ); - const TQString subresourceLabel = resabc->subresourceLabel( *wit ); - const int weight = ( wit != uidToResourceMap.end() ) ? resabc->subresourceCompletionWeight( *wit ) : 80; - const int idx = addCompletionSource( subresourceLabel, weight ); - - //kdDebug(5300) << (*it).fullEmail() << " subres=" << *wit << " weight=" << weight << endl; - addContact( *it, weight, idx ); - } - } else { // KABC non-imap resource - int weight = config.readNumEntry( resource->identifier(), 60 ); - int sourceIndex = addCompletionSource( resource->resourceName(), weight ); - KABC::Resource::Iterator it; - for ( it = resource->begin(); it != resource->end(); ++it ) { - addContact( *it, weight, sourceIndex ); - } - } - } - -#ifndef KDEPIM_NEW_DISTRLISTS // new distr lists are normal contact, already done above - int weight = config.readNumEntry( "DistributionLists", 60 ); - KABC::DistributionListManager manager( addressBook ); - manager.load(); - const TQStringList distLists = manager.listNames(); - TQStringList::const_iterator listIt; - int idx = addCompletionSource( i18n( "Distribution Lists" ) ); - for ( listIt = distLists.begin(); listIt != distLists.end(); ++listIt ) { - - //for KGlobalSettings::CompletionAuto - addCompletionItem( (*listIt).simplifyWhiteSpace(), weight, idx ); - - //for CompletionShell, CompletionPopup - TQStringList sl( (*listIt).simplifyWhiteSpace() ); - addCompletionItem( (*listIt).simplifyWhiteSpace(), weight, idx, &sl ); - - } -#endif - - TQApplication::restoreOverrideCursor(); - - if ( !m_addressBookConnected ) { - connect( addressBook, TQT_SIGNAL( addressBookChanged( AddressBook* ) ), TQT_SLOT( loadContacts() ) ); - m_addressBookConnected = true; - } -} - -void AddresseeLineEdit::addContact( const KABC::Addressee& addr, int weight, int source ) -{ -#ifdef KDEPIM_NEW_DISTRLISTS - if ( KPIM::DistributionList::isDistributionList( addr ) ) { - //kdDebug(5300) << "AddresseeLineEdit::addContact() distribution list \"" << addr.formattedName() << "\" weight=" << weight << endl; - - if ( m_allowDistLists ) { - //for CompletionAuto - addCompletionItem( addr.formattedName(), weight, source ); - - //for CompletionShell, CompletionPopup - TQStringList sl( addr.formattedName() ); - addCompletionItem( addr.formattedName(), weight, source, &sl ); - } - - return; - } -#endif - //m_contactMap.insert( addr.realName(), addr ); - const TQStringList emails = addr.emails(); - TQStringList::ConstIterator it; - const int prefEmailWeight = 1; //increment weight by prefEmailWeight - int isPrefEmail = prefEmailWeight; //first in list is preferredEmail - for ( it = emails.begin(); it != emails.end(); ++it ) { - //TODO: highlight preferredEmail - const TQString email( (*it) ); - const TQString givenName = addr.givenName(); - const TQString familyName= addr.familyName(); - const TQString nickName = addr.nickName(); - const TQString domain = email.mid( email.find( '@' ) + 1 ); - TQString fullEmail = addr.fullEmail( email ); - //TODO: let user decide what fields to use in lookup, e.g. company, city, ... - - //for CompletionAuto - if ( givenName.isEmpty() && familyName.isEmpty() ) { - addCompletionItem( fullEmail, weight + isPrefEmail, source ); // use whatever is there - } else { - const TQString byFirstName= "\"" + givenName + " " + familyName + "\" <" + email + ">"; - const TQString byLastName = "\"" + familyName + ", " + givenName + "\" <" + email + ">"; - addCompletionItem( byFirstName, weight + isPrefEmail, source ); - addCompletionItem( byLastName, weight + isPrefEmail, source ); - } - - addCompletionItem( email, weight + isPrefEmail, source ); - - if ( !nickName.isEmpty() ){ - const TQString byNick = "\"" + nickName + "\" <" + email + ">"; - addCompletionItem( byNick, weight + isPrefEmail, source ); - } - - if ( !domain.isEmpty() ){ - const TQString byDomain = "\"" + domain + " " + familyName + " " + givenName + "\" <" + email + ">"; - addCompletionItem( byDomain, weight + isPrefEmail, source ); - } - - //for CompletionShell, CompletionPopup - TQStringList keyWords; - const TQString realName = addr.realName(); - - if ( !givenName.isEmpty() && !familyName.isEmpty() ) { - keyWords.append( givenName + " " + familyName ); - keyWords.append( familyName + " " + givenName ); - keyWords.append( familyName + ", " + givenName); - }else if ( !givenName.isEmpty() ) - keyWords.append( givenName ); - else if ( !familyName.isEmpty() ) - keyWords.append( familyName ); - - if ( !nickName.isEmpty() ) - keyWords.append( nickName ); - - if ( !realName.isEmpty() ) - keyWords.append( realName ); - - if ( !domain.isEmpty() ) - keyWords.append( domain ); - - keyWords.append( email ); - - /* KMailCompletion does not have knowledge about identities, it stores emails and - * keywords for each email. KMailCompletion::allMatches does a lookup on the - * keywords and returns an ordered list of emails. In order to get the preferred - * email before others for each identity we use this little trick. - * We remove the in getAdjustedCompletionItems. - */ - if ( isPrefEmail == prefEmailWeight ) - fullEmail.replace( " <", " <" ); - - addCompletionItem( fullEmail, weight + isPrefEmail, source, &keyWords ); - isPrefEmail = 0; - -#if 0 - int len = (*it).length(); - if ( len == 0 ) continue; - if( '\0' == (*it)[len-1] ) - --len; - const TQString tmp = (*it).left( len ); - const TQString fullEmail = addr.fullEmail( tmp ); - //kdDebug(5300) << "AddresseeLineEdit::addContact() \"" << fullEmail << "\" weight=" << weight << endl; - addCompletionItem( fullEmail.simplifyWhiteSpace(), weight, source ); - // Try to guess the last name: if found, we add an extra - // entry to the list to make sure completion works even - // if the user starts by typing in the last name. - TQString name( addr.realName().simplifyWhiteSpace() ); - if( name.endsWith("\"") ) - name.truncate( name.length()-1 ); - if( name.startsWith("\"") ) - name = name.mid( 1 ); - - // While we're here also add "email (full name)" for completion on the email - if ( !name.isEmpty() ) - addCompletionItem( addr.preferredEmail() + " (" + name + ")", weight, source ); - - bool bDone = false; - int i = -1; - while( ( i = name.findRev(' ') ) > 1 && !bDone ) { - TQString sLastName( name.mid( i+1 ) ); - if( ! sLastName.isEmpty() && - 2 <= sLastName.length() && // last names must be at least 2 chars long - ! sLastName.endsWith(".") ) { // last names must not end with a dot (like "Jr." or "Sr.") - name.truncate( i ); - if( !name.isEmpty() ){ - sLastName.prepend( "\"" ); - sLastName.append( ", " + name + "\" <" ); - } - TQString sExtraEntry( sLastName ); - sExtraEntry.append( tmp.isEmpty() ? addr.preferredEmail() : tmp ); - sExtraEntry.append( ">" ); - //kdDebug(5300) << "AddresseeLineEdit::addContact() added extra \"" << sExtraEntry.simplifyWhiteSpace() << "\" weight=" << weight << endl; - addCompletionItem( sExtraEntry.simplifyWhiteSpace(), weight, source ); - bDone = true; - } - if( !bDone ) { - name.truncate( i ); - if( name.endsWith("\"") ) - name.truncate( name.length()-1 ); - } - } -#endif - } -} - -void AddresseeLineEdit::addCompletionItem( const TQString& string, int weight, int completionItemSource, const TQStringList * keyWords ) -{ - // Check if there is an exact match for item already, and use the max weight if so. - // Since there's no way to get the information from KCompletion, we have to keep our own TQMap - CompletionItemsMap::iterator it = s_completionItemMap->find( string ); - if ( it != s_completionItemMap->end() ) { - weight = TQMAX( ( *it ).first, weight ); - ( *it ).first = weight; - } else { - s_completionItemMap->insert( string, tqMakePair( weight, completionItemSource ) ); - } - if ( keyWords == 0 ) - s_completion->addItem( string, weight ); - else - s_completion->addItemWithKeys( string, weight, keyWords ); -} - -void AddresseeLineEdit::slotStartLDAPLookup() -{ - KGlobalSettings::Completion mode = completionMode(); - - if ( mode == KGlobalSettings::CompletionNone ) - return; - - if ( !s_LDAPSearch->isAvailable() ) { - return; - } - if ( s_LDAPLineEdit != this ) - return; - - startLoadingLDAPEntries(); -} - -void AddresseeLineEdit::stopLDAPLookup() -{ - s_LDAPSearch->cancelSearch(); - s_LDAPLineEdit = NULL; -} - -void AddresseeLineEdit::startLoadingLDAPEntries() -{ - TQString s( *s_LDAPText ); - // TODO cache last? - TQString prevAddr; - int n = s.findRev( ',' ); - if ( n >= 0 ) { - prevAddr = s.left( n + 1 ) + ' '; - s = s.mid( n + 1, 255 ).stripWhiteSpace(); - } - - if ( s.isEmpty() ) - return; - - //loadContacts(); // TODO reuse these? - s_LDAPSearch->startSearch( s ); -} - -void AddresseeLineEdit::slotLDAPSearchData( const KPIM::LdapResultList& adrs ) -{ - if ( adrs.isEmpty() || s_LDAPLineEdit != this ) - return; - - for ( KPIM::LdapResultList::ConstIterator it = adrs.begin(); it != adrs.end(); ++it ) { - KABC::Addressee addr; - addr.setNameFromString( (*it).name ); - addr.setEmails( (*it).email ); - - if ( !s_ldapClientToCompletionSourceMap->contains( (*it).clientNumber ) ) - updateLDAPWeights(); // we got results from a new source, so update the completion sources - - addContact( addr, (*it).completionWeight, (*s_ldapClientToCompletionSourceMap)[ (*it ).clientNumber ] ); - } - - if ( (hasFocus() || completionBox()->hasFocus() ) - && completionMode() != KGlobalSettings::CompletionNone - && completionMode() != KGlobalSettings::CompletionShell ) { - setText( m_previousAddresses + m_searchString ); - // only complete again if the user didn't change the selection while we were waiting - // otherwise the completion box will be closed - if ( m_searchString.stripWhiteSpace() != completionBox()->currentText().stripWhiteSpace() ) - doCompletion( m_lastSearchMode ); - } -} - -void AddresseeLineEdit::setCompletedItems( const TQStringList& items, bool autoSuggest ) -{ - KCompletionBox* completionBox = this->completionBox(); - - if ( !items.isEmpty() && - !(items.count() == 1 && m_searchString == items.first()) ) - { - TQString oldCurrentText = completionBox->currentText(); - TQListBoxItem *itemUnderMouse = completionBox->itemAt( - completionBox->viewport()->mapFromGlobal(TQCursor::pos()) ); - TQString oldTextUnderMouse; - TQPoint oldPosOfItemUnderMouse; - if ( itemUnderMouse ) { - oldTextUnderMouse = itemUnderMouse->text(); - oldPosOfItemUnderMouse = completionBox->tqitemRect( itemUnderMouse ).topLeft(); - } - - completionBox->setItems( items ); - - if ( !completionBox->isVisible() ) { - if ( !m_searchString.isEmpty() ) - completionBox->setCancelledText( m_searchString ); - completionBox->popup(); - // we have to install the event filter after popup(), since that - // calls show(), and that's where KCompletionBox installs its filter. - // We want to be first, though, so do it now. - if ( s_completion->order() == KCompletion::Weighted ) - tqApp->installEventFilter( this ); - } - - // Try to re-select what was selected before, otherrwise use the first - // item, if there is one - TQListBoxItem* item = 0; - if ( oldCurrentText.isEmpty() - || ( item = completionBox->findItem( oldCurrentText ) ) == 0 ) { - item = completionBox->item( 1 ); - } - if ( item ) - { - if ( itemUnderMouse ) { - TQListBoxItem *newItemUnderMouse = completionBox->findItem( oldTextUnderMouse ); - // if the mouse was over an item, before, but now that's elsewhere, - // move the cursor, so folks don't accidently click the wrong item - if ( newItemUnderMouse ) { - TQRect r = completionBox->tqitemRect( newItemUnderMouse ); - TQPoint target = r.topLeft(); - if ( oldPosOfItemUnderMouse != target ) { - target.setX( target.x() + r.width()/2 ); - TQCursor::setPos( completionBox->viewport()->mapToGlobal(target) ); - } - } - } - completionBox->blockSignals( true ); - completionBox->setSelected( item, true ); - completionBox->setCurrentItem( item ); - completionBox->ensureCurrentVisible(); - - completionBox->blockSignals( false ); - } - - if ( autoSuggest ) - { - int index = items.first().find( m_searchString ); - TQString newText = items.first().mid( index ); - setUserSelection(false); - setCompletedText(newText,true); - } - } - else - { - if ( completionBox && completionBox->isVisible() ) { - completionBox->hide(); - completionBox->setItems( TQStringList() ); - } - } -} - -TQPopupMenu* AddresseeLineEdit::createPopupMenu() -{ - TQPopupMenu *menu = KLineEdit::createPopupMenu(); - if ( !menu ) - return 0; - - if ( m_useCompletion ){ - menu->setItemVisible( ShortAutoCompletion, false ); - menu->setItemVisible( PopupAutoCompletion, false ); - menu->insertItem( i18n( "Configure Completion Order..." ), - this, TQT_SLOT( slotEditCompletionOrder() ) ); - } - return menu; -} - -void AddresseeLineEdit::slotEditCompletionOrder() -{ - init(); // for s_LDAPSearch - CompletionOrderEditor editor( s_LDAPSearch, this ); - editor.exec(); - if ( m_useCompletion ) { - updateLDAPWeights(); - s_addressesDirty = true; - } -} - -void KPIM::AddresseeLineEdit::slotIMAPCompletionOrderChanged() -{ - if ( m_useCompletion ) - s_addressesDirty = true; -} - -void KPIM::AddresseeLineEdit::slotUserCancelled( const TQString& cancelText ) -{ - if ( s_LDAPSearch && s_LDAPLineEdit == this ) - stopLDAPLookup(); - userCancelled( m_previousAddresses + cancelText ); // in KLineEdit -} - -void AddresseeLineEdit::updateSearchString() -{ - m_searchString = text(); - - int n = -1; - bool inQuote = false; - uint searchStringLength = m_searchString.length(); - for ( uint i = 0; i < searchStringLength; ++i ) { - if ( m_searchString[ i ] == '"' ) { - inQuote = !inQuote; - } - if ( m_searchString[ i ] == '\\' && - (i + 1) < searchStringLength && m_searchString[ i + 1 ] == '"' ) { - ++i; - } - if ( inQuote ) { - continue; - } - if ( i < searchStringLength && - ( m_searchString[ i ] == ',' || - ( m_useSemiColonAsSeparator && m_searchString[ i ] == ';' ) ) ) { - n = i; - } - } - - if ( n >= 0 ) { - ++n; // Go past the "," - - int len = m_searchString.length(); - - // Increment past any whitespace... - while ( n < len && m_searchString[ n ].isSpace() ) - ++n; - - m_previousAddresses = m_searchString.left( n ); - m_searchString = m_searchString.mid( n ).stripWhiteSpace(); - } else { - m_previousAddresses = TQString(); - } -} - -void KPIM::AddresseeLineEdit::slotCompletion() -{ - // Called by KLineEdit's keyPressEvent for CompletionModes Auto,Popup -> new text, update search string - // not called for CompletionShell, this is been taken care of in AddresseeLineEdit::keyPressEvent - updateSearchString(); - if ( completionBox() ) - completionBox()->setCancelledText( m_searchString ); - doCompletion( false ); -} - -// not cached, to make sure we get an up-to-date value when it changes -KCompletion::CompOrder KPIM::AddresseeLineEdit::completionOrder() -{ - KConfig config( "kpimcompletionorder" ); - config.setGroup( "General" ); - const TQString order = config.readEntry( "CompletionOrder", "Weighted" ); - - if ( order == "Weighted" ) - return KCompletion::Weighted; - else - return KCompletion::Sorted; -} - -int KPIM::AddresseeLineEdit::addCompletionSource( const TQString &source, int weight ) -{ - TQMap::iterator it = s_completionSourceWeights->find( source ); - if ( it == s_completionSourceWeights->end() ) - s_completionSourceWeights->insert( source, weight ); - else - (*s_completionSourceWeights)[source] = weight; - - int sourceIndex = s_completionSources->findIndex( source ); - if ( sourceIndex == -1 ) { - s_completionSources->append( source ); - return s_completionSources->size() - 1; - } - else - return sourceIndex; -} - -bool KPIM::AddresseeLineEdit::eventFilter(TQObject *obj, TQEvent *e) -{ - if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(completionBox()) ) { - if ( e->type() == TQEvent::MouseButtonPress || - e->type() == TQEvent::MouseMove || - e->type() == TQEvent::MouseButtonRelease || - e->type() == TQEvent::MouseButtonDblClick ) { - TQMouseEvent* me = TQT_TQMOUSEEVENT( e ); - // find list box item at the event position - TQListBoxItem *item = completionBox()->itemAt( me->pos() ); - if ( !item ) { - // In the case of a mouse move outside of the box we don't want - // the parent to fuzzy select a header by mistake. - bool eat = e->type() == TQEvent::MouseMove; - return eat; - } - // avoid selection of headers on button press, or move or release while - // a button is pressed - if ( e->type() == TQEvent::MouseButtonPress - || me->state() & Qt::LeftButton || me->state() & Qt::MidButton - || me->state() & Qt::RightButton ) { - if ( itemIsHeader(item) ) { - return true; // eat the event, we don't want anything to happen - } else { - // if we are not on one of the group heading, make sure the item - // below or above is selected, not the heading, inadvertedly, due - // to fuzzy auto-selection from TQListBox - completionBox()->setCurrentItem( item ); - completionBox()->setSelected( completionBox()->index( item ), true ); - if ( e->type() == TQEvent::MouseMove ) - return true; // avoid fuzzy selection behavior - } - } - } - } - if ( ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(this) ) && - ( e->type() == TQEvent::AccelOverride ) ) { - TQKeyEvent *ke = TQT_TQKEYEVENT( e ); - if ( ke->key() == Key_Up || ke->key() == Key_Down || ke->key() == Key_Tab ) { - ke->accept(); - return true; - } - } - if ( ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(this) ) && - ( e->type() == TQEvent::KeyPress || e->type() == TQEvent::KeyRelease ) && - completionBox()->isVisible() ) { - TQKeyEvent *ke = TQT_TQKEYEVENT( e ); - int currentIndex = completionBox()->currentItem(); - if ( currentIndex < 0 ) { - return true; - } - - if ( ke->key() == Key_Up ) { - //kdDebug() << "EVENTFILTER: Key_Up currentIndex=" << currentIndex << endl; - // figure out if the item we would be moving to is one we want - // to ignore. If so, go one further - TQListBoxItem *itemAbove = completionBox()->item( currentIndex ); - if ( itemAbove && itemIsHeader(itemAbove) ) { - // there is a header above us, check if there is even further up - // and if so go one up, so it'll be selected - if ( currentIndex > 0 && completionBox()->item( currentIndex - 1 ) ) { - //kdDebug() << "EVENTFILTER: Key_Up -> skipping " << currentIndex - 1 << endl; - completionBox()->setCurrentItem( itemAbove->prev() ); - completionBox()->setSelected( currentIndex - 1, true ); - } else if ( currentIndex == 0 ) { - // nothing to skip to, let's stay where we are, but make sure the - // first header becomes visible, if we are the first real entry - completionBox()->ensureVisible( 0, 0 ); - //Kolab issue 2941: be sure to add email even if it's the only element. - if ( itemIsHeader( completionBox()->item( currentIndex ) ) ) { - currentIndex++; - } - completionBox()->setCurrentItem( itemAbove ); - completionBox()->setSelected( currentIndex, true ); - } - return true; - } - } else if ( ke->key() == Key_Down ) { - // same strategy for downwards - //kdDebug() << "EVENTFILTER: Key_Down. currentIndex=" << currentIndex << endl; - TQListBoxItem *itemBelow = completionBox()->item( currentIndex ); - if ( itemBelow && itemIsHeader( itemBelow ) ) { - if ( completionBox()->item( currentIndex + 1 ) ) { - //kdDebug() << "EVENTFILTER: Key_Down -> skipping " << currentIndex+1 << endl; - completionBox()->setCurrentItem( itemBelow->next() ); - completionBox()->setSelected( currentIndex + 1, true ); - } else { - // nothing to skip to, let's stay where we are - completionBox()->setCurrentItem( itemBelow ); - completionBox()->setSelected( currentIndex, true ); - } - return true; - } - // special case of the last and only item in the list needing selection - if ( !itemBelow && currentIndex == 1 ) { - completionBox()->setSelected( currentIndex, true ); - } - // special case of the initial selection, which is unfortunately a header. - // Setting it to selected tricks KCompletionBox into not treating is special - // and selecting making it current, instead of the one below. - TQListBoxItem *item = completionBox()->item( currentIndex ); - if ( item && itemIsHeader(item) ) { - completionBox()->setSelected( currentIndex, true ); - } - } else if ( e->type() == TQEvent::KeyRelease && - ( ke->key() == Key_Tab || ke->key() == Key_Backtab ) ) { - //kdDebug() << "EVENTFILTER: Key_Tab. currentIndex=" << currentIndex << endl; - /// first, find the header of the current section - TQListBoxItem *myHeader = 0; - const int iterationstep = ke->key() == Key_Tab ? 1 : -1; - int i = TQMIN( TQMAX( currentIndex - iterationstep, 0 ), completionBox()->count() - 1 ); - while ( i>=0 ) { - if ( itemIsHeader( completionBox()->item(i) ) ) { - myHeader = completionBox()->item( i ); - break; - } - i--; - } - Q_ASSERT( myHeader ); // we should always be able to find a header - - // find the next header (searching backwards, for Key_Backtab) - TQListBoxItem *nextHeader = 0; - // when iterating forward, start at the currentindex, when backwards, - // one up from our header, or at the end - uint j; - if ( ke->key() == Key_Tab ) { - j = currentIndex; - } else { - i = completionBox()->index( myHeader ); - if ( i == 0 ) { - j = completionBox()->count() - 1; - } else { - j = ( i - 1 ) % completionBox()->count(); - } - } - while ( ( nextHeader = completionBox()->item( j ) ) && nextHeader != myHeader ) { - if ( itemIsHeader(nextHeader) ) { - break; - } - j = (j + iterationstep) % completionBox()->count(); - } - if ( nextHeader && nextHeader != myHeader ) { - TQListBoxItem *item = completionBox()->item( j + 1 ); - if ( item && !itemIsHeader(item) ) { - completionBox()->setSelected( item, true ); - completionBox()->setCurrentItem( item ); - completionBox()->ensureCurrentVisible(); - } - } - return true; - } - } - return ClickLineEdit::eventFilter( obj, e ); -} - -class SourceWithWeight { - public: - int weight; // the weight of the source - TQString sourceName; // the name of the source, e.g. "LDAP Server" - int index; // index into s_completionSources - - bool operator< ( const SourceWithWeight &other ) { - if ( weight > other.weight ) - return true; - if ( weight < other.weight ) - return false; - return sourceName < other.sourceName; - } -}; - -const TQStringList KPIM::AddresseeLineEdit::getAdjustedCompletionItems( bool fullSearch ) -{ - TQStringList items = fullSearch ? - s_completion->allMatches( m_searchString ) - : s_completion->substringCompletion( m_searchString ); - - // For weighted mode, the algorithm is the following: - // In the first loop, we add each item to its section (there is one section per completion source) - // We also add spaces in front of the items. - // The sections are appended to the items list. - // In the second loop, we then walk through the sections and add all the items in there to the - // sorted item list, which is the final result. - // - // The algo for non-weighted mode is different. - - int lastSourceIndex = -1; - unsigned int i = 0; - - // Maps indices of the items list, which are section headers/source items, - // to a TQStringList which are the items of that section/source. - TQMap sections; - TQStringList sortedItems; - for ( TQStringList::Iterator it = items.begin(); it != items.end(); ++it, ++i ) { - CompletionItemsMap::const_iterator cit = s_completionItemMap->find(*it); - if ( cit == s_completionItemMap->end() ) - continue; - int idx = (*cit).second; - - if ( s_completion->order() == KCompletion::Weighted ) { - if ( lastSourceIndex == -1 || lastSourceIndex != idx ) { - const TQString sourceLabel( (*s_completionSources)[idx] ); - if ( sections.find(idx) == sections.end() ) { - items.insert( it, sourceLabel ); - } - lastSourceIndex = idx; - } - (*it) = (*it).prepend( s_completionItemIndentString ); - // remove preferred email sort added in addContact() - (*it).replace( " <", " <" ); - } - sections[idx].append( *it ); - - if ( s_completion->order() == KCompletion::Sorted ) { - sortedItems.append( *it ); - } - } - - if ( s_completion->order() == KCompletion::Weighted ) { - - // Sort the sections - TQValueList sourcesAndWeights; - for ( uint i = 0; i < s_completionSources->size(); i++ ) { - SourceWithWeight sww; - sww.sourceName = (*s_completionSources)[i]; - sww.weight = (*s_completionSourceWeights)[sww.sourceName]; - sww.index = i; - sourcesAndWeights.append( sww ); - } - qHeapSort( sourcesAndWeights ); - - // Add the sections and their items to the final sortedItems result list - for( uint i = 0; i < sourcesAndWeights.size(); i++ ) { - TQStringList sectionItems = sections[sourcesAndWeights[i].index]; - if ( !sectionItems.isEmpty() ) { - sortedItems.append( sourcesAndWeights[i].sourceName ); - TQStringList sectionItems = sections[sourcesAndWeights[i].index]; - for ( TQStringList::Iterator sit( sectionItems.begin() ), send( sectionItems.end() ); - sit != send; ++sit ) { - sortedItems.append( *sit ); - } - } - } - } else { - sortedItems.sort(); - } - return sortedItems; -} -#include "addresseelineedit.moc" diff --git a/libkdepim/addresseelineedit.h b/libkdepim/addresseelineedit.h deleted file mode 100644 index 209151b6e..000000000 --- a/libkdepim/addresseelineedit.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - This file is part of libtdepim. - Copyright (c) 2002 Helge Deller - 2002 Lubos Lunak - 2001,2003 Carsten Pfeiffer - 2001 Waldo Bastian - 2004 Daniel Molkentin - 2004 Karl-Heinz Zimmer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef ADDRESSEELINEEDIT_H -#define ADDRESSEELINEEDIT_H - -#include -#include -#include -#include -#include - -#include - -#include "clicklineedit.h" -#include "kmailcompletion.h" -#include -#include - -class KConfig; - -namespace KPIM { -class LdapSearch; -class LdapResult; -typedef TQValueList LdapResultList; -typedef TQMap< TQString, TQPair > CompletionItemsMap; -} - -namespace KPIM { - -class KDE_EXPORT AddresseeLineEdit : public ClickLineEdit, public DCOPObject -{ - K_DCOP - Q_OBJECT - TQ_OBJECT - - public: - AddresseeLineEdit( TQWidget* parent, bool useCompletion = true, - const char *name = 0L); - virtual ~AddresseeLineEdit(); - - virtual void setFont( const TQFont& ); - void allowSemiColonAsSeparator( bool ); - - /// Sets if distribution lists will be used for completion. - /// This is true by default. - /// Call this right after the constructor, before anything calls loadContacts(), - /// otherwise this has no effect. - void allowDistributionLists( bool allowDistLists ); - - public slots: - void cursorAtEnd(); - void enableCompletion( bool enable ); - /** Reimplemented for stripping whitespace after completion */ - virtual void setText( const TQString& txt ); - - protected slots: - virtual void loadContacts(); - protected: - void addContact( const KABC::Addressee&, int weight, int source = -1 ); - virtual void keyPressEvent( TQKeyEvent* ); - /** - * Reimplemented for smart insertion of email addresses. - * Features: - * - Automatically adds ',' if necessary to separate email addresses - * - Correctly decodes mailto URLs - * - Recognizes email addresses which are protected against address - * harvesters, i.e. "name at kde dot org" and "name(at)kde.org" - */ - virtual void insert( const TQString &text ); - /** Reimplemented for smart insertion of pasted email addresses. */ - virtual void paste(); - /** Reimplemented for smart insertion with middle mouse button. */ - virtual void mouseReleaseEvent( TQMouseEvent *e ); - /** Reimplemented for smart insertion of dragged email addresses. */ - virtual void dropEvent( TQDropEvent *e ); - void doCompletion( bool ctrlT ); - virtual TQPopupMenu *createPopupMenu(); - - /** - * Adds the name of a completion source to the internal list of - * such sources and returns its index, such that that can be used - * for insertion of items associated with that source. - * - * If the source already exists, the weight will be updated. - */ - int addCompletionSource( const TQString&, int weight ); - - /** return whether we are using sorted or weighted display */ - static KCompletion::CompOrder completionOrder(); - - k_dcop: - // Connected to the DCOP signal - void slotIMAPCompletionOrderChanged(); - - private slots: - void slotCompletion(); - void slotPopupCompletion( const TQString& ); - void slotReturnPressed( const TQString& ); - void slotStartLDAPLookup(); - void slotLDAPSearchData( const KPIM::LdapResultList& ); - void slotEditCompletionOrder(); - void slotUserCancelled( const TQString& ); - - private: - virtual bool eventFilter(TQObject *o, TQEvent *e); - void init(); - void startLoadingLDAPEntries(); - void stopLDAPLookup(); - void updateLDAPWeights(); - - void setCompletedItems( const TQStringList& items, bool autoSuggest ); - void addCompletionItem( const TQString& string, int weight, int source, const TQStringList * keyWords=0 ); - TQString completionSearchText( TQString& ); - const TQStringList getAdjustedCompletionItems( bool fullSearch ); - void updateSearchString(); - - TQString m_previousAddresses; - TQString m_searchString; - bool m_useCompletion; - bool m_completionInitialized; - bool m_smartPaste; - bool m_addressBookConnected; - bool m_lastSearchMode; - bool m_searchExtended; //has \" been added? - bool m_useSemiColonAsSeparator; - bool m_allowDistLists; - - //TQMap m_contactMap; - - static bool s_addressesDirty; - static KMailCompletion *s_completion; - static CompletionItemsMap* s_completionItemMap; - static TQTimer *s_LDAPTimer; - static KPIM::LdapSearch *s_LDAPSearch; - static TQString *s_LDAPText; - static AddresseeLineEdit *s_LDAPLineEdit; - static TQStringList *s_completionSources; - static TQMap *s_ldapClientToCompletionSourceMap; - - class AddresseeLineEditPrivate; - AddresseeLineEditPrivate *d; - - //until MenuID moves into protected in KLineEdit, we keep a copy here - //Constants that represent the ID's of the popup menu. - enum MenuID - { - Default = 42, - NoCompletion, - AutoCompletion, - ShellCompletion, - PopupCompletion, - ShortAutoCompletion, - PopupAutoCompletion - }; - -}; - -} - -#endif diff --git a/libkdepim/addresseeselector.cpp b/libkdepim/addresseeselector.cpp deleted file mode 100644 index 792d57625..000000000 --- a/libkdepim/addresseeselector.cpp +++ /dev/null @@ -1,581 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "addresseeselector.h" - -using namespace KPIM; - -class AddresseeSelector::AddressBookManager -{ - public: - TQStringList titles() const; - - void addResource( KABC::Resource* ); - void addAddressBook( const TQString &title, SelectionItem::List &list ); - - void clear(); - bool contains( uint index, const SelectionItem& ); - - private: - struct AddressBookEntry { - TQString title; - SelectionItem::List list; - }; - - TQValueList mResources; - TQValueList mAddressBooks; -}; - -TQStringList AddresseeSelector::AddressBookManager::titles() const -{ - TQStringList titles; - - // we've always an 'all' entry - titles.append( i18n( "All" ) ); - - TQValueList::ConstIterator resIt; - for ( resIt = mResources.begin(); resIt != mResources.end(); ++resIt ) - titles.append( (*resIt)->resourceName() ); - - TQValueList::ConstIterator abIt; - for ( abIt = mAddressBooks.begin(); abIt != mAddressBooks.end(); ++abIt ) - titles.append( (*abIt).title ); - - return titles; -} - -void AddresseeSelector::AddressBookManager::addResource( KABC::Resource *resource ) -{ - if ( mResources.find( resource ) == mResources.end() ) - mResources.append( resource ); -} - -void AddresseeSelector::AddressBookManager::addAddressBook( const TQString &title, - SelectionItem::List &list ) -{ - AddressBookEntry entry; - entry.title = title; - entry.list = list; - - - // TODO: check for duplicates - mAddressBooks.append( entry ); -} - -void AddresseeSelector::AddressBookManager::clear() -{ - mResources.clear(); - mAddressBooks.clear(); -} - -bool AddresseeSelector::AddressBookManager::contains( uint index, const SelectionItem &item ) -{ - if ( index == 0 ) // the 'all' entry - return true; - - if ( mResources.count() > 0 ) { - if ( index <= mResources.count() ) { - index--; - if ( item.addressee().resource() == mResources[ index ] ) - return true; - else - return false; - } - } - - index = index - mResources.count(); - - if ( mAddressBooks.count() > 0 ) { - if ( index <= mAddressBooks.count() ) { - index--; - AddressBookEntry entry = mAddressBooks[ index ]; - SelectionItem::List::ConstIterator it; - for ( it = entry.list.begin(); it != entry.list.end(); ++it ) - if ( (*it).addressee() == item.addressee() ) - return true; - - return false; - } - } - - return false; -} - - -SelectionItem::SelectionItem( const KABC::Addressee &addressee, uint index ) - : mAddressee( addressee ), mDistributionList( 0 ), mIndex( index ) -{ - mField.fill( false, 10 ); -} - -SelectionItem::SelectionItem( KABC::DistributionList *list, uint index ) - : mDistributionList( list ), mIndex( index ) -{ - mField.fill( false, 10 ); -} - -SelectionItem::SelectionItem() - : mDistributionList( 0 ), mIndex( 0 ) -{ - mField.fill( false, 10 ); -} - -void SelectionItem::addToField( int index ) -{ - mField.setBit( index ); -} - -void SelectionItem::removeFromField( int index ) -{ - mField.clearBit( index ); -} - -bool SelectionItem::isInField( int index ) -{ - return mField.testBit( index ); -} - -KABC::Addressee SelectionItem::addressee() const -{ - return mAddressee; -} - -KABC::DistributionList* SelectionItem::distributionList() const -{ - return mDistributionList; -} - -uint SelectionItem::index() const -{ - return mIndex; -} - - -class SelectionViewItem : public TQListViewItem -{ - public: - SelectionViewItem( TQListView *parent, Selection *selection, - SelectionItem *item ) - : TQListViewItem( parent, "" ), mSelection( selection ), mItem( item ) - { - if ( mItem->distributionList() == 0 ) - mIcon = mSelection->itemIcon( mItem->addressee(), mItem->index() ); - else - mIcon = mSelection->distributionListIcon( mItem->distributionList() ); - } - - TQString text( int column ) const - { - if ( column == 0 ) { - if ( mItem->distributionList() == 0 ) - return mSelection->itemText( mItem->addressee(), mItem->index() ); - else - return mSelection->distributionListText( mItem->distributionList() ); - } else - return TQString(); - } - - const TQPixmap* pixmap( int column ) const - { - if ( column == 0 ) { - return &mIcon; - } else - return 0; - } - - SelectionItem* item() const { return mItem; } - - private: - Selection *mSelection; - SelectionItem *mItem; - TQPixmap mIcon; -}; - -AddresseeSelector::AddresseeSelector( Selection *selection, TQWidget *parent, const char *name ) - : TQWidget( parent, name ), mSelection( selection ), mManager( 0 ) -{ - mMoveMapper = new TQSignalMapper( TQT_TQOBJECT(this) ); - mRemoveMapper = new TQSignalMapper( TQT_TQOBJECT(this) ); - - mAddressBookManager = new AddressBookManager(); - - initGUI(); - - init(); - - mSelection->setSelector( this ); -} - -AddresseeSelector::~AddresseeSelector() -{ - delete mManager; - mManager = 0; - - delete mAddressBookManager; - mAddressBookManager = 0; -} - -void AddresseeSelector::init() -{ - connect( KABC::StdAddressBook::self( true ), TQT_SIGNAL( addressBookChanged( AddressBook* ) ), - this, TQT_SLOT( reloadAddressBook() ) ); - connect( mAddresseeFilter, TQT_SIGNAL( textChanged( const TQString& ) ), - this, TQT_SLOT( updateAddresseeView() ) ); - connect( mAddressBookCombo, TQT_SIGNAL( activated( int ) ), - this, TQT_SLOT( updateAddresseeView() ) ); - - connect( mMoveMapper, TQT_SIGNAL( mapped( int ) ), - this, TQT_SLOT( move( int ) ) ); - connect( mRemoveMapper, TQT_SIGNAL( mapped( int ) ), - this, TQT_SLOT( remove( int ) ) ); - - reloadAddressBook(); -} - -void AddresseeSelector::initGUI() -{ - TQGridLayout *tqlayout = new TQGridLayout( this, 2, 3, KDialog::marginHint(), KDialog::spacingHint() ); - TQGridLayout *topLayout = new TQGridLayout( this, 2, 2, KDialog::marginHint() ); - - TQLabel *label = new TQLabel( i18n( "Address book:" ), this ); - mAddressBookCombo = new KComboBox( false, this ); - - topLayout->addWidget( label, 0, 0 ); - topLayout->addWidget( mAddressBookCombo, 0, 1 ); - - label = new TQLabel( i18n( "Search:" ), this ); - mAddresseeFilter = new KLineEdit( this ); - - topLayout->addWidget( label, 1, 0 ); - topLayout->addWidget( mAddresseeFilter, 1, 1 ); - - topLayout->setColStretch( 1, 1 ); - - tqlayout->addMultiCellLayout( topLayout, 0, 0, 0, 2 ); - - int row = 1; - - TQIconSet moveSet = KGlobal::iconLoader()->loadIconSet( "next", KIcon::Small ); - TQIconSet removeSet = KGlobal::iconLoader()->loadIconSet( "previous", KIcon::Small ); - - uint count = mSelection->fieldCount(); - for ( uint i = 0; i < count; ++i, ++row ) { - KListView *listView = new KListView( this ); - listView->addColumn( mSelection->fieldTitle( i ) ); - listView->setFullWidth( true ); - mSelectionViews.append( listView ); - - connect( listView, TQT_SIGNAL( doubleClicked( TQListViewItem*, const TQPoint&, int ) ), - mRemoveMapper, TQT_SLOT( map() ) ); - mRemoveMapper->setMapping( TQT_TQOBJECT(listView), i ); - - TQVBoxLayout *buttonLayout = new TQVBoxLayout( this ); - buttonLayout->tqsetAlignment( TQt::AlignBottom ); - tqlayout->addLayout( buttonLayout, row, 1 ); - - // move button - TQToolButton *moveButton = new TQToolButton( this ); - moveButton->setIconSet( moveSet ); - moveButton->setFixedSize( 30, 30 ); - - connect( moveButton, TQT_SIGNAL( clicked() ), - mMoveMapper, TQT_SLOT( map() ) ); - mMoveMapper->setMapping( TQT_TQOBJECT(moveButton), i ); - - // remove button - TQToolButton *removeButton = new TQToolButton( this ); - removeButton->setIconSet( removeSet ); - removeButton->setFixedSize( 30, 30 ); - - connect( removeButton, TQT_SIGNAL( clicked() ), - mRemoveMapper, TQT_SLOT( map() ) ); - mRemoveMapper->setMapping( TQT_TQOBJECT(removeButton), i ); - - buttonLayout->addWidget( moveButton ); - buttonLayout->addWidget( removeButton ); - - tqlayout->addWidget( listView, row, 2 ); - } - - mAddresseeView = new KListView( this ); - mAddresseeView->addColumn( "" ); - mAddresseeView->header()->hide(); - mAddresseeView->setFullWidth( true ); - - tqlayout->addMultiCellWidget( mAddresseeView, 1, row, 0, 0 ); -} - -void AddresseeSelector::finish() -{ - SelectionItem::List::Iterator it; - - for ( uint field = 0; field < mSelection->fieldCount(); ++field ) { - for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { - if ( (*it).isInField( field ) ) { - if ( (*it).distributionList() == 0 ) - mSelection->addSelectedAddressees( field, (*it).addressee(), (*it).index() ); - else - mSelection->addSelectedDistributionList( field, (*it).distributionList() ); - } - } - } -} - -void AddresseeSelector::updateAddresseeView() -{ - mAddresseeView->clear(); - - int addressBookIndex = mAddressBookCombo->currentItem(); - - SelectionItem::List::Iterator it; - for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { - if ( mAddressBookManager->contains( addressBookIndex, *it ) ) { - if ( (*it).distributionList() == 0 ) { - if ( mAddresseeFilter->text().isEmpty() || - mSelection->itemMatches( (*it).addressee(), (*it).index(), - mAddresseeFilter->text() ) ) - new SelectionViewItem( mAddresseeView, mSelection, &(*it) ); - } else { - if ( mAddresseeFilter->text().isEmpty() || - mSelection->distributionListMatches( (*it).distributionList(), - mAddresseeFilter->text() ) ) - new SelectionViewItem( mAddresseeView, mSelection, &(*it) ); - } - } - } - - updateSelectionViews(); -} - -void AddresseeSelector::move( int index ) -{ - SelectionViewItem *item = dynamic_cast( mAddresseeView->selectedItem() ); - if ( item ) { - item->item()->addToField( index ); - updateSelectionView( index ); - } -} - -void AddresseeSelector::remove( int index ) -{ - KListView *view = mSelectionViews[ index ]; - - SelectionViewItem *item = dynamic_cast( view->selectedItem() ); - if ( item ) { - item->item()->removeFromField( index ); - updateSelectionView( index ); - } -} - -void AddresseeSelector::setItemSelected( uint fieldIndex, const KABC::Addressee &addr, uint itemIndex ) -{ - bool found = false; - - SelectionItem::List::Iterator it; - for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { - if ( (*it).addressee() == addr && (*it).index() == itemIndex ) { - (*it).addToField( fieldIndex ); - found = true; - } - } - - if ( !found ) { - SelectionItem item( addr, itemIndex ); - item.addToField( fieldIndex ); - - mSelectionItems.append( item ); - } - - updateSelectionView( fieldIndex ); -} - -void AddresseeSelector::setItemSelected( uint fieldIndex, const KABC::Addressee &addr, - uint itemIndex, const TQString &text ) -{ - bool found = false; - - SelectionItem::List::Iterator it; - for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { - if ( mSelection->itemEquals( (*it).addressee(), (*it).index(), text ) ) { - (*it).addToField( fieldIndex ); - found = true; - } - } - - if ( !found ) { - SelectionItem item( addr, itemIndex ); - item.addToField( fieldIndex ); - - mSelectionItems.append( item ); - } - - updateSelectionView( fieldIndex ); -} - -void AddresseeSelector::updateSelectionView( int index ) -{ - KListView *view = mSelectionViews[ index ]; - view->clear(); - - SelectionItem::List::Iterator it; - for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { - if ( (*it).isInField( index ) ) - new SelectionViewItem( view, mSelection, &(*it) ); - } -} - -void AddresseeSelector::updateSelectionViews() -{ - for ( uint i = 0; i < mSelection->fieldCount(); ++i ) - updateSelectionView( i ); -} - -void AddresseeSelector::reloadAddressBook() -{ - // load contacts - KABC::Addressee::List list = KABC::StdAddressBook::self( true )->allAddressees(); - KABC::Addressee::List::Iterator it; - - SelectionItem::List selectedItems; - - SelectionItem::List::Iterator itemIt; - for ( itemIt = mSelectionItems.begin(); itemIt != mSelectionItems.end(); ++itemIt ) { - bool isSelected = false; - for ( uint i = 0; i < mSelection->fieldCount(); ++i ) { - if ( (*itemIt).isInField( i ) ) { - isSelected = true; - break; - } - } - - // we don't save distribution lists, since this leads to crashes - if ( isSelected && (*itemIt).distributionList() == 0 ) { - selectedItems.append( *itemIt ); - } - } - - mSelectionItems.clear(); - mSelectionItems = selectedItems; - - for ( it = list.begin(); it != list.end(); ++it ) { - uint itemCount = mSelection->itemCount( *it ); - for ( uint index = 0; index < itemCount; ++index ) { - bool available = false; - for ( itemIt = mSelectionItems.begin(); itemIt != mSelectionItems.end(); ++itemIt ) { - if ( (*itemIt).addressee() == (*it) && (*itemIt).index() == index ) { - available = true; - break; - } - } - - if ( !available ) { - SelectionItem item( *it, index ); - mSelectionItems.append( item ); - } - } - } - - // load distribution lists - delete mManager; - mManager = new KABC::DistributionListManager( KABC::StdAddressBook::self( true ) ); - - mManager->load(); - - TQStringList lists = mManager->listNames(); - - TQStringList::Iterator listIt; - for ( listIt = lists.begin(); listIt != lists.end(); ++listIt ) { - KABC::DistributionList *list = mManager->list( *listIt ); - SelectionItem item( list, 0 ); - mSelectionItems.append( item ); - } - - mAddressBookManager->clear(); - - // update address book combo - mAddressBookCombo->clear(); - - TQPtrList resources = KABC::StdAddressBook::self( true )->resources(); - TQPtrListIterator resIt( resources ); - while ( resIt.current() ) { - if ( resIt.current()->isActive() ) - mAddressBookManager->addResource( resIt ); - - ++resIt; - } - - for ( uint i = 0; i < mSelection->addressBookCount(); ++i ) { - SelectionItem::List itemList; - - KABC::Addressee::List addrList = mSelection->addressBookContent( i ); - for ( it = addrList.begin(); it != addrList.end(); ++it ) { - uint itemCount = mSelection->itemCount( *it ); - for ( uint index = 0; index < itemCount; ++index ) { - SelectionItem item( *it, index ); - mSelectionItems.append( item ); - itemList.append( item ); - } - } - - mAddressBookManager->addAddressBook( mSelection->addressBookTitle( i ), - itemList ); - } - - mAddressBookCombo->insertStringList( mAddressBookManager->titles() ); - - updateAddresseeView(); -} - - -AddresseeSelectorDialog::AddresseeSelectorDialog( Selection *selection, - TQWidget *parent, const char *name ) - : KDialogBase( Plain, "", Ok | Cancel, Ok, parent, name, true ) -{ - TQFrame *frame = plainPage(); - TQVBoxLayout *tqlayout = new TQVBoxLayout( frame ); - mSelector = new KPIM::AddresseeSelector( selection, frame ); - tqlayout->addWidget( mSelector ); - - resize( 500, 490 ); -} - -void AddresseeSelectorDialog::accept() -{ - mSelector->finish(); - TQDialog::accept(); -} - -#include "addresseeselector.moc" diff --git a/libkdepim/addresseeselector.h b/libkdepim/addresseeselector.h deleted file mode 100644 index 7ce70fb84..000000000 --- a/libkdepim/addresseeselector.h +++ /dev/null @@ -1,234 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPIM_ADDRESSEESELECTOR_H -#define KPIM_ADDRESSEESELECTOR_H - -#include -#include -#include -#include -#include - -#include -#include -#include - -class KComboBox; -class KLineEdit; -class KListView; -class TQSignalMapper; - -namespace KPIM { - -class AddresseeSelector; - -class KDE_EXPORT Selection -{ - friend class AddresseeSelector; - - public: - virtual ~Selection() {} - - /** - Returns the number of fields the selection offers. - */ - virtual uint fieldCount() const = 0; - - /** - Returns the title for the field specified by index. - */ - virtual TQString fieldTitle( uint index ) const = 0; - - /** - Returns the number of items for the given addressee. - */ - virtual uint itemCount( const KABC::Addressee &addresse ) const = 0; - - /** - Returns the text that's used for the item specified by index. - */ - virtual TQString itemText( const KABC::Addressee &addresse, uint index ) const = 0; - - /** - Returns the icon that's used for the item specified by index. - */ - virtual TQPixmap itemIcon( const KABC::Addressee &addresse, uint index ) const = 0; - - /** - Returns whether the item specified by index is enabled. - */ - virtual bool itemEnabled( const KABC::Addressee &addresse, uint index ) const = 0; - - /** - Returns whether the item specified by index matches the passed pattern. - */ - virtual bool itemMatches( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0; - - /** - Returns whether the item specified by index equals the passed pattern. - */ - virtual bool itemEquals( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0; - - /** - Returns the text that's used for the given distribution list. - */ - virtual TQString distributionListText( const KABC::DistributionList *distributionList ) const = 0; - - /** - Returns the icon that's used for the given distribution list. - */ - virtual TQPixmap distributionListIcon( const KABC::DistributionList *distributionList ) const = 0; - - /** - Returns whether the given distribution list is enabled. - */ - virtual bool distributionListEnabled( const KABC::DistributionList *distributionList ) const = 0; - - /** - Returns whether the given distribution list matches the passed pattern. - */ - virtual bool distributionListMatches( const KABC::DistributionList *distributionList, - const TQString &pattern ) const = 0; - - /** - Returns the number of additional address books. - */ - virtual uint addressBookCount() const = 0; - - /** - Returns the title for an additional address book. - */ - virtual TQString addressBookTitle( uint index ) const = 0; - - /** - Returns the content for an additional address book. - */ - virtual KABC::Addressee::List addressBookContent( uint index ) const = 0; - - protected: - AddresseeSelector* selector() { return mSelector; } - - private: - virtual void addSelectedAddressees( uint fieldIndex, const KABC::Addressee&, uint itemIndex ) = 0; - virtual void addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList* ) = 0; - - void setSelector( AddresseeSelector *selector ) { mSelector = selector; } - - AddresseeSelector *mSelector; -}; - -/** - Internal helper class - */ -class SelectionItem -{ - public: - typedef TQValueList List; - - SelectionItem( const KABC::Addressee &addressee, uint index ); - SelectionItem( KABC::DistributionList *list, uint index ); - SelectionItem(); - - void addToField( int index ); - void removeFromField( int index ); - bool isInField( int index ); - - KABC::Addressee addressee() const; - KABC::DistributionList* distributionList() const; - uint index() const; - - private: - KABC::Addressee mAddressee; - KABC::DistributionList *mDistributionList; - uint mIndex; - TQBitArray mField; -}; - -class KDE_EXPORT AddresseeSelector : public TQWidget -{ - Q_OBJECT - TQ_OBJECT - - public: - AddresseeSelector( Selection *selection, - TQWidget *parent, const char *name = 0 ); - ~AddresseeSelector(); - - /** - Writes back the selected items to the selection. - */ - void finish(); - - void setItemSelected( uint fieldIndex, const KABC::Addressee&, uint itemIndex ); - void setItemSelected( uint fieldIndex, const KABC::Addressee&, - uint itemIndex, const TQString& ); - - private slots: - void move( int index ); - void remove( int index ); - - void updateAddresseeView(); - void reloadAddressBook(); - - private: - void init(); - void initGUI(); - - void updateSelectionView( int index ); - void updateSelectionViews(); - - Selection *mSelection; - - KComboBox *mAddressBookCombo; - KLineEdit *mAddresseeFilter; - KListView *mAddresseeView; - SelectionItem::List mSelectionItems; - - TQValueList mSelectionViews; - TQSignalMapper *mMoveMapper; - TQSignalMapper *mRemoveMapper; - - KABC::DistributionListManager *mManager; - - class AddressBookManager; - AddressBookManager *mAddressBookManager; -}; - -class KDE_EXPORT AddresseeSelectorDialog : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT - - public: - AddresseeSelectorDialog( Selection *selection, - TQWidget *parent = 0, const char *name = 0 ); - - protected slots: - void accept(); - - private: - AddresseeSelector *mSelector; -}; - -} - -#endif diff --git a/libkdepim/addresseeview.cpp b/libkdepim/addresseeview.cpp deleted file mode 100644 index 15c7215ed..000000000 --- a/libkdepim/addresseeview.cpp +++ /dev/null @@ -1,792 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "addresseeview.h" -#include "sendsmsdialog.h" -#include "resourceabc.h" - -using namespace KPIM; - -AddresseeView::AddresseeView( TQWidget *parent, const char *name, - KConfig *config ) - : KTextBrowser( parent, name ), mDefaultConfig( false ), mImageJob( 0 ), - mLinkMask( AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks | CustomFields ) -{ - setWrapPolicy( TQTextEdit::AtWordBoundary ); - setLinkUnderline( false ); - setVScrollBarMode( TQScrollView::AlwaysOff ); - setHScrollBarMode( TQScrollView::AlwaysOff ); - - TQStyleSheet *sheet = styleSheet(); - TQStyleSheetItem *link = sheet->item( "a" ); - link->setColor( KGlobalSettings::linkColor() ); - - connect( this, TQT_SIGNAL( mailClick( const TQString&, const TQString& ) ), - this, TQT_SLOT( slotMailClicked( const TQString&, const TQString& ) ) ); - connect( this, TQT_SIGNAL( urlClick( const TQString& ) ), - this, TQT_SLOT( slotUrlClicked( const TQString& ) ) ); - connect( this, TQT_SIGNAL( highlighted( const TQString& ) ), - this, TQT_SLOT( slotHighlighted( const TQString& ) ) ); - - setNotifyClick( true ); - - mActionShowBirthday = new KToggleAction( i18n( "Show Birthday" ) ); - mActionShowBirthday->setCheckedState( i18n( "Hide Birthday" ) ); - mActionShowAddresses = new KToggleAction( i18n( "Show Postal Addresses" ) ); - mActionShowAddresses->setCheckedState( i18n( "Hide Postal Addresses" ) ); - mActionShowEmails = new KToggleAction( i18n( "Show Email Addresses" ) ); - mActionShowEmails->setCheckedState( i18n( "Hide Email Addresses" ) ); - mActionShowPhones = new KToggleAction( i18n( "Show Telephone Numbers" ) ); - mActionShowPhones->setCheckedState( i18n( "Hide Telephone Numbers" ) ); - mActionShowURLs = new KToggleAction( i18n( "Show Web Pages (URLs)" ) ); - mActionShowURLs->setCheckedState( i18n( "Hide Web Pages (URLs)" ) ); - mActionShowIMAddresses = new KToggleAction( i18n( "Show Instant Messaging Addresses" ) ); - mActionShowIMAddresses->setCheckedState( i18n( "Hide Instant Messaging Addresses" ) ); - mActionShowCustomFields = new KToggleAction( i18n( "Show Custom Fields" ) ); - mActionShowCustomFields->setCheckedState( i18n( "Hide Custom Fields" ) ); - - connect( mActionShowBirthday, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); - connect( mActionShowAddresses, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); - connect( mActionShowEmails, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); - connect( mActionShowPhones, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); - connect( mActionShowURLs, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); - connect( mActionShowIMAddresses, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); - connect( mActionShowCustomFields, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); - - if ( !config ) { - mConfig = new KConfig( "kaddressbookrc" ); - mDefaultConfig = true; - } else - mConfig = config; - - load(); - - // set up IMProxy to display contacts' IM presence and make connections to keep the display live - mKIMProxy = ::KIMProxy::instance( kapp->dcopClient() ); - connect( mKIMProxy, TQT_SIGNAL( sigContactPresenceChanged( const TQString& ) ), - this, TQT_SLOT( slotPresenceChanged( const TQString& ) ) ); - connect( mKIMProxy, TQT_SIGNAL( sigPresenceInfoExpired() ), - this, TQT_SLOT( slotPresenceInfoExpired() ) ); -} - -AddresseeView::~AddresseeView() -{ - if ( mDefaultConfig ) - delete mConfig; - mConfig = 0; - - delete mActionShowBirthday; - delete mActionShowAddresses; - delete mActionShowEmails; - delete mActionShowPhones; - delete mActionShowURLs; - delete mActionShowIMAddresses; - delete mActionShowCustomFields; - - mKIMProxy = 0; -} - -void AddresseeView::setAddressee( const KABC::Addressee& addr ) -{ - mAddressee = addr; - - if ( mImageJob ) { - mImageJob->kill(); - mImageJob = 0; - } - - mImageData.truncate( 0 ); - - updateView(); -} - -void AddresseeView::enableLinks( int linkMask ) -{ - mLinkMask = linkMask; -} - -TQString AddresseeView::vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask, - bool internalLoading, FieldMask fieldMask ) -{ - TQString image = TQString( "contact_%1_image" ).tqarg( addr.uid() ); - - // Style strings from Gentix; this is just an initial version. - // - // These will be substituted into various HTML strings with .tqarg(). - // Search for @STYLE@ to find where. Note how we use %1 as a - // placeholder where we fill in something else (in this case, - // the global background color). - // - TQString backgroundColor = KGlobalSettings::alternateBackgroundColor().name(); - TQString cellStyle = TQString::tqfromLatin1( - "style=\"" - "padding-right: 2px; " - "border-right: #000 dashed 1px; " - "background: %1;\"").tqarg(backgroundColor); - TQString backgroundColor2 = KGlobalSettings::baseColor().name(); - TQString cellStyle2 = TQString::tqfromLatin1( - "style=\"" - "padding-left: 2px; " - "background: %1;\"").tqarg(backgroundColor2); - TQString tableStyle = TQString::tqfromLatin1( - "style=\"" - "border: solid 1px; " - "margin: 0em;\""); - - // We'll be building a table to display the vCard in. - // Each row of the table will be built using this string for its HTML. - // - TQString rowFmtStr = TQString::tqfromLatin1( - "" - "" // Close tag - "%1" - "" - "" // Close tag - "%2" - "" - "\n" - ) ); - - // Build the table's rows here - TQString dynamicPart; - - - if ( !internalLoading ) { - KABC::Picture pic = addr.photo(); - if ( pic.isIntern() && !pic.data().isNull() ) { - image = pixmapAsDataUrl( pic.data() ); - } else if ( !pic.url().isEmpty() ) { - image = (pic.url().startsWith( "http://" ) || pic.url().startsWith( "https://" ) ? pic.url() : "http://" + pic.url()); - } else { - image = "file:" + KGlobal::iconLoader()->iconPath( "personal", KIcon::Desktop ); - } - } - - if ( fieldMask & BirthdayFields ) { - TQDate date = addr.birthday().date(); - - if ( date.isValid() ) - dynamicPart += rowFmtStr - .tqarg( KABC::Addressee::birthdayLabel() ) - .tqarg( KGlobal::locale()->formatDate( date, true ) ); - } - - if ( fieldMask & PhoneFields ) { - KABC::PhoneNumber::List phones = addr.phoneNumbers(); - KABC::PhoneNumber::List::ConstIterator phoneIt; - for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { - TQString number = TQStyleSheet::escape( (*phoneIt).number() ); - - TQString url; - if ( (*phoneIt).type() & KABC::PhoneNumber::Fax ) - url = TQString::tqfromLatin1( "fax:" ) + number; - else - url = TQString::tqfromLatin1( "phone:" ) + number; - - if ( linkMask & PhoneLinks ) { - TQString smsURL; - if ( (*phoneIt).type() & KABC::PhoneNumber::Cell ) - smsURL = TQString(" (%2)" ).tqarg( number ).tqarg( i18n( "SMS") ); - - dynamicPart += rowFmtStr - .tqarg( (*phoneIt).typeLabel().replace( " ", " " ) ) - .tqarg( TQString::tqfromLatin1( "%2%3" ).tqarg( url ).tqarg( number ).tqarg( smsURL ) ); - } else { - dynamicPart += rowFmtStr - .tqarg( (*phoneIt).typeLabel().replace( " ", " " ) ) - .tqarg( number ); - } - } - } - - if ( fieldMask & EmailFields ) { - TQStringList emails = addr.emails(); - TQStringList::ConstIterator emailIt; - TQString type = i18n( "Email" ); - for ( emailIt = emails.begin(); emailIt != emails.end(); ++emailIt ) { - TQString fullEmail = addr.fullEmail( *emailIt ); - TQUrl::encode( fullEmail ); - - if ( linkMask & EmailLinks ) { - dynamicPart += rowFmtStr.tqarg( type ) - .tqarg( TQString::tqfromLatin1( "%2" ) - .tqarg( fullEmail, TQStyleSheet::escape( *emailIt ) ) ); - } else { - dynamicPart += rowFmtStr.tqarg( type ).tqarg( *emailIt ); - } - } - } - - if ( fieldMask & URLFields ) { - if ( !addr.url().url().isEmpty() ) { - TQString url; - if ( linkMask & URLLinks ) { - url = (addr.url().url().startsWith( "http://" ) || addr.url().url().startsWith( "https://" ) ? addr.url().prettyURL() : - "http://" + addr.url().prettyURL()); - url = KStringHandler::tagURLs( url ); - } else { - url = addr.url().prettyURL(); - } - dynamicPart += rowFmtStr.tqarg( i18n("Homepage") ).tqarg( url ); - } - - TQString blog = addr.custom( "KADDRESSBOOK", "BlogFeed" ); - if ( !blog.isEmpty() ) { - if ( linkMask & URLLinks ) { - blog = KStringHandler::tagURLs( blog ); - } - dynamicPart += rowFmtStr.tqarg( i18n("Blog Feed") ).tqarg( blog ); - } - } - - if ( fieldMask & AddressFields ) { - KABC::Address::List addresses = addr.addresses(); - KABC::Address::List::ConstIterator addrIt; - for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { - if ( (*addrIt).label().isEmpty() ) { - TQString formattedAddress; - - formattedAddress = TQStyleSheet::escape( (*addrIt).formattedAddress().stripWhiteSpace() ); - formattedAddress = formattedAddress.replace( '\n', "
" ); - - TQString link = "" + - formattedAddress + ""; - - if ( linkMask & AddressLinks ) { - dynamicPart += rowFmtStr - .tqarg( KABC::Address::typeLabel( (*addrIt).type() ) ) - .tqarg( link ); - } else { - dynamicPart += rowFmtStr - .tqarg( KABC::Address::typeLabel( (*addrIt).type() ) ) - .tqarg( formattedAddress ); - } - } else { - TQString link = "" + - (*addrIt).label().replace( '\n', "
" ) + "
"; - - if ( linkMask & AddressLinks ) { - dynamicPart += rowFmtStr - .tqarg( KABC::Address::typeLabel( (*addrIt).type() ) ) - .tqarg( link ); - } else { - dynamicPart += rowFmtStr - .tqarg( KABC::Address::typeLabel( (*addrIt).type() ) ) - .tqarg( (*addrIt).label().replace( '\n', "
" ) ); - } - } - } - } - - TQString notes; - if ( !addr.note().isEmpty() ) { - // @STYLE@ - substitute the cell style in first, and append - // the data afterwards (keeps us safe from possible % signs - // in either one). - notes = TQStyleSheet::escape( addr.note() ); - notes = rowFmtStr.tqarg( i18n( "Notes" ) ).tqarg( notes.replace( '\n', "
" ) ) ; - } - - TQString customData; - if ( fieldMask & CustomFields ) { - static TQMap titleMap; - if ( titleMap.isEmpty() ) { - titleMap.insert( "Department", i18n( "Department" ) ); - titleMap.insert( "Profession", i18n( "Profession" ) ); - titleMap.insert( "AssistantsName", i18n( "Assistant's Name" ) ); - titleMap.insert( "ManagersName", i18n( "Manager's Name" ) ); - titleMap.insert( "SpousesName", i18n( "Partner's Name" ) ); - titleMap.insert( "Office", i18n( "Office" ) ); - titleMap.insert( "Anniversary", i18n( "Anniversary" ) ); - } - - if ( !addr.customs().empty() ) { - TQStringList customs = addr.customs(); - TQStringList::Iterator it( customs.begin() ); - const TQStringList::Iterator endIt( customs.end() ); - for ( ; it != endIt; ++it ) { - TQString customEntry = *it; - if ( customEntry.startsWith ( "KADDRESSBOOK-" ) ) { - customEntry.remove( "KADDRESSBOOK-X-" ); - customEntry.remove( "KADDRESSBOOK-" ); - - int pos = customEntry.find( ':' ); - TQString key = customEntry.left( pos ); - const TQString value = customEntry.mid( pos + 1 ); - - // blog and im address is handled separated - if ( key == "BlogFeed" || key == "IMAddress" ) - continue; - - const TQMap::ConstIterator keyIt = titleMap.find( key ); - if ( keyIt != titleMap.end() ) - key = keyIt.data(); - - customData += rowFmtStr.tqarg( key ).tqarg( TQStyleSheet::escape( value ) ) ; - } - } - } - } - - TQString name( TQStyleSheet::escape( addr.realName() ) ); - TQString role( TQStyleSheet::escape( addr.role() ) ); - TQString organization( TQStyleSheet::escape( addr.organization() ) ); - - if ( fieldMask & IMFields ) { - - const TQString imAddress = addr.custom( "KADDRESSBOOK", "X-IMAddress" ); - if ( !imAddress.isEmpty() ) { - customData += rowFmtStr.tqarg( i18n( "IM Address" ) ).tqarg( TQStyleSheet::escape( imAddress ) ) ; - } - - if ( proxy ) { - if ( proxy->isPresent( addr.uid() ) && proxy->presenceNumeric( addr.uid() ) > 0 ) { - // set image source to either a TQMimeSourceFactory key or a data:/ URL - TQString imgSrc; - if ( internalLoading ) { - imgSrc = TQString::tqfromLatin1( "im_status_%1_image").tqarg( addr.uid() ); - TQMimeSourceFactory::defaultFactory()->setPixmap( imgSrc, proxy->presenceIcon( addr.uid() ) ); - } else - imgSrc = pixmapAsDataUrl( proxy->presenceIcon( addr.uid() ) ); - - // make the status a link, if required - TQString imtqStatus; - if ( linkMask & IMLinks ) - imtqStatus = TQString::tqfromLatin1( " (%2)" ); - else - imtqStatus = TQString::tqfromLatin1( " (%2)" ); - - // append our status to the rest of the dynamic part of the addressee - dynamicPart += rowFmtStr - .tqarg( i18n( "Presence" ) ) - .tqarg( imtqStatus - .tqarg( imgSrc ) - .tqarg( proxy->presenceString( addr.uid() ) ) - ); - } - } - } - - // @STYLE@ - construct the string by parts, substituting in - // the styles first. There are lots of appends, but we need to - // do it this way to avoid cases where the substituted string - // contains %1 and the like. - // - TQString strAddr = TQString::tqfromLatin1( - "
" - "" - "").tqarg(tableStyle); - - strAddr.append( TQString::tqfromLatin1( - "") - .tqarg( image ) ); - strAddr.append( TQString::tqfromLatin1( - "" // name - "") - .tqarg( name ) ); - strAddr.append( TQString::tqfromLatin1( - "" - "" // role - "") - .tqarg( role ) ); - strAddr.append( TQString::tqfromLatin1( - "" - "" // organization - "") - .tqarg( organization ) ); - strAddr.append( TQString::tqfromLatin1( - "") - .tqarg( cellStyle2 ) ); - strAddr.append( dynamicPart ); - strAddr.append( notes ); - strAddr.append( customData ); - strAddr.append( TQString::tqfromLatin1( "
") - .tqarg( cellStyle ) ); - strAddr.append( TQString::tqfromLatin1( - "" // image - "") - .tqarg( cellStyle2 ) ); - strAddr.append( TQString::tqfromLatin1( - "%2
") - .tqarg( cellStyle2 ) ); - strAddr.append( TQString::tqfromLatin1( - "%3
") - .tqarg( cellStyle2 ) ); - strAddr.append( TQString::tqfromLatin1( - "%4
") - .tqarg( cellStyle ) ); - strAddr.append( TQString::tqfromLatin1( - "  
\n" ) ); - - if ( addr.resource() ) { - TQString addrBookName = addr.resource()->resourceName(); - ResourceABC *r = dynamic_cast( addr.resource() ); - if ( r && !r->subresources().isEmpty() ) { - const TQString subRes = r->uidToResourceMap()[ addr.uid() ]; - const TQString label = r->subresourceLabel( subRes ); - if ( !label.isEmpty() ) - addrBookName = label; - } - strAddr.append( i18n( "

Address book: %1

" ).tqarg( addrBookName ) ); - } - return strAddr; -} - -TQString AddresseeView::pixmapAsDataUrl( const TQPixmap& pixmap ) -{ - TQByteArray ba; - TQBuffer buffer( ba ); - buffer.open( IO_WriteOnly ); - pixmap.save( &buffer, "PNG" ); - TQString encoded( "data:image/png;base64," ); - encoded.append( KCodecs::base64Encode( ba ) ); - return encoded; -} - -void AddresseeView::updateView() -{ - // clear view - setText( TQString() ); - - if ( mAddressee.isEmpty() ) - return; - - if ( mImageJob ) { - mImageJob->kill(); - mImageJob = 0; - - mImageData.truncate( 0 ); - } - - int fieldMask = NoFields; - if ( mActionShowBirthday->isChecked() ) - fieldMask |= ( FieldMask )BirthdayFields; - if ( mActionShowAddresses->isChecked() ) - fieldMask |= AddressFields; - if ( mActionShowEmails->isChecked() ) - fieldMask |= EmailFields; - if ( mActionShowPhones->isChecked() ) - fieldMask |= PhoneFields; - if ( mActionShowURLs->isChecked() ) - fieldMask |= URLFields; - if ( mActionShowIMAddresses->isChecked() ) - fieldMask |= IMFields; - if ( mActionShowCustomFields->isChecked() ) - fieldMask |= CustomFields; - - TQString strAddr = vCardAsHTML( mAddressee, mKIMProxy, (LinkMask)mLinkMask, - true, (FieldMask)fieldMask ); - - strAddr = TQString::tqfromLatin1( - "" - "" // text and background color - "%3" // dynamic part - "" - "" ) - .tqarg( KGlobalSettings::textColor().name() ) - .tqarg( KGlobalSettings::baseColor().name() ) - .tqarg( strAddr ); - - TQString imageURL = TQString( "contact_%1_image" ).tqarg( mAddressee.uid() ); - - KABC::Picture picture = mAddressee.photo(); - if ( picture.isIntern() && !picture.data().isNull() ) - TQMimeSourceFactory::defaultFactory()->setImage( imageURL, picture.data() ); - else { - if ( !picture.url().isEmpty() ) { - if ( mImageData.count() > 0 ) - TQMimeSourceFactory::defaultFactory()->setImage( imageURL, TQImage(mImageData) ); - else { - mImageJob = KIO::get( KURL( picture.url() ), false, false ); - connect( mImageJob, TQT_SIGNAL( data( KIO::Job*, const TQByteArray& ) ), - this, TQT_SLOT( data( KIO::Job*, const TQByteArray& ) ) ); - connect( mImageJob, TQT_SIGNAL( result( KIO::Job* ) ), - this, TQT_SLOT( result( KIO::Job* ) ) ); - } - } else { - TQMimeSourceFactory::defaultFactory()->setPixmap( imageURL, - KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 128 ) ); - } - } - - // at last display it... - setText( strAddr ); -} - -KABC::Addressee AddresseeView::addressee() const -{ - return mAddressee; -} - -void AddresseeView::urlClicked( const TQString &url ) -{ - kapp->invokeBrowser( url ); -} - -void AddresseeView::emailClicked( const TQString &email ) -{ - if ( email.startsWith( "mailto:" ) ) - kapp->invokeMailer( email.mid( 7 ), TQString() ); - else - kapp->invokeMailer( email, TQString() ); -} - -void AddresseeView::phoneNumberClicked( const TQString &number ) -{ - KConfig config( "kaddressbookrc" ); - config.setGroup( "General" ); - TQString commandLine = config.readEntry( "PhoneHookApplication" ); - - if ( commandLine.isEmpty() ) { - KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) ); - return; - } - - commandLine.replace( "%N", number ); - KRun::runCommand( commandLine ); -} - -void AddresseeView::smsTextClicked( const TQString &number ) -{ - KConfig config( "kaddressbookrc" ); - config.setGroup( "General" ); - TQString commandLine = config.readEntry( "SMSHookApplication" ); - - if ( commandLine.isEmpty() ) { - KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) ); - return; - } - - SendSMSDialog dlg( mAddressee.realName(), this ); - - if ( dlg.exec() ) - sendSMS ( number, dlg.text() ); -} - -void AddresseeView::sendSMS( const TQString &number, const TQString &text ) -{ - KConfig config( "kaddressbookrc" ); - config.setGroup( "General" ); - TQString commandLine = config.readEntry( "SMSHookApplication" ); - - KTempFile file ; - TQTextStream* stream = file.textStream(); - *stream << text; - file.close(); - - commandLine.replace( "%N", number ); - commandLine.replace( "%F", file.name() ); - - KRun::runCommand( commandLine ); -} - -void AddresseeView::faxNumberClicked( const TQString &number ) -{ - KConfig config( "kaddressbookrc" ); - config.setGroup( "General" ); - TQString commandLine = config.readEntry( "FaxHookApplication", "tdeprintfax --phone %N" ); - - if ( commandLine.isEmpty() ) { - KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) ); - return; - } - - commandLine.replace( "%N", number ); - KRun::runCommand( commandLine ); -} - -void AddresseeView::imAddressClicked() -{ - mKIMProxy->chatWithContact( mAddressee.uid() ); -} - -TQPopupMenu *AddresseeView::createPopupMenu( const TQPoint& ) -{ - TQPopupMenu *menu = new TQPopupMenu( this ); - mActionShowBirthday->plug( menu ); - mActionShowAddresses->plug( menu ); - mActionShowEmails->plug( menu ); - mActionShowPhones->plug( menu ); - mActionShowURLs->plug( menu ); - mActionShowIMAddresses->plug( menu ); - mActionShowCustomFields->plug( menu ); - - return menu; -} - -void AddresseeView::slotMailClicked( const TQString&, const TQString &email ) -{ - emailClicked( email ); -} - -void AddresseeView::slotUrlClicked( const TQString &url ) -{ - if ( url.startsWith( "phone:" ) ) - phoneNumberClicked( strippedNumber( url.mid( 8 ) ) ); - else if ( url.startsWith( "sms:" ) ) - smsTextClicked( strippedNumber( url.mid( 6 ) ) ); - else if ( url.startsWith( "fax:" ) ) - faxNumberClicked( strippedNumber( url.mid( 6 ) ) ); - else if ( url.startsWith( "addr:" ) ) - emit addressClicked( url.mid( 7 ) ); - else if ( url.startsWith( "im:" ) ) - imAddressClicked(); - else - urlClicked( url ); -} - -void AddresseeView::slotHighlighted( const TQString &link ) -{ - if ( link.startsWith( "mailto:" ) ) { - TQString email = link.mid( 7 ); - - emit emailHighlighted( email ); - emit highlightedMessage( i18n( "Send mail to '%1'" ).tqarg( email ) ); - } else if ( link.startsWith( "phone:" ) ) { - TQString number = link.mid( 8 ); - - emit phoneNumberHighlighted( strippedNumber( number ) ); - emit highlightedMessage( i18n( "Call number %1" ).tqarg( number ) ); - } else if ( link.startsWith( "fax:" ) ) { - TQString number = link.mid( 6 ); - - emit faxNumberHighlighted( strippedNumber( number ) ); - emit highlightedMessage( i18n( "Send fax to %1" ).tqarg( number ) ); - } else if ( link.startsWith( "addr:" ) ) { - emit highlightedMessage( i18n( "Show address on map" ) ); - } else if ( link.startsWith( "sms:" ) ) { - TQString number = link.mid( 6 ); - emit highlightedMessage( i18n( "Send SMS to %1" ).tqarg( number ) ); - } else if ( link.startsWith( "http:" ) || link.startsWith( "https:" ) ) { - emit urlHighlighted( link ); - emit highlightedMessage( i18n( "Open URL %1" ).tqarg( link ) ); - } else if ( link.startsWith( "im:" ) ) { - emit highlightedMessage( i18n( "Chat with %1" ).tqarg( mAddressee.realName() ) ); - } else - emit highlightedMessage( "" ); -} - -void AddresseeView::slotPresenceChanged( const TQString &uid ) -{ - kdDebug() << k_funcinfo << " uid is: " << uid << " mAddressee is: " << mAddressee.uid() << endl; - if ( uid == mAddressee.uid() ) - updateView(); -} - - -void AddresseeView::slotPresenceInfoExpired() -{ - updateView(); -} - -void AddresseeView::configChanged() -{ - save(); - updateView(); -} - -void AddresseeView::data( KIO::Job*, const TQByteArray &d ) -{ - unsigned int oldSize = mImageData.size(); - mImageData.resize( oldSize + d.size() ); - memcpy( mImageData.data() + oldSize, d.data(), d.size() ); -} - -void AddresseeView::result( KIO::Job *job ) -{ - mImageJob = 0; - - if ( job->error() ) - mImageData.truncate( 0 ); - else - updateView(); -} - -void AddresseeView::load() -{ - mConfig->setGroup( "AddresseeViewSettings" ); - mActionShowBirthday->setChecked( mConfig->readBoolEntry( "ShowBirthday", false ) ); - mActionShowAddresses->setChecked( mConfig->readBoolEntry( "ShowAddresses", true ) ); - mActionShowEmails->setChecked( mConfig->readBoolEntry( "ShowEmails", true ) ); - mActionShowPhones->setChecked( mConfig->readBoolEntry( "ShowPhones", true ) ); - mActionShowURLs->setChecked( mConfig->readBoolEntry( "ShowURLs", true ) ); - mActionShowIMAddresses->setChecked( mConfig->readBoolEntry( "ShowIMAddresses", false ) ); - mActionShowCustomFields->setChecked( mConfig->readBoolEntry( "ShowCustomFields", false ) ); -} - -void AddresseeView::save() -{ - mConfig->setGroup( "AddresseeViewSettings" ); - mConfig->writeEntry( "ShowBirthday", mActionShowBirthday->isChecked() ); - mConfig->writeEntry( "ShowAddresses", mActionShowAddresses->isChecked() ); - mConfig->writeEntry( "ShowEmails", mActionShowEmails->isChecked() ); - mConfig->writeEntry( "ShowPhones", mActionShowPhones->isChecked() ); - mConfig->writeEntry( "ShowURLs", mActionShowURLs->isChecked() ); - mConfig->writeEntry( "ShowIMAddresses", mActionShowIMAddresses->isChecked() ); - mConfig->writeEntry( "ShowCustomFields", mActionShowCustomFields->isChecked() ); - mConfig->sync(); -} - -TQString AddresseeView::strippedNumber( const TQString &number ) -{ - TQString retval; - - for ( uint i = 0; i < number.length(); ++i ) { - TQChar c = number[ i ]; - if ( c.isDigit() || (((c == '*') || (c == '#') || (c == '+')) && (i == 0)) ) - retval.append( c ); - } - - return retval; -} - -#include "addresseeview.moc" diff --git a/libkdepim/addresseeview.h b/libkdepim/addresseeview.h deleted file mode 100644 index 0b7c13b05..000000000 --- a/libkdepim/addresseeview.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPIM_ADDRESSEEVIEW_H -#define KPIM_ADDRESSEEVIEW_H - -#include - -#include -#include -#include -#include - -namespace KIO { -class Job; -} -class KToggleAction; - -class TQPopupMenu; - - -namespace KPIM { - - -class KDE_EXPORT AddresseeView : public KTextBrowser -{ - Q_OBJECT - TQ_OBJECT - public: - /** - Constructor. - - @param config The config object where the settings are stored - which fields will be shown. - */ - AddresseeView( TQWidget *parent = 0, const char *name = 0, - KConfig *config = 0 ); - - ~AddresseeView(); - - /** - Sets the addressee object. The addressee is displayed immediately. - - @param addr The addressee object. - */ - void setAddressee( const KABC::Addressee& addr ); - - /** - Returns the current addressee object. - */ - KABC::Addressee addressee() const; - - - /** - This enums are used by enableLinks to set which kind of links shall - be enabled. - */ - enum LinkMask { - NoLinks = 0, - AddressLinks = 1, - EmailLinks = 2, - PhoneLinks = 4, - URLLinks = 8, - IMLinks = 16, - DefaultLinks = AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks - }; - - /** - Sets which parts of the contact shall be presented as links. - The mask can be OR'ed LinkMask. By default all links are enabled. - */ - void enableLinks( int linkMask ); - - /** - This enums are used by vCardAsHTML to decide which fields shall be - shown. - */ - enum FieldMask { - NoFields = 0, - BirthdayFields = 1, - AddressFields = 2, - EmailFields = 4, - PhoneFields = 8, - URLFields = 16, - IMFields = 32, - CustomFields = 64, - DefaultFields = AddressFields | EmailFields | PhoneFields | URLFields - }; - - /** - Returns the HTML representation of a contact. - The HTML code looks like -
- - ... -
-
- - @param addr The addressee object. - @param linkMask The mask for which parts of the contact will - be displayed as links. - The links looks like this: - "addr://" for addresses - "mailto:" for emails - "phone://" for phone numbers - "http://" for urls - "im:" for instant messaging addresses - "sms://" for sending a sms - @param internalLoading If true, the loading of internal pictures is done automatically. - @param fieldMask The mask for which fields of the contact will - be displayed. - */ - static TQString vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask = DefaultLinks, - bool internalLoading = true, FieldMask fieldMask = DefaultFields ); - - /** - * Encodes a TQPixmap as a PNG into a data: URL (rfc2397), readable by the data kio protocol - * @param pixmap the pixmap to encode - * @return a data: URL - */ - static TQString pixmapAsDataUrl( const TQPixmap& pixmap ); - - signals: - void urlHighlighted( const TQString &url ); - void emailHighlighted( const TQString &email ); - void phoneNumberHighlighted( const TQString &number ); - void faxNumberHighlighted( const TQString &number ); - - void highlightedMessage( const TQString &message ); - - void addressClicked( const TQString &uid ); - - protected: - virtual void urlClicked( const TQString &url ); - virtual void emailClicked( const TQString &mail ); - virtual void phoneNumberClicked( const TQString &number ); - virtual void smsTextClicked( const TQString &number ); - virtual void sendSMS( const TQString &number, const TQString &msg ); - virtual void faxNumberClicked( const TQString &number ); - virtual void imAddressClicked(); - - virtual TQPopupMenu *createPopupMenu( const TQPoint& ); - - private slots: - void slotMailClicked( const TQString&, const TQString& ); - void slotUrlClicked( const TQString& ); - void slotHighlighted( const TQString& ); - void slotPresenceChanged( const TQString & ); - void slotPresenceInfoExpired(); - void configChanged(); - - void data( KIO::Job*, const TQByteArray& ); - void result( KIO::Job* ); - - private: - void load(); - void save(); - - void updateView(); - - TQString strippedNumber( const TQString &number ); - - KConfig *mConfig; - bool mDefaultConfig; - - TQByteArray mImageData; - KIO::Job *mImageJob; - - KToggleAction *mActionShowBirthday; - KToggleAction *mActionShowAddresses; - KToggleAction *mActionShowEmails; - KToggleAction *mActionShowPhones; - KToggleAction *mActionShowURLs; - KToggleAction *mActionShowIMAddresses; - KToggleAction *mActionShowCustomFields; - - KABC::Addressee mAddressee; - int mLinkMask; - - class AddresseeViewPrivate; - AddresseeViewPrivate *d; - ::KIMProxy *mKIMProxy; -}; - -} - -#endif diff --git a/libkdepim/addressesdialog.cpp b/libkdepim/addressesdialog.cpp deleted file mode 100644 index 27f601833..000000000 --- a/libkdepim/addressesdialog.cpp +++ /dev/null @@ -1,1197 +0,0 @@ -/* -*- mode: C++; c-file-style: "gnu" -*- - * - * This file is part of libtdepim. - * - * Copyright (c) 2003 Zack Rusin - * Copyright (c) 2003 Aaron J. Seigo - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "addressesdialog.h" -#include "addresspicker.h" -#include "ldapsearchdialog.h" - -#include - -#include - -#ifdef KDEPIM_NEW_DISTRLISTS -#include "distributionlist.h" -#include -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace KPIM { - -// private start : -struct AddresseeViewItem::AddresseeViewItemPrivate { - KABC::Addressee address; - AddresseeViewItem::Category category; - KABC::Addressee::List addresses; -}; - -struct AddressesDialog::AddressesDialogPrivate { - AddressesDialogPrivate() : - ui(0), personal(0), recent(0), - toItem(0), ccItem(0), bccItem(0), - ldapSearchDialog(0) - {} - - AddressPickerUI *ui; - - AddresseeViewItem *personal; - AddresseeViewItem *recent; - AddresseeViewItem *topdist; - TQPtrList dists; - - AddresseeViewItem *toItem; - AddresseeViewItem *ccItem; - AddresseeViewItem *bccItem; - - TQDict groupDict; - - KABC::Addressee::List recentAddresses; - LDAPSearchDialog *ldapSearchDialog; -}; -// privates end - -AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent, const KABC::Addressee& addr, - int emailIndex ) - : TQObject( 0 ), KListViewItem( parent, addr.realName(), - ( emailIndex == 0 ? addr.preferredEmail() : addr.emails()[ emailIndex ] ) ) -{ - d = new AddresseeViewItemPrivate; - d->address = addr; - d->category = Entry; - - if ( text( 0 ).stripWhiteSpace().isEmpty() ) - setText( 0, addr.preferredEmail() ); - - if ( addr.photo().url().isEmpty() ) { - if ( addr.photo().data().isNull() ) - setPixmap( 0, KGlobal::iconLoader()->loadIcon( "personal", KIcon::Small ) ); - else - setPixmap( 0, addr.photo().data().smoothScale( 16, 16 ) ); - } else { - setPixmap( 0, KGlobal::iconLoader()->loadIcon( addr.photo().url(), KIcon::Small ) ); - } -} - -AddresseeViewItem::AddresseeViewItem( KListView *lv, const TQString& name, Category cat ) - : TQObject(0), KListViewItem( lv, name ) -{ - d = new AddresseeViewItemPrivate; - d->category = cat; -} - -AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent, const TQString& name, - const KABC::Addressee::List &lst ) - : TQObject(0), KListViewItem( parent, name, i18n("") ) -{ - d = new AddresseeViewItemPrivate; - d->category = FilledGroup; - d->addresses = lst; -} - -AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent, const TQString& name ) - : TQObject(0), KListViewItem( parent, name, i18n("") ) -{ - d = new AddresseeViewItemPrivate; - d->category = DistList; - - setPixmap( 0, KGlobal::iconLoader()->loadIcon( "kdmconfig", KIcon::Small ) ); -} - -AddresseeViewItem::~AddresseeViewItem() -{ - delete d; - d = 0; -} - -KABC::Addressee -AddresseeViewItem::addressee() const -{ - return d->address; -} - -KABC::Addressee::List -AddresseeViewItem::addresses() const -{ - return d->addresses; -} - -AddresseeViewItem::Category -AddresseeViewItem::category() const -{ - return d->category; -} - -TQString -AddresseeViewItem::name() const -{ - return text(0); -} - -TQString -AddresseeViewItem::email() const -{ - return text(1); -} - -bool AddresseeViewItem::matches(const TQString& txt) const -{ - return d->address.realName().contains(txt, false) || d->address.preferredEmail().contains(txt, false); -} - -void AddresseeViewItem::setSelected(bool selected) -{ - if (selected == isSelected()) - { - return; - } - - emit addressSelected( this, selected ); - TQListViewItem::setSelected(selected); -} - -int -AddresseeViewItem::compare( TQListViewItem * i, int col, bool ascending ) const -{ - if ( category() == Group || category() == Entry ) - return KListViewItem::compare( i , col, ascending ); - - AddresseeViewItem *item = static_cast( i ); - int a = static_cast( category() ); - int b = static_cast( item->category() ); - - if ( ascending ) - if ( a < b ) - return -1; - else - return 1; - else - if ( a < b ) - return 1; - else - return -1; -} - -AddressesDialog::AddressesDialog( TQWidget *widget, const char *name ) - : KDialogBase( widget, name, true, i18n("Address Selection"), - Ok|Cancel, Ok, true ) -{ - TQVBox *page = makeVBoxMainWidget(); - d = new AddressesDialogPrivate; - d->ui = new AddressPickerUI( page ); - - KABC::StdAddressBook::self( true ); - updateAvailableAddressees(); - initConnections(); - - d->ui->mAvailableView->setFocus(); - - setMainWidget( page ); - page->setMinimumSize( 750, 400 ); -} - -AddressesDialog::~AddressesDialog() -{ - delete d; - d = 0; -} - -AddresseeViewItem* AddressesDialog::selectedToItem() -{ - if ( !d->toItem ) - { - d->toItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("To"), AddresseeViewItem::To ); - connect(d->toItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - } - return d->toItem; -} - -AddresseeViewItem* AddressesDialog::selectedCcItem() -{ - if ( !d->ccItem ) - { - d->ccItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("CC"), AddresseeViewItem::CC ); - connect(d->ccItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - } - return d->ccItem; -} - -AddresseeViewItem* AddressesDialog::selectedBccItem() -{ - if ( !d->bccItem ) - { - d->bccItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("BCC"), AddresseeViewItem::BCC ); - connect(d->bccItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - } - return d->bccItem; -} - -void -AddressesDialog::setSelectedTo( const TQStringList& l ) -{ - TQString name, email; - for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) { - KABC::Addressee addr; - KABC::Addressee::parseEmailAddress( *it, name, email ); - addr.setNameFromString( name ); - addr.insertEmail( email ); - addAddresseeToSelected( addr, selectedToItem() ); - } -} - -void -AddressesDialog::setSelectedCC( const TQStringList& l ) -{ - TQString name, email; - for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) { - KABC::Addressee addr; - KABC::Addressee::parseEmailAddress( *it, name, email ); - addr.setNameFromString( name ); - addr.insertEmail( email ); - addAddresseeToSelected( addr, selectedCcItem() ); - } -} - -void -AddressesDialog::setSelectedBCC( const TQStringList& l ) -{ - TQString name, email; - for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) { - KABC::Addressee addr; - KABC::Addressee::parseEmailAddress( *it, name, email ); - addr.setNameFromString( name ); - addr.insertEmail( email ); - addAddresseeToSelected( addr, selectedBccItem() ); - } -} - -void -AddressesDialog::setRecentAddresses( const KABC::Addressee::List& list ) -{ - d->recentAddresses = list; - - updateRecentAddresses(); - - checkForSingleAvailableGroup(); -} - -void -AddressesDialog::updateRecentAddresses() -{ - static const TQString &recentGroup = KGlobal::staticQString( i18n( "Recent Addresses" ) ); - - if ( !d->recent ) { - d->recent = new AddresseeViewItem( d->ui->mAvailableView, recentGroup ); - connect(d->recent, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(availableAddressSelected(AddresseeViewItem*, bool))); - d->recent->setVisible( false ); - d->groupDict.insert( recentGroup, d->recent ); - } - - KABC::Addressee::List::ConstIterator it; - for ( it = d->recentAddresses.begin(); it != d->recentAddresses.end(); ++it ) - addAddresseeToAvailable( *it, d->recent ); - - if ( d->recent->childCount() > 0 ) { - d->recent->setOpen( true ); - d->recent->setVisible( true ); - } -} - -void -AddressesDialog::setShowCC( bool b ) -{ - d->ui->mCCButton->setShown( b ); -} - -void -AddressesDialog::setShowBCC( bool b ) -{ - d->ui->mBCCButton->setShown( b ); -} - -TQStringList -AddressesDialog::to() const -{ - TQStringList emails = allDistributionLists( d->toItem ); - KABC::Addressee::List l = toAddresses(); - emails += entryToString( l ); - - return emails; -} - -TQStringList -AddressesDialog::cc() const -{ - TQStringList emails = allDistributionLists( d->ccItem ); - KABC::Addressee::List l = ccAddresses(); - emails += entryToString( l ); - - return emails; -} - -TQStringList -AddressesDialog::bcc() const -{ - TQStringList emails = allDistributionLists( d->bccItem ); - - KABC::Addressee::List l = bccAddresses(); - emails += entryToString( l ); - - return emails; -} - -KABC::Addressee::List -AddressesDialog::toAddresses() const -{ - return allAddressee( d->toItem ); -} -KABC::Addressee::List -AddressesDialog::allToAddressesNoDuplicates() const -{ - KABC::Addressee::List aList = allAddressee( d->toItem ); - const TQStringList dList = toDistributionLists(); - KABC::AddressBook* abook = KABC::StdAddressBook::self( true ); -#ifdef KDEPIM_NEW_DISTRLISTS - for ( TQStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) { - const TQValueList eList - = KPIM::DistributionList::findByName(abook, *it).entries(abook); - TQValueList::ConstIterator eit; - for( eit = eList.begin(); eit != eList.end(); ++eit ) { - KABC::Addressee a = (*eit).addressee; - if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) { - aList.append( a ) ; - } - } - } -#else - KABC::DistributionListManager manager( abook ); - manager.load(); - for ( TQStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) { - const TQValueList eList = manager.list( *it )->entries(); - TQValueList::ConstIterator eit; - for( eit = eList.begin(); eit != eList.end(); ++eit ) { - KABC::Addressee a = (*eit).addressee; - if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) { - aList.append( a ) ; - } - } - } -#endif - return aList; -} - -KABC::Addressee::List -AddressesDialog::ccAddresses() const -{ - return allAddressee( d->ccItem ); -} - -KABC::Addressee::List -AddressesDialog::bccAddresses() const -{ - return allAddressee( d->bccItem ); -} - - -TQStringList -AddressesDialog::toDistributionLists() const -{ - return allDistributionLists( d->toItem ); -} - -TQStringList -AddressesDialog::ccDistributionLists() const -{ - return allDistributionLists( d->ccItem ); -} - -TQStringList -AddressesDialog::bccDistributionLists() const -{ - return allDistributionLists( d->bccItem ); -} - -void -AddressesDialog::updateAvailableAddressees() -{ - d->ui->mAvailableView->clear(); - d->groupDict.clear(); - - static const TQString &personalGroup = KGlobal::staticQString( i18n( "Other Addresses" ) ); - d->ui->mAvailableView->setRootIsDecorated( true ); - d->personal = new AddresseeViewItem( d->ui->mAvailableView, personalGroup ); - //connect(d->personal, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - // this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - d->personal->setVisible( false ); - d->groupDict.insert( personalGroup, d->personal ); - - KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); - for( KABC::AddressBook::Iterator it = addressBook->begin(); - it != addressBook->end(); ++it ) { - addAddresseeToAvailable( *it, d->personal ); - } - - d->recent = 0; - updateRecentAddresses(); - - d->topdist = 0; - addDistributionLists(); - if ( d->personal->childCount() > 0 ) { - d->personal->setOpen( true ); - d->personal->setVisible( true ); - } - - checkForSingleAvailableGroup(); -} - -void AddressesDialog::checkForSingleAvailableGroup() -{ - TQListViewItem* item = d->ui->mAvailableView->firstChild(); - TQListViewItem* firstGroup = 0; - int found = 0; - while (item) - { - if (item->isVisible()) - { - if (!firstGroup && static_cast(item)->category() != AddresseeViewItem::Entry) - { - firstGroup = item; - } - ++found; - } - item = item->nextSibling(); - } - - if (found == 1 && firstGroup) - { - firstGroup->setOpen(true); - } -} - -void -AddressesDialog::availableSelectionChanged() -{ - bool selection = !selectedAvailableAddresses.isEmpty(); - d->ui->mToButton->setEnabled(selection); - d->ui->mCCButton->setEnabled(selection); - d->ui->mBCCButton->setEnabled(selection); -} - -void -AddressesDialog::selectedSelectionChanged() -{ - bool selection = !selectedSelectedAddresses.isEmpty(); - d->ui->mRemoveButton->setEnabled(selection); -} - -void -AddressesDialog::availableAddressSelected( AddresseeViewItem* item, bool selected ) -{ - if (selected) - { - selectedAvailableAddresses.append(item); - } - else - { - selectedAvailableAddresses.remove(item); - } -} - -void -AddressesDialog::selectedAddressSelected( AddresseeViewItem* item, bool selected ) -{ - // we have to avoid that a parent and a child is selected together - // because in this case we get a double object deletion ( program crashes ) - // when removing the selected items from list - AddresseeViewItem* parent = static_cast(((TQListViewItem*)item)->parent()); - if ( parent && selected ) - parent->setSelected( false ); - if (selected) - { - selectedSelectedAddresses.append(item); - } - else - { - selectedSelectedAddresses.remove(item); - } - if ( selected ) { - AddresseeViewItem* child = static_cast(item->firstChild()); - while (child) { - child->setSelected( false ); - child = static_cast(child->nextSibling()); - } - } -} - -void -AddressesDialog::initConnections() -{ - connect( d->ui->mFilterEdit, TQT_SIGNAL(textChanged(const TQString &)), - TQT_SLOT(filterChanged(const TQString &)) ); - connect( d->ui->mToButton, TQT_SIGNAL(clicked()), - TQT_SLOT(addSelectedTo()) ); - connect( d->ui->mCCButton, TQT_SIGNAL(clicked()), - TQT_SLOT(addSelectedCC()) ); - connect( d->ui->mBCCButton, TQT_SIGNAL(clicked()), - TQT_SLOT(addSelectedBCC()) ); - connect( d->ui->mSaveAs, TQT_SIGNAL(clicked()), - TQT_SLOT(saveAs()) ); - connect( d->ui->mLdapSearch, TQT_SIGNAL(clicked()), - TQT_SLOT(searchLdap()) ); - connect( d->ui->mRemoveButton, TQT_SIGNAL(clicked()), - TQT_SLOT(removeEntry()) ); - connect( d->ui->mAvailableView, TQT_SIGNAL(selectionChanged()), - TQT_SLOT(availableSelectionChanged()) ); - connect( d->ui->mAvailableView, TQT_SIGNAL(doubleClicked(TQListViewItem*)), - TQT_SLOT(addSelectedTo()) ); - connect( d->ui->mSelectedView, TQT_SIGNAL(selectionChanged()), - TQT_SLOT(selectedSelectionChanged()) ); - connect( d->ui->mSelectedView, TQT_SIGNAL(doubleClicked(TQListViewItem*)), - TQT_SLOT(removeEntry()) ); - -#ifndef KDEPIM_NEW_DISTRLISTS - connect( KABC::DistributionListWatcher::self(), TQT_SIGNAL( changed() ), - this, TQT_SLOT( updateAvailableAddressees() ) ); -#endif - - connect( KABC::StdAddressBook::self( true ), TQT_SIGNAL( addressBookChanged(AddressBook*) ), - this, TQT_SLOT( updateAvailableAddressees() ) ); -} - -void -AddressesDialog::addAddresseeToAvailable( const KABC::Addressee& addr, AddresseeViewItem* defaultParent, bool useCategory ) -{ - if ( addr.preferredEmail().isEmpty() ) - return; - - if ( useCategory ) { - TQStringList categories = addr.categories(); - - for ( TQStringList::Iterator it = categories.begin(); it != categories.end(); ++it ) { - if ( !d->groupDict[ *it ] ) { //we don't have the category yet - AddresseeViewItem* category = new AddresseeViewItem( d->ui->mAvailableView, *it ); - d->groupDict.insert( *it, category ); - } - - for ( uint i = 0; i < addr.emails().count(); ++i ) { - AddresseeViewItem* addressee = new AddresseeViewItem( d->groupDict[ *it ], addr, i ); - connect(addressee, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(availableAddressSelected(AddresseeViewItem*, bool))); - } - } - } - - bool noCategory = false; - if ( useCategory ) { - if ( addr.categories().isEmpty() ) - noCategory = true; - } else - noCategory = true; - - if ( defaultParent && noCategory ) { // only non-categorized items here - AddresseeViewItem* addressee = new AddresseeViewItem( defaultParent, addr ); - connect(addressee, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(availableAddressSelected(AddresseeViewItem*, bool))); - } -} - -void -AddressesDialog::addAddresseeToSelected( const KABC::Addressee& addr, AddresseeViewItem* defaultParent ) -{ - if ( addr.preferredEmail().isEmpty() ) - return; - - if ( defaultParent ) { - AddresseeViewItem *myChild = static_cast( defaultParent->firstChild() ); - while( myChild ) { - if ( myChild->addressee().preferredEmail() == addr.preferredEmail() ) - return;//already got it - myChild = static_cast( myChild->nextSibling() ); - } - AddresseeViewItem* addressee = new AddresseeViewItem( defaultParent, addr ); - connect(addressee, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - defaultParent->setOpen( true ); - } - - d->ui->mSaveAs->setEnabled(true); -} - -void -AddressesDialog::addAddresseesToSelected( AddresseeViewItem *parent, - const TQPtrList& addresses ) -{ - Q_ASSERT( parent ); - - TQPtrListIterator itr( addresses ); - - if (itr.current()) - { - d->ui->mSaveAs->setEnabled(true); - } - - while ( itr.current() ) { - AddresseeViewItem* address = itr.current(); - ++itr; - - if (selectedToAvailableMapping.find(address) != 0) - { - continue; - } - - AddresseeViewItem* newItem = 0; - if (address->category() == AddresseeViewItem::Entry) - { - newItem = new AddresseeViewItem( parent, address->addressee() ); - } - else if (address->category() == AddresseeViewItem::DistList) - { - newItem = new AddresseeViewItem( parent, address->name() ); - } - else - { - newItem = new AddresseeViewItem( parent, address->name(), allAddressee( address ) ); - } - - address->setSelected( false ); - address->setVisible( false ); - selectedToAvailableMapping.insert(address, newItem); - selectedToAvailableMapping.insert(newItem, address); - connect(newItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - } - - parent->setOpen( true ); -} - -TQStringList -AddressesDialog::entryToString( const KABC::Addressee::List& l ) const -{ - TQStringList entries; - - for( KABC::Addressee::List::ConstIterator it = l.begin(); it != l.end(); ++it ) { - entries += (*it).fullEmail(); - } - return entries; -} - -void -AddressesDialog::addSelectedTo() -{ - if ( !d->toItem ) - { - d->toItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("To"), AddresseeViewItem::To ); - connect(d->toItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - } - - addAddresseesToSelected( d->toItem, selectedAvailableAddresses ); - selectedAvailableAddresses.clear(); - - if ( d->toItem->childCount() > 0 ) { - d->toItem->setVisible( true ); - } else { - delete d->toItem; - d->toItem = 0; - } -} - -void -AddressesDialog::addSelectedCC() -{ - if ( !d->ccItem ) - { - d->ccItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("CC"), AddresseeViewItem::CC ); - connect(d->ccItem , TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - } - - addAddresseesToSelected( d->ccItem, selectedAvailableAddresses ); - selectedAvailableAddresses.clear(); - - if ( d->ccItem->childCount() > 0 ) { - d->ccItem->setVisible( true ); - } else { - delete d->ccItem; - d->ccItem = 0; - } -} - -void -AddressesDialog::addSelectedBCC() -{ - if ( !d->bccItem ) - { - d->bccItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("BCC"), AddresseeViewItem::BCC ); - connect(d->bccItem , TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), - this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); - } - - addAddresseesToSelected( d->bccItem, selectedAvailableAddresses ); - selectedAvailableAddresses.clear(); - - if ( d->bccItem->childCount() > 0 ) { - d->bccItem->setVisible( true ); - } else { - delete d->bccItem; - d->bccItem = 0; - } -} - -void AddressesDialog::unmapSelectedAddress(AddresseeViewItem* item) -{ - AddresseeViewItem* correspondingItem = selectedToAvailableMapping[item]; - if (correspondingItem) - { - correspondingItem->setVisible( true ); - selectedToAvailableMapping.remove( item ); - selectedToAvailableMapping.remove( correspondingItem ); - } - - AddresseeViewItem* child = static_cast(item->firstChild()); - while (child) - { - unmapSelectedAddress(child); - child = static_cast(child->nextSibling()); - } -} - -void -AddressesDialog::removeEntry() -{ - TQPtrList lst; - bool resetTo = false; - bool resetCC = false; - bool resetBCC = false; - - lst.setAutoDelete( false ); - TQPtrListIterator it( selectedSelectedAddresses ); - while ( it.current() ) { - AddresseeViewItem* item = it.current(); - ++it; - if ( d->toItem == item ) - resetTo = true; - else if ( d->ccItem == item ) - resetCC = true; - else if( d->bccItem == item ) - resetBCC = true; - // we may only append parent items - unmapSelectedAddress(item); - lst.append( item ); - } - selectedSelectedAddresses.clear(); - lst.setAutoDelete( true ); - lst.clear(); - if ( resetTo ) - d->toItem = 0; - else if ( d->toItem && d->toItem->childCount() == 0 ) - { - delete d->toItem; - d->toItem = 0; - } - if ( resetCC ) - d->ccItem = 0; - else if ( d->ccItem && d->ccItem->childCount() == 0 ) - { - delete d->ccItem; - d->ccItem = 0; - } - if ( resetBCC ) - d->bccItem = 0; - else if ( d->bccItem && d->bccItem->childCount() == 0 ) - { - delete d->bccItem; - d->bccItem = 0; - } - d->ui->mSaveAs->setEnabled(d->ui->mSelectedView->firstChild() != 0); -} - -#ifdef KDEPIM_NEW_DISTRLISTS - -// copied from kabcore.cpp :( -// KDE4: should be in libkabc I think -static KABC::Resource *requestResource( KABC::AddressBook* abook, TQWidget *parent ) -{ - TQPtrList kabcResources = abook->resources(); - - TQPtrList kresResources; - TQPtrListIterator resIt( kabcResources ); - KABC::Resource *resource; - while ( ( resource = resIt.current() ) != 0 ) { - ++resIt; - if ( !resource->readOnly() ) { - KRES::Resource *res = static_cast( resource ); - if ( res ) - kresResources.append( res ); - } - } - - KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); - return static_cast( res ); -} -#endif - -void -AddressesDialog::saveAs() -{ -#ifndef KDEPIM_NEW_DISTRLISTS - KABC::DistributionListManager manager( KABC::StdAddressBook::self( true ) ); - manager.load(); -#endif - - if ( !d->ui->mSelectedView->firstChild() ) { - KMessageBox::information( 0, - i18n("There are no addresses in your list. " - "First add some addresses from your address book, " - "then try again.") ); - return; - } - - bool ok = false; - TQString name = KInputDialog::getText( i18n("New Distribution List"), - i18n("Please enter name:"), - TQString(), &ok, - this ); - if ( !ok || name.isEmpty() ) - return; - - bool alreadyExists = false; -#ifdef KDEPIM_NEW_DISTRLISTS - KABC::AddressBook* abook = KABC::StdAddressBook::self( true ); - KPIM::DistributionList dlist = KPIM::DistributionList::findByName( abook, name ); - alreadyExists = !dlist.isEmpty(); -#else - alreadyExists = manager.list( name ); -#endif - - if ( alreadyExists ) { - KMessageBox::information( 0, - i18n( "Distribution list with the given name %1 " - "already exists. Please select a different name." ) - .tqarg( name ) ); - return; - } - -#ifdef KDEPIM_NEW_DISTRLISTS - KABC::Resource* resource = requestResource( abook, this ); - if ( !resource ) - return; - - dlist.setResource( resource ); - dlist.setName( name ); - KABC::Addressee::List addrl = allAddressee( d->ui->mSelectedView, false ); - for ( KABC::Addressee::List::iterator itr = addrl.begin(); - itr != addrl.end(); ++itr ) { - dlist.insertEntry( *itr ); - } - abook->insertAddressee( dlist ); -#else - KABC::DistributionList *dlist = new KABC::DistributionList( &manager, name ); - KABC::Addressee::List addrl = allAddressee( d->ui->mSelectedView, false ); - for ( KABC::Addressee::List::iterator itr = addrl.begin(); - itr != addrl.end(); ++itr ) { - dlist->insertEntry( *itr ); - } - - manager.save(); -#endif -} - -void -AddressesDialog::searchLdap() -{ - if ( !d->ldapSearchDialog ) { - d->ldapSearchDialog = new LDAPSearchDialog( this ); - connect( d->ldapSearchDialog, TQT_SIGNAL( addresseesAdded() ), - TQT_SLOT(ldapSearchResult() ) ); - } - d->ldapSearchDialog->show(); -} - -void -AddressesDialog::ldapSearchResult() -{ - TQStringList emails = KPIM::splitEmailAddrList( d->ldapSearchDialog->selectedEMails() ); - TQStringList::iterator it( emails.begin() ); - TQStringList::iterator end( emails.end() ); - for ( ; it != end; ++it ){ - TQString name; - TQString email; - KPIM::getNameAndMail( (*it), name, email ); - KABC::Addressee ad; - ad.setNameFromString( name ); - ad.insertEmail( email ); - addAddresseeToSelected( ad, selectedToItem() ); - } -} - -void -AddressesDialog::launchAddressBook() -{ - kapp->startServiceByDesktopName( "kaddressbook", TQString() ); -} - -void -AddressesDialog::filterChanged( const TQString& txt ) -{ - TQListViewItemIterator it( d->ui->mAvailableView ); - bool showAll = false; - - if ( txt.isEmpty() ) - showAll = true; - - int personalVisible = 0; - int recentVisible = 0; - while ( it.current() ) { - AddresseeViewItem* item = static_cast( it.current() ); - ++it; - - if ( showAll ) { - item->setOpen( true ); - item->setVisible( true ); - // allen: I do not like the following behavior. comment out and see if anyone screams - //if ( item->category() == AddresseeViewItem::Group ) - // item->setOpen( false );//close to not have too many entries - continue; - } - - if ( item->category() == AddresseeViewItem::Entry ) { - bool matches = item->matches( txt ); - item->setVisible( matches ); - TQListViewItem *parent = static_cast( item )->parent(); - if ( matches && parent ) { - if ( parent == d->personal ) { - personalVisible++; - } else if ( parent == d->recent ) { - recentVisible++; - } - } - } - if ( item->category() == AddresseeViewItem::Group ) { - item->setOpen( true ); - item->setVisible( true ); - } - } - - if ( !showAll && personalVisible == 0 ) { - d->personal->setOpen( false ); - d->personal->setVisible( false ); - } - if ( !showAll && recentVisible == 0 ) { - d->recent->setOpen( false ); - d->recent->setVisible( false ); - } - - int distlistgroupVisible = 0; - if ( !showAll ) { - TQPtrListIterator it( d->dists ); - for ( ; it.current(); ++it ) { - TQListViewItem *p = *it; - p->setVisible( true ); - AddresseeViewItem *p2 = static_cast( p->firstChild() ); - int pcount = 0; - while ( p2 ) { - if ( p2->matches( txt ) ) { - p2->setVisible( true ); - pcount++; - } else { - p2->setVisible( false ); - } - p2 = static_cast( p2->nextSibling() ); - } - if ( !pcount && !p->text( 0 ).contains( txt, false ) ) { - p->setVisible( false ); - } - distlistgroupVisible += pcount; - if ( p->text( 0 ).contains( txt, false ) ) { - distlistgroupVisible++; - } - } - } - if ( d->topdist ) { - if ( showAll || distlistgroupVisible > 0 ) { - d->topdist->setOpen( true ); - } else { - d->topdist->setOpen( false ); - d->topdist->setVisible( false ); - } - } -} - -KABC::Addressee::List -AddressesDialog::allAddressee( KListView* view, bool onlySelected ) const -{ - KABC::Addressee::List lst; - TQListViewItemIterator it( view ); - while ( it.current() ) { - AddresseeViewItem* item = static_cast( it.current() ); - if ( !onlySelected || item->isSelected() ) { - if ( item->category() != AddresseeViewItem::Entry ) { - AddresseeViewItem *myChild = static_cast( item->firstChild() ); - while( myChild ) { - lst.append( myChild->addressee() ); - myChild = static_cast( myChild->nextSibling() ); - } - } else { - lst.append( item->addressee() ); - } - } - ++it; - } - - return lst; -} - -KABC::Addressee::List -AddressesDialog::allAddressee( AddresseeViewItem* parent ) const -{ - KABC::Addressee::List lst; - - if ( !parent ) return lst; - - if ( parent->category() == AddresseeViewItem::Entry ) - { - lst.append( parent->addressee() ); - return lst; - } - - AddresseeViewItem *myChild = static_cast( parent->firstChild() ); - while( myChild ) { - if ( myChild->category() == AddresseeViewItem::FilledGroup ) - lst += myChild->addresses(); - else if ( !myChild->addressee().isEmpty() ) - lst.append( myChild->addressee() ); - myChild = static_cast( myChild->nextSibling() ); - } - - return lst; -} - -TQStringList -AddressesDialog::allDistributionLists( AddresseeViewItem* parent ) const -{ - TQStringList lists; - - if ( !parent ) - return TQStringList(); - - AddresseeViewItem *item = static_cast( parent->firstChild() ); - while ( item ) { - if ( item->category() == AddresseeViewItem::DistList && !item->name().isEmpty() ) - lists.append( item->name() ); - - item = static_cast( item->nextSibling() ); - } - - return lists; -} - -void -AddressesDialog::addDistributionLists() -{ - KABC::AddressBook* abook = KABC::StdAddressBook::self( true ); - -#ifdef KDEPIM_NEW_DISTRLISTS - const TQValueList distLists = - KPIM::DistributionList::allDistributionLists( abook ); -#else - KABC::DistributionListManager manager( abook ); - manager.load(); - - TQStringList distLists = manager.listNames(); -#endif - - if ( distLists.isEmpty() ) - return; - - if ( !d->topdist ) { - d->topdist = new AddresseeViewItem( d->ui->mAvailableView, i18n( "Distribution Lists" ) ); - } - -#ifdef KDEPIM_NEW_DISTRLISTS - TQValueList::ConstIterator listIt; -#else - TQStringList::Iterator listIt; -#endif - int total = 0; - for ( listIt = distLists.begin(); listIt != distLists.end(); ++listIt ) { -#ifdef KDEPIM_NEW_DISTRLISTS - KPIM::DistributionList dlist = *listIt; - KPIM::DistributionList::Entry::List entries = dlist.entries(abook); -#else - KABC::DistributionList& dlist = *manager.list( *listIt ); - KABC::DistributionList::Entry::List entries = dlist.entries(); -#endif - - AddresseeViewItem *item = new AddresseeViewItem( d->topdist, dlist.name() ); - d->dists.append( item ); - connect( item, TQT_SIGNAL( addressSelected( AddresseeViewItem*, bool ) ), - this, TQT_SLOT( availableAddressSelected( AddresseeViewItem*, bool ) ) ); - -#ifdef KDEPIM_NEW_DISTRLISTS - KPIM::DistributionList::Entry::List::Iterator itemIt; -#else - KABC::DistributionList::Entry::List::Iterator itemIt; -#endif - for ( itemIt = entries.begin(); itemIt != entries.end(); ++itemIt ) { - addAddresseeToAvailable( (*itemIt).addressee, item, false ); - } - if ( item->childCount() > 0 ) { - item->setOpen( true ); - item->setVisible( true ); - } - total += item->childCount(); - } - if ( total > 0 ) { - d->topdist->setOpen( true ); - d->topdist->setVisible( true ); - } -} - -} // namespace - -#include "addressesdialog.moc" diff --git a/libkdepim/addressesdialog.h b/libkdepim/addressesdialog.h deleted file mode 100644 index c553c6421..000000000 --- a/libkdepim/addressesdialog.h +++ /dev/null @@ -1,223 +0,0 @@ -/* -*- mode: C++; c-file-style: "gnu" -*- - * - * This file is part of libtdepim. - * - * Copyright (c) 2003 Zack Rusin - * Copyright (c) 2003 Aaron J. Seigo - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef ADDRESSESDIALOG_H -#define ADDRESSESDIALOG_H - -#include -#include -#include -#include -#include -#include -#include - -namespace KPIM { - - class AddresseeViewItem : public TQObject, public KListViewItem - { - Q_OBJECT - TQ_OBJECT - - public: - enum Category { - To =0, - CC =1, - BCC =2, - Group =3, - Entry =4, - FilledGroup =5, - DistList =6 - }; - AddresseeViewItem( AddresseeViewItem *parent, const KABC::Addressee& addr, int emailIndex = 0 ); - AddresseeViewItem( KListView *lv, const TQString& name, Category cat=Group ); - AddresseeViewItem( AddresseeViewItem *parent, const TQString& name, const KABC::Addressee::List &lst ); - AddresseeViewItem( AddresseeViewItem *parent, const TQString& name ); - ~AddresseeViewItem(); - - KABC::Addressee addressee() const; - KABC::Addressee::List addresses() const; - Category category() const; - - TQString name() const; - TQString email() const; - - bool matches( const TQString& ) const; - - virtual int compare( TQListViewItem * i, int col, bool ascending ) const; - virtual void setSelected( bool ); - - signals: - void addressSelected( AddresseeViewItem*, bool ); - - private: - struct AddresseeViewItemPrivate; - AddresseeViewItemPrivate *d; - }; - - class KDE_EXPORT AddressesDialog : public KDialogBase - { - Q_OBJECT - TQ_OBJECT - public: - AddressesDialog( TQWidget *widget=0, const char *name=0 ); - ~AddressesDialog(); - - /** - * Returns the list of picked "To" addresses as a TQStringList. - */ - TQStringList to() const; - /** - * Returns the list of picked "CC" addresses as a TQStringList. - */ - TQStringList cc() const; - /** - * Returns the list of picked "BCC" addresses as a TQStringList. - */ - TQStringList bcc() const; - - /** - * Returns the list of picked "To" addresses as KABC::Addressee::List. - * Note that this doesn't include the distribution lists - */ - KABC::Addressee::List toAddresses() const; - /** - * Returns the list of picked "To" addresses as KABC::Addressee::List. - * Note that this does include the distribution lists - * Multiple Addressees are removed - */ - KABC::Addressee::List allToAddressesNoDuplicates() const; - /** - * Returns the list of picked "CC" addresses as KABC::Addressee::List. - * Note that this doesn't include the distribution lists - */ - KABC::Addressee::List ccAddresses() const; - /** - * Returns the list of picked "BCC" addresses as KABC::Addressee::List. - * Note that this doesn't include the distribution lists - */ - KABC::Addressee::List bccAddresses() const; - - /** - * Returns the list of picked "To" distribution lists. - * This complements @ref toAddresses. - */ - TQStringList toDistributionLists() const; - /** - * Returns the list of picked "CC" distribution lists. - * This complements @ref ccAddresses. - */ - TQStringList ccDistributionLists() const; - /** - * Returns the list of picked "BCC" distribution lists. - * This complements @ref bccAddresses. - */ - TQStringList bccDistributionLists() const; - - public slots: - /** - * Displays the CC field if @p b is true, else - * hides it. By default displays it. - */ - void setShowCC( bool b ); - /** - * Displays the BCC field if @p b is true, else - * hides it. By default displays it. - */ - void setShowBCC( bool b ); - /** - * If called adds "Recent Addresses" item to the picker list view, - * with the addresses given in @p addr. - */ - void setRecentAddresses( const KABC::Addressee::List& addr ); - /** - * Adds addresses in @p l to the selected "To" group. - */ - void setSelectedTo( const TQStringList& l ); - /** - * Adds addresses in @p l to the selected "CC" group. - */ - void setSelectedCC( const TQStringList& l ); - /** - * Adds addresses in @p l to the selected "BCC" group. - */ - void setSelectedBCC( const TQStringList& l ); - - protected slots: - void addSelectedTo(); - void addSelectedCC(); - void addSelectedBCC(); - - void removeEntry(); - void saveAs(); - void searchLdap(); - void ldapSearchResult(); - void launchAddressBook(); - - void filterChanged( const TQString & ); - - void updateAvailableAddressees(); - void availableSelectionChanged(); - void selectedSelectionChanged(); - void availableAddressSelected( AddresseeViewItem* item, bool selected ); - void selectedAddressSelected( AddresseeViewItem* item, bool selected ); - - protected: - AddresseeViewItem* selectedToItem(); - AddresseeViewItem* selectedCcItem(); - AddresseeViewItem* selectedBccItem(); - - void initConnections(); - void addDistributionLists(); - void addAddresseeToAvailable( const KABC::Addressee& addr, - AddresseeViewItem* defaultParent=0, bool useCategory=true ); - void addAddresseeToSelected( const KABC::Addressee& addr, - AddresseeViewItem* defaultParent=0 ); - void addAddresseesToSelected( AddresseeViewItem *parent, - const TQPtrList& addresses ); - TQStringList entryToString( const KABC::Addressee::List& l ) const; - KABC::Addressee::List allAddressee( AddresseeViewItem* parent ) const; - KABC::Addressee::List allAddressee( KListView* view, bool onlySelected = true ) const; - TQStringList allDistributionLists( AddresseeViewItem* parent ) const; - - private: - // if there's only one group in the available list, open it - void checkForSingleAvailableGroup(); - - // used to re-show items in the available list - // it is recursive, but should only ever recurse once so should be fine - void unmapSelectedAddress(AddresseeViewItem* item); - void updateRecentAddresses(); - - struct AddressesDialogPrivate; - AddressesDialogPrivate *d; - - TQPtrList selectedAvailableAddresses; - TQPtrList selectedSelectedAddresses; - TQPtrDict selectedToAvailableMapping; - }; - -} - -#endif /* ADDRESSESDIALOG_H */ diff --git a/libkdepim/addresspicker.ui b/libkdepim/addresspicker.ui deleted file mode 100644 index fc88d52a0..000000000 --- a/libkdepim/addresspicker.ui +++ /dev/null @@ -1,327 +0,0 @@ - -AddressPickerUI - - - AddressPickerUI - - - - 0 - 0 - 591 - 442 - - - - Address Selection - - - - unnamed - - - - - Name - - - true - - - true - - - - - Email Address - - - true - - - true - - - - mAvailableView - - - Extended - - - true - - - true - - - true - - - AllColumns - - - true - - - - - tqlayout10 - - - - unnamed - - - - spacer1 - - - Vertical - - - Expanding - - - - 20 - 16 - - - - - - mToButton - - - false - - - &To >> - - - - - mCCButton - - - false - - - &CC >> - - - - - mBCCButton - - - false - - - &BCC >> - - - - - spacer2 - - - Vertical - - - Expanding - - - - 20 - 16 - - - - - - mRemoveButton - - - false - - - << &Remove - - - - - spacer2_2 - - - Vertical - - - Expanding - - - - 20 - 20 - - - - - - - - textLabel2 - - - - 1 - - - - &Selected Addresses - - - WordBreak|AlignCenter - - - mSelectedView - - - - - textLabel1 - - - - 1 - - - - &Address Book - - - WordBreak|AlignCenter - - - mAvailableView - - - - - tqlayout1 - - - - unnamed - - - - TextLabel2 - - - &Filter on: - - - mFilterEdit - - - - - mFilterEdit - - - - 7 - 0 - 1 - 0 - - - - - - - - - - - - Name - - - true - - - true - - - - - Email Address - - - true - - - true - - - - mSelectedView - - - Extended - - - true - - - true - - - true - - - AllColumns - - - true - - - - - mSaveAs - - - false - - - Save as &Distribution List... - - - Alt+D - - - - - mLdapSearch - - - &Search Directory Service - - - - - - - - - klistview.h - kpushbutton.h - kpushbutton.h - kpushbutton.h - kpushbutton.h - klistview.h - - diff --git a/libkdepim/alarmclient.cpp b/libkdepim/alarmclient.cpp deleted file mode 100644 index 5616cd029..000000000 --- a/libkdepim/alarmclient.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - This file is part of KOrganizer. - - Copyright (c) 2003 Cornelius Schumacher - Copyright (c) 2005 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "alarmclient.h" - -#include -#include -#include - -#include -#include - -AlarmClient::AlarmClient() -{ - kdDebug(5850) << "AlarmClient::AlarmClient()" << endl; -} - -void AlarmClient::startDaemon() -{ - if ( kapp->dcopClient()->isApplicationRegistered( "korgac" ) ) { - // Alarm daemon already runs - return; - } - - KGlobal::dirs()->addResourceType("autostart", "share/autostart"); - TQString desktopFile = locate( "autostart", "korgac.desktop" ); - if ( desktopFile.isEmpty() ) { - kdWarning() << "Couldn't find autostart/korgac.desktop!" << endl; - } - else { - TQString error; - if ( kapp->startServiceByDesktopPath( desktopFile, TQStringList(), &error ) != 0 ) - kdWarning() << "Failure starting korgac:" << error << endl; - } -} - -void AlarmClient::stopDaemon() -{ - DCOPRef ref( "korgac", "ac" ); - ref.send( "quit" ); -} diff --git a/libkdepim/alarmclient.h b/libkdepim/alarmclient.h deleted file mode 100644 index 2d294143d..000000000 --- a/libkdepim/alarmclient.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - This file is part of the KOrganizer interfaces. - - Copyright (c) 2003 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef ALARMCLIENT_H -#define ALARMCLIENT_H - -/** - This class provides the interface for communicating with the alarm daemon. It - can be subclassed for specific daemons. -*/ -class AlarmClient -{ - public: - AlarmClient(); - - /** - Start alarm daemon. - */ - virtual void startDaemon(); - - /** - Stop alarm daemon. - */ - virtual void stopDaemon(); -}; - -#endif diff --git a/libkdepim/broadcaststatus.cpp b/libkdepim/broadcaststatus.cpp deleted file mode 100644 index a50479195..000000000 --- a/libkdepim/broadcaststatus.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - broadcaststatus.cpp - - This file is part of KDEPIM. - - Author: Don Sanders - - Copyright (C) 2000 Don Sanders - - License GPL -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include -#include -#include - -#include "broadcaststatus.h" -#include "progressmanager.h" - -KPIM::BroadcastStatus* KPIM::BroadcastStatus::instance_ = 0; -static KStaticDeleter broadcasStatusDeleter; - -namespace KPIM { - -BroadcastStatus* BroadcastStatus::instance() -{ - if (!instance_) - broadcasStatusDeleter.setObject( instance_, new BroadcastStatus() ); - - return instance_; -} - -BroadcastStatus::BroadcastStatus() - :mTransientActive( false ) -{ -} - -BroadcastStatus::~BroadcastStatus() -{ - instance_ = 0; -} - -void BroadcastStatus::seStatusMsg( const TQString& message ) -{ - mStatusMsg = message; - if( !mTransientActive ) - emit statusMsg( message ); -} - -void BroadcastStatus::seStatusMsgWithTimestamp( const TQString& message ) -{ - KLocale* locale = KGlobal::locale(); - seStatusMsg( i18n( "%1 is a time, %2 is a status message", "[%1] %2" ) - .tqarg( locale->formatTime( TQTime::currentTime(), - true /* with seconds */ ) ) - .tqarg( message ) ); -} - -void BroadcastStatus::seStatusMsgTransmissionCompleted( int numMessages, - int numBytes, - int numBytesRead, - int numBytesToRead, - bool mLeaveOnServer, - KPIM::ProgressItem* item ) -{ - TQString statusMsg; - if( numMessages > 0 ) { - if( numBytes != -1 ) { - if( ( numBytesToRead != numBytes ) && mLeaveOnServer ) - statusMsg = i18n( "Transmission complete. %n new message in %1 KB " - "(%2 KB remaining on the server).", - "Transmission complete. %n new messages in %1 KB " - "(%2 KB remaining on the server).", - numMessages ) - .tqarg( numBytesRead / 1024 ) - .tqarg( numBytes / 1024 ); - else - statusMsg = i18n( "Transmission complete. %n message in %1 KB.", - "Transmission complete. %n messages in %1 KB.", - numMessages ) - .tqarg( numBytesRead / 1024 ); - } - else - statusMsg = i18n( "Transmission complete. %n new message.", - "Transmission complete. %n new messages.", - numMessages ); - } - else - statusMsg = i18n( "Transmission complete. No new messages." ); - - seStatusMsgWithTimestamp( statusMsg ); - if ( item ) - item->setqStatus( statusMsg ); -} - -void BroadcastStatus::seStatusMsgTransmissionCompleted( const TQString& account, - int numMessages, - int numBytes, - int numBytesRead, - int numBytesToRead, - bool mLeaveOnServer, - KPIM::ProgressItem* item ) -{ - TQString statusMsg; - if( numMessages > 0 ) { - if( numBytes != -1 ) { - if( ( numBytesToRead != numBytes ) && mLeaveOnServer ) - statusMsg = i18n( "Transmission for account %3 complete. " - "%n new message in %1 KB " - "(%2 KB remaining on the server).", - "Transmission for account %3 complete. " - "%n new messages in %1 KB " - "(%2 KB remaining on the server).", - numMessages ) - .tqarg( numBytesRead / 1024 ) - .tqarg( numBytes / 1024 ) - .tqarg( account ); - else - statusMsg = i18n( "Transmission for account %2 complete. " - "%n message in %1 KB.", - "Transmission for account %2 complete. " - "%n messages in %1 KB.", - numMessages ) - .tqarg( numBytesRead / 1024 ) - .tqarg( account ); - } - else - statusMsg = i18n( "Transmission for account %1 complete. " - "%n new message.", - "Transmission for account %1 complete. " - "%n new messages.", - numMessages ) - .tqarg( account ); - } - else - statusMsg = i18n( "Transmission for account %1 complete. No new messages.") - .tqarg( account ); - - seStatusMsgWithTimestamp( statusMsg ); - if ( item ) - item->setqStatus( statusMsg ); -} - -void BroadcastStatus::setTransienStatusMsg( const TQString& msg ) -{ - mTransientActive = true; - emit statusMsg( msg ); -} - -void BroadcastStatus::reset() -{ - mTransientActive = false; - // restore - emit statusMsg( mStatusMsg ); -} - -} - -#include "broadcaststatus.moc" diff --git a/libkdepim/broadcaststatus.h b/libkdepim/broadcaststatus.h deleted file mode 100644 index c29e0ff05..000000000 --- a/libkdepim/broadcaststatus.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - broadcaststatus.h - - This file is part of KDEPIM. - - Copyright (C) 2000 Don Sanders - - License GPL -*/ - -#ifndef __kpim_broadcast_status_h -#define __kpim_broadcast_status_h - -#include -#include - -#include - -#undef None - -namespace KPIM { - -class ProgressItem; - -/** - Provides a singleton which broadcasts status messages by emitting - signals. Interested mainwindows can connect to the statusMsg() - signal and update statusBars or whatever they use for showing status. - */ - - -class KDE_EXPORT BroadcastStatus : public TQObject -{ - - Q_OBJECT - TQ_OBJECT - -public: - virtual ~BroadcastStatus(); - - /** Return the instance of the singleton object for this class */ - static BroadcastStatus *instance(); - - /** Return the last status message from seStatusMsg() */ - TQString statusMsg() const { return mStatusMsg; } - /** Sets a status bar message with timestamp */ - void seStatusMsgWithTimestamp( const TQString& message ); - /** Sets a transmission completed status bar message */ - void seStatusMsgTransmissionCompleted( int numMessages, - int numBytes = -1, - int numBytesRead = -1, - int numBytesToRead = -1, - bool mLeaveOnServer = false, - KPIM::ProgressItem* progressItem = 0 ); // set the same status in this progress item - void seStatusMsgTransmissionCompleted( const TQString& account, - int numMessages, - int numBytes = -1, - int numBytesRead = -1, - int numBytesToRead = -1, - bool mLeaveOnServer = false, - KPIM::ProgressItem* progressItem = 0 ); // set the same status in this progress item - -public slots: - /** Emit an update status bar signal. It's a slot so it can be hooked up - to other signals. */ - void seStatusMsg( const TQString& message ); - - /** - Set a status message that will go away again with the next call of - reset(). - */ - void setTransienStatusMsg( const TQString& msg ); - /** - Reset the status message to what ever non-transient message was last - active or has since been set. - */ - void reset(); - -signals: - - /** Emitted when seStatusMsg is called. */ - void statusMsg( const TQString& ); - -protected: - - BroadcastStatus(); - TQString mStatusMsg; - bool mTransientActive; - static BroadcastStatus* instance_; -}; - - -} -#endif diff --git a/libkdepim/calendardiffalgo.cpp b/libkdepim/calendardiffalgo.cpp deleted file mode 100644 index 587d0dc0c..000000000 --- a/libkdepim/calendardiffalgo.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include - -#include "calendardiffalgo.h" - -using namespace KPIM; - -#ifndef KDE_USE_FINAL -static bool compareString( const TQString &left, const TQString &right ) -{ - if ( left.isEmpty() && right.isEmpty() ) - return true; - else - return left == right; -} -#endif - -static TQString toString( KCal::Attendee *attendee ) -{ - return attendee->name() + "<" + attendee->email() + ">"; -} - -static TQString toString( KCal::Alarm * ) -{ - return TQString(); -} - -static TQString toString( KCal::Incidence * ) -{ - return TQString(); -} - -static TQString toString( KCal::Attachment * ) -{ - return TQString(); -} - -static TQString toString( const TQDate &date ) -{ - return date.toString(); -} - -static TQString toString( const TQDateTime &dateTime ) -{ - return dateTime.toString(); -} - -static TQString toString( const TQString str ) -{ - return str; -} - -static TQString toString( bool value ) -{ - if ( value ) - return i18n( "Yes" ); - else - return i18n( "No" ); -} - -CalendarDiffAlgo::CalendarDiffAlgo( KCal::Incidence *leftIncidence, - KCal::Incidence *rightIncidence ) - : mLeftIncidence( leftIncidence ), mRightIncidence( rightIncidence ) -{ -} - -void CalendarDiffAlgo::run() -{ - begin(); - - diffIncidenceBase( mLeftIncidence, mRightIncidence ); - diffIncidence( mLeftIncidence, mRightIncidence ); - - KCal::Event *leftEvent = dynamic_cast( mLeftIncidence ); - KCal::Event *rightEvent = dynamic_cast( mRightIncidence ); - if ( leftEvent && rightEvent ) { - diffEvent( leftEvent, rightEvent ); - } else { - KCal::Todo *leftTodo = dynamic_cast( mLeftIncidence ); - KCal::Todo *rightTodo = dynamic_cast( mRightIncidence ); - if ( leftTodo && rightTodo ) { - diffTodo( leftTodo, rightTodo ); - } - } - - end(); -} - -void CalendarDiffAlgo::diffIncidenceBase( KCal::IncidenceBase *left, KCal::IncidenceBase *right ) -{ - diffList( i18n( "Attendees" ), left->attendees(), right->attendees() ); - - if ( left->dtStart() != right->dtStart() ) - conflictField( i18n( "Start time" ), left->dtStartStr(), right->dtStartStr() ); - - if ( !compareString( left->organizer().fullName(), right->organizer().fullName() ) ) - conflictField( i18n( "Organizer" ), left->organizer().fullName(), right->organizer().fullName() ); - - if ( !compareString( left->uid(), right->uid() ) ) - conflictField( i18n( "UID" ), left->uid(), right->uid() ); - - if ( left->doesFloat() != right->doesFloat() ) - conflictField( i18n( "Is floating" ), toString( left->doesFloat() ), toString( right->doesFloat() ) ); - - if ( left->hasDuration() != right->hasDuration() ) - conflictField( i18n( "Has duration" ), toString( left->hasDuration() ), toString( right->hasDuration() ) ); - - if ( left->duration() != right->duration() ) - conflictField( i18n( "Duration" ), TQString::number( left->duration() ), TQString::number( right->duration() ) ); -} - -void CalendarDiffAlgo::diffIncidence( KCal::Incidence *left, KCal::Incidence *right ) -{ - if ( !compareString( left->description(), right->description() ) ) - conflictField( i18n( "Description" ), left->description(), right->description() ); - - if ( !compareString( left->summary(), right->summary() ) ) - conflictField( i18n( "Summary" ), left->summary(), right->summary() ); - - if ( left->status() != right->status() ) - conflictField( i18n( "Status" ), left->statusStr(), right->statusStr() ); - - if ( left->secrecy() != right->secrecy() ) - conflictField( i18n( "Secrecy" ), toString( left->secrecy() ), toString( right->secrecy() ) ); - - if ( left->priority() != right->priority() ) - conflictField( i18n( "Priority" ), toString( left->priority() ), toString( right->priority() ) ); - - if ( !compareString( left->location(), right->location() ) ) - conflictField( i18n( "Location" ), left->location(), right->location() ); - - diffList( i18n( "Categories" ), left->categories(), right->categories() ); - diffList( i18n( "Alarms" ), left->alarms(), right->alarms() ); - diffList( i18n( "Resources" ), left->resources(), right->resources() ); - diffList( i18n( "Relations" ), left->relations(), right->relations() ); - diffList( i18n( "Attachments" ), left->attachments(), right->attachments() ); - diffList( i18n( "Exception Dates" ), left->recurrence()->exDates(), right->recurrence()->exDates() ); - diffList( i18n( "Exception Times" ), left->recurrence()->exDateTimes(), right->recurrence()->exDateTimes() ); - // TODO: recurrence dates and date/times, exrules, rrules - - if ( left->created() != right->created() ) - conflictField( i18n( "Created" ), left->created().toString(), right->created().toString() ); - - if ( !compareString( left->relatedToUid(), right->relatedToUid() ) ) - conflictField( i18n( "Related Uid" ), left->relatedToUid(), right->relatedToUid() ); -} - -void CalendarDiffAlgo::diffEvent( KCal::Event *left, KCal::Event *right ) -{ - if ( left->hasEndDate() != right->hasEndDate() ) - conflictField( i18n( "Has End Date" ), toString( left->hasEndDate() ), toString( right->hasEndDate() ) ); - - if ( left->dtEnd() != right->dtEnd() ) - conflictField( i18n( "End Date" ), left->dtEndStr(), right->dtEndStr() ); - - // TODO: check transparency -} - -void CalendarDiffAlgo::diffTodo( KCal::Todo *left, KCal::Todo *right ) -{ - if ( left->hasStartDate() != right->hasStartDate() ) - conflictField( i18n( "Has Start Date" ), toString( left->hasStartDate() ), toString( right->hasStartDate() ) ); - - if ( left->hasDueDate() != right->hasDueDate() ) - conflictField( i18n( "Has Due Date" ), toString( left->hasDueDate() ), toString( right->hasDueDate() ) ); - - if ( left->dtDue() != right->dtDue() ) - conflictField( i18n( "Due Date" ), left->dtDue().toString(), right->dtDue().toString() ); - - if ( left->hasCompletedDate() != right->hasCompletedDate() ) - conflictField( i18n( "Has Complete Date" ), toString( left->hasCompletedDate() ), toString( right->hasCompletedDate() ) ); - - if ( left->percentComplete() != right->percentComplete() ) - conflictField( i18n( "Complete" ), TQString::number( left->percentComplete() ), TQString::number( right->percentComplete() ) ); - - if ( left->completed() != right->completed() ) - conflictField( i18n( "Completed" ), toString( left->completed() ), toString( right->completed() ) ); -} - -template -void CalendarDiffAlgo::diffList( const TQString &id, - const TQValueList &left, const TQValueList &right ) -{ - for ( uint i = 0; i < left.count(); ++i ) { - if ( right.find( left[ i ] ) == right.end() ) - additionalLeftField( id, toString( left[ i ] ) ); - } - - for ( uint i = 0; i < right.count(); ++i ) { - if ( left.find( right[ i ] ) == left.end() ) - additionalRightField( id, toString( right[ i ] ) ); - } -} diff --git a/libkdepim/calendardiffalgo.h b/libkdepim/calendardiffalgo.h deleted file mode 100644 index 9ccd6c8c0..000000000 --- a/libkdepim/calendardiffalgo.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPIM_CALENDARDIFFALGO_H -#define KPIM_CALENDARDIFFALGO_H - -#include "diffalgo.h" - -#include -#include - -namespace KPIM { - -class KDE_EXPORT CalendarDiffAlgo : public DiffAlgo -{ - public: - CalendarDiffAlgo( KCal::Incidence *leftIncidence, KCal::Incidence *rightIncidence ); - - void run(); - - private: - template - void diffList( const TQString &id, const TQValueList &left, const TQValueList &right ); - - void diffIncidenceBase( KCal::IncidenceBase*, KCal::IncidenceBase* ); - void diffIncidence( KCal::Incidence*, KCal::Incidence* ); - void diffEvent( KCal::Event*, KCal::Event* ); - void diffTodo( KCal::Todo*, KCal::Todo* ); - - KCal::Incidence *mLeftIncidence; - KCal::Incidence *mRightIncidence; -}; - -} - -#endif diff --git a/libkdepim/categoryeditdialog.cpp b/libkdepim/categoryeditdialog.cpp deleted file mode 100644 index 72e1de8ae..000000000 --- a/libkdepim/categoryeditdialog.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2000, 2001, 2002 Cornelius Schumacher - Copyright (C) 2003-2004 Reinhold Kainhofer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "kpimprefs.h" - -#include "categoryeditdialog.h" - -using namespace KPIM; - -class CategoryEditDialog::Private -{ - public: - TQListView *mView; - TQPushButton *mAddButton; - TQPushButton *mEditButton; - TQPushButton *mDeleteButton; -}; - -class CategoryListViewItem : public TQListViewItem -{ - public: - CategoryListViewItem( TQListView *view, const TQString &text ) : - TQListViewItem( view, text ) - { - } - - void okRename ( int col ) // we need that public to explicitly accept renaming when closing the dialog - { - TQListViewItem::okRename( col ); - } -}; - -CategoryEditDialog::CategoryEditDialog( KPimPrefs *prefs, TQWidget* parent, - const char* name, bool modal ) - : KDialogBase::KDialogBase( parent, name, modal, - i18n("Edit Categories"), Ok|Apply|Cancel|Help, Ok, true ), - mPrefs( prefs ), d( new Private ) -{ - TQWidget *widget = new TQWidget( this ); - setMainWidget( widget ); - - TQGridLayout *tqlayout = new TQGridLayout( widget, 4, 2, marginHint(), spacingHint() ); - - d->mView = new TQListView( widget ); - d->mView->addColumn( "" ); - d->mView->header()->hide(); - d->mView->setDefaultRenameAction( TQListView::Accept ); - - tqlayout->addMultiCellWidget( d->mView, 0, 3, 0, 0 ); - - d->mAddButton = new TQPushButton( i18n( "Add" ), widget ); - tqlayout->addWidget( d->mAddButton, 0, 1 ); - - d->mEditButton = new TQPushButton( i18n( "Edit" ), widget ); - tqlayout->addWidget( d->mEditButton, 1, 1 ); - - d->mDeleteButton = new TQPushButton( i18n( "Remove" ), widget ); - tqlayout->addWidget( d->mDeleteButton, 2, 1 ); - - - fillList(); - - connect( d->mAddButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( add() ) ); - connect( d->mEditButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( edit() ) ); - connect( d->mDeleteButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( remove() ) ); -} - -/* - * Destroys the object and frees any allocated resources - */ -CategoryEditDialog::~CategoryEditDialog() -{ - delete d; -} - -void CategoryEditDialog::fillList() -{ - d->mView->clear(); - TQStringList::Iterator it; - bool categoriesExist=false; - for ( it = mPrefs->mCustomCategories.begin(); - it != mPrefs->mCustomCategories.end(); ++it ) { - - TQListViewItem *item = new CategoryListViewItem( d->mView, *it ); - item->setRenameEnabled( 0, true ); - - categoriesExist = true; - } - - d->mEditButton->setEnabled( categoriesExist ); - d->mDeleteButton->setEnabled( categoriesExist ); - d->mView->setSelected( d->mView->firstChild(), true ); -} - -void CategoryEditDialog::add() -{ - if ( d->mView->firstChild() ) - d->mView->setCurrentItem( d->mView->firstChild() ); - - TQListViewItem *item = new CategoryListViewItem( d->mView, i18n( "New category" ) ); - item->setRenameEnabled( 0, true ); - - d->mView->setSelected( item, true ); - d->mView->ensureItemVisible( item ); - item->startRename( 0 ); - - bool itemCount = d->mView->childCount() > 0; - d->mEditButton->setEnabled( itemCount ); - d->mDeleteButton->setEnabled( itemCount ); -} - -void CategoryEditDialog::edit() -{ - if ( d->mView->currentItem() ) - d->mView->currentItem()->startRename( 0 ); -} - -void CategoryEditDialog::remove() -{ - if ( d->mView->currentItem() ) { - delete d->mView->currentItem(); - - d->mView->setSelected( d->mView->currentItem(), true ); - - bool itemCount = d->mView->childCount() > 0; - d->mEditButton->setEnabled( itemCount ); - d->mDeleteButton->setEnabled( itemCount ); - } -} - -void CategoryEditDialog::slotOk() -{ - // accept the currently ongoing rename - if ( d->mView->selectedItem() ) - static_cast( d->mView->selectedItem() )->okRename( 0 ); - slotApply(); - accept(); -} - -void CategoryEditDialog::slotApply() -{ - mPrefs->mCustomCategories.clear(); - - TQListViewItem *item = d->mView->firstChild(); - while ( item ) { - if ( !item->text( 0 ).isEmpty() ) - mPrefs->mCustomCategories.append( item->text( 0 ) ); - item = item->nextSibling(); - } - mPrefs->writeConfig(); - - emit categoryConfigChanged(); -} - -void CategoryEditDialog::slotCancel() -{ - reload(); - KDialogBase::slotCancel(); -} - -void CategoryEditDialog::reload() -{ - fillList(); -} - -#include "categoryeditdialog.moc" diff --git a/libkdepim/categoryeditdialog.h b/libkdepim/categoryeditdialog.h deleted file mode 100644 index 064f8b682..000000000 --- a/libkdepim/categoryeditdialog.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2000, 2001, 2002 Cornelius Schumacher - Copyright (C) 2003-2004 Reinhold Kainhofer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KPIM_CATEGORYEDITDIALOG_H -#define KPIM_CATEGORYEDITDIALOG_H - -#include -#include - -class KPimPrefs; - -namespace KPIM { - -class KDE_EXPORT CategoryEditDialog : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT - public: - CategoryEditDialog( KPimPrefs *prefs, TQWidget* parent = 0, - const char* name = 0, - bool modal = false ); - ~CategoryEditDialog(); - - public slots: - void reload(); - - protected slots: - void slotOk(); - void slotApply(); - void slotCancel(); - void add(); - void edit(); - void remove(); - - signals: - void categoryConfigChanged(); - - protected: - void fillList(); - - private: - KPimPrefs *mPrefs; - class Private; - Private* const d; -}; - -} - -#endif diff --git a/libkdepim/categoryeditdialog_base.ui b/libkdepim/categoryeditdialog_base.ui deleted file mode 100644 index 11cd98740..000000000 --- a/libkdepim/categoryeditdialog_base.ui +++ /dev/null @@ -1,107 +0,0 @@ - -CategoryEditDialog_base - - - CategoryEditDialog_base - - - - 0 - 0 - 386 - 270 - - - - Edit Categories - - - - unnamed - - - 0 - - - 6 - - - - mEdit - - - - - - Category - - - true - - - true - - - - mCategories - - - true - - - AllColumns - - - - - tqlayout103 - - - - unnamed - - - - mButtonAdd - - - A&dd - - - - - mButtonRemove - - - &Remove - - - - - Spacer3 - - - Vertical - - - Expanding - - - - 20 - 20 - - - - - - - - - mCategories - mEdit - mButtonAdd - mButtonRemove - - - diff --git a/libkdepim/categoryselectdialog.cpp b/libkdepim/categoryselectdialog.cpp deleted file mode 100644 index 36996614e..000000000 --- a/libkdepim/categoryselectdialog.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2000, 2001, 2002 Cornelius Schumacher - Copyright (C) 2003-2004 Reinhold Kainhofer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include "categoryselectdialog_base.h" -#include -#include "categoryselectdialog.h" - -#include "kpimprefs.h" - -using namespace KPIM; - -CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, TQWidget* parent, - const char* name, bool modal ) - : KDialogBase::KDialogBase( parent, name, modal, - i18n("Select Categories"), Ok|Apply|Cancel|Help, Ok, true ), - mPrefs( prefs ) -{ - mWidget = new CategorySelectDialog_base( this, "CategorySelection" ); - mWidget->mCategories->header()->hide(); - setMainWidget( mWidget ); - - setCategories(); - - connect( mWidget->mButtonEdit, TQT_SIGNAL(clicked()), - TQT_SIGNAL(editCategories()) ); - connect( mWidget->mButtonClear, TQT_SIGNAL(clicked()), - TQT_SLOT(clear()) ); -} - -void CategorySelectDialog::setCategories( const TQStringList &categoryList ) -{ - mWidget->mCategories->clear(); - mCategoryList.clear(); - - TQStringList::ConstIterator it; - - for ( it = categoryList.begin(); it != categoryList.end(); ++it ) - if ( mPrefs->mCustomCategories.find( *it ) == mPrefs->mCustomCategories.end() ) - mPrefs->mCustomCategories.append( *it ); - - for ( it = mPrefs->mCustomCategories.begin(); - it != mPrefs->mCustomCategories.end(); ++it ) { - new TQCheckListItem( mWidget->mCategories, *it, TQCheckListItem::CheckBox ); - } -} - -CategorySelectDialog::~CategorySelectDialog() -{ -} - -void CategorySelectDialog::setSelected(const TQStringList &selList) -{ - clear(); - - TQStringList::ConstIterator it; - for ( it = selList.begin(); it != selList.end(); ++it ) { - TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); - while (item) { - if (item->text() == *it) { - item->setOn(true); - break; - } - item = (TQCheckListItem *)item->nextSibling(); - } - } -} - -TQStringList CategorySelectDialog::selectedCategories() const -{ - return mCategoryList; -} - -void CategorySelectDialog::slotApply() -{ - TQStringList categories; - TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); - while (item) { - if (item->isOn()) { - categories.append(item->text()); - } - item = (TQCheckListItem *)item->nextSibling(); - } - - TQString categoriesStr = categories.join(", "); - - mCategoryList = categories; - - emit categoriesSelected(categories); - emit categoriesSelected(categoriesStr); -} - -void CategorySelectDialog::slotOk() -{ - slotApply(); - accept(); -} - -void CategorySelectDialog::clear() -{ - TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); - while (item) { - item->setOn(false); - item = (TQCheckListItem *)item->nextSibling(); - } -} - -void CategorySelectDialog::updateCategoryConfig() -{ - TQStringList selected; - TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); - while (item) { - if (item->isOn()) { - selected.append(item->text()); - } - item = (TQCheckListItem *)item->nextSibling(); - } - - setCategories(); - - setSelected(selected); -} - -#include "categoryselectdialog.moc" diff --git a/libkdepim/categoryselectdialog.h b/libkdepim/categoryselectdialog.h deleted file mode 100644 index 3cff0313c..000000000 --- a/libkdepim/categoryselectdialog.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2000, 2001, 2002 Cornelius Schumacher - Copyright (C) 2003-2004 Reinhold Kainhofer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KPIM_CATEGORYSELECTDIALOG_H -#define KPIM_CATEGORYSELECTDIALOG_H - -#include -#include - -class KPimPrefs; -class CategorySelectDialog_base; - -namespace KPIM { - -class KDE_EXPORT CategorySelectDialog : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT - public: - CategorySelectDialog( KPimPrefs *prefs, TQWidget *parent = 0, - const char *name = 0, bool modal = false ); - ~CategorySelectDialog(); - - /** - Adds this categories to the default categories. - */ - void setCategories( const TQStringList &categoryList = TQStringList() ); - void setSelected( const TQStringList &selList ); - - TQStringList selectedCategories() const; - - public slots: - void slotOk(); - void slotApply(); - void clear(); - void updateCategoryConfig(); - - signals: - void categoriesSelected( const TQString & ); - void categoriesSelected( const TQStringList & ); - void editCategories(); - - private: - KPimPrefs *mPrefs; - CategorySelectDialog_base *mWidget; - TQStringList mCategoryList; - - class CategorySelectDialogPrivate; - CategorySelectDialogPrivate *d; -}; - -} - -#endif diff --git a/libkdepim/categoryselectdialog_base.ui b/libkdepim/categoryselectdialog_base.ui deleted file mode 100644 index 1e45bd468..000000000 --- a/libkdepim/categoryselectdialog_base.ui +++ /dev/null @@ -1,101 +0,0 @@ - -CategorySelectDialog_base - - - CategorySelectDialog_base - - - - 0 - 0 - 387 - 280 - - - - Select Categories - - - - unnamed - - - 0 - - - 6 - - - - - Category - - - true - - - true - - - - mCategories - - - - - Layout12 - - - - unnamed - - - 0 - - - 6 - - - - mButtonClear - - - &Clear Selection - - - - - Spacer3 - - - Horizontal - - - Expanding - - - - 20 - 20 - - - - - - mButtonEdit - - - &Edit Categories... - - - - - - - - mCategories - mButtonClear - mButtonEdit - - - diff --git a/libkdepim/cfgc/Makefile.am b/libkdepim/cfgc/Makefile.am deleted file mode 100644 index ec9f505f0..000000000 --- a/libkdepim/cfgc/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -AM_CPPFLAGS = -I$(top_builddir)/libtdepim -I$(top_srcdir) $(all_includes) - -check_PROGRAMS = example -#autoexample - -example_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor -example_LDADD = ../libtdepim.la $(LIB_KDECORE) -example_SOURCES = example.cpp exampleprefs_base.kcfgc - -#autoexample_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor -#autoexample_LDADD = ../libtdepim.la $(LIB_KDECORE) -#autoexample_SOURCES = general_base.ui myoptions_base.ui autoexample.cpp - -METASOURCES = AUTO diff --git a/libkdepim/cfgc/README b/libkdepim/cfgc/README deleted file mode 100644 index 6a7783817..000000000 --- a/libkdepim/cfgc/README +++ /dev/null @@ -1,6 +0,0 @@ -This directory contains text and example code for automatic creation of -configuration dialogs based on KConfigSkeleton, kconfig_compiler and -KPrefsDialog. - -If you have questions or comments please contact Cornelius Schumacher -. diff --git a/libkdepim/cfgc/autoexample.cpp b/libkdepim/cfgc/autoexample.cpp deleted file mode 100644 index 45617e6f6..000000000 --- a/libkdepim/cfgc/autoexample.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - This file is part of KDE. - - Copyright (c) 2003 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "general_base.h" -#include "myoptions_base.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -int main( int argc, char **argv ) -{ - KAboutData aboutData( "example", I18N_NOOP("autoconfig example"), "0.1" ); - aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); - - KCmdLineArgs::init( argc, argv, &aboutData ); - - KApplication app; - - // Create a new dialog with the same name as the above checking code. - KAutoConfigDialog *dialog = new KAutoConfigDialog(0, "settings"); - - // Add the general page. Store the settings in the General group and - // use the icon package_settings. - GeneralBase *general = new GeneralBase( 0 ); - dialog->addPage( general, i18n("General"), "General", "" ); - - MyOptionsBase *myOptions = new MyOptionsBase( 0 ); - -// myOptions->show(); - dialog->addPage( myOptions, i18n("MyOptions"), "MyOptions", "" ); - -// app.setMainWidget( dialog ); - - dialog->show(); - - return app.exec(); -} diff --git a/libkdepim/cfgc/example.cfg b/libkdepim/cfgc/example.cfg deleted file mode 100644 index 18c7b8b15..000000000 --- a/libkdepim/cfgc/example.cfg +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - OneOption - - true - - - Another Option - - 5 - - - - One - Two - Three - - ListOption - One - - - - - MyString - - Default String - - - MyStringList - up,down - - - diff --git a/libkdepim/cfgc/example.cpp b/libkdepim/cfgc/example.cpp deleted file mode 100644 index 4f818e900..000000000 --- a/libkdepim/cfgc/example.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - This file is part of KDE. - - Copyright (c) 2003 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "exampleprefs_base.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -int main( int argc, char **argv ) -{ - KAboutData aboutData( "example", I18N_NOOP("cfgc example"), "0.1" ); - aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); - - KCmdLineArgs::init( argc, argv, &aboutData ); - - KApplication app; - - ExamplePrefsBase *prefs = ExamplePrefsBase::self(); - - KPrefsDialog *dialog = new KPrefsDialog( prefs ); - - dialog->autoCreate(); - - app.setMainWidget( dialog ); - - dialog->show(); - - return app.exec(); -} diff --git a/libkdepim/cfgc/exampleprefs_base.kcfg b/libkdepim/cfgc/exampleprefs_base.kcfg deleted file mode 100644 index e197ae7cd..000000000 --- a/libkdepim/cfgc/exampleprefs_base.kcfg +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - true - - - - 5 - - - - And this is a longer description of this option. Just wondering, how will the translations of those be handled? - - - - - - - - - - - - One - - - - - - Default String - - - up,down - - - diff --git a/libkdepim/cfgc/exampleprefs_base.kcfgc b/libkdepim/cfgc/exampleprefs_base.kcfgc deleted file mode 100644 index 36e5ed4e6..000000000 --- a/libkdepim/cfgc/exampleprefs_base.kcfgc +++ /dev/null @@ -1,11 +0,0 @@ -# Code generation options for kconfig_compiler -File=exampleprefs_base.kcfg -ClassName=ExamplePrefsBase -Singleton=true -Mutators=true -Inherits=KPimPrefs -IncludeFiles=libtdepim/kpimprefs.h -MemberVariables=public -GlobalEnums=true -ItemAccessors=true -SetUserTexts=true diff --git a/libkdepim/cfgc/general_base.ui b/libkdepim/cfgc/general_base.ui deleted file mode 100644 index 7cafaa011..000000000 --- a/libkdepim/cfgc/general_base.ui +++ /dev/null @@ -1,46 +0,0 @@ - -GeneralBase - - - GeneralBase - - - - 0 - 0 - 600 - 480 - - - - AutoExampleDialog - - - - unnamed - - - - OneOption - - - OneOption - - - - - Another_Option - - - - - textLabel1 - - - AnotherOption: - - - - - - diff --git a/libkdepim/cfgc/myoptions_base.ui b/libkdepim/cfgc/myoptions_base.ui deleted file mode 100644 index 4d4f8247f..000000000 --- a/libkdepim/cfgc/myoptions_base.ui +++ /dev/null @@ -1,46 +0,0 @@ - -MyOptionsBase - - - MyOptionsBase - - - - 0 - 0 - 600 - 480 - - - - - textLabel1 - - - - 30 - 180 - 70 - 20 - - - - MyString: - - - - - MyString - - - - 130 - 180 - 123 - 22 - - - - - - diff --git a/libkdepim/clicklineedit.cpp b/libkdepim/clicklineedit.cpp deleted file mode 100644 index 28e66a0ba..000000000 --- a/libkdepim/clicklineedit.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - This file is part of libtdepim. - Copyright (c) 2004 Daniel Molkentin - based on code by Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - - -#include "clicklineedit.h" - -#include "tqpainter.h" - -using namespace KPIM; - -ClickLineEdit::ClickLineEdit(TQWidget *parent, const TQString &msg, const char* name) : - KLineEdit(parent, name) -{ - mDrawClickMsg = true; - setClickMessage( msg ); -} - -ClickLineEdit::~ClickLineEdit() {} - - -void ClickLineEdit::setClickMessage( const TQString &msg ) -{ - mClickMessage = msg; - tqrepaint(); -} - -void ClickLineEdit::setText( const TQString &txt ) -{ - mDrawClickMsg = txt.isEmpty(); - tqrepaint(); - KLineEdit::setText( txt ); -} - -void ClickLineEdit::drawContents( TQPainter *p ) -{ - KLineEdit::drawContents( p ); - - if ( mDrawClickMsg == true && !hasFocus() ) { - TQPen tmp = p->pen(); - p->setPen( palette().color( TQPalette::Disabled, TQColorGroup::Text ) ); - TQRect cr = contentsRect(); - p->drawText( cr, AlignAuto|AlignVCenter, mClickMessage ); - p->setPen( tmp ); - } -} - -void ClickLineEdit::focusInEvent( TQFocusEvent *ev ) -{ - if ( mDrawClickMsg == true ) - { - mDrawClickMsg = false; - tqrepaint(); - } - TQLineEdit::focusInEvent( ev ); -} - -void ClickLineEdit::focusOutEvent( TQFocusEvent *ev ) -{ - if ( text().isEmpty() ) - { - mDrawClickMsg = true; - tqrepaint(); - } - TQLineEdit::focusOutEvent( ev ); -} - -#include "clicklineedit.moc" diff --git a/libkdepim/clicklineedit.h b/libkdepim/clicklineedit.h deleted file mode 100644 index 28b771ff5..000000000 --- a/libkdepim/clicklineedit.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - This file is part of libtdepim. - Copyright (c) 2004 Daniel Molkentin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef CLICKLINEEDIT_H -#define CLICKLINEEDIT_H - -#include -#include - -namespace KPIM { - -/** - This class provides a KLineEdit which contains a greyed-out hinting - text as long as the user didn't enter any text - - @short LineEdit with customizable "Click here" text - @author Daniel Molkentin -*/ -class KDE_EXPORT ClickLineEdit : public KLineEdit -{ - Q_OBJECT - TQ_OBJECT - TQ_PROPERTY( TQString clickMessage READ clickMessage WRITE setClickMessage ) - public: - ClickLineEdit( TQWidget *parent, const TQString &msg = TQString(), const char* name = 0 ); - ~ClickLineEdit(); - - void setClickMessage( const TQString &msg ); - TQString clickMessage() const { return mClickMessage; } - - virtual void setText( const TQString& txt ); - - protected: - virtual void drawContents( TQPainter *p ); - virtual void focusInEvent( TQFocusEvent *ev ); - virtual void focusOutEvent( TQFocusEvent *ev ); - - private: - TQString mClickMessage; - bool mDrawClickMsg; - -}; - -} - -#endif // CLICKLINEEDIT_H - - diff --git a/libkdepim/collectingprocess.cpp b/libkdepim/collectingprocess.cpp deleted file mode 100644 index 58cdcb5ee..000000000 --- a/libkdepim/collectingprocess.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - collectingprocess.cpp - - This file is part of libtdepim. - Copyright (c) 2004 Ingo Kloecker - - This library 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 library 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 TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 "collectingprocess.h" - -#include - -#include - -using namespace KPIM; - -struct CollectingProcess::Private { - Private() : stdoutSize( 0 ), stderrSize( 0 ) - {} - - uint stdoutSize; - TQValueList stdoutBuffer; - uint stderrSize; - TQValueList stderrBuffer; -}; - - -CollectingProcess::CollectingProcess( TQObject * parent, const char * name ) - : KProcess( parent, name ) -{ - d = new Private(); -} - -CollectingProcess::~CollectingProcess() { - delete d; d = 0; -} - -bool CollectingProcess::start( RunMode runmode, Communication comm ) { - // prevent duplicate connection - disconnect( this, TQT_SIGNAL( receivedStdout( KProcess *, char *, int ) ), - this, TQT_SLOT( slotReceivedStdout( KProcess *, char *, int ) ) ); - if ( comm & Stdout ) { - connect( this, TQT_SIGNAL( receivedStdout( KProcess *, char *, int ) ), - this, TQT_SLOT( slotReceivedStdout( KProcess *, char *, int ) ) ); - } - // prevent duplicate connection - disconnect( this, TQT_SIGNAL( receivedStderr( KProcess *, char *, int ) ), - this, TQT_SLOT( slotReceivedStderr( KProcess *, char *, int ) ) ); - if ( comm & Stderr ) { - connect( this, TQT_SIGNAL( receivedStderr( KProcess *, char *, int ) ), - this, TQT_SLOT( slotReceivedStderr( KProcess *, char *, int ) ) ); - } - return KProcess::start( runmode, comm ); -} - -void CollectingProcess::slotReceivedStdout( KProcess *, char *buf, int len ) -{ - TQByteArray b; - b.duplicate( buf, len ); - d->stdoutBuffer.append( b ); - d->stdoutSize += len; -} - -void CollectingProcess::slotReceivedStderr( KProcess *, char *buf, int len ) -{ - TQByteArray b; - b.duplicate( buf, len ); - d->stderrBuffer.append( b ); - d->stderrSize += len; -} - -TQByteArray CollectingProcess::collectedStdout() -{ - if ( d->stdoutSize == 0 ) { - return TQByteArray(); - } - - uint offset = 0; - TQByteArray b( d->stdoutSize ); - for ( TQValueList::const_iterator it = d->stdoutBuffer.begin(); - it != d->stdoutBuffer.end(); - ++it ) { - memcpy( b.data() + offset, (*it).data(), (*it).size() ); - offset += (*it).size(); - } - d->stdoutBuffer.clear(); - d->stdoutSize = 0; - - return b; -} - -TQByteArray CollectingProcess::collectedStderr() -{ - if ( d->stderrSize == 0 ) { - return TQByteArray(); - } - - uint offset = 0; - TQByteArray b( d->stderrSize ); - for ( TQValueList::const_iterator it = d->stderrBuffer.begin(); - it != d->stderrBuffer.end(); - ++it ) { - memcpy( b.data() + offset, (*it).data(), (*it).size() ); - offset += (*it).size(); - } - d->stderrBuffer.clear(); - d->stderrSize = 0; - - return b; -} - -void CollectingProcess::virtual_hook( int id, void * data ) { - KProcess::virtual_hook( id, data ); -} - -#include "collectingprocess.moc" diff --git a/libkdepim/collectingprocess.h b/libkdepim/collectingprocess.h deleted file mode 100644 index ae7378264..000000000 --- a/libkdepim/collectingprocess.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- mode: C++ -*- - collectingprocess.h - - This file is part of libtdepim. - Copyright (c) 2004 Ingo Kloecker - - This library 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 library 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 TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 __KPIM_COLLECTINGPROCESS_H__ -#define __KPIM_COLLECTINGPROCESS_H__ - -#include -#include - -namespace KPIM { - -/** - * @short An output collecting KProcess class. - * - * This class simplifies the usage of KProcess by collecting all output - * (stdout/stderr) of the process. - * - * @author Ingo Kloecker - */ -class KDE_EXPORT CollectingProcess : public KProcess { - Q_OBJECT - TQ_OBJECT -public: - CollectingProcess( TQObject * parent = 0, const char * name = 0 ); - ~CollectingProcess(); - - /** Starts the process in NotifyOnExit mode and writes in to stdin of - the process. - */ - bool start( RunMode runmode, Communication comm ); - - /** Returns the contents of the stdout buffer and clears it afterwards. */ - TQByteArray collectedStdout(); - /** Returns the contents of the stderr buffer and clears it afterwards. */ - TQByteArray collectedStderr(); - -private slots: - void slotReceivedStdout( KProcess *, char *, int ); - void slotReceivedStderr( KProcess *, char *, int ); - -private: - class Private; - Private * d; -protected: - void virtual_hook( int id, void * data ); -}; - -} // namespace KPIM - -#endif // __KPIM_COLLECTINGPROCESS_H__ diff --git a/libkdepim/completionordereditor.cpp b/libkdepim/completionordereditor.cpp deleted file mode 100644 index 2687188d0..000000000 --- a/libkdepim/completionordereditor.cpp +++ /dev/null @@ -1,307 +0,0 @@ -/** -*- c++ -*- - * completionordereditor.cpp - * - * Copyright (c) 2004 David Faure - * - * 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; version 2 of the License - * - * 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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 // FOR KDEPIM_NEW_DISTRLISTS - -#include "completionordereditor.h" -#include "ldapclient.h" -#include "resourceabc.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -/* - -Several items are used in addresseelineedit's completion object: - LDAP servers, KABC resources (imap and non-imap), Recent addresses (in kmail only). - -The default completion weights are as follow: - Recent addresses (kmail) : 10 (see kmail/kmlineeditspell.cpp) - LDAP: 50, 49, 48 etc. (see ldapclient.cpp) - KABC non-imap resources: 60 (see addresseelineedit.cpp and SimpleCompletionItem here) - Distribution lists: 60 (see addresseelineedit.cpp and SimpleCompletionItem here) - KABC imap resources: 80 (see kresources/imap/kabc/resourceimap.cpp) - -This dialog allows to change those weights, by showing one item per: - - LDAP server - - KABC non-imap resource - - KABC imap subresource - plus one item for Distribution Lists. - - Maybe 'recent addresses' should be configurable too, but first it might - be better to add support for them in korganizer too. - -*/ - -using namespace KPIM; - -namespace KPIM { - -int CompletionItemList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 ) -{ - int w1 = ( (CompletionItem*)s1 )->completionWeight(); - int w2 = ( (CompletionItem*)s2 )->completionWeight(); - // s1 < s2 if it has a higher completion value, i.e. w1 > w2. - return w2 - w1; -} - -class LDAPCompletionItem : public CompletionItem -{ -public: - LDAPCompletionItem( LdapClient* ldapClient ) : mLdapClient( ldapClient ) {} - virtual TQString label() const { return i18n( "LDAP server %1" ).tqarg( mLdapClient->server().host() ); } - virtual int completionWeight() const { return mLdapClient->completionWeight(); } - virtual void save( CompletionOrderEditor* ); -protected: - virtual void setCompletionWeight( int weight ) { mWeight = weight; } -private: - LdapClient* mLdapClient; - int mWeight; -}; - -void LDAPCompletionItem::save( CompletionOrderEditor* ) -{ - KConfig * config = LdapSearch::config(); - config->setGroup( "LDAP" ); - config->writeEntry( TQString( "SelectedCompletionWeight%1" ).tqarg( mLdapClient->clientNumber() ), - mWeight ); - config->sync(); -} - -// A simple item saved into kpimcompletionorder (no subresources, just name/identifier/weight) -class SimpleCompletionItem : public CompletionItem -{ -public: - SimpleCompletionItem( CompletionOrderEditor* editor, const TQString& label, const TQString& identifier, int weight ) - : mLabel( label ), mIdentifier( identifier ) { - KConfigGroup group( editor->configFile(), "CompletionWeights" ); - mWeight = group.readNumEntry( mIdentifier, weight ); - } - virtual TQString label() const { return mLabel; } - virtual int completionWeight() const { return mWeight; } - virtual void save( CompletionOrderEditor* ); -protected: - virtual void setCompletionWeight( int weight ) { mWeight = weight; } -private: - TQString mLabel, mIdentifier; - int mWeight; -}; - -void SimpleCompletionItem::save( CompletionOrderEditor* editor ) -{ - // Maybe KABC::Resource could have a completionWeight setting (for readConfig/writeConfig) - // But for kdelibs-3.2 compat purposes I can't do that. - KConfigGroup group( editor->configFile(), "CompletionWeights" ); - group.writeEntry( mIdentifier, mWeight ); -} - -// An imap subresource for kabc -class KABCImapSubResCompletionItem : public CompletionItem -{ -public: - KABCImapSubResCompletionItem( ResourceABC* resource, const TQString& subResource ) - : mResource( resource ), mSubResource( subResource ), mWeight( completionWeight() ) {} - virtual TQString label() const { - return TQString( "%1 %2" ).tqarg( mResource->resourceName() ).tqarg( mResource->subresourceLabel( mSubResource ) ); - } - virtual int completionWeight() const { - return mResource->subresourceCompletionWeight( mSubResource ); - } - virtual void setCompletionWeight( int weight ) { - mWeight = weight; - } - virtual void save( CompletionOrderEditor* ) { - mResource->setSubresourceCompletionWeight( mSubResource, mWeight ); - } -private: - ResourceABC* mResource; - TQString mSubResource; - int mWeight; -}; - -///////// - -class CompletionViewItem : public TQListViewItem -{ -public: - CompletionViewItem( TQListView* lv, CompletionItem* item ) - : TQListViewItem( lv, lv->lastItem(), item->label() ), mItem( item ) {} - CompletionItem* item() const { return mItem; } - void setItem( CompletionItem* i ) { mItem = i; setText( 0, mItem->label() ); } - -private: - CompletionItem* mItem; -}; - -CompletionOrderEditor::CompletionOrderEditor( KPIM::LdapSearch* ldapSearch, - TQWidget* parent, const char* name ) - : KDialogBase( parent, name, true, i18n("Edit Completion Order"), Ok|Cancel, Ok, true ), - mConfig( "kpimcompletionorder" ), mDirty( false ) -{ - mItems.setAutoDelete( true ); - // The first step is to gather all the data, creating CompletionItem objects - TQValueList< LdapClient* > ldapClients = ldapSearch->clients(); - for( TQValueList::const_iterator it = ldapClients.begin(); it != ldapClients.end(); ++it ) { - //kdDebug(5300) << "LDAP: host " << (*it)->host() << " weight " << (*it)->completionWeight() << endl; - mItems.append( new LDAPCompletionItem( *it ) ); - } - KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); - TQPtrList resources = addressBook->resources(); - for( TQPtrListIterator resit( resources ); *resit; ++resit ) { - //kdDebug(5300) << "KABC Resource: " << (*resit)->className() << endl; - ResourceABC* res = dynamic_cast( *resit ); - if ( res ) { // IMAP KABC resource - const TQStringList subresources = res->subresources(); - for( TQStringList::const_iterator it = subresources.begin(); it != subresources.end(); ++it ) { - mItems.append( new KABCImapSubResCompletionItem( res, *it ) ); - } - } else { // non-IMAP KABC resource - mItems.append( new SimpleCompletionItem( this, (*resit)->resourceName(), - (*resit)->identifier(), 60 ) ); - } - } - -#ifndef KDEPIM_NEW_DISTRLISTS // new distr lists are normal contact, so no separate item if using them - // Add an item for distribution lists - mItems.append( new SimpleCompletionItem( this, i18n( "Distribution Lists" ), "DistributionLists" ), 60 ); -#endif - - mItems.append( new SimpleCompletionItem( this, i18n( "Recent Addresses" ), "Recent Addresses", 10 ) ); - - // Now sort the items, then create the GUI - mItems.sort(); - - TQHBox* page = makeHBoxMainWidget(); - mListView = new KListView( page ); - mListView->setSorting( -1 ); - mListView->addColumn( TQString() ); - mListView->header()->hide(); - - for( TQPtrListIterator compit( mItems ); *compit; ++compit ) { - new CompletionViewItem( mListView, *compit ); - kdDebug(5300) << " " << (*compit)->label() << " " << (*compit)->completionWeight() << endl; - } - - TQVBox* upDownBox = new TQVBox( page ); - mUpButton = new KPushButton( upDownBox, "mUpButton" ); - mUpButton->setIconSet( BarIconSet( "up", KIcon::SizeSmall ) ); - mUpButton->setEnabled( false ); // b/c no item is selected yet - mUpButton->setFocusPolicy( TQ_StrongFocus ); - - mDownButton = new KPushButton( upDownBox, "mDownButton" ); - mDownButton->setIconSet( BarIconSet( "down", KIcon::SizeSmall ) ); - mDownButton->setEnabled( false ); // b/c no item is selected yet - mDownButton->setFocusPolicy( TQ_StrongFocus ); - - TQWidget* spacer = new TQWidget( upDownBox ); - upDownBox->setStretchFactor( spacer, 100 ); - - connect( mListView, TQT_SIGNAL( selectionChanged( TQListViewItem* ) ), - TQT_SLOT( slotSelectionChanged( TQListViewItem* ) ) ); - connect( mUpButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotMoveUp() ) ); - connect( mDownButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotMoveDown() ) ); -} - -CompletionOrderEditor::~CompletionOrderEditor() -{ -} - -void CompletionOrderEditor::slotSelectionChanged( TQListViewItem *item ) -{ - mDownButton->setEnabled( item && item->itemBelow() ); - mUpButton->setEnabled( item && item->itemAbove() ); -} - -static void swapItems( CompletionViewItem *one, CompletionViewItem *other ) -{ - CompletionItem* i = one->item(); - one->setItem( other->item() ); - other->setItem( i ); -} - -void CompletionOrderEditor::slotMoveUp() -{ - CompletionViewItem *item = static_cast( mListView->selectedItem() ); - if ( !item ) return; - CompletionViewItem *above = static_cast( item->itemAbove() ); - if ( !above ) return; - swapItems( item, above ); - mListView->setCurrentItem( above ); - mListView->setSelected( above, true ); - mDirty = true; -} - -void CompletionOrderEditor::slotMoveDown() -{ - CompletionViewItem *item = static_cast( mListView->selectedItem() ); - if ( !item ) return; - CompletionViewItem *below = static_cast( item->itemBelow() ); - if ( !below ) return; - swapItems( item, below ); - mListView->setCurrentItem( below ); - mListView->setSelected( below, true ); - mDirty = true; -} - -void CompletionOrderEditor::slotOk() -{ - if ( mDirty ) { - int w = 100; - for ( TQListViewItem* it = mListView->firstChild(); it; it = it->nextSibling() ) { - CompletionViewItem *item = static_cast( it ); - item->item()->setCompletionWeight( w ); - item->item()->save( this ); - kdDebug(5300) << "slotOk: " << item->item()->label() << " " << w << endl; - --w; - } - - // Emit DCOP signal - // The emitter is always set to KPIM::IMAPCompletionOrder, so that the connect works - // This is why we can't use k_dcop_signals here, but need to use emitDCOPSignal - kapp->dcopClient()->emitDCOPSignal( "KPIM::IMAPCompletionOrder", "orderChanged()", TQByteArray() ); - } - KDialogBase::slotOk(); -} - -} // namespace KPIM - -#include "completionordereditor.moc" diff --git a/libkdepim/completionordereditor.h b/libkdepim/completionordereditor.h deleted file mode 100644 index 50cc3b3cb..000000000 --- a/libkdepim/completionordereditor.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- c++ -*- - * completionordereditor.h - * - * Copyright (c) 2004 David Faure - * - * 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; version 2 of the License - * - * 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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 COMPLETIONORDEREDITOR_H -#define COMPLETIONORDEREDITOR_H - -#include -#include - -class KPushButton; -class KListView; -namespace KPIM { - -class LdapSearch; -class CompletionOrderEditor; - -// Base class for items in the list -class CompletionItem -{ -public: - virtual ~CompletionItem() {} - virtual TQString label() const = 0; - virtual int completionWeight() const = 0; - virtual void setCompletionWeight( int weight ) = 0; - virtual void save( CompletionOrderEditor* ) = 0; -}; - - -// I don't like TQPtrList much, but it has compareItems, which TQValueList doesn't -class CompletionItemList : public TQPtrList -{ -public: - CompletionItemList() {} - virtual int compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 ); -}; - -class CompletionOrderEditor : public KDialogBase { - Q_OBJECT - TQ_OBJECT - -public: - CompletionOrderEditor( KPIM::LdapSearch* ldapSearch, TQWidget* parent, const char* name = 0 ); - ~CompletionOrderEditor(); - - KConfig* configFile() { return &mConfig; } - -private slots: - void slotSelectionChanged( TQListViewItem* ); - void slotMoveUp(); - void slotMoveDown(); - virtual void slotOk(); - -private: - KConfig mConfig; - CompletionItemList mItems; - KListView* mListView; - KPushButton* mUpButton; - KPushButton* mDownButton; - - bool mDirty; -}; - -} // namespace - -#endif /* COMPLETIONORDEREDITOR_H */ - diff --git a/libkdepim/configmanager.cpp b/libkdepim/configmanager.cpp deleted file mode 100644 index 64b4562fc..000000000 --- a/libkdepim/configmanager.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - configmanager.cpp - - KMail, the KDE mail client. - Copyright (c) 2002 the KMail authors. - See file AUTHORS for details - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2.0, as published by the Free Software Foundation. - 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, US -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "configmanager.h" - -using namespace KPIM; - -ConfigManager::ConfigManager( TQObject * parent, const char * name ) - : TQObject( parent, name ) -{ - -} - -ConfigManager::~ConfigManager() -{ - -} - -#include "configmanager.moc" diff --git a/libkdepim/configmanager.h b/libkdepim/configmanager.h deleted file mode 100644 index 832a0f70f..000000000 --- a/libkdepim/configmanager.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- c++ -*- - configmanager.h - - KMail, the KDE mail client. - Copyright (c) 2002 the KMail authors. - See file AUTHORS for details - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2.0, as published by the Free Software Foundation. - 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, US -*/ - - -#ifndef _KMAIL_CONFIGMANAGER_H_ -#define _KMAIL_CONFIGMANAGER_H_ - -#include - -#include - -class KMKernel; - -namespace KPIM { - -/** - * @short Class for managing a set of config options. - * @author Marc Mutz - **/ -class KDE_EXPORT ConfigManager : public TQObject { - Q_OBJECT - TQ_OBJECT -public: - /** Commit changes to disk and emit changed() if necessary. */ - virtual void commit() = 0; - /** Re-read the config from disk and forget changes. */ - virtual void rollback() = 0; - - /** Check whether there are any unsaved changes. */ - virtual bool hasPendingChanges() const = 0; - -signals: - /** Emitted whenever a commit changes any configure option */ - void changed(); - -protected: - ConfigManager( TQObject * parent=0, const char * name=0 ); - virtual ~ConfigManager(); -}; - -} - -#endif // _KMAIL_CONFIGMANAGER_H_ diff --git a/libkdepim/configure.in.in b/libkdepim/configure.in.in deleted file mode 100644 index c405f31c4..000000000 --- a/libkdepim/configure.in.in +++ /dev/null @@ -1,14 +0,0 @@ -AC_MSG_CHECKING([whether to use new-style distribution lists]) -AC_ARG_ENABLE(newdistrlists, -AC_HELP_STRING([--disable-newdistrlists], - [Disables the new distribution lists (which are saved as addressee in the address book as normal contacts, useful for Kolab)]), - [ enable_new_distrlists=$enableval], [enable_new_distrlists=yes])dnl -if test "$enable_new_distrlists" = "yes" ; then - AC_DEFINE_UNQUOTED(KDEPIM_NEW_DISTRLISTS, 1, [Define if you want to use the new distribution lists]) - AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi - -AM_CONDITIONAL(compile_newdistrlists, test "x$enable_new_distrlists" = "xyes") - diff --git a/libkdepim/csshelper.cpp b/libkdepim/csshelper.cpp deleted file mode 100644 index 05f20e390..000000000 --- a/libkdepim/csshelper.cpp +++ /dev/null @@ -1,647 +0,0 @@ -/* -*- mode: C++; c-file-style: "gnu" -*- - csshelper.cpp - - This file is part of KMail, the KDE mail client. - Copyright (c) 2003 Marc Mutz - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 "csshelper.h" - -#include -#include -#include -#include - -#include -#include - -namespace KPIM { - - namespace { - // some TQColor manipulators that hide the ugly TQColor API w.r.t. HSV: - inline TQColor darker( const TQColor & c ) { - int h, s, v; - c.hsv( &h, &s, &v ); - return TQColor( h, s, v*4/5, TQColor::Hsv ); - } - - inline TQColor desaturate( const TQColor & c ) { - int h, s, v; - c.hsv( &h, &s, &v ); - return TQColor( h, s/8, v, TQColor::Hsv ); - } - - inline TQColor fixValue( const TQColor & c, int newV ) { - int h, s, v; - c.hsv( &h, &s, &v ); - return TQColor( h, s, newV, TQColor::Hsv ); - } - - inline int getValueOf( const TQColor & c ) { - int h, s, v; - c.hsv( &h, &s, &v ); - return v; - } - } - - CSSHelper::CSSHelper( const TQPaintDeviceMetrics &pdm ) : - mShrinkQuotes( false ), - mMetrics( pdm ) - { - // initialize with defaults - should match the corresponding application defaults - mForegroundColor = TQApplication::tqpalette().active().text(); - mLinkColor = KGlobalSettings::linkColor(); - mVisitedLinkColor = KGlobalSettings::visitedLinkColor(); - mBackgroundColor = TQApplication::tqpalette().active().base(); - cHtmlWarning = TQColor( 0xFF, 0x40, 0x40 ); // warning frame color: light red - - cPgpEncrH = TQColor( 0x00, 0x80, 0xFF ); // light blue - cPgpOk1H = TQColor( 0x40, 0xFF, 0x40 ); // light green - cPgpOk0H = TQColor( 0xFF, 0xFF, 0x40 ); // light yellow - cPgpWarnH = TQColor( 0xFF, 0xFF, 0x40 ); // light yellow - cPgpErrH = TQt::red; - - for ( int i = 0 ; i < 3 ; ++i ) - mQuoteColor[i] = TQColor( 0x00, 0x80 - i * 0x10, 0x00 ); // shades of green - mRecycleQuoteColors = false; - - TQFont defaultFont = KGlobalSettings::generalFont(); - TQFont defaultFixedFont = KGlobalSettings::fixedFont(); - mBodyFont = mPrintFont = defaultFont; - mFixedFont = mFixedPrintFont = defaultFixedFont; - defaultFont.setItalic( true ); - for ( int i = 0 ; i < 3 ; ++i ) - mQuoteFont[i] = defaultFont; - - mBackingPixmapOn = false; - - recalculatePGPColors(); - } - - void CSSHelper::recalculatePGPColors() { - // determine the frame and body color for PGP messages from the header color - // if the header color equals the background color then the other colors are - // also set to the background color (-> old style PGP message viewing) - // else - // the brightness of the frame is set to 4/5 of the brightness of the header - // and in case of a light background color - // the saturation of the body is set to 1/8 of the saturation of the header - // while in case of a dark background color - // the value of the body is set to the value of the background color - - // Check whether the user uses a light color scheme - const int vBG = getValueOf( mBackgroundColor ); - const bool lightBG = vBG >= 128; - if ( cPgpOk1H == mBackgroundColor ) { - cPgpOk1F = mBackgroundColor; - cPgpOk1B = mBackgroundColor; - } else { - cPgpOk1F= darker( cPgpOk1H ); - cPgpOk1B = lightBG ? desaturate( cPgpOk1H ) : fixValue( cPgpOk1H, vBG ); - } - if ( cPgpOk0H == mBackgroundColor ) { - cPgpOk0F = mBackgroundColor; - cPgpOk0B = mBackgroundColor; - } else { - cPgpOk0F = darker( cPgpOk0H ); - cPgpOk0B = lightBG ? desaturate( cPgpOk0H ) : fixValue( cPgpOk0H, vBG ); - } - if ( cPgpWarnH == mBackgroundColor ) { - cPgpWarnF = mBackgroundColor; - cPgpWarnB = mBackgroundColor; - } else { - cPgpWarnF = darker( cPgpWarnH ); - cPgpWarnB = lightBG ? desaturate( cPgpWarnH ) : fixValue( cPgpWarnH, vBG ); - } - if ( cPgpErrH == mBackgroundColor ) { - cPgpErrF = mBackgroundColor; - cPgpErrB = mBackgroundColor; - } else { - cPgpErrF = darker( cPgpErrH ); - cPgpErrB = lightBG ? desaturate( cPgpErrH ) : fixValue( cPgpErrH, vBG ); - } - if ( cPgpEncrH == mBackgroundColor ) { - cPgpEncrF = mBackgroundColor; - cPgpEncrB = mBackgroundColor; - } else { - cPgpEncrF = darker( cPgpEncrH ); - cPgpEncrB = lightBG ? desaturate( cPgpEncrH ) : fixValue( cPgpEncrH, vBG ); - } - } - - TQString CSSHelper::cssDefinitions( bool fixed ) const { - return - commonCssDefinitions() - + - "@media screen {\n\n" - + - screenCssDefinitions( this, fixed ) - + - "}\n" - "@media print {\n\n" - + - printCssDefinitions( fixed ) - + - "}\n"; - } - - TQString CSSHelper::htmlHead( bool /*fixed*/ ) const { - return - "\n" - "\n" - "\n"; - } - - TQString CSSHelper::quoteFontTag( int level ) const { - if ( level < 0 ) - level = 0; - static const int numQuoteLevels = sizeof mQuoteFont / sizeof *mQuoteFont; - const int effectiveLevel = mRecycleQuoteColors - ? level % numQuoteLevels + 1 - : kMin( level + 1, numQuoteLevels ) ; - if ( level >= numQuoteLevels ) - return TQString( "
" ).tqarg( effectiveLevel ); - else - return TQString( "
" ).tqarg( effectiveLevel ); - } - - TQString CSSHelper::nonQuotedFontTag() const { - return "
"; - } - - TQFont CSSHelper::bodyFont( bool fixed, bool print ) const { - return fixed ? ( print ? mFixedPrintFont : mFixedFont ) - : ( print ? mPrintFont : mBodyFont ); - } - - int CSSHelper::fontSize( bool fixed, bool print ) const { - return bodyFont( fixed, print ).pointSize(); - } - - - namespace { - int pointsToPixel( const TQPaintDeviceMetrics & metrics, int pointSize ) { - return ( pointSize * metrics.logicalDpiY() + 36 ) / 72 ; - } - } - - static const char * const quoteFontSizes[] = { "85", "80", "75" }; - - TQString CSSHelper::printCssDefinitions( bool fixed ) const { - const TQString headerFont = TQString( " font-family: \"%1\" ! important;\n" - " font-size: %2pt ! important;\n" ) - .tqarg( mPrintFont.family() ) - .tqarg( mPrintFont.pointSize() ); - const TQColorGroup & cg = TQApplication::tqpalette().active(); - - const TQFont printFont = bodyFont( fixed, true /* print */ ); - TQString quoteCSS; - if ( printFont.italic() ) - quoteCSS += " font-style: italic ! important;\n"; - if ( printFont.bold() ) - quoteCSS += " font-weight: bold ! important;\n"; - if ( !quoteCSS.isEmpty() ) - quoteCSS = "div.noquote {\n" + quoteCSS + "}\n\n"; - - return - TQString( "body {\n" - " font-family: \"%1\" ! important;\n" - " font-size: %2pt ! important;\n" - " color: #000000 ! important;\n" - " background-color: #ffffff ! important\n" - "}\n\n" ) - .tqarg( printFont.family(), - TQString::number( printFont.pointSize() ) ) - + - TQString( "tr.textAtmH,\n" - "tr.signInProgressH,\n" - "tr.rfc822H,\n" - "tr.encrH,\n" - "tr.signOkKeyOkH,\n" - "tr.signOkKeyBadH,\n" - "tr.signWarnH,\n" - "tr.signErrH,\n" - "div.header {\n" - "%1" - "}\n\n" - - "div.fancy.header > div {\n" - " background-color: %2 ! important;\n" - " color: %3 ! important;\n" - " padding: 4px ! important;\n" - " border: solid %3 1px ! important;\n" - "}\n\n" - - "div.fancy.header > div a[href] { color: %3 ! important; }\n\n" - - "div.fancy.header > table.outer{\n" - " background-color: %2 ! important;\n" - " color: %3 ! important;\n" - " border-bottom: solid %3 1px ! important;\n" - " border-left: solid %3 1px ! important;\n" - " border-right: solid %3 1px ! important;\n" - "}\n\n" - - "div.spamheader {\n" - " display:none ! important;\n" - "}\n\n" - - "div.htmlWarn {\n" - " border: 2px solid #ffffff ! important;\n" - "}\n\n" - - "div.senderpic{\n" - " font-size:0.8em ! important;\n" - " border:1px solid black ! important;\n" - " background-color:%2 ! important;\n" - "}\n\n" - - "div.senderstatus{\n" - " text-align:center ! important;\n" - "}\n\n" - - "div.noprint {\n" - " display:none ! important;\n" - "}\n\n" - ) - .tqarg( headerFont, - cg.background().name(), - cg.foreground().name() ) - + quoteCSS; - } - - TQString CSSHelper::screenCssDefinitions( const CSSHelper * helper, bool fixed ) const { - const TQString fgColor = mForegroundColor.name(); - const TQString bgColor = mBackgroundColor.name(); - const TQString linkColor = mLinkColor.name(); - const TQString headerFont = TQString(" font-family: \"%1\" ! important;\n" - " font-size: %2px ! important;\n") - .tqarg( mBodyFont.family() ) - .tqarg( pointsToPixel( helper->mMetrics, mBodyFont.pointSize() ) ); - const TQString background = ( mBackingPixmapOn - ? TQString( " background-image:url(file://%1) ! important;\n" ) - .tqarg( mBackingPixmapStr ) - : TQString( " background-color: %1 ! important;\n" ) - .tqarg( bgColor ) ); - const TQString bodyFontSize = TQString::number( pointsToPixel( helper->mMetrics, fontSize( fixed ) ) ) + "px" ; - const TQColorGroup & cg = TQApplication::tqpalette().active(); - - TQString quoteCSS; - if ( bodyFont( fixed ).italic() ) - quoteCSS += " font-style: italic ! important;\n"; - if ( bodyFont( fixed ).bold() ) - quoteCSS += " font-weight: bold ! important;\n"; - if ( !quoteCSS.isEmpty() ) - quoteCSS = "div.noquote {\n" + quoteCSS + "}\n\n"; - - // CSS definitions for quote levels 1-3 - for ( int i = 0 ; i < 3 ; ++i ) { - quoteCSS += TQString( "div.quotelevel%1 {\n" - " color: %2 ! important;\n" ) - .tqarg( TQString::number(i+1), mQuoteColor[i].name() ); - if ( mQuoteFont[i].italic() ) - quoteCSS += " font-style: italic ! important;\n"; - if ( mQuoteFont[i].bold() ) - quoteCSS += " font-weight: bold ! important;\n"; - if ( mShrinkQuotes ) - quoteCSS += " font-size: " + TQString::tqfromLatin1( quoteFontSizes[i] ) - + "% ! important;\n"; - quoteCSS += "}\n\n"; - } - - // CSS definitions for quote levels 4+ - for ( int i = 0 ; i < 3 ; ++i ) { - quoteCSS += TQString( "div.deepquotelevel%1 {\n" - " color: %2 ! important;\n" ) - .tqarg( TQString::number(i+1), mQuoteColor[i].name() ); - if ( mQuoteFont[i].italic() ) - quoteCSS += " font-style: italic ! important;\n"; - if ( mQuoteFont[i].bold() ) - quoteCSS += " font-weight: bold ! important;\n"; - if ( mShrinkQuotes ) - quoteCSS += " font-size: 70% ! important;\n"; - quoteCSS += "}\n\n"; - } - - return - TQString( "body {\n" - " font-family: \"%1\" ! important;\n" - " font-size: %2 ! important;\n" - " color: %3 ! important;\n" - "%4" - "}\n\n" ) - .tqarg( bodyFont( fixed ).family(), - bodyFontSize, - fgColor, - background ) - + - TQString( "a {\n" - " color: %1 ! important;\n" - " text-decoration: none ! important;\n" - "}\n\n" - - "a.white {\n" - " color: white ! important;\n" - "}\n\n" - - "a.black {\n" - " color: black ! important;\n" - "}\n\n" - - "table.textAtm { background-color: %2 ! important; }\n\n" - - "tr.textAtmH {\n" - " background-color: %3 ! important;\n" - "%4" - "}\n\n" - - "tr.textAtmB {\n" - " background-color: %3 ! important;\n" - "}\n\n" - - "table.signInProgress,\n" - "table.rfc822 {\n" - " background-color: %3 ! important;\n" - "}\n\n" - - "tr.signInProgressH,\n" - "tr.rfc822H {\n" - "%4" - "}\n\n" ) - .tqarg( linkColor, fgColor, bgColor, headerFont ) - + - TQString( "table.encr {\n" - " background-color: %1 ! important;\n" - "}\n\n" - - "tr.encrH {\n" - " background-color: %2 ! important;\n" - "%3" - "}\n\n" - - "tr.encrB { background-color: %4 ! important; }\n\n" ) - .tqarg( cPgpEncrF.name(), - cPgpEncrH.name(), - headerFont, - cPgpEncrB.name() ) - + - TQString( "table.signOkKeyOk {\n" - " background-color: %1 ! important;\n" - "}\n\n" - - "tr.signOkKeyOkH {\n" - " background-color: %2 ! important;\n" - "%3" - "}\n\n" - - "tr.signOkKeyOkB { background-color: %4 ! important; }\n\n" ) - .tqarg( cPgpOk1F.name(), - cPgpOk1H.name(), - headerFont, - cPgpOk1B.name() ) - + - TQString( "table.signOkKeyBad {\n" - " background-color: %1 ! important;\n" - "}\n\n" - - "tr.signOkKeyBadH {\n" - " background-color: %2 ! important;\n" - "%3" - "}\n\n" - - "tr.signOkKeyBadB { background-color: %4 ! important; }\n\n" ) - .tqarg( cPgpOk0F.name(), - cPgpOk0H.name(), - headerFont, - cPgpOk0B.name() ) - + - TQString( "table.signWarn {\n" - " background-color: %1 ! important;\n" - "}\n\n" - - "tr.signWarnH {\n" - " background-color: %2 ! important;\n" - "%3" - "}\n\n" - - "tr.signWarnB { background-color: %4 ! important; }\n\n" ) - .tqarg( cPgpWarnF.name(), - cPgpWarnH.name(), - headerFont, - cPgpWarnB.name() ) - + - TQString( "table.signErr {\n" - " background-color: %1 ! important;\n" - "}\n\n" - - "tr.signErrH {\n" - " background-color: %2 ! important;\n" - "%3" - "}\n\n" - - "tr.signErrB { background-color: %4 ! important; }\n\n" ) - .tqarg( cPgpErrF.name(), - cPgpErrH.name(), - headerFont, - cPgpErrB.name() ) - + - TQString( "div.htmlWarn {\n" - " border: 2px solid %1 ! important;\n" - "}\n\n" ) - .tqarg( cHtmlWarning.name() ) - + - TQString( "div.header {\n" - "%1" - "}\n\n" - - "div.fancy.header > div {\n" - " background-color: %2 ! important;\n" - " color: %3 ! important;\n" - " border: solid %4 1px ! important;\n" - "}\n\n" - - "div.fancy.header > div a[href] { color: %3 ! important; }\n\n" - - "div.fancy.header > div a[href]:hover { text-decoration: underline ! important; }\n\n" - - "div.fancy.header > div.spamheader {\n" - " background-color: #cdcdcd ! important;\n" - " border-top: 0px ! important;\n" - " padding: 3px ! important;\n" - " color: black ! important;\n" - " font-weight: bold ! important;\n" - " font-size: smaller ! important;\n" - "}\n\n" - - "div.fancy.header > table.outer {\n" - " background-color: %5 ! important;\n" - " color: %4 ! important;\n" - " border-bottom: solid %4 1px ! important;\n" - " border-left: solid %4 1px ! important;\n" - " border-right: solid %4 1px ! important;\n" - "}\n\n" - - "div.senderpic{\n" - " padding: 0px ! important;\n" - " font-size:0.8em ! important;\n" - " border:1px solid %6 ! important;\n" - // FIXME: InfoBackground crashes KHTML - //" background-color:InfoBackground ! important;\n" - " background-color:%5 ! important;\n" - "}\n\n" - - "div.senderstatus{\n" - " text-align:center ! important;\n" - "}\n\n" - ) - - .tqarg( headerFont ) - .tqarg( cg.highlight().name(), - cg.highlightedText().name(), - cg.foreground().name(), - cg.background().name() ) - .tqarg( cg.mid().name() ) - + quoteCSS; - } - - TQString CSSHelper::commonCssDefinitions() const { - return - "div.header {\n" - " margin-bottom: 10pt ! important;\n" - "}\n\n" - - "table.textAtm {\n" - " margin-top: 10pt ! important;\n" - " margin-bottom: 10pt ! important;\n" - "}\n\n" - - "tr.textAtmH,\n" - "tr.textAtmB,\n" - "tr.rfc822B {\n" - " font-weight: normal ! important;\n" - "}\n\n" - - "tr.signInProgressH,\n" - "tr.rfc822H,\n" - "tr.encrH,\n" - "tr.signOkKeyOkH,\n" - "tr.signOkKeyBadH,\n" - "tr.signWarnH,\n" - "tr.signErrH {\n" - " font-weight: bold ! important;\n" - "}\n\n" - - "tr.textAtmH td,\n" - "tr.textAtmB td {\n" - " padding: 3px ! important;\n" - "}\n\n" - - "table.rfc822 {\n" - " width: 100% ! important;\n" - " border: solid 1px black ! important;\n" - " margin-top: 10pt ! important;\n" - " margin-bottom: 10pt ! important;\n" - "}\n\n" - - "table.textAtm,\n" - "table.encr,\n" - "table.signWarn,\n" - "table.signErr,\n" - "table.signOkKeyBad,\n" - "table.signOkKeyOk,\n" - "table.signInProgress,\n" - "div.fancy.header table {\n" - " width: 100% ! important;\n" - " border-width: 0px ! important;\n" - "}\n\n" - - "div.htmlWarn {\n" - " margin: 0px 5% ! important;\n" - " padding: 10px ! important;\n" - " text-align: left ! important;\n" - "}\n\n" - - "div.fancy.header > div {\n" - " font-weight: bold ! important;\n" - " padding: 4px ! important;\n" - "}\n\n" - - "div.fancy.header table {\n" - " padding: 2px ! important;\n" // ### khtml bug: this is ignored - " text-align: left ! important\n" - "}\n\n" - - "div.fancy.header table th {\n" - " padding: 0px ! important;\n" - " white-space: nowrap ! important;\n" - " border-spacing: 0px ! important;\n" - " text-align: left ! important;\n" - " vertical-align: top ! important;\n" - "}\n\n" - - "div.fancy.header table td {\n" - " padding: 0px ! important;\n" - " border-spacing: 0px ! important;\n" - " text-align: left ! important;\n" - " vertical-align: top ! important;\n" - " width: 100% ! important;\n" - "}\n\n" - - "span.pimsmileytext {\n" - " position: absolute;\n" - " top: 0px;\n" - " left: 0px;\n" - " visibility: hidden;\n" - "}\n\n" - - "img.pimsmileyimg {\n" - "}\n\n" - - "div.quotelevelmark {\n" - " position: absolute;\n" - " margin-left:-10px;\n" - "}\n\n" - ; - } - - - void CSSHelper::setBodyFont( const TQFont& font ) - { - mBodyFont = font; - } - - void CSSHelper::setPrintFont( const TQFont& font ) - { - mPrintFont = font; - } - - TQColor CSSHelper::pgpWarnColor() const - { - return cPgpWarnH; - } - -} // namespace KPIM diff --git a/libkdepim/csshelper.h b/libkdepim/csshelper.h deleted file mode 100644 index ab9190cf8..000000000 --- a/libkdepim/csshelper.h +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- c++ -*- - csshelper.h - - This file is part of KMail, the KDE mail client. - Copyright (c) 2003 Marc Mutz - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 KPIM_CSSHELPER_H -#define KPIM_CSSHELPER_H - -#include -#include -#include - -class TQString; - -namespace KPIM { - -class CSSHelper { - public: - /** Construct a CSSHelper object and set its font and color settings to - default values. - Sub-Classes should put their config loading here. - */ - CSSHelper( const TQPaintDeviceMetrics &pdm ); - - /** @return HTML head including style sheet definitions and the - >body< tag */ - TQString htmlHead( bool fixedFont = false ) const; - - /** @return The collected CSS definitions as a string */ - TQString cssDefinitions( bool fixedFont = false ) const; - - /** @return a <div> start tag with embedded style - information suitable for quoted text with quote level @p level */ - TQString quoteFontTag( int level ) const; - /** @return a <div> start tag with embedded style - information suitable for non-quoted text */ - TQString nonQuotedFontTag() const; - - TQFont bodyFont( bool fixedFont = false, bool printing = false ) const; - - void setBodyFont( const TQFont& font ); - void setPrintFont( const TQFont& font ); - - TQColor pgpWarnColor() const; - - protected: - /** Recalculate PGP frame and body colors (should be called after changing - color settings) */ - void recalculatePGPColors(); - - protected: - TQFont mBodyFont, mPrintFont, mFixedFont, mFixedPrintFont; - TQFont mQuoteFont[3]; - TQColor mQuoteColor[3]; - bool mRecycleQuoteColors; - bool mBackingPixmapOn; - bool mShrinkQuotes; - TQString mBackingPixmapStr; - TQColor mForegroundColor, mLinkColor, mVisitedLinkColor, mBackgroundColor; - // colors for PGP (Frame, Header, Body) - TQColor cPgpOk1F, cPgpOk1H, cPgpOk1B, - cPgpOk0F, cPgpOk0H, cPgpOk0B, - cPgpWarnF, cPgpWarnH, cPgpWarnB, - cPgpErrF, cPgpErrH, cPgpErrB, - cPgpEncrF, cPgpEncrH, cPgpEncrB; - // color of frame of warning preceding the source of HTML messages - TQColor cHtmlWarning; - - private: - int fontSize( bool fixed, bool print = false ) const; - // returns CSS rules specific to the print media type - TQString printCssDefinitions( bool fixed ) const; - // returns CSS rules specific to the screen media type - TQString screenCssDefinitions( const CSSHelper * helper, bool fixed ) const; - // returns CSS rules common to both screen and print media types - TQString commonCssDefinitions() const; - - private: - const TQPaintDeviceMetrics mMetrics; - -}; - -} // namespace KPIM - -#endif // KPIM_CSSHELPER_H diff --git a/libkdepim/designerfields.cpp b/libkdepim/designerfields.cpp deleted file mode 100644 index 1a07655f7..000000000 --- a/libkdepim/designerfields.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - Copyright (c) 2004 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "designerfields.h" - -using namespace KPIM; - -DesignerFields::DesignerFields( const TQString &uiFile, TQWidget *parent, - const char *name ) - : TQWidget( parent, name ) -{ - initGUI( uiFile ); -} - -void DesignerFields::initGUI( const TQString &uiFile ) -{ - TQVBoxLayout *tqlayout = new TQVBoxLayout( this ); - - TQWidget *wdg = TQWidgetFactory::create( uiFile, 0, this ); - if ( !wdg ) { - kdError() << "No ui file found" << endl; - return; - } - - mTitle = wdg->caption(); - mIdentifier = wdg->name(); - - tqlayout->addWidget( wdg ); - - TQObjectList *list = wdg->queryList( TQWIDGET_OBJECT_NAME_STRING ); - TQObjectListIt it( *list ); - - TQStringList allowedTypes; - allowedTypes << TQLINEEDIT_OBJECT_NAME_STRING - << TQTEXTEDIT_OBJECT_NAME_STRING - << TQSPINBOX_OBJECT_NAME_STRING - << TQCHECKBOX_OBJECT_NAME_STRING - << TQCOMBOBOX_OBJECT_NAME_STRING - << TQDATETIMEEDIT_OBJECT_NAME_STRING - << "KLineEdit" - << "KDateTimeWidget" - << "KDatePicker"; - - while ( it.current() ) { - if ( allowedTypes.contains( it.current()->className() ) ) { - TQString name = it.current()->name(); - if ( name.startsWith( "X_" ) ) { - name = name.mid( 2 ); - - TQWidget *widget = TQT_TQWIDGET( it.current() ); - if ( !name.isEmpty() ) - mWidgets.insert( name, widget ); - - if ( it.current()->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) ) - connect( it.current(), TQT_SIGNAL( textChanged( const TQString& ) ), - TQT_SIGNAL( modified() ) ); - else if ( it.current()->inherits( TQSPINBOX_OBJECT_NAME_STRING ) ) - connect( it.current(), TQT_SIGNAL( valueChanged( int ) ), - TQT_SIGNAL( modified() ) ); - else if ( it.current()->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) ) - connect( it.current(), TQT_SIGNAL( toggled( bool ) ), - TQT_SIGNAL( modified() ) ); - else if ( it.current()->inherits( TQCOMBOBOX_OBJECT_NAME_STRING ) ) - connect( it.current(), TQT_SIGNAL( activated( const TQString& ) ), - TQT_SIGNAL( modified() ) ); - else if ( it.current()->inherits( TQDATETIMEEDIT_OBJECT_NAME_STRING ) ) - connect( it.current(), TQT_SIGNAL( valueChanged( const TQDateTime& ) ), - TQT_SIGNAL( modified() ) ); - else if ( it.current()->inherits( "KDateTimeWidget" ) ) - connect( it.current(), TQT_SIGNAL( valueChanged( const TQDateTime& ) ), - TQT_SIGNAL( modified() ) ); - else if ( it.current()->inherits( "KDatePicker" ) ) - connect( it.current(), TQT_SIGNAL( dateChanged( TQDate ) ), - TQT_SIGNAL( modified() ) ); - else if ( it.current()->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) ) - connect( it.current(), TQT_SIGNAL( textChanged() ), - TQT_SIGNAL( modified() ) ); - - if ( !widget->isEnabled() ) - mDisabledWidgets.append( widget ); - } - } - - ++it; - } - - delete list; -} - -TQString DesignerFields::identifier() const -{ - return mIdentifier; -} - -TQString DesignerFields::title() const -{ - return mTitle; -} - -void DesignerFields::load( DesignerFields::Storage *storage ) -{ - TQStringList keys = storage->keys(); - - // clear all custom page widgets - // we can't do this in the following loop, as it works on the - // custom fields of the vcard, which may not be set. - TQMap::ConstIterator widIt; - for ( widIt = mWidgets.begin(); widIt != mWidgets.end(); ++widIt ) { - TQString value; - if ( widIt.data()->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) ) { - TQLineEdit *wdg = static_cast( widIt.data() ); - wdg->setText( TQString() ); - } else if ( widIt.data()->inherits( TQSPINBOX_OBJECT_NAME_STRING ) ) { - TQSpinBox *wdg = static_cast( widIt.data() ); - wdg->setValue( wdg->minValue() ); - } else if ( widIt.data()->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) ) { - TQCheckBox *wdg = static_cast( widIt.data() ); - wdg->setChecked( false ); - } else if ( widIt.data()->inherits( TQDATETIMEEDIT_OBJECT_NAME_STRING ) ) { - TQDateTimeEdit *wdg = static_cast( widIt.data() ); - wdg->setDateTime( TQDateTime::tqcurrentDateTime() ); - } else if ( widIt.data()->inherits( "KDateTimeWidget" ) ) { - KDateTimeWidget *wdg = static_cast( widIt.data() ); - wdg->setDateTime( TQDateTime::tqcurrentDateTime() ); - } else if ( widIt.data()->inherits( "KDatePicker" ) ) { - KDatePicker *wdg = static_cast( widIt.data() ); - wdg->setDate( TQDate::tqcurrentDate() ); - } else if ( widIt.data()->inherits( TQCOMBOBOX_OBJECT_NAME_STRING ) ) { - TQComboBox *wdg = static_cast( widIt.data() ); - wdg->setCurrentItem( 0 ); - } else if ( widIt.data()->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) ) { - TQTextEdit *wdg = static_cast( widIt.data() ); - wdg->setText( TQString() ); - } - } - - TQStringList::ConstIterator it2; - for ( it2 = keys.begin(); it2 != keys.end(); ++it2 ) { - TQString value = storage->read( *it2 ); - - TQMap::ConstIterator it = mWidgets.find( *it2 ); - if ( it != mWidgets.end() ) { - if ( it.data()->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) ) { - TQLineEdit *wdg = static_cast( it.data() ); - wdg->setText( value ); - } else if ( it.data()->inherits( TQSPINBOX_OBJECT_NAME_STRING ) ) { - TQSpinBox *wdg = static_cast( it.data() ); - wdg->setValue( value.toInt() ); - } else if ( it.data()->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) ) { - TQCheckBox *wdg = static_cast( it.data() ); - wdg->setChecked( value == "true" || value == "1" ); - } else if ( it.data()->inherits( TQDATETIMEEDIT_OBJECT_NAME_STRING ) ) { - TQDateTimeEdit *wdg = static_cast( it.data() ); - wdg->setDateTime( TQDateTime::fromString( value, Qt::ISODate ) ); - } else if ( it.data()->inherits( "KDateTimeWidget" ) ) { - KDateTimeWidget *wdg = static_cast( it.data() ); - wdg->setDateTime( TQDateTime::fromString( value, Qt::ISODate ) ); - } else if ( it.data()->inherits( "KDatePicker" ) ) { - KDatePicker *wdg = static_cast( it.data() ); - wdg->setDate( TQDate::fromString( value, Qt::ISODate ) ); - } else if ( it.data()->inherits( TQCOMBOBOX_OBJECT_NAME_STRING ) ) { - TQComboBox *wdg = static_cast( it.data() ); - wdg->setCurrentText( value ); - } else if ( it.data()->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) ) { - TQTextEdit *wdg = static_cast( it.data() ); - wdg->setText( value ); - } - } - } -} - -void DesignerFields::save( DesignerFields::Storage *storage ) -{ - TQMap::Iterator it; - for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) { - TQString value; - if ( it.data()->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) ) { - TQLineEdit *wdg = static_cast( it.data() ); - value = wdg->text(); - } else if ( it.data()->inherits( TQSPINBOX_OBJECT_NAME_STRING ) ) { - TQSpinBox *wdg = static_cast( it.data() ); - value = TQString::number( wdg->value() ); - } else if ( it.data()->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) ) { - TQCheckBox *wdg = static_cast( it.data() ); - value = ( wdg->isChecked() ? "true" : "false" ); - } else if ( it.data()->inherits( TQDATETIMEEDIT_OBJECT_NAME_STRING ) ) { - TQDateTimeEdit *wdg = static_cast( it.data() ); - value = wdg->dateTime().toString( Qt::ISODate ); - } else if ( it.data()->inherits( "KDateTimeWidget" ) ) { - KDateTimeWidget *wdg = static_cast( it.data() ); - value = wdg->dateTime().toString( Qt::ISODate ); - } else if ( it.data()->inherits( "KDatePicker" ) ) { - KDatePicker *wdg = static_cast( it.data() ); - value = wdg->date().toString( Qt::ISODate ); - } else if ( it.data()->inherits( TQCOMBOBOX_OBJECT_NAME_STRING ) ) { - TQComboBox *wdg = static_cast( it.data() ); - value = wdg->currentText(); - } else if ( it.data()->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) ) { - TQTextEdit *wdg = static_cast( it.data() ); - value = wdg->text(); - } - - storage->write( it.key(), value ); - } -} - -void DesignerFields::setReadOnly( bool readOnly ) -{ - TQMap::Iterator it; - for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) - if ( mDisabledWidgets.find( it.data() ) == mDisabledWidgets.end() ) - it.data()->setEnabled( !readOnly ); -} - -#include "designerfields.moc" diff --git a/libkdepim/designerfields.h b/libkdepim/designerfields.h deleted file mode 100644 index c7c2d22ca..000000000 --- a/libkdepim/designerfields.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - Copyright (c) 2004 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KPIM_DESIGNERFIELDS_H -#define KPIM_DESIGNERFIELDS_H - -#include - -#include -#include -#include - -#include - -namespace KPIM { - -class KDE_EXPORT DesignerFields : public TQWidget -{ - Q_OBJECT - TQ_OBJECT - public: - DesignerFields( const TQString &uiFile, TQWidget *parent, - const char *name = 0 ); - - class Storage - { - public: - virtual ~Storage() {} - - virtual TQStringList keys() = 0; - virtual TQString read( const TQString &key ) = 0; - virtual void write( const TQString &key, const TQString &value ) = 0; - }; - - void load( Storage * ); - void save( Storage * ); - - void setReadOnly( bool readOnly ); - - TQString identifier() const; - TQString title() const; - - signals: - void modified(); - - private: - void initGUI( const TQString& ); - - TQMap mWidgets; - TQValueList mDisabledWidgets; - TQString mTitle; - TQString mIdentifier; -}; - -} - -#endif diff --git a/libkdepim/diffalgo.cpp b/libkdepim/diffalgo.cpp deleted file mode 100644 index b2cfc40eb..000000000 --- a/libkdepim/diffalgo.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include - -using namespace KPIM; - -void DiffAlgo::begin() -{ - TQValueList::Iterator it; - for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) - (*it)->begin(); -} - -void DiffAlgo::end() -{ - TQValueList::Iterator it; - for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) - (*it)->end(); -} - -void DiffAlgo::setLeftSourceTitle( const TQString &title ) -{ - TQValueList::Iterator it; - for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) - (*it)->setLeftSourceTitle( title ); -} - -void DiffAlgo::setRightSourceTitle( const TQString &title ) -{ - TQValueList::Iterator it; - for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) - (*it)->setRightSourceTitle( title ); -} - -void DiffAlgo::additionalLeftField( const TQString &id, const TQString &value ) -{ - TQValueList::Iterator it; - for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) - (*it)->additionalLeftField( id, value ); -} - -void DiffAlgo::additionalRightField( const TQString &id, const TQString &value ) -{ - TQValueList::Iterator it; - for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) - (*it)->additionalRightField( id, value ); -} - -void DiffAlgo::conflictField( const TQString &id, const TQString &leftValue, - const TQString &rightValue ) -{ - TQValueList::Iterator it; - for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) - (*it)->conflictField( id, leftValue, rightValue ); -} - -void DiffAlgo::addDisplay( DiffAlgoDisplay *display ) -{ - if ( mDisplays.find( display ) == mDisplays.end() ) - mDisplays.append( display ); -} - -void DiffAlgo::removeDisplay( DiffAlgoDisplay *display ) -{ - mDisplays.remove( display ); -} diff --git a/libkdepim/diffalgo.h b/libkdepim/diffalgo.h deleted file mode 100644 index 513db7e33..000000000 --- a/libkdepim/diffalgo.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef DIFFALGO_H -#define DIFFALGO_H - -#include -#include - -namespace KPIM { - -/** - DiffAlgo and DiffAlgoDisplay work together for displaying differences between - two PIM objects like contacts, events or todos. - DiffAlgo is the bas class for the diffing algorithm and DiffAlgoDisplay is - responsible for representation. The separation makes it possible to use one - display for all diffing algorithm and vice versa. - */ -class DiffAlgoDisplay -{ - public: - - /** - Is called on the start of the diff. - */ - virtual void begin() = 0; - - /** - Is called on the end of the diff. - */ - virtual void end() = 0; - - /** - Sets the title of the left data source. - */ - virtual void setLeftSourceTitle( const TQString &title ) = 0; - - /** - Sets the title of the right data source. - */ - virtual void setRightSourceTitle( const TQString &title ) = 0; - - /** - Adds a field which is only available in the left data source. - */ - virtual void additionalLeftField( const TQString &id, const TQString &value ) = 0; - - /** - Adds a field which is only available in the right data source. - */ - virtual void additionalRightField( const TQString &id, const TQString &value ) = 0; - - /** - Adds a conflict between two fields. - */ - virtual void conflictField( const TQString &id, const TQString &leftValue, - const TQString &rightValue ) = 0; -}; - - -class KDE_EXPORT DiffAlgo -{ - public: - /** - Destructor. - */ - virtual ~DiffAlgo() {} - - /** - Starts the diffing algorithm. - */ - virtual void run() = 0; - - /** - Must be called on the start of the diff. - */ - void begin(); - - /** - Must be called on the end of the diff. - */ - void end(); - - /** - Sets the title of the left data source. - */ - void setLeftSourceTitle( const TQString &title ); - - /** - Sets the title of the right data source. - */ - void setRightSourceTitle( const TQString &title ); - - /** - Adds a field which is only available in the left data source. - */ - void additionalLeftField( const TQString &id, const TQString &value ); - - /** - Adds a field which is only available in the right data source. - */ - void additionalRightField( const TQString &id, const TQString &value ); - - /** - Adds a conflict between two fields. - */ - void conflictField( const TQString &id, const TQString &leftValue, - const TQString &rightValue ); - - void addDisplay( DiffAlgoDisplay *display ); - void removeDisplay( DiffAlgoDisplay *display ); - - - private: - TQValueList mDisplays; -}; - -} - -#endif diff --git a/libkdepim/distributionlist.cpp b/libkdepim/distributionlist.cpp deleted file mode 100644 index 4cf079c76..000000000 --- a/libkdepim/distributionlist.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#include "distributionlist.h" -#include - -static const char* s_customFieldName = "DistributionList"; - -KPIM::DistributionList::DistributionList() - : KABC::Addressee() -{ - // can't insert the custom entry here, we need to remain a null addressee -} - -KPIM::DistributionList::DistributionList( const KABC::Addressee& addr ) - : KABC::Addressee( addr ) -{ -} - -void KPIM::DistributionList::setName( const TQString &name ) -{ - // We can't use Addressee::setName, the name isn't saved/loaded in the vcard (fixed in 3.4) - Addressee::setFormattedName( name ); - // Also set family name, just in case this entry appears in the normal contacts list (e.g. old kaddressbook) - Addressee::setFamilyName( name ); - // We're not an empty addressee anymore - // Set the custom field to non-empty, so that isDistributionList works - if ( custom( "KADDRESSBOOK", s_customFieldName ).isEmpty() ) - insertCustom( "KADDRESSBOOK", s_customFieldName, ";" ); -} - -// Helper function, to parse the contents of the custom field -// Returns a list of { uid, email } -typedef TQValueList > ParseList; -static ParseList parseCustom( const TQString& str ) -{ - ParseList res; - const TQStringList lst = TQStringList::split( ';', str ); - for( TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { - if ( (*it).isEmpty() ) - continue; - // parse "uid,email" - TQStringList helpList = TQStringList::split( ',', (*it), true ); - Q_ASSERT( !helpList.isEmpty() ); - if ( helpList.isEmpty() ) - continue; - Q_ASSERT( helpList.count() < 3 ); // 1 or 2 items, but not more - const TQString uid = helpList.first(); - const TQString email = helpList.last(); - res.append( tqMakePair( uid, email ) ); - } - return res; -} - -void KPIM::DistributionList::insertEntry( const Addressee& addr, const TQString& email ) -{ - // insertEntry will removeEntry(uid), but not with formattedName - removeEntry( addr.formattedName(), email ); - insertEntry( addr.uid(), email ); -} - -void KPIM::DistributionList::insertEntry( const TQString& uid, const TQString& email ) -{ - Q_ASSERT( !email.isEmpty() || email.isNull() ); // hopefully never called with "", would lead to confusion - removeEntry( uid, email ); // avoid duplicates - TQString str = custom( "KADDRESSBOOK", s_customFieldName ); - // Assumption: UIDs don't contain ; nor , - str += ";" + uid + "," + email; - insertCustom( "KADDRESSBOOK", s_customFieldName, str ); // replace old value -} - -void KPIM::DistributionList::removeEntry( const Addressee& addr, const TQString& email ) -{ - removeEntry( addr.uid(), email ); - // Also remove entries with the full name as uid (for the kolab thing) - removeEntry( addr.formattedName(), email ); -} - -void KPIM::DistributionList::removeEntry( const TQString& uid, const TQString& email ) -{ - Q_ASSERT( !email.isEmpty() || email.isNull() ); // hopefully never called with "", would lead to confusion - ParseList parseList = parseCustom( custom( "KADDRESSBOOK", s_customFieldName ) ); - TQString str; - for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) { - const TQString thisUid = (*it).first; - const TQString thisEmail = (*it).second; - if ( thisUid == uid && thisEmail == email ) { - continue; // remove that one - } - str += ";" + thisUid + "," + thisEmail; - } - if ( str.isEmpty() ) - str = ";"; // keep something, for isDistributionList to work - insertCustom( "KADDRESSBOOK", s_customFieldName, str ); // replace old value -} - -bool KPIM::DistributionList::isDistributionList( const KABC::Addressee& addr ) -{ - const TQString str = addr.custom( "KADDRESSBOOK", s_customFieldName ); - return !str.isEmpty(); -} - -// ###### KDE4: add findByFormattedName to KABC::AddressBook -static KABC::Addressee::List findByFormattedName( KABC::AddressBook* book, - const TQString& name, - bool caseSensitive = true ) -{ - KABC::Addressee::List res; - KABC::AddressBook::Iterator abIt; - for ( abIt = book->begin(); abIt != book->end(); ++abIt ) - { - if ( caseSensitive && (*abIt).formattedName() == name ) - res.append( *abIt ); - if ( !caseSensitive && (*abIt).formattedName().lower() == name.lower() ) - res.append( *abIt ); - } - return res; -} - -KPIM::DistributionList KPIM::DistributionList::findByName( KABC::AddressBook* book, - const TQString& name, - bool caseSensitive ) -{ - KABC::AddressBook::Iterator abIt; - for ( abIt = book->begin(); abIt != book->end(); ++abIt ) - { - if ( isDistributionList( *abIt ) ) { - if ( caseSensitive && (*abIt).formattedName() == name ) - return *abIt; - if ( !caseSensitive && (*abIt).formattedName().lower() == name.lower() ) - return *abIt; - } - } - return DistributionList(); -} - -static KABC::Addressee findByUidOrName( KABC::AddressBook* book, const TQString& uidOrName, const TQString& email ) -{ - KABC::Addressee a = book->findByUid( uidOrName ); - if ( a.isEmpty() ) { - // UID not found, maybe it is a name instead. - // If we have an email, let's use that for the lookup. - // [This is used by e.g. the Kolab resource] - if ( !email.isEmpty() ) { - KABC::Addressee::List lst = book->findByEmail( email ); - KABC::Addressee::List::ConstIterator listit = lst.begin(); - for ( ; listit != lst.end(); ++listit ) - if ( (*listit).formattedName() == uidOrName ) { - a = *listit; - break; - } - if ( !lst.isEmpty() && a.isEmpty() ) { // found that email, but no match on the fullname - a = lst.first(); // probably the last name changed - } - } - // If we don't have an email, or if we didn't find any match for it, look up by full name - if ( a.isEmpty() ) { - // (But this has to be done here, since when loading we might not have the entries yet) - KABC::Addressee::List lst = findByFormattedName( book, uidOrName ); - if ( !lst.isEmpty() ) - a = lst.first(); - } - } - return a; -} - -KPIM::DistributionList::Entry::List KPIM::DistributionList::entries( KABC::AddressBook* book ) const -{ - Entry::List res; - const TQString str = custom( "KADDRESSBOOK", s_customFieldName ); - const ParseList parseList = parseCustom( str ); - for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) { - const TQString uid = (*it).first; - const TQString email = (*it).second; - // look up contact - KABC::Addressee a = findByUidOrName( book, uid, email ); - if ( a.isEmpty() ) { - // ## The old DistributionListManager had a "missing entries" list... - kdWarning() << "Addressee not found: " << uid << endl; - } else { - res.append( Entry( a, email ) ); - } - } - return res; -} - -TQStringList KPIM::DistributionList::emails( KABC::AddressBook* book ) const -{ - TQStringList emails; - - const TQString str = custom( "KADDRESSBOOK", s_customFieldName ); - ParseList parseList = parseCustom( str ); - for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) { - const TQString thisUid = (*it).first; - const TQString thisEmail = (*it).second; - - // look up contact - KABC::Addressee a = findByUidOrName( book, thisUid, thisEmail ); - if ( a.isEmpty() ) { - // ## The old DistributionListManager had a "missing entries" list... - continue; - } - - const TQString email = thisEmail.isEmpty() ? a.fullEmail() : - a.fullEmail( thisEmail ); - if ( !email.isEmpty() ) { - emails.append( email ); - } - } - - return emails; -} - -TQValueList - KPIM::DistributionList::allDistributionLists( KABC::AddressBook* book ) -{ - TQValueList lst; - KABC::AddressBook::Iterator abIt; - for ( abIt = book->begin(); abIt != book->end(); ++abIt ) - { - if ( isDistributionList( *abIt ) ) { - lst.append( KPIM::DistributionList( *abIt ) ); - } - } - return lst; -} diff --git a/libkdepim/distributionlist.h b/libkdepim/distributionlist.h deleted file mode 100644 index 99391fca3..000000000 --- a/libkdepim/distributionlist.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - This file is part of libtdepim. - Copyright (c) 2004-2005 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef DISTRIBUTIONLIST_H -#define DISTRIBUTIONLIST_H - -#include - -namespace KABC { -class AddressBook; -} - -namespace KPIM { - -/** - * @short Distribution list of email addresses - * - * This class represents a list of email addresses. Each email address is - * associated with an address book entry. If the address book entry changes, the - * entry in the distribution list is automatically updated. - * - * This should go into kdelibs in KDE4. - * - * @author David Faure - */ -class DistributionList : public KABC::Addressee -{ - public: - /** - * @short Distribution List Entry - * - * This class represents an entry of a distribution list. It consists of an - * addressee and an email address. If the email address is null, the - * preferred email address of the addressee is used. - */ - struct Entry - { - typedef TQValueList List; - - Entry() {} - Entry( const Addressee &_addressee, const TQString &_email ) : - addressee( _addressee ), email( _email ) {} - - Addressee addressee; - TQString email; - }; - - typedef TQValueList List; - - /** - * Create a distribution list. - */ - DistributionList(); - /** - * Create a distribution list from an addressee object - * (this is a kind of down-cast) - */ - DistributionList( const KABC::Addressee& addr ); - - /** - * Destructor. - */ - ~DistributionList() {} - - /// HACK: reimplemented from Addressee, but it's NOT virtual there - void setName( const TQString &name ); - - /// HACK: reimplemented from Addressee, but it's NOT virtual there - TQString name() const { return formattedName(); } - - /** - Insert an entry into this distribution list. If the entry already exists - nothing happens. - */ - void insertEntry( const Addressee &, const TQString &email=TQString() ); - - /** - Remove an entry from this distribution list. If the entry doesn't exist - nothing happens. - */ - void removeEntry( const Addressee &, const TQString &email=TQString() ); - - /// Overload, used by resources to avoid looking up the addressee - void insertEntry( const TQString& uid, const TQString& email=TQString() ); - /// Overload, used by resources to avoid looking up the addressee - void removeEntry( const TQString& uid, const TQString& email=TQString() ); - - - /** - Return list of email addresses, which belong to this distributon list. - These addresses can be directly used by e.g. a mail client. - @param book necessary to look up entries - */ - TQStringList emails( KABC::AddressBook* book ) const; - - /** - Return list of entries belonging to this distribution list. This function - is mainly useful for a distribution list editor. - @param book necessary to look up entries - */ - Entry::List entries( KABC::AddressBook* book ) const; - - // KDE4: should be a method of Addressee - static bool isDistributionList( const KABC::Addressee& addr ); - - // KDE4: should be a method of AddressBook - static DistributionList findByName( KABC::AddressBook* book, - const TQString& name, - bool caseSensitive = true ); - // KDE4: should be a method of AddressBook - // A bit slow (but no more than findByName). - // From KAddressbook, use Core::distributionLists() instead. - static TQValueList allDistributionLists( KABC::AddressBook* book ); - - - private: - // can't have any data here, use Addressee's methods instead -}; - -} - -#endif /* DISTRIBUTIONLIST_H */ - diff --git a/libkdepim/embeddedurlpage.cpp b/libkdepim/embeddedurlpage.cpp deleted file mode 100644 index 3971bf367..000000000 --- a/libkdepim/embeddedurlpage.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2005 Reinhold Kainhofer - Part of loadContents() copied from the kpartsdesignerplugin: - Copyright (C) 2005, David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "embeddedurlpage.h" -#include -#include -#include -#include -#include -#include -#include - -using namespace KPIM; - -EmbeddedURLPage::EmbeddedURLPage( const TQString &url, const TQString &mimetype, - TQWidget *parent, const char *name ) - : TQWidget( parent, name ), mUri(url), mMimeType( mimetype ), mPart( 0 ) -{ - initGUI( url, mimetype ); -} - -void EmbeddedURLPage::initGUI( const TQString &url, const TQString &/*mimetype*/ ) -{ - TQVBoxLayout *tqlayout = new TQVBoxLayout( this ); - tqlayout->setAutoAdd( true ); - new TQLabel( i18n("Showing URL %1").tqarg( url ), this ); -} - -void EmbeddedURLPage::loadContents() -{ - if ( !mPart ) { - if ( mMimeType.isEmpty() || mUri.isEmpty() ) - return; - TQString mimetype = mMimeType; - if ( mimetype == "auto" ) - mimetype == KMimeType::findByURL( mUri )->name(); - // "this" is both the parent widget and the parent object - mPart = KParts::ComponentFactory::createPartInstanceFromQuery( mimetype, TQString(), TQT_TQWIDGET(this), 0, TQT_TQOBJECT(this), 0 ); - if ( mPart ) { - mPart->openURL( mUri ); - mPart->widget()->show(); - } -//void KParts::BrowserExtension::openURLRequestDelayed( const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() ) - KParts::BrowserExtension* be = KParts::BrowserExtension::childObject( mPart ); - connect( be, TQT_SIGNAL( openURLRequestDelayed( const KURL &, const KParts::URLArgs & ) ), -// mPart, TQT_SLOT( openURL( const KURL & ) ) ); - this, TQT_SIGNAL( openURL( const KURL & ) ) ); - } -} - -#include "embeddedurlpage.moc" diff --git a/libkdepim/embeddedurlpage.h b/libkdepim/embeddedurlpage.h deleted file mode 100644 index c306466cd..000000000 --- a/libkdepim/embeddedurlpage.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2005 Reinhold Kainhofer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KPIM_EMBEDDEDURLPAGE_H -#define KPIM_EMBEDDEDURLPAGE_H - -#include -#include -#include - -namespace KParts { class ReadOnlyPart; } - -namespace KPIM { - -class KDE_EXPORT EmbeddedURLPage : public TQWidget -{ - Q_OBJECT - TQ_OBJECT - public: - EmbeddedURLPage( const TQString &url, const TQString &mimetype, - TQWidget *parent, const char *name = 0 ); - - public slots: - void loadContents(); - signals: - void openURL( const KURL &url ); - private: - void initGUI( const TQString &url, const TQString &mimetype ); - - TQString mUri; - TQString mMimeType; - KParts::ReadOnlyPart* mPart; -}; - -} - -#endif diff --git a/libkdepim/groupwarejob.cpp b/libkdepim/groupwarejob.cpp deleted file mode 100644 index bd413e12b..000000000 --- a/libkdepim/groupwarejob.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "groupwarejob.h" - -#include -#include - -using namespace KIO; - -KIO::TransferJob *GroupwareJob::getCalendar( const KURL &u ) -{ - KURL url = u; - url.setPath( "/calendar/" ); - - kdDebug() << "GroupwareJob::getCalendar(): URL: " << url << endl; - - return KIO::get( url, false, false ); -} - -KIO::TransferJob *GroupwareJob::getAddressBook( const KURL &u ) -{ - KURL url = u; - url.setPath( "/addressbook/" ); - - kdDebug() << "GroupwareJob::getAddressBook(): URL: " << url << endl; - - return KIO::get( url, false, false ); -} diff --git a/libkdepim/groupwarejob.h b/libkdepim/groupwarejob.h deleted file mode 100644 index bf5a33f6e..000000000 --- a/libkdepim/groupwarejob.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KIO_GROUPWAREJOB_H -#define KIO_GROUPWAREJOB_H - -#include - -namespace KIO { - -class GroupwareJob -{ - public: - static KIO::TransferJob *getCalendar( const KURL & ); - static KIO::TransferJob *getAddressBook( const KURL & ); -}; - -} - -#endif diff --git a/libkdepim/htmldiffalgodisplay.cpp b/libkdepim/htmldiffalgodisplay.cpp deleted file mode 100644 index 726854e4e..000000000 --- a/libkdepim/htmldiffalgodisplay.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include - -#include - -using namespace KPIM; - -static TQString textToHTML( const TQString &text ) -{ - return TQStyleSheet::convertFromPlainText( text ); -} - -HTMLDiffAlgoDisplay::HTMLDiffAlgoDisplay( TQWidget *parent ) - : KTextBrowser( parent ) -{ - setWrapPolicy( TQTextEdit::AtWordBoundary ); - setVScrollBarMode( TQScrollView::AlwaysOff ); - setHScrollBarMode( TQScrollView::AlwaysOff ); -} - -void HTMLDiffAlgoDisplay::begin() -{ - clear(); - mText = ""; - - mText.append( "" ); - mText.append( TQString( "" ) - .tqarg( KGlobalSettings::textColor().name() ) - .tqarg( KGlobalSettings::baseColor().name() ) ); - - mText.append( "
" ); - mText.append( TQString( "" ) - .tqarg( mLeftTitle ) - .tqarg( mRightTitle ) ); -} - -void HTMLDiffAlgoDisplay::end() -{ - mText.append( "
%1 %2
" - "" - "" ); - - setText( mText ); -} - -void HTMLDiffAlgoDisplay::setLeftSourceTitle( const TQString &title ) -{ - mLeftTitle = title; -} - -void HTMLDiffAlgoDisplay::setRightSourceTitle( const TQString &title ) -{ - mRightTitle = title; -} - -void HTMLDiffAlgoDisplay::additionalLeftField( const TQString &id, const TQString &value ) -{ - mText.append( TQString( "%1:%2" ) - .tqarg( id ) - .tqarg( textToHTML( value ) ) ); -} - -void HTMLDiffAlgoDisplay::additionalRightField( const TQString &id, const TQString &value ) -{ - mText.append( TQString( "%1:%2" ) - .tqarg( id ) - .tqarg( textToHTML( value ) ) ); -} - -void HTMLDiffAlgoDisplay::conflictField( const TQString &id, const TQString &leftValue, - const TQString &rightValue ) -{ - mText.append( TQString( "%1:%2%3" ) - .tqarg( id ) - .tqarg( textToHTML( leftValue ) ) - .tqarg( textToHTML( rightValue ) ) ); -} diff --git a/libkdepim/htmldiffalgodisplay.h b/libkdepim/htmldiffalgodisplay.h deleted file mode 100644 index 35d95f5c8..000000000 --- a/libkdepim/htmldiffalgodisplay.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPIM_HTMLDIFFALGODISPLAY_H -#define KPIM_HTMLDIFFALGODISPLAY_H - -#include "diffalgo.h" - -#include -#include - -namespace KPIM { - -class KDE_EXPORT HTMLDiffAlgoDisplay : virtual public DiffAlgoDisplay, public KTextBrowser -{ - public: - HTMLDiffAlgoDisplay( TQWidget *parent ); - - void begin(); - void end(); - void setLeftSourceTitle( const TQString &title ); - void setRightSourceTitle( const TQString &title ); - void additionalLeftField( const TQString &id, const TQString &value ); - void additionalRightField( const TQString &id, const TQString &value ); - void conflictField( const TQString &id, const TQString &leftValue, - const TQString &rightValue ); - - private: - TQString mLeftTitle; - TQString mRightTitle; - TQString mText; -}; - -} - -#endif diff --git a/libkdepim/icons/CMakeLists.txt b/libkdepim/icons/CMakeLists.txt deleted file mode 100644 index 189a3a200..000000000 --- a/libkdepim/icons/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -################################################# -# -# (C) 2010-2011 Serghei Amelian -# serghei (DOT) amelian (AT) gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# - -tde_install_icons() diff --git a/libkdepim/icons/Makefile.am b/libkdepim/icons/Makefile.am deleted file mode 100644 index 2e31aecbf..000000000 --- a/libkdepim/icons/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -KDE_ICON=AUTO - diff --git a/libkdepim/icons/cr22-action-button_fewer.png b/libkdepim/icons/cr22-action-button_fewer.png deleted file mode 100644 index 96919575a..000000000 Binary files a/libkdepim/icons/cr22-action-button_fewer.png and /dev/null differ diff --git a/libkdepim/icons/cr22-action-button_more.png b/libkdepim/icons/cr22-action-button_more.png deleted file mode 100644 index 31c064ba9..000000000 Binary files a/libkdepim/icons/cr22-action-button_more.png and /dev/null differ diff --git a/libkdepim/infoextension.cpp b/libkdepim/infoextension.cpp deleted file mode 100644 index 25f7e8ba7..000000000 --- a/libkdepim/infoextension.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2003 Sven Lüppken - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - - #include "infoextension.h" - -#include -#include - -using namespace KParts; - -InfoExtension::InfoExtension( KParts::ReadOnlyPart *parent, const char* name) -: TQObject(parent, name), d(0) -{ -} - -InfoExtension::~InfoExtension() -{ -} - -#include "infoextension.moc" diff --git a/libkdepim/infoextension.h b/libkdepim/infoextension.h deleted file mode 100644 index b857dc4a5..000000000 --- a/libkdepim/infoextension.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2003 Sven Lüppken - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#ifndef INFOEXTENSION_H -#define INFOEXTENSION_H - -#include -#include - -class TQWidget; - -namespace KParts -{ - - class ReadOnlyPart; - - /** - * Provides a way to get information out of a PIM-Part - **/ - class KDE_EXPORT InfoExtension : public TQObject - { - Q_OBJECT - TQ_OBJECT - - public: - /** - * Constucts an InfoExtension. - * - * @param parent The parent widget. - * @param name The name of the class. - **/ - InfoExtension( KParts::ReadOnlyPart *parent, const char* name); - ~InfoExtension(); - - private: - class InfoExtensionPrivate; - InfoExtensionPrivate *d; - - signals: - void textChanged( const TQString& ); - void iconChanged( const TQPixmap& ); - }; -} -#endif // INFOEXTENSION_H diff --git a/libkdepim/interfaces/AddressBookServiceIface.h b/libkdepim/interfaces/AddressBookServiceIface.h deleted file mode 100644 index e07ac3e76..000000000 --- a/libkdepim/interfaces/AddressBookServiceIface.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef ADDRESSBOOKSERVICEIFACE_H -#define ADDRESSBOOKSERVICEIFACE_H - -#include -#include -#include -#include -#include -#include - -namespace KPIM { - -#define AddressBookServiceIface KDE_EXPORT AddressBookServiceIface - class AddressBookServiceIface : virtual public DCOPObject -#undef AddressBookServiceIface - { - K_DCOP - - k_dcop: - /** - This method will add a vcard to the address book. - - @param vCard The vCard in string representation. - */ - virtual void importVCardFromData( const TQString& vCard ) = 0; - - /** - This method will add a vcard to the address book. - - @param url The url where the vcard is located. - */ - virtual void importVCard( const KURL& url ) = 0; - }; - -} - -#endif - diff --git a/libkdepim/interfaces/MailTransportServiceIface.h b/libkdepim/interfaces/MailTransportServiceIface.h deleted file mode 100644 index d256775a3..000000000 --- a/libkdepim/interfaces/MailTransportServiceIface.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Daniel Molkentin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef MAILTRANSPORTSERVICEIFACE_H -#define MAILTRANSPORTSERVICEIFACE_H - -#include -#include -#include -#include -#include - -#include - -namespace KPim { - -#define MailTransportServiceIface KDE_EXPORT MailTransportServiceIface - class MailTransportServiceIface : virtual public DCOPObject -#undef MailTransportServiceIface - { - K_DCOP - - k_dcop: - /** - * This method will compose a message and send it using the mailers - * preferred transport. The mimetype of the attachments passed is - * determined using mime magic. - * - * @return true when the message was send successfully, false on failure. - **/ - virtual bool sendMessage( const TQString& from, const TQString& to, - const TQString& cc, const TQString& bcc, - const TQString& subject, const TQString& body, - const KURL::List& attachments ) = 0; - - /** - * This method basically behaves like the one above, but takes only one - * attachment as TQByteArray. This is useful if you want to attach simple - * text files (e.g. a vCalendar). The mimetype is determined using - * mime magic. - * - * @return true when the message was send successfully, false on failure. - **/ - virtual bool sendMessage( const TQString& from, const TQString& to, - const TQString& cc, const TQString& bcc, - const TQString& subject, const TQString& body, - const TQByteArray& attachment ) = 0; - - k_dcop_hidden: - /** - * This method is deprecated. Use the corresponding method with the - * additional parameter from instead. - **/ - // FIXME KDE 4.0: Remove this. - virtual bool sendMessage( const TQString& to, - const TQString& cc, const TQString& bcc, - const TQString& subject, const TQString& body, - const KURL::List& attachments ) = 0; - - /** - * This method is deprecated. Use the corresponding method with the - * additional parameter from instead. - **/ - // FIXME KDE 4.0: Remove this. - virtual bool sendMessage( const TQString& to, - const TQString& cc, const TQString& bcc, - const TQString& subject, const TQString& body, - const TQByteArray& attachment ) = 0; - - }; - -} - -#endif // MAILTRANSPORTSERVICEIFACE_H - diff --git a/libkdepim/interfaces/Makefile.am b/libkdepim/interfaces/Makefile.am deleted file mode 100644 index e69de29bb..000000000 diff --git a/libkdepim/kabcresourcecached.cpp b/libkdepim/kabcresourcecached.cpp deleted file mode 100644 index eece76351..000000000 --- a/libkdepim/kabcresourcecached.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* - This file is part of libtdepim. - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "kabcresourcecached.h" - -using namespace KABC; - -ResourceCached::ResourceCached( const KConfig *config ) - : KABC::Resource( config ), mIdMapper( "kabc/uidmaps/" ), - mReloadPolicy( ReloadInterval ), mReloadInterval( 10 ), - mKABCReloadTimer( 0, "mKABCReloadTimer" ), mReloaded( false ), - mSavePolicy( SaveDelayed ), mSaveInterval( 10 ), - mKABCSaveTimer( 0, "mKABCSaveTimer" ) -{ - connect( &mKABCReloadTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotKABCReload() ) ); - connect( &mKABCSaveTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotKABCSave() ) ); - - if (config) - this->readConfig(const_cast(config)); -} - -ResourceCached::~ResourceCached() -{ -} - -void ResourceCached::setReloadPolicy( int i ) -{ - mReloadPolicy = i; - - setupReloadTimer(); -} - -int ResourceCached::reloadPolicy() const -{ - return mReloadPolicy; -} - -void ResourceCached::setReloadInterval( int minutes ) -{ - mReloadInterval = minutes; -} - -int ResourceCached::reloadInterval() const -{ - return mReloadInterval; -} - -void ResourceCached::setSavePolicy( int i ) -{ - mSavePolicy = i; - - setupSaveTimer(); -} - -int ResourceCached::savePolicy() const -{ - return mSavePolicy; -} - -void ResourceCached::setSaveInterval( int minutes ) -{ - mSaveInterval = minutes; -} - -int ResourceCached::saveInterval() const -{ - return mSaveInterval; -} - -void ResourceCached::writeConfig( KConfig *config ) -{ - config->writeEntry( "ReloadPolicy", mReloadPolicy ); - config->writeEntry( "ReloadInterval", mReloadInterval ); - - config->writeEntry( "SavePolicy", mSavePolicy ); - config->writeEntry( "SaveInterval", mSaveInterval ); - - config->writeEntry( "LastLoad", mLastLoad ); - config->writeEntry( "LastSave", mLastSave ); - - KABC::Resource::writeConfig( config ); -} - -void ResourceCached::readConfig( KConfig *config ) -{ - mReloadPolicy = config->readNumEntry( "ReloadPolicy", ReloadNever ); - mReloadInterval = config->readNumEntry( "ReloadInterval", 10 ); - - mSaveInterval = config->readNumEntry( "SaveInterval", 10 ); - mSavePolicy = config->readNumEntry( "SavePolicy", SaveNever ); - - mLastLoad = config->readDateTimeEntry( "LastLoad" ); - mLastSave = config->readDateTimeEntry( "LastSave" ); - - setupSaveTimer(); - setupReloadTimer(); -} - -void ResourceCached::setupSaveTimer() -{ - if ( mSavePolicy == SaveInterval ) { - kdDebug(5800) << "ResourceCached::setSavePolicy(): start save timer (interval " - << mSaveInterval << " minutes)." << endl; - mKABCSaveTimer.start( mSaveInterval * 60 * 1000 ); // n minutes - } else { - mKABCSaveTimer.stop(); - } -} - -void ResourceCached::setupReloadTimer() -{ - if ( mReloadPolicy == ReloadInterval ) { - kdDebug(5800) << "ResourceCached::setSavePolicy(): start reload timer " - "(interval " << mReloadInterval << " minutes)" << endl; - mKABCReloadTimer.start( mReloadInterval * 60 * 1000 ); // n minutes - } else { - mKABCReloadTimer.stop(); - } -} - -void ResourceCached::slotKABCReload() -{ - if ( !isActive() ) return; - - kdDebug(5800) << "ResourceCached::slotKABCReload()" << endl; - - load(); -} - -void ResourceCached::slotKABCSave() -{ - if ( !isActive() ) return; - - kdDebug(5800) << "ResourceCached::slotKABCSave()" << endl; - - KABC::Ticket *ticket = requestSaveTicket(); - if ( ticket ) { - save( ticket ); - } -} - -void ResourceCached::insertAddressee( const Addressee &addr ) -{ - if ( !mAddrMap.contains( addr.uid() ) ) { // new contact - if ( mDeletedAddressees.contains( addr.uid() ) ) { - // it was first removed, then added, so it's an update... - mDeletedAddressees.remove( addr.uid() ); - - mAddrMap.insert( addr.uid(), addr ); - mChangedAddressees.insert( addr.uid(), addr ); - return; - } - - mAddrMap.insert( addr.uid(), addr ); - mAddedAddressees.insert( addr.uid(), addr ); - } else { - KABC::Addressee oldAddressee = mAddrMap.find( addr.uid() ).data(); - if ( oldAddressee != addr ) { - mAddrMap.remove( addr.uid() ); - mAddrMap.insert( addr.uid(), addr ); - mChangedAddressees.insert( addr.uid(), addr ); - } - } -} - -void ResourceCached::removeAddressee( const Addressee &addr ) -{ - if ( mAddedAddressees.contains( addr.uid() ) ) { - mAddedAddressees.remove( addr.uid() ); - return; - } - - if ( mDeletedAddressees.find( addr.uid() ) == mDeletedAddressees.end() ) - mDeletedAddressees.insert( addr.uid(), addr ); - - mAddrMap.remove( addr.uid() ); -} - -void ResourceCached::loadCache() -{ - mAddrMap.clear(); - - setIdMapperIdentifier(); - mIdMapper.load(); - - // load cache - TQFile file( cacheFile() ); - if ( !file.open( IO_ReadOnly ) ) - return; - - - KABC::VCardConverter converter; -#if defined(KABC_VCARD_ENCODING_FIX) - KABC::Addressee::List list = converter.parseVCardsRaw( file.readAll().data() ); -#else - KABC::Addressee::List list = converter.parseVCards( TQString::fromUtf8( file.readAll() ) ); -#endif - KABC::Addressee::List::Iterator it; - - for ( it = list.begin(); it != list.end(); ++it ) { - (*it).setResource( this ); - (*it).setChanged( false ); - mAddrMap.insert( (*it).uid(), *it ); - } - - file.close(); -} - -void ResourceCached::saveCache() -{ - setIdMapperIdentifier(); - mIdMapper.save(); - - // save cache - TQFile file( cacheFile() ); - if ( !file.open( IO_WriteOnly ) ) - return; - - KABC::Addressee::List list = mAddrMap.values(); - - KABC::VCardConverter converter; -#if defined(KABC_VCARD_ENCODING_FIX) - TQCString vCard = converter.createVCardsRaw( list ); - file.writeBlock( vCard, vCard.length() ); -#else - TQString vCard = converter.createVCards( list ); - file.writeBlock( vCard.utf8(), vCard.utf8().length() ); -#endif - file.close(); -} - -void ResourceCached::clearCache() -{ - // TEST ME - mAddrMap.clear(); -} - -void ResourceCached::cleanUpCache( const KABC::Addressee::List &addrList ) -{ - // load cache - TQFile file( cacheFile() ); - if ( !file.open( IO_ReadOnly ) ) - return; - - - KABC::VCardConverter converter; -#if defined(KABC_VCARD_ENCODING_FIX) - KABC::Addressee::List list = converter.parseVCardsRaw( file.readAll().data() ); -#else - KABC::Addressee::List list = converter.parseVCards( TQString::fromUtf8( file.readAll() ) ); -#endif - KABC::Addressee::List::Iterator cacheIt; - KABC::Addressee::List::ConstIterator it; - - for ( cacheIt = list.begin(); cacheIt != list.end(); ++cacheIt ) { - bool found = false; - for ( it = addrList.begin(); it != addrList.end(); ++it ) { - if ( (*it).uid() == (*cacheIt).uid() ) - found = true; - } - - if ( !found ) { - mIdMapper.removeRemoteId( mIdMapper.remoteId( (*cacheIt).uid() ) ); - mAddrMap.remove( (*cacheIt).uid() ); - } - } - - file.close(); -} - -KPIM::IdMapper& ResourceCached::idMapper() -{ - return mIdMapper; -} - -bool ResourceCached::hasChanges() const -{ - return !( mAddedAddressees.isEmpty() && - mChangedAddressees.isEmpty() && - mDeletedAddressees.isEmpty() ); -} - -void ResourceCached::clearChanges() -{ - mAddedAddressees.clear(); - mChangedAddressees.clear(); - mDeletedAddressees.clear(); -} - -void ResourceCached::clearChange( const KABC::Addressee &addr ) -{ - mAddedAddressees.remove( addr.uid() ); - mChangedAddressees.remove( addr.uid() ); - mDeletedAddressees.remove( addr.uid() ); -} - -void ResourceCached::clearChange( const TQString &uid ) -{ - mAddedAddressees.remove( uid ); - mChangedAddressees.remove( uid ); - mDeletedAddressees.remove( uid ); -} - -KABC::Addressee::List ResourceCached::addedAddressees() const -{ - return mAddedAddressees.values(); -} - -KABC::Addressee::List ResourceCached::changedAddressees() const -{ - return mChangedAddressees.values(); -} - -KABC::Addressee::List ResourceCached::deletedAddressees() const -{ - return mDeletedAddressees.values(); -} - -TQString ResourceCached::cacheFile() const -{ - return locateLocal( "cache", "kabc/kresources/" + identifier() ); -} - -TQString ResourceCached::changesCacheFile( const TQString &type ) const -{ - return locateLocal( "cache", "kabc/changescache/" + identifier() + "_" + type ); -} - -void ResourceCached::saveChangesCache( const TQMap &map, const TQString &type ) -{ - TQFile file( changesCacheFile( type ) ); - - const KABC::Addressee::List list = map.values(); - if ( list.isEmpty() ) { - file.remove(); - } else { - if ( !file.open( IO_WriteOnly ) ) { - kdError() << "Can't open changes cache file '" << file.name() << "' for saving." << endl; - return; - } - - KABC::VCardConverter converter; -#if defined(KABC_VCARD_ENCODING_FIX) - const TQCString vCards = converter.createVCardsRaw( list ); - file.writeBlock( vCards, vCards.length() ); -#else - const TQString vCards = converter.createVCards( list ); - TQCString content = vCards.utf8(); - file.writeBlock( content, content.length() ); -#endif - } -} - -void ResourceCached::saveChangesCache() -{ - saveChangesCache( mAddedAddressees, "added" ); - saveChangesCache( mDeletedAddressees, "deleted" ); - saveChangesCache( mChangedAddressees, "changed" ); -} - -void ResourceCached::loadChangesCache( TQMap &map, const TQString &type ) -{ - TQFile file( changesCacheFile( type ) ); - if ( !file.open( IO_ReadOnly ) ) - return; - - KABC::VCardConverter converter; - -#if defined(KABC_VCARD_ENCODING_FIX) - const KABC::Addressee::List list = converter.parseVCardsRaw( file.readAll().data() ); -#else - const KABC::Addressee::List list = converter.parseVCards( TQString::fromUtf8( file.readAll() ) ); -#endif - KABC::Addressee::List::ConstIterator it; - for ( it = list.begin(); it != list.end(); ++it ) - map.insert( (*it).uid(), *it ); - - file.close(); -} - -void ResourceCached::loadChangesCache() -{ - loadChangesCache( mAddedAddressees, "added" ); - loadChangesCache( mDeletedAddressees, "deleted" ); - loadChangesCache( mChangedAddressees, "changed" ); -} - -void ResourceCached::setIdMapperIdentifier() -{ - mIdMapper.setIdentifier( type() + "_" + identifier() ); -} - -#include "kabcresourcecached.moc" diff --git a/libkdepim/kabcresourcecached.h b/libkdepim/kabcresourcecached.h deleted file mode 100644 index 2cf0352ef..000000000 --- a/libkdepim/kabcresourcecached.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - This file is part of libtdepim. - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KABC_RESOURCECACHED_H -#define KABC_RESOURCECACHED_H - -#include -#include - -#include -#include - -#include "libemailfunctions/idmapper.h" - -namespace KABC { - -class KDE_EXPORT ResourceCached : public Resource -{ - Q_OBJECT - TQ_OBJECT - - public: - /** - Reload policy. - - @see setReloadPolicy(), reloadPolicy() - */ - enum { ReloadNever, ReloadOnStartup, ReloadInterval }; - /** - Save policy. - - @see setSavePolicy(), savePolicy() - */ - enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways }; - - ResourceCached( const KConfig* ); - ~ResourceCached(); - - /** - Set reload policy. This controls when the cache is refreshed. - - ReloadNever never reload - ReloadOnStartup reload when resource is started - ReloadInterval reload regularly after given interval - */ - void setReloadPolicy( int policy ); - /** - Return reload policy. - - @see setReloadPolicy() - */ - int reloadPolicy() const; - - /** - Set reload interval in minutes which is used when reload policy is - ReloadInterval. - */ - void setReloadInterval( int minutes ); - - /** - Return reload interval in minutes. - */ - int reloadInterval() const; - - /** - Set save policy. This controls when the cache is refreshed. - - SaveNever never save - SaveOnExit save when resource is exited - SaveInterval save regularly after given interval - SaveDelayed save after small delay - SaveAlways save on every change - */ - void setSavePolicy( int policy ); - /** - Return save policy. - - @see setsavePolicy() - */ - int savePolicy() const; - - /** - Set save interval in minutes which is used when save policy is - SaveInterval. - */ - void setSaveInterval( int minutes ); - - /** - Return save interval in minutes. - */ - int saveInterval() const; - - void setupSaveTimer(); - void setupReloadTimer(); - - /** - Reads the resource specific config from disk. - */ - virtual void readConfig( KConfig *config ); - - /** - Writes the resource specific config to disk. - */ - virtual void writeConfig( KConfig *config ); - - /** - Insert an addressee into the resource. - */ - virtual void insertAddressee( const Addressee& ); - - /** - Removes an addressee from resource. - */ - virtual void removeAddressee( const Addressee& addr ); - - void loadCache(); - void saveCache(); - void clearCache(); - void cleanUpCache( const KABC::Addressee::List &list ); - - /** - Returns a reference to the id mapper. - */ - KPIM::IdMapper& idMapper(); - - bool hasChanges() const; - void clearChanges(); - void clearChange( const KABC::Addressee& ); - void clearChange( const TQString& ); - - KABC::Addressee::List addedAddressees() const; - KABC::Addressee::List changedAddressees() const; - KABC::Addressee::List deletedAddressees() const; - - protected: - virtual TQString cacheFile() const; - - /** - Functions for keeping the changes persistent. - */ - virtual TQString changesCacheFile( const TQString& ) const; - void loadChangesCache( TQMap&, const TQString& ); - void loadChangesCache(); - void saveChangesCache( const TQMap&, const TQString& ); - void saveChangesCache(); - - void setIdMapperIdentifier(); - - private: - TQMap mAddedAddressees; - TQMap mChangedAddressees; - TQMap mDeletedAddressees; - - KPIM::IdMapper mIdMapper; - - class ResourceCachedPrivate; - ResourceCachedPrivate *d; - - int mReloadPolicy; - int mReloadInterval; - TQTimer mKABCReloadTimer; - bool mReloaded; - - int mSavePolicy; - int mSaveInterval; - TQTimer mKABCSaveTimer; - - TQDateTime mLastLoad; - TQDateTime mLastSave; - - protected slots: - void slotKABCReload(); - void slotKABCSave(); -}; - -} - -#endif diff --git a/libkdepim/kabcresourcenull.h b/libkdepim/kabcresourcenull.h deleted file mode 100644 index 7d77b89b7..000000000 --- a/libkdepim/kabcresourcenull.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KABC_RESOURCENULL_H -#define KABC_RESOURCENULL_H - -#include - -namespace KABC { - -/** - This resource does nothing. -*/ -class ResourceNull : public Resource -{ - public: - ResourceNull( const KConfig *cfg ) : Resource( cfg ) {} - ResourceNull() : Resource( 0 ) {} - virtual ~ResourceNull() {} - - Ticket *requestSaveTicket() { return 0; } - void releaseSaveTicket( Ticket * ) {} - bool load() { return false; } - bool save( Ticket * ) { return false; } -}; - -} - -#endif diff --git a/libkdepim/kaccount.cpp b/libkdepim/kaccount.cpp deleted file mode 100644 index 392fea265..000000000 --- a/libkdepim/kaccount.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- c++ -*- - kaccount.cpp - - This file is part of KMail, the KDE mail client. - - Copyright (C) 2002 Carsten Burghardt - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 "kaccount.h" - -#include - -KAccount::KAccount( const uint id, const TQString &name, const Type type ) - : mId( id ), mName( name ), mType( type ) -{ -} - -void KAccount::writeConfig( KConfig &config, const TQString &group ) -{ - TQString oldGroup = config.group(); - if (!group.isEmpty()) - config.setGroup(group); - config.writeEntry("Id", mId); - config.writeEntry("Name", mName); - if (!group.isEmpty()) // restore - config.setGroup(oldGroup); -} - -void KAccount::readConfig( KConfig &config, const TQString &group ) -{ - TQString oldGroup = config.group(); - if (!group.isEmpty()) - config.setGroup(group); - mId = config.readUnsignedNumEntry("Id", 0); - mName = config.readEntry("Name"); - if (!group.isEmpty()) // restore - config.setGroup(oldGroup); -} diff --git a/libkdepim/kaccount.h b/libkdepim/kaccount.h deleted file mode 100644 index d0a1b7f21..000000000 --- a/libkdepim/kaccount.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- c++ -*- - kaccount.h - - This file is part of KMail, the KDE mail client. - Copyright (C) 2002 Carsten Burghardt - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 __KACCOUNT -#define __KACCOUNT - -#include -#include - -class KConfig; - -class KDE_EXPORT KAccount -{ - public: - /** Type information */ - enum Type { - Imap, - MBox, - Maildir, - News, - DImap, - Other - }; - - KAccount( const uint id = 0, const TQString &name = TQString(), - const Type type = Other ); - - /** - * Get/Set name - */ - TQString name() const { return mName; } - void setName( const TQString& name ) { mName = name; } - - /** - * Get/Set id - */ - uint id() const { return mId; } - void setId( const uint id ) { mId = id; } - - /** - * Get/Set type - */ - Type type() const { return mType; } - void setType( const Type type ) { mType = type; } - - /** - * Save the settings - * If the group is empty it must be preset in the KConfig - */ - void writeConfig( KConfig &config, const TQString &group = TQString() ); - - /** - * Read the settings - * If the group is empty it must be preset in the KConfig - */ - void readConfig( KConfig &config, const TQString &group = TQString() ); - - protected: - uint mId; - TQString mName; - Type mType; -}; - -#endif diff --git a/libkdepim/kaddrbook.cpp b/libkdepim/kaddrbook.cpp deleted file mode 100644 index 1036a263b..000000000 --- a/libkdepim/kaddrbook.cpp +++ /dev/null @@ -1,285 +0,0 @@ -// -*- mode: C++; c-file-style: "gnu" -*- -// kaddrbook.cpp -// Author: Stefan Taferner -// This code is under GPL - -#include - -#include "kaddrbook.h" - -#ifdef KDEPIM_NEW_DISTRLISTS -#include "distributionlist.h" -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -//----------------------------------------------------------------------------- -void KAddrBookExternal::openEmail( const TQString &addr, TQWidget *parent ) { - TQString email; - TQString name; - - KABC::Addressee::parseEmailAddress( addr, name, email ); - - KABC::AddressBook *ab = KABC::StdAddressBook::self( true ); - - // force a reload of the address book file so that changes that were made - // by other programs are loaded - ab->asyncLoad(); - - // if we have to reload the address book then we should also wait until - // it's completely reloaded -#if KDE_IS_VERSION(3,4,89) - // This ugly hack will be removed in 4.0 - while ( !ab->loadingHasFinished() ) { - TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput ); - - // use sleep here to reduce cpu usage - usleep( 100 ); - } -#endif - - KABC::Addressee::List addressees = ab->findByEmail( email ); - - if ( addressees.count() > 0 ) { - if ( kapp->dcopClient()->isApplicationRegistered( "kaddressbook" ) ){ - //make sure kaddressbook is loaded, otherwise showContactEditor - //won't work as desired, see bug #87233 - DCOPRef call ( "kaddressbook", "kaddressbook" ); - call.send( "newInstance()" ); - } else { - kapp->startServiceByDesktopName( "kaddressbook" ); - } - - DCOPRef call( "kaddressbook", "KAddressBookIface" ); - call.send( "showContactEditor(TQString)", addressees.first().uid() ); - } else { - //TODO: Enable the better message at the next string unfreeze -#if 0 - TQString text = i18n("The email address %1 cannot be " - "found in your addressbook.").tqarg( email ); -#else - TQString text = email + " " + i18n( "is not in address book" ); -#endif - KMessageBox::information( parent, text, TQString(), "notInAddressBook" ); - } -} - -//----------------------------------------------------------------------------- -void KAddrBookExternal::addEmail( const TQString& addr, TQWidget *parent) { - TQString email; - TQString name; - - KABC::Addressee::parseEmailAddress( addr, name, email ); - - KABC::AddressBook *ab = KABC::StdAddressBook::self( true ); - - ab->setErrorHandler( new KABC::GuiErrorHandler( parent ) ); - - // force a reload of the address book file so that changes that were made - // by other programs are loaded - ab->asyncLoad(); - - // if we have to reload the address book then we should also wait until - // it's completely reloaded -#if KDE_IS_VERSION(3,4,89) - // This ugly hack will be removed in 4.0 - while ( !ab->loadingHasFinished() ) { - TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput ); - - // use sleep here to reduce cpu usage - usleep( 100 ); - } -#endif - - KABC::Addressee::List addressees = ab->findByEmail( email ); - - if ( addressees.isEmpty() ) { - KABC::Addressee a; - a.setNameFromString( name ); - a.insertEmail( email, true ); - - { - KConfig config( "kaddressbookrc" ); - config.setGroup( "General" ); - int type = config.readNumEntry( "FormattedNameType", 1 ); - - TQString name; - switch ( type ) { - case 1: - name = a.givenName() + " " + a.familyName(); - break; - case 2: - name = a.assembledName(); - break; - case 3: - name = a.familyName() + ", " + a.givenName(); - break; - case 4: - name = a.familyName() + " " + a.givenName(); - break; - case 5: - name = a.organization(); - break; - default: - name = ""; - break; - } - name.simplifyWhiteSpace(); - - a.setFormattedName( name ); - } - - if ( KAddrBookExternal::addAddressee( a ) ) { - TQString text = i18n("The email address %1 was added to your " - "addressbook; you can add more information to this " - "entry by opening the addressbook.").tqarg( addr ); - KMessageBox::information( parent, text, TQString(), "addedtokabc" ); - } - } else { - TQString text = i18n("The email address %1 is already in your " - "addressbook.").tqarg( addr ); - KMessageBox::information( parent, text, TQString(), - "alreadyInAddressBook" ); - } - ab->setErrorHandler( 0 ); -} - -void KAddrBookExternal::openAddressBook(TQWidget *) { - kapp->startServiceByDesktopName( "kaddressbook" ); -} - -void KAddrBookExternal::addNewAddressee( TQWidget* ) -{ - kapp->startServiceByDesktopName("kaddressbook"); - DCOPRef call("kaddressbook", "KAddressBookIface"); - call.send("newContact()"); -} - -bool KAddrBookExternal::addVCard( const KABC::Addressee& addressee, TQWidget *parent ) -{ - KABC::AddressBook *ab = KABC::StdAddressBook::self( true ); - bool inserted = false; - - ab->setErrorHandler( new KABC::GuiErrorHandler( parent ) ); - - KABC::Addressee::List addressees = - ab->findByEmail( addressee.preferredEmail() ); - - if ( addressees.isEmpty() ) { - if ( KAddrBookExternal::addAddressee( addressee ) ) { - TQString text = i18n("The VCard was added to your addressbook; " - "you can add more information to this " - "entry by opening the addressbook."); - KMessageBox::information( parent, text, TQString(), "addedtokabc" ); - inserted = true; - } - } else { - TQString text = i18n("The VCard's primary email address is already in " - "your addressbook; however, you may save the VCard " - "into a file and import it into the addressbook " - "manually."); - KMessageBox::information( parent, text ); - inserted = true; - } - - ab->setErrorHandler( 0 ); - return inserted; -} - -bool KAddrBookExternal::addAddressee( const KABC::Addressee& addr ) -{ - KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); - KABC::Resource *kabcResource = selectResourceForSaving( addressBook ); - if( !kabcResource ) - return false; - KABC::Ticket *ticket = addressBook->requestSaveTicket( kabcResource ); - bool saved = false; - if ( ticket ) { - KABC::Addressee addressee( addr ); - addressee.setResource( kabcResource ); - addressBook->insertAddressee( addressee ); - saved = addressBook->save( ticket ); - if ( !saved ) - addressBook->releaseSaveTicket( ticket ); - } - - addressBook->emitAddressBookChanged(); - - return saved; -} - -TQString KAddrBookExternal::expandDistributionList( const TQString& listName ) -{ - if ( listName.isEmpty() ) - return TQString(); - - const TQString lowerListName = listName.lower(); - KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); -#ifdef KDEPIM_NEW_DISTRLISTS - KPIM::DistributionList distrList = KPIM::DistributionList::findByName( addressBook, lowerListName, false ); - if ( !distrList.isEmpty() ) { - return distrList.emails( addressBook ).join( ", " ); - } -#else - KABC::DistributionListManager manager( addressBook ); - manager.load(); - const TQStringList listNames = manager.listNames(); - - for ( TQStringList::ConstIterator it = listNames.begin(); - it != listNames.end(); ++it) { - if ( (*it).lower() == lowerListName ) { - const TQStringList addressList = manager.list( *it )->emails(); - return addressList.join( ", " ); - } - } -#endif - return TQString(); -} - -KABC::Resource* KAddrBookExternal::selectResourceForSaving( KABC::AddressBook *addressBook ) -{ -#if KDE_IS_VERSION(3,4,89) - // This ugly hack will be removed in 4.0 - while ( !addressBook->loadingHasFinished() ) { - TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput ); - - // use sleep here to reduce cpu usage - usleep( 100 ); - } -#endif - - // Select a resource - TQPtrList kabcResources = addressBook->resources(); - - TQPtrList kresResources; - TQPtrListIterator resIt( kabcResources ); - KABC::Resource *kabcResource; - while ( ( kabcResource = resIt.current() ) != 0 ) { - ++resIt; - if ( !kabcResource->readOnly() ) { - KRES::Resource *res = static_cast( kabcResource ); - if ( res ) - kresResources.append( res ); - } - } - - return static_cast( KRES::SelectDialog::getResource( kresResources, 0 ) ); -} diff --git a/libkdepim/kaddrbook.h b/libkdepim/kaddrbook.h deleted file mode 100644 index f2bab1003..000000000 --- a/libkdepim/kaddrbook.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Simple Addressbook for KMail - * Author: Stefan Taferner - * This code is under GPL - */ -#ifndef KAddrBook_h -#define KAddrBook_h - -#include - -#include -#include -#include - -namespace KABC { - class AddressBook; -} - -class TQWidget; - -class KDE_EXPORT KAddrBookExternal { -public: - static void addEmail( const TQString &addr, TQWidget *parent ); - static void addNewAddressee( TQWidget* ); - static void openEmail( const TQString &addr, TQWidget *parent ); - static void openAddressBook( TQWidget *parent ); - - static bool addVCard( const KABC::Addressee& addressee, TQWidget *parent ); - - static TQString expandDistributionList( const TQString& listName ); - - /** - * Pops up a dialog to ask the user to select a resource for saving something, and - * returns the selected resource or 0 on failure or if the user cancelled. - * - * The addressbook used to get the resource list from. If the addressbook was loaded - * async and loading is not yet finished, this method will run an eventloop until the - * addressbook is loaded. - */ - static KABC::Resource* selectResourceForSaving( KABC::AddressBook *addressBook ); - -private: - static bool addAddressee( const KABC::Addressee& addressee ); -}; - -#endif /*KAddrBook_h*/ diff --git a/libkdepim/kcmdesignerfields.cpp b/libkdepim/kcmdesignerfields.cpp deleted file mode 100644 index 870d89ce2..000000000 --- a/libkdepim/kcmdesignerfields.cpp +++ /dev/null @@ -1,430 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - Copyright (c) 2004 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "kcmdesignerfields.h" - -using namespace KPIM; - -class PageItem : public TQCheckListItem -{ - public: - PageItem( TQListView *parent, const TQString &path ) - : TQCheckListItem( parent, "", TQCheckListItem::CheckBox ), - mPath( path ), mIsActive( false ) - { - mName = path.mid( path.findRev( '/' ) + 1 ); - - TQWidget *wdg = TQWidgetFactory::create( mPath, 0, 0 ); - if ( wdg ) { - setText( 0, wdg->caption() ); - - TQPixmap pm = TQPixmap::grabWidget( wdg ); - TQImage img = pm.convertToImage().smoothScale( 300, 300, TQ_ScaleMin ); - mPreview = img; - - TQObjectList *list = wdg->queryList( TQWIDGET_OBJECT_NAME_STRING ); - TQObjectListIt it( *list ); - - TQMap allowedTypes; - allowedTypes.insert( TQLINEEDIT_OBJECT_NAME_STRING, i18n( "Text" ) ); - allowedTypes.insert( TQTEXTEDIT_OBJECT_NAME_STRING, i18n( "Text" ) ); - allowedTypes.insert( TQSPINBOX_OBJECT_NAME_STRING, i18n( "Numeric Value" ) ); - allowedTypes.insert( TQCHECKBOX_OBJECT_NAME_STRING, i18n( "Boolean" ) ); - allowedTypes.insert( TQCOMBOBOX_OBJECT_NAME_STRING, i18n( "Selection" ) ); - allowedTypes.insert( TQDATETIMEEDIT_OBJECT_NAME_STRING, i18n( "Date & Time" ) ); - allowedTypes.insert( "KLineEdit", i18n( "Text" ) ); - allowedTypes.insert( "KDateTimeWidget", i18n( "Date & Time" ) ); - allowedTypes.insert( "KDatePicker", i18n( "Date" ) ); - - while ( it.current() ) { - if ( allowedTypes.find( it.current()->className() ) != allowedTypes.end() ) { - TQString name = it.current()->name(); - if ( name.startsWith( "X_" ) ) { - new TQListViewItem( this, name, - allowedTypes[ it.current()->className() ], - it.current()->className(), - TQWhatsThis::textFor( TQT_TQWIDGET( it.current() ) ) ); - } - } - - ++it; - } - - delete list; - } - } - - TQString name() const { return mName; } - TQString path() const { return mPath; } - - TQPixmap preview() - { - return mPreview; - } - - void setIsActive( bool isActive ) { mIsActive = isActive; } - bool isActive() const { return mIsActive; } - - protected: - void paintBranches( TQPainter *p, const TQColorGroup & cg, int w, int y, int h ) - { - TQListViewItem::paintBranches( p, cg, w, y, h ); - } - - private: - TQString mName; - TQString mPath; - TQPixmap mPreview; - bool mIsActive; -}; - -KCMDesignerFields::KCMDesignerFields( TQWidget *parent, const char *name ) - : KCModule( parent, name ) -{ - TQTimer::singleShot( 0, this, TQT_SLOT( delayedInit() ) ); - - KAboutData *about = new KAboutData( I18N_NOOP( "KCMDesignerfields" ), - I18N_NOOP( "TQt Designer Fields Dialog" ), - 0, 0, KAboutData::License_LGPL, - I18N_NOOP( "(c), 2004 Tobias Koenig" ) ); - - about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" ); - about->addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); - setAboutData( about ); -} - -void KCMDesignerFields::delayedInit() -{ - kdDebug() << "KCMDesignerFields::delayedInit()" << endl; - - initGUI(); - - connect( mPageView, TQT_SIGNAL( selectionChanged( TQListViewItem* ) ), - this, TQT_SLOT( updatePreview( TQListViewItem* ) ) ); - connect( mPageView, TQT_SIGNAL( clicked( TQListViewItem* ) ), - this, TQT_SLOT( itemClicked( TQListViewItem* ) ) ); - - connect( mDeleteButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( deleteFile() ) ); - connect( mImportButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( importFile() ) ); - connect( mDesignerButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( startDesigner() ) ); - - load(); - - // Install a dirwatcher that will detect newly created or removed designer files - KDirWatch *dw = new KDirWatch( TQT_TQOBJECT(this) ); - KStandardDirs::makeDir(localUiDir()); - dw->addDir( localUiDir(), true ); - connect( dw, TQT_SIGNAL( created(const TQString&) ), TQT_SLOT( rebuildList() ) ); - connect( dw, TQT_SIGNAL( deleted(const TQString&) ), TQT_SLOT( rebuildList() ) ); - connect( dw, TQT_SIGNAL( dirty(const TQString&) ), TQT_SLOT( rebuildList() ) ); -} - -void KCMDesignerFields::deleteFile() -{ - TQListViewItem *item = mPageView->selectedItem(); - if ( item ) { - PageItem *pageItem = static_cast( item->parent() ? item->parent() : item ); - if (KMessageBox::warningContinueCancel(this, - i18n( "Do you really want to delete '%1'?").tqarg( pageItem->text(0) ), "", KStdGuiItem::del() ) - == KMessageBox::Continue) - KIO::NetAccess::del( pageItem->path(), 0 ); - } - // The actual view refresh will be done automagically by the slots connected to kdirwatch -} - -void KCMDesignerFields::importFile() -{ - KURL src = KFileDialog::getOpenFileName( TQDir::homeDirPath(), i18n("*.ui|Designer Files"), - this, i18n("Import Page") ); - KURL dest = localUiDir(); - dest.setFileName(src.fileName()); - KIO::NetAccess::file_copy( src, dest, -1, true, false, this ); - // The actual view refresh will be done automagically by the slots connected to kdirwatch -} - - -void KCMDesignerFields::loadUiFiles() -{ - TQStringList list = KGlobal::dirs()->findAllResources( "data", uiPath() + "/*.ui", true, true ); - for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) { - new PageItem( mPageView, *it ); - } -} - -void KCMDesignerFields::rebuildList() -{ - TQStringList ai = saveActivePages(); - updatePreview( 0 ); - mPageView->clear(); - loadUiFiles(); - loadActivePages(ai); -} - -void KCMDesignerFields::loadActivePages(const TQStringList& ai) -{ - TQListViewItemIterator it( mPageView ); - while ( it.current() ) { - if ( it.current()->parent() == 0 ) { - PageItem *item = static_cast( it.current() ); - if ( ai.find( item->name() ) != ai.end() ) { - item->setOn( true ); - item->setIsActive( true ); - } - } - - ++it; - } -} - -void KCMDesignerFields::load() -{ - loadActivePages( readActivePages() ); -} - -TQStringList KCMDesignerFields::saveActivePages() -{ - TQListViewItemIterator it( mPageView, TQListViewItemIterator::Checked | - TQListViewItemIterator::Selectable ); - - TQStringList activePages; - while ( it.current() ) { - if ( it.current()->parent() == 0 ) { - PageItem *item = static_cast( it.current() ); - activePages.append( item->name() ); - } - - ++it; - } - - return activePages; -} - -void KCMDesignerFields::save() -{ - writeActivePages( saveActivePages() ); -} - -void KCMDesignerFields::defaults() -{ -} - -void KCMDesignerFields::initGUI() -{ - TQVBoxLayout *tqlayout = new TQVBoxLayout( this, KDialog::marginHint(), - KDialog::spacingHint() ); - - bool noDesigner = KStandardDirs::findExe("designer").isEmpty(); - - if ( noDesigner ) - { - TQString txt = - i18n("Warning: TQt Designer could not be found. It is probably not " - "installed. You will only be able to import existing designer files."); - TQLabel *lbl = new TQLabel( txt, this ); - tqlayout->addWidget( lbl ); - } - - TQHBoxLayout *hbox = new TQHBoxLayout( tqlayout, KDialog::spacingHint() ); - - mPageView = new KListView( this ); - mPageView->addColumn( i18n( "Available Pages" ) ); - mPageView->setRootIsDecorated( true ); - mPageView->setAllColumnsShowFocus( true ); - mPageView->setFullWidth( true ); - hbox->addWidget( mPageView ); - - TQGroupBox *box = new TQGroupBox(1, Qt::Horizontal, i18n("Preview of Selected Page"), this ); - - mPagePreview = new TQLabel( box ); - mPagePreview->setMinimumWidth( 300 ); - - mPageDetails = new TQLabel( box ); - - hbox->addWidget( box ); - - loadUiFiles(); - - hbox = new TQHBoxLayout( tqlayout, KDialog::spacingHint() ); - - TQString cwHowto = i18n("

This section allows you to add your own GUI" - " Elements ('Widgets') to store your own values" - " into %1. Proceed as described below:

" - "
    " - "
  1. Click on 'Edit with TQt Designer'" - "
  2. In the dialog, select 'Widget', then click OK" - "
  3. Add your widgets to the form" - "
  4. Save the file in the directory proposed by TQt Designer" - "
  5. Close TQt Designer" - "
" - "

In case you already have a designer file (*.ui) located" - " somewhere on your hard disk, simply choose 'Import Page'

" - "

Important: The name of each input widget you place within" - " the form must start with 'X_'; so if you want the widget to" - " correspond to your custom entry 'X-Foo', set the widget's" - " name property to 'X_Foo'.

" - "

Important: The widget will edit custom fields with an" - " application name of %2. To change the application name" - " to be edited, set the widget name in TQt Designer.

" ) - .tqarg( applicationName(), applicationName() ); - - KActiveLabel *activeLabel = new KActiveLabel( - i18n( "How does this work?" ).tqarg(cwHowto), this ); - hbox->addWidget( activeLabel ); - - // ### why is this needed? Looks like a KActiveLabel bug... - activeLabel->tqsetSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Maximum ); - - hbox->addStretch( 1 ); - - mDeleteButton = new TQPushButton( i18n( "Delete Page" ), this); - mDeleteButton->setEnabled( false ); - hbox->addWidget( mDeleteButton ); - mImportButton = new TQPushButton( i18n( "Import Page..." ), this); - hbox->addWidget( mImportButton ); - mDesignerButton = new TQPushButton( i18n( "Edit with TQt Designer..." ), this ); - hbox->addWidget( mDesignerButton ); - - if ( noDesigner ) - mDesignerButton->setEnabled( false ); - - // FIXME: Why do I have to call show() for all widgets? A this->show() doesn't - // seem to work. - mPageView->show(); - box->show(); - activeLabel->show(); - mDeleteButton->show(); - mImportButton->show(); - mDesignerButton->show(); -} - -void KCMDesignerFields::updatePreview( TQListViewItem *item ) -{ - bool widgetItemSelected = false; - - if ( item ) { - if ( item->parent() ) { - TQString details = TQString( "" - "" - "" - "" - "" - "
%1%2
%3%4
%5%6
%7%8
" ) - .tqarg( i18n( "Key:" ) ) - .tqarg( item->text( 0 ).replace("X_","X-") ) - .tqarg( i18n( "Type:" ) ) - .tqarg( item->text( 1 ) ) - .tqarg( i18n( "Classname:" ) ) - .tqarg( item->text( 2 ) ) - .tqarg( i18n( "Description:" ) ) - .tqarg( item->text( 3 ) ); - - mPageDetails->setText( details ); - - PageItem *pageItem = static_cast( item->parent() ); - mPagePreview->setPixmap( pageItem->preview() ); - } else { - mPageDetails->setText( TQString() ); - - PageItem *pageItem = static_cast( item ); - mPagePreview->setPixmap( pageItem->preview() ); - - widgetItemSelected = true; - } - - mPagePreview->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); - } else { - mPagePreview->setPixmap( TQPixmap() ); - mPagePreview->setFrameStyle( 0 ); - mPageDetails->setText( TQString() ); - } - - mDeleteButton->setEnabled( widgetItemSelected ); -} - -void KCMDesignerFields::itemClicked( TQListViewItem *item ) -{ - if ( !item || item->parent() != 0 ) - return; - - PageItem *pageItem = static_cast( item ); - - if ( pageItem->isOn() != pageItem->isActive() ) { - emit changed( true ); - pageItem->setIsActive( pageItem->isOn() ); - } -} - -void KCMDesignerFields::startDesigner() -{ - TQString cmdLine = "designer"; - - // check if path exists and create one if not. - TQString cepPath = localUiDir(); - if( !KGlobal::dirs()->exists(cepPath) ) { - KIO::NetAccess::mkdir( cepPath, this ); - } - - // finally jump there - chdir(cepPath.local8Bit()); - - TQListViewItem *item = mPageView->selectedItem(); - if ( item ) { - PageItem *pageItem = static_cast( item->parent() ? item->parent() : item ); - cmdLine += " " + KProcess::quote( pageItem->path() ); - } - - KRun::runCommand( cmdLine ); -} - -#include "kcmdesignerfields.moc" diff --git a/libkdepim/kcmdesignerfields.h b/libkdepim/kcmdesignerfields.h deleted file mode 100644 index 820506f93..000000000 --- a/libkdepim/kcmdesignerfields.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - Copyright (c) 2004 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KPIM_KCMDESIGNERFIELDS_H -#define KPIM_KCMDESIGNERFIELDS_H - -#include -#include - -class KListView; - -class TQLabel; -class TQListViewItem; -class TQPushButton; - -namespace KPIM { - -class KDE_EXPORT KCMDesignerFields : public KCModule -{ - Q_OBJECT - TQ_OBJECT - - public: - KCMDesignerFields( TQWidget *parent = 0, const char *name = 0 ); - - virtual void load(); - virtual void save(); - virtual void defaults(); - - protected: - void loadUiFiles(); - void loadActivePages(const TQStringList&); - TQStringList saveActivePages(); - - virtual TQString localUiDir() = 0; - virtual TQString uiPath() = 0; - virtual void writeActivePages( const TQStringList & ) = 0; - virtual TQStringList readActivePages() = 0; - virtual TQString applicationName() = 0; - - private slots: - void updatePreview( TQListViewItem* ); - void itemClicked( TQListViewItem* ); - void startDesigner(); - void rebuildList(); - void deleteFile(); - void importFile(); - void delayedInit(); - - private: - void initGUI(); - - KListView *mPageView; - TQLabel *mPagePreview; - TQLabel *mPageDetails; - TQPushButton *mDeleteButton; - TQPushButton *mImportButton; - TQPushButton *mDesignerButton; -}; - -} - -#endif diff --git a/libkdepim/kconfigpropagator.cpp b/libkdepim/kconfigpropagator.cpp deleted file mode 100644 index d22805db9..000000000 --- a/libkdepim/kconfigpropagator.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kconfigpropagator.h" - -#include -#include -#include -#include -#include -#include - -#include -#include - -KConfigPropagator::Change::~Change() -{ -} - -KConfigPropagator::ChangeConfig::ChangeConfig() - : KConfigPropagator::Change( i18n("Change Config Value") ), - hideValue( false ) -{ -} - -TQString KConfigPropagator::ChangeConfig::arg1() const -{ - return file + "/" + group + "/" + name; -} - -TQString KConfigPropagator::ChangeConfig::arg2() const -{ - if ( hideValue ) return "*"; - else return value; -} - -void KConfigPropagator::ChangeConfig::apply() -{ - KConfig cfg( file ); - cfg.setGroup( group ); - cfg.writeEntry( name, value ); - - cfg.sync(); -} - -KConfigPropagator::KConfigPropagator() - : mSkeleton( 0 ) -{ - init(); -} - -KConfigPropagator::KConfigPropagator( KConfigSkeleton *skeleton, - const TQString &kcfgFile ) - : mSkeleton( skeleton ), mKcfgFile( kcfgFile ) -{ - init(); - - readKcfgFile(); -} - -void KConfigPropagator::init() -{ - mChanges.setAutoDelete( true ); -} - -void KConfigPropagator::readKcfgFile() -{ - TQString filename = locate( "kcfg", mKcfgFile ); - if ( filename.isEmpty() ) { - kdError() << "Unable to find kcfg file '" << mKcfgFile << "'" << endl; - return; - } - - TQFile input( filename ); - TQDomDocument doc; - TQString errorMsg; - int errorRow; - int errorCol; - if ( !doc.setContent( &input, &errorMsg, &errorRow, &errorCol ) ) { - kdError() << "Parse error in " << mKcfgFile << ", line " << errorRow << ", col " << errorCol << ": " << errorMsg << endl; - return; - } - - TQDomElement cfgElement = doc.documentElement(); - - if ( cfgElement.isNull() ) { - kdError() << "No document in kcfg file" << endl; - return; - } - - mRules.clear(); - - TQDomNode n; - for ( n = cfgElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { - TQDomElement e = n.toElement(); - - TQString tag = e.tagName(); - - if ( tag == "propagation" ) { - Rule rule = parsePropagation( e ); - mRules.append( rule ); - } else if ( tag == "condition" ) { - Condition condition = parseCondition( e ); - TQDomNode n2; - for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { - TQDomElement e2 = n2.toElement(); - if ( e2.tagName() == "propagation" ) { - Rule rule = parsePropagation( e2 ); - rule.condition = condition; - mRules.append( rule ); - } else { - kdError() << "Unknow tag: " << e2.tagName() << endl; - } - } - } - } -} - -KConfigPropagator::Rule KConfigPropagator::parsePropagation( const TQDomElement &e ) -{ - Rule r; - - TQString source = e.attribute( "source" ); - parseConfigEntryPath( source, r.sourceFile, r.sourceGroup, r.sourceEntry ); - - TQString target = e.attribute( "target" ); - parseConfigEntryPath( target, r.targetFile, r.targetGroup, r.targetEntry ); - - r.hideValue = e.hasAttribute( "hidevalue" ) && - e.attribute( "hidevalue" ) == "true"; - - return r; -} - -void KConfigPropagator::parseConfigEntryPath( const TQString &path, - TQString &file, - TQString &group, - TQString &entry ) -{ - TQStringList p = TQStringList::split( "/", path ); - - if ( p.count() != 3 ) { - kdError() << "Path has to be of form file/group/entry" << endl; - file = TQString(); - group = TQString(); - entry = TQString(); - return; - } - - file = p[ 0 ]; - group = p[ 1 ]; - entry = p[ 2 ]; - - return; -} - -KConfigPropagator::Condition KConfigPropagator::parseCondition( const TQDomElement &e ) -{ - Condition c; - - TQString key = e.attribute( "key" ); - - parseConfigEntryPath( key, c.file, c.group, c.key ); - - c.value = e.attribute( "value" ); - - c.isValid = true; - - return c; -} - -void KConfigPropagator::commit() -{ - updateChanges(); - - Change *c; - for( c = mChanges.first(); c; c = mChanges.next() ) { - c->apply(); - } -} - -KConfigSkeletonItem *KConfigPropagator::findItem( const TQString &group, - const TQString &name ) -{ -// kdDebug() << "KConfigPropagator::findItem()" << endl; - - if ( !mSkeleton ) return 0; - - KConfigSkeletonItem::List items = mSkeleton->items(); - KConfigSkeletonItem::List::ConstIterator it; - for( it = items.begin(); it != items.end(); ++it ) { -// kdDebug() << " Item: " << (*it)->name() << " Type: " -// << (*it)->property().typeName() << endl; - if ( (*it)->group() == group && (*it)->name() == name ) { - break; - } - } - if ( it == items.end() ) return 0; - else return *it; -} - -TQString KConfigPropagator::itemValueAsString( KConfigSkeletonItem *item ) -{ - TQVariant p = item->property(); - - if ( p.type() == TQVariant::Bool ) { - if ( p.toBool() ) return "true"; - else return "false"; - } - - return p.toString(); -} - -void KConfigPropagator::updateChanges() -{ - mChanges.clear(); - - Rule::List::ConstIterator it; - for( it = mRules.begin(); it != mRules.end(); ++it ) { - Rule r = *it; - Condition c = r.condition; - if ( c.isValid ) { - KConfigSkeletonItem *item = findItem( c.group, c.key ); - kdDebug() << "Item " << c.group << "/" << c.key << ":" << endl; - if ( !item ) { - kdError() << " Item not found." << endl; - } else { - TQString value = itemValueAsString( item ); - kdDebug() << " Value: " << value << endl; - if ( value != c.value ) { - continue; - } - } - } - - KConfigSkeletonItem *item = findItem( r.sourceGroup, r.sourceEntry ); - if ( !item ) { - kdError() << "Item " << r.sourceGroup << "/" << r.sourceEntry - << " not found." << endl; - continue; - } - TQString value = itemValueAsString( item ); - - KConfig target( r.targetFile ); - target.setGroup( r.targetGroup ); - TQString targetValue = target.readEntry( r.targetEntry ); - if ( r.hideValue ) targetValue = KStringHandler::obscure( targetValue ); - if ( targetValue != value ) { - ChangeConfig *change = new ChangeConfig(); - change->file = r.targetFile; - change->group = r.targetGroup; - change->name = r.targetEntry; - if ( r.hideValue ) value = KStringHandler::obscure( value ); - change->value = value; - change->hideValue = r.hideValue; - mChanges.append( change ); - } - } - - addCustomChanges( mChanges ); -} - -KConfigPropagator::Change::List KConfigPropagator::changes() -{ - return mChanges; -} - -KConfigPropagator::Rule::List KConfigPropagator::rules() -{ - return mRules; -} diff --git a/libkdepim/kconfigpropagator.h b/libkdepim/kconfigpropagator.h deleted file mode 100644 index 3e52eb7c4..000000000 --- a/libkdepim/kconfigpropagator.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KCONFIGPROPAGATOR_H -#define KCONFIGPROPAGATOR_H - -#include -#include -#include -#include - -#include - -class KConfigSkeleton; -class KConfigSkeletonItem; - -class KDE_EXPORT KConfigPropagator -{ - public: - - /** - Create KConfigPropagator object without associated source configuration. - */ - KConfigPropagator(); - /** - Create KConfigPropagator object. - - @param skeleton KConfigSkeleton object used as source for the propagation - @param kcfgFile file name of kcfg file containing the propagation rules - */ - KConfigPropagator( KConfigSkeleton *skeleton, const TQString &kcfgFile ); - virtual ~KConfigPropagator() {} - - KConfigSkeleton *skeleton() { return mSkeleton; } - - /* - Commit changes according to propagation rules. - */ - void commit(); - - class KDE_EXPORT Condition - { - public: - Condition() : isValid( false ) {} - - TQString file; - TQString group; - TQString key; - TQString value; - - bool isValid; - }; - - class KDE_EXPORT Rule - { - public: - typedef TQValueList List; - - Rule() : hideValue( false ) {} - - TQString sourceFile; - TQString sourceGroup; - TQString sourceEntry; - - TQString targetFile; - TQString targetGroup; - TQString targetEntry; - - Condition condition; - - bool hideValue; - }; - - class KDE_EXPORT Change - { - public: - typedef TQPtrList List; - - Change( const TQString &title ) : mTitle( title ) {} - virtual ~Change(); - - void setTitle( const TQString &title ) { mTitle = title; } - TQString title() const { return mTitle; } - - virtual TQString arg1() const { return TQString(); } - virtual TQString arg2() const { return TQString(); } - - virtual void apply() = 0; - - private: - TQString mTitle; - }; - - class KDE_EXPORT ChangeConfig : public Change - { - public: - ChangeConfig(); - ~ChangeConfig() {} - - TQString arg1() const; - TQString arg2() const; - - void apply(); - - TQString file; - TQString group; - TQString name; - TQString label; - TQString value; - bool hideValue; - }; - - void updateChanges(); - - Change::List changes(); - - Rule::List rules(); - - protected: - void init(); - - /** - Implement this function in a subclass if you want to add changes which - can't be expressed as propagations in the kcfg file. - */ - virtual void addCustomChanges( Change::List & ) {} - - KConfigSkeletonItem *findItem( const TQString &group, const TQString &name ); - - TQString itemValueAsString( KConfigSkeletonItem * ); - - void readKcfgFile(); - - Rule parsePropagation( const TQDomElement &e ); - Condition parseCondition( const TQDomElement &e ); - - void parseConfigEntryPath( const TQString &path, TQString &file, - TQString &group, TQString &entry ); - - private: - KConfigSkeleton *mSkeleton; - TQString mKcfgFile; - - Rule::List mRules; - Change::List mChanges; -}; - -#endif diff --git a/libkdepim/kconfigwizard.cpp b/libkdepim/kconfigwizard.cpp deleted file mode 100644 index bceacd656..000000000 --- a/libkdepim/kconfigwizard.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kconfigwizard.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -KConfigWizard::KConfigWizard( TQWidget *parent, - char *name, bool modal ) - : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent, - name, modal ), - mPropagator( 0 ), mChangesPage( 0 ) -{ - init(); -} - -KConfigWizard::KConfigWizard( KConfigPropagator *propagator, TQWidget *parent, - char *name, bool modal ) - : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent, - name, modal ), - mPropagator( propagator ), mChangesPage( 0 ) -{ - init(); -} - -KConfigWizard::~KConfigWizard() -{ - delete mPropagator; -} - -void KConfigWizard::init() -{ - connect( this, TQT_SIGNAL( aboutToShowPage( TQWidget * ) ), - TQT_SLOT( slotAboutToShowPage( TQWidget * ) ) ); - - TQTimer::singleShot( 0, this, TQT_SLOT( readConfig() ) ); -} - -void KConfigWizard::setPropagator( KConfigPropagator *p ) -{ - mPropagator = p; -} - -void KConfigWizard::slotAboutToShowPage( TQWidget *page ) -{ - if ( page == mChangesPage ) { - updateChanges(); - } -} - -TQFrame *KConfigWizard::createWizardPage( const TQString &title ) -{ - return addPage( title ); -} - -void KConfigWizard::setupRulesPage() -{ - TQFrame *topFrame = addPage( i18n("Rules") ); - TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame ); - - mRuleView = new TQListView( topFrame ); - topLayout->addWidget( mRuleView ); - - mRuleView->addColumn( i18n("Source") ); - mRuleView->addColumn( i18n("Target") ); - mRuleView->addColumn( i18n("Condition") ); - - updateRules(); -} - -void KConfigWizard::updateRules() -{ - if ( !mPropagator ) { - kdError() << "KConfigWizard: No KConfigPropagator set." << endl; - return; - } - - mRuleView->clear(); - - KConfigPropagator::Rule::List rules = mPropagator->rules(); - KConfigPropagator::Rule::List::ConstIterator it; - for( it = rules.begin(); it != rules.end(); ++it ) { - KConfigPropagator::Rule r = *it; - TQString source = r.sourceFile + "/" + r.sourceGroup + "/" + - r.sourceEntry; - TQString target = r.targetFile + "/" + r.targetGroup + "/" + - r.targetEntry; - TQString condition; - KConfigPropagator::Condition c = r.condition; - if ( c.isValid ) { - condition = c.file + "/" + c.group + "/" + c.key + " = " + c.value; - } - new TQListViewItem( mRuleView, source, target, condition ); - } -} - -void KConfigWizard::setupChangesPage() -{ - TQFrame *topFrame = addPage( i18n("Changes") ); - TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame ); - - mChangeView = new TQListView( topFrame ); - topLayout->addWidget( mChangeView ); - - mChangeView->addColumn( i18n("Action") ); - mChangeView->addColumn( i18n("Option") ); - mChangeView->addColumn( i18n("Value") ); - mChangeView->setSorting( -1 ); - - mChangesPage = topFrame; -} - -void KConfigWizard::updateChanges() -{ - kdDebug() << "KConfigWizard::updateChanges()" << endl; - - if ( !mPropagator ) { - kdError() << "KConfigWizard: No KConfigPropagator set." << endl; - return; - } - - usrWriteConfig(); - - mPropagator->updateChanges(); - - mChangeView->clear(); - - KConfigPropagator::Change::List changes = mPropagator->changes(); - KConfigPropagator::Change *c; - for( c = changes.first(); c; c = changes.next() ) { - new TQListViewItem( mChangeView, mChangeView->lastItem(), c->title(), c->arg1(), c->arg2() ); - } -} - -void KConfigWizard::readConfig() -{ - kdDebug() << "KConfigWizard::readConfig()" << endl; - - int result = KMessageBox::warningContinueCancel( this, - i18n("Please make sure that the programs which are " - "configured by the wizard do not run in parallel to the wizard; " - "otherwise, changes done by the wizard could be lost."), - i18n("Warning"), i18n("Run Wizard Now"), "warning_running_instances" ); - if ( result != KMessageBox::Continue ) kapp->quit(); - - usrReadConfig(); -} - -void KConfigWizard::slotOk() -{ - TQString error = validate(); - if ( error.isNull() ) { - usrWriteConfig(); - - if ( !mPropagator ) { - kdError() << "KConfigWizard: No KConfigPropagator set." << endl; - return; - } else { - if ( mPropagator->skeleton() ) { - mPropagator->skeleton()->writeConfig(); - } - mPropagator->commit(); - } - - accept(); - } else { - KMessageBox::sorry( this, error ); - } -} - -#include "kconfigwizard.moc" diff --git a/libkdepim/kconfigwizard.h b/libkdepim/kconfigwizard.h deleted file mode 100644 index 71455277c..000000000 --- a/libkdepim/kconfigwizard.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KCONFIGWIZARD_H -#define KCONFIGWIZARD_H - -#include -#include -#include - -class TQListView; - -/** - @short Configuration wizard base class -*/ -class KDE_EXPORT KConfigWizard : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT - public: - /** - Create wizard. You have to set a propgator with setPropagator() later. - */ - KConfigWizard( TQWidget *parent = 0, char *name = 0, bool modal = false ); - /** - Create wizard for given KConfigPropagator. The wizard takes ownership of - the propagator. - */ - KConfigWizard( KConfigPropagator *propagator, TQWidget *parent = 0, - char *name = 0, bool modal = false ); - /** - Destructor. - */ - virtual ~KConfigWizard(); - - /** - Set propagator the wizard operates on. - */ - void setPropagator( KConfigPropagator * ); - /** - Return propagator the wizard operates on. - */ - KConfigPropagator *propagator() { return mPropagator; } - - /** - Create wizard page with given title. - */ - TQFrame *createWizardPage( const TQString &title ); - - /** - Use this function to read the configuration from the KConfigSkeleton - object to the GUI. - */ - virtual void usrReadConfig() = 0; - - /** - This function is called when the wizard is finished. You have to save all - settings from the GUI to the KConfigSkeleton object here, so that the - KConfigPropagator can take them up from there. - */ - virtual void usrWriteConfig() = 0; - - /** - Validates the supplied data. Returns a appropiate error when some data - is invalid. Return TQString() if all data is valid. - */ - virtual TQString validate() { return TQString(); } - - protected slots: - void readConfig(); - - void slotOk(); - - void slotAboutToShowPage( TQWidget *page ); - - protected: - void init(); - - void setupRulesPage(); - void updateRules(); - void setupChangesPage(); - void updateChanges(); - - private: - KConfigPropagator *mPropagator; - - TQListView *mRuleView; - TQListView *mChangeView; - - TQWidget *mChangesPage; -}; - -#endif diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp deleted file mode 100644 index 44c4e696a..000000000 --- a/libkdepim/kdateedit.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002 Cornelius Schumacher - Copyright (c) 2002 David Jarvie - Copyright (c) 2003-2004 Reinhold Kainhofer - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "kdateedit.h" - -class DateValidator : public TQValidator -{ - public: - DateValidator( const TQStringList &keywords, TQWidget* parent, const char* name = 0 ) - : TQValidator( TQT_TQOBJECT(parent), name ), mKeywords( keywords ) - {} - - virtual State validate( TQString &str, int& ) const - { - int length = str.length(); - - // empty string is intermediate so one can clear the edit line and start from scratch - if ( length <= 0 ) - return Intermediate; - - if ( mKeywords.contains( str.lower() ) ) - return Acceptable; - - bool ok = false; - KGlobal::locale()->readDate( str, &ok ); - if ( ok ) - return Acceptable; - else - return Intermediate; - } - - private: - TQStringList mKeywords; -}; - -KDateEdit::KDateEdit( TQWidget *parent, const char *name ) - : TQComboBox( true, parent, name ), - mReadOnly( false ), - mDiscardNextMousePress( false ) -{ - // need at least one entry for popup to work - setMaxCount( 1 ); - - mDate = TQDate::tqcurrentDate(); - TQString today = KGlobal::locale()->formatDate( mDate, true ); - - insertItem( today ); - setCurrentItem( 0 ); - changeItem( today, 0 ); - setMinimumSize( tqsizeHint() ); - - connect( lineEdit(), TQT_SIGNAL( returnPressed() ), - this, TQT_SLOT( lineEnterPressed() ) ); - connect( this, TQT_SIGNAL( textChanged( const TQString& ) ), - TQT_SLOT( slotTextChanged( const TQString& ) ) ); - - mPopup = new KDatePickerPopup( KDatePickerPopup::DatePicker | KDatePickerPopup::Words ); - mPopup->hide(); - mPopup->installEventFilter( this ); - - connect( mPopup, TQT_SIGNAL( dateChanged( TQDate ) ), - TQT_SLOT( dateSelected( TQDate ) ) ); - - // handle keyword entry - setupKeywords(); - lineEdit()->installEventFilter( this ); - - setValidator( new DateValidator( mKeywordMap.keys(), this ) ); - - mTextChanged = false; -} - -KDateEdit::~KDateEdit() -{ - delete mPopup; - mPopup = 0; -} - -void KDateEdit::setDate( const TQDate& date ) -{ - assignDate( date ); - updateView(); -} - -TQDate KDateEdit::date() const -{ - return mDate; -} - -void KDateEdit::setReadOnly( bool readOnly ) -{ - mReadOnly = readOnly; - lineEdit()->setReadOnly( readOnly ); -} - -bool KDateEdit::isReadOnly() const -{ - return mReadOnly; -} - -void KDateEdit::popup() -{ - if ( mReadOnly ) - return; - - TQRect desk = KGlobalSettings::desktopGeometry( this ); - - TQPoint popupPoint = mapToGlobal( TQPoint( 0,0 ) ); - - int dateFrameHeight = mPopup->tqsizeHint().height(); - if ( popupPoint.y() + height() + dateFrameHeight > desk.bottom() ) - popupPoint.setY( popupPoint.y() - dateFrameHeight ); - else - popupPoint.setY( popupPoint.y() + height() ); - - int dateFrameWidth = mPopup->tqsizeHint().width(); - if ( popupPoint.x() + dateFrameWidth > desk.right() ) - popupPoint.setX( desk.right() - dateFrameWidth ); - - if ( popupPoint.x() < desk.left() ) - popupPoint.setX( desk.left() ); - - if ( popupPoint.y() < desk.top() ) - popupPoint.setY( desk.top() ); - - if ( mDate.isValid() ) - mPopup->setDate( mDate ); - else - mPopup->setDate( TQDate::tqcurrentDate() ); - - mPopup->popup( popupPoint ); - - // The combo box is now shown pressed. Make it show not pressed again - // by causing its (invisible) list box to emit a 'selected' signal. - // First, ensure that the list box contains the date currently displayed. - TQDate date = parseDate(); - assignDate( date ); - updateView(); - // Now, simulate an Enter to unpress it - TQListBox *lb = listBox(); - if (lb) { - lb->setCurrentItem(0); - TQKeyEvent* keyEvent = new TQKeyEvent(TQEvent::KeyPress, TQt::Key_Enter, 0, 0); - TQApplication::postEvent(lb, keyEvent); - } -} - -void KDateEdit::dateSelected( TQDate date ) -{ - if (assignDate( date ) ) { - updateView(); - emit dateChanged( date ); - emit dateEntered( date ); - - if ( date.isValid() ) { - mPopup->hide(); - } - } -} - -void KDateEdit::lineEnterPressed() -{ - bool replaced = false; - - TQDate date = parseDate( &replaced ); - - if (assignDate( date ) ) { - if ( replaced ) - updateView(); - - emit dateChanged( date ); - emit dateEntered( date ); - } -} - -TQDate KDateEdit::parseDate( bool *replaced ) const -{ - TQString text = currentText(); - TQDate result; - - if ( replaced ) - (*replaced) = false; - - if ( text.isEmpty() ) - result = TQDate(); - else if ( mKeywordMap.contains( text.lower() ) ) { - TQDate today = TQDate::tqcurrentDate(); - int i = mKeywordMap[ text.lower() ]; - if ( i >= 100 ) { - /* A day name has been entered. Convert to offset from today. - * This uses some math tricks to figure out the offset in days - * to the next date the given day of the week occurs. There - * are two cases, that the new day is >= the current day, which means - * the new day has not occurred yet or that the new day < the current day, - * which means the new day is already passed (so we need to find the - * day in the next week). - */ - i -= 100; - int currentDay = today.dayOfWeek(); - if ( i >= currentDay ) - i -= currentDay; - else - i += 7 - currentDay; - } - - result = today.addDays( i ); - if ( replaced ) - (*replaced) = true; - } else { - result = KGlobal::locale()->readDate( text ); - } - - return result; -} - -bool KDateEdit::eventFilter( TQObject *object, TQEvent *event ) -{ - if ( TQT_BASE_OBJECT(object) == TQT_BASE_OBJECT(lineEdit()) ) { - // We only process the focus out event if the text has changed - // since we got focus - if ( (event->type() == TQEvent::FocusOut) && mTextChanged ) { - lineEnterPressed(); - mTextChanged = false; - } else if ( event->type() == TQEvent::KeyPress ) { - // Up and down arrow keys step the date - TQKeyEvent* keyEvent = (TQKeyEvent*)event; - - if ( keyEvent->key() == TQt::Key_Return ) { - lineEnterPressed(); - return true; - } - - int step = 0; - if ( keyEvent->key() == TQt::Key_Up ) - step = 1; - else if ( keyEvent->key() == TQt::Key_Down ) - step = -1; - // TODO: If it's not an input key, but something like Return, Enter, Tab, etc..., don't eat the keypress, but handle it through to the default eventfilter! - if ( step && !mReadOnly ) { - TQDate date = parseDate(); - if ( date.isValid() ) { - date = date.addDays( step ); - if ( assignDate( date ) ) { - updateView(); - emit dateChanged( date ); - emit dateEntered( date ); - return true; - } - } - } - } - } else { - // It's a date picker event - switch ( event->type() ) { - case TQEvent::MouseButtonDblClick: - case TQEvent::MouseButtonPress: { - TQMouseEvent *mouseEvent = (TQMouseEvent*)event; - if ( !TQT_TQRECT_OBJECT(mPopup->rect()).contains( mouseEvent->pos() ) ) { - TQPoint globalPos = mPopup->mapToGlobal( mouseEvent->pos() ); - if ( TQApplication::widgetAt( globalPos, true ) == this ) { - // The date picker is being closed by a click on the - // KDateEdit widget. Avoid popping it up again immediately. - mDiscardNextMousePress = true; - } - } - - break; - } - default: - break; - } - } - - return false; -} - -void KDateEdit::mousePressEvent( TQMouseEvent *event ) -{ - if ( event->button() == Qt::LeftButton && mDiscardNextMousePress ) { - mDiscardNextMousePress = false; - return; - } - - TQComboBox::mousePressEvent( event ); -} - -void KDateEdit::slotTextChanged( const TQString& ) -{ - TQDate date = parseDate(); - - if ( assignDate( date ) ) - emit dateChanged( date ); - - mTextChanged = true; -} - -void KDateEdit::setupKeywords() -{ - // Create the keyword list. This will be used to match against when the user - // enters information. - mKeywordMap.insert( i18n( "tomorrow" ), 1 ); - mKeywordMap.insert( i18n( "today" ), 0 ); - mKeywordMap.insert( i18n( "yesterday" ), -1 ); - - TQString dayName; - for ( int i = 1; i <= 7; ++i ) { - dayName = KGlobal::locale()->calendar()->weekDayName( i ).lower(); - mKeywordMap.insert( dayName, i + 100 ); - } -} - -bool KDateEdit::assignDate( const TQDate& date ) -{ - mDate = date; - mTextChanged = false; - return true; -} - -void KDateEdit::updateView() -{ - TQString dateString; - if ( mDate.isValid() ) - dateString = KGlobal::locale()->formatDate( mDate, true ); - - // We do not want to generate a signal here, - // since we explicitly setting the date - bool blocked = signalsBlocked(); - blockSignals( true ); - changeItem( dateString, 0 ); - blockSignals( blocked ); -} - -#include "kdateedit.moc" diff --git a/libkdepim/kdateedit.h b/libkdepim/kdateedit.h deleted file mode 100644 index 02a7701cc..000000000 --- a/libkdepim/kdateedit.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002 Cornelius Schumacher - Copyright (c) 2002 David Jarvie - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KDATEEDIT_H -#define KDATEEDIT_H - -#include -#include -#include - -#include - -#include "kdatepickerpopup.h" - -class TQEvent; - -/** - A date editing widget that consists of an editable combo box. - The combo box contains the date in text form, and clicking the combo - box arrow will display a 'popup' style date picker. - - This widget also supports advanced features like allowing the user - to type in the day name to get the date. The following keywords - are supported (in the native language): tomorrow, yesturday, today, - monday, tuesday, wednesday, thursday, friday, saturday, sunday. - - @image html kdateedit.png "This is how it looks" - - @author Cornelius Schumacher - @author Mike Pilone - @author David Jarvie - @author Tobias Koenig -*/ -class KDE_EXPORT KDateEdit : public TQComboBox -{ - Q_OBJECT - TQ_OBJECT - - public: - KDateEdit( TQWidget *parent = 0, const char *name = 0 ); - virtual ~KDateEdit(); - - /** - @return The date entered. This date could be invalid, - you have to check validity yourself. - */ - TQDate date() const; - - /** - Sets whether the widget is read-only for the user. If read-only, - the date picker pop-up is inactive, and the displayed date cannot be edited. - - @param readOnly True to set the widget read-only, false to set it read-write. - */ - void setReadOnly( bool readOnly ); - - /** - @return True if the widget is read-only, false if read-write. - */ - bool isReadOnly() const; - - virtual void popup(); - - signals: - /** - This signal is emitted whenever the user has entered a new date. - When the user changes the date by editing the line edit field, - the signal is not emitted until focus leaves the line edit field. - The passed date can be invalid. - */ - void dateEntered( const TQDate &date ); - - /** - This signal is emitted whenever the user modifies the date. - The passed date can be invalid. - */ - void dateChanged( const TQDate &date ); - - public slots: - /** - Sets the date. - - @param date The new date to display. This date must be valid or - it will not be set - */ - void setDate( const TQDate &date ); - - protected slots: - void lineEnterPressed(); - void slotTextChanged( const TQString& ); - void dateSelected( TQDate ); - - protected: - virtual bool eventFilter( TQObject*, TQEvent* ); - virtual void mousePressEvent( TQMouseEvent* ); - - /** - Sets the date, without altering the display. - This method is used internally to set the widget's date value. - As a virtual method, it allows derived classes to perform additional validation - on the date value before it is set. Derived classes should return true if - TQDate::isValid(@p date) returns false. - - @param date The new date to set. - @return True if the date was set, false if it was considered invalid and - remains unchanged. - */ - virtual bool assignDate( const TQDate &date ); - - /** - Fills the keyword map. Reimplement it if you want additional - keywords. - */ - void setupKeywords(); - - private: - TQDate parseDate( bool* = 0 ) const; - void updateView(); - - KDatePickerPopup *mPopup; - - TQDate mDate; - bool mReadOnly; - bool mTextChanged; - bool mDiscardNextMousePress; - - TQMap mKeywordMap; -}; - -#endif diff --git a/libkdepim/kdatepickerpopup.cpp b/libkdepim/kdatepickerpopup.cpp deleted file mode 100644 index 998c44e4a..000000000 --- a/libkdepim/kdatepickerpopup.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Bram Schoenmakers - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include -#include - -#include - -#include "kdatepickerpopup.h" - -KDatePickerPopup::KDatePickerPopup( int items, const TQDate &date, TQWidget *parent, - const char *name ) - : TQPopupMenu( parent, name ) -{ - mItems = items; - - mDatePicker = new KDatePicker( this ); - mDatePicker->setCloseButton( false ); - - connect( mDatePicker, TQT_SIGNAL( dateEntered( TQDate ) ), - TQT_SLOT( slotDateChanged( TQDate ) ) ); - connect( mDatePicker, TQT_SIGNAL( dateSelected( TQDate ) ), - TQT_SLOT( slotDateChanged( TQDate ) ) ); - - mDatePicker->setDate( date ); - - buildMenu(); -} - -void KDatePickerPopup::buildMenu() -{ - if ( isVisible() ) return; - clear(); - - if ( mItems & DatePicker ) { - insertItem( mDatePicker ); - - if ( ( mItems & NoDate ) || ( mItems & Words ) ) - insertSeparator(); - } - - if ( mItems & Words ) { - insertItem( i18n("&Today"), this, TQT_SLOT( slotToday() ) ); - insertItem( i18n("To&morrow"), this, TQT_SLOT( slotTomorrow() ) ); - insertItem( i18n("Next &Week"), this, TQT_SLOT( slotNextWeek() ) ); - insertItem( i18n("Next M&onth"), this, TQT_SLOT( slotNextMonth() ) ); - - if ( mItems & NoDate ) - insertSeparator(); - } - - if ( mItems & NoDate ) - insertItem( i18n("No Date"), this, TQT_SLOT( slotNoDate() ) ); -} - -KDatePicker *KDatePickerPopup::datePicker() const -{ - return mDatePicker; -} - -void KDatePickerPopup::setDate( const TQDate &date ) -{ - mDatePicker->setDate( date ); -} - -#if 0 -void KDatePickerPopup::setItems( int items ) -{ - mItems = items; - buildMenu(); -} -#endif - -void KDatePickerPopup::slotDateChanged( TQDate date ) -{ - emit dateChanged( date ); - hide(); -} - -void KDatePickerPopup::slotToday() -{ - emit dateChanged( TQDate::tqcurrentDate() ); -} - -void KDatePickerPopup::slotTomorrow() -{ - emit dateChanged( TQDate::tqcurrentDate().addDays( 1 ) ); -} - -void KDatePickerPopup::slotNoDate() -{ - emit dateChanged( TQDate() ); -} - -void KDatePickerPopup::slotNextWeek() -{ - emit dateChanged( TQDate::tqcurrentDate().addDays( 7 ) ); -} - -void KDatePickerPopup::slotNextMonth() -{ - emit dateChanged( TQDate::tqcurrentDate().addMonths( 1 ) ); -} - -#include "kdatepickerpopup.moc" diff --git a/libkdepim/kdatepickerpopup.h b/libkdepim/kdatepickerpopup.h deleted file mode 100644 index 44dc7c668..000000000 --- a/libkdepim/kdatepickerpopup.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Bram Schoenmakers - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KDATEPICKERPOPUP_H -#define KDATEPICKERPOPUP_H - -#include -#include - -#include -#include - -/** - @short This menu helps the user to select a date quickly. - - This menu helps the user to select a date quicly. It offers various ways of selecting, e.g. with a KDatePicker or with words like "Tomorrow". - - The available items are: - - @li NoDate: A menu-item with "No Date". If choosen, the datepicker will emit a null TQDate. - @li DatePicker: Show a KDatePicker-widget. - @li Words: Show items like "Today", "Tomorrow" or "Next Week". - - When supplying multiple items, separate each item with a bitwise OR. - - @author Bram Schoenmakers -*/ -class KDE_EXPORT KDatePickerPopup: public TQPopupMenu -{ - Q_OBJECT - TQ_OBJECT - public: - enum { NoDate = 1, DatePicker = 2, Words = 4 }; - - /** - A constructor for the KDatePickerPopup. - - @param items List of all desirable items, separated with a bitwise OR. - @param date Initial date of datepicker-widget. - @param parent The object's parent. - @param name The object's name. - */ - KDatePickerPopup( int items = DatePicker, const TQDate &date = TQDate::tqcurrentDate(), - TQWidget *parent = 0, const char *name = 0 ); - - /** - @return A pointer to the private variable mDatePicker, an instance of - KDatePicker. - */ - KDatePicker *datePicker() const; - - void setDate( const TQDate &date ); - -#if 0 - /** Set items which should be shown and rebuilds the menu afterwards. Only if the menu is not visible. - @param items List of all desirable items, separated with a bitwise OR. - */ - void setItems( int items = 1 ); -#endif - /** @return Returns the bitwise result of the active items in the popup. */ - int items() const { return mItems; } - - signals: - - /** - This signal emits the new date (selected with datepicker or other - menu-items). - */ - void dateChanged ( TQDate ); - - protected slots: - void slotDateChanged ( TQDate ); - - void slotToday(); - void slotTomorrow(); - void slotNextWeek(); - void slotNextMonth(); - void slotNoDate(); - - private: - void buildMenu(); - - KDatePicker *mDatePicker; - int mItems; -}; - -#endif diff --git a/libkdepim/kdepim.widgets b/libkdepim/kdepim.widgets deleted file mode 100644 index 765abc23b..000000000 --- a/libkdepim/kdepim.widgets +++ /dev/null @@ -1,29 +0,0 @@ -[Global] -PluginName=KDEPimWidgets -Includes=kinstance.h -Init=new KInstance("tdepimwidgets"); - -[KPIM::AddresseeLineEdit] -ToolTip=Addressee Line Edit (KDE-PIM) -WhatsThis=A line edit which lets you select addressees from the addressbook -IncludeFile=libtdepim/addresseelineedit.h -Group=Input (KDE-PIM) - -[KPIM::ClickLineEdit] -ToolTip=Click Line Edit (KDE-PIM) -WhatsThis=A line edit that shows grayed-out default text when no text is set. -IncludeFile=libtdepim/clicklineedit.h -Group=Input (KDE-PIM) - -[KDateEdit] -ToolTip=Date Edit Combobox (KDE-PIM) -WhatsThis=A widget to enter a date. It can also be selected from a date picker calendar. -IncludeFile=libtdepim/kdateedit.h -Group=Input (KDE-PIM) - -[KTimeEdit] -ToolTip=Time Edit Combobox (KDE-PIM) -WhatsThis=A widget to enter a time. It can also be selected from a drop-down list. -IncludeFile=libtdepim/ktimeedit.h -ConstructorArgs=(parent, TQTime::currentTime(), name) -Group=Input (KDE-PIM) diff --git a/libkdepim/kdepimmacros.h b/libkdepim/kdepimmacros.h deleted file mode 100644 index b341ee7ba..000000000 --- a/libkdepim/kdepimmacros.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002-2003 KDE Team - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// WARNING Don't add include guards here, they were removed on purpose - -#include -#include - -#if KDE_IS_VERSION( 3,3,90 ) -/* life is great */ -#else -/* workaround typo that breaks compilation with newer gcc */ -#undef KDE_EXPORT -#define KDE_EXPORT -#undef KDE_NO_EXPORT -#define KDE_NO_EXPORT -#endif diff --git a/libkdepim/kdepimprotocols.h b/libkdepim/kdepimprotocols.h deleted file mode 100644 index e269fcabd..000000000 --- a/libkdepim/kdepimprotocols.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2005 Rafal Rzepecki - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KDEPIM_KDEPIMPROTOCOLS_H -#define KDEPIM_KDEPIMPROTOCOLS_H - -/* a central place to store protocol strings to avoid knowledge duplication */ - -#define KDEPIMPROTOCOL_CONTACT "uid:" -#define KDEPIMPROTOCOL_EMAIL "kmail:" -#define KDEPIMPROTOCOL_INCIDENCE "urn:x-ical" -#define KDEPIMPROTOCOL_NEWSARTICLE "news:" - -#endif diff --git a/libkdepim/kfileio.cpp b/libkdepim/kfileio.cpp deleted file mode 100644 index e167662bb..000000000 --- a/libkdepim/kfileio.cpp +++ /dev/null @@ -1,390 +0,0 @@ -// kfileio.cpp -// Author: Stefan Taferner -// License: GPL - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include - -namespace KPIM { - -//----------------------------------------------------------------------------- -static void msgDialog(const TQString &msg) -{ - KMessageBox::sorry(0, msg, i18n("File I/O Error")); -} - - -//----------------------------------------------------------------------------- -KDE_EXPORT TQCString kFileToString(const TQString &aFileName, bool aEnsureNL, bool aVerbose) -{ - TQCString result; - TQFileInfo info(aFileName); - unsigned int readLen; - unsigned int len = info.size(); - TQFile file(aFileName); - - //assert(aFileName!=0); - if( aFileName.isEmpty() ) - return ""; - - if (!info.exists()) - { - if (aVerbose) - msgDialog(i18n("The specified file does not exist:\n%1").tqarg(aFileName)); - return TQCString(); - } - if (info.isDir()) - { - if (aVerbose) - msgDialog(i18n("This is a folder and not a file:\n%1").tqarg(aFileName)); - return TQCString(); - } - if (!info.isReadable()) - { - if (aVerbose) - msgDialog(i18n("You do not have read permissions " - "to the file:\n%1").tqarg(aFileName)); - return TQCString(); - } - if (len <= 0) return TQCString(); - - if (!file.open(IO_Raw|IO_ReadOnly)) - { - if (aVerbose) switch(file.status()) - { - case IO_ReadError: - msgDialog(i18n("Could not read file:\n%1").tqarg(aFileName)); - break; - case IO_OpenError: - msgDialog(i18n("Could not open file:\n%1").tqarg(aFileName)); - break; - default: - msgDialog(i18n("Error while reading file:\n%1").tqarg(aFileName)); - } - return TQCString(); - } - - result.resize(len + (int)aEnsureNL + 1); - readLen = file.readBlock(result.data(), len); - if (aEnsureNL && result[len-1]!='\n') - { - result[len++] = '\n'; - readLen++; - } - result[len] = '\0'; - - if (readLen < len) - { - TQString msg = i18n("Could only read %1 bytes of %2.") - .tqarg(readLen).tqarg(len); - msgDialog(msg); - return TQCString(); - } - - return result; -} - -//----------------------------------------------------------------------------- -#if 0 // unused -TQByteArray kFileToBytes(const TQString &aFileName, bool aVerbose) -{ - TQByteArray result; - TQFileInfo info(aFileName); - unsigned int readLen; - unsigned int len = info.size(); - TQFile file(aFileName); - - //assert(aFileName!=0); - if( aFileName.isEmpty() ) - return result; - - if (!info.exists()) - { - if (aVerbose) - msgDialog(i18n("The specified file does not exist:\n%1") - .tqarg(aFileName)); - return result; - } - if (info.isDir()) - { - if (aVerbose) - msgDialog(i18n("This is a folder and not a file:\n%1") - .tqarg(aFileName)); - return result; - } - if (!info.isReadable()) - { - if (aVerbose) - msgDialog(i18n("You do not have read permissions " - "to the file:\n%1").tqarg(aFileName)); - return result; - } - if (len <= 0) return result; - - if (!file.open(IO_Raw|IO_ReadOnly)) - { - if (aVerbose) switch(file.status()) - { - case IO_ReadError: - msgDialog(i18n("Could not read file:\n%1").tqarg(aFileName)); - break; - case IO_OpenError: - msgDialog(i18n("Could not open file:\n%1").tqarg(aFileName)); - break; - default: - msgDialog(i18n("Error while reading file:\n%1").tqarg(aFileName)); - } - return result; - } - - result.resize(len); - readLen = file.readBlock(result.data(), len); - kdDebug(5300) << TQString( "len %1" ).tqarg(len) << endl; - - if (readLen < len) - { - TQString msg; - msg = i18n("Could only read %1 bytes of %2.") - .tqarg(readLen).tqarg(len); - msgDialog(msg); - return result; - } - - return result; -} -#endif - -//----------------------------------------------------------------------------- -KDE_EXPORT bool kBytesToFile(const char* aBuffer, int len, - const TQString &aFileName, - bool aAskIfExists, bool aBackup, bool aVerbose) -{ - // TODO: use KSaveFile - TQFile file(aFileName); - int writeLen, rc; - - //assert(aFileName!=0); - if(aFileName.isEmpty()) - return FALSE; - - if (file.exists()) - { - if (aAskIfExists) - { - TQString str; - str = i18n("File %1 exists.\nDo you want to replace it?") - .tqarg(aFileName); - rc = KMessageBox::warningContinueCancel(0, - str, i18n("Save to File"), i18n("&Replace")); - if (rc != KMessageBox::Continue) return FALSE; - } - if (aBackup) - { - // make a backup copy - // TODO: use KSaveFile::backupFile() - TQString bakName = aFileName; - bakName += '~'; - TQFile::remove(bakName); - if( !TQDir::current().rename(aFileName, bakName) ) - { - // failed to rename file - if (!aVerbose) return FALSE; - rc = KMessageBox::warningContinueCancel(0, - i18n("Failed to make a backup copy of %1.\nContinue anyway?") - .tqarg(aFileName), - i18n("Save to File"), KStdGuiItem::save() ); - if (rc != KMessageBox::Continue) return FALSE; - } - } - } - - if (!file.open(IO_Raw|IO_WriteOnly|IO_Truncate)) - { - if (aVerbose) switch(file.status()) - { - case IO_WriteError: - msgDialog(i18n("Could not write to file:\n%1").tqarg(aFileName)); - break; - case IO_OpenError: - msgDialog(i18n("Could not open file for writing:\n%1") - .tqarg(aFileName)); - break; - default: - msgDialog(i18n("Error while writing file:\n%1").tqarg(aFileName)); - } - return FALSE; - } - - writeLen = file.writeBlock(aBuffer, len); - - if (writeLen < 0) - { - if (aVerbose) - msgDialog(i18n("Could not write to file:\n%1").tqarg(aFileName)); - return FALSE; - } - else if (writeLen < len) - { - TQString msg = i18n("Could only write %1 bytes of %2.") - .tqarg(writeLen).tqarg(len); - if (aVerbose) - msgDialog(msg); - return FALSE; - } - - return TRUE; -} - -KDE_EXPORT bool kCStringToFile(const TQCString& aBuffer, const TQString &aFileName, - bool aAskIfExists, bool aBackup, bool aVerbose) -{ - return kBytesToFile(aBuffer, aBuffer.length(), aFileName, aAskIfExists, - aBackup, aVerbose); -} - -KDE_EXPORT bool kByteArrayToFile(const TQByteArray& aBuffer, const TQString &aFileName, - bool aAskIfExists, bool aBackup, bool aVerbose) -{ - return kBytesToFile(aBuffer, aBuffer.size(), aFileName, aAskIfExists, - aBackup, aVerbose); -} - - -TQString checkAndCorrectPermissionsIfPossible( const TQString &toCheck, - const bool recursive, const bool wantItReadable, - const bool wantItWritable ) -{ - // First we have to find out which type the toCheck is. This can be - // a directory (follow if recursive) or a file (check permissions). - // Symlinks are followed as expected. - TQFileInfo fiToCheck(toCheck); - fiToCheck.setCaching(false); - TQCString toCheckEnc = TQFile::encodeName(toCheck); - TQString error; - struct stat statbuffer; - - if ( !fiToCheck.exists() ) { - error.append( i18n("%1 does not exist") - .tqarg(toCheck) + "\n"); - } - - // check the access bit of a folder. - if ( fiToCheck.isDir() ) { - if ( stat( toCheckEnc,&statbuffer ) != 0 ) { - kdDebug() << "wantItA: Can't read perms of " << toCheck << endl; - } - TQDir g( toCheck ); - if ( !g.isReadable() ) { - if ( chmod( toCheckEnc, statbuffer.st_mode + S_IXUSR ) != 0 ) { - error.append( i18n("%1 is not accessible and that is " - "unchangeable.").tqarg(toCheck) + "\n"); - } else { - kdDebug() << "Changed access bit for " << toCheck << endl; - } - } - } - - // For each file or folder we can check if the file is readable - // and writable, as requested. - if ( fiToCheck.isFile() || fiToCheck.isDir() ) { - - if ( !fiToCheck.isReadable() && wantItReadable ) { - // Get the current permissions. No need to do anything with an - // error, it will het added to errors anyhow, later on. - if ( stat(toCheckEnc,&statbuffer) != 0 ) { - kdDebug() << "wantItR: Can't read perms of " << toCheck << endl; - } - - // Lets try changing it. - if ( chmod( toCheckEnc, statbuffer.st_mode + S_IRUSR ) != 0 ) { - error.append( i18n("%1 is not readable and that is unchangeable.") - .tqarg(toCheck) + "\n"); - } else { - kdDebug() << "Changed the read bit for " << toCheck << endl; - } - } - - if ( !fiToCheck.isWritable() && wantItWritable ) { - // Gets the current persmissions. Needed because it can be changed - // curing previous operation. - if (stat(toCheckEnc,&statbuffer) != 0) { - kdDebug() << "wantItW: Can't read perms of " << toCheck << endl; - } - - // Lets try changing it. - if ( chmod (toCheckEnc, statbuffer.st_mode + S_IWUSR ) != 0 ) { - error.append( i18n("%1 is not writable and that is unchangeable.") - .tqarg(toCheck) + "\n"); - } else { - kdDebug() << "Changed the write bit for " << toCheck << endl; - } - } - } - - // If it is a folder and recursive is true, then we check the contents of - // the folder. - if ( fiToCheck.isDir() && recursive ){ - TQDir g(toCheck); - // First check if the folder is readable for us. If not, we get - // some ugly crashes. - if ( !g.isReadable() ){ - error.append(i18n("Folder %1 is inaccessible.").tqarg(toCheck) + "\n"); - } else { - const TQFileInfoList *list = g.entryInfoList(); - TQFileInfoListIterator it( *list ); - TQFileInfo *fi; - while ((fi = it.current()) != 0) { - TQString newToCheck = toCheck + "/" + fi->fileName(); - TQFileInfo fiNewToCheck(newToCheck); - if ( fi->fileName() != "." && fi->fileName() != ".." ) { - error.append ( checkAndCorrectPermissionsIfPossible( newToCheck, - recursive, wantItReadable, wantItWritable) ); - } - ++it; - } - } - } - return error; -} - -bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( TQWidget *parent, - const TQString &toCheck, const bool recursive, const bool wantItReadable, - const bool wantItWritable ) -{ - TQString error = checkAndCorrectPermissionsIfPossible(toCheck, recursive, - wantItReadable, wantItWritable); - // There is no KMessageBox with Retry, Cancel and Details. - // so, I can't provide a functionality to recheck. So it now - // it is just a warning. - if ( !error.isEmpty() ) { - kdDebug() << "checkPermissions found:" << error << endl; - KMessageBox::detailedSorry(parent, - i18n("Some files or folders do not have " - "the right permissions, please correct them " - "manually."), - error, i18n("Permissions Check"), false); - return false; - } else { - return true; - } -} - -} diff --git a/libkdepim/kfileio.h b/libkdepim/kfileio.h deleted file mode 100644 index 15db09338..000000000 --- a/libkdepim/kfileio.h +++ /dev/null @@ -1,105 +0,0 @@ -/* Load / save entire (local) files with nice diagnostics dialog messages. - * These functions load/save the whole buffer in one i/o call, so they - * should be pretty efficient. - * - * Author: Stefan Taferner - * This code is under GPL. - */ -#ifndef kpim_kfileio_h -#define kpim_kfileio_h - -#include -#include - -#include - -class TQString; - -namespace KPIM { - -/** Load a file. Returns a pointer to the memory-block that contains - * the loaded file. Returns a null string if the file could not be loaded. - * If withDialogs is FALSE no warning dialogs are opened if there are - * problems. - * The string returned is always zero-terminated and therefore one - * byte longer than the file itself. - * If ensureNewline is TRUE the string will always have a trailing newline. - */ -TQCString kFileToString(const TQString &fileName, bool ensureNewline=true, - bool withDialogs=true) KDE_EXPORT; - -// unused -//TQByteArray kFileToBytes(const TQString &fileName, bool withDialogs=true); - - -/** Save a file. If withDialogs is FALSE no warning dialogs are opened if - * there are problems. Returns TRUE on success and FALSE on failure. - * Replaces existing files without warning if askIfExists==FALSE. - * Makes a copy if the file exists to filename~ if createBackup==TRUE. - */ -bool kBytesToFile(const char* aBuffer, int len, - const TQString &aFileName, - bool aAskIfExists, bool aBackup, bool aVerbose) KDE_EXPORT; - -bool kCStringToFile(const TQCString& buffer, const TQString &fileName, - bool askIfExists=false, bool createBackup=true, - bool withDialogs=true) KDE_EXPORT; -/** Does not stop at NUL */ -KDE_EXPORT bool kByteArrayToFile(const TQByteArray& buffer, const TQString &fileName, - bool askIfExists=false, bool createBackup=true, - bool withDialogs=true) KDE_EXPORT; - - - /** - * Checks and corrects the permissions of a file or folder, and if requested - * all files and folders below. It gives back a list of files which do not - * have the right permissions. This list can be used to show to the user. - * - * @param toCheck The file or folder of which the permissions should - * be checked. - * @param recursive Set to true, it will check the contents of a folder - * for the permissions recursively. If false only - * toCheck will be checked. - * @param wantItReadable Set to true, it will check for read permissions. - * If the read permissions are not available, there will - * be a attempt to correct this. - * @param wantItWritable Set to true, it will check for write permissions. - * If the write permissions are not available, there - * will be a attempt to correct this. - * @return It will return a string with all files and folders which do not - * have the right permissions. If empty, then all permissions are ok. - */ -TQString checkAndCorrectPermissionsIfPossible( const TQString &toCheck, - const bool recursive, const bool wantItReadable, - const bool wantItWritable ); - - /** - * Checks and corrects the permissions of a file or folder, and if requested - * all files and folders below. If the permissions are not ok, it tries to correct - * them. If that fails then a warning with detailled information is given. - * - * @param parent If parent is 0, then the message box becomes an - * application-global modal dialog box. If parent - * is a widget, the message box becomes modal - * relative to parent. - * @param toCheck The file or folder of which the permissions should - * be checked. - * @param recursive Set to true, it will check the contents of a folder - * for the permissions recursively. If false only - * toCheck will be checked. - * @param wantItReadable Set to true, it will check for read permissions. - * If the read permissions are not available, there will - * be a attempt to correct this. - * @param wantItWritable Set to true, it will check for write permissions. - * If the write permissions are not available, there - * will be a attempt to correct this. - * @return It will return true if all permissions in the end are ok. If false - * then the permissions are not ok and it was not possible to correct - * all errors. - */ -bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( TQWidget *parent, - const TQString &toCheck, const bool recursive, const bool wantItReadable, - const bool wantItWritable ); -} - -#endif /*kpim_kfileio_h*/ diff --git a/libkdepim/kfoldertree.cpp b/libkdepim/kfoldertree.cpp deleted file mode 100644 index 64859199a..000000000 --- a/libkdepim/kfoldertree.cpp +++ /dev/null @@ -1,542 +0,0 @@ -// -*- c-basic-offset: 2 -*- - -#include "kfoldertree.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//----------------------------------------------------------------------------- -KFolderTreeItem::KFolderTreeItem( KFolderTree *parent, const TQString & label, - Protocol protocol, Type type ) - : KListViewItem( parent, label ), mProtocol( protocol ), mType( type ), - mUnread(-1), mTotal(0), mSize(0), mFolderIsCloseToQuota( false ) -{ -} - -//----------------------------------------------------------------------------- -KFolderTreeItem::KFolderTreeItem( KFolderTreeItem *parent, - const TQString & label, Protocol protocol, Type type, - int unread, int total ) - : KListViewItem( parent, label ), mProtocol( protocol ), mType( type ), - mUnread( unread ), mTotal( total ), mSize(0), mFolderIsCloseToQuota( false ) -{ -} - -//----------------------------------------------------------------------------- -int KFolderTreeItem::protocolSortingKey() const -{ - // protocol dependant sorting order: - // local < imap < news < search < other - switch ( mProtocol ) { - case Local: - return 1; - case CachedImap: - case Imap: - return 2; - case News: - return 3; - case Search: - return 4; - default: - return 42; - } -} - -//----------------------------------------------------------------------------- -int KFolderTreeItem::typeSortingKey() const -{ - // type dependant sorting order: - // inbox < outbox < sent-mail < trash < drafts - // < calendar < contacts < notes < tasks - // < normal folders - switch ( mType ) { - case Inbox: - return 1; - case Outbox: - return 2; - case SentMail: - return 3; - case Trash: - return 4; - case Drafts: - return 5; - case Templates: - return 6; - case Calendar: - return 7; - case Contacts: - return 8; - case Notes: - return 9; - case Tasks: - return 10; - default: - return 42; - } -} - -//----------------------------------------------------------------------------- -int KFolderTreeItem::compare( TQListViewItem * i, int col, bool ) const -{ - KFolderTreeItem* other = static_cast( i ); - - if (col == 0) - { - // sort by folder - - // local root-folder - if ( depth() == 0 && mProtocol == NONE ) - return -1; - if ( other->depth() == 0 && other->protocol() == NONE ) - return 1; - - // first compare by protocol - int thisKey = protocolSortingKey(); - int thatKey = other->protocolSortingKey(); - if ( thisKey < thatKey ) - return -1; - if ( thisKey > thatKey ) - return 1; - - // then compare by type - thisKey = typeSortingKey(); - thatKey = other->typeSortingKey(); - if ( thisKey < thatKey ) - return -1; - if ( thisKey > thatKey ) - return 1; - - // and finally compare by name - return text( 0 ).localeAwareCompare( other->text( 0 ) ); - } - else - { - // sort by unread or total-column - TQ_INT64 a = 0, b = 0; - if (col == static_cast(listView())->unreadIndex()) - { - a = mUnread; - b = other->unreadCount(); - } - else if (col == static_cast(listView())->totalIndex()) - { - a = mTotal; - b = other->totalCount(); - } - else if (col == static_cast(listView())->sizeIndex()) - { - a = mSize; - b = other->folderSize(); - } - - if ( a == b ) - return 0; - else - return (a < b ? -1 : 1); - } -} - -//----------------------------------------------------------------------------- -void KFolderTreeItem::setUnreadCount( int aUnread ) -{ - if ( aUnread < 0 ) return; - - mUnread = aUnread; - - TQString unread = TQString(); - if (mUnread == 0) - unread = "- "; - else { - unread.setNum(mUnread); - unread += " "; - } - - setText( static_cast(listView())->unreadIndex(), - unread ); -} - -//----------------------------------------------------------------------------- -void KFolderTreeItem::setTotalCount( int aTotal ) -{ - if ( aTotal < 0 ) return; - - mTotal = aTotal; - - TQString total = TQString(); - if (mTotal == 0) - total = "- "; - else { - total.setNum(mTotal); - total += " "; - } - - setText( static_cast(listView())->totalIndex(), - total ); -} - -//----------------------------------------------------------------------------- -void KFolderTreeItem::setFolderSize( TQ_INT64 aSize ) -{ - if ( aSize < 0 ) return; // we need to update even if nothing changed, kids ... - - mSize = aSize; - - TQString size; - if (mType != Root) { - if (mSize == 0 && (childCount() == 0 || isOpen() ) ) - size = "- "; - else - size = KIO::convertSize(mSize); - } - if ( childCount() > 0 && !isOpen() ) { - TQ_INT64 recursiveSize = recursiveFolderSize(); - if ( recursiveSize != mSize ) { - if ( mType != Root ) - size += TQString::tqfromLatin1(" + %1").tqarg( KIO::convertSize( recursiveSize - mSize ) ); - else - size = KIO::convertSize( recursiveSize ); - } - } - size += " "; - - setText( static_cast(listView())->sizeIndex(), size ); -} - -//----------------------------------------------------------------------------- -TQ_INT64 KFolderTreeItem::recursiveFolderSize() const -{ - TQ_INT64 size = mSize; - - for ( TQListViewItem *item = firstChild() ; - item ; item = item->nextSibling() ) - { - size += static_cast(item)->recursiveFolderSize(); - } - return size; -} - - - -//----------------------------------------------------------------------------- -int KFolderTreeItem::countUnreadRecursive() -{ - int count = (mUnread > 0) ? mUnread : 0; - - for ( TQListViewItem *item = firstChild() ; - item ; item = item->nextSibling() ) - { - count += static_cast(item)->countUnreadRecursive(); - } - - return count; -} - -//----------------------------------------------------------------------------- -void KFolderTreeItem::paintCell( TQPainter * p, const TQColorGroup & cg, - int column, int width, int align ) -{ - KFolderTree *ft = static_cast(listView()); - - const int unreadRecursiveCount = countUnreadRecursive(); - const int unreadCount = ( mUnread > 0 ) ? mUnread : 0; - - - // use a special color for folders which are close to their quota - TQColorGroup mycg = cg; - if ( ( column == 0 || column == ft->sizeIndex() ) && folderIsCloseToQuota() ) - { - mycg.setColor( TQColorGroup::Text, ft->paintInfo().colCloseToQuota ); - } - - // use a bold-font for the folder- and the unread-columns - if ( (column == 0 || column == ft->unreadIndex()) - && ( unreadCount > 0 - || ( !isOpen() && unreadRecursiveCount > 0 ) ) ) - { - TQFont f = p->font(); - f.setWeight(TQFont::Bold); - p->setFont(f); - } - - - // most cells can be handled by KListView::paintCell, we only need to - // deal with the folder column if the unread column is not shown - - /* The below is exceedingly silly, but Ingo insists that the unread - * count that is shown in parenthesis after the folder name must - * be configurable in color. That means that paintCell needs to do - * two painting passes which flickers. Since that flicker is not - * needed when there is the unread column, special case that. */ - if ( ft->isUnreadActive() || column != 0 ) { - KListViewItem::paintCell( p, mycg, column, width, align ); - } else { - TQListView *lv = listView(); - TQString oldText = text(column); - - // set an empty text so that we can have our own implementation (see further down) - // but still benefit from KListView::paintCell - setText( column, "" ); - - KListViewItem::paintCell( p, mycg, column, width, align ); - - const TQPixmap *icon = pixmap( column ); - int marg = lv ? lv->itemMargin() : 1; - int r = marg; - - setText( column, oldText ); - if ( isSelected() ) - p->setPen( mycg.highlightedText() ); - else - p->setPen( mycg.color( TQColorGroup::Text ) ); - - if ( icon ) { - r += icon->width() + marg; - } - TQString t = text( column ); - if (t.isEmpty()) - return; - - // draw the unread-count if the unread-column is not active - TQString unread; - - if ( unreadCount > 0 || ( !isOpen() && unreadRecursiveCount > 0 ) ) { - if ( isOpen() ) - unread = " (" + TQString::number( unreadCount ) + ")"; - else if ( unreadRecursiveCount == unreadCount || mType == Root ) - unread = " (" + TQString::number( unreadRecursiveCount ) + ")"; - else - unread = " (" + TQString::number( unreadCount ) + " + " + - TQString::number( unreadRecursiveCount-unreadCount ) + ")"; - } - - // check if the text needs to be squeezed - TQFontMetrics fm( p->fontMetrics() ); - int unreadWidth = fm.width( unread ); - if ( fm.width( t ) + marg + r + unreadWidth > width ) - t = squeezeFolderName( t, fm, width - marg - r - unreadWidth ); - - TQRect br; - p->drawText( r, 0, width-marg-r, height(), - align | AlignVCenter, t, -1, &br ); - - if ( !unread.isEmpty() ) { - if (!isSelected()) - p->setPen( ft->paintInfo().colUnread ); - p->drawText( br.right(), 0, width-marg-br.right(), height(), - align | AlignVCenter, unread ); - } - } -} - - -TQString KFolderTreeItem::squeezeFolderName( const TQString &text, - const TQFontMetrics &fm, - uint width ) const -{ - return KStringHandler::rPixelSqueeze( text, fm, width ); -} - -bool KFolderTreeItem::folderIsCloseToQuota() const -{ - return mFolderIsCloseToQuota; -} - -void KFolderTreeItem::setFolderIsCloseToQuota( bool v ) -{ - if ( mFolderIsCloseToQuota != v) { - mFolderIsCloseToQuota = v; - tqrepaint(); - } -} - - -//============================================================================= - - -KFolderTree::KFolderTree( TQWidget *parent, const char* name ) - : KListView( parent, name ), mUnreadIndex(-1), mTotalIndex(-1), mSizeIndex(-1) -{ - // GUI-options - setStyleDependantFrameWidth(); - setAcceptDrops(true); - setDropVisualizer(false); - setAllColumnsShowFocus(true); - setShowSortIndicator(true); - setUpdatesEnabled(true); - setItemsRenameable(false); - setRootIsDecorated(true); - setSelectionModeExt(Extended); - setAlternateBackground(TQColor()); -#if KDE_IS_VERSION( 3, 3, 90 ) - setShadeSortColumn ( false ); -#endif - setFullWidth(true); - disableAutoSelection(); - setColumnWidth( 0, 120 ); //reasonable default size - - disconnect( header(), TQT_SIGNAL( sizeChange( int, int, int ) ) ); - connect( header(), TQT_SIGNAL( sizeChange( int, int, int ) ), - TQT_SLOT( slotSizeChanged( int, int, int ) ) ); -} - -//----------------------------------------------------------------------------- -void KFolderTree::setStyleDependantFrameWidth() -{ - // set the width of the frame to a reasonable value for the current GUI style - int frameWidth; - if( tqstyle().isA("KeramikStyle") ) - frameWidth = tqstyle().tqpixelMetric( TQStyle::PM_DefaultFrameWidth ) - 1; - else - frameWidth = tqstyle().tqpixelMetric( TQStyle::PM_DefaultFrameWidth ); - if ( frameWidth < 0 ) - frameWidth = 0; - if ( frameWidth != lineWidth() ) - setLineWidth( frameWidth ); -} - -//----------------------------------------------------------------------------- -void KFolderTree::styleChange( TQStyle& oldStyle ) -{ - setStyleDependantFrameWidth(); - KListView::styleChange( oldStyle ); -} - -//----------------------------------------------------------------------------- -void KFolderTree::drawContentsOffset( TQPainter * p, int ox, int oy, - int cx, int cy, int cw, int ch ) -{ - bool oldUpdatesEnabled = isUpdatesEnabled(); - setUpdatesEnabled(false); - KListView::drawContentsOffset( p, ox, oy, cx, cy, cw, ch ); - setUpdatesEnabled(oldUpdatesEnabled); -} - -//----------------------------------------------------------------------------- -void KFolderTree::contentsMousePressEvent( TQMouseEvent *e ) -{ - setSelectionModeExt(Single); - KListView::contentsMousePressEvent(e); -} - -//----------------------------------------------------------------------------- -void KFolderTree::contentsMouseReleaseEvent( TQMouseEvent *e ) -{ - KListView::contentsMouseReleaseEvent(e); - setSelectionModeExt(Extended); -} - -//----------------------------------------------------------------------------- -void KFolderTree::addAcceptableDropMimetype( const char *mimeType, bool outsideOk ) -{ - int oldSize = mAcceptableDropMimetypes.size(); - mAcceptableDropMimetypes.resize(oldSize+1); - mAcceptOutside.resize(oldSize+1); - - mAcceptableDropMimetypes.at(oldSize) = mimeType; - mAcceptOutside.setBit(oldSize, outsideOk); -} - -//----------------------------------------------------------------------------- -bool KFolderTree::acceptDrag( TQDropEvent* event ) const -{ - TQListViewItem* item = itemAt(contentsToViewport(event->pos())); - - for (uint i = 0; i < mAcceptableDropMimetypes.size(); i++) - { - if (event->provides(mAcceptableDropMimetypes[i])) - { - if (item) - return (static_cast(item))->acceptDrag(event); - else - return mAcceptOutside[i]; - } - } - return false; -} - -//----------------------------------------------------------------------------- -void KFolderTree::addUnreadColumn( const TQString & name, int width ) -{ - mUnreadIndex = addColumn( name, width ); - setColumnAlignment( mUnreadIndex, tqApp->reverseLayout() ? TQt::AlignLeft : TQt::AlignRight ); - header()->adjustHeaderSize(); -} - -//----------------------------------------------------------------------------- -void KFolderTree::addTotalColumn( const TQString & name, int width ) -{ - mTotalIndex = addColumn( name, width ); - setColumnAlignment( mTotalIndex, tqApp->reverseLayout() ? TQt::AlignLeft : TQt::AlignRight ); - header()->adjustHeaderSize(); -} - -//----------------------------------------------------------------------------- -void KFolderTree::removeUnreadColumn() -{ - if ( !isUnreadActive() ) return; - removeColumn( mUnreadIndex ); - if ( isTotalActive() && mTotalIndex > mUnreadIndex ) - mTotalIndex--; - if ( isSizeActive() && mSizeIndex > mUnreadIndex ) - mSizeIndex--; - - mUnreadIndex = -1; - header()->adjustHeaderSize(); -} - -//----------------------------------------------------------------------------- -void KFolderTree::removeTotalColumn() -{ - if ( !isTotalActive() ) return; - removeColumn( mTotalIndex ); - if ( isUnreadActive() && mTotalIndex < mUnreadIndex ) - mUnreadIndex--; - if ( isSizeActive() && mTotalIndex < mSizeIndex ) - mSizeIndex--; - mTotalIndex = -1; - header()->adjustHeaderSize(); -} - -//----------------------------------------------------------------------------- -void KFolderTree::addSizeColumn( const TQString & name, int width ) -{ - mSizeIndex = addColumn( name, width ); - setColumnAlignment( mSizeIndex, tqApp->reverseLayout() ? TQt::AlignLeft : TQt::AlignRight ); - header()->adjustHeaderSize(); -} - -//----------------------------------------------------------------------------- -void KFolderTree::removeSizeColumn() -{ - if ( !isSizeActive() ) return; - removeColumn( mSizeIndex ); - if ( isUnreadActive() && mSizeIndex < mUnreadIndex ) - mUnreadIndex--; - if ( isTotalActive() && mSizeIndex < mTotalIndex ) - mTotalIndex--; - mSizeIndex = -1; - header()->adjustHeaderSize(); -} - - -//----------------------------------------------------------------------------- -void KFolderTree::setFullWidth( bool fullWidth ) -{ - if (fullWidth) - header()->setStretchEnabled( true, 0 ); -} - -//----------------------------------------------------------------------------- -void KFolderTree::slotSizeChanged( int section, int, int newSize ) -{ - viewport()->tqrepaint( - header()->sectionPos(section), 0, newSize, visibleHeight(), false ); -} - -#include "kfoldertree.moc" diff --git a/libkdepim/kfoldertree.h b/libkdepim/kfoldertree.h deleted file mode 100644 index 5ee255731..000000000 --- a/libkdepim/kfoldertree.h +++ /dev/null @@ -1,319 +0,0 @@ -/* -*- mode: C++; c-file-style: "gnu" -*- - - This file is part of libtdepim. - - Copyright (C) 2002 Carsten Burghardt - Copyright (C) 2002 Marc Mutz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef __KFOLDERTREE -#define __KFOLDERTREE - -#include -#include -#include -#include -#include -#include - -class KFolderTree; - -/** Information shared by all items in a list view */ -struct KPaintInfo { - - // Popup ids for toggle-able columns - enum ColumnIds - { - COL_SIZE, - COL_ATTACHMENT, - COL_INVITATION, - COL_IMPORTANT, - COL_TODO, - COL_SPAM_HAM, - COL_WATCHED_IGNORED, - COL_STATUS, - COL_SIGNED, - COL_CRYPTO, - COL_RECEIVER, - COL_SCORE - }; - - KPaintInfo() : - pixmapOn(false), - - showSize(false), - showAttachment(false), - showInvitation(false), - showImportant(false), - showTodo(false), - showSpamHam(false), - showWatchedIgnored(false), - showtqStatus(false), - showSigned(false), - showCrypto(false), - showReceiver(false), - showScore(false), - - scoreCol(-1), - flagCol(-1), - senderCol(-1), - receiverCol(-1), - subCol(-1), - dateCol(-1), - sizeCol(-1), - attachmentCol(-1), - invitationCol(-1), - importantCol(-1), - todoCol(-1), - spamHamCol(-1), - watchedIgnoredCol(-1), - statusCol(-1), - signedCol(-1), - cryptoCol(-1), - - orderOfArrival(false), - status(false), - showCryptoIcons(false), - showAttachmentIcon(false), - showInvitationIcon(false) - {} - - bool pixmapOn; - TQPixmap pixmap; - TQColor colFore; - TQColor colBack; - TQColor colNew; - TQColor colUnread; - TQColor colFlag; - TQColor colTodo; - TQColor colCloseToQuota; - - bool showSize; - bool showAttachment; - bool showInvitation; - bool showImportant; - bool showTodo; - bool showSpamHam; - bool showWatchedIgnored; - bool showtqStatus; - bool showSigned; - bool showCrypto; - bool showReceiver; - bool showScore; - - int scoreCol; - int flagCol; - int senderCol; - int receiverCol; - int subCol; - int dateCol; - int sizeCol; - int attachmentCol; - int invitationCol; - int importantCol; - int todoCol; - int spamHamCol; - int watchedIgnoredCol; - int statusCol; - int signedCol; - int cryptoCol; - - bool orderOfArrival; - bool status; - bool showCryptoIcons; - bool showAttachmentIcon; - bool showInvitationIcon; -}; - -//========================================================================== - -class KDE_EXPORT KFolderTreeItem : public KListViewItem -{ - public: - /** Protocol information */ - enum Protocol { - Imap, - Local, - News, - CachedImap, - Search, - NONE - }; - - /** Type information */ - enum Type { - Inbox, - Outbox, - SentMail, - Trash, - Drafts, - Templates, - Root, - Calendar, - Tasks, - Journals, - Contacts, - Notes, - Other - }; - - /** constructs a root-item */ - KFolderTreeItem( KFolderTree *parent, const TQString & label=TQString(), - Protocol protocol=NONE, Type type=Root ); - - /** constructs a child-item */ - KFolderTreeItem( KFolderTreeItem *parent, const TQString & label=TQString(), - Protocol protocol=NONE, Type type=Other, int unread=0, int total=0 ); - - /** compare */ - virtual int compare( TQListViewItem * i, int col, - bool ascending ) const; - - /** set/get the unread-count */ - int unreadCount() { return mUnread; } - virtual void setUnreadCount( int aUnread ); - - /** set/get the total-count */ - int totalCount() { return mTotal; } - virtual void setTotalCount( int aTotal ); - - /** set/get the total-count */ - TQ_INT64 folderSize() { return mSize; } - virtual void setFolderSize( TQ_INT64 aSize ); - - /** set/get the protocol of the item */ - Protocol protocol() const { return mProtocol; } - virtual void setProtocol( Protocol aProtocol ) { mProtocol = aProtocol; } - - /** set/get the type of the item */ - Type type() const { return mType; } - virtual void setType( Type aType ) { mType = aType; } - - /** recursive unread count */ - virtual int countUnreadRecursive(); - - virtual TQ_INT64 recursiveFolderSize() const; - - /** paints the cell */ - virtual void paintCell( TQPainter * p, const TQColorGroup & cg, - int column, int width, int align ); - - /** dnd */ - virtual bool acceptDrag(TQDropEvent* ) const { return true; } - - void setFolderIsCloseToQuota( bool ); - bool folderIsCloseToQuota() const; - - private: - /** returns a sorting key based on the folder's protocol */ - int protocolSortingKey() const; - /** returns a sorting key based on the folder's type */ - int typeSortingKey() const; - - protected: - /** reimplement to use special squeezing algorithm for the folder name */ - virtual TQString squeezeFolderName( const TQString &text, - const TQFontMetrics &fm, - uint width ) const; - - Protocol mProtocol; - Type mType; - int mUnread; - int mTotal; - TQ_INT64 mSize; - bool mFolderIsCloseToQuota; -}; - -//========================================================================== - -class KDE_EXPORT KFolderTree : public KListView -{ - Q_OBJECT - TQ_OBJECT - - public: - KFolderTree( TQWidget *parent, const char *name=0 ); - - /** registers MIMETypes that are handled - @param mimeType the name of the MIMEType - @param outsideOk accept drops of this type even if - the mouse cursor is not on top of an item */ - virtual void addAcceptableDropMimetype( const char *mimeType, bool outsideOk ); - - /** checks if the drag is acceptable */ - virtual bool acceptDrag( TQDropEvent* event ) const; - - /** returns the KPaintInfo */ - KPaintInfo paintInfo() const { return mPaintInfo; } - - /** add/remove unread/total-columns */ - virtual void addUnreadColumn( const TQString & name, int width=70 ); - virtual void removeUnreadColumn(); - virtual void addTotalColumn( const TQString & name, int width=70 ); - virtual void removeTotalColumn(); - virtual void addSizeColumn( const TQString & name, int width=70 ); - virtual void removeSizeColumn(); - - - /** the current index of the unread/total column */ - int unreadIndex() const { return mUnreadIndex; } - int totalIndex() const { return mTotalIndex; } - int sizeIndex() const { return mSizeIndex; } - - /** is the unread/total-column active? */ - bool isUnreadActive() const { return mUnreadIndex >= 0; } - bool isTotalActive() const { return mTotalIndex >= 0; } - bool isSizeActive() const { return mSizeIndex >= 0; } - - /** reimp to set full width of the _first_ column */ - virtual void setFullWidth( bool fullWidth ); - - protected: - /** reimplemented in order to update the frame width in case of a changed - GUI style */ - void styleChange( TQStyle& oldStyle ); - - /** Set the width of the frame to a reasonable value for the current GUI - style */ - void setStyleDependantFrameWidth(); - - virtual void drawContentsOffset( TQPainter * p, int ox, int oy, - int cx, int cy, int cw, int ch ); - - virtual void contentsMousePressEvent( TQMouseEvent *e ); - virtual void contentsMouseReleaseEvent( TQMouseEvent *e ); - - /** for mimetypes */ - TQMemArray mAcceptableDropMimetypes; - TQBitArray mAcceptOutside; - - /** shared information */ // ### why isn't it then static? ;-) - KPaintInfo mPaintInfo; - - /** current index of unread/total-column - * -1 is deactivated */ - int mUnreadIndex; - int mTotalIndex; - int mSizeIndex; - - private slots: - /** repaints the complete column (instead of only parts of it as done in - TQListView) if the size has changed */ - void slotSizeChanged( int section, int oldSize, int newSize ); - -}; - -#endif diff --git a/libkdepim/kimportdialog.cpp b/libkdepim/kimportdialog.cpp deleted file mode 100644 index da6c98fad..000000000 --- a/libkdepim/kimportdialog.cpp +++ /dev/null @@ -1,767 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002 Cornelius Schumacher - Copyright (c) 2002 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// Generic CSV import. Please do not add application specific code to this -// class. Application specific code should go to a subclass provided by the -// application using this dialog. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kimportdialog.h" -#include "kimportdialog.moc" - -KImportColumn::KImportColumn(KImportDialog *dlg,const TQString &header, int count) - : m_maxCount(count), - m_refCount(0), - m_header(header), - mDialog(dlg) -{ - mFormats.append(FormatPlain); - mFormats.append(FormatUnquoted); -// mFormats.append(FormatBracketed); - - mDefaultFormat = FormatUnquoted; - - mDialog->addColumn(this); -} - -TQValueList KImportColumn::formats() -{ - return mFormats; -} - -TQString KImportColumn::formatName(int format) -{ - switch (format) { - case FormatPlain: - return i18n("Plain"); - case FormatUnquoted: - return i18n("Unquoted"); - case FormatBracketed: - return i18n("Bracketed"); - default: - return i18n("Undefined"); - } -} - -int KImportColumn::defaultFormat() -{ - return mDefaultFormat; -} - -TQString KImportColumn::preview(const TQString &value, int format) -{ - if (format == FormatBracketed) { - return "(" + value + ")"; - } else if (format == FormatUnquoted) { - if (value.left(1) == "\"" && value.right(1) == "\"") { - return value.mid(1,value.length()-2); - } else { - return value; - } - } else { - return value; - } -} - -void KImportColumn::addColId(int id) -{ - mColIds.append(id); -} - -void KImportColumn::removeColId(int id) -{ - mColIds.remove(id); -} - -TQValueList KImportColumn::colIdList() -{ - return mColIds; -} - -TQString KImportColumn::convert() -{ - TQValueList::ConstIterator it = mColIds.begin(); - if (it == mColIds.end()) return ""; - else return mDialog->cell(*it); -} - - -class ColumnItem : public TQListViewItem { - public: - ColumnItem(KImportColumn *col,TQListView *parent) : TQListViewItem(parent), mColumn(col) - { - setText(0,mColumn->header()); - } - - KImportColumn *column() { return mColumn; } - - private: - KImportColumn *mColumn; -}; - -/** - This is a generic class for importing line-oriented data from text files. It - provides a dialog for file selection, preview, separator selection and column - assignment as well as generic conversion routines. For conversion to special - data objects, this class has to be inherited by a special class, which - reimplements the convertRow() function. -*/ -KImportDialog::KImportDialog(TQWidget* parent) - : KDialogBase(parent,"importdialog",true,i18n("Import Text File"),Ok|Cancel), - mSeparator(","), - mCurrentRow(0) -{ - mData.setAutoDelete( true ); - - TQVBox *topBox = new TQVBox(this); - setMainWidget(topBox); - topBox->setSpacing(spacingHint()); - - TQHBox *fileBox = new TQHBox(topBox); - fileBox->setSpacing(spacingHint()); - new TQLabel(i18n("File to import:"),fileBox); - KURLRequester *urlRequester = new KURLRequester(fileBox); - urlRequester->setFilter( "*.csv" ); - connect(urlRequester,TQT_SIGNAL(returnPressed(const TQString &)), - TQT_SLOT(setFile(const TQString &))); - connect(urlRequester,TQT_SIGNAL(urlSelected(const TQString &)), - TQT_SLOT(setFile(const TQString &))); - connect(urlRequester->lineEdit(),TQT_SIGNAL(textChanged ( const TQString & )), - TQT_SLOT(slotUrlChanged(const TQString & ))); - mTable = new TQTable(5,5,topBox); - mTable->setMinimumHeight( 150 ); - connect(mTable,TQT_SIGNAL(selectionChanged()),TQT_SLOT(tableSelected())); - - TQHBox *separatorBox = new TQHBox( topBox ); - separatorBox->setSpacing( spacingHint() ); - - new TQLabel( i18n( "Separator:" ), separatorBox ); - - mSeparatorCombo = new KComboBox( separatorBox ); - mSeparatorCombo->insertItem( "," ); - mSeparatorCombo->insertItem( i18n( "Tab" ) ); - mSeparatorCombo->insertItem( i18n( "Space" ) ); - mSeparatorCombo->insertItem( "=" ); - mSeparatorCombo->insertItem( ";" ); - connect(mSeparatorCombo, TQT_SIGNAL( activated(int) ), - this, TQT_SLOT( separatorClicked(int) ) ); - mSeparatorCombo->setCurrentItem( 0 ); - - TQHBox *rowsBox = new TQHBox( topBox ); - rowsBox->setSpacing( spacingHint() ); - - new TQLabel( i18n( "Import starts at row:" ), rowsBox ); - mStartRow = new TQSpinBox( rowsBox ); - mStartRow->setMinValue( 1 ); -/* - new TQLabel( i18n( "And ends at row:" ), rowsBox ); - mEndRow = new TQSpinBox( rowsBox ); - mEndRow->setMinValue( 1 ); -*/ - TQVBox *assignBox = new TQVBox(topBox); - assignBox->setSpacing(spacingHint()); - - TQHBox *listsBox = new TQHBox(assignBox); - listsBox->setSpacing(spacingHint()); - - mHeaderList = new TQListView(listsBox); - mHeaderList->addColumn(i18n("Header")); - connect(mHeaderList, TQT_SIGNAL(selectionChanged(TQListViewItem*)), - this, TQT_SLOT(headerSelected(TQListViewItem*))); - connect(mHeaderList,TQT_SIGNAL(doubleClicked(TQListViewItem*)), - TQT_SLOT(assignColumn(TQListViewItem *))); - - mFormatCombo = new KComboBox( listsBox ); - mFormatCombo->setDuplicatesEnabled( false ); - - TQPushButton *assignButton = new TQPushButton(i18n("Assign to Selected Column"), - assignBox); - connect(assignButton,TQT_SIGNAL(clicked()),TQT_SLOT(assignColumn())); - - TQPushButton *removeButton = new TQPushButton(i18n("Remove Assignment From Selected Column"), - assignBox); - connect(removeButton,TQT_SIGNAL(clicked()),TQT_SLOT(removeColumn())); - - TQPushButton *assignTemplateButton = new TQPushButton(i18n("Assign with Template..."), - assignBox); - connect(assignTemplateButton,TQT_SIGNAL(clicked()),TQT_SLOT(assignTemplate())); - - TQPushButton *saveTemplateButton = new TQPushButton(i18n("Save Current Template"), - assignBox); - connect(saveTemplateButton,TQT_SIGNAL(clicked()),TQT_SLOT(saveTemplate())); - - resize(500,300); - - connect(this,TQT_SIGNAL(okClicked()),TQT_SLOT(applyConverter())); - connect(this,TQT_SIGNAL(applyClicked()),TQT_SLOT(applyConverter())); - enableButtonOK(!urlRequester->lineEdit()->text().isEmpty()); -} - -void KImportDialog::slotUrlChanged(const TQString & text) -{ - enableButtonOK(!text.isEmpty()); -} - -bool KImportDialog::setFile(const TQString& file) -{ - enableButtonOK(!file.isEmpty()); - kdDebug(5300) << "KImportDialog::setFile(): " << file << endl; - - TQFile f(file); - - if (f.open(IO_ReadOnly)) { - mFile = ""; - TQTextStream t(&f); - mFile = t.read(); -// while (!t.eof()) mFile.append(t.readLine()); - f.close(); - - readFile(); - -// mEndRow->setValue( mData.count() ); - - return true; - } else { - kdDebug(5300) << " Open failed" << endl; - return false; - } -} - -void KImportDialog::registerColumns() -{ - TQPtrListIterator colIt(mColumns); - for (; colIt.current(); ++colIt) { - new ColumnItem(*colIt,mHeaderList); - } - mHeaderList->setSelected(mHeaderList->firstChild(),true); -} - -void KImportDialog::fillTable() -{ -// kdDebug(5300) << "KImportDialog::fillTable()" << endl; - - int row, column; - - for (row = 0; row < mTable->numRows(); ++row) - for (column = 0; column < mTable->numCols(); ++column) - mTable->clearCell(row, column); - - for ( row = 0; row < int(mData.count()); ++row ) { - TQValueVector *rowVector = mData[ row ]; - for( column = 0; column < int(rowVector->size()); ++column ) { - setCellText( row, column, rowVector->at( column ) ); - } - } -} - -void KImportDialog::readFile( int rows ) -{ - kdDebug(5300) << "KImportDialog::readFile(): " << rows << endl; - - mData.clear(); - - int row, column; - enum { S_START, S_TQUOTED_FIELD, S_MAYBE_END_OF_TQUOTED_FIELD, S_END_OF_TQUOTED_FIELD, - S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; - - TQChar m_textquote = '"'; - int m_startline = 0; - - TQChar x; - TQString field = ""; - - row = column = 0; - TQTextStream inputStream(mFile, IO_ReadOnly); - inputStream.setEncoding(TQTextStream::Locale); - - KProgressDialog pDialog(this, 0, i18n("Loading Progress"), - i18n("Please wait while the file is loaded."), true); - pDialog.setAllowCancel(true); - pDialog.showCancelButton(true); - pDialog.setAutoClose(true); - - KProgress *progress = pDialog.progressBar(); - progress->setTotalSteps( mFile.contains(mSeparator, false) ); - progress->setValue(0); - int progressValue = 0; - - if (progress->totalSteps() > 0) // We have data - pDialog.show(); - - while (!inputStream.atEnd() && !pDialog.wasCancelled()) { - inputStream >> x; // read one char - - // update the dialog if needed - if (x == mSeparator) - { - progress->setValue(progressValue++); - if (progressValue % 15 == 0) // try not to constantly tqrepaint - kapp->processEvents(); - } - - if (x == '\r') inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly - - switch (state) { - case S_START : - if (x == m_textquote) { - field += x; - state = S_TQUOTED_FIELD; - } else if (x == mSeparator) { - ++column; - } else if (x == '\n') { - ++row; - column = 0; - } else { - field += x; - state = S_MAYBE_NORMAL_FIELD; - } - break; - case S_TQUOTED_FIELD : - if (x == m_textquote) { - field += x; - state = S_MAYBE_END_OF_TQUOTED_FIELD; - } else if (x == '\n') { - setData(row - m_startline, column, field); - field = ""; - if (x == '\n') { - ++row; - column = 0; - } else { - ++column; - } - state = S_START; - } else { - field += x; - } - break; - case S_MAYBE_END_OF_TQUOTED_FIELD : - if (x == m_textquote) { - field += x; - state = S_TQUOTED_FIELD; - } else if (x == mSeparator || x == '\n') { - setData(row - m_startline, column, field); - field = ""; - if (x == '\n') { - ++row; - column = 0; - } else { - ++column; - } - state = S_START; - } else { - state = S_END_OF_TQUOTED_FIELD; - } - break; - case S_END_OF_TQUOTED_FIELD : - if (x == mSeparator || x == '\n') { - setData(row - m_startline, column, field); - field = ""; - if (x == '\n') { - ++row; - column = 0; - } else { - ++column; - } - state = S_START; - } else { - state = S_END_OF_TQUOTED_FIELD; - } - break; - case S_MAYBE_NORMAL_FIELD : - if (x == m_textquote) { - field = ""; - state = S_TQUOTED_FIELD; - } - case S_NORMAL_FIELD : - if (x == mSeparator || x == '\n') { - setData(row - m_startline, column, field); - field = ""; - if (x == '\n') { - ++row; - column = 0; - } else { - ++column; - } - state = S_START; - } else { - field += x; - } - } - - if ( rows > 0 && row > rows ) break; - } - - fillTable(); -} - -void KImportDialog::setCellText(int row, int col, const TQString& text) -{ - if (row < 0) return; - - if ((mTable->numRows() - 1) < row) mTable->setNumRows(row + 1); - if ((mTable->numCols() - 1) < col) mTable->setNumCols(col + 1); - - KImportColumn *c = mColumnDict.find(col); - TQString formattedText; - if (c) formattedText = c->preview(text,findFormat(col)); - else formattedText = text; - mTable->setText(row, col, formattedText); -} - -void KImportDialog::formatSelected(TQListViewItem*) -{ -// kdDebug(5300) << "KImportDialog::formatSelected()" << endl; -} - -void KImportDialog::headerSelected(TQListViewItem* item) -{ - KImportColumn *col = ((ColumnItem *)item)->column(); - - if (!col) return; - - mFormatCombo->clear(); - - TQValueList formats = col->formats(); - - TQValueList::ConstIterator it = formats.begin(); - TQValueList::ConstIterator end = formats.end(); - while(it != end) { - mFormatCombo->insertItem( col->formatName(*it), *it - 1 ); - ++it; - } - - TQTableSelection selection = mTable->selection(mTable->currentSelection()); - - updateFormatSelection(selection.leftCol()); -} - -void KImportDialog::updateFormatSelection(int column) -{ - int format = findFormat(column); - - if ( format == KImportColumn::FormatUndefined ) - mFormatCombo->setCurrentItem( 0 ); - else - mFormatCombo->setCurrentItem( format - 1 ); -} - -void KImportDialog::tableSelected() -{ - TQTableSelection selection = mTable->selection(mTable->currentSelection()); - - TQListViewItem *item = mHeaderList->firstChild(); - KImportColumn *col = mColumnDict.find(selection.leftCol()); - if (col) { - while(item) { - if (item->text(0) == col->header()) { - break; - } - item = item->nextSibling(); - } - } - if (item) { - mHeaderList->setSelected(item,true); - } - - updateFormatSelection(selection.leftCol()); -} - -void KImportDialog::separatorClicked(int id) -{ - switch(id) { - case 0: - mSeparator = ','; - break; - case 1: - mSeparator = '\t'; - break; - case 2: - mSeparator = ' '; - break; - case 3: - mSeparator = '='; - break; - case 4: - mSeparator = ';'; - break; - default: - mSeparator = ','; - break; - } - - readFile(); -} - -void KImportDialog::assignColumn(TQListViewItem *item) -{ - if (!item) return; - -// kdDebug(5300) << "KImportDialog::assignColumn(): current Col: " << mTable->currentColumn() -// << endl; - - ColumnItem *colItem = (ColumnItem *)item; - - TQTableSelection selection = mTable->selection(mTable->currentSelection()); - -// kdDebug(5300) << " l: " << selection.leftCol() << " r: " << selection.rightCol() << endl; - - for(int i=selection.leftCol();i<=selection.rightCol();++i) { - if (i >= 0) { - mTable->horizontalHeader()->setLabel(i,colItem->text(0)); - mColumnDict.replace(i,colItem->column()); - int format = mFormatCombo->currentItem() + 1; - mFormats.replace(i,format); - colItem->column()->addColId(i); - } - } - - readFile(); -} - -void KImportDialog::assignColumn() -{ - assignColumn(mHeaderList->currentItem()); -} - -void KImportDialog::assignTemplate() -{ - TQMap columnMap; - TQMap fileMap; - TQStringList templates; - - // load all template files - TQStringList list = KGlobal::dirs()->findAllResources( "data" , TQString( kapp->name() ) + - "/csv-templates/*.desktop", true, true ); - - for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) - { - KSimpleConfig config( *it, true ); - - if ( !config.hasGroup( "csv column map" ) ) - continue; - - config.setGroup( "Misc" ); - templates.append( config.readEntry( "Name" ) ); - fileMap.insert( config.readEntry( "Name" ), *it ); - } - - // let the user chose, what to take - bool ok = false; - TQString tmp; - tmp = KInputDialog::getItem( i18n( "Template Selection" ), - i18n( "Please select a template, that matches the CSV file:" ), - templates, 0, false, &ok, this ); - - if ( !ok ) - return; - - KSimpleConfig config( fileMap[ tmp ], true ); - config.setGroup( "General" ); - uint numColumns = config.readUnsignedNumEntry( "Columns" ); - int format = config.readNumEntry( "Format" ); - - // create the column map - config.setGroup( "csv column map" ); - for ( uint i = 0; i < numColumns; ++i ) { - int col = config.readNumEntry( TQString::number( i ) ); - columnMap.insert( i, col ); - } - - // apply the column map - for ( uint i = 0; i < columnMap.count(); ++i ) { - int tableColumn = columnMap[i]; - if ( tableColumn == -1 ) - continue; - KImportColumn *col = mColumns.at(i); - mTable->horizontalHeader()->setLabel( tableColumn, col->header() ); - mColumnDict.replace( tableColumn, col ); - mFormats.replace( tableColumn, format ); - col->addColId( tableColumn ); - } - - readFile(); -} - -void KImportDialog::removeColumn() -{ - TQTableSelection selection = mTable->selection(mTable->currentSelection()); - -// kdDebug(5300) << " l: " << selection.leftCol() << " r: " << selection.rightCol() << endl; - - for(int i=selection.leftCol();i<=selection.rightCol();++i) { - if (i >= 0) { - mTable->horizontalHeader()->setLabel(i,TQString::number(i+1)); - KImportColumn *col = mColumnDict.find(i); - if (col) { - mColumnDict.remove(i); - mFormats.remove(i); - col->removeColId(i); - } - } - } - - readFile(); -} - -void KImportDialog::applyConverter() -{ - kdDebug(5300) << "KImportDialog::applyConverter" << endl; - - KProgressDialog pDialog(this, 0, i18n("Importing Progress"), - i18n("Please wait while the data is imported."), true); - pDialog.setAllowCancel(true); - pDialog.showCancelButton(true); - pDialog.setAutoClose(true); - - KProgress *progress = pDialog.progressBar(); - progress->setTotalSteps( mTable->numRows()-1 ); - progress->setValue(0); - - readFile( 0 ); - - pDialog.show(); - for( uint i = mStartRow->value() - 1; i < mData.count() && !pDialog.wasCancelled(); ++i ) { - mCurrentRow = i; - progress->setValue(i); - if (i % 5 == 0) // try to avoid constantly processing events - kapp->processEvents(); - - convertRow(); - } -} - -int KImportDialog::findFormat(int column) -{ - TQMap::ConstIterator formatIt = mFormats.find(column); - int format; - if (formatIt == mFormats.end()) format = KImportColumn::FormatUndefined; - else format = *formatIt; - -// kdDebug(5300) << "KImportDialog::findformat(): " << column << ": " << format << endl; - - return format; -} - -TQString KImportDialog::cell(uint col) -{ - if ( col >= mData[ mCurrentRow ]->size() ) return ""; - else return data( mCurrentRow, col ); -} - -void KImportDialog::addColumn(KImportColumn *col) -{ - mColumns.append(col); -} - -void KImportDialog::setData( uint row, uint col, const TQString &value ) -{ - TQString val = value; - val.replace( "\\n", "\n" ); - - if ( row >= mData.count() ) { - mData.resize( row + 1 ); - } - - TQValueVector *rowVector = mData[ row ]; - if ( !rowVector ) { - rowVector = new TQValueVector; - mData.insert( row, rowVector ); - } - if ( col >= rowVector->size() ) { - rowVector->resize( col + 1 ); - } - - KImportColumn *c = mColumnDict.find( col ); - if ( c ) - rowVector->at( col ) = c->preview( val, findFormat(col) ); - else - rowVector->at( col ) = val; -} - -TQString KImportDialog::data( uint row, uint col ) -{ - return mData[ row ]->at( col ); -} - -void KImportDialog::saveTemplate() -{ - TQString fileName = KFileDialog::getSaveFileName( - locateLocal( "data", TQString( kapp->name() ) + "/csv-templates/" ), - "*.desktop", this ); - - if ( fileName.isEmpty() ) - return; - - if ( !fileName.contains( ".desktop" ) ) - fileName += ".desktop"; - - TQString name = KInputDialog::getText( i18n( "Template Name" ), i18n( "Please enter a name for the template:" ) ); - - if ( name.isEmpty() ) - return; - - KConfig config( fileName ); - config.setGroup( "General" ); - config.writeEntry( "Columns", mColumns.count() ); - config.writeEntry( "Format", mFormatCombo->currentItem() + 1 ); - - config.setGroup( "Misc" ); - config.writeEntry( "Name", name ); - - config.setGroup( "csv column map" ); - - KImportColumn *column; - uint counter = 0; - for ( column = mColumns.first(); column; column = mColumns.next() ) { - TQValueList list = column->colIdList(); - if ( list.count() > 0 ) - config.writeEntry( TQString::number( counter ), list[ 0 ] ); - else - config.writeEntry( TQString::number( counter ), -1 ); - counter++; - } - - config.sync(); -} diff --git a/libkdepim/kimportdialog.h b/libkdepim/kimportdialog.h deleted file mode 100644 index abcbb3181..000000000 --- a/libkdepim/kimportdialog.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002 Cornelius Schumacher - Copyright (c) 2002 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KIMPORTDIALOG_H -#define KIMPORTDIALOG_H - -#include -#include -#include -#include -#include - -#include - -class TQTable; -class TQListView; - -class KImportDialog; -class KComboBox; - -class KImportColumn -{ - public: - enum { FormatUndefined = 0, FormatPlain, FormatUnquoted, FormatBracketed, FormatLast }; - - KImportColumn(KImportDialog *dlg, const TQString &header, int count = 0); - virtual ~KImportColumn() {} - - TQString header() const { return m_header; } - - TQValueList formats(); - TQString formatName(int format); - int defaultFormat(); - - TQString convert(); -// virtual void convert(const TQString &value,int format) = 0; - TQString preview(const TQString &value,int format); - - void addColId(int i); - void removeColId(int i); - - TQValueList colIdList(); - - protected: - - private: - int m_maxCount, m_refCount; - - TQString m_header; - TQValueList mFormats; - int mDefaultFormat; - - TQValueList mColIds; - - KImportDialog *mDialog; -}; - -class KImportDialog : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT - public: - KImportDialog(TQWidget* parent); - - public slots: - bool setFile(const TQString& file); - - TQString cell(uint row); - - void addColumn(KImportColumn *); - - protected: - void readFile( int rows = 10 ); - - void fillTable(); - void registerColumns(); - int findFormat(int column); - - virtual void convertRow() {} - - protected slots: - void separatorClicked(int id); - void formatSelected(TQListViewItem* item); - void headerSelected(TQListViewItem* item); - void assignColumn(TQListViewItem *); - void assignColumn(); - void assignTemplate(); - void removeColumn(); - void applyConverter(); - void tableSelected(); - void slotUrlChanged(const TQString & ); - void saveTemplate(); - - private: - void updateFormatSelection(int column); - void setCellText(int row, int col, const TQString& text); - - void setData( uint row, uint col, const TQString &text ); - TQString data( uint row, uint col ); - - TQListView *mHeaderList; - TQSpinBox *mStartRow; - TQSpinBox *mEndRow; - TQTable *mTable; - - KComboBox *mFormatCombo; - KComboBox *mSeparatorCombo; - - TQString mSeparator; - int mCurrentRow; - TQString mFile; - TQIntDict mColumnDict; - TQIntDict mTemplateDict; - TQMap mFormats; - TQPtrList mColumns; - TQPtrVector > mData; -}; - -#endif diff --git a/libkdepim/kincidencechooser.cpp b/libkdepim/kincidencechooser.cpp deleted file mode 100644 index fee89bbb6..000000000 --- a/libkdepim/kincidencechooser.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Lutz Rogowski - - 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. - - As a special exception, permission is given to link this program - with any edition of TQt, and distribute the resulting executable, - without including the source code for TQt in the source distribution. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include - -#include "kincidencechooser.h" -#include "libkcal/incidence.h" -#include "libkcal/incidenceformatter.h" - -int KIncidenceChooser::chooseMode = KIncidenceChooser::ask ; - -KIncidenceChooser::KIncidenceChooser(TQWidget *parent, char *name) : - KDialog(parent,name,true) -{ - KDialog *topFrame = this; - TQGridLayout *topLayout = new TQGridLayout(topFrame,5,3); - int iii = 0; - setCaption( i18n("Conflict Detected")); - TQLabel * lab; - lab = new TQLabel( i18n( - "A conflict was detected. This probably means someone edited the same entry on the server while you changed it locally." - "
NOTE: You have to check mail again to apply your changes to the server.
"), topFrame); - topLayout->addMultiCellWidget(lab, iii,iii,0,2); - ++iii; - TQHBox * b_box = new TQHBox( topFrame ); - topLayout->addMultiCellWidget(b_box, iii,iii,0,2); - ++iii; - TQPushButton* button = new TQPushButton( i18n("Take Local"), b_box ); - connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeIncidence1() ) ); - button = new TQPushButton( i18n("Take New"), b_box ); - connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeIncidence2() ) ); - button = new TQPushButton( i18n("Take Both"), b_box ); - connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeBoth() ) ); - topLayout->setSpacing(spacingHint()); - topLayout->setMargin(marginHint()); - // text is not translated, because text has to be set later - mInc1lab = new TQLabel ( i18n("Local incidence"), topFrame); - topLayout->addWidget(mInc1lab ,iii,0); - mInc1Sumlab = new TQLabel ( i18n("Local incidence summary"), topFrame); - topLayout->addMultiCellWidget(mInc1Sumlab, iii,iii,1,2); - ++iii; - topLayout->addWidget( new TQLabel ( i18n("Last modified:"), topFrame) ,iii,0); - mMod1lab = new TQLabel ( "Set Last modified", topFrame); - topLayout->addWidget(mMod1lab,iii,1); - mShowDetails1 = new TQPushButton( i18n("Show Details"),topFrame ); - connect ( mShowDetails1, TQT_SIGNAL( clicked()), this, TQT_SLOT (showIncidence1() ) ); - topLayout->addWidget(mShowDetails1,iii,2); - ++iii; - - mInc2lab = new TQLabel ( "Local incidence", topFrame); - topLayout->addWidget(mInc2lab,iii,0); - mInc2Sumlab = new TQLabel ( "Local incidence summary", topFrame); - topLayout->addMultiCellWidget(mInc2Sumlab, iii,iii,1,2); - ++iii; - topLayout->addWidget( new TQLabel ( i18n("Last modified:"), topFrame) ,iii,0); - mMod2lab = new TQLabel ( "Set Last modified", topFrame); - topLayout->addWidget(mMod2lab,iii,1); - mShowDetails2 = new TQPushButton( i18n("Show Details"), topFrame); - connect ( mShowDetails2, TQT_SIGNAL( clicked()), this, TQT_SLOT (showIncidence2() ) ); - topLayout->addWidget(mShowDetails2,iii,2); - ++iii; - // -#if 0 - // commented out for now, because the diff code has too many bugs - mDiffBut = new TQPushButton( i18n("Show Differences"), topFrame ); - connect ( mDiffBut, TQT_SIGNAL( clicked()), this, TQT_SLOT ( showDiff() ) ); - topLayout->addMultiCellWidget(mDiffBut, iii,iii,0,2); - ++iii; -#else - mDiffBut = 0; -#endif - mBg = new TQButtonGroup ( 1, Qt::Horizontal, i18n("Sync Preferences"), topFrame); - topLayout->addMultiCellWidget(mBg, iii,iii,0,2); - ++iii; - mBg->insert( new TQRadioButton ( i18n("Take local entry on conflict"), mBg ), KIncidenceChooser::local); - mBg->insert( new TQRadioButton ( i18n("Take new (remote) entry on conflict"), mBg ), KIncidenceChooser::remote); - mBg->insert( new TQRadioButton ( i18n("Take newest entry on conflict"), mBg ), KIncidenceChooser::newest ); - mBg->insert( new TQRadioButton ( i18n("Ask for every entry on conflict"), mBg ),KIncidenceChooser::ask ); - mBg->insert( new TQRadioButton ( i18n("Take both on conflict"), mBg ), KIncidenceChooser::both ); - mBg->setButton ( chooseMode ); - mTbL = 0; - mTbN = 0; - mDisplayDiff = 0; - mSelIncidence = 0; - button = new TQPushButton( i18n("Apply This to All Conflicts of This Sync"), topFrame ); - connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT ( setSyncMode() ) ); - topLayout->addMultiCellWidget(button, iii,iii,0,2); -} - -KIncidenceChooser::~KIncidenceChooser() -{ - if ( mTbL ) delete mTbL; - if ( mTbN ) delete mTbN; - if ( mDisplayDiff ) { - delete mDisplayDiff; - delete diff; - } -} - -void KIncidenceChooser::setIncidence( KCal::Incidence* local ,KCal::Incidence* remote ) -{ - mInc1 = local; - mInc2 = remote; - setLabels(); - -} -KCal::Incidence* KIncidenceChooser::getIncidence( ) -{ - - KCal::Incidence* retval = mSelIncidence; - if ( chooseMode == KIncidenceChooser::local ) - retval = mInc1; - else if ( chooseMode == KIncidenceChooser::remote ) - retval = mInc2; - else if ( chooseMode == KIncidenceChooser::both ) { - retval = 0; - } - else if ( chooseMode == KIncidenceChooser::newest ) { - if ( mInc1->lastModified() == mInc2->lastModified()) - retval = 0; - if ( mInc1->lastModified() > mInc2->lastModified() ) - retval = mInc1; - else - retval = mInc2; - } - return retval; -} - -void KIncidenceChooser::setSyncMode() -{ - chooseMode = mBg->selectedId (); - if ( chooseMode != KIncidenceChooser::ask ) - TQDialog::accept(); - -} - -void KIncidenceChooser::useGlobalMode() -{ - if ( chooseMode != KIncidenceChooser::ask ) - TQDialog::reject(); -} - -void KIncidenceChooser::setLabels() -{ - KCal::Incidence* inc = mInc1; - TQLabel* des = mInc1lab; - TQLabel * sum = mInc1Sumlab; - - - if ( inc->type() == "Event" ) { - des->setText( i18n( "Local Event") ); - sum->setText( inc->summary().left( 30 )); - if ( mDiffBut ) - mDiffBut->setEnabled( true ); - } - else if ( inc->type() == "Todo" ) { - des->setText( i18n( "Local Todo") ); - sum->setText( inc->summary().left( 30 )); - if ( mDiffBut ) - mDiffBut->setEnabled( true ); - - } - else if ( inc->type() == "Journal" ) { - des->setText( i18n( "Local Journal") ); - sum->setText( inc->description().left( 30 )); - if ( mDiffBut ) - mDiffBut->setEnabled( false ); - } - mMod1lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() )); - inc = mInc2; - des = mInc2lab; - sum = mInc2Sumlab; - if ( inc->type() == "Event" ) { - des->setText( i18n( "New Event") ); - sum->setText( inc->summary().left( 30 )); - } - else if ( inc->type() == "Todo" ) { - des->setText( i18n( "New Todo") ); - sum->setText( inc->summary().left( 30 )); - - } - else if ( inc->type() == "Journal" ) { - des->setText( i18n( "New Journal") ); - sum->setText( inc->description().left( 30 )); - - } - mMod2lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() )); -} - -void KIncidenceChooser::showIncidence1() -{ - if ( mTbL ) { - if ( mTbL->isVisible() ) { - mShowDetails1->setText( i18n("Show Details")); - mTbL->hide(); - } else { - mShowDetails1->setText( i18n("Hide Details")); - mTbL->show(); - mTbL->raise(); - } - return; - } - mTbL = new KDialogBase( this, "", false /*not modal*/, mInc1lab->text(), KDialogBase::Ok ); - mTbL->setEscapeButton( KDialogBase::Ok ); - connect( mTbL, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( detailsDialogClosed() ) ); - TQTextBrowser* textBrowser = new TQTextBrowser( mTbL ); - mTbL->setMainWidget( textBrowser ); - textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc1 ) ); - mTbL->setMinimumSize( 400, 400 ); - mShowDetails1->setText( i18n("Hide Details")); - mTbL->show(); - mTbL->raise(); -} - -void KIncidenceChooser::detailsDialogClosed() -{ - KDialogBase* dialog = static_cast( TQT_TQWIDGET( const_cast(sender()) ) ); - if ( dialog == mTbL ) - mShowDetails1->setText( i18n( "Show details..." ) ); - else - mShowDetails2->setText( i18n( "Show details..." ) ); -} - -void KIncidenceChooser::showDiff() -{ - if ( mDisplayDiff ) { - mDisplayDiff->show(); - mDisplayDiff->raise(); - return; - } - mDisplayDiff = new KPIM::HTMLDiffAlgoDisplay (this); - if ( mInc1->summary().left( 20 ) != mInc2->summary().left( 20 ) ) - mDisplayDiff->setCaption( i18n( "Differences of %1 and %2").tqarg( mInc1->summary().left( 20 ) ).tqarg( mInc2->summary().left( 20 ) ) ); - else - mDisplayDiff->setCaption( i18n( "Differences of %1").tqarg( mInc1->summary().left( 20 ) ) ); - - diff = new KPIM::CalendarDiffAlgo( mInc1, mInc2); - diff->setLeftSourceTitle( i18n( "Local entry")); - diff->setRightSourceTitle(i18n( "New (remote) entry") ); - diff->addDisplay( mDisplayDiff ); - diff->run(); - mDisplayDiff->show(); - mDisplayDiff->raise(); -} - -void KIncidenceChooser::showIncidence2() -{ - if ( mTbN ) { - if ( mTbN->isVisible() ) { - mShowDetails2->setText( i18n("Show Details")); - mTbN->hide(); - } else { - mShowDetails2->setText( i18n("Hide Details")); - mTbN->show(); - mTbN->raise(); - } - return; - } - mTbN = new KDialogBase( this, "", false /*not modal*/, mInc2lab->text(), KDialogBase::Ok ); - mTbN->setEscapeButton( KDialogBase::Ok ); - connect( mTbN, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( detailsDialogClosed() ) ); - TQTextBrowser* textBrowser = new TQTextBrowser( mTbN ); - mTbN->setMainWidget( textBrowser ); - textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc2 ) ); - mTbN->setMinimumSize( 400, 400 ); - mShowDetails2->setText( i18n("Hide Details")); - mTbN->show(); - mTbN->raise(); -} - -void KIncidenceChooser::takeIncidence1() -{ - mSelIncidence = mInc1; - TQDialog::accept(); -} - -void KIncidenceChooser::takeIncidence2() -{ - mSelIncidence = mInc2; - TQDialog::accept(); -} - -void KIncidenceChooser::takeBoth() -{ - - mSelIncidence = 0; - TQDialog::accept(); -} - - -#include "kincidencechooser.moc" diff --git a/libkdepim/kincidencechooser.h b/libkdepim/kincidencechooser.h deleted file mode 100644 index 0d8107f05..000000000 --- a/libkdepim/kincidencechooser.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Lutz Rogowski - - 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. - - As a special exception, permission is given to link this program - with any edition of TQt, and distribute the resulting executable, - without including the source code for TQt in the source distribution. -*/ -#ifndef _KINCIDENCECHOOSER_H -#define _KINCIDENCECHOOSER_H - -#include "calendardiffalgo.h" -#include "htmldiffalgodisplay.h" - -#include - -namespace KCal { - class Incidence; -} -using namespace KCal; - -class TQButtonGroup; - -/** Dialog to change the korganizer configuration. - */ - -class KDE_EXPORT KIncidenceChooser : public KDialog -{ - Q_OBJECT - TQ_OBJECT - public: - enum mode { - local, remote, newest, ask, both - }; - /** Initialize dialog and pages */ - KIncidenceChooser( TQWidget *parent=0, char *name=0 ); - ~KIncidenceChooser(); - //void setChooseText( TQString ); - void setIncidence( KCal::Incidence *, KCal::Incidence * ); - KCal::Incidence *getIncidence(); - static int chooseMode; - - public slots: - void useGlobalMode(); - - protected slots: - void showIncidence1(); - void showIncidence2(); - void showDiff(); - void takeIncidence1(); - void takeIncidence2(); - void takeBoth(); - void setLabels(); - void setSyncMode(); - void detailsDialogClosed(); - - private: - KPIM::HTMLDiffAlgoDisplay *mDisplayDiff; - KPIM::CalendarDiffAlgo *diff; - KDialogBase *mTbL, *mTbN; - KCal::Incidence *mSelIncidence; - KCal::Incidence *mInc1, *mInc2; - TQButtonGroup *mBg; - TQPushButton *mDiffBut,*mShowDetails1,*mShowDetails2; - TQLabel *mInc1lab, *mInc2lab,* mInc1Sumlab, *mInc2Sumlab,*mMod1lab,*mMod2lab; - -}; - -#endif diff --git a/libkdepim/kmailcompletion.cpp b/libkdepim/kmailcompletion.cpp deleted file mode 100644 index d7fcc8ce4..000000000 --- a/libkdepim/kmailcompletion.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2006 Christian Schaarschmidt - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kmailcompletion.h" -#include - -#include - -using namespace KPIM; - -KMailCompletion::KMailCompletion() -{ - setIgnoreCase( true ); -} - -void KMailCompletion::clear() -{ - m_keyMap.clear(); - KCompletion::clear(); -} - -TQString KMailCompletion::makeCompletion( const TQString &string ) -{ - TQString match = KCompletion::makeCompletion( string ); - - // this should be in postProcessMatch, but postProcessMatch is const and will not allow nextMatch - if ( !match.isEmpty() ){ - const TQString firstMatch( match ); - while ( match.find( TQRegExp( "(@)|(<.*>)" ) ) == -1 ) { - /* local email do not require @domain part, if match is an address we'll find - * last+first in m_keyMap and we'll know that match is already a valid email. - * - * Distribution list do not have last+first entry, they will be in mailAddr - */ - const TQStringList &mailAddr = m_keyMap[ match ]; //get all mailAddr for this keyword - bool isEmail = false; - for ( TQStringList::ConstIterator sit ( mailAddr.begin() ), sEnd( mailAddr.end() ); sit != sEnd; ++sit ) - if ( (*sit).find( "<" + match + ">" ) != -1 || (*sit) == match ) { - isEmail = true; - break; - } - - if ( !isEmail ) { - // match is a keyword, skip it and try to find match - match = nextMatch(); - if ( firstMatch == match ){ - match = TQString(); - break; - } - } else - break; - } - } - return match; -} - -void KMailCompletion::addItemWithKeys( const TQString& email, int weight, const TQStringList* keyWords) -{ - Q_ASSERT( keyWords != 0 ); - for ( TQStringList::ConstIterator it( keyWords->begin() ); it != keyWords->end(); ++it ) { - TQStringList &emailList = m_keyMap[ (*it) ]; //lookup email-list for given keyword - if ( emailList.find( email ) == emailList.end() ) //add email if not there - emailList.append( email ); - addItem( (*it),weight ); //inform KCompletion about keyword - } -} - -void KMailCompletion::postProcessMatches( TQStringList * pMatches )const -{ - Q_ASSERT( pMatches != 0 ); - if ( pMatches->isEmpty() ) - return; - - //KCompletion has found the keywords for us, we can now map them to mail-addr - TQMap< TQString, bool > mailAddrDistinct; //TODO replace with TQSet in KDE4 - for ( TQStringList::ConstIterator sit ( pMatches->begin() ), sEnd( pMatches->end() ); sit != sEnd; ++sit ) { - const TQStringList &mailAddr = m_keyMap[ (*sit) ]; //get all mailAddr for this keyword - for ( TQStringList::ConstIterator sit ( mailAddr.begin() ), sEnd( mailAddr.end() ); sit != sEnd; ++sit ) { - mailAddrDistinct[ (*sit) ] = true; //store mailAddr, TQMap will make them unique - } - } - pMatches->clear(); //delete keywords - (*pMatches) += mailAddrDistinct.keys(); //add emailAddr -} -#include "kmailcompletion.moc" diff --git a/libkdepim/kmailcompletion.h b/libkdepim/kmailcompletion.h deleted file mode 100644 index 9251c2797..000000000 --- a/libkdepim/kmailcompletion.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2006 Christian Schaarschmidt - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPIM_KMAILCOMPLETION_H -#define KPIM_KMAILCOMPLETION_H - -#include -#include -#include "kcompletion.h" - - -namespace KPIM { - -/** - * KMailCompletion allows lookup of email addresses by keyword. - * Typically a keywods would be firstname, lastname, nickname or domain. - */ -class KMailCompletion : public KCompletion -{ - Q_OBJECT - TQ_OBJECT - - public: - KMailCompletion(); - - /** - * Clears internal keyword map and calls KCompletion::clear. - */ - virtual void clear(); - - /** - * Uses KCompletion::makeCompletion to find email addresses which starts with string. - * ignores keywords. - * - * @returns email address - */ - TQString makeCompletion( const TQString &string ); - - /** - * Specify keywords for email. - * - * Items may be added with KCompletion::addItem, those will only be returned as match if they - * are in one of these formats: - * \li contains localpart@domain - * \li contains - * or if they have also been added with this function. - */ - void addItemWithKeys( const TQString& email, int weight, const TQStringList * keyWords); - - /** - * Uses an internal map to replace all keywords in pMatches whith corrsesponding email addresses. - */ - virtual void postProcessMatches( TQStringList * pMatches )const; - - private: - TQMap< TQString, TQStringList > m_keyMap; -}; - -} - -#endif diff --git a/libkdepim/komposer/Makefile.am b/libkdepim/komposer/Makefile.am deleted file mode 100644 index 13509925e..000000000 --- a/libkdepim/komposer/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = core plugins test diff --git a/libkdepim/komposer/core/Makefile.am b/libkdepim/komposer/core/Makefile.am deleted file mode 100644 index b494e7151..000000000 --- a/libkdepim/komposer/core/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -AM_CPPFLAGS = -I$(top_builddir)/libtdepim $(all_includes) -METASOURCES = AUTO - -lib_LTLIBRARIES = libkomposer.la - -libkomposer_la_SOURCES = plugin.cpp editor.cpp core.cpp attachment.cpp corewidget.cpp \ - settings.kcfgc pluginmanager.cpp komposerIface.skel -libkomposer_la_LDFLAGS = -no-undefined $(KDE_RPATH) -version-info 1:0:0 $(all_libraries) -libkomposer_la_LIBADD = $(LIB_KPARTS) $(top_builddir)/libtdepim/libtdepim.la -lkutils - -#kde_module_LTLIBRARIES = kcm_komposer.la - -#kcm_komposer_la_SOURCES = prefsmodule.cpp -#kcm_komposer_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries) -#kcm_komposer_la_LIBADD = libkomposer.la $(top_builddir)/libtdepim/libtdepim.la $(LIB_KDECORE) - -kpincludedir = $(includedir)/komposer -kpinclude_HEADERS = plugin.h editor.h core.h - -rcdir = $(kde_datadir)/komposer -rc_DATA = komposerui.rc - -kde_kcfg_DATA = komposer.kcfg - -servicetypedir = $(kde_servicetypesdir) -servicetype_DATA = komposerplugin.desktop komposereditor.desktop - -kde_services_DATA = komposerconfig.desktop diff --git a/libkdepim/komposer/core/attachment.cpp b/libkdepim/komposer/core/attachment.cpp deleted file mode 100644 index df803de60..000000000 --- a/libkdepim/komposer/core/attachment.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * attachment.cpp - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include "attachment.h" - -using namespace Komposer; - -class Attachment::Private -{ -public: - TQString name; - TQCString cte; - TQByteArray data; - TQCString type; - TQCString subType; - TQCString paramAttr; - TQString paramValue; - TQCString contDisp; -}; - -Attachment::Attachment( const TQString &name, - const TQCString &cte, - const TQByteArray &data, - const TQCString &type, - const TQCString &subType, - const TQCString ¶mAttr, - const TQString ¶mValue, - const TQCString &contDisp ) - : d( new Private ) -{ - d->name = name; - d->cte = cte; - d->data = data; - d->type = type; - d->subType = subType; - d->paramAttr = paramAttr; - d->paramValue = paramValue; - d->contDisp = contDisp; -} - -Attachment::~Attachment() -{ - delete d; d = 0; -} - -TQString -Attachment::name() const -{ - return d->name; -} - -TQCString -Attachment::cte() const -{ - return d->cte; -} - -TQByteArray -Attachment::data() const -{ - return d->data; -} - -TQCString -Attachment::type() const -{ - return d->type; -} - - -TQCString -Attachment::subType() const -{ - return d->subType; -} - -TQCString -Attachment::paramAttr() const -{ - return d->paramAttr; -} - -TQString -Attachment::paramValue() const -{ - return d->paramValue; -} - -TQCString -Attachment::contentDisposition() const -{ - return d->contDisp; -} - diff --git a/libkdepim/komposer/core/attachment.h b/libkdepim/komposer/core/attachment.h deleted file mode 100644 index 5c4e1ebf2..000000000 --- a/libkdepim/komposer/core/attachment.h +++ /dev/null @@ -1,61 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * attachment.h - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef KOMPOSER_ATTACHMENT_H -#define KOMPOSER_ATTACHMENT_H - -#include -#include -#include - -namespace Komposer -{ - - class Attachment - { - public: - Attachment( const TQString &name, - const TQCString &cte, - const TQByteArray &data, - const TQCString &type, - const TQCString &subType, - const TQCString ¶mAttr, - const TQString ¶mValue, - const TQCString &contDisp ); - ~Attachment(); - - TQString name() const; - TQCString cte() const; - TQByteArray data() const; - TQCString type() const; - TQCString subType() const; - TQCString paramAttr() const; - TQString paramValue() const; - TQCString contentDisposition() const; - - private: - class Private; - Private *d; - }; - typedef TQValueList AttachmentList; -} - -#endif diff --git a/libkdepim/komposer/core/core.cpp b/libkdepim/komposer/core/core.cpp deleted file mode 100644 index f93e59cc9..000000000 --- a/libkdepim/komposer/core/core.cpp +++ /dev/null @@ -1,357 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * core.cpp - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "core.h" - -#include "pluginmanager.h" -#include "editor.h" -#include "plugin.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace Komposer; - -Core::Core( TQWidget *parent, const char *name ) - : KomposerIface( "KomposerIface" ), - KMainWindow( parent, name ), m_currentEditor( 0 ) -{ - initWidgets(); - initCore(); - initConnections(); - setInstance( new KInstance( "komposer" ) ); - - createActions(); - setXMLFile( "komposerui.rc" ); - - createGUI( 0 ); - - resize( 600, 400 ); // initial size - setAutoSaveSettings(); - - loadSettings(); -} - -Core::~Core() -{ - saveSettings(); - - //Prefs::self()->writeConfig(); -} - -void -Core::addEditor( Komposer::Editor *editor ) -{ - if ( editor->widget() ) { - m_stack->addWidget( editor->widget() ); - m_stack->raiseWidget( editor->widget() ); - editor->widget()->show(); - m_currentEditor = editor; - } - - // merge the editors GUI into the main window - //insertChildClient( editor ); - guiFactory()->addClient( editor ); -} - -void -Core::addPlugin( Komposer::Plugin *plugin ) -{ - //insertChildClient( plugin ); - guiFactory()->addClient( plugin ); -} - -void -Core::slotPluginLoaded( Plugin *plugin ) -{ - kdDebug() << "Plugin loaded "<( plugin ); - if ( editor ) { - addEditor( editor ); - } else { - addPlugin( plugin ); - } -} - -void -Core::slotAllPluginsLoaded() -{ - TQValueList plugins = m_pluginManager->availablePlugins(); - kdDebug()<<"Number of available plugins is "<< plugins.count() <::iterator it = plugins.begin(); it != plugins.end(); ++it ) { - KPluginInfo *i = ( *it ); - kdDebug()<<"\tAvailable plugin "<< i->pluginName() - <<", comment = "<< i->comment() <visibleWidget() ) { - m_pluginManager->loadPlugin( "komposer_defaulteditor", PluginManager::LoadAsync ); - } -} - -#if 0 -void -Core::slotActivePartChanged( KParts::Part *part ) -{ - if ( !part ) { - createGUI( 0 ); - return; - } - - kdDebug() << "Part activated: " << part << " with stack id. " - << m_stack->id( part->widget() )<< endl; - - createGUI( part ); -} - -void -Core::selectEditor( Komposer::Editor *editor ) -{ - if ( !editor ) - return; - - KParts::Part *part = editor->part(); - - editor->select(); - - TQPtrList *partList = const_cast*>( - m_partManager->parts() ); - if ( partList->find( part ) == -1 ) - addPart( part ); - - m_partManager->setActivePart( part ); - TQWidget *view = part->widget(); - Q_ASSERT( view ); - - kdDebug()<<"Raising view "<raiseWidget( view ); - view->show(); - view->setFocus(); - m_currentEditor = editor; - } -} - -void -Core::selectEditor( const TQString &editorName ) -{ - -} -#endif - -void -Core::loadSettings() -{ - //kdDebug()<<"Trying to select "<< Prefs::self()->m_activeEditor <m_activeEditor ); - - //m_activeEditors = Prefs::self()->m_activeEditors; -} - -void -Core::saveSettings() -{ - //if ( m_currentEditor ) - //Prefs::self()->m_activeEditor = m_currentEditor->identifier(); -} - -void -Core::slotQuit() -{ - kdDebug()<<"exit"<shutdown(); -} - -void -Core::slotPreferences() -{ - if ( m_dlg == 0 ) - m_dlg = new KSettings::Dialog( this ); - m_dlg->show(); -} - -void -Core::initWidgets() -{ - statusBar()->show(); - TQHBox *topWidget = new TQHBox( this ); - setCentralWidget( topWidget ); - m_stack = new TQWidgetStack( topWidget ); -} - -void -Core::initCore() -{ - m_pluginManager = new PluginManager( this ); - connect( m_pluginManager, TQT_SIGNAL(pluginLoaded(Plugin*)), - TQT_SLOT(slotPluginLoaded(Plugin*)) ); - connect( m_pluginManager, TQT_SIGNAL(allPluginsLoaded()), - TQT_SLOT(slotAllPluginsLoaded()) ); - - - m_pluginManager->loadAllPlugins(); - kdDebug()<<"Loading"<setText( body ); -} - -void -Core::addAttachment( const TQString &name, - const TQCString &cte, - const TQByteArray &data, - const TQCString &type, - const TQCString &subType, - const TQCString ¶mAttr, - const TQString ¶mValue, - const TQCString &contDisp ) -{ - -} - -#include "core.moc" diff --git a/libkdepim/komposer/core/core.h b/libkdepim/komposer/core/core.h deleted file mode 100644 index 91487572a..000000000 --- a/libkdepim/komposer/core/core.h +++ /dev/null @@ -1,108 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * core.h - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef KOMPOSER_CORE_H -#define KOMPOSER_CORE_H - -#include "komposerIface.h" - -#include -#include - -namespace KSettings { - class Dialog; -} -class TQWidgetStack; - -namespace Komposer -{ - - class Editor; - class Plugin; - class PluginManager; - - /** - * This class provides the interface to the Komposer core for the editor. - */ - class Core : public KMainWindow, virtual public KomposerIface - { - Q_OBJECT - TQ_OBJECT - public: - Core( TQWidget *parentWidget = 0, const char *name = 0 ); - virtual ~Core(); - - public slots: - virtual void send( int how ); - virtual void addAttachment( const KURL &url, const TQString &comment ); - virtual void setBody( const TQString &body ); - virtual void addAttachment( const TQString &name, - const TQCString &cte, - const TQByteArray &data, - const TQCString &type, - const TQCString &subType, - const TQCString ¶mAttr, - const TQString ¶mValue, - const TQCString &contDisp ); - - - - protected slots: - //void slotActivePartChanged( KParts::Part *part ); - void slotPluginLoaded( Plugin* ); - void slotAllPluginsLoaded(); - void slotPreferences(); - void slotQuit(); - void slotClose(); - - void slotSendNow(); - void slotSendLater(); - void slotSaveDraft(); - void slotInsertFile(); - void slotAddrBook(); - void slotNewComposer(); - void slotAttachFile(); - - protected: - virtual void initWidgets(); - void initCore(); - void initConnections(); - void loadSettings(); - void saveSettings(); - void createActions(); - - void addEditor( Komposer::Editor *editor ); - void addPlugin( Komposer::Plugin *plugin ); - - private: - TQWidgetStack *m_stack; - Editor *m_currentEditor; - PluginManager *m_pluginManager; - - KSettings::Dialog *m_dlg; - - class Private; - Private *d; -}; - -} - -#endif diff --git a/libkdepim/komposer/core/corewidget.cpp b/libkdepim/komposer/core/corewidget.cpp deleted file mode 100644 index c65893766..000000000 --- a/libkdepim/komposer/core/corewidget.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * corewidget.cpp - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "corewidget.h" - -using namespace Komposer; - -CoreWidget::CoreWidget( TQWidget *parent, const char *name ) - : TQWidget( parent, name ) -{ -} - -#include "corewidget.moc" diff --git a/libkdepim/komposer/core/corewidget.h b/libkdepim/komposer/core/corewidget.h deleted file mode 100644 index 7d2acc6db..000000000 --- a/libkdepim/komposer/core/corewidget.h +++ /dev/null @@ -1,49 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * corewidget.h - * - * Copyright (C) 2003-2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef COREWIDGET_H -#define COREWIDGET_H - -#include "attachment.h" - -#include - -namespace Komposer -{ - - class CoreWidget : public TQWidget - { - Q_OBJECT - TQ_OBJECT - public: - CoreWidget( TQWidget *parent, const char *name=0 ); - - virtual TQString subject() const =0; - virtual TQStringList to() const =0; - virtual TQStringList cc() const =0; - virtual TQStringList bcc() const =0; - virtual TQString from() const =0; - virtual TQString replyTo() const =0; - virtual AttachmentList attachments() const =0; - }; -} - -#endif diff --git a/libkdepim/komposer/core/editor.cpp b/libkdepim/komposer/core/editor.cpp deleted file mode 100644 index 5dada393f..000000000 --- a/libkdepim/komposer/core/editor.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * editor.cpp - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "editor.h" -#include "core.h" - -namespace Komposer { - -class Editor::Private { -public: - TQString id; -}; - -Editor::Editor( TQObject *parent, const char *name, const TQStringList &args ) - : Plugin( parent, name, args ), d( new Private ) -{ -} - -Editor::~Editor() -{ - delete d; d = 0; -} - -void -Editor::select() -{ -} - - -} - -#include "editor.moc" diff --git a/libkdepim/komposer/core/editor.h b/libkdepim/komposer/core/editor.h deleted file mode 100644 index cdc05710d..000000000 --- a/libkdepim/komposer/core/editor.h +++ /dev/null @@ -1,105 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * editor.h - * - * Copyright (C) 2003-2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef KOMPOSER_EDITOR_H -#define KOMPOSER_EDITOR_H - -#include "plugin.h" - -#include - -namespace KParts { - class Part; -} - -namespace Komposer { - - class Core; - - class Editor : public Plugin - { - Q_OBJECT - TQ_OBJECT - public: - enum TextType { - Plain = 1 << 0, - RichText = 1 << 1, - HTML = 1 << 2 - }; - virtual ~Editor(); - - /** - * This is the magic function that all derivatives have to reimplement. - * It returns the actual editor component. - */ - virtual TQWidget *widget() =0; - - int supportedTextFormats() const; - - /** - * Returns the full text inside the editor. - */ - virtual TQString text() const =0; - - /** - * This function is called when the plugin is selected by the user before the - * widget of the KPart belonging to the plugin is raised. - */ - virtual void select(); - - /** - * Reimplement this method and return a @ref TQStringList of all config - * modules your application part should offer via Komposer. Note that the - * part and the module will have to take care for config syncing themselves. - * Usually @p DCOP used for that purpose. - * - * @note Make sure you offer the modules in the form: - * "pathrelativetosettings/mysettings.desktop" - */ - virtual TQStringList configModules() const { return TQStringList(); } - - - public slots: - /** - * Sets the text of the opened editor. - * Most commonly used on replaying. - * If any text is present if will be deleted. - */ - virtual void setText( const TQString &txt ) =0; - - /** - * Changes currently used signature. If no signature is present - * a new one should be appened. - */ - virtual void changeSignature( const TQString &txt ) =0; - - protected: - Editor( TQObject *parent, const char *name, const TQStringList &args ); - - private: - class Private; - Private *d; - }; - -} - -#endif diff --git a/libkdepim/komposer/core/komposer.kcfg b/libkdepim/komposer/core/komposer.kcfg deleted file mode 100644 index 111584b88..000000000 --- a/libkdepim/komposer/core/komposer.kcfg +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - #ff0000 - #00ff00 - #0000ff - #ffff00 - - - - - diff --git a/libkdepim/komposer/core/komposerIface.h b/libkdepim/komposer/core/komposerIface.h deleted file mode 100644 index eecab2f3a..000000000 --- a/libkdepim/komposer/core/komposerIface.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * komposerIface.h - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef KOMPOSERIFACE_H -#define KOMPOSERIFACE_H - -#include -#include - -namespace Komposer -{ - -/** - DCOP interface for mail composer window. The address header fields are set, - when the composer is constructed. KMailIface::openComposer() returns a - reference to the DCOP interface of the new composer window, which provides the - functions defined in the MailComposerIface. -*/ -class KomposerIface : virtual public DCOPObject -{ - K_DCOP -k_dcop: - /** - Send message. - - @param how 0 for deafult method, 1 for sending now, 2 for sending later. - */ - virtual void send(int how) = 0; - - /** - Add url as attachment with a user-defined comment. - */ - virtual void addAttachment( const KURL &url, const TQString &comment) = 0; - - /** - Set message body. - */ - virtual void setBody( const TQString &body ) = 0; - - /** - Add attachment. - - @param name Name of Attachment - @param cte Content Transfer Encoding - @param data Data to be attached - @param type MIME content type - @param subType MIME content sub type - @param paramAttr Attribute name of parameter of content type - @param paramValue Value of parameter of content type - @param contDisp Content disposition - */ - virtual void addAttachment( const TQString &name, - const TQCString &cte, - const TQByteArray &data, - const TQCString &type, - const TQCString &subType, - const TQCString ¶mAttr, - const TQString ¶mValue, - const TQCString &contDisp ) = 0; -public: - KomposerIface( const char *name ) - : DCOPObject( name ) - {} -}; - -} - -#endif diff --git a/libkdepim/komposer/core/komposerconfig.desktop b/libkdepim/komposer/core/komposerconfig.desktop deleted file mode 100644 index 58c8bd765..000000000 --- a/libkdepim/komposer/core/komposerconfig.desktop +++ /dev/null @@ -1,56 +0,0 @@ -[Desktop Entry] -Exec=kcmshell komposerconfig -Icon=komposer -Type=Application -Terminal=false - -X-KDE-ModuleType=Library -X-KDE-Library=komposer -X-KDE-FactoryName=komposerconfig -X-KDE-HasReadOnlyMode=false - -Name=Komposer -Name[cy]=Kyfansoddydd -Name[da]=Brevskriver -Name[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° -Name[ms]=Penggubah -Name[ne]=कमà¥à¤ªà¥‹à¤œà¤° -Name[pt]=Kompositor -Name[ta]=கமà¯à®ªà¯‹à®šà®°à¯ -Comment=KDE Komposer -Comment[bg]=ПиÑане на форматиран текÑÑ‚ -Comment[br]=Komposer KDE -Comment[ca]=Compositor per a KDE -Comment[cy]=Cyfansoddydd KDE -Comment[da]=KDE Brevskriver -Comment[de]=KDE-Komposer -Comment[fr]=Komposer KDE -Comment[ga]=Komposer KDE -Comment[hi]=केडीई कमà¥à¤ªà¥‹à¤œà¤¼à¤° -Comment[ms]=Penggubah KDE -Comment[nds]=Nettbreef-Editor vun KDE -Comment[ne]=केडीई कमà¥à¤ªà¥‹à¤œà¤° -Comment[nn]=KDE, tekstredigerar for e-post -Comment[pl]=Komposer dla KDE -Comment[pt]=Kompositor do KDE -Comment[pt_BR]=Konposer do KDE -Comment[ru]=Композитор KDE -Comment[ta]=கேடிஇ கமà¯à®ªà¯‹à®šà®°à¯ -Comment[tg]=Композитори KDE -Keywords=komposer -Keywords[bg]=редактор, ÑÑŠÑтавител, форматиране, текÑÑ‚, komposer -Keywords[ca]=compositor -Keywords[cy]=komposer,kyfansoddydd -Keywords[da]=brevskriver -Keywords[de]=Komposer -Keywords[fy]=komposer,opstellen, opsteller -Keywords[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° -Keywords[nds]=Komposer -Keywords[ne]=कमà¥à¤ªà¥‹à¤œà¤° -Keywords[nl]=komposer,opstellen -Keywords[nn]=komposer,tekstredigerar,epost -Keywords[ru]=komposer,ноты -Keywords[sr]=komposer,ÑаÑтављач -Keywords[sr@Latn]=komposer,sastavljaÄ -Keywords[ta]=கமà¯à®ªà¯‹à®šà®°à¯ -Keywords[tg]=komposer,нотаҳо diff --git a/libkdepim/komposer/core/komposereditor.desktop b/libkdepim/komposer/core/komposereditor.desktop deleted file mode 100644 index fd1c1341e..000000000 --- a/libkdepim/komposer/core/komposereditor.desktop +++ /dev/null @@ -1,56 +0,0 @@ -[Desktop Entry] -Type=ServiceType -X-KDE-ServiceType=Komposer/Editor -X-KDE-Derived=Komposer/Plugin -Comment=Komposer Editor -Comment[af]=Komposer Redigeerder -Comment[bg]=ПиÑане на форматиран текÑÑ‚ -Comment[br]=Aozer Komposer -Comment[bs]=Komposer editor -Comment[ca]=Compositor per a KDE -Comment[cs]=Komposer editor -Comment[da]=Komposer editor -Comment[el]=ΕπεξεÏγαστής Komposer -Comment[eo]=Komposer-redaktilo -Comment[es]=Editor Komposer -Comment[et]=Komposeri redaktor -Comment[eu]=Komposer editorea -Comment[fa]=ویرایشگر Komposer -Comment[fi]=Komposer-muokkain -Comment[fr]=Éditeur Komposer -Comment[fy]=Komposer-bewurker -Comment[ga]=Eagarthóir Komposer -Comment[gl]=Editor Komposer -Comment[he]=עורך של Komposer -Comment[hu]=Komposer -Comment[is]=Komposer ritill -Comment[it]=Komposer editor -Comment[ja]=Komposer,エディタ -Comment[kk]=Komposer өңдегіші -Comment[km]=កម្មវិធី​និពន្ធ Komposer -Comment[ko]=Komposer 편집기 -Comment[lt]=Komposer redaktorius -Comment[ms]=Editor Komposer -Comment[nb]=Komposer redigerer -Comment[nds]=Komposer-Editor -Comment[ne]=कमà¥à¤ªà¥‹à¤œà¤° समà¥à¤ªà¤¾à¤¦à¤• -Comment[nl]=Komposer-editor -Comment[nn]=Komposer redigerar -Comment[pl]=Edytor Komposer -Comment[pt]=Editor Kompositor -Comment[pt_BR]=Editor de Mensagens -Comment[ru]=Редактор Komposer -Comment[sk]=Editor Komposer -Comment[sl]=Urejevalnik Komposer -Comment[sr]=Уређивач Komposer -Comment[sr@Latn]=UreÄ‘ivaÄ Komposer -Comment[sv]=Komposer editor -Comment[ta]=கமà¯à®ªà¯‹à®šà®°à¯ தொகà¯à®ªà¯à®ªà®¾à®©à¯ -Comment[tg]=Муҳаррири Komposer -Comment[tr]=Komposer Düzenleyicisi -Comment[uk]=Редактор Komposer -Comment[zh_CN]=Komposer 编辑器 -Comment[zh_TW]=Komposer 編輯器 - -[PropertyDef::X-Komposer-Weight] -Type=int diff --git a/libkdepim/komposer/core/komposerplugin.desktop b/libkdepim/komposer/core/komposerplugin.desktop deleted file mode 100644 index b398e1c67..000000000 --- a/libkdepim/komposer/core/komposerplugin.desktop +++ /dev/null @@ -1,59 +0,0 @@ -[Desktop Entry] -Type=ServiceType -X-KDE-ServiceType=Komposer/Plugin -X-KDE-Derived=KPluginInfo -Name=Komposer Plugin -Name[af]=Komposer inprop module -Name[bg]=ПриÑтавка за Komposer -Name[br]=Lugent Komposer -Name[bs]=Komposer dodatak -Name[ca]=Endollable Komposer -Name[cs]=Komposer modul -Name[cy]=Ategyn Kyfansoddydd -Name[da]=Brevskriver-plugin -Name[de]=Komposer-Modul -Name[el]=ΠÏόσθετο του Komposer -Name[eo]=Komposer-kromaĵo -Name[es]=Accesorio Komposer -Name[et]=Komposeri plugin -Name[eu]=Komposer plugin-a -Name[fa]=وصلۀ Komposer -Name[fi]=Komposer-liitännäinen -Name[fr]=Module de Komposer -Name[fy]=Komposer-plugin -Name[ga]=Breiseán Komposer -Name[gl]=Extensión Komposer -Name[he]=תןסף Kompoer -Name[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° पà¥à¤²à¤—इन -Name[hu]=Komposer bÅ‘vítÅ‘modul -Name[is]=Komposer íforrit -Name[it]=Plugin Komposer -Name[ja]=Komposer プラグイン -Name[kk]=Komposer плагин модулі -Name[km]=កម្មវិធី​ជំនួយ Komposer -Name[ko]=Komposer í”ŒëŸ¬ê·¸ì¸ -Name[lt]=Komposer priedas -Name[ms]=Plugin Komposer -Name[nb]=Komposer-programtillegg -Name[nds]=Komposer-Moduul -Name[ne]=कमà¥à¤ªà¥‹à¤œà¤° पà¥à¤²à¤—इन -Name[nn]=Komposer-programtillegg -Name[pl]=Wtyczka Komposer -Name[pt]='Plugin' do Kompositor -Name[pt_BR]=Plug-in do Komposer -Name[ro]=Modul Komposer -Name[ru]=Модуль Komposer -Name[sk]=Modul Komposer -Name[sl]=Vstavek za Komposer -Name[sr]=Прикључак Komposer-а -Name[sr@Latn]=PrikljuÄak Komposer-a -Name[sv]=Komposer-insticksprogram -Name[ta]=கமà¯à®ªà¯‹à®šà®°à¯ சொரà¯à®•à¯à®ªà¯à®ªà¯Šà®°à¯à®³à¯ -Name[tg]=Модули Komposer -Name[tr]=Komposer Eklentisi -Name[uk]=Втулок Komposer -Name[zh_CN]=Komposer æ’件 -Name[zh_TW]=Komposer å¤–æŽ›ç¨‹å¼ - -[PropertyDef::X-Komposer-Version] -Type=int diff --git a/libkdepim/komposer/core/komposerui.rc b/libkdepim/komposer/core/komposerui.rc deleted file mode 100644 index 83ec4d299..000000000 --- a/libkdepim/komposer/core/komposerui.rc +++ /dev/null @@ -1,51 +0,0 @@ - - - - - &Message - - - - - - - - - - - - - - - - - &Attach - - - - - - - - &Tools - - - - - &Settings - - - - - -Main Toolbar - - - - - - - - - - diff --git a/libkdepim/komposer/core/plugin.cpp b/libkdepim/komposer/core/plugin.cpp deleted file mode 100644 index 41af47cd9..000000000 --- a/libkdepim/komposer/core/plugin.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * plugin.cpp - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include "plugin.h" - -#include "core.h" - -#include -#include - -namespace Komposer -{ - -class Plugin::Private -{ -public: - //Core* core; -}; - -Plugin::Plugin( TQObject *parent, const char *name, const TQStringList & ) - : TQObject( parent, name ), d( new Private ) -{ - //d->core = core; -} - -Plugin::~Plugin() -{ - delete d; d = 0; -} - -void -Plugin::startedComposing() -{ -} - -void -Plugin::sendClicked() -{ -} - -void -Plugin::quitClicked() -{ -} - -void -Plugin::aboutToUnload() -{ - kdDebug()<<"plugin unloading"<core; -} - -}//end namespace Komposer - -#include "plugin.moc" diff --git a/libkdepim/komposer/core/plugin.h b/libkdepim/komposer/core/plugin.h deleted file mode 100644 index 7acd7f70f..000000000 --- a/libkdepim/komposer/core/plugin.h +++ /dev/null @@ -1,76 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * plugin.h - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef KOMPOSER_PLUGIN_H -#define KOMPOSER_PLUGIN_H - -#include -#include - -namespace Komposer -{ - class Core; - - class Plugin : public TQObject, - virtual public KXMLGUIClient - { - Q_OBJECT - TQ_OBJECT - public: - virtual ~Plugin(); - - signals: - void statusMessage( const TQString & ); - void readyForUnload(); - - protected slots: - /** - * Called when a new message is created. - */ - virtual void startedComposing(); - - /** - * Called after the send button has been pressed - * and before the message has been sent. - */ - virtual void sendClicked(); - - /** - * Called after the quit button has been pressed - */ - virtual void quitClicked(); - - virtual void aboutToUnload(); - - protected: - Core *core() const; - protected: - friend class PluginManager; - Plugin( TQObject *parent, const char *name, const TQStringList& args = TQStringList() ); - - private: - class Private; - Private *d; - }; - -} - -#endif diff --git a/libkdepim/komposer/core/pluginmanager.cpp b/libkdepim/komposer/core/pluginmanager.cpp deleted file mode 100644 index dcfea6f4b..000000000 --- a/libkdepim/komposer/core/pluginmanager.cpp +++ /dev/null @@ -1,489 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- -/** - * pluginmanager.cpp - * Most of this code has been lifted from Martijn's KopetePluginManager class - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include "pluginmanager.h" - -#include "plugin.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace Komposer -{ - -class PluginManager::Private -{ -public: - // All available plugins, regardless of category, and loaded or not - TQValueList plugins; - - // Dict of all currently loaded plugins, mapping the KPluginInfo to - // a plugin - TQMap loadedPlugins; - - // The plugin manager's mode. The mode is StartingUp until loadAllPlugins() - // has finished loading the plugins, after which it is set to Running. - // ShuttingDown and DoneShutdown are used during Komposer shutdown by the - // async unloading of plugins. - enum ShutdownMode { StartingUp, Running, ShuttingDown, DoneShutdown }; - ShutdownMode shutdownMode; - - KSharedConfig::Ptr config; - // Plugins pending for loading - TQValueStack pluginsToLoad; -}; - -PluginManager::PluginManager( TQObject *parent ) - : TQObject( parent ) -{ - d = new Private; - - // We want to add a reference to the application's event loop so we - // can remain in control when all windows are removed. - // This way we can unload plugins asynchronously, which is more - // robust if they are still doing processing. - kapp->ref(); - d->shutdownMode = Private::StartingUp; - - KSettings::Dispatcher::self()->registerInstance( KGlobal::instance(), - this, TQT_SLOT( loadAllPlugins() ) ); - - d->plugins = KPluginInfo::fromServices( - KTrader::self()->query( TQString::tqfromLatin1( "Komposer/Plugin" ), - TQString::tqfromLatin1( "[X-Komposer-Version] == 1" ) ) ); -} - -PluginManager::~PluginManager() -{ - if ( d->shutdownMode != Private::DoneShutdown ) { - slotShutdownTimeout(); -#if 0 - kdWarning() << k_funcinfo - << "Destructing plugin manager without going through " - << "the shutdown process!" - << endl - << kdBacktrace(10) << endl; -#endif - } - - // Quick cleanup of the remaining plugins, hope it helps - TQMap::ConstIterator it; - for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); /* EMPTY */ ) - { - // Remove causes the iterator to become invalid, so pre-increment first - TQMap::ConstIterator nextIt( it ); - ++nextIt; - kdWarning() << k_funcinfo << "Deleting stale plugin '" - << it.data()->name() << "'" << endl; - delete it.data(); - it = nextIt; - } - - delete d; -} - -TQValueList -PluginManager::availablePlugins( const TQString &category ) const -{ - if ( category.isEmpty() ) - return d->plugins; - - TQValueList result; - TQValueList::ConstIterator it; - for ( it = d->plugins.begin(); it != d->plugins.end(); ++it ) - { - if ( ( *it )->category() == category ) - result.append( *it ); - } - - return result; -} - -TQMap -PluginManager::loadedPlugins( const TQString &category ) const -{ - TQMap result; - TQMap::ConstIterator it; - for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) - { - if ( category.isEmpty() || it.key()->category() == category ) - result.insert( it.key(), it.data() ); - } - - return result; -} - -void -PluginManager::shutdown() -{ - d->shutdownMode = Private::ShuttingDown; - - // Remove any pending plugins to load, we're shutting down now :) - d->pluginsToLoad.clear(); - - // Ask all plugins to unload - if ( d->loadedPlugins.empty() ) { - d->shutdownMode = Private::DoneShutdown; - } else { - TQMap::ConstIterator it; - for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); /* EMPTY */ ) - { - // Remove causes the iterator to become invalid, so pre-increment first - TQMap::ConstIterator nextIt( it ); - ++nextIt; - it.data()->aboutToUnload(); - it = nextIt; - } - } - - TQTimer::singleShot( 3000, this, TQT_SLOT(slotShutdownTimeout()) ); -} - -void -PluginManager::slotPluginReadyForUnload() -{ - // Using TQObject::sender() is on purpose here, because otherwise all - // plugins would have to pass 'this' as parameter, which makes the API - // less clean for plugin authors - Plugin* plugin = dynamic_cast( const_cast( sender() ) ); - if ( !plugin ) - { - kdWarning() << k_funcinfo << "Calling object is not a plugin!" << endl; - return; - - } - kdDebug()<<"manager unloading"<deleteLater(); -} - -void -PluginManager::slotShutdownTimeout() -{ - // When we were already done the timer might still fire. - // Do nothing in that case. - if ( d->shutdownMode == Private::DoneShutdown ) - return; - -#ifndef NDEBUG - TQStringList remaining; - for ( TQMap::ConstIterator it = d->loadedPlugins.begin(); - it != d->loadedPlugins.end(); ++it ) - remaining.append( it.key()->pluginName() ); - - kdWarning() << k_funcinfo << "Some plugins didn't shutdown in time!" << endl - << "Remaining plugins: " - << remaining.join( TQString::tqfromLatin1( ", " ) ) << endl - << "Forcing Komposer shutdown now." << endl; -#endif - - slotShutdownDone(); -} - -void -PluginManager::slotShutdownDone() -{ - d->shutdownMode = Private::DoneShutdown; - - kapp->deref(); -} - -void -PluginManager::loadAllPlugins() -{ - // FIXME: We need session management here - Martijn - - if ( !d->config ) - d->config = KSharedConfig::openConfig( "komposerrc" ); - - TQMap entries = d->config->entryMap( - TQString::tqfromLatin1( "Plugins" ) ); - - TQMap::Iterator it; - for ( it = entries.begin(); it != entries.end(); ++it ) - { - TQString key = it.key(); - if ( key.endsWith( TQString::tqfromLatin1( "Enabled" ) ) ) - { - key.setLength( key.length() - 7 ); - //kdDebug() << k_funcinfo << "Set " << key << " to " << it.data() << endl; - - if ( it.data() == TQString::tqfromLatin1( "true" ) ) - { - if ( !plugin( key ) ) - d->pluginsToLoad.push( key ); - } - else - { - // FIXME: Does this ever happen? As loadAllPlugins is only called on startup - // I'd say 'no'. If it does, it should be made async - // though. - Martijn - if ( plugin( key ) ) - unloadPlugin( key ); - } - } - } - - // Schedule the plugins to load - TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); -} - -void PluginManager::slotLoadNextPlugin() -{ - if ( d->pluginsToLoad.isEmpty() ) - { - if ( d->shutdownMode == Private::StartingUp ) - { - d->shutdownMode = Private::Running; - emit allPluginsLoaded(); - } - return; - } - - TQString key = d->pluginsToLoad.pop(); - loadPluginInternal( key ); - - // Schedule the next run unconditionally to avoid code duplication on the - // allPluginsLoaded() signal's handling. This has the added benefit that - // the signal is delayed one event loop, so the accounts are more likely - // to be instantiated. - TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); -} - -Plugin* -PluginManager::loadPlugin( const TQString &pluginId, - PluginLoadMode mode /* = LoadSync */ ) -{ - if ( mode == LoadSync ) { - return loadPluginInternal( pluginId ); - } else { - d->pluginsToLoad.push( pluginId ); - TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); - return 0; - } -} - -Plugin* -PluginManager::loadPluginInternal( const TQString &pluginId ) -{ - KPluginInfo* info = infoForPluginId( pluginId ); - if ( !info ) { - kdWarning() << k_funcinfo << "Unable to find a plugin named '" - << pluginId << "'!" << endl; - return 0; - } - - if ( d->loadedPlugins.contains( info ) ) - return d->loadedPlugins[ info ]; - - int error = 0; - Plugin *plugin = KParts::ComponentFactory::createInstanceFromQuery( - TQString::tqfromLatin1( "Komposer/Plugin" ), - TQString::tqfromLatin1( "[X-KDE-PluginInfo-Name]=='%1'" ).tqarg( pluginId ), - this, 0, TQStringList(), &error ); - - if ( plugin ) { - d->loadedPlugins.insert( info, plugin ); - info->setPluginEnabled( true ); - - connect( plugin, TQT_SIGNAL(destroyed(TQObject*)), - this, TQT_SLOT(slotPluginDestroyed(TQObject*)) ); - connect( plugin, TQT_SIGNAL(readyForUnload()), - this, TQT_SLOT(slotPluginReadyForUnload()) ); - - kdDebug() << k_funcinfo << "Successfully loaded plugin '" - << pluginId << "'" << endl; - - emit pluginLoaded( plugin ); - } else { - switch ( error ) { - case KParts::ComponentFactory::ErrNoServiceFound: - kdDebug() << k_funcinfo << "No service implementing the given mimetype " - << "and fullfilling the given constraint expression can be found." - << endl; - break; - - case KParts::ComponentFactory::ErrServiceProvidesNoLibrary: - kdDebug() << "the specified service provides no shared library." << endl; - break; - - case KParts::ComponentFactory::ErrNoLibrary: - kdDebug() << "the specified library could not be loaded." << endl; - break; - - case KParts::ComponentFactory::ErrNoFactory: - kdDebug() << "the library does not export a factory for creating components." - << endl; - break; - - case KParts::ComponentFactory::ErrNoComponent: - kdDebug() << "the factory does not support creating components " - << "of the specified type." - << endl; - break; - } - - kdDebug() << k_funcinfo << "Loading plugin '" << pluginId - << "' failed, KLibLoader reported error: '" - << KLibLoader::self()->lastErrorMessage() - << "'" << endl; - } - - return plugin; -} - -bool -PluginManager::unloadPlugin( const TQString &spec ) -{ - TQMap::ConstIterator it; - for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) - { - if ( it.key()->pluginName() == spec ) - { - it.data()->aboutToUnload(); - return true; - } - } - - return false; -} - -void -PluginManager::slotPluginDestroyed( TQObject *plugin ) -{ - TQMap::Iterator it; - for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) - { - if ( it.data() == plugin ) - { - d->loadedPlugins.erase( it ); - break; - } - } - - if ( d->shutdownMode == Private::ShuttingDown && d->loadedPlugins.isEmpty() ) - { - // Use a timer to make sure any pending deleteLater() calls have - // been handled first - TQTimer::singleShot( 0, this, TQT_SLOT(slotShutdownDone()) ); - } -} - -Plugin* -PluginManager::plugin( const TQString &pluginId ) const -{ - KPluginInfo *info = infoForPluginId( pluginId ); - if ( !info ) - return 0; - - if ( d->loadedPlugins.contains( info ) ) - return d->loadedPlugins[ info ]; - else - return 0; -} - -TQString -PluginManager::pluginName( const Plugin *plugin ) const -{ - TQMap::ConstIterator it; - for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) - { - if ( it.data() == plugin ) - return it.key()->name(); - } - - return TQString::tqfromLatin1( "Unknown" ); -} - -TQString -PluginManager::pluginId( const Plugin *plugin ) const -{ - TQMap::ConstIterator it; - for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) - { - if ( it.data() == plugin ) - return it.key()->pluginName(); - } - - return TQString::tqfromLatin1( "unknown" ); -} - -TQString -PluginManager::pluginIcon( const Plugin *plugin ) const -{ - TQMap::ConstIterator it; - for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) - { - if ( it.data() == plugin ) - return it.key()->icon(); - } - - return TQString::tqfromLatin1( "Unknown" ); -} - -KPluginInfo* -PluginManager::infoForPluginId( const TQString &pluginId ) const -{ - TQValueList::ConstIterator it; - for ( it = d->plugins.begin(); it != d->plugins.end(); ++it ) - { - if ( ( *it )->pluginName() == pluginId ) - return *it; - } - - return 0; -} - -bool -PluginManager::setPluginEnabled( const TQString &pluginId, bool enabled /* = true */ ) -{ - if ( !d->config ) - d->config = KSharedConfig::openConfig( "komposerrc" ); - - d->config->setGroup( "Plugins" ); - - - if ( !infoForPluginId( pluginId ) ) - return false; - - d->config->writeEntry( pluginId + TQString::tqfromLatin1( "Enabled" ), enabled ); - d->config->sync(); - - return true; -} - -} - -#include "pluginmanager.moc" diff --git a/libkdepim/komposer/core/pluginmanager.h b/libkdepim/komposer/core/pluginmanager.h deleted file mode 100644 index 34cc6b9c5..000000000 --- a/libkdepim/komposer/core/pluginmanager.h +++ /dev/null @@ -1,252 +0,0 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- -/** - * pluginmanager.h - * - * Copyright (C) 2004 Zack Rusin - * Copyright (C) 2003 Martijn Klingens - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef KOMPOSER_PLUGINMANAGER_H -#define KOMPOSER_PLUGINMANAGER_H - -#include -#include -#include -#include -#include - -class KPluginInfo; - -namespace Komposer -{ - - class Plugin; - - class PluginManager : public TQObject - { - Q_OBJECT - TQ_OBJECT - - public: - PluginManager( TQObject * ); - - ~PluginManager(); - - /** - * Returns a list of all available plugins for the given category. - * Currently there are two categories, "Plugins" and "Editors", but - * you can add your own categories if you want. - * - * If you pass an empty string you get the complete list of ALL plugins. - * - * You can query all information on the plugins through the @ref KPluginInfo - * interface. - */ - TQValueList availablePlugins( const TQString &category - = TQString() ) const; - - /** - * Returns a list of all plugins that are actually loaded. - * If you omit the category you get all, otherwise it's a filtered list. - * See also @ref availablePlugins(). - */ - TQMap loadedPlugins( const TQString &category - = TQString() ) const; - - /** - * @brief Search by plugin name. This is the key used as X-KDE-PluginInfo-Name - * in the .desktop file, e.g. "komposer_attachment" - * - * @return The @ref Plugin object found by the search, or a null - * pointer if the plugin is not loaded. - * - * If you want to also load the plugin you can better use @ref loadPlugin, - * which returns - * the pointer to the plugin if it's already loaded. - */ - Plugin* plugin( const TQString &pluginName ) const; - - /** - * @brief Return the short user-visible name of the plugin. - * - * If you want to have the internal name, use @ref pluginId() instead. - * - * @return The name of the protocol, in the user's locale. - */ - TQString pluginName( const Plugin *plugin ) const; - - /** - * @brief Return the internal name of the plugin. - * - * You cannot display this name on the screen, it's used internally for - * passing around IDs. Use @ref pluginName() for a string ready for display. - * - * @return The name of the protocol, in the user's locale. - */ - TQString pluginId( const Plugin *plugin ) const; - - /** - * @brief Unload the plugin specified by @p pluginName - */ - bool unloadPlugin( const TQString &pluginName ); - - /** - * @brief Retrieve the name of the icon for a @ref Plugin. - * - * @return An empty string if the given plugin is not loaded - * or the filename of the icon to use. - */ - TQString pluginIcon( const Plugin *plugin ) const; - - /** - * Shuts down the plugin manager on Komposer shutdown, but first - * unloads all plugins asynchronously. - * - * After 3 seconds all plugins should be removed; what's still left - * by then is unloaded through a hard delete instead. - * - * Note that this call also derefs the plugin manager from the event - * loop, so do NOT call this method when not terminating Komposer! - */ - void shutdown(); - - /** - * Enable a plugin. - * - * This marks a plugin as enabled in the config file, so loadAll() - * can pick it up later. - * - * This method does not actually load a plugin, it only edits the - * config file. - * - * @param name is the name of the plugin as it is listed in the .desktop - * file in the X-KDE-Library field. - * - * Returns false when no appropriate plugin can be found. - */ - bool setPluginEnabled( const TQString &name, bool enabled = true ); - - /** - * Plugin loading mode. Used by @loadPlugin. Code that doesn't want to block - * the GUI and/or lot a lot of plugins at once should use Async loading. - * The default is sync loading. - */ - enum PluginLoadMode { LoadSync, LoadAsync }; - - public slots: - /** - * @brief Load a single plugin by plugin name. Returns an existing plugin - * if one is already loaded in memory. - * - * If mode is set to Async, the plugin will be queued and loaded in - * the background. This method will return a null pointer. To get - * the loaded plugin you can track the @ref pluginLoaded() signal. - * - * See also @ref plugin(). - */ - Plugin* loadPlugin( const TQString &pluginId, PluginLoadMode mode = LoadSync ); - - /** - * @brief Loads all the enabled plugins. Also used to reread the - * config file when the configuration has changed. - */ - void loadAllPlugins(); - - signals: - /** - * @brief Signals a new plugin has just been loaded. - */ - void pluginLoaded( Plugin *plugin ); - - /** - * @brief All plugins have been loaded by the plugin manager. - * - * This signal is emitted exactly ONCE, when the plugin manager has emptied - * its plugin queue for the first time. This means that if you call an async - * loadPlugin() before loadAllPlugins() this signal is probably emitted after - * the initial call completes, unless you are quick enough to fill the queue - * before it completes, which is a dangerous race you shouldn't count upon :) - * - * The signal is delayed one event loop iteration through a singleShot timer, - * but that is not guaranteed to be enough for account instantiation. You may - * need an additional timer for it in the code if you want to programmatically - * act on it. - * - * If you use the signal for enabling/disabling GUI objects there is little - * chance a user is able to activate them in the short while that's remaining, - * the slow part of the code is over now and the remaining processing time - * is neglectable for the user. - */ - void allPluginsLoaded(); - - private slots: - /** - * @brief Cleans up some references if the plugin is destroyed - */ - void slotPluginDestroyed( TQObject *plugin ); - - /** - * shutdown() starts a timer, when it fires we force all plugins - * to be unloaded here by deref()-ing the event loop to trigger the plugin - * manager's destruction - */ - void slotShutdownTimeout(); - - /** - * Common entry point to deref() the KApplication. Used both by the clean - * shutdown and the timeout condition of slotShutdownTimeout() - */ - void slotShutdownDone(); - - /** - * Emitted by a Plugin when it's ready for unload - */ - void slotPluginReadyForUnload(); - - /** - * Load a plugin from our queue. Does nothing if the queue is empty. - * Schedules itself again if more plugins are pending. - */ - void slotLoadNextPlugin(); - - private: - /** - * @internal - * - * The internal method for loading plugins. - * Called by @ref loadPlugin directly or through the queue for async plugin - * loading. - */ - Plugin *loadPluginInternal( const TQString &pluginId ); - - /** - * @internal - * - * Find the KPluginInfo structure by key. Reduces some code duplication. - * - * Returns a null pointer when no plugin info is found. - */ - KPluginInfo *infoForPluginId( const TQString &pluginId ) const; - private: - class Private; - Private *d; - }; - -} - -#endif // KOMPOSER_PLUGINMANAGER_H diff --git a/libkdepim/komposer/core/prefsmodule.cpp b/libkdepim/komposer/core/prefsmodule.cpp deleted file mode 100644 index 77e1c264b..000000000 --- a/libkdepim/komposer/core/prefsmodule.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/** - * prefsmodule.cpp - * - * Copyright (C) 2003-2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "prefsmodule.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -extern "C" -{ - KDE_EXPORT KCModule *create_komposerconfig( TQWidget *parent, const char * ) { - return new Komposer::PrefsModule( parent, "komposerprefs" ); - } -} -using namespace Komposer; - -PrefsModule::PrefsModule( TQWidget *parent, const char *name ) - : KPrefsModule( Komposer::Prefs::self(), parent, name ) -{ - TQVBoxLayout *topLayout = new TQVBoxLayout( this ); - - EditorSelection *editors = new EditorSelection( i18n( "Editors" ), - Komposer::Prefs::self()->m_activeEditor, - this ); - topLayout->addWidget( editors->groupBox() ); - - addWid( editors ); - - load(); -} - -const KAboutData* -PrefsModule::aboutData() const -{ - KAboutData *about = new KAboutData( I18N_NOOP( "komposerconfig" ), - I18N_NOOP( "KDE Komposer" ), - 0, 0, KAboutData::License_LGPL, - I18N_NOOP( "(c), 2003-2004 Zack Rusin" ) ); - - about->addAuthor( "Zack Rusin", 0, "zack@kde.org" );; - - return about; -} - - -EditorSelection::EditorSelection( const TQString &text, TQString &reference, - TQWidget *parent ) - : m_reference( reference ) -{ - m_box = new TQGroupBox( 0, TQt::Vertical, text, parent ); - TQVBoxLayout *boxLayout = new TQVBoxLayout( m_box->tqlayout() ); - boxLayout->tqsetAlignment( TQt::AlignTop ); - - m_editorsCombo = new KComboBox( m_box ); - boxLayout->addWidget( m_editorsCombo ); - - connect( m_editorsCombo, TQT_SIGNAL(activated(const TQString&)), - TQT_SLOT(slotActivated(const TQString&)) ); -} - -EditorSelection::~EditorSelection() -{ -} - -TQGroupBox* -EditorSelection::groupBox() const -{ - return m_box; -} - -void -EditorSelection::readConfig() -{ - m_editorsCombo->clear(); - - KTrader::OfferList editors = KTrader::self()->query( - TQString::tqfromLatin1( "Komposer/Editor" ) ); - KTrader::OfferList::ConstIterator it; - int i = 0; - for ( it = editors.begin(); it != editors.end(); ++it, ++i ) { - if ( !(*it)->hasServiceType( TQString::tqfromLatin1( "Komposer/Editor" ) ) ) - continue; - - TQString name = (*it)->property( "X-KDE-KomposerIdentifier" ).toString(); - m_editorsCombo->insertItem( name ); - if ( m_reference.contains( name ) ) - m_editorsCombo->setCurrentItem( i ); - } -} - -void EditorSelection::writeConfig() -{ - m_reference = m_services[ m_editorsCombo->currentText()]-> - property( "X-KDE-KomposerIdentifier" ).toString(); -} - -void -EditorSelection::slotActivated( const TQString &editor ) -{ - if ( !editor.isEmpty() ) - emit changed(); -} - -void -EditorSelection::setItem( const TQString &str ) -{ - for ( int i = 0; i < m_editorsCombo->count(); ++i ) { - if ( m_editorsCombo->text( i ) == str ) { - m_editorsCombo->setCurrentItem( i ); - break; - } - } -} - -#include "prefsmodule.moc" diff --git a/libkdepim/komposer/core/prefsmodule.h b/libkdepim/komposer/core/prefsmodule.h deleted file mode 100644 index aba969f16..000000000 --- a/libkdepim/komposer/core/prefsmodule.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * prefsmodule.h - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef KOMPOSER_PREFSMODULE_H -#define KOMPOSER_PREFSMODULE_H - -#include -#include -#include -class TQGroupBox; -class TQListViewItem; - -class KAboutData; -class KComboBox; - -namespace Komposer { - - class PrefsModule : public KPrefsModule - { - Q_OBJECT - TQ_OBJECT - public: - PrefsModule( TQWidget *parent=0, const char *name=0 ); - virtual const KAboutData *aboutData() const; - }; - - class EditorSelection : public KPrefsWid - { - Q_OBJECT - TQ_OBJECT - - public: - EditorSelection( const TQString &text, TQString &reference, TQWidget *parent ); - ~EditorSelection(); - - void readConfig(); - void writeConfig(); - - TQGroupBox *groupBox() const; - - private slots: - void slotActivated( const TQString & ); - - private: - void setItem( const TQString & ); - private: - TQString &m_reference; - - TQGroupBox *m_box; - KComboBox *m_editorsCombo; - TQMap m_services; - }; -} - -#endif diff --git a/libkdepim/komposer/core/settings.kcfgc b/libkdepim/komposer/core/settings.kcfgc deleted file mode 100644 index fc98478a9..000000000 --- a/libkdepim/komposer/core/settings.kcfgc +++ /dev/null @@ -1,9 +0,0 @@ -# Code generation options for kconfig_compiler -File=komposer.kcfg -NameSpace=Komposer -ClassName=Config -Singleton=true -Mutators=true -#MemberVariables=public -GlobalEnums=true -#SetUserTexts=true diff --git a/libkdepim/komposer/core/tests/Makefile.am b/libkdepim/komposer/core/tests/Makefile.am deleted file mode 100644 index fbf127956..000000000 --- a/libkdepim/komposer/core/tests/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -INCLUDES = -I$(top_builddir)/libtdepim/komposer/core $(all_includes) - -check_PROGRAMS = testfactory testmanager testkomposer - -METASOURCES = AUTO - -testfactory_SOURCES = main.cpp managertest.cpp -testfactory_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor -testfactory_LDADD = ../libkomposer.la - -testmanager_SOURCES = testmanager.cpp -testmanager_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor -testmanager_LDADD = ../libkomposer.la - -testkomposer_SOURCES = testkomposer.cpp -testkomposer_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor -testkomposer_LDADD = ../libkomposer.la - -check: testfactory - @./testfactory 2>&1 | grep "tests:" diff --git a/libkdepim/komposer/core/tests/main.cpp b/libkdepim/komposer/core/tests/main.cpp deleted file mode 100644 index 4a33a2f13..000000000 --- a/libkdepim/komposer/core/tests/main.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/** - * main.cpp - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include "testfactory.h" -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - -static const KCmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - KCmdLineLastOption -}; -int main( int argc, char** argv ) -{ - KAboutData aboutData( "tests","Test","0.1" ); - KCmdLineArgs::init( argc, argv, &aboutData ); - KCmdLineArgs::addCmdLineOptions( options ); - - KApplication app; - - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - Q_UNUSED( args ); - - TestFactory t; - return t.runTests(); -} diff --git a/libkdepim/komposer/core/tests/managertest.cpp b/libkdepim/komposer/core/tests/managertest.cpp deleted file mode 100644 index 487a84c59..000000000 --- a/libkdepim/komposer/core/tests/managertest.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * managertest.cpp - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include "managertest.h" - -#include "pluginmanager.h" -using namespace Komposer; - -ManagerTest::ManagerTest( TQObject* parent ) - : TQObject( parent ) -{ - m_manager = new PluginManager( this ); -} - - -void ManagerTest::allTests() -{ - CHECK( m_manager->availablePlugins().isEmpty(), true ); - CHECK( m_manager->loadedPlugins().empty(), true ); - CHECK( m_manager->plugin( "non-existing" ), ( Plugin* )0 ); - m_manager->loadAllPlugins(); - CHECK( m_manager->loadedPlugins().empty(), true ); - m_manager->shutdown(); -} - -#include "managertest.moc" diff --git a/libkdepim/komposer/core/tests/managertest.h b/libkdepim/komposer/core/tests/managertest.h deleted file mode 100644 index f02510e67..000000000 --- a/libkdepim/komposer/core/tests/managertest.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * managertest.h - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef MANAGERTEST_H -#define MANAGERTEST_H - -#include -#include "tester.h" - -namespace Komposer { - class PluginManager; -} - -class ManagerTest : public TQObject, - public Tester -{ - Q_OBJECT - TQ_OBJECT -public: - ManagerTest( TQObject* parent = 0 ); - -public slots: - void allTests(); -private: - Komposer::PluginManager* m_manager; -}; - -#endif diff --git a/libkdepim/komposer/core/tests/tester.cpp b/libkdepim/komposer/core/tests/tester.cpp deleted file mode 100644 index b32c89644..000000000 --- a/libkdepim/komposer/core/tests/tester.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/** - * tester.cpp - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include "tester.h" - - -Tester::Tester( TQObject* parent ) - : TQObject( parent ) -{ -} - - -#include "tester.moc" diff --git a/libkdepim/komposer/core/tests/tester.h b/libkdepim/komposer/core/tests/tester.h deleted file mode 100644 index 5981d681d..000000000 --- a/libkdepim/komposer/core/tests/tester.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * tester.h - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef TESTER_H -#define TESTER_H - -#include -#include - -#define CHECK( x, y ) check( __FILE__, __LINE__, #x, x, y ) - -class Tester -{ -public: - Tester() : m_tests( 0 ) {} - virtual ~Tester() {} - -public: - virtual void allTests() = 0; - -public: - int testsFinished() const { - return m_tests; - } - int testsFailed() const { - return m_errorList.count(); - } - TQStringList errorList() const { - return m_errorList; - } - -protected: - template - void check( const char* file, int line, const char* str, - const T& result, const T& expectedResult ) - { - if ( result != expectedResult ) { - TQString error; - TQTextStream ts( &error, IO_WriteOnly ); - ts << file << "["<< line <<"]:" - <<" failed on \""<< str <<"\"" - << "\ntests:\t\t result = " - << result - << ", expected = "<< expectedResult; - m_errorList.append( error ); - } - ++m_tests; - } -private: - TQStringList m_errorList; - int m_tests; -}; - -#endif diff --git a/libkdepim/komposer/core/tests/testfactory.h b/libkdepim/komposer/core/tests/testfactory.h deleted file mode 100644 index 9354e52ad..000000000 --- a/libkdepim/komposer/core/tests/testfactory.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * testfactory.h - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef TESTFACTORY_H -#define TESTFACTORY_H - -#include "managertest.h" - -#include - -#define ADD_TEST(x) addTest( #x, new x ) - -class TestFactory -{ -public: - TestFactory() - { - ADD_TEST( ManagerTest ); - m_tests.setAutoDelete( true ); - } - - int runTests() - { - int result = 0; - kdDebug()<<"Running tests..."< it( m_tests ); - for( ; it.current(); ++it ) { - Tester* test = it.current(); - test->allTests(); - TQStringList errorList = test->errorList(); - if ( !errorList.empty() ) { - ++result; - kdDebug()<< it.currentKey() <<" errors:" << endl; - for ( TQStringList::Iterator itr = errorList.begin(); - itr != errorList.end(); ++itr ) { - kdDebug()<< "\t" << (*itr).latin1() < m_tests; -}; - -#endif diff --git a/libkdepim/komposer/core/tests/testkomposer.cpp b/libkdepim/komposer/core/tests/testkomposer.cpp deleted file mode 100644 index b7997e8c3..000000000 --- a/libkdepim/komposer/core/tests/testkomposer.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "core.h" - -#include -#include -#include -#include - -int main( int argc, char **argv ) -{ - KCmdLineArgs::init( argc, argv, "test", "test", "test", "0.1" ); - KApplication app; - - Komposer::Core *core = new Komposer::Core(); - app.setMainWidget( core ); - core->show(); - - return app.exec(); -} diff --git a/libkdepim/komposer/core/tests/testmanager.cpp b/libkdepim/komposer/core/tests/testmanager.cpp deleted file mode 100644 index 0fcba16b9..000000000 --- a/libkdepim/komposer/core/tests/testmanager.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "testmanager.h" -#include "testmanager.moc" - -#include "pluginmanager.h" -#include "plugin.h" - -#include -#include -#include -#include - -using namespace Komposer; - -TestManager::TestManager( TQObject *parent ) - : TQObject( parent ) -{ - m_manager = new PluginManager( this ); - connect( m_manager, TQT_SIGNAL(pluginLoaded(Plugin*)), - TQT_SLOT(slotPluginLoaded(Plugin*)) ); - connect( m_manager, TQT_SIGNAL(allPluginsLoaded()), - TQT_SLOT(slotAllPluginsLoaded()) ); - m_manager->loadAllPlugins(); - - TQValueList plugins = m_manager->availablePlugins(); - kdDebug()<<"Number of available plugins is "<< plugins.count() <::iterator it = plugins.begin(); it != plugins.end(); ++it ) { - KPluginInfo *i = ( *it ); - kdDebug()<<"\tAvailable plugin "<< i->name() - <<", comment = "<< i->comment() <shutdown(); - tqApp->exit(); -} - -void TestManager::slotPluginLoaded( Plugin *plugin ) -{ - kdDebug()<<"A plugin "<< m_manager->pluginName( plugin ) << " has been loaded"< - -namespace Komposer { - class Plugin; - class PluginManager; -} -using Komposer::Plugin; - -class TestManager : public TQObject -{ - Q_OBJECT - TQ_OBJECT -public: - TestManager( TQObject *parent ); - -public slots: - void slotPluginLoaded( Plugin *plugin ); - void slotAllPluginsLoaded(); -private: - Komposer::PluginManager *m_manager; -}; - -#endif diff --git a/libkdepim/komposer/plugins/Makefile.am b/libkdepim/komposer/plugins/Makefile.am deleted file mode 100644 index dcc4764a7..000000000 --- a/libkdepim/komposer/plugins/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = default diff --git a/libkdepim/komposer/plugins/default/Makefile.am b/libkdepim/komposer/plugins/default/Makefile.am deleted file mode 100644 index 7ae32dc08..000000000 --- a/libkdepim/komposer/plugins/default/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -AM_CPPFLAGS = -I$(top_builddir)/libtdepim/komposer/core $(all_includes) - -kde_module_LTLIBRARIES = libkomposer_defaulteditor.la -libkomposer_defaulteditor_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) -libkomposer_defaulteditor_la_LIBADD = ../../core/libkomposer.la $(LIB_KPARTS) - -libkomposer_defaulteditor_la_SOURCES = defaulteditor.cpp - -METASOURCES = AUTO - -servicedir = $(kde_servicesdir)/komposer -service_DATA = defaulteditor.desktop - -rcdir = $(kde_datadir)/komposer_defaulteditor -rc_DATA = defaulteditorui.rc diff --git a/libkdepim/komposer/plugins/default/defaulteditor.cpp b/libkdepim/komposer/plugins/default/defaulteditor.cpp deleted file mode 100644 index 27018ce5a..000000000 --- a/libkdepim/komposer/plugins/default/defaulteditor.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/** - * defaulteditor.cpp - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include "defaulteditor.h" -#include "core.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -typedef KGenericFactory DefaultEditorFactory; -K_EXPORT_COMPONENT_FACTORY( libkomposer_defaulteditor, - DefaultEditorFactory( "komposer_defaulteditor" ) ) - -DefaultEditor::DefaultEditor( TQObject *parent, const char *name, const TQStringList &args ) - : Editor( parent, name, args ), m_textEdit( 0 ) -{ - setInstance( DefaultEditorFactory::instance() ); - - m_textEdit = new TQTextEdit( 0 ); - - createActions( actionCollection() ); - - setXMLFile( "defaulteditorui.rc" ); -} - -DefaultEditor::~DefaultEditor() -{ -} - - -TQWidget* -DefaultEditor::widget() -{ - return m_textEdit; -} - -TQString -DefaultEditor::text() const -{ - return m_textEdit->text(); -} - -void -DefaultEditor::setText( const TQString &text ) -{ - m_textEdit->setText( text ); -} - -void -DefaultEditor::changeSignature( const TQString &sig ) -{ - TQString text = m_textEdit->text(); - - int sigStart = text.findRev( "-- " ); - TQString sigText = TQString( "-- \n%1" ).tqarg( sig ); - - text.replace( sigStart, text.length(), sigText ); -} - -void -DefaultEditor::createActions( KActionCollection *ac ) -{ - // - // File Actions - // - (void) KStdAction::open( this, TQT_SLOT(open()), ac ); - (void) KStdAction::openRecent( this, TQT_SLOT(openURL(const KURL &)), ac ); - (void) KStdAction::save( this, TQT_SLOT(save()), ac ); - (void) KStdAction::saveAs( this, TQT_SLOT(saveAs()), ac ); - - // - // Edit Actions - // - KAction *actionUndo = KStdAction::undo( m_textEdit, TQT_SLOT(undo()), ac ); - actionUndo->setEnabled( false ); - connect( m_textEdit, TQT_SIGNAL(undoAvailable(bool)), - actionUndo, TQT_SLOT(setEnabled(bool)) ); - - KAction *actionRedo = KStdAction::redo( m_textEdit, TQT_SLOT(redo()), ac ); - actionRedo->setEnabled( false ); - connect( m_textEdit, TQT_SIGNAL(redoAvailable(bool)), - actionRedo, TQT_SLOT(setEnabled(bool)) ); - - KAction *action_cut = KStdAction::cut( m_textEdit, TQT_SLOT(cut()), ac ); - action_cut->setEnabled( false ); - connect( m_textEdit, TQT_SIGNAL(copyAvailable(bool)), - action_cut, TQT_SLOT(setEnabled(bool)) ); - - KAction *action_copy = KStdAction::copy( m_textEdit, TQT_SLOT(copy()), ac ); - action_copy->setEnabled( false ); - connect( m_textEdit, TQT_SIGNAL(copyAvailable(bool)), - action_copy, TQT_SLOT(setEnabled(bool)) ); - - (void) KStdAction::print( this, TQT_SLOT(print()), ac ); - - (void) KStdAction::paste( m_textEdit, TQT_SLOT(paste()), ac ); - (void) new KAction( i18n( "C&lear" ), 0, - m_textEdit, TQT_SLOT(removeSelectedText()), - ac, "edit_clear" ); - - (void) KStdAction::selectAll( m_textEdit, TQT_SLOT(selectAll()), ac ); - - // - // View Actions - // - (void) KStdAction::zoomIn( m_textEdit, TQT_SLOT(zoomIn()), ac ); - (void) KStdAction::zoomOut( m_textEdit, TQT_SLOT(zoomOut()), ac ); - - // - // Character Formatting - // - m_actionBold = new KToggleAction( i18n("&Bold"), "text_bold", CTRL+Key_B, - ac, "format_bold" ); - connect( m_actionBold, TQT_SIGNAL(toggled(bool)), - m_textEdit, TQT_SLOT(setBold(bool)) ); - - m_actionItalic = new KToggleAction( i18n("&Italic"), "text_italic", CTRL+Key_I, - ac, "format_italic" ); - - connect( m_actionItalic, TQT_SIGNAL(toggled(bool)), - m_textEdit, TQT_SLOT(setItalic(bool) )); - - m_actionUnderline = new KToggleAction( i18n("&Underline"), "text_under", CTRL+Key_U, - ac, "format_underline" ); - - connect( m_actionUnderline, TQT_SIGNAL(toggled(bool)), - m_textEdit, TQT_SLOT(setUnderline(bool)) ); - - (void) new KAction( i18n("Text &Color..."), "colorpicker", 0, - this, TQT_SLOT(formatColor()), - ac, "format_color" ); - - // - // Font - // - m_actionFont = new KFontAction( i18n("&Font"), 0, - ac, "format_font" ); - connect( m_actionFont, TQT_SIGNAL(activated(const TQString &)), - m_textEdit, TQT_SLOT(setFamily(const TQString &)) ); - - - m_actionFontSize = new KFontSizeAction( i18n("Font &Size"), 0, - ac, "format_font_size" ); - connect( m_actionFontSize, TQT_SIGNAL(fontSizeChanged(int)), - m_textEdit, TQT_SLOT(setPointSize(int)) ); - - // - // Alignment - // - m_actionAlignLeft = new KToggleAction( i18n("Align &Left"), "text_left", 0, - ac, "format_align_left" ); - connect( m_actionAlignLeft, TQT_SIGNAL(toggled(bool)), - this, TQT_SLOT(setAlignLeft(bool)) ); - - m_actionAlignCenter = new KToggleAction( i18n("Align &Center"), "text_center", 0, - ac, "format_align_center" ); - connect( m_actionAlignCenter, TQT_SIGNAL(toggled(bool)), - this, TQT_SLOT(setAlignCenter(bool)) ); - - m_actionAlignRight = new KToggleAction( i18n("Align &Right"), "text_right", 0, - ac, "format_align_right" ); - connect( m_actionAlignRight, TQT_SIGNAL(toggled(bool)), - this, TQT_SLOT(setAlignRight(bool)) ); - - m_actionAlignJustify = new KToggleAction( i18n("&Justify"), "text_block", 0, - ac, "format_align_justify" ); - connect( m_actionAlignJustify, TQT_SIGNAL(toggled(bool)), - this, TQT_SLOT(setAlignJustify(bool)) ); - - m_actionAlignLeft->setExclusiveGroup( "tqalignment" ); - m_actionAlignCenter->setExclusiveGroup( "tqalignment" ); - m_actionAlignRight->setExclusiveGroup( "tqalignment" ); - m_actionAlignJustify->setExclusiveGroup( "tqalignment" ); - - // - // Tools - // - (void) KStdAction::spelling( this, TQT_SLOT(checkSpelling()), ac ); - - // - // Setup enable/disable - // - updateActions(); - - connect( m_textEdit, TQT_SIGNAL(currentFontChanged(const TQFont &)), - this, TQT_SLOT( updateFont() ) ); - connect( m_textEdit, TQT_SIGNAL(currentFontChanged(const TQFont &)), - this, TQT_SLOT(updateCharFmt()) ); - connect( m_textEdit, TQT_SIGNAL(cursorPositionChanged(int, int)), - this, TQT_SLOT(updateAligment()) ); -} - -void -DefaultEditor::updateActions() -{ - updateCharFmt(); - updateAligment(); - updateFont(); -} - -void -DefaultEditor::updateCharFmt() -{ - m_actionBold->setChecked( m_textEdit->bold() ); - m_actionItalic->setChecked( m_textEdit->italic() ); - m_actionUnderline->setChecked( m_textEdit->underline() ); -} - -void -DefaultEditor::updateAligment() -{ - int align = m_textEdit->tqalignment(); - - switch ( align ) { - case AlignRight: - m_actionAlignRight->setChecked( true ); - break; - case AlignCenter: - m_actionAlignCenter->setChecked( true ); - break; - case AlignLeft: - m_actionAlignLeft->setChecked( true ); - break; - case AlignJustify: - m_actionAlignJustify->setChecked( true ); - break; - default: - break; - } -} - -void -DefaultEditor::updateFont() -{ - if ( m_textEdit->pointSize() > 0 ) - m_actionFontSize->setFontSize( m_textEdit->pointSize() ); - m_actionFont->setFont( m_textEdit->family() ); -} - -void -DefaultEditor::formatColor() -{ - TQColor col; - - int s = KColorDialog::getColor( col, m_textEdit->color(), m_textEdit ); - if ( s != TQDialog::Accepted ) - return; - - m_textEdit->setColor( col ); -} - -void -DefaultEditor::setAlignLeft( bool yes ) -{ - if ( yes ) - m_textEdit->tqsetAlignment( AlignLeft ); -} - -void -DefaultEditor::setAlignRight( bool yes ) -{ - if ( yes ) - m_textEdit->tqsetAlignment( AlignRight ); -} - -void -DefaultEditor::setAlignCenter( bool yes ) -{ - if ( yes ) - m_textEdit->tqsetAlignment( AlignCenter ); -} - -void -DefaultEditor::setAlignJustify( bool yes ) -{ - if ( yes ) - m_textEdit->tqsetAlignment( AlignJustify ); -} - -// -// Content Actions -// - -bool -DefaultEditor::open() -{ - KURL url = KFileDialog::getOpenURL(); - if ( url.isEmpty() ) - return false; - - //fixme - //return openURL( url ); - return true; -} - -bool -DefaultEditor::saveAs() -{ - KURL url = KFileDialog::getSaveURL(); - if ( url.isEmpty() ) - return false; - - //FIXME - //return KParts::ReadWritePart::saveAs( url ); - return true; -} - -void -DefaultEditor::checkSpelling() -{ - TQString s; - if ( m_textEdit->hasSelectedText() ) - s = m_textEdit->selectedText(); - else - s = m_textEdit->text(); - - //KSpell::modalCheck( s ); -} - -bool -DefaultEditor::print() -{ - return true; -} - -#include "defaulteditor.moc" diff --git a/libkdepim/komposer/plugins/default/defaulteditor.desktop b/libkdepim/komposer/plugins/default/defaulteditor.desktop deleted file mode 100644 index 910f7d89c..000000000 --- a/libkdepim/komposer/plugins/default/defaulteditor.desktop +++ /dev/null @@ -1,109 +0,0 @@ -[Desktop Entry] -Type=Service -Icon=editor -ServiceTypes=Komposer/Editor - -X-KDE-Library=libkomposer_defaulteditor -X-Komposer-Version=1 -X-Komposer-Weight=10 - -X-KDE-PluginInfo-Author=Zack Rusin -X-KDE-PluginInfo-Email=zack@kde.org -X-KDE-PluginInfo-Name=komposer_defaulteditor -X-KDE-PluginInfo-Version=0.0.1 -X-KDE-PluginInfo-Website=http://www.kde.org -X-KDE-PluginInfo-Category=Editors -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=LGPL -X-KDE-PluginInfo-EnabledByDefault=true -Name=Komposer Editor -Name[af]=Komposer Redigeerder -Name[bg]=Редактор за Komposer -Name[br]=Aozer Komposer -Name[ca]=Editor Komposer -Name[cs]=Komposer editor -Name[da]=Komposer-editor -Name[el]=ΕπεξεÏγαστής Komposer -Name[eo]=Komposer-redaktilo -Name[es]=Editor Komposer -Name[et]=Komposeri redaktor -Name[eu]=Komposer editorea -Name[fa]=ویرایشگر Komposer -Name[fi]=Komposer-muokkain -Name[fr]=Éditeur Komposer -Name[fy]=Komposer-bewurker -Name[ga]=Eagarthóir Komposer -Name[gl]=Editor Komposer -Name[hu]=Komposer szerkesztÅ‘ -Name[is]=Komposer ritill -Name[it]=Editor Komposer -Name[ja]=Komposer エディタ -Name[kk]=Komposer өңдегіші -Name[km]=កម្មវិធី​និពន្ធ Komposer -Name[lt]=Komposer redaktorius -Name[ms]=Editor Komposer -Name[nb]=Komposer-redigering -Name[ne]=कमà¥à¤ªà¥‹à¤œà¤° समà¥à¤ªà¤¾à¤¦à¤• -Name[nl]=Komposer-editor -Name[nn]=Komposer-redigering -Name[pl]=Edytor Komposer -Name[pt]=Editor Kompositor -Name[pt_BR]=Editor do Komposer -Name[ru]=Редактор Komposer -Name[sk]=Editor Komposer -Name[sl]=Urejevalnik Komposer -Name[sr]=Уређивач Komposer-а -Name[sr@Latn]=UreÄ‘ivaÄ Komposer-a -Name[sv]=Komposer editor -Name[ta]=கமà¯à®ªà¯‹à®šà®°à¯ தொகà¯à®ªà¯à®ªà®¾à®©à¯ -Name[tr]=Komposer Düzenleyicisi -Name[uk]=Редактор Komposer -Name[zh_CN]=Komposer 编辑器 -Name[zh_TW]=Komposer 編輯器 -Comment=Komposer default editor -Comment[af]=Komposer standaard redigeerder -Comment[bg]=Подразбиращ Ñе редактор за Komposer -Comment[ca]=Editor predeterminat de Komposer -Comment[cs]=Výchozí Komposer editor -Comment[da]=Komposer standardeditor -Comment[de]=Komposer Standardeditor -Comment[el]=ΠÏοεπιλεγμένος επεξεÏγαστής του Komposer -Comment[eo]=Komposer-redaktilo apriora -Comment[es]=Editor predefinido Komposer -Comment[et]=Komposeri vaikeredaktor -Comment[eu]=Komposer editore lehenetsia -Comment[fa]=ویرایشگر پیش‌Ùرض Komposer -Comment[fi]=Komposer oletusmuokkain -Comment[fr]=Éditeur Komposer par défaut -Comment[fy]=Komposer standertbewurker -Comment[ga]=Eagarthóir réamhshocraithe Komposer -Comment[gl]=Editor por defecto Komposer -Comment[he]=עורך ברירת מחדל של Kompoer -Comment[hu]=A Komposer alapértelmezett szerkesztÅ‘je -Comment[is]=Sjálfgefinn ritill Komposer -Comment[it]=Editor di default per Komposer -Comment[ja]=Komposer 標準エディタ -Comment[kk]=Komposer әдетті өңдегіші -Comment[km]=កម្មវិធី​និពន្ធ​លំនាំដើម​របស់ Komposer -Comment[ko]=Komposer 기본 편집기 -Comment[lt]=Komposer numatytasis redaktorius -Comment[ms]=Pengedit piawai Komposer -Comment[nb]=Komposer standard-redigerer -Comment[nds]=Komposer-Standardeditor -Comment[ne]=कमà¥à¤ªà¥‹à¤œà¤°à¤•à¥‹ पूरà¥à¤µà¤¨à¤¿à¤°à¥à¤§à¤¾à¤°à¤¿à¤¤ समà¥à¤ªà¤¾à¤¦à¤• -Comment[nl]=Komposer standaardeditor -Comment[nn]=Komposer standard-redigeringsprogram -Comment[pl]=DomyÅ›lny edytor Komposera -Comment[pt]=Editor predefinido Kompositor -Comment[pt_BR]=Editor padrão do Komposer -Comment[ru]=Редактор Komposer по умолчанию -Comment[sk]=Å tandardný editor Komposer -Comment[sl]=Privzeti urejevalnik Komposer -Comment[sr]=Подразумевани Komposer-ов уређивач -Comment[sr@Latn]=Podrazumevani Komposer-ov ureÄ‘ivaÄ -Comment[sv]=Komposer standardeditor -Comment[ta]=கமà¯à®ªà¯‹à®šà®°à¯ à®®à¯à®©à¯à®©à®¿à®°à¯à®ªà¯à®ªà¯ தொகà¯à®ªà¯à®ªà®¾à®©à¯ -Comment[tr]=Öntanımlı Komposer düzenleyicisi -Comment[uk]=Типовий редактор Komposer -Comment[zh_CN]=Komposer 默认编辑器 -Comment[zh_TW]=Komposer é è¨­ç·¨è¼¯å™¨ diff --git a/libkdepim/komposer/plugins/default/defaulteditor.h b/libkdepim/komposer/plugins/default/defaulteditor.h deleted file mode 100644 index 84cedcbc6..000000000 --- a/libkdepim/komposer/plugins/default/defaulteditor.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * defaulteditor.h - * - * Copyright (C) 2004 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef DEFAULTEDITOR_H -#define DEFAULTEDITOR_H - -#include "editor.h" - -class TQTextEdit; -class KFontAction; -class KFontSizeAction; -class KToggleAction; -class KActionCollection; - - -class DefaultEditor : public Komposer::Editor -{ - Q_OBJECT - TQ_OBJECT -public: - DefaultEditor( TQObject *parent, const char *name, const TQStringList &args ); - ~DefaultEditor(); - - virtual TQWidget *widget(); - virtual TQString text() const; -public slots: - virtual void setText( const TQString &txt ); - virtual void changeSignature( const TQString &txt ); - - /** - * Displays a file dialog and loads the selected file. - */ - bool open(); - - /** - * Displays a file dialog and saves to the selected file. - */ - bool saveAs(); - - /** - * Prints the current document - */ - bool print(); - - /** - * Displays a color dialog and sets the text color to the selected value. - */ - void formatColor(); - - void checkSpelling(); - - /** - * @internal - */ - void setAlignLeft( bool yes ); - - /** - * @internal - */ - void setAlignRight( bool yes ); - - /** - * @internal - */ - void setAlignCenter( bool yes ); - - /** - * @internal - */ - void setAlignJustify( bool yes ); - -protected slots: - /** - * Creates the part's actions in the part's action collection. - */ - void createActions( KActionCollection *ac ); - - void updateActions(); - - void updateFont(); - void updateCharFmt(); - void updateAligment(); - -private: - TQTextEdit *m_textEdit; - - KToggleAction *m_actionBold; - KToggleAction *m_actionItalic; - KToggleAction *m_actionUnderline; - - KFontAction *m_actionFont; - KFontSizeAction *m_actionFontSize; - - KToggleAction *m_actionAlignLeft; - KToggleAction *m_actionAlignRight; - KToggleAction *m_actionAlignCenter; - KToggleAction *m_actionAlignJustify; -}; - -#endif diff --git a/libkdepim/komposer/plugins/default/defaulteditorui.rc b/libkdepim/komposer/plugins/default/defaulteditorui.rc deleted file mode 100644 index de8c2e6d2..000000000 --- a/libkdepim/komposer/plugins/default/defaulteditorui.rc +++ /dev/null @@ -1,90 +0,0 @@ - - - - &Edit - - - - - - - - - - - &View - - - - - F&ormat - - - - - - - &Alignment - - - - - - - - - - - - &Tools - - - - &Help - - -Editor Toolbar - - - - - - - - - - - -Format Toolbar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libkdepim/komposer/test/Makefile.am b/libkdepim/komposer/test/Makefile.am deleted file mode 100644 index af51004e8..000000000 --- a/libkdepim/komposer/test/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir) -I../core $(all_includes) -LDADD = $(LIB_KPARTS) ../core/libkomposer.la -AM_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor - -check_PROGRAMS = test - -test_SOURCES = test.cpp diff --git a/libkdepim/komposer/test/test.cpp b/libkdepim/komposer/test/test.cpp deleted file mode 100644 index 5d4544d2a..000000000 --- a/libkdepim/komposer/test/test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/** - * test.cpp - * - * Copyright (C) 2003 Zack Rusin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "core.h" - -#include -#include -#include -#include -#include - -#include - -static const char description[] = - I18N_NOOP( "KDE mail editing manager" ); - -static const char version[] = "0.0.1 (SVN)"; - -int main(int argc, char **argv) -{ - KAboutData about( "komposertest", I18N_NOOP( "KomposerTest" ), version, description, - KAboutData::License_GPL, "(C) 2001-2003 The Kontact developers", 0, "http://kontact.kde.org", "zack@kde.org" ); - about.addAuthor( "Zack Rusin", 0, "zack@kde.org" ); - - KCmdLineArgs::init( argc, argv, &about ); - KUniqueApplication app; - - // see if we are starting with session management - if ( app.isRestored() ) - RESTORE( Komposer::Core ) - else { - // no session.. just start up normally - Komposer::Core *mw = new Komposer::Core; - mw->show(); - } - - return app.exec(); -} diff --git a/libkdepim/kpartsdesignerplugin/CMakeLists.txt b/libkdepim/kpartsdesignerplugin/CMakeLists.txt deleted file mode 100644 index 55c75251c..000000000 --- a/libkdepim/kpartsdesignerplugin/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -################################################# -# -# (C) 2010-2011 Serghei Amelian -# serghei (DOT) amelian (AT) gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# - -add_definitions( -DQT_PLUGIN ) - -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/libtdepim - ${TDE_INCLUDE_DIR} - ${TQT_INCLUDE_DIRS} -) - -link_directories( - ${TQT_LIBRARY_DIRS} -) - - -##### kpartsdesignerplugin (module) ############# - -tde_add_kpart( kpartsdesignerplugin AUTOMOC - SOURCES kpartsdesignerplugin.cpp - LINK kparts-shared kio-shared - DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/designer -) diff --git a/libkdepim/kpartsdesignerplugin/Makefile.am b/libkdepim/kpartsdesignerplugin/Makefile.am deleted file mode 100644 index ebbfbfba2..000000000 --- a/libkdepim/kpartsdesignerplugin/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -AM_CXXFLAGS = -DQT_PLUGIN -METASOURCES = AUTO -INCLUDES = $(all_includes) - -kde_widget_LTLIBRARIES = kpartsdesignerplugin.la -kpartsdesignerplugin_la_LDFLAGS = $(KDE_PLUGIN) -module $(all_libraries) $(LIB_QT) -ltdecore -lkio -kpartsdesignerplugin_la_LIBADD = $(LIB_KPARTS) -kpartsdesignerplugin_la_SOURCES = kpartsdesignerplugin.cpp diff --git a/libkdepim/kpartsdesignerplugin/README b/libkdepim/kpartsdesignerplugin/README deleted file mode 100644 index fb9f42837..000000000 --- a/libkdepim/kpartsdesignerplugin/README +++ /dev/null @@ -1,2 +0,0 @@ -When moving this to kdelibs: the KPartsGenericPart class should move to libkparts so -that it's possible to add an accessor for m_part there. diff --git a/libkdepim/kpartsdesignerplugin/kpartsdesignerplugin.cpp b/libkdepim/kpartsdesignerplugin/kpartsdesignerplugin.cpp deleted file mode 100644 index c3eedc329..000000000 --- a/libkdepim/kpartsdesignerplugin/kpartsdesignerplugin.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright (C) 2004, David Faure - This file is part of the KDE project - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kpartsdesignerplugin.h" - -#include -#include -#include -#include -#include -#include - -KPartsGenericPart::KPartsGenericPart( TQWidget* parentWidget, const char* name ) - : TQWidget( parentWidget, name ), m_part( 0 ) -{ - TQVBoxLayout* tqlayout = new TQVBoxLayout( this ); - tqlayout->setAutoAdd( true ); -} - -void KPartsGenericPart::load() -{ - if ( m_mimetype.isEmpty() || m_url.isEmpty() ) - return; // not enough info yet - // Here it crashes in KSycoca::openDatabase when trying to load the stuff from designer itself - // Not sure why - but it's not really needed anyway. - if ( !kapp ) - return; - TQString mimetype = m_mimetype; - if ( mimetype == "auto" ) - mimetype == KMimeType::findByURL( m_url )->name(); - if ( m_part ) { - delete m_part; - } - // "this" is both the parent widget and the parent object - m_part = KParts::ComponentFactory::createPartInstanceFromQuery( mimetype, TQString(), TQT_TQWIDGET(this), 0, TQT_TQOBJECT(this), 0 ); - if ( m_part ) { - m_part->openURL( m_url ); - m_part->widget()->show(); - } -} - -//// - -static const char* mykey = "KPartsGenericPart"; - -TQStringList KPartsWidgetPlugin::keys() const { - return TQStringList() << mykey; -} - -TQWidget * KPartsWidgetPlugin::create( const TQString & key, TQWidget * parent, const char * name ) { - if ( key == mykey ) - return new KPartsGenericPart( parent, name ); - return 0; -} - -TQString KPartsWidgetPlugin::group( const TQString & key ) const { - if ( key == mykey ) - return "Display (KDE)"; - return TQString(); -} - -#if 0 -TQIconSet KPartsWidgetPlugin::iconSet( const TQString & key ) const { - return TQIconSet(); -} -#endif - -TQString KPartsWidgetPlugin::includeFile( const TQString & key ) const { - if ( key == mykey ) - return "partplugin.h"; - return TQString(); -} - -TQString KPartsWidgetPlugin::toolTip( const TQString & key ) const { - if ( key == mykey ) - return "Generic KParts viewer"; - return TQString(); -} - -TQString KPartsWidgetPlugin::whatsThis( const TQString & key ) const { - if ( key == mykey ) - return "A widget to embed any KParts viewer, given a url and optionally a mimetype"; - return TQString(); -} - -bool KPartsWidgetPlugin::isContainer( const TQString & /*key*/ ) const { - return false; -} - -/// Duplicated from kdelibs/tdecore/kdemacros.h.in for those with kdelibs < 3.4 -#ifndef KDE_TQ_EXPORT_PLUGIN -#define KDE_TQ_EXPORT_PLUGIN(PLUGIN) \ - TQ_EXTERN_C KDE_EXPORT const char* qt_ucm_query_verification_data(); \ - TQ_EXTERN_C KDE_EXPORT TQUnknownInterface* ucm_instantiate(); \ - TQ_EXPORT_PLUGIN(PLUGIN) -#endif - -KDE_TQ_EXPORT_PLUGIN( KPartsWidgetPlugin ) - -#include "kpartsdesignerplugin.moc" - diff --git a/libkdepim/kpartsdesignerplugin/kpartsdesignerplugin.h b/libkdepim/kpartsdesignerplugin/kpartsdesignerplugin.h deleted file mode 100644 index fc49f2511..000000000 --- a/libkdepim/kpartsdesignerplugin/kpartsdesignerplugin.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright (C) 2005, David Faure - This file is part of the KDE project - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - - -#ifndef DESIGNER_PARTPLUGIN_H -#define DESIGNER_PARTPLUGIN_H - -#include -#include -namespace KParts { class ReadOnlyPart; } - -/** - * Generic part loader, able to view any kind of file for which - * a KParts::ReadOnlyPart is available - */ -class KPartsGenericPart : public TQWidget { - Q_OBJECT - TQ_OBJECT - TQ_PROPERTY( TQString url READ url WRITE setURL ) - TQ_PROPERTY( TQString mimetype READ mimetype WRITE setMimetype ) -public: - KPartsGenericPart( TQWidget* parentWidget, const char* name ); - - TQString url() const { return m_url; } - void setURL( const TQString& url ) { m_url = url; load(); } - - // The mimetype, or "auto" if unknown - TQString mimetype() const { return m_mimetype; } - void setMimetype( const TQString& mimetype ) { m_mimetype = mimetype; load(); } - -private: - void load(); - -private: - TQString m_mimetype; - TQString m_url; - KParts::ReadOnlyPart* m_part; -}; - -/** - * TQt designer plugin for embedding a KParts using KPartsGenericPart - */ -class KPartsWidgetPlugin : public TQWidgetPlugin { -public: - TQStringList keys() const; - TQWidget * create( const TQString & key, TQWidget * parent, const char * name ); - TQString group( const TQString & key ) const; - //TQIconSet iconSet( const TQString & key ) const; - TQString includeFile( const TQString & key ) const; - TQString toolTip( const TQString & key ) const; - TQString whatsThis( const TQString & key ) const; - bool isContainer( const TQString & key ) const; -}; - -#endif diff --git a/libkdepim/kpimprefs.cpp b/libkdepim/kpimprefs.cpp deleted file mode 100644 index 478ed7047..000000000 --- a/libkdepim/kpimprefs.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "kpimprefs.h" - -KPimPrefs::KPimPrefs( const TQString &name ) - : KConfigSkeleton( name ) -{ -} - -KPimPrefs::~KPimPrefs() -{ -} - -void KPimPrefs::usrSetDefaults() -{ - setCategoryDefaults(); -} - -void KPimPrefs::usrReadConfig() -{ - kdDebug(5300) << "KPimPrefs::usrReadConfig()" << endl; - - config()->setGroup("General"); - mCustomCategories = config()->readListEntry( "Custom Categories" ); - if ( mCustomCategories.isEmpty() ) setCategoryDefaults(); - mCustomCategories.sort(); -} - -const TQString KPimPrefs::timezone() -{ - TQString zone = ""; - - // Read TimeZoneId from korganizerrc. - KConfig korgcfg( locate( "config", "korganizerrc" ) ); - korgcfg.setGroup( "Time & Date" ); - TQString tz( korgcfg.readEntry( "TimeZoneId" ) ); - if ( !tz.isEmpty() ) { - zone = tz; - kdDebug(5300) << "timezone from korganizerrc is " << zone << endl; - } - - // If timezone not found in KOrg, use the system's default timezone. - if ( zone.isEmpty() ) { - char zonefilebuf[ PATH_MAX ]; - - int len = readlink( "/etc/localtime", zonefilebuf, PATH_MAX ); - if ( len > 0 && len < PATH_MAX ) { - zone = TQString::fromLocal8Bit( zonefilebuf, len ); - zone = zone.mid( zone.find( "zoneinfo/" ) + 9 ); - kdDebug(5300) << "system timezone from /etc/localtime is " << zone - << endl; - } else { - tzset(); - zone = tzname[ 0 ]; - kdDebug(5300) << "system timezone from tzset() is " << zone << endl; - } - } - - return( zone ); -} - -TQDateTime KPimPrefs::utcToLocalTime( const TQDateTime &_dt, - const TQString &timeZoneId ) -{ - TQDateTime dt(_dt); -// kdDebug() << "--- UTC: " << dt.toString() << endl; - - int yearCorrection = 0; - // The timezone conversion only works for dates > 1970 - // For dates < 1970 we adjust the date to be in 1970, - // do the correction there and then re-adjust back. - // Actually, we use 1971 to prevent errors around - // January 1, 1970 - int year = dt.date().year(); - if (year < 1971) - { - yearCorrection = 1971 - year; - dt = dt.addYears(yearCorrection); -// kdDebug() << "--- Adjusted UTC: " << dt.toString() << endl; - } - - TQCString origTz = getenv("TZ"); - - setenv( "TZ", "UTC", 1 ); - time_t utcTime = dt.toTime_t(); - - setenv( "TZ", timeZoneId.local8Bit(), 1 ); - struct tm *local = localtime( &utcTime ); - - if ( origTz.isNull() ) { - unsetenv( "TZ" ); - } else { - setenv( "TZ", origTz, 1 ); - } - tzset(); - - TQDateTime result( TQDate( local->tm_year + 1900 - yearCorrection, - local->tm_mon + 1, local->tm_mday ), - TQTime( local->tm_hour, local->tm_min, local->tm_sec ) ); - -// kdDebug() << "--- LOCAL: " << result.toString() << endl; - return result; -} - -TQDateTime KPimPrefs::localTimeToUtc( const TQDateTime &_dt, - const TQString &timeZoneId ) -{ - TQDateTime dt(_dt); -// kdDebug() << "--- LOCAL: " << dt.toString() << endl; - - int yearCorrection = 0; - // The timezone conversion only works for dates > 1970 - // For dates < 1970 we adjust the date to be in 1970, - // do the correction there and then re-adjust back. - // Actually, we use 1971 to prevent errors around - // January 1, 1970 - - int year = dt.date().year(); - if (year < 1971) - { - yearCorrection = 1971 - year; - dt = dt.addYears(yearCorrection); -// kdDebug() << "--- Adjusted LOCAL: " << dt.toString() << endl; - } - - TQCString origTz = getenv("TZ"); - - setenv( "TZ", timeZoneId.local8Bit(), 1 ); - time_t localTime = dt.toTime_t(); - - setenv( "TZ", "UTC", 1 ); - struct tm *utc = gmtime( &localTime ); - - if ( origTz.isNull() ) { - unsetenv( "TZ" ); - } else { - setenv( "TZ", origTz, 1 ); - } - tzset(); - - TQDateTime result( TQDate( utc->tm_year + 1900 - yearCorrection, - utc->tm_mon + 1, utc->tm_mday ), - TQTime( utc->tm_hour, utc->tm_min, utc->tm_sec ) ); - -// kdDebug() << "--- UTC: " << result.toString() << endl; - - return result; -} - -void KPimPrefs::usrWriteConfig() -{ - config()->setGroup( "General" ); - config()->writeEntry( "Custom Categories", mCustomCategories ); -} diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h deleted file mode 100644 index 1d88a8d8f..000000000 --- a/libkdepim/kpimprefs.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KPIMPREFS_H -#define KPIMPREFS_H - -#include - -#include -#include - -class TQString; - -class KDE_EXPORT KPimPrefs : public KConfigSkeleton -{ - public: - KPimPrefs( const TQString &name = TQString() ); - - virtual ~KPimPrefs(); - - /** Set preferences to default values */ - void usrSetDefaults(); - - /** Read preferences from config file */ - void usrReadConfig(); - - /** Write preferences to config file */ - void usrWriteConfig(); - - /** - * Get user's timezone. - * - * This will first look for whatever timezone is stored in KOrganizer's - * configuration file. If no timezone is found there, it uses - * /etc/localtime. - * - * The value returned may be in various formats (for example, - * America/New_York or EST) so your program should be prepared to these - * formats. - * - * The Calendar class in libkcal says accepts all timezone codes that are - * listed in /usr/share/zoneinfo/zone.tab. - * - * @see Calendar - */ - static const TQString timezone(); - - /** - Convert time given in UTC to local time at timezone specified by given - timezone id. - */ - static TQDateTime utcToLocalTime( const TQDateTime &dt, - const TQString &timeZoneId ); - - /** - Convert time given in local time at timezone specified by given - timezone id to UTC. - */ - static TQDateTime localTimeToUtc( const TQDateTime &dt, - const TQString &timeZoneId ); - - public: - TQStringList mCustomCategories; - - protected: - virtual void setCategoryDefaults() {} -}; - -#endif diff --git a/libkdepim/kpimurlrequesterdlg.cpp b/libkdepim/kpimurlrequesterdlg.cpp deleted file mode 100644 index 553ca659f..000000000 --- a/libkdepim/kpimurlrequesterdlg.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Wilco Greven - - library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - - -#include -#include -#include -#include - -// KDE3.4 or KDE4.0: FIXME: Move to kdelibs! -KURL KPimURLRequesterDlg::getURL( const TQString& dir, const TQString &label, - TQWidget *parent, const TQString& caption ) -{ - KURLRequesterDlg dlg(dir, label, parent, "filedialog", true); - - dlg.setCaption(caption.isNull() ? i18n("Open") : caption); - - dlg.exec(); - - const KURL& url = dlg.selectedURL(); - if (url.isValid()) - KRecentDocument::add(url); - - return url; -} diff --git a/libkdepim/kpimurlrequesterdlg.h b/libkdepim/kpimurlrequesterdlg.h deleted file mode 100644 index 6a00cf4ef..000000000 --- a/libkdepim/kpimurlrequesterdlg.h +++ /dev/null @@ -1,47 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Wilco Greven - - library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPIMURLREQUESTDLG_H_INCLUDED -#define KPIMURLREQUESTDLG_H_INCLUDED - -#include -#include -#include - -class TQWidget; - -class KDE_EXPORT KPimURLRequesterDlg -{ - public: - /** - * Creates a modal dialog with the given label text, executes it and - * returns the selected URL. - * - * @param url This specifies the initial path of the input line. - * @param text The text to be shown on the label. - * @param parent The widget the dialog will be centered on initially. - */ - static KURL getURL( const TQString &url = TQString(), - const TQString &text = TQString(), - TQWidget *parent = 0, - const TQString &caption = TQString() ); -}; - -#endif // KPIMURLREQUESTDLG_H_INCLUDED - diff --git a/libkdepim/kpixmapregionselectordialog.cpp b/libkdepim/kpixmapregionselectordialog.cpp deleted file mode 100644 index b715e000b..000000000 --- a/libkdepim/kpixmapregionselectordialog.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2004 Antonio Larrosa -#include -#include -#include -#include - -using namespace KPIM; - -KPixmapRegionSelectorDialog::KPixmapRegionSelectorDialog(TQWidget *parent, - const char *name, bool modal ) : KDialogBase(parent, name, modal, i18n("Select Region of Image"), Help|Ok|Cancel, Ok, true ) -{ - TQVBox *vbox=new TQVBox(this); - new TQLabel(i18n("Please click and drag on the image to select the region of interest:"), vbox); - m_pixmapSelectorWidget= new KPixmapRegionSelectorWidget(vbox); - - vbox->setSpacing( KDialog::spacingHint() ); - - setMainWidget(vbox); -} - -KPixmapRegionSelectorDialog::~KPixmapRegionSelectorDialog() -{ -} - -TQRect KPixmapRegionSelectorDialog::getSelectedRegion(const TQPixmap &pixmap, TQWidget *parent ) -{ - KPixmapRegionSelectorDialog dialog(parent); - - dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); - - TQDesktopWidget desktopWidget; - TQRect screen=desktopWidget.availableGeometry(); - dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( - (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); - - int result = dialog.exec(); - - TQRect rect; - - if ( result == TQDialog::Accepted ) - rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion(); - - return rect; -} - -TQRect KPixmapRegionSelectorDialog::getSelectedRegion(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent ) -{ - KPixmapRegionSelectorDialog dialog(parent); - - dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); - dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight); - - TQDesktopWidget desktopWidget; - TQRect screen=desktopWidget.availableGeometry(); - dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( - (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); - - int result = dialog.exec(); - - TQRect rect; - - if ( result == TQDialog::Accepted ) - rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion(); - - return rect; -} - -TQImage KPixmapRegionSelectorDialog::getSelectedImage(const TQPixmap &pixmap, TQWidget *parent ) -{ - KPixmapRegionSelectorDialog dialog(parent); - - dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); - - TQDesktopWidget desktopWidget; - TQRect screen=desktopWidget.availableGeometry(); - dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( - (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); - int result = dialog.exec(); - - TQImage image; - - if ( result == TQDialog::Accepted ) - image = dialog.pixmapRegionSelectorWidget()->selectedImage(); - - return image; -} - -TQImage KPixmapRegionSelectorDialog::getSelectedImage(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent ) -{ - KPixmapRegionSelectorDialog dialog(parent); - - dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); - dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight); - - TQDesktopWidget desktopWidget; - TQRect screen=desktopWidget.availableGeometry(); - dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( - (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); - - int result = dialog.exec(); - - TQImage image; - - if ( result == TQDialog::Accepted ) - image = dialog.pixmapRegionSelectorWidget()->selectedImage(); - - return image; -} - diff --git a/libkdepim/kpixmapregionselectordialog.h b/libkdepim/kpixmapregionselectordialog.h deleted file mode 100644 index ee864391a..000000000 --- a/libkdepim/kpixmapregionselectordialog.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2004 Antonio Larrosa -#include -#include -#include - -namespace KPIM { - -/** - * A dialog that uses a KPixmapRegionSelectorWidget to allow the user - * to select a region of an image. If you want to use special features - * like forcing the selected area to have a fixed aspect ratio, you can use - * @see pixmapRegionSelectorWidget() to get the pointer to the - * pixmapRegionSelectorWidget object and set the desired options there. - * - * There are some convenience methods that allow to easily show a dialog - * for the user to select a region of an image, and just care about the selected - * image. - * - * @author Antonio Larrosa - * @since 3.4 - */ -class KDE_EXPORT KPixmapRegionSelectorDialog : public KDialogBase -{ -public: - /** - * The constructor of an empty KPixmapRegionSelectorDialog, you have to call - * later the setPixmap method of the KPixmapRegionSelectorWidget widget of - * the new object. - */ - KPixmapRegionSelectorDialog(TQWidget *parent=0L, const char *name=0L, - bool modal = false ); - /** - * The destructor of the dialog - */ - ~KPixmapRegionSelectorDialog(); - - /** - * @returns the KPixmapRegionSelectorWidget widget so that additional - * parameters can be set by using it. - */ - KPIM::KPixmapRegionSelectorWidget *pixmapRegionSelectorWidget() const - { return m_pixmapSelectorWidget; } - - /** - * Creates a modal dialog, lets the user to select a region of the @p pixmap - * and returns when the dialog is closed. - * - * @returns the selected rectangle, or an invalid rectangle if the user - * pressed the Cancel button. - */ - static TQRect getSelectedRegion(const TQPixmap &pixmap, TQWidget *parent = 0L ); - - /** - * Creates a modal dialog, lets the user to select a region of the @p pixmap - * with the same aspect ratio than @p aspectRatioWidth x @p aspectRatioHeight - * and returns when the dialog is closed. - * - * @returns the selected rectangle, or an invalid rectangle if the user - * pressed the Cancel button. - */ - static TQRect getSelectedRegion(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent = 0L ); - - /** - * Creates a modal dialog, lets the user to select a region of the @p pixmap - * and returns when the dialog is closed. - * - * @returns the selected image, or an invalid image if the user - * pressed the Cancel button. - */ - static TQImage getSelectedImage(const TQPixmap &pixmap, TQWidget *parent = 0L ); - - /** - * Creates a modal dialog, lets the user to select a region of the @p pixmap - * with the same aspect ratio than @p aspectRatioWidth x @p aspectRatioHeight - * and returns when the dialog is closed. - * - * @returns the selected image, or an invalid image if the user - * pressed the Cancel button. - */ - static TQImage getSelectedImage(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent = 0L ); - -protected: - KPIM::KPixmapRegionSelectorWidget *m_pixmapSelectorWidget; -}; - -} - -#endif diff --git a/libkdepim/kpixmapregionselectorwidget.cpp b/libkdepim/kpixmapregionselectorwidget.cpp deleted file mode 100644 index d687ae8a1..000000000 --- a/libkdepim/kpixmapregionselectorwidget.cpp +++ /dev/null @@ -1,454 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2004 Antonio Larrosa -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace KPIM; - -KPixmapRegionSelectorWidget::KPixmapRegionSelectorWidget( TQWidget *parent, - const char *name) : TQWidget( parent, name) -{ - TQHBoxLayout * hboxLayout=new TQHBoxLayout( this ); - - hboxLayout->addStretch(); - TQVBoxLayout * vboxLayout=new TQVBoxLayout( hboxLayout ); - - vboxLayout->addStretch(); - m_label = new TQLabel(this, "pixmapHolder"); - m_label->setBackgroundMode( TQt::NoBackground ); - m_label->installEventFilter( this ); - - vboxLayout->addWidget(m_label); - vboxLayout->addStretch(); - - hboxLayout->addStretch(); - - m_forcedAspectRatio=0; - - m_zoomFactor=1.0; -} - -KPixmapRegionSelectorWidget::~KPixmapRegionSelectorWidget() -{ -} - -void KPixmapRegionSelectorWidget::setPixmap( const TQPixmap &pixmap ) -{ - Q_ASSERT(!pixmap.isNull()); //This class isn't designed to deal with null pixmaps. - m_originalPixmap = pixmap; - m_unzoomedPixmap = pixmap; - m_label->setPixmap( pixmap ); - resetSelection(); -} - -void KPixmapRegionSelectorWidget::resetSelection() -{ - m_selectedRegion = m_originalPixmap.rect(); - updatePixmap(); -} - -TQRect KPixmapRegionSelectorWidget::selectedRegion() const -{ - return m_selectedRegion; -} - -void KPixmapRegionSelectorWidget::setSelectedRegion(const TQRect &rect) -{ - if (!rect.isValid()) resetSelection(); - else - { - m_selectedRegion=rect; - updatePixmap(); - - TQRect r=unzoomedSelectedRegion(); - } -} - -void KPixmapRegionSelectorWidget::updatePixmap() -{ - Q_ASSERT(!m_originalPixmap.isNull()); if(m_originalPixmap.isNull()) { m_label->setPixmap(m_originalPixmap); return; } - if (m_selectedRegion.width()>m_originalPixmap.width()) m_selectedRegion.setWidth( m_originalPixmap.width() ); - if (m_selectedRegion.height()>m_originalPixmap.height()) m_selectedRegion.setHeight( m_originalPixmap.height() ); - - TQPainter painter; - if (m_linedPixmap.isNull()) - { - m_linedPixmap = m_originalPixmap; - - painter.begin(&m_linedPixmap); - painter.setRasterOp( TQt::XorROP ); - painter.fillRect(0,0,m_linedPixmap.width(), m_linedPixmap.height(), - TQBrush( TQColor(255,255,255), TQt::BDiagPattern) ); - painter.end(); - - TQImage image=m_linedPixmap.convertToImage(); - image=KImageEffect::fade(image, 0.4, TQColor(0,0,0)); - m_linedPixmap.convertFromImage(image); - } - - TQPixmap pixmap = m_linedPixmap; - - painter.begin(&pixmap); - painter.drawPixmap( m_selectedRegion.topLeft(), - m_originalPixmap, m_selectedRegion ); - - painter.setPen( TQColor(255,255,255) ); - painter.setRasterOp( TQt::XorROP ); - - painter.drawRect( m_selectedRegion ); - - painter.end(); - - m_label->setPixmap(pixmap); -} - -KPopupMenu *KPixmapRegionSelectorWidget::createPopupMenu() -{ - KPopupMenu *popup=new KPopupMenu(this, "PixmapRegionSelectorPopup"); - popup->insertTitle(i18n("Image Operations")); - - KAction *action = new KAction(i18n("&Rotate Clockwise"), "rotate_cw", - 0, TQT_TQOBJECT(this), TQT_SLOT(rotateClockwise()), - TQT_TQOBJECT(popup), "rotateclockwise"); - action->plug(popup); - - action = new KAction(i18n("Rotate &Counterclockwise"), "rotate_ccw", - 0, TQT_TQOBJECT(this), TQT_SLOT(rotateCounterclockwise()), - TQT_TQOBJECT(popup), "rotatecounterclockwise"); - action->plug(popup); - -/* - I wonder if it would be appropiate to have here an "Open with..." option to - edit the image (antlarr) -*/ - return popup; -} - -void KPixmapRegionSelectorWidget::rotate(KImageEffect::RotateDirection direction) -{ - int w=m_originalPixmap.width(); - int h=m_originalPixmap.height(); - TQImage img=m_unzoomedPixmap.convertToImage(); - img= KImageEffect::rotate(img, direction); - m_unzoomedPixmap.convertFromImage(img); - - img=m_originalPixmap.convertToImage(); - img= KImageEffect::rotate(img, direction); - m_originalPixmap.convertFromImage(img); - - m_linedPixmap=TQPixmap(); - - if (m_forcedAspectRatio>0 && m_forcedAspectRatio!=1) - resetSelection(); - else - { - switch (direction) - { - case ( KImageEffect::Rotate90 ): - { - int x=h-m_selectedRegion.y()-m_selectedRegion.height(); - int y=m_selectedRegion.x(); - m_selectedRegion.setRect(x, y, m_selectedRegion.height(), m_selectedRegion.width() ); - updatePixmap(); - } break; - case ( KImageEffect::Rotate270 ): - { - int x=m_selectedRegion.y(); - int y=w-m_selectedRegion.x()-m_selectedRegion.width(); - m_selectedRegion.setRect(x, y, m_selectedRegion.height(), m_selectedRegion.width() ); - updatePixmap(); - } break; - default: resetSelection(); - } - } -} - -void KPixmapRegionSelectorWidget::rotateClockwise() -{ - rotate(KImageEffect::Rotate90); -} - -void KPixmapRegionSelectorWidget::rotateCounterclockwise() -{ - rotate(KImageEffect::Rotate270); -} - - - -bool KPixmapRegionSelectorWidget::eventFilter(TQObject *obj, TQEvent *ev) -{ - if ( ev->type() == TQEvent::MouseButtonPress ) - { - TQMouseEvent *mev= (TQMouseEvent *)(ev); - //kdDebug() << TQString("click at %1,%2").tqarg( mev->x() ).tqarg( mev->y() ) << endl; - - if ( mev->button() == Qt::RightButton ) - { - KPopupMenu *popup = createPopupMenu( ); - popup->exec( mev->globalPos() ); - delete popup; - return TRUE; - }; - - TQCursor cursor; - if ( m_selectedRegion.contains( mev->pos() ) - && m_selectedRegion!=m_originalPixmap.rect() ) - { - m_state=Moving; - cursor=TQCursor(TQt::SizeAllCursor); - } - else - { - m_state=Resizing; - cursor=TQCursor(TQt::CrossCursor); - } - TQApplication::setOverrideCursor(cursor); - - m_tempFirstClick=mev->pos(); - - return TRUE; - } - - if ( ev->type() == TQEvent::MouseMove ) - { - TQMouseEvent *mev= (TQMouseEvent *)(ev); - - //kdDebug() << TQString("move to %1,%2").tqarg( mev->x() ).tqarg( mev->y() ) << endl; - - if ( m_state == Resizing ) - { - setSelectedRegion ( - calcSelectionRectangle( m_tempFirstClick, mev->pos() ) ); - } - else if (m_state == Moving ) - { - int mevx = mev->x(); - int mevy = mev->y(); - bool mouseOutside=false; - if ( mevx < 0 ) - { - m_selectedRegion.moveBy(-m_selectedRegion.x(),0); - mouseOutside=true; - } - else if ( mevx > m_originalPixmap.width() ) - { - m_selectedRegion.moveBy(m_originalPixmap.width()-m_selectedRegion.width()-m_selectedRegion.x(),0); - mouseOutside=true; - } - if ( mevy < 0 ) - { - m_selectedRegion.moveBy(0,-m_selectedRegion.y()); - mouseOutside=true; - } - else if ( mevy > m_originalPixmap.height() ) - { - m_selectedRegion.moveBy(0,m_originalPixmap.height()-m_selectedRegion.height()-m_selectedRegion.y()); - mouseOutside=true; - } - if (mouseOutside) { updatePixmap(); return TRUE; }; - - m_selectedRegion.moveBy( mev->x()-m_tempFirstClick.x(), - mev->y()-m_tempFirstClick.y() ); - - // Check that the region has not fallen outside the image - if (m_selectedRegion.x() < 0) - m_selectedRegion.moveBy(-m_selectedRegion.x(),0); - else if (m_selectedRegion.right() > m_originalPixmap.width()) - m_selectedRegion.moveBy(-(m_selectedRegion.right()-m_originalPixmap.width()),0); - - if (m_selectedRegion.y() < 0) - m_selectedRegion.moveBy(0,-m_selectedRegion.y()); - else if (m_selectedRegion.bottom() > m_originalPixmap.height()) - m_selectedRegion.moveBy(0,-(m_selectedRegion.bottom()-m_originalPixmap.height())); - - m_tempFirstClick=mev->pos(); - updatePixmap(); - } - return TRUE; - } - - if ( ev->type() == TQEvent::MouseButtonRelease ) - { - TQMouseEvent *mev= (TQMouseEvent *)(ev); - - if ( m_state == Resizing && mev->pos() == m_tempFirstClick) - resetSelection(); - - m_state=None; - TQApplication::restoreOverrideCursor(); - - return TRUE; - } - - TQWidget::eventFilter(obj, ev); - return FALSE; -} - -TQRect KPixmapRegionSelectorWidget::calcSelectionRectangle( const TQPoint & startPoint, const TQPoint & _endPoint ) -{ - TQPoint endPoint = _endPoint; - if ( endPoint.x() < 0 ) endPoint.setX(0); - else if ( endPoint.x() > m_originalPixmap.width() ) endPoint.setX(m_originalPixmap.width()); - if ( endPoint.y() < 0 ) endPoint.setY(0); - else if ( endPoint.y() > m_originalPixmap.height() ) endPoint.setY(m_originalPixmap.height()); - int w=abs(startPoint.x()-endPoint.x()); - int h=abs(startPoint.y()-endPoint.y()); - - if (m_forcedAspectRatio>0) - { - double aspectRatio=w/double(h); - - if (aspectRatio>m_forcedAspectRatio) - h=(int)(w/m_forcedAspectRatio); - else - w=(int)(h*m_forcedAspectRatio); - } - - int x,y; - if ( startPoint.x() < endPoint.x() ) - x=startPoint.x(); - else - x=startPoint.x()-w; - if ( startPoint.y() < endPoint.y() ) - y=startPoint.y(); - else - y=startPoint.y()-h; - - if (x<0) - { - w+=x; - x=0; - h=(int)(w/m_forcedAspectRatio); - - if ( startPoint.y() > endPoint.y() ) - y=startPoint.y()-h; - } - else if (x+w>m_originalPixmap.width()) - { - w=m_originalPixmap.width()-x; - h=(int)(w/m_forcedAspectRatio); - - if ( startPoint.y() > endPoint.y() ) - y=startPoint.y()-h; - } - if (y<0) - { - h+=y; - y=0; - w=(int)(h*m_forcedAspectRatio); - - if ( startPoint.x() > endPoint.x() ) - x=startPoint.x()-w; - } - else if (y+h>m_originalPixmap.height()) - { - h=m_originalPixmap.height()-y; - w=(int)(h*m_forcedAspectRatio); - - if ( startPoint.x() > endPoint.x() ) - x=startPoint.x()-w; - } - - return TQRect(x,y,w,h); -} - -TQRect KPixmapRegionSelectorWidget::unzoomedSelectedRegion() const -{ - return TQRect((int)(m_selectedRegion.x()/m_zoomFactor), - (int)(m_selectedRegion.y()/m_zoomFactor), - (int)(m_selectedRegion.width()/m_zoomFactor), - (int)(m_selectedRegion.height()/m_zoomFactor)); -} - -TQImage KPixmapRegionSelectorWidget::selectedImage() const -{ - TQImage origImage=m_unzoomedPixmap.convertToImage(); - return origImage.copy(unzoomedSelectedRegion()); -} - -void KPixmapRegionSelectorWidget::setSelectionAspectRatio(int width, int height) -{ - m_forcedAspectRatio=width/double(height); -} - -void KPixmapRegionSelectorWidget::setFreeSelectionAspectRatio() -{ - m_forcedAspectRatio=0; -} - -void KPixmapRegionSelectorWidget::setMaximumWidgetSize(int width, int height) -{ - m_maxWidth=width; - m_maxHeight=height; - - m_originalPixmap=m_unzoomedPixmap; - if (m_selectedRegion == m_originalPixmap.rect()) m_selectedRegion=TQRect(); - -// kdDebug() << TQString(" original Pixmap :") << m_originalPixmap.rect() << endl; -// kdDebug() << TQString(" unzoomed Pixmap : %1 x %2 ").tqarg(m_unzoomedPixmap.width()).tqarg(m_unzoomedPixmap.height()) << endl; - - if ( !m_originalPixmap.isNull() && - ( m_originalPixmap.width() > m_maxWidth || - m_originalPixmap.height() > m_maxHeight ) ) - { - /* We have to resize the pixmap to get it complete on the screen */ - TQImage image=m_originalPixmap.convertToImage(); - m_originalPixmap.convertFromImage( image.smoothScale( width, height, TQ_ScaleMin ) ); - //m_originalPixmap.convertFromImage( KImageEffect::sample( image, width, height ) ); - double oldZoomFactor = m_zoomFactor; - m_zoomFactor=m_originalPixmap.width()/(double)m_unzoomedPixmap.width(); - - if (m_selectedRegion.isValid()) - { - m_selectedRegion= - TQRect((int)(m_selectedRegion.x()*m_zoomFactor/oldZoomFactor), - (int)(m_selectedRegion.y()*m_zoomFactor/oldZoomFactor), - (int)(m_selectedRegion.width()*m_zoomFactor/oldZoomFactor), - (int)(m_selectedRegion.height()*m_zoomFactor/oldZoomFactor) ); - } - } - - if (!m_selectedRegion.isValid()) m_selectedRegion = m_originalPixmap.rect(); - - m_linedPixmap=TQPixmap(); - updatePixmap(); - resize(m_label->width(), m_label->height()); -} - -#include "kpixmapregionselectorwidget.moc" diff --git a/libkdepim/kpixmapregionselectorwidget.h b/libkdepim/kpixmapregionselectorwidget.h deleted file mode 100644 index 7b75c98b2..000000000 --- a/libkdepim/kpixmapregionselectorwidget.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2004 Antonio Larrosa -#include -#include -#include -#include - -class KPopupMenu; - -namespace KPIM { - -/** - * KPixmapRegionSelectorWidget is a widget that shows a picture and provides the - * user with a friendly way to select a rectangular subregion of the pixmap. - * - * NOTE: There are two copies of this .h and the .cpp file, with subtle differences. - * One copy is in kdelibs/tdeui, and the other copy is in tdepim/libtdepim - * This is because tdepim has to remain backwards compatible. Any changes - * to either file should be made to the other. - * - * @author Antonio Larrosa - * @since 3.4 - */ -class KPixmapRegionSelectorWidget : public TQWidget -{ - Q_OBJECT - TQ_OBJECT - -public: - /** - * Constructor for a KPixmapRegionSelectorWidget. - */ - KPixmapRegionSelectorWidget( TQWidget *parent = 0L, const char *name=0L); - - /** - * Destructor for a KPixmapRegionSelectorWidget - */ - ~KPixmapRegionSelectorWidget(); - - /** - * Sets the pixmap which will be shown for the user to select a region from. - * @param pixmap The pixmap. Must be non-null. - */ - void setPixmap( const TQPixmap &pixmap ); - - /** - * @return the original whole pixmap that we're using in this widget as the - * pixmap the user is selecting a region from. - */ - TQPixmap pixmap() const { return m_unzoomedPixmap; } - - /** - * Sets the selected region to be @p rect (in zoomed pixmap coordinates) - */ - void setSelectedRegion(const TQRect &rect); - - /** - * Returns the selected region ( in zoomed pixmap coordinates ) - */ - TQRect selectedRegion() const; - - /** - * Returns the selected region ( in unzoomed, original pixmap coordinates ) - */ - TQRect unzoomedSelectedRegion() const; - - /** - * Resets the selection to use the whole image - */ - void resetSelection(); - - /** - * @returns a TQImage object with just the region the user selected from the - * image - */ - TQImage selectedImage() const; - - /** - * Sets the aspect ration that the selected subimage should have. The way to - * select it, is specifying an example valid @p width and @p height. - * @see setFreeSelectionAspectRatio() - */ - void setSelectionAspectRatio(int width, int height); - - /** - * Allows the user to do a selection which has any aspect ratio. This is - * the default. - * @see setSelectionAspectRatio() - */ - void setFreeSelectionAspectRatio(); - - /** - * Sets the maximum size for the widget. If the image is larger than this - * (either horizontally or vertically), it's scaled to adjust to the maximum - * size (preserving the aspect ratio) - */ - void setMaximumWidgetSize( int width, int height ); - - /** - * Rotates the image as specified by the @p direction parameter, also tries - * to rotate the selected region so that it doesn't change, as long as the - * forced aspect ratio setting is respected, in other case, the selected region - * is resetted. - */ - void rotate(KImageEffect::RotateDirection direction); - -public slots: - /** - * Rotates the current image 90º clockwise - */ - void rotateClockwise(); - /** - * Rotates the current image 90º counterclockwise - */ - void rotateCounterclockwise(); - -protected: - /** - * Creates a KPopupMenu with the menu that appears when clicking with the right button on the label - */ - virtual KPopupMenu *createPopupMenu(); - - -private: - bool eventFilter(TQObject *obj, TQEvent *ev); - - /** - * Recalculates the pixmap that is shown based on the current selected area, - * the original image, etc. - */ - void updatePixmap(); - - TQRect calcSelectionRectangle( const TQPoint &startPoint, const TQPoint & endPoint ); - - enum CursorState { None=0, Resizing, Moving }; - CursorState m_state; - - TQPixmap m_unzoomedPixmap; - TQPixmap m_originalPixmap; - TQPixmap m_linedPixmap; - TQRect m_selectedRegion; - TQLabel *m_label; - - TQPoint m_tempFirstClick; - double m_forcedAspectRatio; - - int m_maxWidth, m_maxHeight; - double m_zoomFactor; -}; - -} // for namespace - -#endif diff --git a/libkdepim/kprefsdialog.cpp b/libkdepim/kprefsdialog.cpp deleted file mode 100644 index 466691083..000000000 --- a/libkdepim/kprefsdialog.cpp +++ /dev/null @@ -1,907 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2001,2003 Cornelius Schumacher - Copyright (C) 2003-2004 Reinhold Kainhofer - Copyright (C) 2005 Allen Winter - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "ktimeedit.h" -#include "kdateedit.h" - -#include "kprefsdialog.h" -#include "kprefsdialog.moc" - -namespace KPrefsWidFactory { - -KPrefsWid *create( KConfigSkeletonItem *item, TQWidget *parent ) -{ - KConfigSkeleton::ItemBool *boolItem = - dynamic_cast( item ); - if ( boolItem ) { - return new KPrefsWidBool( boolItem, parent ); - } - - KConfigSkeleton::ItemString *stringItem = - dynamic_cast( item ); - if ( stringItem ) { - return new KPrefsWidString( stringItem, parent ); - } - - KConfigSkeleton::ItemEnum *enumItem = - dynamic_cast( item ); - if ( enumItem ) { - TQValueList choices = enumItem->choices(); - if ( choices.isEmpty() ) { - kdError() << "KPrefsWidFactory::create(): Enum has no choices." << endl; - return 0; - } else { - KPrefsWidRadios *radios = new KPrefsWidRadios( enumItem, parent ); - TQValueList::ConstIterator it; - for( it = choices.begin(); it != choices.end(); ++it ) { - radios->addRadio( (*it).label ); - } - return radios; - } - } - - KConfigSkeleton::ItemInt *intItem = - dynamic_cast( item ); - if ( intItem ) { - return new KPrefsWidInt( intItem, parent ); - } - - return 0; -} - -} - - -TQValueList KPrefsWid::widgets() const -{ - return TQValueList(); -} - - -KPrefsWidBool::KPrefsWidBool( KConfigSkeleton::ItemBool *item, TQWidget *parent ) - : mItem( item ) -{ - mCheck = new TQCheckBox( item->label(), parent); - connect( mCheck, TQT_SIGNAL( clicked() ), TQT_SIGNAL( changed() ) ); - if ( !item->whatsThis().isNull() ) { - TQWhatsThis::add( mCheck, item->whatsThis() ); - } -} - -void KPrefsWidBool::readConfig() -{ - mCheck->setChecked( mItem->value() ); -} - -void KPrefsWidBool::writeConfig() -{ - mItem->setValue( mCheck->isChecked() ); -} - -TQCheckBox *KPrefsWidBool::checkBox() -{ - return mCheck; -} - -TQValueList KPrefsWidBool::widgets() const -{ - TQValueList widgets; - widgets.append( mCheck ); - return widgets; -} - - -KPrefsWidInt::KPrefsWidInt( KConfigSkeleton::ItemInt *item, - TQWidget *parent ) - : mItem( item ) -{ - mLabel = new TQLabel( mItem->label()+':', parent ); - mSpin = new TQSpinBox( parent ); - if ( !item->minValue().isNull() ) { - mSpin->setMinValue( item->minValue().toInt() ); - } - if ( !item->maxValue().isNull() ) { - mSpin->setMaxValue( item->maxValue().toInt() ); - } - connect( mSpin, TQT_SIGNAL( valueChanged( int ) ), TQT_SIGNAL( changed() ) ); - mLabel->setBuddy( mSpin ); - TQString whatsThis = mItem->whatsThis(); - if ( !whatsThis.isEmpty() ) { - TQWhatsThis::add( mLabel, whatsThis ); - TQWhatsThis::add( mSpin, whatsThis ); - } -} - -void KPrefsWidInt::readConfig() -{ - mSpin->setValue( mItem->value() ); -} - -void KPrefsWidInt::writeConfig() -{ - mItem->setValue( mSpin->value() ); -} - -TQLabel *KPrefsWidInt::label() -{ - return mLabel; -} - -TQSpinBox *KPrefsWidInt::spinBox() -{ - return mSpin; -} - -TQValueList KPrefsWidInt::widgets() const -{ - TQValueList widgets; - widgets.append( mLabel ); - widgets.append( mSpin ); - return widgets; -} - - -KPrefsWidColor::KPrefsWidColor( KConfigSkeleton::ItemColor *item, - TQWidget *parent ) - : mItem( item ) -{ - mButton = new KColorButton( parent ); - connect( mButton, TQT_SIGNAL( changed( const TQColor & ) ), TQT_SIGNAL( changed() ) ); - mLabel = new TQLabel( mButton, mItem->label()+':', parent ); - mLabel->setBuddy( mButton ); - TQString whatsThis = mItem->whatsThis(); - if (!whatsThis.isNull()) { - TQWhatsThis::add(mButton, whatsThis); - } -} - -KPrefsWidColor::~KPrefsWidColor() -{ -// kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl; -} - -void KPrefsWidColor::readConfig() -{ - mButton->setColor( mItem->value() ); -} - -void KPrefsWidColor::writeConfig() -{ - mItem->setValue( mButton->color() ); -} - -TQLabel *KPrefsWidColor::label() -{ - return mLabel; -} - -KColorButton *KPrefsWidColor::button() -{ - return mButton; -} - - -KPrefsWidFont::KPrefsWidFont( KConfigSkeleton::ItemFont *item, - TQWidget *parent, const TQString &sampleText ) - : mItem( item ) -{ - mLabel = new TQLabel( mItem->label()+':', parent ); - - mPreview = new TQLabel( sampleText, parent ); - mPreview->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); - - mButton = new TQPushButton( i18n("Choose..."), parent ); - connect( mButton, TQT_SIGNAL( clicked() ), TQT_SLOT( selectFont() ) ); - TQString whatsThis = mItem->whatsThis(); - if (!whatsThis.isNull()) { - TQWhatsThis::add(mPreview, whatsThis); - TQWhatsThis::add(mButton, whatsThis); - } -} - -KPrefsWidFont::~KPrefsWidFont() -{ -} - -void KPrefsWidFont::readConfig() -{ - mPreview->setFont( mItem->value() ); -} - -void KPrefsWidFont::writeConfig() -{ - mItem->setValue( mPreview->font() ); -} - -TQLabel *KPrefsWidFont::label() -{ - return mLabel; -} - -TQFrame *KPrefsWidFont::preview() -{ - return mPreview; -} - -TQPushButton *KPrefsWidFont::button() -{ - return mButton; -} - -void KPrefsWidFont::selectFont() -{ - TQFont myFont(mPreview->font()); - int result = KFontDialog::getFont(myFont); - if (result == KFontDialog::Accepted) { - mPreview->setFont(myFont); - emit changed(); - } -} - - -KPrefsWidTime::KPrefsWidTime( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ) - : mItem( item ) -{ - mLabel = new TQLabel( mItem->label()+':', parent ); - mTimeEdit = new KTimeEdit( parent ); - mLabel->setBuddy( mTimeEdit ); - connect( mTimeEdit, TQT_SIGNAL( timeChanged( TQTime ) ), TQT_SIGNAL( changed() ) ); - TQString whatsThis = mItem->whatsThis(); - if ( !whatsThis.isNull() ) { - TQWhatsThis::add( mTimeEdit, whatsThis ); - } -} - -void KPrefsWidTime::readConfig() -{ - mTimeEdit->setTime( mItem->value().time() ); -} - -void KPrefsWidTime::writeConfig() -{ - // Don't overwrite the date value of the TQDateTime, so we can use a - // KPrefsWidTime and a KPrefsWidDate on the same config entry! - TQDateTime dt( mItem->value() ); - dt.setTime( mTimeEdit->getTime() ); - mItem->setValue( dt ); -} - -TQLabel *KPrefsWidTime::label() -{ - return mLabel; -} - -KTimeEdit *KPrefsWidTime::timeEdit() -{ - return mTimeEdit; -} - - -KPrefsWidDuration::KPrefsWidDuration( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ) - : mItem( item ) -{ - mLabel = new TQLabel( mItem->label()+':', parent ); - mTimeEdit = new TQTimeEdit( parent ); - mLabel->setBuddy( mTimeEdit ); - mTimeEdit->setAutoAdvance( true ); - mTimeEdit->setDisplay( TQTimeEdit::Hours | TQTimeEdit::Minutes ); - mTimeEdit->setRange( TQTime( 0, 1 ), TQTime( 24, 0 ) ); // [1min, 24hr] - connect( mTimeEdit, - TQT_SIGNAL( valueChanged( const TQTime & ) ), TQT_SIGNAL( changed() ) ); - TQString whatsThis = mItem->whatsThis(); - if ( !whatsThis.isNull() ) { - TQWhatsThis::add( mTimeEdit, whatsThis ); - } -} - -void KPrefsWidDuration::readConfig() -{ - mTimeEdit->setTime( mItem->value().time() ); -} - -void KPrefsWidDuration::writeConfig() -{ - TQDateTime dt( mItem->value() ); - dt.setTime( mTimeEdit->time() ); - mItem->setValue( dt ); -} - -TQLabel *KPrefsWidDuration::label() -{ - return mLabel; -} - -TQTimeEdit *KPrefsWidDuration::timeEdit() -{ - return mTimeEdit; -} - - -KPrefsWidDate::KPrefsWidDate( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ) - : mItem( item ) -{ - mLabel = new TQLabel( mItem->label()+':', parent ); - mDateEdit = new KDateEdit( parent ); - mLabel->setBuddy( mDateEdit ); - connect( mDateEdit, TQT_SIGNAL( dateChanged( const TQDate& ) ), TQT_SIGNAL( changed() ) ); - TQString whatsThis = mItem->whatsThis(); - if ( !whatsThis.isNull() ) { - TQWhatsThis::add( mDateEdit, whatsThis ); - } -} - -void KPrefsWidDate::readConfig() -{ - mDateEdit->setDate( mItem->value().date().isValid() ? mItem->value().date() : TQDate::tqcurrentDate() ); -} - -void KPrefsWidDate::writeConfig() -{ - TQDateTime dt( mItem->value() ); - dt.setDate( mDateEdit->date() ); - mItem->setValue( dt ); -} - -TQLabel *KPrefsWidDate::label() -{ - return mLabel; -} - -KDateEdit *KPrefsWidDate::dateEdit() -{ - return mDateEdit; -} - - -KPrefsWidRadios::KPrefsWidRadios( KConfigSkeleton::ItemEnum *item, - TQWidget *parent ) - : mItem( item ) -{ - mBox = new TQButtonGroup( 1, Qt::Horizontal, mItem->label(), parent ); - connect( mBox, TQT_SIGNAL( clicked( int ) ), TQT_SIGNAL( changed() ) ); -} - -KPrefsWidRadios::~KPrefsWidRadios() -{ -} - -void KPrefsWidRadios::addRadio(const TQString &text, const TQString &whatsThis) -{ - TQRadioButton *r = new TQRadioButton(text,mBox); - if (!whatsThis.isNull()) { - TQWhatsThis::add(r, whatsThis); - } -} - -TQButtonGroup *KPrefsWidRadios::groupBox() -{ - return mBox; -} - -void KPrefsWidRadios::readConfig() -{ - mBox->setButton( mItem->value() ); -} - -void KPrefsWidRadios::writeConfig() -{ - mItem->setValue( mBox->id( mBox->selected() ) ); -} - -TQValueList KPrefsWidRadios::widgets() const -{ - TQValueList w; - w.append( mBox ); - return w; -} - -KPrefsWidCombo::KPrefsWidCombo( KConfigSkeleton::ItemEnum *item, - TQWidget *parent ) - : mItem( item ) -{ - TQHBox *hbox = new TQHBox(parent); - new TQLabel( mItem->label(), hbox ); - mCombo = new TQComboBox( hbox ); - connect( mCombo, TQT_SIGNAL( activated( int ) ), TQT_SIGNAL( changed() ) ); -} - -KPrefsWidCombo::~KPrefsWidCombo() -{ -} - -void KPrefsWidCombo::readConfig() -{ - mCombo->setCurrentItem( mItem->value() ); -} - -void KPrefsWidCombo::writeConfig() -{ - mItem->setValue( mCombo->currentItem() ); -} - -TQValueList KPrefsWidCombo::widgets() const -{ - TQValueList w; - w.append( mCombo ); - return w; -} - -TQComboBox* KPrefsWidCombo::comboBox() -{ - return mCombo; -} - -KPrefsWidString::KPrefsWidString( KConfigSkeleton::ItemString *item, - TQWidget *parent, - TQLineEdit::EchoMode echomode ) - : mItem( item ) -{ - mLabel = new TQLabel( mItem->label()+':', parent ); - mEdit = new TQLineEdit( parent ); - mLabel->setBuddy( mEdit ); - connect( mEdit, TQT_SIGNAL( textChanged( const TQString & ) ), - TQT_SIGNAL( changed() ) ); - mEdit->setEchoMode( echomode ); - TQString whatsThis = mItem->whatsThis(); - if ( !whatsThis.isNull() ) { - TQWhatsThis::add( mEdit, whatsThis ); - } -} - -KPrefsWidString::~KPrefsWidString() -{ -} - -void KPrefsWidString::readConfig() -{ - mEdit->setText( mItem->value() ); -} - -void KPrefsWidString::writeConfig() -{ - mItem->setValue( mEdit->text() ); -} - -TQLabel *KPrefsWidString::label() -{ - return mLabel; -} - -TQLineEdit *KPrefsWidString::lineEdit() -{ - return mEdit; -} - -TQValueList KPrefsWidString::widgets() const -{ - TQValueList widgets; - widgets.append( mLabel ); - widgets.append( mEdit ); - return widgets; -} - - -KPrefsWidPath::KPrefsWidPath( KConfigSkeleton::ItemPath *item, TQWidget *parent, - const TQString &filter, uint mode ) - : mItem( item ) -{ - mLabel = new TQLabel( mItem->label()+':', parent ); - mURLRequester = new KURLRequester( parent ); - mLabel->setBuddy( mURLRequester ); - mURLRequester->setMode( mode ); - mURLRequester->setFilter( filter ); - connect( mURLRequester, TQT_SIGNAL( textChanged( const TQString & ) ), - TQT_SIGNAL( changed() ) ); - TQString whatsThis = mItem->whatsThis(); - if ( !whatsThis.isNull() ) { - TQWhatsThis::add( mURLRequester, whatsThis ); - } -} - -KPrefsWidPath::~KPrefsWidPath() -{ -} - -void KPrefsWidPath::readConfig() -{ - mURLRequester->setURL( mItem->value() ); -} - -void KPrefsWidPath::writeConfig() -{ - mItem->setValue( mURLRequester->url() ); -} - -TQLabel *KPrefsWidPath::label() -{ - return mLabel; -} - -KURLRequester *KPrefsWidPath::urlRequester() -{ - return mURLRequester; -} - -TQValueList KPrefsWidPath::widgets() const -{ - TQValueList widgets; - widgets.append( mLabel ); - widgets.append( mURLRequester ); - return widgets; -} - - -KPrefsWidManager::KPrefsWidManager( KConfigSkeleton *prefs ) - : mPrefs( prefs ) -{ -} - -KPrefsWidManager::~KPrefsWidManager() -{ -} - -void KPrefsWidManager::addWid( KPrefsWid *wid ) -{ - mPrefsWids.append( wid ); -} - -KPrefsWidBool *KPrefsWidManager::addWidBool( KConfigSkeleton::ItemBool *item, - TQWidget *parent ) -{ - KPrefsWidBool *w = new KPrefsWidBool( item, parent ); - addWid( w ); - return w; -} - -KPrefsWidTime *KPrefsWidManager::addWidTime( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ) -{ - KPrefsWidTime *w = new KPrefsWidTime( item, parent ); - addWid( w ); - return w; -} - -KPrefsWidDuration *KPrefsWidManager::addWidDuration( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ) -{ - KPrefsWidDuration *w = new KPrefsWidDuration( item, parent ); - addWid( w ); - return w; -} - -KPrefsWidDate *KPrefsWidManager::addWidDate( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ) -{ - KPrefsWidDate *w = new KPrefsWidDate( item, parent ); - addWid( w ); - return w; -} - -KPrefsWidColor *KPrefsWidManager::addWidColor( KConfigSkeleton::ItemColor *item, - TQWidget *parent ) -{ - KPrefsWidColor *w = new KPrefsWidColor( item, parent ); - addWid( w ); - return w; -} - -KPrefsWidRadios *KPrefsWidManager::addWidRadios( KConfigSkeleton::ItemEnum *item, - TQWidget *parent ) -{ - KPrefsWidRadios *w = new KPrefsWidRadios( item, parent ); - TQValueList choices; - choices = item->choices(); - TQValueList::ConstIterator it; - for( it = choices.begin(); it != choices.end(); ++it ) { - w->addRadio( (*it).label, (*it).whatsThis ); - } - addWid( w ); - return w; -} - -KPrefsWidCombo *KPrefsWidManager::addWidCombo( KConfigSkeleton::ItemEnum *item, - TQWidget* parent ) -{ - KPrefsWidCombo *w = new KPrefsWidCombo( item, parent ); - TQValueList choices; - choices = item->choices(); - TQValueList::ConstIterator it; - for( it = choices.begin(); it != choices.end(); ++it ) { - w->comboBox()->insertItem( (*it).label, -1 ); - } - addWid( w ); - return w; -} - -KPrefsWidString *KPrefsWidManager::addWidString( KConfigSkeleton::ItemString *item, - TQWidget *parent ) -{ - KPrefsWidString *w = new KPrefsWidString( item, parent, - TQLineEdit::Normal ); - addWid( w ); - return w; -} - -KPrefsWidPath *KPrefsWidManager::addWidPath( KConfigSkeleton::ItemPath *item, - TQWidget *parent, const TQString &filter, uint mode ) -{ - KPrefsWidPath *w = new KPrefsWidPath( item, parent, filter, mode ); - addWid( w ); - return w; -} - -KPrefsWidString *KPrefsWidManager::addWidPassword( KConfigSkeleton::ItemString *item, - TQWidget *parent ) -{ - KPrefsWidString *w = new KPrefsWidString( item, parent, TQLineEdit::Password ); - addWid( w ); - return w; -} - -KPrefsWidFont *KPrefsWidManager::addWidFont( KConfigSkeleton::ItemFont *item, - TQWidget *parent, - const TQString &sampleText ) -{ - KPrefsWidFont *w = new KPrefsWidFont( item, parent, sampleText ); - addWid( w ); - return w; -} - -KPrefsWidInt *KPrefsWidManager::addWidInt( KConfigSkeleton::ItemInt *item, - TQWidget *parent ) -{ - KPrefsWidInt *w = new KPrefsWidInt( item, parent ); - addWid( w ); - return w; -} - -void KPrefsWidManager::setWidDefaults() -{ - kdDebug() << "KPrefsWidManager::setWidDefaults()" << endl; - - bool tmp = mPrefs->useDefaults( true ); - - readWidConfig(); - - mPrefs->useDefaults( tmp ); -} - -void KPrefsWidManager::readWidConfig() -{ - kdDebug(5310) << "KPrefsWidManager::readWidConfig()" << endl; - - KPrefsWid *wid; - for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) { - wid->readConfig(); - } -} - -void KPrefsWidManager::writeWidConfig() -{ - kdDebug(5310) << "KPrefsWidManager::writeWidConfig()" << endl; - - KPrefsWid *wid; - for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) { - wid->writeConfig(); - } - - mPrefs->writeConfig(); -} - - -KPrefsDialog::KPrefsDialog( KConfigSkeleton *prefs, TQWidget *parent, char *name, - bool modal ) - : KDialogBase(IconList,i18n("Preferences"),Ok|Apply|Cancel|Default,Ok,parent, - name,modal,true), - KPrefsWidManager( prefs ) -{ -// TODO: This seems to cause a crash on exit. Investigate later. -// mPrefsWids.setAutoDelete(true); - -// connect(this,TQT_SIGNAL(defaultClicked()),TQT_SLOT(setDefaults())); - connect(this,TQT_SIGNAL(cancelClicked()),TQT_SLOT(reject())); -} - -KPrefsDialog::~KPrefsDialog() -{ -} - -void KPrefsDialog::autoCreate() -{ - KConfigSkeletonItem::List items = prefs()->items(); - - TQMap mGroupPages; - TQMap mGroupLayouts; - TQMap mCurrentRows; - - KConfigSkeletonItem::List::ConstIterator it; - for( it = items.begin(); it != items.end(); ++it ) { - TQString group = (*it)->group(); - TQString name = (*it)->name(); - - kdDebug() << "ITEMS: " << (*it)->name() << endl; - - TQWidget *page; - TQGridLayout *tqlayout; - int currentRow; - if ( !mGroupPages.contains( group ) ) { - page = addPage( group ); - tqlayout = new TQGridLayout( page ); - mGroupPages.insert( group, page ); - mGroupLayouts.insert( group, tqlayout ); - currentRow = 0; - mCurrentRows.insert( group, currentRow ); - } else { - page = mGroupPages[ group ]; - tqlayout = mGroupLayouts[ group ]; - currentRow = mCurrentRows[ group ]; - } - - KPrefsWid *wid = KPrefsWidFactory::create( *it, page ); - - if ( wid ) { - TQValueList widgets = wid->widgets(); - if ( widgets.count() == 1 ) { - tqlayout->addMultiCellWidget( widgets[ 0 ], - currentRow, currentRow, 0, 1 ); - } else if ( widgets.count() == 2 ) { - tqlayout->addWidget( widgets[ 0 ], currentRow, 0 ); - tqlayout->addWidget( widgets[ 1 ], currentRow, 1 ); - } else { - kdError() << "More widgets than expected: " << widgets.count() << endl; - } - - if ( (*it)->isImmutable() ) { - TQValueList::Iterator it2; - for( it2 = widgets.begin(); it2 != widgets.end(); ++it2 ) { - (*it2)->setEnabled( false ); - } - } - - addWid( wid ); - - mCurrentRows.replace( group, ++currentRow ); - } - } - - readConfig(); -} - -void KPrefsDialog::setDefaults() -{ - setWidDefaults(); -} - -void KPrefsDialog::readConfig() -{ - readWidConfig(); - - usrReadConfig(); -} - -void KPrefsDialog::writeConfig() -{ - writeWidConfig(); - - usrWriteConfig(); - - readConfig(); -} - - -void KPrefsDialog::slotApply() -{ - writeConfig(); - emit configChanged(); -} - -void KPrefsDialog::slotOk() -{ - slotApply(); - accept(); -} - -void KPrefsDialog::slotDefault() -{ - kdDebug() << "KPrefsDialog::slotDefault()" << endl; - - if (KMessageBox::warningContinueCancel(this, - i18n("You are about to set all preferences to default values. All " - "custom modifications will be lost."),i18n("Setting Default Preferences"), - i18n("Reset to Defaults")) - == KMessageBox::Continue) setDefaults(); -} - - -KPrefsModule::KPrefsModule( KConfigSkeleton *prefs, TQWidget *parent, - const char *name ) - : KCModule( parent, name ), - KPrefsWidManager( prefs ) -{ - emit changed( false ); -} - -void KPrefsModule::addWid( KPrefsWid *wid ) -{ - KPrefsWidManager::addWid( wid ); - - connect( wid, TQT_SIGNAL( changed() ), TQT_SLOT( slotWidChanged() ) ); -} - -void KPrefsModule::slotWidChanged() -{ - kdDebug(5310) << "KPrefsModule::slotWidChanged()" << endl; - - emit changed( true ); -} - -void KPrefsModule::load() -{ - kdDebug(5310) << "KPrefsModule::load()" << endl; - - readWidConfig(); - - usrReadConfig(); - - emit changed( false ); -} - -void KPrefsModule::save() -{ - kdDebug(5310) << "KPrefsModule::save()" << endl; - - writeWidConfig(); - - usrWriteConfig(); -} - -void KPrefsModule::defaults() -{ - setWidDefaults(); - - emit changed( true ); -} diff --git a/libkdepim/kprefsdialog.h b/libkdepim/kprefsdialog.h deleted file mode 100644 index b1fffcdd7..000000000 --- a/libkdepim/kprefsdialog.h +++ /dev/null @@ -1,798 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2001-2003 Cornelius Schumacher - Copyright (C) 2003-2004 Reinhold Kainhofer - Copyright (C) 2005 Allen Winter - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KPREFSDIALOG_H -#define KPREFSDIALOG_H - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -class KColorButton; -class TQCheckBox; -class TQComboBox; -class TQLabel; -class TQSpinBox; -class TQButtonGroup; -class TQTimeEdit; -class KTimeEdit; -class KDateEdit; -class KURLRequester; - -/** - @short Base class for GUI control elements used by @ref KPrefsDialog. - @author Cornelius Schumacher - @see KPrefsDialog - - This class provides the interface for the GUI control elements used by - KPrefsDialog. The control element consists of a set of widgets for handling - a certain type of configuration information. -*/ -class KDE_EXPORT KPrefsWid : public TQObject -{ - Q_OBJECT - TQ_OBJECT - public: - /** - This function is called to read value of the setting from the - stored configuration and display it in the widget. - */ - virtual void readConfig() = 0; - /** - This function is called to write the current setting of the widget to the - stored configuration. - */ - virtual void writeConfig() = 0; - - /** - Return a list of widgets used by this control element. - */ - virtual TQValueList widgets() const; - - signals: - /** - Emitted when widget value has changed. - */ - void changed(); -}; - -/** - @short Widgets for bool settings in @ref KPrefsDialog. - - This class provides a control element for configuring bool values. It is meant - to be used by KPrefsDialog. The user is responsible for the tqlayout management. -*/ -class KDE_EXPORT KPrefsWidBool : public KPrefsWid -{ - public: - /** - Create a bool value control element consisting of a TQCheckbox. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidBool( KConfigSkeleton::ItemBool *item, TQWidget *parent ); - - /** - Return the TQCheckbox used by this control element. - */ - TQCheckBox *checkBox(); - - void readConfig(); - void writeConfig(); - - TQValueList widgets() const; - - private: - KConfigSkeleton::ItemBool *mItem; - - TQCheckBox *mCheck; -}; - -/** - @short Widgets for int settings in @ref KPrefsDialog. - - This class provides a control element for configuring integer values. It is - meant to be used by KPrefsDialog. The user is responsible for the tqlayout - management. -*/ -class KDE_EXPORT KPrefsWidInt : public KPrefsWid -{ - public: - /** - Create a integer value control element consisting of a label and a - spinbox. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidInt( KConfigSkeleton::ItemInt *item, TQWidget *parent ); - - /** - Return TQLabel used by this control element. - */ - TQLabel *label(); - - /** - Return the TQSpinBox used by this control element. - */ - TQSpinBox *spinBox(); - - void readConfig(); - void writeConfig(); - - TQValueList widgets() const; - - private: - KConfigSkeleton::ItemInt *mItem; - - TQLabel *mLabel; - TQSpinBox *mSpin; -}; - -/** - @short Widgets for time settings in @ref KPrefsDialog. - - This class provides a control element for configuring time values. It is - meant to be used by KPrefsDialog. The user is responsible for the tqlayout - management. -*/ -class KDE_EXPORT KPrefsWidTime : public KPrefsWid -{ - public: - /** - Create a time value control element consisting of a label and a spinbox. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidTime( KConfigSkeleton::ItemDateTime *item, TQWidget *parent ); - - /** - Return TQLabel used by this widget. - */ - TQLabel *label(); - /** - Return TQSpinBox used by this widget. - */ - KTimeEdit *timeEdit(); - - void readConfig(); - void writeConfig(); - - private: - KConfigSkeleton::ItemDateTime *mItem; - - TQLabel *mLabel; - KTimeEdit *mTimeEdit; -}; - -/** - @short Widgets for duration settings in @ref KPrefsDialog. - - This class provides a control element for configuring duration values. It is - meant to be used by KPrefsDialog. The user is responsible for the tqlayout - management. -*/ -class KDE_EXPORT KPrefsWidDuration : public KPrefsWid -{ - public: - /** - Create a duration value control element consisting of a label and a - spinbox. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidDuration( KConfigSkeleton::ItemDateTime *item, TQWidget *parent ); - - /** - Return TQLabel used by this widget. - */ - TQLabel *label(); - /** - Return TQSpinBox used by this widget. - */ - TQTimeEdit *timeEdit(); - - void readConfig(); - void writeConfig(); - - private: - KConfigSkeleton::ItemDateTime *mItem; - - TQLabel *mLabel; - TQTimeEdit *mTimeEdit; -}; - -/** - @short Widgets for time settings in @ref KPrefsDialog. - - This class provides a control element for configuring date values. It is - meant to be used by KPrefsDialog. The user is responsible for the tqlayout - management. -*/ -class KDE_EXPORT KPrefsWidDate : public KPrefsWid -{ - public: - /** - Create a time value control element consisting of a label and a date box. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidDate( KConfigSkeleton::ItemDateTime *item, TQWidget *parent ); - - /** - Return TQLabel used by this widget. - */ - TQLabel *label(); - /** - Return TQSpinBox used by this widget. - */ - KDateEdit *dateEdit(); - - void readConfig(); - void writeConfig(); - - private: - KConfigSkeleton::ItemDateTime *mItem; - - TQLabel *mLabel; - KDateEdit *mDateEdit; -}; - -/** - @short Widgets for color settings in @ref KPrefsDialog. - - This class provides a control element for configuring color values. It is - meant to be used by KPrefsDialog. The user is responsible for the tqlayout - management. -*/ -class KDE_EXPORT KPrefsWidColor : public KPrefsWid -{ - Q_OBJECT - TQ_OBJECT - public: - /** - Create a color value control element consisting of a test field and a - button for opening a color dialog. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidColor( KConfigSkeleton::ItemColor *item, TQWidget *parent ); - /** - Destruct color setting widget. - */ - ~KPrefsWidColor(); - - /** - Return TQLabel for the button - */ - TQLabel *label(); - /** - Return button opening the color dialog. - */ - KColorButton *button(); - - void readConfig(); - void writeConfig(); - - private: - KConfigSkeleton::ItemColor *mItem; - - TQLabel *mLabel; - KColorButton *mButton; -}; - -/** - @short Widgets for font settings in @ref KPrefsDialog. - - This class provides a control element for configuring font values. It is meant - to be used by KPrefsDialog. The user is responsible for the tqlayout management. -*/ -class KDE_EXPORT KPrefsWidFont : public KPrefsWid -{ - Q_OBJECT - TQ_OBJECT - public: - /** - Create a font value control element consisting of a test field and a - button for opening a font dialog. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - @param sampleText Sample text for previewing the selected font. - */ - KPrefsWidFont( KConfigSkeleton::ItemFont *item, - TQWidget *parent, const TQString &sampleText ); - /** - Destruct font setting widget. - */ - ~KPrefsWidFont(); - - /** - Return TQLabel. - */ - TQLabel *label(); - /** - Return TQFrame used as preview field. - */ - TQFrame *preview(); - /** - Return button opening the font dialog. - */ - TQPushButton *button(); - - void readConfig(); - void writeConfig(); - - protected slots: - void selectFont(); - - private: - KConfigSkeleton::ItemFont *mItem; - - TQLabel *mLabel; - TQLabel *mPreview; - TQPushButton *mButton; -}; - -/** - @short Widgets for settings represented by a group of radio buttons in - @ref KPrefsDialog. - - This class provides a control element for configuring selections. It is meant - to be used by KPrefsDialog. The user is responsible for the tqlayout management. - - The setting is interpreted as an int value, corresponding to the position of - the radio button. The position of the button is defined by the sequence of - @ref addRadio() calls, starting with 0. -*/ -class KDE_EXPORT KPrefsWidRadios : public KPrefsWid -{ - public: - /** - Create a control element for selection of an option. It consists of a box - with several radio buttons. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidRadios( KConfigSkeleton::ItemEnum *item, TQWidget *parent ); - virtual ~KPrefsWidRadios(); - - /** - Add a radio button. - - @param text Text of the button. - @param whatsThis What's This help for the button. - */ - void addRadio( const TQString &text, - const TQString &whatsThis = TQString() ); - - /** - Return the box widget used by this widget. - */ - TQButtonGroup *groupBox(); - - void readConfig(); - void writeConfig(); - - TQValueList widgets() const; - - private: - KConfigSkeleton::ItemEnum *mItem; - - TQButtonGroup *mBox; -}; - -/** - @short Widgets for settings represented by a combo box in - @ref KPrefsDialog. - - This class provides a control element for configuring selections. It is meant - to be used by KPrefsDialog. The user is responsible for the tqlayout management. - - The setting is interpreted as an int value, corresponding to the index in - the combo box. -*/ -class KDE_EXPORT KPrefsWidCombo : public KPrefsWid -{ - public: - /** - Create a control element for selection of an option. It consists of a - combo box. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidCombo( KConfigSkeleton::ItemEnum *item, TQWidget *parent ); - virtual ~KPrefsWidCombo(); - - void readConfig(); - void writeConfig(); - - TQComboBox *comboBox(); - TQValueList widgets() const; - - private: - KConfigSkeleton::ItemEnum *mItem; - TQComboBox *mCombo; -}; - - - -/** - @short Widgets for string settings in @ref KPrefsDialog. - - This class provides a control element for configuring string values. It is - meant to be used by KPrefsDialog. The user is responsible for the tqlayout - management. -*/ -class KDE_EXPORT KPrefsWidString : public KPrefsWid -{ - public: - /** - Create a string value control element consisting of a test label and a - line edit. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - @param echomode Describes how a line edit should display its contents. - */ - KPrefsWidString( KConfigSkeleton::ItemString *item, TQWidget *parent, - TQLineEdit::EchoMode echomode=TQLineEdit::Normal ); - /** - Destructor. - */ - virtual ~KPrefsWidString(); - - /** - Return TQLabel used by this widget. - */ - TQLabel *label(); - /** - Return TQLineEdit used by this widget. - */ - TQLineEdit *lineEdit(); - - void readConfig(); - void writeConfig(); - - TQValueList widgets() const; - - private: - KConfigSkeleton::ItemString *mItem; - - TQLabel *mLabel; - TQLineEdit *mEdit; -}; - - -/** - @short Widgets for string settings in @ref KPrefsDialog. - - This class provides a control element for configuring string values. It is - meant to be used by KPrefsDialog. The user is responsible for the tqlayout - management. -*/ -class KDE_EXPORT KPrefsWidPath : public KPrefsWid -{ - public: - /** - Create a string value control element consisting of a test label and a - line edit. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - @param filter URLRequester filter - @param mode Describes how a line edit should display its contents. - */ - KPrefsWidPath( KConfigSkeleton::ItemPath *item, TQWidget *parent, - const TQString &filter = TQString(), uint mode = KFile::File ); - /** - Destructor. - */ - virtual ~KPrefsWidPath(); - - /** - Return TQLabel used by this widget. - */ - TQLabel *label(); - /** - Return TQLineEdit used by this widget. - */ - KURLRequester *urlRequester(); - - void readConfig(); - void writeConfig(); - - TQValueList widgets() const; - - private: - KConfigSkeleton::ItemPath *mItem; - - TQLabel *mLabel; - KURLRequester *mURLRequester; -}; - - -/** - @short Class for managing KPrefsWid objects. - - This class manages standard configuration widgets provided bz the KPrefsWid - subclasses. It handles creation, loading, saving and default values in a - transparent way. The user has to add the widgets by the corresponding addWid - functions and KPrefsWidManager handles the rest automatically. -*/ -class KDE_EXPORT KPrefsWidManager -{ - public: - /** - Create a KPrefsWidManager object for a KPrefs object. - - @param prefs KPrefs object used to access te configuration. - */ - KPrefsWidManager( KConfigSkeleton *prefs ); - /** - Destructor. - */ - virtual ~KPrefsWidManager(); - - KConfigSkeleton *prefs() const { return mPrefs; } - - /** - Register a custom KPrefsWid object. - */ - virtual void addWid( KPrefsWid * ); - - /** - Register a @ref KPrefsWidBool object. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidBool *addWidBool( KConfigSkeleton::ItemBool *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidInt object. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidInt *addWidInt( KConfigSkeleton::ItemInt *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidDate object. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidDate *addWidDate( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidTime object. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidTime *addWidTime( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidDuration object. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidDuration *addWidDuration( KConfigSkeleton::ItemDateTime *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidColor object. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidColor *addWidColor( KConfigSkeleton::ItemColor *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidRadios object. The choices represented by the - given item object are automatically added as radio buttons. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidRadios *addWidRadios( KConfigSkeleton::ItemEnum *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidCombo object. The choices represented by the - given item object are automatically added to the combo box. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidCombo *addWidCombo( KConfigSkeleton::ItemEnum *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidString object. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidString *addWidString( KConfigSkeleton::ItemString *item, - TQWidget *parent ); - - /** - Register a path @ref KPrefsWidPath object. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - @param filter URLRequester filter - @param mode URLRequester mode - */ - KPrefsWidPath *addWidPath ( KConfigSkeleton::ItemPath *item, TQWidget *parent, - const TQString &filter = TQString(), - uint mode = KFile::File ); - - /** - Register a password @ref KPrefsWidString object, with echomode set to TQLineEdit::Password. - - @param item The KConfigSkeletonItem representing the preferences entry. - @param parent Parent widget. - */ - KPrefsWidString *addWidPassword ( KConfigSkeleton::ItemString *item, - TQWidget *parent ); - - /** - Register a @ref KPrefsWidFont object. - - @param item The KConfigSkeletonItem representing the preferences - entry. - @param parent Parent widget. - @param sampleText Sample text for previewing the selected font. - */ - KPrefsWidFont *addWidFont( KConfigSkeleton::ItemFont *item, - TQWidget *parent, const TQString &sampleText ); - - /** Set all widgets to default values. */ - void setWidDefaults(); - - /** Read preferences from config file. */ - void readWidConfig(); - - /** Write preferences to config file. */ - void writeWidConfig(); - - private: - KConfigSkeleton *mPrefs; - - TQPtrList mPrefsWids; -}; - - -/** - @short Base class for a preferences dialog. - - This class provides the framework for a preferences dialog. You have to - subclass it and add the code to create the actual configuration widgets and - do the tqlayout management. - - KPrefsDialog provides functions to add subclasses of @ref KPrefsWid via - KPrefsWidManager. For these widgets the reading, writing and setting to - default values is handled automatically. Custom widgets have to be handled in - the functions @ref usrReadConfig() and @ref usrWriteConfig(). -*/ -class KDE_EXPORT KPrefsDialog : public KDialogBase, public KPrefsWidManager -{ - Q_OBJECT - TQ_OBJECT - public: - /** - Create a KPrefsDialog for a KPrefs object. - - @param prefs KPrefs object used to access te configuration. - @param parent Parent widget. - @param name Widget name. - @param modal true, if dialog has to be modal, false for non-modal. - */ - KPrefsDialog( KConfigSkeleton *prefs, TQWidget *parent = 0, char *name = 0, - bool modal = false ); - /** - Destructor. - */ - virtual ~KPrefsDialog(); - - void autoCreate(); - - public slots: - /** Set all widgets to default values. */ - void setDefaults(); - - /** Read preferences from config file. */ - void readConfig(); - - /** Write preferences to config file. */ - void writeConfig(); - - signals: - /** Emitted when the a changed configuration has been stored. */ - void configChanged(); - - protected slots: - /** Apply changes to preferences */ - void slotApply(); - - /** Accept changes to preferences and close dialog */ - void slotOk(); - - /** Set preferences to default values */ - void slotDefault(); - - protected: - /** Implement this to read custom configuration widgets. */ - virtual void usrReadConfig() {} - /** Implement this to write custom configuration widgets. */ - virtual void usrWriteConfig() {} -}; - - -class KDE_EXPORT KPrefsModule : public KCModule, public KPrefsWidManager -{ - Q_OBJECT - TQ_OBJECT - public: - KPrefsModule( KConfigSkeleton *, TQWidget *parent = 0, const char *name = 0 ); - - virtual void addWid( KPrefsWid * ); - - void load(); - void save(); - void defaults(); - - protected slots: - void slotWidChanged(); - - protected: - /** Implement this to read custom configuration widgets. */ - virtual void usrReadConfig() {} - /** Implement this to write custom configuration widgets. */ - virtual void usrWriteConfig() {} -}; - -#endif diff --git a/libkdepim/kregexp3.cpp b/libkdepim/kregexp3.cpp deleted file mode 100644 index c4efa96f1..000000000 --- a/libkdepim/kregexp3.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* -*- c++ -*- - kregexp3.cpp - - This file is part of libkdenetwork. - Copyright (c) 2001 Marc Mutz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - This library 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 library; 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 library with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 "kregexp3.h" - -// #define DEBUG_KREGEXP3 - -#ifdef DEBUG_KREGEXP3 -#include -#endif - -TQString KRegExp3::replace( const TQString & str, - const TQString & replacementStr, - int start, bool global ) -{ - int oldpos, pos; - - //-------- parsing the replacementStr into - //-------- literal parts and backreferences: - TQStringList literalStrs; - TQValueList backRefs; - - // Due to LTS: The regexp in unquoted form and with spaces: - // \\ (\d) | \$ (\d) | \$ \{ (\d+) \} - TQRegExp rx( "\\\\(\\d)|\\$(\\d)|\\$\\{(\\d+)\\}" ); - TQRegExp bbrx("\\\\"); - TQRegExp brx("\\"); - -#ifdef DEBUG_KREGEXP3 - kdDebug() << "Analyzing replacementStr: \"" + replacementStr + "\"" << endl; -#endif - - oldpos = 0; - pos = 0; - while ( true ) { - pos = rx.search( replacementStr, pos ); - -#ifdef DEBUG_KREGEXP3 - kdDebug() << TQString(" Found match at pos %1").tqarg(pos) << endl; -#endif - - if ( pos < 0 ) { - literalStrs << replacementStr.mid( oldpos ) - .replace( bbrx, "\\" ) - .replace( brx, "" ); -#ifdef DEBUG_KREGEXP3 - kdDebug() << " No more matches. Last literal is \"" + literalStrs.last() + "\"" << endl; -#endif - break; - } else { - literalStrs << replacementStr.mid( oldpos, pos-oldpos ) - .replace( bbrx, "\\" ) - .replace( brx, "" ); -#ifdef DEBUG_KREGEXP3 - kdDebug() << TQString(" Inserting \"") + literalStrs.last() + "\" as literal." << endl; - kdDebug() << " Searching for corresponding digit(s):" << endl; -#endif - for ( int i = 1 ; i < 4 ; i++ ) - if ( !rx.cap(i).isEmpty() ) { - backRefs << rx.cap(i).toInt(); -#ifdef DEBUG_KREGEXP3 - kdDebug() << TQString(" Found %1 at position %2 in the capturedTexts.") - .tqarg(backRefs.last()).tqarg(i) << endl; -#endif - break; - } - pos += rx.matchedLength(); -#ifdef DEBUG_KREGEXP3 - kdDebug() << TQString(" Setting new pos to %1.").tqarg(pos) << endl; -#endif - oldpos = pos; - } - } - -#ifdef DEBUG_KREGEXP3 - kdDebug() << "Finished the analysis of replacementStr!" << endl; -#endif - Q_ASSERT( literalStrs.count() == backRefs.count() + 1 ); - - //-------- actual construction of the - //-------- resulting TQString - TQString result = ""; - oldpos = 0; - pos = start; - - TQStringList::Iterator sIt; - TQValueList::Iterator iIt; - - if ( start < 0 ) - start += str.length(); - -#ifdef DEBUG_KREGEXP3 - kdDebug() << "Constructing the resultant string starts now:" << endl; -#endif - - while ( pos < (int)str.length() ) { - pos = search( str, pos ); - -#ifdef DEBUG_KREGEXP3 - kdDebug() << TQString(" Found match at pos %1").tqarg(pos) << endl; -#endif - - if ( pos < 0 ) { - result += str.mid( oldpos ); -#ifdef DEBUG_KREGEXP3 - kdDebug() << " No more matches. Adding trailing part from str:" << endl; - kdDebug() << " result == \"" + result + "\"" << endl; -#endif - break; - } else { - result += str.mid( oldpos, pos-oldpos ); -#ifdef DEBUG_KREGEXP3 - kdDebug() << " Adding unchanged part from str:" << endl; - kdDebug() << " result == \"" + result + "\"" << endl; -#endif - for ( sIt = literalStrs.begin(), iIt = backRefs.begin() ; - iIt != backRefs.end() ; ++sIt, ++iIt ) { - result += (*sIt); -#ifdef DEBUG_KREGEXP3 - kdDebug() << " Adding literal replacement part:" << endl; - kdDebug() << " result == \"" + result + "\"" << endl; -#endif - result += cap( (*iIt) ); -#ifdef DEBUG_KREGEXP3 - kdDebug() << " Adding captured string:" << endl; - kdDebug() << " result == \"" + result + "\"" << endl; -#endif - } - result += (*sIt); -#ifdef DEBUG_KREGEXP3 - kdDebug() << " Adding literal replacement part:" << endl; - kdDebug() << " result == \"" + result + "\"" << endl; -#endif - } - if (matchedLength() == 0 && pos == 0) { - // if we matched the begin of the string, then better avoid endless - // recursion - result += str.mid( oldpos ); - break; - } - pos += matchedLength(); -#ifdef DEBUG_KREGEXP3 - kdDebug() << TQString(" Setting new pos to %1.").tqarg(pos) << endl; -#endif - oldpos = pos; - - if ( !global ) { - // only replace the first occurrence, so stop here: - result += str.mid( oldpos ); - break; - } - } - - return result; -} diff --git a/libkdepim/kregexp3.h b/libkdepim/kregexp3.h deleted file mode 100644 index e5013366c..000000000 --- a/libkdepim/kregexp3.h +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- c++ -*- - kregexp3.h - - This file is part of libkdenetwork. - Copyright (c) 2001 Marc Mutz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - This library 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 library; 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 library with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 - -/** @short A TQRegExp (TQt3.x) with a replace() method. - - This class is simply there to provide a namespace for some nice - enhancements of the mighty TQRegExp (TQt3 version) regular - expression engine, namely the method replace(), which can be - used to do search-and-replace like one is used to from perl or sed. - - It "simply" adds the ability to define a replacement string which - contains references to the captured substrings. The following - constructs are understood, which can be freely mixed in the - replacement string: - - @section Sed syntax - - Back references in the replacement string are made using \n - (backslash-digit), where @p n is a single digit. With this mode of - operation, only the first nine captured substrings can be - referenced. - - NOTE: Remember that C++ interprets the backslash in string - constants, so you have to write a backslash as "\\". - - @section Perl syntax - - Back references in the replacement string are made using $n - (dollarsign-digit), where @p n is a single digit. With this mode - of operation, only the first nine captured substrings can be - referenced. - - Additionally, Perl supports the syntax ${nn} - (dollarSign-leftCurlyBrace-digits-rightCurlyBrace), where @p nn - can be a multi-digit number. - - In all modes, counting of captured substrings starts with 1 (one)! - To reference the entire matched string, use $0, ${0} or \\0. - - @author Marc Mutz - @see TQRegExp -*/ - -class KDE_EXPORT KRegExp3 : public TQRegExp -{ -public: - KRegExp3() - : TQRegExp() {} - KRegExp3( const TQString & pattern, - bool caseSensitive = TRUE, - bool wildcard = FALSE ) - : TQRegExp( pattern, caseSensitive, wildcard ) {} - KRegExp3( const TQRegExp & rx ) - : TQRegExp( rx ) {} - KRegExp3( const KRegExp3 & rx ) - : TQRegExp( (TQRegExp)rx ) {} - - /** Replaces each matching subpattern in @p str with - @p replacementStr, inserting captured substrings for - \\n, $n and ${nn} as described in the class documentation. - @param str The source string. - @param replacementStr The string which replaces matched - substrings of @p str. - @param start Start position for the search. - If @p start is negative, starts @p -(start) positions - from the end of @p str. - @param global If @p TRUE, requests to replace all occurrences - of the regexp with @p replacementStr; if @p FALSE, - only the first occurrence will be replaced. - Equivalent to the /g switch to perl's s/// operator. - @return The modified string. - */ - TQString replace( const TQString & str, - const TQString & replacementStr, - int start=0, bool global=TRUE ); -}; diff --git a/libkdepim/kresourceprefs.cpp b/libkdepim/kresourceprefs.cpp deleted file mode 100644 index c343f806d..000000000 --- a/libkdepim/kresourceprefs.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include - -#include "kresourceprefs.h" - -KResourcePrefs::KResourcePrefs( const TQString &name ) - : KConfigSkeleton( name ) -{ -} - -void KResourcePrefs::addGroupPrefix( const TQString &prefix ) -{ - KConfigSkeletonItem::List itemList = items(); - KConfigSkeletonItem::List::Iterator it; - - for ( it = itemList.begin(); it != itemList.end(); ++it ) - (*it)->setGroup( prefix + ":" + (*it)->group() ); -} diff --git a/libkdepim/kresourceprefs.h b/libkdepim/kresourceprefs.h deleted file mode 100644 index 6d96deadb..000000000 --- a/libkdepim/kresourceprefs.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KRESOURCEPREFS_H -#define KRESOURCEPREFS_H - -#include -#include - -class TQString; - -/** - This is a base class for all KPrefs objects, where multiple instances want - to work on the same config file. - By calling addGroupPrefix( "foobar" ), 'foobar' as a prefix is added to the - group names in the configuration file. - The prefix should be an unique identifier to avoid name clashes and the method - has to be called before readConfig(), otherwise the wrong entries are read. - */ -class KDE_EXPORT KResourcePrefs : public KConfigSkeleton -{ - public: - KResourcePrefs( const TQString &name = TQString() ); - - /** - Adds a prefix to all groups of this prefs object. - */ - void addGroupPrefix( const TQString &prefix ); -}; - -#endif diff --git a/libkdepim/krsqueezedtextlabel.cpp b/libkdepim/krsqueezedtextlabel.cpp deleted file mode 100644 index ef9746ee0..000000000 --- a/libkdepim/krsqueezedtextlabel.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* This file has been copied from the KDE libraries and slightly modified. - This can be removed as soon as kdelibs provides the same functionality. - - Copyright (C) 2000 Ronny Standtke - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "krsqueezedtextlabel.h" -#include "kstringhandler.h" -#include - -KRSqueezedTextLabel::KRSqueezedTextLabel( const TQString &text , TQWidget *parent, const char *name ) - : TQLabel ( parent, name ) { - tqsetSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed )); - fullText = text; - squeezeTextToLabel(); -} - -KRSqueezedTextLabel::KRSqueezedTextLabel( TQWidget *parent, const char *name ) - : TQLabel ( parent, name ) { - tqsetSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed )); -} - -void KRSqueezedTextLabel::resizeEvent( TQResizeEvent * ) { - squeezeTextToLabel(); -} - -TQSize KRSqueezedTextLabel::tqminimumSizeHint() const -{ - TQSize sh = TQLabel::tqminimumSizeHint(); - sh.setWidth(-1); - return sh; -} - -TQSize KRSqueezedTextLabel::tqsizeHint() const -{ - return TQSize(contentsRect().width(), TQLabel::tqsizeHint().height()); -} - -void KRSqueezedTextLabel::setText( const TQString &text ) { - fullText = text; - squeezeTextToLabel(); -} - -void KRSqueezedTextLabel::squeezeTextToLabel() { - TQFontMetrics fm(fontMetrics()); - int labelWidth = size().width(); - int textWidth = fm.width(fullText); - if (textWidth > labelWidth) { - TQString squeezedText = KStringHandler::rPixelSqueeze(fullText, fm, labelWidth); - TQLabel::setText(squeezedText); - - TQToolTip::remove( this ); - TQToolTip::add( this, fullText ); - - } else { - TQLabel::setText(fullText); - - TQToolTip::remove( this ); - TQToolTip::hide(); - - } -} - -void KRSqueezedTextLabel::tqsetAlignment( int tqalignment ) -{ - // save fullText and restore it - TQString tmpFull(fullText); - TQLabel::tqsetAlignment(tqalignment); - fullText = tmpFull; -} - -#include "krsqueezedtextlabel.moc" diff --git a/libkdepim/krsqueezedtextlabel.h b/libkdepim/krsqueezedtextlabel.h deleted file mode 100644 index 36bd209b6..000000000 --- a/libkdepim/krsqueezedtextlabel.h +++ /dev/null @@ -1,75 +0,0 @@ -/* This file has been copied from the KDE libraries and slightly modified. - This can be removed as soon as kdelibs provides the same functionality. - - Copyright (C) 2000 Ronny Standtke - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KRSTQUEEZEDTEXTLABEL_H -#define KRSTQUEEZEDTEXTLABEL_H - -#include -#include - -/** - * @short A replacement for TQLabel that squeezes its text - * - * A label class that squeezes its text into the label - * - * If the text is too long to fit into the label it is divided into - * remaining left and right parts which are separated by three dots. - * - * @author Ronny Standtke - */ - -/* - * TQLabel - */ -class KDE_EXPORT KRSqueezedTextLabel : public TQLabel { - Q_OBJECT - TQ_OBJECT - -public: - /** - * Default constructor. - */ - KRSqueezedTextLabel( TQWidget *parent, const char *name = 0 ); - KRSqueezedTextLabel( const TQString &text, TQWidget *parent, const char *name = 0 ); - - virtual TQSize tqminimumSizeHint() const; - virtual TQSize tqsizeHint() const; - /** - * Overridden for internal reasons; the API remains unaffected. - */ - virtual void tqsetAlignment( int ); - -public slots: - void setText( const TQString & ); - -protected: - /** - * used when widget is resized - */ - void resizeEvent( TQResizeEvent * ); - /** - * does the dirty work - */ - void squeezeTextToLabel(); - TQString fullText; - -}; - -#endif // KRSTQUEEZEDTEXTLABEL_H diff --git a/libkdepim/kscoring.cpp b/libkdepim/kscoring.cpp deleted file mode 100644 index cf02d88f4..000000000 --- a/libkdepim/kscoring.cpp +++ /dev/null @@ -1,1234 +0,0 @@ -/* - kscoring.cpp - - Copyright (c) 2001 Mathias Waack - Copyright (C) 2005 by Volker Krause - - Author: Mathias Waack - - 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. - 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, US -*/ -#ifdef KDE_USE_FINAL -#undef TQT_NO_ASCII_CAST -#endif - -#undef TQT_NO_COMPAT - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kscoring.h" -#include "kscoringeditor.h" - - -//---------------------------------------------------------------------------- -// a small function to encode attribute values, code stolen from TQDom -static TQString toXml(const TQString& str) -{ - TQString tmp(str); - uint len = tmp.length(); - uint i = 0; - while ( i < len ) { - if (tmp[(int)i] == '<') { - tmp.replace(i, 1, "<"); - len += 3; - i += 4; - } else if (tmp[(int)i] == '"') { - tmp.replace(i, 1, """); - len += 5; - i += 6; - } else if (tmp[(int)i] == '&') { - tmp.replace(i, 1, "&"); - len += 4; - i += 5; - } else if (tmp[(int)i] == '>') { - tmp.replace(i, 1, ">"); - len += 3; - i += 4; - } else { - ++i; - } - } - - return tmp; -} - - -// small dialog to display the messages from NotifyAction -NotifyDialog* NotifyDialog::me = 0; -NotifyDialog::NotesMap NotifyDialog::dict; - -NotifyDialog::NotifyDialog(TQWidget* p) - : KDialogBase(p,"notify action dialog",true,"Notify Message",Close,Close,true) -{ - TQFrame *f = makeMainWidget(); - TQVBoxLayout *topL = new TQVBoxLayout(f); - note = new TQLabel(f); - note->setTextFormat(RichText); - topL->addWidget(note); - TQCheckBox *check = new TQCheckBox(i18n("Do not show this message again"),f); - check->setChecked(true); - topL->addWidget(check); - connect(check,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotShowAgainToggled(bool))); -} - -void NotifyDialog::slotShowAgainToggled(bool flag) -{ - dict.replace(msg,!flag); - kdDebug(5100) << "note \"" << note << "\" will popup again: " << flag << endl; -} - -void NotifyDialog::display(ScorableArticle& a, const TQString& s) -{ - kdDebug(5100) << "displaying message" << endl; - if (!me) me = new NotifyDialog(); - me->msg = s; - - NotesMap::Iterator i = dict.find(s); - if (i == dict.end() || i.data()) { - TQString msg = i18n("Article\n%1
%2
caused the following" - " note to appear:
%3"). - arg(a.from()). - arg(a.subject()). - arg(s); - me->note->setText(msg); - if ( i == dict.end() ) i = dict.replace(s,false); - me->adjustSize(); - me->exec(); - } -} - - -//---------------------------------------------------------------------------- -ScorableArticle::~ScorableArticle() -{ -} - -void ScorableArticle::displayMessage(const TQString& note) -{ - NotifyDialog::display(*this,note); -} - -//---------------------------------------------------------------------------- -ScorableGroup::~ScorableGroup() -{ -} - -// the base class for all actions -ActionBase::ActionBase() -{ - kdDebug(5100) << "new Action " << this << endl; -} - -ActionBase::~ActionBase() -{ - kdDebug(5100) << "delete Action " << this << endl; -} - - -TQStringList ActionBase::userNames() -{ - TQStringList l; - l << userName(SETSCORE); - l << userName(NOTIFY); - l << userName(COLOR); - l << userName(MARKASREAD); - return l; -} - -ActionBase* ActionBase::factory(int type, const TQString &value) -{ - switch (type) { - case SETSCORE: return new ActionSetScore(value); - case NOTIFY: return new ActionNotify(value); - case COLOR: return new ActionColor(value); - case MARKASREAD: return new ActionMarkAsRead(); - default: - kdWarning(5100) << "unknown type " << type << " in ActionBase::factory()" << endl; - return 0; - } -} - -TQString ActionBase::userName(int type) -{ - switch (type) { - case SETSCORE: return i18n("Adjust Score"); - case NOTIFY: return i18n("Display Message"); - case COLOR: return i18n("Colorize Header"); - case MARKASREAD: return i18n("Mark As Read"); - default: - kdWarning(5100) << "unknown type " << type << " in ActionBase::userName()" << endl; - return 0; - } -} - -int ActionBase::getTypeForName(const TQString& name) -{ - if (name == "SETSCORE") return SETSCORE; - else if (name == "NOTIFY") return NOTIFY; - else if (name == "COLOR") return COLOR; - else if (name == "MARKASREAD") return MARKASREAD; - else { - kdWarning(5100) << "unknown type string " << name - << " in ActionBase::getTypeForName()" << endl; - return -1; - } -} - -int ActionBase::getTypeForUserName(const TQString& name) -{ - if (name == userName(SETSCORE)) return SETSCORE; - else if (name == userName(NOTIFY)) return NOTIFY; - else if (name == userName(COLOR)) return COLOR; - else if ( name == userName(MARKASREAD) ) return MARKASREAD; - else { - kdWarning(5100) << "unknown type string " << name - << " in ActionBase::getTypeForUserName()" << endl; - return -1; - } -} - -// the set score action -ActionSetScore::ActionSetScore(short v) - : val(v) -{ -} - -ActionSetScore::ActionSetScore(const TQString& s) -{ - val = s.toShort(); -} - -ActionSetScore::ActionSetScore(const ActionSetScore& as) - : ActionBase(), - val(as.val) -{ -} - -ActionSetScore::~ActionSetScore() -{ -} - -TQString ActionSetScore::toString() const -{ - TQString a; - a += ""; - return a; -} - -void ActionSetScore::apply(ScorableArticle& a) const -{ - a.addScore(val); -} - -ActionSetScore* ActionSetScore::clone() const -{ - return new ActionSetScore(*this); -} - -// the color action -ActionColor::ActionColor(const TQColor& c) - : ActionBase(), color(c) -{ -} - -ActionColor::ActionColor(const TQString& s) - : ActionBase() -{ - setValue(s); -} - -ActionColor::ActionColor(const ActionColor& a) - : ActionBase(), color(a.color) -{ -} - -ActionColor::~ActionColor() -{} - -TQString ActionColor::toString() const -{ - TQString a; - a += ""; - return a; -} - -void ActionColor::apply(ScorableArticle& a) const -{ - a.changeColor(color); -} - -ActionColor* ActionColor::clone() const -{ - return new ActionColor(*this); -} - - -// the notify action -ActionNotify::ActionNotify(const TQString& s) -{ - note = s; -} - -ActionNotify::ActionNotify(const ActionNotify& an) - : ActionBase() -{ - note = an.note; -} - -TQString ActionNotify::toString() const -{ - return ""; -} - -void ActionNotify::apply(ScorableArticle& a) const -{ - a.displayMessage(note); -} - -ActionNotify* ActionNotify::clone() const -{ - return new ActionNotify(*this); -} - - -// mark as read action -ActionMarkAsRead::ActionMarkAsRead() : - ActionBase() -{ -} - -ActionMarkAsRead::ActionMarkAsRead( const ActionMarkAsRead &action ) : - ActionBase() -{ - Q_UNUSED( action ); -} - -TQString ActionMarkAsRead::toString() const -{ - return ""; -} - -void ActionMarkAsRead::apply( ScorableArticle &article ) const -{ - article.markAsRead(); -} - -ActionMarkAsRead* ActionMarkAsRead::clone() const -{ - return new ActionMarkAsRead(*this); -} - -//---------------------------------------------------------------------------- -NotifyCollection::NotifyCollection() -{ - notifyList.setAutoDelete(true); -} - -NotifyCollection::~NotifyCollection() -{ -} - -void NotifyCollection::addNote(const ScorableArticle& a, const TQString& note) -{ - article_list *l = notifyList.find(note); - if (!l) { - notifyList.insert(note,new article_list); - l = notifyList.find(note); - } - article_info i; - i.from = a.from(); - i.subject = a.subject(); - l->append(i); -} - -TQString NotifyCollection::collection() const -{ - TQString notifyCollection = i18n("

List of collected notes

"); - notifyCollection += "

    "; - // first look thru the notes and create one string - TQDictIterator it(notifyList); - for(;it.current();++it) { - const TQString& note = it.currentKey(); - notifyCollection += "
  • " + note + "
      "; - article_list* alist = it.current(); - article_list::Iterator ait; - for(ait = alist->begin(); ait != alist->end(); ++ait) { - notifyCollection += "
    • From: " + (*ait).from + "
      "; - notifyCollection += "Subject: " + (*ait).subject; - } - notifyCollection += "
    "; - } - notifyCollection += "
"; - - return notifyCollection; -} - -void NotifyCollection::displayCollection(TQWidget *p) const -{ - //KMessageBox::information(p,collection(),i18n("Collected Notes")); - KDialogBase *dlg = new KDialogBase( p, 0, false, i18n("Collected Notes"), - KDialogBase::Close, KDialogBase::Close ); - TQTextView *text = new TQTextView(dlg); - text->setText(collection()); - dlg->setMainWidget(text); - dlg->setMinimumWidth(300); - dlg->setMinimumHeight(300); - dlg->show(); -} - -//---------------------------------------------------------------------------- -KScoringExpression::KScoringExpression(const TQString& h, const TQString& t, const TQString& n, const TQString& ng) - : header(h), expr_str(n) -{ - if (t == "MATCH" ) { - cond = MATCH; - expr.setPattern(expr_str); - expr.setCaseSensitive(false); - } - else if ( t == "MATCHCS" ) { - cond = MATCHCS; - expr.setPattern( expr_str ); - expr.setCaseSensitive( true ); - } - else if (t == "CONTAINS" ) cond = CONTAINS; - else if (t == "ETQUALS" ) cond = ETQUALS; - else if (t == "GREATER") { - cond = GREATER; - expr_int = expr_str.toInt(); - } - else if (t == "SMALLER") { - cond = SMALLER; - expr_int = expr_str.toInt(); - } - else { - kdDebug(5100) << "unknown match type in new expression" << endl; - } - - neg = ng.toInt(); - c_header = header.latin1(); - - kdDebug(5100) << "new expr: " << c_header << " " << t << " " - << expr_str << " " << neg << endl; -} - -// static -int KScoringExpression::getConditionForName(const TQString& s) -{ - if (s == getNameForCondition(CONTAINS)) return CONTAINS; - else if (s == getNameForCondition(MATCH)) return MATCH; - else if (s == getNameForCondition(MATCHCS)) return MATCHCS; - else if (s == getNameForCondition(ETQUALS)) return ETQUALS; - else if (s == getNameForCondition(SMALLER)) return SMALLER; - else if (s == getNameForCondition(GREATER)) return GREATER; - else { - kdWarning(5100) << "unknown condition name " << s - << " in KScoringExpression::getConditionForName()" << endl; - return -1; - } -} - -// static -TQString KScoringExpression::getNameForCondition(int cond) -{ - switch (cond) { - case CONTAINS: return i18n("Contains Substring"); - case MATCH: return i18n("Matches Regular Expression"); - case MATCHCS: return i18n("Matches Regular Expression (Case Sensitive)"); - case ETQUALS: return i18n("Is Exactly the Same As"); - case SMALLER: return i18n("Less Than"); - case GREATER: return i18n("Greater Than"); - default: - kdWarning(5100) << "unknown condition " << cond - << " in KScoringExpression::getNameForCondition()" << endl; - return ""; - } -} - -// static -TQStringList KScoringExpression::conditionNames() -{ - TQStringList l; - l << getNameForCondition(CONTAINS); - l << getNameForCondition(MATCH); - l << getNameForCondition(MATCHCS); - l << getNameForCondition(ETQUALS); - l << getNameForCondition(SMALLER); - l << getNameForCondition(GREATER); - return l; -} - -// static -TQStringList KScoringExpression::headerNames() -{ - TQStringList l; - l.append("From"); - l.append("Message-ID"); - l.append("Subject"); - l.append("Date"); - l.append("References"); - l.append("NNTP-Posting-Host"); - l.append("Bytes"); - l.append("Lines"); - l.append("Xref"); - return l; -} - -KScoringExpression::~KScoringExpression() -{ -} - -bool KScoringExpression::match(ScorableArticle& a) const -{ - //kdDebug(5100) << "matching against header " << c_header << endl; - bool res = true; - TQString head; - - if (header == "From") - head = a.from(); - else if (header == "Subject") - head = a.subject(); - else - head = a.getHeaderByType(c_header); - - if (!head.isEmpty()) { - switch (cond) { - case ETQUALS: - res = (head.lower() == expr_str.lower()); - break; - case CONTAINS: - res = (head.lower().find(expr_str.lower()) >= 0); - break; - case MATCH: - case MATCHCS: - res = (expr.search(head)!=-1); - break; - case GREATER: - res = (head.toInt() > expr_int); - break; - case SMALLER: - res = (head.toInt() < expr_int); - break; - default: - kdDebug(5100) << "unknown match" << endl; - res = false; - } - } - else res = false; -// kdDebug(5100) << "matching returns " << res << endl; - return (neg)?!res:res; -} - -void KScoringExpression::write(TQTextStream& st) const -{ - st << toString(); -} - -TQString KScoringExpression::toString() const -{ -// kdDebug(5100) << "KScoringExpression::toString() starts" << endl; -// kdDebug(5100) << "header is " << header << endl; -// kdDebug(5100) << "expr is " << expr_str << endl; -// kdDebug(5100) << "neg is " << neg << endl; -// kdDebug(5100) << "type is " << getType() << endl; - TQString e; - e += ""; -// kdDebug(5100) << "KScoringExpression::toString() finished" << endl; - return e; -} - -TQString KScoringExpression::getTypeString() const -{ - return KScoringExpression::getTypeString(cond); -} - -TQString KScoringExpression::getTypeString(int cond) -{ - switch (cond) { - case CONTAINS: return "CONTAINS"; - case MATCH: return "MATCH"; - case MATCHCS: return "MATCHCS"; - case ETQUALS: return "ETQUALS"; - case SMALLER: return "SMALLER"; - case GREATER: return "GREATER"; - default: - kdWarning(5100) << "unknown cond " << cond << " in KScoringExpression::getTypeString()" << endl; - return ""; - } -} - -int KScoringExpression::getType() const -{ - return cond; -} - -//---------------------------------------------------------------------------- -KScoringRule::KScoringRule(const TQString& n ) - : name(n), link(AND) -{ - expressions.setAutoDelete(true); - actions.setAutoDelete(true); -} - -KScoringRule::KScoringRule(const KScoringRule& r) -{ - kdDebug(5100) << "copying rule " << r.getName() << endl; - name = r.getName(); - expressions.setAutoDelete(true); - actions.setAutoDelete(true); - // copy expressions - expressions.clear(); - const ScoreExprList& rexpr = r.expressions; - TQPtrListIterator it(rexpr); - for ( ; it.current(); ++it ) { - KScoringExpression *t = new KScoringExpression(**it); - expressions.append(t); - } - // copy actions - actions.clear(); - const ActionList& ract = r.actions; - TQPtrListIterator ait(ract); - for ( ; ait.current(); ++ait ) { - ActionBase *t = *ait; - actions.append(t->clone()); - } - // copy groups, servers, linkmode and expires - groups = r.groups; - expires = r.expires; - link = r.link; -} - -KScoringRule::~KScoringRule() -{ - cleanExpressions(); - cleanActions(); -} - -void KScoringRule::cleanExpressions() -{ - // the expressions is setAutoDelete(true) - expressions.clear(); -} - -void KScoringRule::cleanActions() -{ - // the actions is setAutoDelete(true) - actions.clear(); -} - -void KScoringRule::addExpression( KScoringExpression* expr) -{ - kdDebug(5100) << "KScoringRule::addExpression" << endl; - expressions.append(expr); -} - -void KScoringRule::addAction(int type, const TQString& val) -{ - ActionBase *action = ActionBase::factory(type,val); - addAction(action); -} - -void KScoringRule::addAction(ActionBase* a) -{ - kdDebug(5100) << "KScoringRule::addAction() " << a->toString() << endl; - actions.append(a); -} - -void KScoringRule::setLinkMode(const TQString& l) -{ - if (l == "OR") link = OR; - else link = AND; -} - -void KScoringRule::setExpire(const TQString& e) -{ - if (e != "never") { - TQStringList l = TQStringList::split("-",e); - Q_ASSERT( l.count() == 3 ); - expires.setYMD( (*(l.at(0))).toInt(), - (*(l.at(1))).toInt(), - (*(l.at(2))).toInt()); - } - kdDebug(5100) << "Rule " << getName() << " expires at " << getExpireDateString() << endl; -} - -bool KScoringRule::matchGroup(const TQString& group) const -{ - for(GroupList::ConstIterator i=groups.begin(); i!=groups.end();++i) { - TQRegExp e(*i); - if (e.search(group, 0) != -1 && - (uint)e.matchedLength() == group.length()) - return true; - } - return false; -} - -void KScoringRule::applyAction(ScorableArticle& a) const -{ - TQPtrListIterator it(actions); - for(; it.current(); ++it) { - it.current()->apply(a); - } -} - -void KScoringRule::applyRule(ScorableArticle& a) const -{ - // kdDebug(5100) << "checking rule " << name << endl; - // kdDebug(5100) << " for article from " - // << a->from()->asUnicodeString() - // << endl; - bool oper_and = (link == AND); - bool res = true; - TQPtrListIterator it(expressions); - //kdDebug(5100) << "checking " << expressions.count() << " expressions" << endl; - for (; it.current(); ++it) { - Q_ASSERT( it.current() ); - res = it.current()->match(a); - if (!res && oper_and) return; - else if (res && !oper_and) break; - } - if (res) applyAction(a); -} - -void KScoringRule::applyRule(ScorableArticle& a /*, const TQString& s*/, const TQString& g) const -{ - // check if one of the groups match - for (TQStringList::ConstIterator i = groups.begin(); i != groups.end(); ++i) { - if (TQRegExp(*i).search(g) != -1) { - applyRule(a); - return; - } - } -} - -void KScoringRule::write(TQTextStream& s) const -{ - s << toString(); -} - -TQString KScoringRule::toString() const -{ - //kdDebug(5100) << "KScoringRule::toString() starts" << endl; - TQString r; - r += ""; - //kdDebug(5100) << "building grouplist..." << endl; - for(GroupList::ConstIterator i=groups.begin();i!=groups.end();++i) { - r += ""; - } - //kdDebug(5100) << "building expressionlist..." << endl; - TQPtrListIterator eit(expressions); - for (; eit.current(); ++eit) { - r += eit.current()->toString(); - } - //kdDebug(5100) << "building actionlist..." << endl; - TQPtrListIterator ait(actions); - for (; ait.current(); ++ait) { - r += ait.current()->toString(); - } - r += ""; - //kdDebug(5100) << "KScoringRule::toString() finished" << endl; - return r; -} - -TQString KScoringRule::getLinkModeName() const -{ - switch (link) { - case AND: return "AND"; - case OR: return "OR"; - default: return "AND"; - } -} - -TQString KScoringRule::getExpireDateString() const -{ - if (expires.isNull()) return "never"; - else { - return TQString::number(expires.year()) + TQString("-") - + TQString::number(expires.month()) + TQString("-") - + TQString::number(expires.day()); - } -} - -bool KScoringRule::isExpired() const -{ - return (expires.isValid() && (expires < TQDate::tqcurrentDate())); -} - - - -//---------------------------------------------------------------------------- -KScoringManager::KScoringManager(const TQString& appName) - : cacheValid(false)//, _s(0) -{ - allRules.setAutoDelete(true); - // determine filename of the scorefile - if(appName.isEmpty()) - mFilename = KGlobal::dirs()->saveLocation("appdata") + "/scorefile"; - else - mFilename = KGlobal::dirs()->saveLocation("data") + "/" + appName + "/scorefile"; - // open the score file - load(); -} - - -KScoringManager::~KScoringManager() -{ -} - -void KScoringManager::load() -{ - TQDomDocument sdoc("Scorefile"); - TQFile f( mFilename ); - if ( !f.open( IO_ReadOnly ) ) - return; - if ( !sdoc.setContent( &f ) ) { - f.close(); - kdDebug(5100) << "loading the scorefile failed" << endl; - return; - } - f.close(); - kdDebug(5100) << "loaded the scorefile, creating internal representation" << endl; - allRules.clear(); - createInternalFromXML(sdoc); - expireRules(); - kdDebug(5100) << "ready, got " << allRules.count() << " rules" << endl; -} - -void KScoringManager::save() -{ - kdDebug(5100) << "KScoringManager::save() starts" << endl; - TQFile f( mFilename ); - if ( !f.open( IO_WriteOnly ) ) - return; - TQTextStream stream(&f); - stream.setEncoding(TQTextStream::Unicode); - kdDebug(5100) << "KScoringManager::save() creating xml" << endl; - createXMLfromInternal().save(stream,2); - kdDebug(5100) << "KScoringManager::save() finished" << endl; -} - -TQDomDocument KScoringManager::createXMLfromInternal() -{ - // I was'nt able to create a TQDomDocument in memory:( - // so I write the content into a string, which is really stupid - TQDomDocument sdoc("Scorefile"); - TQString ss; // scorestring - ss += ""; - ss += toString(); - ss += "\n"; - kdDebug(5100) << "KScoringManager::createXMLfromInternal():" << endl << ss << endl; - sdoc.setContent(ss); - return sdoc; -} - -TQString KScoringManager::toString() const -{ - TQString s; - s += "\n"; - TQPtrListIterator it(allRules); - for( ; it.current(); ++it) { - s += it.current()->toString(); - } - return s; -} - -void KScoringManager::expireRules() -{ - for ( KScoringRule *cR = allRules.first(); cR; cR=allRules.next()) { - if (cR->isExpired()) { - kdDebug(5100) << "Rule " << cR->getName() << " is expired, deleting it" << endl; - allRules.remove(); - } - } -} - -void KScoringManager::createInternalFromXML(TQDomNode n) -{ - static KScoringRule *cR = 0; // the currentRule - // the XML file was parsed and now we simply traverse the resulting tree - if ( !n.isNull() ) { - kdDebug(5100) << "inspecting node of type " << n.nodeType() - << " named " << n.toElement().tagName() << endl; - - switch (n.nodeType()) { - case TQDomNode::DocumentNode: { - // the document itself - break; - } - case TQDomNode::ElementNode: { - // Server, Newsgroup, Rule, Expression, Action - TQDomElement e = n.toElement(); - //kdDebug(5100) << "The name of the element is " - //<< e.tagName().latin1() << endl; - TQString s = e.tagName(); - if (s == "Rule") { - cR = new KScoringRule(e.attribute("name")); - cR->setLinkMode(e.attribute("linkmode")); - cR->setExpire(e.attribute("expires")); - addRuleInternal(cR); - } - else if (s == "Group") { - Q_CHECK_PTR(cR); - cR->addGroup( e.attribute("name") ); - } - else if (s == "Expression") { - cR->addExpression(new KScoringExpression(e.attribute("header"), - e.attribute("type"), - e.attribute("expr"), - e.attribute("neg"))); - } - else if (s == "Action") { - Q_CHECK_PTR(cR); - cR->addAction(ActionBase::getTypeForName(e.attribute("type")), - e.attribute("value")); - } - break; - } - default: // kdDebug(5100) << "unknown DomNode::type" << endl; - ; - } - TQDomNodeList nodelist = n.childNodes(); - unsigned cnt = nodelist.count(); - //kdDebug(5100) << "recursive checking " << cnt << " nodes" << endl; - for (unsigned i=0;iaddGroup( group ); - rule->addExpression( - new KScoringExpression("From","CONTAINS", - a.from(),"0")); - if (score) rule->addAction(new ActionSetScore(score)); - rule->setExpireDate(TQDate::tqcurrentDate().addDays(30)); - addRule(rule); - KScoringEditor *edit = KScoringEditor::createEditor(this); - edit->setRule(rule); - edit->show(); - setCacheValid(false); - return rule; -} - -KScoringRule* KScoringManager::addRule(KScoringRule* expr) -{ - int i = allRules.findRef(expr); - if (i == -1) { - // only add a rule we don't know - addRuleInternal(expr); - } - else { - emit changedRules(); - } - return expr; -} - -KScoringRule* KScoringManager::addRule() -{ - KScoringRule *rule = new KScoringRule(findUniqueName()); - addRule(rule); - return rule; -} - -void KScoringManager::addRuleInternal(KScoringRule *e) -{ - allRules.append(e); - setCacheValid(false); - emit changedRules(); - kdDebug(5100) << "KScoringManager::addRuleInternal " << e->getName() << endl; -} - -void KScoringManager::cancelNewRule(KScoringRule *r) -{ - // if e was'nt previously added to the list of rules, we delete it - int i = allRules.findRef(r); - if (i == -1) { - kdDebug(5100) << "deleting rule " << r->getName() << endl; - deleteRule(r); - } - else { - kdDebug(5100) << "rule " << r->getName() << " not deleted" << endl; - } -} - -void KScoringManager::setRuleName(KScoringRule *r, const TQString& s) -{ - bool cont = true; - TQString text = s; - TQString oldName = r->getName(); - while (cont) { - cont = false; - TQPtrListIterator it(allRules); - for (; it.current(); ++it) { - if ( it.current() != r && it.current()->getName() == text ) { - kdDebug(5100) << "rule name " << text << " is not unique" << endl; - text = KInputDialog::getText(i18n("Choose Another Rule Name"), - i18n("The rule name is already assigned, please choose another name:"), - text); - cont = true; - break; - } - } - } - if (text != oldName) { - r->setName(text); - emit changedRuleName(oldName,text); - } -} - -void KScoringManager::deleteRule(KScoringRule *r) -{ - int i = allRules.findRef(r); - if (i != -1) { - allRules.remove(); - emit changedRules(); - } -} - -void KScoringManager::editRule(KScoringRule *e, TQWidget *w) -{ - KScoringEditor *edit = KScoringEditor::createEditor(this, w); - edit->setRule(e); - edit->show(); - delete edit; -} - -void KScoringManager::moveRuleAbove( KScoringRule *above, KScoringRule *below ) -{ - int aindex = allRules.findRef( above ); - int bindex = allRules.findRef( below ); - if ( aindex <= 0 || bindex < 0 ) - return; - if ( aindex < bindex ) - --bindex; - allRules.take( aindex ); - allRules.insert( bindex, above ); -} - -void KScoringManager::moveRuleBelow( KScoringRule *below, KScoringRule *above ) -{ - int bindex = allRules.findRef( below ); - int aindex = allRules.findRef( above ); - if ( bindex < 0 || bindex >= (int)allRules.count() - 1 || aindex < 0 ) - return; - if ( bindex < aindex ) - --aindex; - allRules.take( bindex ); - allRules.insert( aindex + 1, below ); -} - -void KScoringManager::editorReady() -{ - kdDebug(5100) << "emitting signal finishedEditing" << endl; - save(); - emit finishedEditing(); -} - -KScoringRule* KScoringManager::copyRule(KScoringRule *r) -{ - KScoringRule *rule = new KScoringRule(*r); - rule->setName(findUniqueName()); - addRuleInternal(rule); - return rule; -} - -void KScoringManager::applyRules(ScorableGroup* ) -{ - kdWarning(5100) << "KScoringManager::applyRules(ScorableGroup* ) isn't implemented" << endl; -} - -void KScoringManager::applyRules(ScorableArticle& article, const TQString& group) -{ - setGroup(group); - applyRules(article); -} - -void KScoringManager::applyRules(ScorableArticle& a) -{ - TQPtrListIterator it(isCacheValid()? ruleList : allRules); - for( ; it.current(); ++it) { - it.current()->applyRule(a); - } -} - -void KScoringManager::initCache(const TQString& g) -{ - group = g; - ruleList.clear(); - TQPtrListIterator it(allRules); - for (; it.current(); ++it) { - if ( it.current()->matchGroup(group) ) { - ruleList.append(it.current()); - } - } - kdDebug(5100) << "created cache for group " << group - << " with " << ruleList.count() << " rules" << endl; - setCacheValid(true); -} - -void KScoringManager::setGroup(const TQString& g) -{ - if (group != g) initCache(g); -} - -bool KScoringManager::hasRulesForCurrentGroup() -{ - return ruleList.count() != 0; -} - - -TQStringList KScoringManager::getRuleNames() -{ - TQStringList l; - TQPtrListIterator it(allRules); - for( ; it.current(); ++it) { - l << it.current()->getName(); - } - return l; -} - -KScoringRule* KScoringManager::findRule(const TQString& ruleName) -{ - TQPtrListIterator it(allRules); - for (; it.current(); ++it) { - if ( it.current()->getName() == ruleName ) { - return it; - } - } - return 0; -} - -bool KScoringManager::setCacheValid(bool v) -{ - bool res = cacheValid; - cacheValid = v; - return res; -} - -TQString KScoringManager::findUniqueName() const -{ - int nr = 0; - TQString ret; - bool duplicated=false; - - while (nr < 99999999) { - nr++; - ret = i18n("rule %1").tqarg(nr); - - duplicated=false; - TQPtrListIterator it(allRules); - for( ; it.current(); ++it) { - if (it.current()->getName() == ret) { - duplicated = true; - break; - } - } - - if (!duplicated) - return ret; - } - - return ret; -} - -bool KScoringManager::hasFeature(int p) -{ - switch (p) { - case ActionBase::SETSCORE: return canScores(); - case ActionBase::NOTIFY: return canNotes(); - case ActionBase::COLOR: return canColors(); - case ActionBase::MARKASREAD: return canMarkAsRead(); - default: return false; - } -} - -TQStringList KScoringManager::getDefaultHeaders() const -{ - TQStringList l; - l.append("Subject"); - l.append("From"); - l.append("Date"); - l.append("Message-ID"); - return l; -} - -void KScoringManager::pushRuleList() -{ - stack.push(allRules); -} - -void KScoringManager::popRuleList() -{ - stack.pop(allRules); -} - -void KScoringManager::removeTOS() -{ - stack.drop(); -} - -RuleStack::RuleStack() -{ -} - -RuleStack::~RuleStack() -{} - -void RuleStack::push(TQPtrList& l) -{ - kdDebug(5100) << "RuleStack::push pushing list with " << l.count() << " rules" << endl; - KScoringManager::ScoringRuleList *l1 = new KScoringManager::ScoringRuleList; - for ( KScoringRule *r=l.first(); r != 0; r=l.next() ) { - l1->append(new KScoringRule(*r)); - } - stack.push(l1); - kdDebug(5100) << "now there are " << stack.count() << " lists on the stack" << endl; -} - -void RuleStack::pop(TQPtrList& l) -{ - top(l); - drop(); - kdDebug(5100) << "RuleStack::pop pops list with " << l.count() << " rules" << endl; - kdDebug(5100) << "now there are " << stack.count() << " lists on the stack" << endl; -} - -void RuleStack::top(TQPtrList& l) -{ - l.clear(); - KScoringManager::ScoringRuleList *l1 = stack.top(); - l = *l1; -} - -void RuleStack::drop() -{ - kdDebug(5100) << "drop: now there are " << stack.count() << " lists on the stack" << endl; - stack.remove(); -} - - -#include "kscoring.moc" diff --git a/libkdepim/kscoring.h b/libkdepim/kscoring.h deleted file mode 100644 index 7225eb93f..000000000 --- a/libkdepim/kscoring.h +++ /dev/null @@ -1,429 +0,0 @@ -/* - kscoring.h - - Copyright (c) 2001 Mathias Waack - Copyright (C) 2005 by Volker Krause - - Author: Mathias Waack - - 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. - 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, US -*/ - -#ifndef KSCORING_H -#define KSCORING_H - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -class TQDomNode; -class TQDomDocument; -class TQDomElement; -class TQTextStream; -class TQLabel; - - -/** - The following classes ScorableArticle, ScorableGroup define - the interface for the scoring. Any application using this mechanism should - create its own subclasses of this classes. The scoring itself will be handled - by the ScoringManager class. - */ - -//---------------------------------------------------------------------------- -class KDE_EXPORT ScorableGroup -{ -public: - virtual ~ScorableGroup(); -}; - -class KDE_EXPORT ScorableArticle -{ -public: - virtual ~ScorableArticle(); - - virtual void addScore(short) {} - virtual void displayMessage(const TQString&); - virtual void changeColor(const TQColor&) {} - virtual void markAsRead() {} - virtual TQString from() const = 0; - virtual TQString subject() const = 0; - virtual TQString getHeaderByType(const TQString&) const = 0; - //virtual ScorableGroup group() const =0; -}; - - -//---------------------------------------------------------------------------- -/** - Base class for other Action classes. - */ -class KDE_EXPORT ActionBase { - public: - ActionBase(); - virtual ~ActionBase(); - virtual TQString toString() const =0; - virtual void apply(ScorableArticle&) const =0; - virtual ActionBase* clone() const =0; - virtual int getType() const =0; - virtual TQString getValueString() const { return TQString(); } - virtual void setValue(const TQString&) {} - static ActionBase* factory(int type, const TQString &value); - static TQStringList userNames(); - static TQString userName(int type); - static int getTypeForName(const TQString& name); - static int getTypeForUserName(const TQString& name); - TQString userName() { return userName(getType()); } - enum ActionTypes { SETSCORE, NOTIFY, COLOR, MARKASREAD }; -}; - -class KDE_EXPORT ActionColor : public ActionBase { -public: - ActionColor(const TQColor&); - ActionColor(const TQString&); - ActionColor(const ActionColor&); - virtual ~ActionColor(); - virtual TQString toString() const; - virtual int getType() const { return COLOR; } - virtual TQString getValueString() const { return color.name(); } - virtual void setValue(const TQString& s) { color.setNamedColor(s); } - void setValue(const TQColor& c) { color = c; } - TQColor value() const { return color; } - virtual void apply(ScorableArticle&) const; - virtual ActionColor* clone() const; -private: - TQColor color; -}; - -class KDE_EXPORT ActionSetScore : public ActionBase { - public: - ActionSetScore(short); - ActionSetScore(const ActionSetScore&); - ActionSetScore(const TQString&); - virtual ~ActionSetScore(); - virtual TQString toString() const; - virtual int getType() const { return SETSCORE; } - virtual TQString getValueString() const { return TQString::number(val); } - virtual void setValue(const TQString& s) { val = s.toShort(); } - void setValue(short v) { val = v; } - short value() const { return val; } - virtual void apply(ScorableArticle&) const; - virtual ActionSetScore* clone() const; - private: - short val; -}; - -class KDE_EXPORT ActionNotify : public ActionBase { - public: - ActionNotify(const TQString&); - ActionNotify(const ActionNotify&); - virtual ~ActionNotify() {} - virtual TQString toString() const; - virtual int getType() const { return NOTIFY; } - virtual TQString getValueString() const { return note; } - virtual void setValue(const TQString& s) { note = s; } - virtual void apply(ScorableArticle&) const; - virtual ActionNotify* clone() const; - private: - TQString note; -}; - -class KDE_EXPORT ActionMarkAsRead : public ActionBase { - public: - ActionMarkAsRead(); - ActionMarkAsRead( const ActionMarkAsRead& ); - virtual ~ActionMarkAsRead() {} - virtual TQString toString() const; - virtual int getType() const { return MARKASREAD; } - virtual void apply( ScorableArticle &article ) const; - virtual ActionMarkAsRead* clone() const; -}; - -class KDE_EXPORT NotifyCollection -{ -public: - NotifyCollection(); - ~NotifyCollection(); - void addNote(const ScorableArticle&, const TQString&); - TQString collection() const; - void displayCollection(TQWidget *p=0) const; -private: - struct article_info { - TQString from; - TQString subject; - }; - typedef TQValueList article_list; - typedef TQDict note_list; - note_list notifyList; -}; - - -//---------------------------------------------------------------------------- -class KDE_EXPORT KScoringExpression -{ - friend class KScoringRule; - public: - enum Condition { CONTAINS, MATCH, ETQUALS, SMALLER, GREATER, MATCHCS }; - - KScoringExpression(const TQString&,const TQString&,const TQString&, const TQString&); - ~KScoringExpression(); - - bool match(ScorableArticle& a) const ; - TQString getTypeString() const; - static TQString getTypeString(int); - int getType() const; - TQString toString() const; - void write(TQTextStream& ) const; - - bool isNeg() const { return neg; } - Condition getCondition() const { return cond; } - TQString getExpression() const { return expr_str; } - TQString getHeader() const { return header; } - static TQStringList conditionNames(); - static TQStringList headerNames(); - static int getConditionForName(const TQString&); - static TQString getNameForCondition(int); - private: - bool neg; - TQString header; - const char* c_header; - Condition cond; - TQRegExp expr; - TQString expr_str; - int expr_int; -}; - -//---------------------------------------------------------------------------- -class KDE_EXPORT KScoringRule -{ - friend class KScoringManager; - public: - KScoringRule(const TQString& name); - KScoringRule(const KScoringRule& r); - ~KScoringRule(); - - typedef TQPtrList ScoreExprList; - typedef TQPtrList ActionList; - typedef TQStringList GroupList; - enum LinkMode { AND, OR }; - - TQString getName() const { return name; } - TQStringList getGroups() const { return groups; } - void setGroups(const TQStringList &l) { groups = l; } - LinkMode getLinkMode() const { return link; } - TQString getLinkModeName() const; - TQString getExpireDateString() const; - TQDate getExpireDate() const { return expires; } - void setExpireDate(const TQDate &d) { expires = d; } - bool isExpired() const; - ScoreExprList getExpressions() const { return expressions; } - ActionList getActions() const { return actions; } - void cleanExpressions(); - void cleanActions(); - - bool matchGroup(const TQString& group) const ; - void applyRule(ScorableArticle& a) const; - void applyRule(ScorableArticle& a, const TQString& group) const; - void applyAction(ScorableArticle& a) const; - - void setLinkMode(const TQString& link); - void setLinkMode(LinkMode m) { link = m; } - void setExpire(const TQString& exp); - void addExpression( KScoringExpression* ); - void addGroup( const TQString& group) { groups.append(group); } - //void addServer(const TQString& server) { servers.append(server); } - void addAction(int, const TQString& ); - void addAction(ActionBase*); - - void updateXML(TQDomElement& e, TQDomDocument& d); - TQString toString() const; - - // writes the rule in XML format into the textstream - void write(TQTextStream& ) const; -protected: - //! assert that the name is unique - void setName(const TQString &n) { name = n; } -private: - TQString name; - GroupList groups; - //ServerList servers; - LinkMode link; - ScoreExprList expressions; - ActionList actions; - TQDate expires; -}; - -/** this helper class implements a stack for lists of lists of rules. - With the help of this class its very easy for the KScoringManager - to temporary drop lists of rules and restore them afterwards -*/ -class KDE_EXPORT RuleStack -{ -public: - RuleStack(); - ~RuleStack(); - //! puts the list on the stack, doesn't change the list - void push(TQPtrList&); - //! clears the argument list and copy the content of the TOS into it - //! after that the TOS gets dropped - void pop(TQPtrList&); - //! like pop but without dropping the TOS - void top(TQPtrList&); - //! drops the TOS - void drop(); -private: - TQPtrStack< TQPtrList > stack; -}; - -//---------------------------------------------------------------------------- -// Manages the score rules. -class KDE_EXPORT KScoringManager : public TQObject -{ - Q_OBJECT - TQ_OBJECT - - public: - //* this is the container for all rules - typedef TQPtrList ScoringRuleList; - - KScoringManager(const TQString& appName = TQString()); - virtual ~KScoringManager(); - - //* returns a list of all available groups, must be overridden - virtual TQStringList getGroups() const =0; - - //! returns a list of common (or available) headers - //! defaults to returning { Subject, From, Message-ID, Date } - virtual TQStringList getDefaultHeaders() const; - - //* setting current server and group and calling applyRules(ScorableArticle&) - void applyRules(ScorableArticle& article, const TQString& group/*, const TQString& server*/); - //* assuming a properly set group - void applyRules(ScorableArticle&); - //* same as above - void applyRules(ScorableGroup* group); - - //* pushes the current rule list onto a stack - void pushRuleList(); - //* restores the current rule list from list stored on a stack - //* by a previous call to pushRuleList (this implicitly deletes the - //* current rule list) - void popRuleList(); - //* removes the TOS from the stack of rule lists - void removeTOS(); - - KScoringRule* addRule(KScoringRule *); - KScoringRule* addRule(const ScorableArticle&, TQString group, short =0); - KScoringRule* addRule(); - void cancelNewRule(KScoringRule *); - void deleteRule(KScoringRule *); - void editRule(KScoringRule *e, TQWidget *w=0); - KScoringRule* copyRule(KScoringRule *); - void moveRuleAbove( KScoringRule *above, KScoringRule *below ); - void moveRuleBelow( KScoringRule *below, KScoringRule *above ); - void setGroup(const TQString& g); - // has to be called after setGroup() or initCache() - bool hasRulesForCurrentGroup(); - TQString findUniqueName() const; - - /** called from an editor whenever it finishes editing the rule base, - causes the finishedEditing signal to be emitted */ - void editorReady(); - - ScoringRuleList getAllRules() const { return allRules; } - KScoringRule *findRule(const TQString&); - TQStringList getRuleNames(); - void setRuleName(KScoringRule *, const TQString&); - int getRuleCount() const { return allRules.count(); } - TQString toString() const; - - bool setCacheValid(bool v); - bool isCacheValid() { return cacheValid; } - void initCache(const TQString& group/*, const TQString& server*/); - - void load(); - void save(); - - //--------------- Properties - virtual bool canScores() const { return true; } - virtual bool canNotes() const { return true; } - virtual bool canColors() const { return false; } - virtual bool canMarkAsRead() const { return false; } - virtual bool hasFeature(int); - - signals: - void changedRules(); - void changedRuleName(const TQString& oldName, const TQString& newName); - void finishedEditing(); - - private: - void addRuleInternal(KScoringRule *e); - void expireRules(); - - TQDomDocument createXMLfromInternal(); - void createInternalFromXML(TQDomNode); - - // list of all Rules - ScoringRuleList allRules; - - // the stack for temporary storing rule lists - RuleStack stack; - - // for the cache - bool cacheValid; - // current rule set, ie the cache - ScoringRuleList ruleList; - //TQString server; - TQString group; - - //ScorableServer* _s; - - // filename of the scorefile - TQString mFilename; -}; - - -//---------------------------------------------------------------------------- -class KDE_EXPORT NotifyDialog : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT -public: - static void display(ScorableArticle&,const TQString&); -protected slots: - void slotShowAgainToggled(bool); -private: - NotifyDialog(TQWidget* p =0); - static NotifyDialog *me; - - TQLabel *note; - TQString msg; - typedef TQMap NotesMap; - static NotesMap dict; -}; - - -#endif diff --git a/libkdepim/kscoringeditor.cpp b/libkdepim/kscoringeditor.cpp deleted file mode 100644 index 6e520e983..000000000 --- a/libkdepim/kscoringeditor.cpp +++ /dev/null @@ -1,1029 +0,0 @@ -/* - kscoringeditor.cpp - - Copyright (c) 2001 Mathias Waack - Copyright (C) 2005 by Volker Krause - - Author: Mathias Waack - - 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. - 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, US -*/ - -#undef TQT_NO_COMPAT - -#include "kscoring.h" -#include "kscoringeditor.h" - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// works for both ListBox and ComboBox -template static int setCurrentItem(T *box, const TQString& s) -{ - int cnt = box->count(); - for (int i=0;itext(i) == s) { - box->setCurrentItem(i); - return i; - } - } - return -1; -} - - -//============================================================================ -// -// class SingleConditionWidget (editor for one condition, used in ConditionEditWidget) -// -//============================================================================ -SingleConditionWidget::SingleConditionWidget(KScoringManager *m,TQWidget *p, const char *n) - : TQFrame(p,n), manager(m) -{ - TQBoxLayout *topL = new TQVBoxLayout(this,5); - TQBoxLayout *firstRow = new TQHBoxLayout(topL); - neg = new TQCheckBox(i18n("Not"),this); - TQToolTip::add(neg,i18n("Negate this condition")); - firstRow->addWidget(neg); - headers = new KComboBox(this); - headers->insertStringList(manager->getDefaultHeaders()); - headers->setEditable( true ); - TQToolTip::add(headers,i18n("Select the header to match this condition against")); - firstRow->addWidget(headers,1); - matches = new KComboBox(this); - matches->insertStringList(KScoringExpression::conditionNames()); - TQToolTip::add(matches,i18n("Select the type of match")); - firstRow->addWidget(matches,1); - connect( matches, TQT_SIGNAL( activated( int ) ), TQT_SLOT( toggleRegExpButton( int ) ) ); - TQHBoxLayout *secondRow = new TQHBoxLayout( topL ); - secondRow->setSpacing( 1 ); - expr = new KLineEdit( this ); - TQToolTip::add(expr,i18n("The condition for the match")); - // reserve space for at least 20 characters - expr->setMinimumWidth(fontMetrics().maxWidth()*20); - secondRow->addWidget( expr ); - regExpButton = new TQPushButton( i18n("Edit..."), this ); - secondRow->addWidget( regExpButton ); - connect( regExpButton, TQT_SIGNAL( clicked() ), TQT_SLOT( showRegExpDialog() ) ); - - // occupy at much width as possible - tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Fixed)); - setFrameStyle(Box | Sunken); - setLineWidth(1); -} - -SingleConditionWidget::~SingleConditionWidget() -{} - -void SingleConditionWidget::setCondition(KScoringExpression *e) -{ - neg->setChecked(e->isNeg()); - headers->setCurrentText( e->getHeader() ); - setCurrentItem(matches,KScoringExpression::getNameForCondition(e->getCondition())); - toggleRegExpButton( matches->currentItem() ); - expr->setText(e->getExpression()); -} - -KScoringExpression* SingleConditionWidget::createCondition() const -{ - TQString head = headers->currentText(); - TQString match = matches->currentText(); - int condType = KScoringExpression::getConditionForName(match); - match = KScoringExpression::getTypeString(condType); - TQString cond = expr->text(); - TQString negs = (neg->isChecked())?"1":"0"; - return new KScoringExpression(head,match,cond,negs); -} - -void SingleConditionWidget::clear() -{ - neg->setChecked(false); - expr->clear(); -} - -void SingleConditionWidget::toggleRegExpButton( int selected ) -{ - bool isRegExp = (KScoringExpression::MATCH == selected || - KScoringExpression::MATCHCS == selected) && - !KTrader::self()->query("KRegExpEditor/KRegExpEditor").isEmpty(); - regExpButton->setEnabled( isRegExp ); -} - -void SingleConditionWidget::showRegExpDialog() -{ - TQDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery( "KRegExpEditor/KRegExpEditor" ); - if ( editorDialog ) { - KRegExpEditorInterface *editor = static_cast( editorDialog->qt_cast( "KRegExpEditorInterface" ) ); - Q_ASSERT( editor ); // This should not fail! - editor->setRegExp( expr->text() ); - editorDialog->exec(); - expr->setText( editor->regExp() ); - } -} - -//============================================================================ -// -// class ConditionEditWidget (the widget to edit the conditions of a rule) -// -//============================================================================ -ConditionEditWidget::ConditionEditWidget(KScoringManager *m, TQWidget *p, const char *n) - : KWidgetLister(1,8,p,n), manager(m) -{ - // create one initial widget - addWidgetAtEnd(); -} - -ConditionEditWidget::~ConditionEditWidget() -{} - -TQWidget* ConditionEditWidget::createWidget(TQWidget *parent) -{ - return new SingleConditionWidget(manager,parent); -} - -void ConditionEditWidget::clearWidget(TQWidget *w) -{ - Q_ASSERT( w->isA("SingleConditionWidget") ); - SingleConditionWidget *sw = dynamic_cast(w); - if (sw) - sw->clear(); -} - -void ConditionEditWidget::slotEditRule(KScoringRule *rule) -{ - KScoringRule::ScoreExprList l; - if (rule) l = rule->getExpressions(); - if (!rule || l.count() == 0) { - slotClear(); - } else { - setNumberOfShownWidgetsTo(l.count()); - KScoringExpression *e = l.first(); - SingleConditionWidget *scw = static_cast(mWidgetList.first()); - while (e && scw) { - scw->setCondition(e); - e = l.next(); - scw = static_cast(mWidgetList.next()); - } - } -} - -void ConditionEditWidget::updateRule(KScoringRule *rule) -{ - rule->cleanExpressions(); - for(TQWidget *w = mWidgetList.first(); w; w = mWidgetList.next()) { - if (! w->isA("SingleConditionWidget")) { - kdWarning(5100) << "there is a widget in ConditionEditWidget " - << "which isn't a SingleConditionWidget" << endl; - } else { - SingleConditionWidget *saw = dynamic_cast(w); - if (saw) - rule->addExpression(saw->createCondition()); - } - } -} - -//============================================================================ -// -// class SingleActionWidget (editor for one action, used in ActionEditWidget) -// -//============================================================================ -SingleActionWidget::SingleActionWidget(KScoringManager *m,TQWidget *p, const char *n) - : TQWidget(p,n), notifyEditor(0), scoreEditor(0), colorEditor(0),manager(m) -{ - TQHBoxLayout *topL = new TQHBoxLayout(this,0,5); - types = new KComboBox(this); - types->setEditable(false); - topL->addWidget(types); - stack = new TQWidgetStack(this); - topL->addWidget(stack); - - dummyLabel = new TQLabel(i18n("Select an action."), stack); - stack->addWidget(dummyLabel, 0); - - // init widget stack and the types combo box - int index = 1; - types->insertItem(TQString()); - TQStringList l = ActionBase::userNames(); - for ( TQStringList::Iterator it = l.begin(); it != l.end(); ++it ) { - TQString name = *it; - int feature = ActionBase::getTypeForUserName(name); - if (manager->hasFeature(feature)) { - types->insertItem(name); - TQWidget *w=0; - switch (feature) { - case ActionBase::SETSCORE: - w = scoreEditor = new KIntSpinBox(-99999,99999,1,0,10, stack); - break; - case ActionBase::NOTIFY: - w = notifyEditor = new KLineEdit(stack); - break; - case ActionBase::COLOR: - w = colorEditor = new KColorCombo(stack); - break; - case ActionBase::MARKASREAD: - w = new TQLabel( stack ); // empty dummy - break; - } - if ( w ) - stack->addWidget(w,index++); - } - } - - connect(types,TQT_SIGNAL(activated(int)),stack,TQT_SLOT(raiseWidget(int))); - - // raise the dummy label - types->setCurrentItem(0); - stack->raiseWidget(dummyLabel); -} - -SingleActionWidget::~SingleActionWidget() -{ -} - -void SingleActionWidget::setAction(ActionBase *act) -{ - kdDebug(5100) << "SingleActionWidget::setAction()" << endl; - setCurrentItem(types,ActionBase::userName(act->getType())); - int index = types->currentItem(); - stack->raiseWidget(index); - switch (act->getType()) { - case ActionBase::SETSCORE: - scoreEditor->setValue(act->getValueString().toInt()); - break; - case ActionBase::NOTIFY: - notifyEditor->setText(act->getValueString()); - break; - case ActionBase::COLOR: - colorEditor->setColor(TQColor(act->getValueString())); - break; - case ActionBase::MARKASREAD: - // nothing - break; - default: - kdWarning(5100) << "unknown action type in SingleActionWidget::setAction()" << endl; - } -} - -ActionBase* SingleActionWidget::createAction() const -{ - // no action selected... - if (types->currentText().isEmpty()) - return 0; - - int type = ActionBase::getTypeForUserName(types->currentText()); - switch (type) { - case ActionBase::SETSCORE: - return new ActionSetScore(scoreEditor->value()); - case ActionBase::NOTIFY: - return new ActionNotify(notifyEditor->text()); - case ActionBase::COLOR: - return new ActionColor(TQString(colorEditor->color().name())); - case ActionBase::MARKASREAD: - return new ActionMarkAsRead(); - default: - kdWarning(5100) << "unknown action type in SingleActionWidget::getValue()" << endl; - return 0; - } -} - -void SingleActionWidget::clear() -{ - if (scoreEditor) scoreEditor->setValue(0); - if (notifyEditor) notifyEditor->clear(); - if (colorEditor) colorEditor->setCurrentItem(0); - types->setCurrentItem(0); - stack->raiseWidget(dummyLabel); -} - -//============================================================================ -// -// class ActionEditWidget (the widget to edit the actions of a rule) -// -//============================================================================ -ActionEditWidget::ActionEditWidget(KScoringManager *m,TQWidget *p, const char *n) - : KWidgetLister(1,8,p,n), manager(m) -{ - // create one initial widget - addWidgetAtEnd(); -} - -ActionEditWidget::~ActionEditWidget() -{} - -TQWidget* ActionEditWidget::createWidget( TQWidget *parent ) -{ - return new SingleActionWidget(manager,parent); -} - -void ActionEditWidget::slotEditRule(KScoringRule *rule) -{ - KScoringRule::ActionList l; - if (rule) l = rule->getActions(); - if (!rule || l.count() == 0) { - slotClear(); - } else { - setNumberOfShownWidgetsTo(l.count()); - ActionBase *act = l.first(); - SingleActionWidget *saw = static_cast(mWidgetList.first()); - while (act && saw) { - saw->setAction(act); - act = l.next(); - saw = static_cast(mWidgetList.next()); - } - } -} - -void ActionEditWidget::updateRule(KScoringRule *rule) -{ - rule->cleanActions(); - for(TQWidget *w = mWidgetList.first(); w; w = mWidgetList.next()) { - if (! w->isA("SingleActionWidget")) { - kdWarning(5100) << "there is a widget in ActionEditWidget " - << "which isn't a SingleActionWidget" << endl; - } else { - SingleActionWidget *saw = dynamic_cast(w); - if (saw) - { - ActionBase *act = saw->createAction(); - if (act) - rule->addAction(act); - } - } - } -} - -void ActionEditWidget::clearWidget(TQWidget *w) -{ - Q_ASSERT( w->isA("SingleActionWidget") ); - SingleActionWidget *sw = dynamic_cast(w); - if (sw) - sw->clear(); -} - -//============================================================================ -// -// class RuleEditWidget (the widget to edit one rule) -// -//============================================================================ -RuleEditWidget::RuleEditWidget(KScoringManager *m,TQWidget *p, const char *n) - : TQWidget(p,n), dirty(false), manager(m), oldRuleName(TQString()) -{ - kdDebug(5100) << "RuleEditWidget::RuleEditWidget()" << endl; - if ( !n ) setName( "RuleEditWidget" ); - TQVBoxLayout *topLayout = new TQVBoxLayout( this, 5, KDialog::spacingHint() ); - - //------------- Name, Servers, Groups --------------------- - TQGroupBox *groupB = new TQGroupBox(i18n("Properties"),this); - topLayout->addWidget(groupB); - TQGridLayout* groupL = new TQGridLayout(groupB, 6,2, 8,5); - groupL->addRowSpacing(0, fontMetrics().lineSpacing()-4); - - // name - ruleNameEdit = new KLineEdit( groupB, "ruleNameEdit" ); - groupL->addWidget( ruleNameEdit, 1, 1 ); - TQLabel *ruleNameLabel = new TQLabel(ruleNameEdit, i18n("&Name:"), groupB, "ruleNameLabel"); - groupL->addWidget( ruleNameLabel, 1, 0 ); - - // groups - groupsEdit = new KLineEdit( groupB, "groupsEdit" ); - groupL->addWidget( groupsEdit, 2, 1 ); - TQLabel *groupsLabel = new TQLabel(groupsEdit, i18n("&Groups:"), groupB, "groupsLabel"); - groupL->addWidget( groupsLabel, 2, 0 ); - - TQPushButton *groupsBtn = new TQPushButton(i18n("A&dd Group"), groupB); - connect(groupsBtn,TQT_SIGNAL(clicked()),TQT_SLOT(slotAddGroup())); - groupL->addWidget( groupsBtn, 3, 0 ); - - groupsBox = new KComboBox( false, groupB, "groupsBox" ); - groupsBox->setDuplicatesEnabled(false); - groupsBox->insertStringList(manager->getGroups()); - groupsBox->tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed)); - groupL->addWidget( groupsBox, 3, 1 ); - - // expires - expireCheck = new TQCheckBox(i18n("&Expire rule automatically"), groupB); - groupL->addMultiCellWidget( expireCheck, 4,4, 0,1 ); - expireEdit = new KIntSpinBox(1,99999,1,30,10, groupB, "expireWidget"); - //Init suffix - slotExpireEditChanged(30); - connect(expireEdit, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotExpireEditChanged(int))); - groupL->addWidget( expireEdit, 5, 1 ); - expireLabel = new TQLabel(expireEdit, i18n("&Rule is valid for:"), groupB, "expireLabel"); - groupL->addWidget( expireLabel, 5, 0 ); - expireLabel->setEnabled(false); - expireEdit->setEnabled(false); - - connect(expireCheck, TQT_SIGNAL(toggled(bool)), expireLabel, TQT_SLOT(setEnabled(bool))); - connect(expireCheck, TQT_SIGNAL(toggled(bool)), expireEdit, TQT_SLOT(setEnabled(bool))); - - //------------- Conditions --------------------- - TQGroupBox *groupConds = new TQGroupBox(i18n("Conditions"), this); - topLayout->addWidget(groupConds); - TQGridLayout *condL = new TQGridLayout(groupConds, 3,2, 8,5); - - condL->addRowSpacing(0, fontMetrics().lineSpacing()-4); - - TQButtonGroup *buttonGroup = new TQButtonGroup(groupConds); - buttonGroup->hide(); - linkModeAnd = new TQRadioButton(i18n("Match a&ll conditions"), groupConds); - buttonGroup->insert(linkModeAnd); - condL->addWidget(linkModeAnd, 1,0); - linkModeOr = new TQRadioButton(i18n("Matc&h any condition"), groupConds); - buttonGroup->insert(linkModeOr); - condL->addWidget(linkModeOr, 1,1); - linkModeAnd->setChecked(true); - - condEditor = new ConditionEditWidget(manager,groupConds); - condL->addMultiCellWidget(condEditor, 2,2, 0,1); - connect(condEditor,TQT_SIGNAL(widgetRemoved()),this,TQT_SLOT(slotShrink())); - - //------------- Actions --------------------- - TQGroupBox *groupActions = new TQGroupBox(i18n("Actions"), this); - topLayout->addWidget(groupActions); - TQBoxLayout *actionL = new TQVBoxLayout(groupActions,8,5); - actionL->addSpacing(fontMetrics().lineSpacing()-4); - actionEditor = new ActionEditWidget(manager,groupActions); - actionL->addWidget(actionEditor); - connect(actionEditor,TQT_SIGNAL(widgetRemoved()),this,TQT_SLOT(slotShrink())); - - topLayout->addStretch(1); - - kdDebug(5100) << "constructed RuleEditWidget" << endl; -} - -RuleEditWidget::~RuleEditWidget() -{ -} - -void RuleEditWidget::slotEditRule(const TQString& ruleName) -{ - kdDebug(5100) << "RuleEditWidget::slotEditRule(" << ruleName << ")" << endl; -// // first update the old rule if there is one -// kdDebug(5100) << "let see if we have a rule with name " << oldRuleName << endl; -// KScoringRule *rule; -// if (!oldRuleName.isNull() && oldRuleName != ruleName) { -// rule = manager->findRule(oldRuleName); -// if (rule) { -// kdDebug(5100) << "updating rule " << rule->getName() << endl; -// updateRule(rule); -// } -// } - - KScoringRule* rule = manager->findRule(ruleName); - if (!rule) { - kdDebug(5100) << "no rule for ruleName " << ruleName << endl; - clearContents(); - return; - } - oldRuleName = rule->getName(); - ruleNameEdit->setText(rule->getName()); - groupsEdit->setText(rule->getGroups().join(";")); - - bool b = rule->getExpireDate().isValid(); - expireCheck->setChecked(b); - expireEdit->setEnabled(b); - expireLabel->setEnabled(b); - if (b) - expireEdit->setValue(TQDate::tqcurrentDate().daysTo(rule->getExpireDate())); - else - expireEdit->setValue(30); - if (rule->getLinkMode() == KScoringRule::AND) { - linkModeAnd->setChecked(true); - } - else { - linkModeOr->setChecked(true); - } - - condEditor->slotEditRule(rule); - actionEditor->slotEditRule(rule); - - kdDebug(5100) << "RuleEditWidget::slotEditRule() ready" << endl; -} - -void RuleEditWidget::clearContents() -{ - ruleNameEdit->setText(""); - groupsEdit->setText(""); - expireCheck->setChecked(false); - expireEdit->setValue(30); - expireEdit->setEnabled(false); - condEditor->slotEditRule(0); - actionEditor->slotEditRule(0); - oldRuleName = TQString(); -} - -void RuleEditWidget::updateRule(KScoringRule *rule) -{ - oldRuleName = TQString(); - TQString groups = groupsEdit->text(); - if (groups.isEmpty()) - rule->setGroups(TQStringList(".*")); - else - rule->setGroups(TQStringList::split(";",groups)); - bool b = expireCheck->isChecked(); - if (b) - rule->setExpireDate(TQDate::tqcurrentDate().addDays(expireEdit->value())); - else - rule->setExpireDate(TQDate()); - actionEditor->updateRule(rule); - rule->setLinkMode(linkModeAnd->isChecked()?KScoringRule::AND:KScoringRule::OR); - condEditor->updateRule(rule); - if (rule->getName() != ruleNameEdit->text()) - manager->setRuleName(rule,ruleNameEdit->text()); -} - -void RuleEditWidget::updateRule() -{ - KScoringRule *rule = manager->findRule(oldRuleName); - if (rule) updateRule(rule); -} - -void RuleEditWidget::slotAddGroup() -{ - TQString grp = groupsBox->currentText(); - if ( grp.isEmpty() ) - return; - TQString txt = groupsEdit->text().stripWhiteSpace(); - if ( txt == ".*" || txt.isEmpty() ) groupsEdit->setText(grp); - else groupsEdit->setText(txt + ";" + grp); -} - -void RuleEditWidget::setDirty() -{ - kdDebug(5100) << "RuleEditWidget::setDirty()" << endl; - if (dirty) return; - dirty = true; -} - -void RuleEditWidget::slotShrink() -{ - emit(shrink()); -} - -void RuleEditWidget::slotExpireEditChanged(int value) -{ - expireEdit->setSuffix(i18n(" day", " days", value)); -} - -//============================================================================ -// -// class RuleListWidget (the widget for managing a list of rules) -// -//============================================================================ -RuleListWidget::RuleListWidget(KScoringManager *m, bool standalone, TQWidget *p, const char *n) - : TQWidget(p,n), alone(standalone), manager(m) -{ - kdDebug(5100) << "RuleListWidget::RuleListWidget()" << endl; - if (!n) setName("RuleListWidget"); - TQVBoxLayout *topL = new TQVBoxLayout(this,standalone? 0:5,KDialog::spacingHint()); - ruleList = new KListBox(this); - if (standalone) { - connect(ruleList,TQT_SIGNAL(doubleClicked(TQListBoxItem*)), - this,TQT_SLOT(slotEditRule(TQListBoxItem*))); - connect(ruleList,TQT_SIGNAL(returnPressed(TQListBoxItem*)), - this,TQT_SLOT(slotEditRule(TQListBoxItem*))); - } - connect(ruleList, TQT_SIGNAL(currentChanged(TQListBoxItem*)), - this, TQT_SLOT(slotRuleSelected(TQListBoxItem*))); - topL->addWidget(ruleList); - - TQHBoxLayout *btnL = new TQHBoxLayout( topL, KDialog::spacingHint() ); - mRuleUp = new TQPushButton( this ); - mRuleUp->setPixmap( BarIcon( "up", KIcon::SizeSmall ) ); - TQToolTip::add( mRuleUp, i18n("Move rule up") ); - btnL->addWidget( mRuleUp ); - connect( mRuleUp, TQT_SIGNAL( clicked() ), TQT_SLOT( slotRuleUp() ) ); - mRuleDown = new TQPushButton( this ); - mRuleDown->setPixmap( BarIcon( "down", KIcon::SizeSmall ) ); - TQToolTip::add( mRuleDown, i18n("Move rule down") ); - btnL->addWidget( mRuleDown ); - connect( mRuleDown, TQT_SIGNAL( clicked() ), TQT_SLOT( slotRuleDown() ) ); - - btnL = new TQHBoxLayout( topL, KDialog::spacingHint() ); - editRule=0L; - newRule = new TQPushButton(this); - newRule->setPixmap( BarIcon( "filenew", KIcon::SizeSmall ) ); - TQToolTip::add(newRule,i18n("New rule")), - btnL->addWidget(newRule); - connect(newRule, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotNewRule())); - // if we're standalone, we need an additional edit button - if (standalone) { - editRule = new TQPushButton(this); - editRule->setIconSet( BarIconSet("edit", KIcon::SizeSmall) ); - TQToolTip::add(editRule,i18n("Edit rule")); - btnL->addWidget(editRule); - connect(editRule,TQT_SIGNAL(clicked()),this,TQT_SLOT(slotEditRule())); - } - delRule = new TQPushButton(this); - delRule->setIconSet( BarIconSet( "editdelete", KIcon::SizeSmall ) ); - TQToolTip::add(delRule,i18n("Remove rule")); - btnL->addWidget(delRule); - connect(delRule, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotDelRule())); - copyRule = new TQPushButton(this); - copyRule->setIconSet(BarIconSet("editcopy", KIcon::SizeSmall)); - TQToolTip::add(copyRule,i18n("Copy rule")); - btnL->addWidget(copyRule); - connect(copyRule, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotCopyRule())); - - // the group filter - TQBoxLayout *filterL = new TQVBoxLayout(topL,KDialog::spacingHint()); - KComboBox *filterBox = new KComboBox(this); - TQStringList l = m->getGroups(); - filterBox->insertItem(i18n("")); - filterBox->insertStringList(l); - filterBox->tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed)); - connect(filterBox,TQT_SIGNAL(activated(const TQString&)), - this,TQT_SLOT(slotGroupFilter(const TQString&))); - slotGroupFilter(i18n("")); - TQLabel *lab = new TQLabel(filterBox,i18n("Sho&w only rules for group:"),this); - filterL->addWidget(lab); - filterL->addWidget(filterBox); - - connect(manager,TQT_SIGNAL(changedRules()), - this,TQT_SLOT(updateRuleList())); - connect(manager,TQT_SIGNAL(changedRuleName(const TQString&,const TQString&)), - this,TQT_SLOT(slotRuleNameChanged(const TQString&,const TQString&))); - - updateRuleList(); - updateButton(); -} - -RuleListWidget::~RuleListWidget() -{ -} - -void RuleListWidget::updateButton() -{ - bool state = ruleList->count() > 0; - if(editRule) - editRule->setEnabled(state); - delRule->setEnabled(state); - copyRule->setEnabled(state); - - TQListBoxItem *item = ruleList->item( ruleList->currentItem() ); - if ( item ) { - mRuleUp->setEnabled( item->prev() != 0 ); - mRuleDown->setEnabled( item->next() != 0 ); - } -} - -void RuleListWidget::updateRuleList() -{ - emit leavingRule(); - kdDebug(5100) << "RuleListWidget::updateRuleList()" << endl; - TQString curr = ruleList->currentText(); - ruleList->clear(); - if (group == i18n("")) { - TQStringList l = manager->getRuleNames(); - ruleList->insertStringList(l); - } else { - KScoringManager::ScoringRuleList l = manager->getAllRules(); - for (KScoringRule* rule = l.first(); rule; rule = l.next() ) { - if (rule->matchGroup(group)) ruleList->insertItem(rule->getName()); - } - } - int index = setCurrentItem(ruleList,curr); - if (index <0) { - ruleList->setCurrentItem(0); - slotRuleSelected(ruleList->currentText()); - } - else { - slotRuleSelected(curr); - } -} - -void RuleListWidget::updateRuleList(const KScoringRule *rule) -{ - kdDebug(5100) << "RuleListWidget::updateRuleList(" << rule->getName() << ")" << endl; - TQString name = rule->getName(); - updateRuleList(); - slotRuleSelected(name); -} - -void RuleListWidget::slotRuleNameChanged(const TQString& oldName, const TQString& newName) -{ - int ind = ruleList->currentItem(); - for (uint i=0;icount();++i) - if (ruleList->text(i) == oldName) { - ruleList->changeItem(newName,i); - ruleList->setCurrentItem(ind); - return; - } -} - -void RuleListWidget::slotEditRule(const TQString& s) -{ - emit ruleEdited(s); -} - -void RuleListWidget::slotEditRule() -{ - if (ruleList->currentItem() >= 0) { - emit ruleEdited(ruleList->currentText()); - } - else if (ruleList->count() == 0) - emit ruleEdited(TQString()); -} - -void RuleListWidget::slotEditRule(TQListBoxItem* item) -{ - slotEditRule(item->text()); -} - -void RuleListWidget::slotGroupFilter(const TQString& s) -{ - group = s; - updateRuleList(); -} - -void RuleListWidget::slotRuleSelected(const TQString& ruleName) -{ - emit leavingRule(); - kdDebug(5100) << "RuleListWidget::slotRuleSelected(" << ruleName << ")" << endl; - if (ruleName != ruleList->currentText()) { - setCurrentItem(ruleList,ruleName); - } - updateButton(); - emit ruleSelected(ruleName); -} - -void RuleListWidget::slotRuleSelected(TQListBoxItem *item) -{ - if (!item) return; - TQString ruleName = item->text(); - slotRuleSelected(ruleName); -} - -void RuleListWidget::slotRuleSelected(int index) -{ - uint idx = index; - if (idx >= ruleList->count()) return; - TQString ruleName = ruleList->text(index); - slotRuleSelected(ruleName); -} - -void RuleListWidget::slotNewRule() -{ - emit leavingRule(); - KScoringRule *rule = manager->addRule(); - updateRuleList(rule); - if (alone) slotEditRule(rule->getName()); - updateButton(); -} - -void RuleListWidget::slotDelRule() -{ - KScoringRule *rule = manager->findRule(ruleList->currentText()); - if (rule) - manager->deleteRule(rule); - // goto the next rule - if (!alone) slotEditRule(); - updateButton(); -} - -void RuleListWidget::slotCopyRule() -{ - emit leavingRule(); - TQString ruleName = ruleList->currentText(); - KScoringRule *rule = manager->findRule(ruleName); - if (rule) { - KScoringRule *nrule = manager->copyRule(rule); - updateRuleList(nrule); - slotEditRule(nrule->getName()); - } - updateButton(); -} - -void RuleListWidget::slotRuleUp() -{ - KScoringRule *rule = 0, *below = 0; - TQListBoxItem *item = ruleList->item( ruleList->currentItem() ); - if ( item ) { - rule = manager->findRule( item->text() ); - item = item->prev(); - if ( item ) - below = manager->findRule( item->text() ); - } - if ( rule && below ) - manager->moveRuleAbove( rule, below ); - updateRuleList(); - updateButton(); -} - -void RuleListWidget::slotRuleDown() -{ - KScoringRule *rule = 0, *above = 0; - TQListBoxItem *item = ruleList->item( ruleList->currentItem() ); - if ( item ) { - rule = manager->findRule( item->text() ); - item = item->next(); - if ( item ) - above = manager->findRule( item->text() ); - } - if ( rule && above ) - manager->moveRuleBelow( rule, above ); - updateRuleList(); - updateButton(); -} - -//============================================================================ -// -// class KScoringEditor (the score edit dialog) -// -//============================================================================ -KScoringEditor* KScoringEditor::scoreEditor = 0; - -KScoringEditor::KScoringEditor(KScoringManager* m, - TQWidget *parent, const char *name) - : KDialogBase(parent,name,false,i18n("Rule Editor"),Ok|Apply|Cancel,Ok,true), manager(m) -{ - manager->pushRuleList(); - if (!scoreEditor) scoreEditor = this; - kdDebug(5100) << "KScoringEditor::KScoringEditor()" << endl; - if (!name) setName("KScoringEditor"); - // the left side gives an overview about all rules, the right side - // shows a detailed view of an selected rule - TQWidget *w = new TQWidget(this); - setMainWidget(w); - TQHBoxLayout *hbl = new TQHBoxLayout(w,0,spacingHint()); - ruleLister = new RuleListWidget(manager,false,w); - hbl->addWidget(ruleLister); - ruleEditor = new RuleEditWidget(manager,w); - hbl->addWidget(ruleEditor); - connect(ruleLister,TQT_SIGNAL(ruleSelected(const TQString&)), - ruleEditor, TQT_SLOT(slotEditRule(const TQString&))); - connect(ruleLister, TQT_SIGNAL(leavingRule()), - ruleEditor, TQT_SLOT(updateRule())); - connect(ruleEditor, TQT_SIGNAL(shrink()), TQT_SLOT(slotShrink())); - connect(this,TQT_SIGNAL(finished()),TQT_SLOT(slotFinished())); - ruleLister->slotRuleSelected(0); - resize(550, tqsizeHint().height()); -} - -void KScoringEditor::setDirty() -{ - TQPushButton *applyBtn = actionButton(Apply); - applyBtn->setEnabled(true); -} - -KScoringEditor::~KScoringEditor() -{ - scoreEditor = 0; -} - -KScoringEditor* KScoringEditor::createEditor(KScoringManager* m, - TQWidget *parent, const char *name) -{ - if (scoreEditor) return scoreEditor; - else return new KScoringEditor(m,parent,name); -} - -void KScoringEditor::setRule(KScoringRule* r) -{ - kdDebug(5100) << "KScoringEditor::setRule(" << r->getName() << ")" << endl; - TQString ruleName = r->getName(); - ruleLister->slotRuleSelected(ruleName); -} - -void KScoringEditor::slotShrink() -{ - TQTimer::singleShot(5, this, TQT_SLOT(slotDoShrink())); -} - -void KScoringEditor::slotDoShrink() -{ - updateGeometry(); - TQApplication::sendPostedEvents(); - resize(width(),tqsizeHint().height()); -} - -void KScoringEditor::slotApply() -{ - TQString ruleName = ruleLister->currentRule(); - KScoringRule *rule = manager->findRule(ruleName); - if (rule) { - ruleEditor->updateRule(rule); - ruleLister->updateRuleList(rule); - } - manager->removeTOS(); - manager->pushRuleList(); -} - -void KScoringEditor::slotOk() -{ - slotApply(); - manager->removeTOS(); - KDialogBase::slotOk(); - manager->editorReady(); -} - -void KScoringEditor::slotCancel() -{ - manager->popRuleList(); - KDialogBase::slotCancel(); -} - -void KScoringEditor::slotFinished() -{ - delayedDestruct(); -} - -//============================================================================ -// -// class KScoringEditorWidgetDialog (a dialog for the KScoringEditorWidget) -// -//============================================================================ -KScoringEditorWidgetDialog::KScoringEditorWidgetDialog(KScoringManager *m, const TQString& r, TQWidget *p, const char *n) - : KDialogBase(p,n,true,i18n("Edit Rule"), - KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Close, - KDialogBase::Ok,true), - manager(m), ruleName(r) -{ - TQFrame *f = makeMainWidget(); - TQBoxLayout *topL = new TQVBoxLayout(f); - ruleEditor = new RuleEditWidget(manager,f); - connect(ruleEditor, TQT_SIGNAL(shrink()), TQT_SLOT(slotShrink())); - topL->addWidget(ruleEditor); - ruleEditor->slotEditRule(ruleName); - resize(0,0); -} - -void KScoringEditorWidgetDialog::slotApply() -{ - KScoringRule *rule = manager->findRule(ruleName); - if (rule) { - ruleEditor->updateRule(rule); - ruleName = rule->getName(); - } -} - -void KScoringEditorWidgetDialog::slotOk() -{ - slotApply(); - KDialogBase::slotOk(); -} - -void KScoringEditorWidgetDialog::slotShrink() -{ - TQTimer::singleShot(5, this, TQT_SLOT(slotDoShrink())); -} - -void KScoringEditorWidgetDialog::slotDoShrink() -{ - updateGeometry(); - TQApplication::sendPostedEvents(); - resize(width(),tqsizeHint().height()); -} - -//============================================================================ -// -// class KScoringEditorWidget (a reusable widget for config dialog...) -// -//============================================================================ -KScoringEditorWidget::KScoringEditorWidget(KScoringManager *m,TQWidget *p, const char *n) - : TQWidget(p,n), manager(m) -{ - TQBoxLayout *topL = new TQVBoxLayout(this); - ruleLister = new RuleListWidget(manager,true,this); - topL->addWidget(ruleLister); - connect(ruleLister,TQT_SIGNAL(ruleEdited(const TQString&)), - this,TQT_SLOT(slotRuleEdited(const TQString &))); -} - -KScoringEditorWidget::~KScoringEditorWidget() -{ - manager->editorReady(); -} - -void KScoringEditorWidget::slotRuleEdited(const TQString& ruleName) -{ - KScoringEditorWidgetDialog dlg(manager,ruleName,this); - dlg.exec(); - ruleLister->updateRuleList(); -} - -#include "kscoringeditor.moc" diff --git a/libkdepim/kscoringeditor.h b/libkdepim/kscoringeditor.h deleted file mode 100644 index ba0ee190e..000000000 --- a/libkdepim/kscoringeditor.h +++ /dev/null @@ -1,317 +0,0 @@ -/* - kscoringeditor.h - - Copyright (c) 2001 Mathias Waack - Copyright (C) 2005 by Volker Krause - - Author: Mathias Waack - - 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. - 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, US -*/ - -#ifndef SCOREEDITWIDGET_H -#define SCOREEDITWIDGET_H - -#include -#include -#include -#include - -#include "kwidgetlister.h" - -#include - -class KComboBox; -class KLineEdit; -class KIntSpinBox; -class KListBox; -class TQFrame; -class TQLabel; -class TQListBoxItem; -class TQPushButton; -class TQCheckBox; -class TQRadioButton; - -class KScoringRule; -class KScoringExpression; -class KScoringManager; -class ActionBase; -class KScoringEditor; -class ScoreEditWidget; -class KColorCombo; - -/** this widget implements an editor for one condition. - It is used in ExpressionEditWidget -*/ -class KDE_EXPORT SingleConditionWidget : public TQFrame -{ - Q_OBJECT - TQ_OBJECT - friend class ConditionEditWidget; -public: - SingleConditionWidget(KScoringManager *,TQWidget *p =0, const char *n =0); - ~SingleConditionWidget(); - void setCondition(KScoringExpression*); - KScoringExpression *createCondition() const; - void clear(); - -protected slots: - void toggleRegExpButton( int ); - void showRegExpDialog(); - -private: - /** marks a condition as negated */ - TQCheckBox *neg; - /** list of possible headers */ - KComboBox *headers; - /** list of match types */ - KComboBox *matches; - /** the expression which will be matched */ - KLineEdit *expr; - /** the button to open the regexp-editor */ - TQPushButton *regExpButton; - - KScoringManager *manager; -}; - -/** this widget implements the conditions editor - */ -class ConditionEditWidget: public KWidgetLister -{ - Q_OBJECT - TQ_OBJECT -public: - ConditionEditWidget(KScoringManager *,TQWidget *p =0, const char *n =0); - ~ConditionEditWidget(); - TQWidget* createWidget(TQWidget*); - void updateRule(KScoringRule*); - void clearWidget(TQWidget*); -public slots: - void slotEditRule(KScoringRule*); -private: - KScoringManager *manager; -}; - -/** this widget implements an editor for one action. - It is used in ActionEditWidget -*/ -class SingleActionWidget : public TQWidget -{ - Q_OBJECT - TQ_OBJECT - friend class ActionEditWidget; -public: - SingleActionWidget(KScoringManager *m,TQWidget *p =0, const char *n =0); - ~SingleActionWidget(); - void setAction(ActionBase*); - ActionBase *createAction() const; - void clear(); -private: - /** the list of available action */ - KComboBox *types; - /** the stack of the edit widgets for each action type */ - TQWidgetStack *stack; - /** the notify action editor */ - KLineEdit *notifyEditor; - /** the score acton editor */ - KIntSpinBox *scoreEditor; - /** the color action editor */ - KColorCombo *colorEditor; - /** the dummy label */ - TQLabel *dummyLabel; - - KScoringManager *manager; -}; - -/** this widget implements the action editor - */ -class KDE_EXPORT ActionEditWidget : public KWidgetLister -{ - Q_OBJECT - TQ_OBJECT -public: - ActionEditWidget(KScoringManager *m,TQWidget *p =0, const char *n =0); - ~ActionEditWidget(); - TQWidget* createWidget(TQWidget *parent); - void updateRule(KScoringRule*); - void clearWidget(TQWidget *); -public slots: - void slotEditRule(KScoringRule *); -private: - KScoringManager *manager; -}; - -/** This widget implements the rule editor - */ -class RuleEditWidget : public TQWidget -{ - Q_OBJECT - TQ_OBJECT -public: - RuleEditWidget(KScoringManager *m,TQWidget *p =0, const char *n =0); - ~RuleEditWidget(); -public slots: - void setDirty(); - void slotEditRule(const TQString&); - void updateRule(KScoringRule*); - void updateRule(); -signals: - void shrink(); -protected slots: - void slotAddGroup(); - void slotShrink(); -private slots: - void slotExpireEditChanged(int value); -private: - void clearContents(); - - bool dirty; - /** the name of the rule */ - KLineEdit *ruleNameEdit; - /** the list of groups this rule applies to */ - KLineEdit *groupsEdit; - /** list of all available groups */ - KComboBox *groupsBox; - /** the expire enable */ - TQCheckBox *expireCheck; - /** the label to the expireCheck */ - TQLabel *expireLabel; - /** the expire delay */ - KIntSpinBox *expireEdit; - /** the link modes of the conditions */ - TQRadioButton *linkModeOr, *linkModeAnd; - /** the actions editor */ - ActionEditWidget *actionEditor; - /** the conditions editor */ - ConditionEditWidget *condEditor; - - KScoringManager *manager; - - // the old name of the current rule - TQString oldRuleName; -}; - -/** This widget shows a list of rules with buttons for - copy, delete aso. -*/ -class KDE_EXPORT RuleListWidget : public TQWidget -{ - Q_OBJECT - TQ_OBJECT -public: - RuleListWidget(KScoringManager *m, bool =false, TQWidget *p =0, const char *n =0); - ~RuleListWidget(); - TQString currentRule() const { return ruleList->currentText(); } -protected: - void updateButton(); - -signals: - void ruleSelected(const TQString&); - void ruleEdited(const TQString&); - void leavingRule(); -public slots: - void slotRuleSelected(const TQString&); - void slotRuleSelected(TQListBoxItem *); - void slotRuleSelected(int); - void updateRuleList(); - void updateRuleList(const KScoringRule*); - void slotRuleNameChanged(const TQString&,const TQString&); -protected slots: - void slotGroupFilter(const TQString&); - void slotEditRule(TQListBoxItem*); - void slotEditRule(const TQString&); - void slotEditRule(); - void slotDelRule(); - void slotNewRule(); - void slotCopyRule(); - void slotRuleUp(); - void slotRuleDown(); - -private: - /** the list of rules */ - KListBox *ruleList; - /** the current group */ - TQString group; - /** marks if we're alone or together with the edit widget */ - bool alone; - - KScoringManager *manager; - - TQPushButton *editRule; - TQPushButton *newRule; - TQPushButton *delRule; - TQPushButton *copyRule; - TQPushButton *mRuleUp; - TQPushButton *mRuleDown; -}; - -class KDE_EXPORT KScoringEditor : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT -public: - ~KScoringEditor(); - void setRule(KScoringRule*); - static KScoringEditor *createEditor(KScoringManager* m, TQWidget *parent=0, const char *name=0); - static KScoringEditor *editor() { return scoreEditor; } - void setDirty(); -protected: - KScoringEditor(KScoringManager* m, TQWidget *parent=0, const char *name=0); -private: - /** the editor for the current rule */ - RuleEditWidget* ruleEditor; - /** the list of known rules */ - RuleListWidget *ruleLister; -protected slots: - void slotShrink(); - void slotDoShrink(); - void slotApply(); - void slotOk(); - void slotCancel(); - void slotFinished(); -private: - KScoringManager *manager; - ScoreEditWidget *edit; - /** make sure that there is only one instance of ourselve */ - static KScoringEditor *scoreEditor; -}; - -class KScoringEditorWidgetDialog : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT -public: - KScoringEditorWidgetDialog(KScoringManager *m, const TQString& rName, TQWidget *parent=0, const char *name=0); -protected slots: - void slotApply(); - void slotOk(); - void slotShrink(); - void slotDoShrink(); -private: - RuleEditWidget *ruleEditor; - KScoringManager *manager; - TQString ruleName; -}; - -class KDE_EXPORT KScoringEditorWidget : public TQWidget -{ - Q_OBJECT - TQ_OBJECT -public: - KScoringEditorWidget(KScoringManager *m,TQWidget *p =0, const char *n =0); - ~KScoringEditorWidget(); -protected slots: - void slotRuleEdited(const TQString&); -private: - RuleListWidget *ruleLister; - KScoringManager *manager; -}; - - -#endif // SCOREEDITWIDGET_H diff --git a/libkdepim/ksubscription.cpp b/libkdepim/ksubscription.cpp deleted file mode 100644 index b611e1260..000000000 --- a/libkdepim/ksubscription.cpp +++ /dev/null @@ -1,793 +0,0 @@ -/* - ksubscription.cpp - - 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. - 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, US -*/ - -#include "ksubscription.h" -#include "kaccount.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - - -//============================================================================= - -KGroupInfo::KGroupInfo(const TQString &name, const TQString &description, - bool newGroup, bool subscribed, - tqStatus status, TQString path) - : name(name), description(description), - newGroup(newGroup), subscribed(subscribed), - status(status), path(path) -{ -} - -//----------------------------------------------------------------------------- -bool KGroupInfo::operator== (const KGroupInfo &gi2) -{ - return (name == gi2.name); -} - -//----------------------------------------------------------------------------- -bool KGroupInfo::operator< (const KGroupInfo &gi2) -{ - return (name < gi2.name); -} - -//============================================================================= - -GroupItem::GroupItem( TQListView *v, const KGroupInfo &gi, KSubscription* browser, - bool isCheckItem ) - : TQCheckListItem( v, gi.name, isCheckItem ? CheckBox : CheckBoxController ), - mInfo( gi ), mBrowser( browser ), mIsCheckItem( isCheckItem ), - mIgnoreStateChange( false ) -{ - if (listView()->columns() > 1) - setDescription(); -} - -//----------------------------------------------------------------------------- -GroupItem::GroupItem( TQListViewItem *i, const KGroupInfo &gi, KSubscription* browser, - bool isCheckItem ) - : TQCheckListItem( i, gi.name, isCheckItem ? CheckBox : CheckBoxController ), - mInfo( gi ), mBrowser( browser ), mIsCheckItem( isCheckItem ), - mIgnoreStateChange( false ) -{ - if (listView()->columns() > 1) - setDescription(); -} - -//----------------------------------------------------------------------------- -void GroupItem::setInfo( KGroupInfo info ) -{ - mInfo = info; - setText(0, mInfo.name); - if (listView()->columns() > 1) - setDescription(); -} - -//----------------------------------------------------------------------------- -void GroupItem::setDescription() -{ - setText(1, mInfo.description); -} - -//----------------------------------------------------------------------------- -void GroupItem::setOn( bool on ) -{ - if (mBrowser->isLoading()) - { - // set this only if we're loading/creating items - // otherwise changes are only permanent when the dialog is saved - mInfo.subscribed = on; - } - if (isCheckItem()) - TQCheckListItem::setOn(on); -} - -//------------------------------------------------------------------------------ -void GroupItem::stateChange( bool on ) -{ - // delegate to parent - if ( !mIgnoreStateChange ) - mBrowser->changeItemState(this, on); -} - -//------------------------------------------------------------------------------ -void GroupItem::setVisible( bool b ) -{ - if (b) - { - TQListViewItem::setVisible(b); - setEnabled(true); - } - else - { - if (isCheckItem()) - { - bool setInvisible = true; - for (TQListViewItem * lvchild = firstChild(); lvchild != 0; - lvchild = lvchild->nextSibling()) - { - if (lvchild->isVisible()) // item has a visible child - setInvisible = false; - } - if (setInvisible) - TQListViewItem::setVisible(b); - else - { - // leave it visible so that tqchildren remain visible - setOpen(true); - setEnabled(false); - } - } - else - { - // non-checkable item - TQPtrList moveItems; - - for (TQListViewItem * lvchild = firstChild(); lvchild != 0; - lvchild = lvchild->nextSibling()) - { - if (static_cast(lvchild)->isCheckItem()) - { - // remember the items - moveItems.append(lvchild); - } - } - TQPtrListIterator it( moveItems ); - for ( ; it.current(); ++it) - { - // move the checkitem to top - TQListViewItem* parent = it.current()->parent(); - if (parent) parent->takeItem(it.current()); - listView()->insertItem(it.current()); - } - TQListViewItem::setVisible(false); - } - } -} - -//----------------------------------------------------------------------------- -void GroupItem::paintCell( TQPainter * p, const TQColorGroup & cg, - int column, int width, int align ) -{ - if (mIsCheckItem) - return TQCheckListItem::paintCell( p, cg, column, width, align ); - else - return TQListViewItem::paintCell( p, cg, column, width, align ); -} - -//----------------------------------------------------------------------------- -void GroupItem::paintFocus( TQPainter * p, const TQColorGroup & cg, - const TQRect & r ) -{ - if (mIsCheckItem) - TQCheckListItem::paintFocus(p, cg, r); - else - TQListViewItem::paintFocus(p, cg, r); -} - -//----------------------------------------------------------------------------- -int GroupItem::width( const TQFontMetrics& fm, const TQListView* lv, int column) const -{ - if (mIsCheckItem) - return TQCheckListItem::width(fm, lv, column); - else - return TQListViewItem::width(fm, lv, column); -} - -//----------------------------------------------------------------------------- -void GroupItem::setup() -{ - if (mIsCheckItem) - TQCheckListItem::setup(); - else - TQListViewItem::setup(); -} - - -//============================================================================= - -KSubscription::KSubscription( TQWidget *parent, const TQString &caption, - KAccount * acct, int buttons, const TQString &user1, bool descriptionColumn ) - : KDialogBase( parent, 0, true, caption, buttons | Help | Ok | Cancel, Ok, - true, i18n("Reload &List"), user1 ), - mAcct( acct ) -{ - mLoading = true; - setWFlags( getWFlags() | WDestructiveClose ); - - // create Widgets - page = new TQWidget(this); - setMainWidget(page); - - TQLabel *comment = new TQLabel("

"+ - i18n("Manage which mail folders you want to see in your folder view") + "

", page); - - TQToolButton *clearButton = new TQToolButton( page ); - clearButton->setIconSet( KGlobal::iconLoader()->loadIconSet( - KApplication::reverseLayout() ? "clear_left":"locationbar_erase", KIcon::Small, 0 ) ); - filterEdit = new KLineEdit(page); - TQLabel *l = new TQLabel(filterEdit,i18n("S&earch:"), page); - connect( clearButton, TQT_SIGNAL( clicked() ), filterEdit, TQT_SLOT( clear() ) ); - - // checkboxes - noTreeCB = new TQCheckBox(i18n("Disable &tree view"), page); - noTreeCB->setChecked(false); - subCB = new TQCheckBox(i18n("&Subscribed only"), page); - subCB->setChecked(false); - newCB = new TQCheckBox(i18n("&New only"), page); - newCB->setChecked(false); - - - KSeparator *sep = new KSeparator(KSeparator::HLine, page); - - // init the labels - TQFont fnt = font(); - fnt.setBold(true); - leftLabel = new TQLabel(i18n("Loading..."), page); - rightLabel = new TQLabel(i18n("Current changes:"), page); - leftLabel->setFont(fnt); - rightLabel->setFont(fnt); - - // icons - pmRight = BarIconSet("forward"); - pmLeft = BarIconSet("back"); - - arrowBtn1 = new TQPushButton(page); - arrowBtn1->setEnabled(false); - arrowBtn2 = new TQPushButton(page); - arrowBtn2->setEnabled(false); - arrowBtn1->setIconSet(pmRight); - arrowBtn2->setIconSet(pmRight); - arrowBtn1->setFixedSize(35,30); - arrowBtn2->setFixedSize(35,30); - - // the main listview - groupView = new TQListView(page); - groupView->setRootIsDecorated(true); - groupView->addColumn(i18n("Name")); - groupView->setAllColumnsShowFocus(true); - if (descriptionColumn) - mDescrColumn = groupView->addColumn(i18n("Description")); - else - groupView->header()->setStretchEnabled(true, 0); - - // tqlayout - TQGridLayout *topL = new TQGridLayout(page,4,1,0, KDialog::spacingHint()); - TQHBoxLayout *filterL = new TQHBoxLayout(KDialog::spacingHint()); - TQVBoxLayout *arrL = new TQVBoxLayout(KDialog::spacingHint()); - listL = new TQGridLayout(2, 3, KDialog::spacingHint()); - - topL->addWidget(comment, 0,0); - topL->addLayout(filterL, 1,0); - topL->addWidget(sep,2,0); - topL->addLayout(listL, 3,0); - - filterL->addWidget(clearButton); - filterL->addWidget(l); - filterL->addWidget(filterEdit, 1); - filterL->addWidget(noTreeCB); - filterL->addWidget(subCB); - filterL->addWidget(newCB); - - listL->addWidget(leftLabel, 0,0); - listL->addWidget(rightLabel, 0,2); - listL->addWidget(groupView, 1,0); - listL->addLayout(arrL, 1,1); - listL->setRowStretch(1,1); - listL->setColStretch(0,5); - listL->setColStretch(2,2); - - arrL->addWidget(arrowBtn1, AlignCenter); - arrL->addWidget(arrowBtn2, AlignCenter); - - // listviews - subView = new TQListView(page); - subView->addColumn(i18n("Subscribe To")); - subView->header()->setStretchEnabled(true, 0); - unsubView = new TQListView(page); - unsubView->addColumn(i18n("Unsubscribe From")); - unsubView->header()->setStretchEnabled(true, 0); - - TQVBoxLayout *protL = new TQVBoxLayout(3); - listL->addLayout(protL, 1,2); - protL->addWidget(subView); - protL->addWidget(unsubView); - - // disable some widgets as long we're loading - enableButton(User1, false); - enableButton(User2, false); - newCB->setEnabled(false); - noTreeCB->setEnabled(false); - subCB->setEnabled(false); - - filterEdit->setFocus(); - - // items clicked - connect(groupView, TQT_SIGNAL(clicked(TQListViewItem *)), - this, TQT_SLOT(slotChangeButtonState(TQListViewItem*))); - connect(subView, TQT_SIGNAL(clicked(TQListViewItem *)), - this, TQT_SLOT(slotChangeButtonState(TQListViewItem*))); - connect(unsubView, TQT_SIGNAL(clicked(TQListViewItem *)), - this, TQT_SLOT(slotChangeButtonState(TQListViewItem*))); - - // connect buttons - connect(arrowBtn1, TQT_SIGNAL(clicked()), TQT_SLOT(slotButton1())); - connect(arrowBtn2, TQT_SIGNAL(clicked()), TQT_SLOT(slotButton2())); - connect(this, TQT_SIGNAL(user1Clicked()), TQT_SLOT(slotLoadFolders())); - - // connect checkboxes - connect(subCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled())); - connect(newCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled())); - connect(noTreeCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled())); - - // connect textfield - connect(filterEdit, TQT_SIGNAL(textChanged(const TQString&)), - TQT_SLOT(slotFilterTextChanged(const TQString&))); - - // update status - connect(this, TQT_SIGNAL(listChanged()), TQT_SLOT(slotUpdateStatusLabel())); -} - -//----------------------------------------------------------------------------- -KSubscription::~KSubscription() -{ -} - -//----------------------------------------------------------------------------- -void KSubscription::setStartItem( const KGroupInfo &info ) -{ - TQListViewItemIterator it(groupView); - - for ( ; it.current(); ++it) - { - if (static_cast(it.current())->info() == info) - { - it.current()->setSelected(true); - it.current()->setOpen(true); - } - } -} - -//----------------------------------------------------------------------------- -void KSubscription::removeListItem( TQListView *view, const KGroupInfo &gi ) -{ - if(!view) return; - TQListViewItemIterator it(view); - - for ( ; it.current(); ++it) - { - if (static_cast(it.current())->info() == gi) - { - delete it.current(); - break; - } - } - if (view == groupView) - emit listChanged(); -} - -//----------------------------------------------------------------------------- -TQListViewItem* KSubscription::getListItem( TQListView *view, const KGroupInfo &gi ) -{ - if(!view) return 0; - TQListViewItemIterator it(view); - - for ( ; it.current(); ++it) - { - if (static_cast(it.current())->info() == gi) - return (it.current()); - } - return 0; -} - -//----------------------------------------------------------------------------- -bool KSubscription::itemInListView( TQListView *view, const KGroupInfo &gi ) -{ - if(!view) return false; - TQListViewItemIterator it(view); - - for ( ; it.current(); ++it) - if (static_cast(it.current())->info() == gi) - return true; - - return false; -} - -//------------------------------------------------------------------------------ -void KSubscription::setDirectionButton1( Direction dir ) -{ - mDirButton1 = dir; - if (dir == Left) - arrowBtn1->setIconSet(pmLeft); - else - arrowBtn1->setIconSet(pmRight); -} - -//------------------------------------------------------------------------------ -void KSubscription::setDirectionButton2( Direction dir ) -{ - mDirButton2 = dir; - if (dir == Left) - arrowBtn2->setIconSet(pmLeft); - else - arrowBtn2->setIconSet(pmRight); -} - -//------------------------------------------------------------------------------ -void KSubscription::changeItemState( GroupItem* item, bool on ) -{ - // is this a checkable item - if (!item->isCheckItem()) return; - - // if we're currently loading the items ignore changes - if (mLoading) return; - if (on) - { - if (!itemInListView(unsubView, item->info())) - { - TQListViewItem *p = item->parent(); - while (p) - { - // make sure all parents are subscribed - GroupItem* pi = static_cast(p); - if (pi->isCheckItem() && !pi->isOn()) - { - pi->setIgnoreStateChange(true); - pi->setOn(true); - pi->setIgnoreStateChange(false); - new GroupItem(subView, pi->info(), this); - } - p = p->parent(); - } - new GroupItem(subView, item->info(), this); - } - // eventually remove it from the other listview - removeListItem(unsubView, item->info()); - } - else { - if (!itemInListView(subView, item->info())) - { - new GroupItem(unsubView, item->info(), this); - } - // eventually remove it from the other listview - removeListItem(subView, item->info()); - } - // update the buttons - slotChangeButtonState(item); -} - -//------------------------------------------------------------------------------ -void KSubscription::filterChanged( TQListViewItem* item, const TQString & text ) -{ - if ( !item && groupView ) - item = groupView->firstChild(); - if ( !item ) - return; - - do - { - if ( item->firstChild() ) // recursive descend - filterChanged(item->firstChild(), text); - - GroupItem* gr = static_cast(item); - if (subCB->isChecked() || newCB->isChecked() || !text.isEmpty() || - noTreeCB->isChecked()) - { - // set it invisible - if ( subCB->isChecked() && - (!gr->isCheckItem() || - (gr->isCheckItem() && !gr->info().subscribed)) ) - { - // only subscribed - gr->setVisible(false); - continue; - } - if ( newCB->isChecked() && - (!gr->isCheckItem() || - (gr->isCheckItem() && !gr->info().newGroup)) ) - { - // only new - gr->setVisible(false); - continue; - } - if ( !text.isEmpty() && - gr->text(0).find(text, 0, false) == -1) - { - // searchfield - gr->setVisible(false); - continue; - } - if ( noTreeCB->isChecked() && - !gr->isCheckItem() ) - { - // disable treeview - gr->setVisible(false); - continue; - } - - gr->setVisible(true); - - } else { - gr->setVisible(true); - } - - } while ((item = item->nextSibling())); - -} - -//------------------------------------------------------------------------------ -uint KSubscription::activeItemCount() -{ - TQListViewItemIterator it(groupView); - - uint count = 0; - for ( ; it.current(); ++it) - { - if (static_cast(it.current())->isCheckItem() && - it.current()->isVisible() && it.current()->isEnabled()) - count++; - } - - return count; -} - -//------------------------------------------------------------------------------ -void KSubscription::restoreOriginalParent() -{ - TQPtrList move; - TQListViewItemIterator it(groupView); - for ( ; it.current(); ++it) - { - TQListViewItem* origParent = static_cast(it.current())-> - originalParent(); - if (origParent && origParent != it.current()->parent()) - { - // remember this to avoid messing up the iterator - move.append(it.current()); - } - } - TQPtrListIterator it2( move ); - for ( ; it2.current(); ++it2) - { - // restore the original parent - TQListViewItem* origParent = static_cast(it2.current())-> - originalParent(); - groupView->takeItem(it2.current()); - origParent->insertItem(it2.current()); - } -} - -//----------------------------------------------------------------------------- -void KSubscription::saveOpenStates() -{ - TQListViewItemIterator it(groupView); - - for ( ; it.current(); ++it) - { - static_cast(it.current())->setLastOpenState( - it.current()->isOpen() ); - } -} - -//----------------------------------------------------------------------------- -void KSubscription::restoreOpenStates() -{ - TQListViewItemIterator it(groupView); - - for ( ; it.current(); ++it) - { - it.current()->setOpen( - static_cast(it.current())->lastOpenState() ); - } -} - -//----------------------------------------------------------------------------- -void KSubscription::slotLoadingComplete() -{ - mLoading = false; - - enableButton(User1, true); - enableButton(User2, true); - newCB->setEnabled(true); - noTreeCB->setEnabled(true); - subCB->setEnabled(true); - - // remember the correct parent - TQListViewItemIterator it(groupView); - for ( ; it.current(); ++it) - { - static_cast(it.current())-> - setOriginalParent( it.current()->parent() ); - } - - emit listChanged(); -} - -//------------------------------------------------------------------------------ -void KSubscription::slotChangeButtonState( TQListViewItem *item ) -{ - if (!item || - (item->listView() == groupView && - !static_cast(item)->isCheckItem())) - { - // disable and return - arrowBtn1->setEnabled(false); - arrowBtn2->setEnabled(false); - return; - } - // set the direction of the buttons and enable/disable them - TQListView* currentView = item->listView(); - if (currentView == groupView) - { - setDirectionButton1(Right); - setDirectionButton2(Right); - if (static_cast(item)->isOn()) - { - // already subscribed - arrowBtn1->setEnabled(false); - arrowBtn2->setEnabled(true); - } else { - // unsubscribed - arrowBtn1->setEnabled(true); - arrowBtn2->setEnabled(false); - } - } else if (currentView == subView) - { - // undo possible - setDirectionButton1(Left); - - arrowBtn1->setEnabled(true); - arrowBtn2->setEnabled(false); - } else if (currentView == unsubView) - { - // undo possible - setDirectionButton2(Left); - - arrowBtn1->setEnabled(false); - arrowBtn2->setEnabled(true); - } -} - -//------------------------------------------------------------------------------ -void KSubscription::slotButton1() -{ - if (mDirButton1 == Right) - { - if (groupView->currentItem() && - static_cast(groupView->currentItem())->isCheckItem()) - { - // activate - GroupItem* item = static_cast(groupView->currentItem()); - item->setOn(true); - } - } - else { - if (subView->currentItem()) - { - GroupItem* item = static_cast(subView->currentItem()); - // get the corresponding item from the groupView - TQListViewItem* listitem = getListItem(groupView, item->info()); - if (listitem) - { - // deactivate - GroupItem* chk = static_cast(listitem); - chk->setOn(false); - } - } - } -} - -//------------------------------------------------------------------------------ -void KSubscription::slotButton2() -{ - if (mDirButton2 == Right) - { - if (groupView->currentItem() && - static_cast(groupView->currentItem())->isCheckItem()) - { - // deactivate - GroupItem* item = static_cast(groupView->currentItem()); - item->setOn(false); - } - } - else { - if (unsubView->currentItem()) - { - GroupItem* item = static_cast(unsubView->currentItem()); - // get the corresponding item from the groupView - TQListViewItem* listitem = getListItem(groupView, item->info()); - if (listitem) - { - // activate - GroupItem* chk = static_cast(listitem); - chk->setOn(true); - } - } - } -} - -//------------------------------------------------------------------------------ -void KSubscription::slotCBToggled() -{ - if (!noTreeCB->isChecked() && !newCB->isChecked() && !subCB->isChecked()) - { - restoreOriginalParent(); - } - // set items {in}visible - filterChanged(groupView->firstChild()); - emit listChanged(); -} - -//------------------------------------------------------------------------------ -void KSubscription::slotFilterTextChanged( const TQString & text ) -{ - // remember is the items are open - if (mLastText.isEmpty()) - saveOpenStates(); - - if (!mLastText.isEmpty() && text.length() < mLastText.length()) - { - // reset - restoreOriginalParent(); - TQListViewItemIterator it(groupView); - for ( ; it.current(); ++it) - { - it.current()->setVisible(true); - it.current()->setEnabled(true); - } - } - // set items {in}visible - filterChanged(groupView->firstChild(), text); - // restore the open-states - if (text.isEmpty()) - restoreOpenStates(); - - emit listChanged(); - mLastText = text; -} - -//------------------------------------------------------------------------------ -void KSubscription::slotUpdateStatusLabel() -{ - TQString text; - if (mLoading) - text = i18n("Loading... (1 matching)", "Loading... (%n matching)", - activeItemCount()); - else - text = i18n("%1: (1 matching)", "%1: (%n matching)", activeItemCount()) - .tqarg(account()->name()); - - leftLabel->setText(text); -} - -//------------------------------------------------------------------------------ -void KSubscription::slotLoadFolders() -{ - enableButton(User1, false); - mLoading = true; - subView->clear(); - unsubView->clear(); - groupView->clear(); -} - -#include "ksubscription.moc" diff --git a/libkdepim/ksubscription.h b/libkdepim/ksubscription.h deleted file mode 100644 index c819701d1..000000000 --- a/libkdepim/ksubscription.h +++ /dev/null @@ -1,382 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2002 Carsten Burghardt - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -/** @file -* This file defines a generic subscription widget and some support classes. -*/ - -#ifndef __KSUBSCRIPTION -#define __KSUBSCRIPTION - -#include -#include - -#include -#include -#include "kfoldertree.h" - -class KSubscription; - -class KLineEdit; -class TQLayout; -class TQLabel; -class TQGridLayout; -class KAccount; - -//========================================================================== - -class KDE_EXPORT KGroupInfo -{ - public: - enum tqStatus { - unknown, - readOnly, - postingAllowed, - moderated - }; - - KGroupInfo( const TQString &name, const TQString &description = TQString(), - bool newGroup = false, bool subscribed = false, - tqStatus status = unknown, TQString path = TQString() ); - - TQString name, description; - bool newGroup, subscribed; - tqStatus status; - TQString path; - - bool operator== (const KGroupInfo &gi2); - bool operator< (const KGroupInfo &gi2); - -}; - -//========================================================================== - -/** A class representing a single group item (what's that?) */ -class KDE_EXPORT GroupItem : public TQCheckListItem -{ - public: - GroupItem( TQListView *v, const KGroupInfo &gi, KSubscription* browser, - bool isCheckItem = false ); - GroupItem( TQListViewItem *i, const KGroupInfo &gi, KSubscription* browser, - bool isCheckItem = false ); - - /** - * Get/Set the KGroupInfo - */ - KGroupInfo info() { return mInfo; } - void setInfo( KGroupInfo info ); - - /** - * Get/Set the original parent - */ - TQListViewItem* originalParent() { return mOriginalParent; } - void setOriginalParent( TQListViewItem* parent ) { mOriginalParent = parent; } - - /** - * Get/Set the last open state - */ - bool lastOpenState() { return mLastOpenState; } - void setLastOpenState( bool last ) { mLastOpenState = last; } - - /** - * Sets the description from the KGroupInfo - * Reimplement this for special cases - */ - virtual void setDescription(); - - /** - * Get if this is a checkable item - */ - bool isCheckItem() const { return mIsCheckItem; } - - /** - * Get/Set if state changes should be ignored - */ - bool ignoreStateChange() { return mIgnoreStateChange; } - void setIgnoreStateChange( bool ignore ) { mIgnoreStateChange = ignore; } - - /** - * Reimplemented - * Sets the subscribed property (only while items are loaded) - */ - virtual void setOn( bool on ); - - /** - * Reimlemented - * Calls KSubscription::changeItemState if mIgnoreStateChange == false - */ - virtual void stateChange( bool on ); - - /** - * Reimplemented - * Sets items invisible or disabled or even moves them - */ - void setVisible( bool b ); - - /** - * Reimplemented - * Calls TQListViewItem or TQCheckListItem - */ - virtual void paintCell( TQPainter * p, const TQColorGroup & cg, - int column, int width, int align ); - - /** - * Reimplemented - * Calls TQListViewItem or TQCheckListItem - */ - virtual void paintFocus( TQPainter *, const TQColorGroup & cg, - const TQRect & r ); - - /** - * Reimplemented - * Calls TQListViewItem or TQCheckListItem - */ - virtual int width( const TQFontMetrics&, const TQListView*, int column) const; - - /** - * Reimplemented - * Calls TQListViewItem or TQCheckListItem - */ - virtual void setup(); - - /** Reimplemented */ - virtual int rtti () const { return 15689; } - - protected: - KGroupInfo mInfo; - KSubscription* mBrowser; - TQListViewItem* mOriginalParent; - // remember last open state - bool mLastOpenState; - // is this a checkable item - bool mIsCheckItem; - // ignore state changes - bool mIgnoreStateChange; -}; - -//========================================================================== - -/** - * This class provides a generic subscription widget - * The dialog itself has a main listview that holds all items and two listviews that - * show all changes. The user can change the state of the items via checkable items. - * When you construct a new instance you need to provide an account and a caption - * After inserting your items (checkable or not) you need to call slotLoadingComplete() - * You should at least connect slots to the signals okClicked() (to save your changes) - * and user1Clicked() (to reload the list) - * You can hide unwanted checkboxes via the respective hide methods - * - */ - -class KDE_EXPORT KSubscription : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT - - public: - /** - * The direction of the buttons - */ - enum Direction { - Left, - Right - }; - - KSubscription( TQWidget *parent, const TQString &caption, KAccount* acct, - int buttons = 0, const TQString &user1 = TQString(), - bool descriptionColumn = true ); - - ~KSubscription(); - - /** - * Get/Set the account - */ - KAccount* account() { return mAcct; } - void setAccount( KAccount * acct ) { mAcct = acct; } - - /** - * Access to the treewidget that holds the GroupItems - */ - TQListView* folderTree() { return groupView; } - - /** - * Access to the searchfield - */ - KLineEdit* searchField() { return filterEdit; } - - /** - * The item that should be selected on startup - */ - void setStartItem( const KGroupInfo &info ); - - /** - * Removes the item from the listview - */ - void removeListItem( TQListView *view, const KGroupInfo &gi ); - - /** - * Gets the item from the listview - * Returns 0 if the item can't be found - */ - TQListViewItem* getListItem( TQListView *view, const KGroupInfo &gi ); - - /** - * Is the item in the given listview - */ - bool itemInListView( TQListView *view, const KGroupInfo &gi ); - - /** - * Makes all changes after an item is toggled - * called by the item's stateChange-method - */ - void changeItemState( GroupItem* item, bool on ); - - /** - * Get/Set the direction of button1 - */ - Direction directionButton1() { return mDirButton1; } - void setDirectionButton1( Direction dir ); - - /** - * Get/Set the direction of button2 - */ - Direction directionButton2() { return mDirButton2; } - void setDirectionButton2( Direction dir ); - - /** - * Returns true if items are being constructed - * Call 'slotLoadingComplete' to switch this - */ - bool isLoading() { return mLoading; } - - /** - * Hide 'Disable tree view' checkbox - */ - void hideTreeCheckbox() { noTreeCB->hide(); } - - /** - * Hide 'New Only' checkbox - */ - void hideNewOnlyCheckbox() { newCB->hide(); } - - /** - * Update the item-states (visible, enabled) when a filter - * criteria changed - */ - void filterChanged( TQListViewItem* item = 0, - const TQString & text = TQString() ); - - /** - * The amount of items that are visible and enabled - */ - uint activeItemCount(); - - /** - * Moves all items from toplevel back to their original position - */ - void restoreOriginalParent(); - - /** - * Saves the open states - */ - void saveOpenStates(); - - /** - * Restores the saved open state - */ - void restoreOpenStates(); - - - public slots: - /** - * Call this slot when you have created all items - */ - void slotLoadingComplete(); - - /** - * Changes the current state of the buttons - */ - void slotChangeButtonState( TQListViewItem* ); - - /** - * Buttons are clicked - */ - void slotButton1(); - void slotButton2(); - - /** - * Updates the status-label - */ - void slotUpdateStatusLabel(); - - /** - * The reload-button is pressed - */ - void slotLoadFolders(); - - protected slots: - /** - * Slot for the checkboxes - */ - void slotCBToggled(); - - /** - * Filter text changed - */ - void slotFilterTextChanged( const TQString & text ); - - signals: - /** - * Emitted when the amount of items in the - * groupView changes (e.g. on filtering) - */ - void listChanged(); - - - protected: - // current account - KAccount* mAcct; - - // widgets - TQWidget *page; - TQListView *groupView; - TQListView *subView, *unsubView; - KLineEdit *filterEdit; - TQCheckBox *noTreeCB, *subCB, *newCB; - TQPushButton *arrowBtn1, *arrowBtn2; - TQIconSet pmRight, pmLeft; - TQGridLayout *listL; - TQLabel *leftLabel, *rightLabel; - - // false if all items are loaded - bool mLoading; - - // directions - Direction mDirButton1; - Direction mDirButton2; - - // remember last searchtext - TQString mLastText; - - // remember description column - int mDescrColumn; -}; - -#endif diff --git a/libkdepim/ktimeedit.cpp b/libkdepim/ktimeedit.cpp deleted file mode 100644 index c968f235c..000000000 --- a/libkdepim/ktimeedit.cpp +++ /dev/null @@ -1,292 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 1999 Preston Brown - Copyright (c) 1999 Ian Dawes - Copyright (C) 2003-2004 Reinhold Kainhofer - - 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. - - As a special exception, permission is given to link this program - with any edition of TQt, and distribute the resulting executable, - without including the source code for TQt in the source distribution. -*/ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "ktimeedit.h" -#include -#include "ktimeedit.moc" - -// Validator for a time value with only hours and minutes (no seconds) -// Mostly locale aware. Author: David Faure -class KOTimeValidator : public TQValidator -{ -public: - KOTimeValidator(TQWidget* parent, const char* name=0) : TQValidator(TQT_TQOBJECT(parent), name) {} - - virtual State validate(TQString& str, int& /*cursorPos*/) const - { - int length = str.length(); - // empty string is intermediate so one can clear the edit line and start from scratch - if ( length <= 0 ) - return Intermediate; - - bool ok = false; - /*TQTime time =*/ KGlobal::locale()->readTime(str, KLocale::WithoutSeconds, &ok); - if ( ok ) - return Acceptable; -// kdDebug(5300)<<"Time "<= 0 && m < 60 ) - return Intermediate; - } else if ( str[str.length()-1] == sep ) - { - TQString hours = str.left(length-1); - int h = hours.toInt(&ok); - if ( ok && h >= 0 && h < 24 ) - return Intermediate; - } -// return Invalid; - return Intermediate; - } - virtual void fixup ( TQString & input ) const { - bool ok = false; - KGlobal::locale()->readTime( input, KLocale::WithoutSeconds, &ok ); - if ( !ok ) { - // Also try to accept times in "military format", i.e. no delimiter, like 1200 - int tm = input.toInt( &ok ); - if ( ( 0 <= tm ) && ( tm < 2400 ) && ( tm%100 < 60 ) && ok ) { - input = KGlobal::locale()->formatTime( TQTime( tm / 100, tm % 100, 0 ) ); - } - } - } -}; - -// KTimeWidget/TQTimeEdit provide nicer editing, but don't provide a combobox. -// Difficult to get all in one... -// But TQt-3.2 will offer TQLineEdit::setMask, so a "99:99" mask would help. -KTimeEdit::KTimeEdit( TQWidget *parent, TQTime qt, const char *name ) - : TQComboBox( true, parent, name ) -{ - setInsertionPolicy( NoInsertion ); - setValidator( new KOTimeValidator( this ) ); - - mTime = qt; - -// mNoTimeString = i18n("No Time"); -// insertItem( mNoTimeString ); - - // Fill combo box with selection of times in localized format. - TQTime timeEntry(0,0,0); - do { - insertItem(KGlobal::locale()->formatTime(timeEntry)); - timeEntry = timeEntry.addSecs(60*15); - } while (!timeEntry.isNull()); - // Add end of day. - insertItem( KGlobal::locale()->formatTime( TQTime( 23, 59, 59 ) ) ); - - updateText(); - setFocusPolicy(TQ_StrongFocus); - - connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(active(int))); - connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(hilit(int))); - connect(this, TQT_SIGNAL(textChanged(const TQString&)),this,TQT_SLOT(changedText())); -} - -KTimeEdit::~KTimeEdit() -{ -} - -bool KTimeEdit::hasTime() const -{ - // Can't happen - if ( currentText().isEmpty() ) return false; - //if ( currentText() == mNoTimeString ) return false; - - return true; // always -} - -TQTime KTimeEdit::getTime() const -{ - //kdDebug(5300) << "KTimeEdit::getTime(), currentText() = " << currentText() << endl; - // TODO use KLocale::WithoutSeconds in HEAD - bool ok = false; - TQTime time = KGlobal::locale()->readTime( currentText(), KLocale::WithoutSeconds, &ok ); - if ( !ok ) { - // Also try to accept times in "military format", i.e. no delimiter, like 1200 - int tm = currentText().toInt( &ok ); - if ( ( 0 <= tm ) && ( tm < 2400 ) && ( tm%100 < 60 ) && ok ) { - time.setHMS( tm / 100, tm % 100, 0 ); - } else { - ok = false; - } - } - // kdDebug(5300) << "KTimeEdit::getTime(): " << time.toString() << endl; - return time; -} - -TQSizePolicy KTimeEdit::sizePolicy() const -{ - // Set size policy to Fixed, because edit cannot contain more text than the - // string representing the time. It doesn't make sense to provide more space. - TQSizePolicy sizePolicy(TQSizePolicy::Fixed,TQSizePolicy::Fixed); - - return sizePolicy; -} - -void KTimeEdit::setTime(TQTime newTime) -{ - if ( mTime != newTime ) - { - kdDebug(5300) << "KTimeEdit::setTime(): " << TQString(newTime.toString()) << endl; - - mTime = newTime; - updateText(); - } -} - -void KTimeEdit::active(int i) -{ - // The last entry, 23:59, is a special case - if( i == count() - 1 ) - mTime = TQTime( 23, 59, 0 ); - else - mTime = TQTime(0,0,0).addSecs(i*15*60); - emit timeChanged(mTime); -} - -void KTimeEdit::hilit(int ) -{ - // we don't currently need to do anything here. -} - -void KTimeEdit::addTime(TQTime qt) -{ - // Calculate the new time. - mTime = qt.addSecs(mTime.minute()*60+mTime.hour()*3600); - updateText(); - emit timeChanged(mTime); -} - -void KTimeEdit::subTime(TQTime qt) -{ - int h, m; - - // Note that we cannot use the same method for determining the new - // time as we did in addTime, because TQTime does not handle adding - // negative seconds well at all. - h = mTime.hour()-qt.hour(); - m = mTime.minute()-qt.minute(); - - if(m < 0) { - m += 60; - h -= 1; - } - - if(h < 0) { - h += 24; - } - - // store the newly calculated time. - mTime.setHMS(h, m, 0); - updateText(); - emit timeChanged(mTime); -} - -void KTimeEdit::keyPressEvent(TQKeyEvent *qke) -{ - switch(qke->key()) { - case Key_Down: - addTime(TQTime(0,1,0)); - break; - case Key_Up: - subTime(TQTime(0,1,0)); - break; - case Key_Prior: - subTime(TQTime(1,0,0)); - break; - case Key_Next: - addTime(TQTime(1,0,0)); - break; - default: - TQComboBox::keyPressEvent(qke); - break; - } // switch -} - -void KTimeEdit::updateText() -{ -// kdDebug(5300) << "KTimeEdit::updateText() " << endl; - TQString s = KGlobal::locale()->formatTime(mTime); - // Set the text but without emitting signals, nor losing the cursor position - TQLineEdit *line = lineEdit(); - line->blockSignals(true); - int pos = line->cursorPosition(); - - // select item with nearest time, must be done while line edit is blocked - // as setCurrentItem() calls setText() with triggers KTimeEdit::changedText() - setCurrentItem((mTime.hour()*4)+((mTime.minute()+7)/15)); - - line->setText(s); - line->setCursorPosition(pos); - line->blockSignals(false); - -// kdDebug(5300) << "KTimeEdit::updateText(): " << s << endl; -} - -bool KTimeEdit::inputIsValid() const -{ - int cursorPos = lineEdit()->cursorPosition(); - TQString str = currentText(); - return validator()->validate( str, cursorPos ) == TQValidator::Acceptable; -} - -void KTimeEdit::changedText() -{ - //kdDebug(5300) << "KTimeEdit::changedText()" << endl; - if ( inputIsValid() ) - { - mTime = getTime(); - emit timeChanged(mTime); - } -} diff --git a/libkdepim/ktimeedit.h b/libkdepim/ktimeedit.h deleted file mode 100644 index 11190842a..000000000 --- a/libkdepim/ktimeedit.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 1999 Preston Brown - Copyright (c) 1999 Ian Dawes - - 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. - - As a special exception, permission is given to link this program - with any edition of TQt, and distribute the resulting executable, - without including the source code for TQt in the source distribution. -*/ -#ifndef _KTIMEEDIT_H -#define _KTIMEEDIT_H - -#include -#include -#include -#include -#include - -#include -#include - -/** - This is a class that provides an easy, user friendly way to edit times. - up/down/ increase or decrease time, respectively. - - @short Provides a way to edit times in a user-friendly manner. - @author Preston Brown, Ian Dawes -*/ -class KDE_EXPORT KTimeEdit : public TQComboBox -{ - Q_OBJECT - TQ_OBJECT - public: - /** constructs a new time edit. */ - KTimeEdit(TQWidget *parent=0, TQTime qt=TQTime(12,0), const char *name=0); - - virtual ~KTimeEdit(); - - /** - Returns, if a time is selected. Can not return false anymore.... - */ - bool hasTime() const; - - /** returns the time that is currently set in the timeLineEdit. */ - TQTime getTime() const; - - /** returns the preferred size policy of the KTimeEdit */ - TQSizePolicy sizePolicy() const; - - /** return true if input is a valid time and false if not */ - bool inputIsValid() const; - - signals: - /** - Emitted every time the time displayed changes. "newt" is the new - time. - */ - void timeChanged(TQTime newt); - - public slots: - /** used to set the time which is displayed to a specific value. */ - void setTime(TQTime qt); - - protected slots: - void active(int); - void hilit(int); - void changedText(); - - protected: - virtual void keyPressEvent(TQKeyEvent *qke); - void addTime(TQTime qt); - void subTime(TQTime qt); - // Update the lineedit text from mTime - void updateText(); - -private: - TQTime mTime; // the widget's displayed time. - //TQString mNoTimeString; -}; - -#endif diff --git a/libkdepim/kvcarddrag.cpp b/libkdepim/kvcarddrag.cpp deleted file mode 100644 index 054a424e9..000000000 --- a/libkdepim/kvcarddrag.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kvcarddrag.h" - -#include - -static const char vcard_mime_string[] = "text/x-vcard"; - -#if defined(KABC_VCARD_ENCODING_FIX) -KVCardDrag::KVCardDrag( const TQByteArray &content, TQWidget *dragsource, const char *name ) -#else -KVCardDrag::KVCardDrag( const TQString &content, TQWidget *dragsource, const char *name ) -#endif - : TQStoredDrag( vcard_mime_string, dragsource, name ) -{ - setVCard( content ); -} - -KVCardDrag::KVCardDrag( TQWidget *dragsource, const char *name ) - : TQStoredDrag( vcard_mime_string, dragsource, name ) -{ -#if defined(KABC_VCARD_ENCODING_FIX) - setVCard( TQByteArray() ); -#else - setVCard( TQString() ); -#endif -} - -#if defined(KABC_VCARD_ENCODING_FIX) -void KVCardDrag::setVCard( const TQByteArray &content ) -{ - setEncodedData( content ); -} -#else -void KVCardDrag::setVCard( const TQString &content ) -{ - setEncodedData( content.utf8() ); -} -#endif - -bool KVCardDrag::canDecode( TQMimeSource *e ) -{ - return e->provides( vcard_mime_string ); -} - -#if defined(KABC_VCARD_ENCODING_FIX) -bool KVCardDrag::decode( TQMimeSource *e, TQByteArray &content ) -{ - if ( !canDecode( e ) ) { - return false; - } - content = e->tqencodedData( vcard_mime_string ); - return true; -} -#else -bool KVCardDrag::decode( TQMimeSource *e, TQString &content ) -{ - if ( !canDecode( e ) ) { - return false; - } - content = TQString::fromUtf8( e->tqencodedData( vcard_mime_string ) ); - return true; -} -#endif - -bool KVCardDrag::decode( TQMimeSource *e, KABC::Addressee::List& addressees ) -{ - if ( !canDecode( e ) ) { - return false; - } -#if defined(KABC_VCARD_ENCODING_FIX) - addressees = KABC::VCardConverter().parseVCardsRaw( e->tqencodedData( vcard_mime_string ).data() ); -#else - addressees = KABC::VCardConverter().parseVCards( e->tqencodedData( vcard_mime_string ) ); -#endif - return true; -} - -void KVCardDrag::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "kvcarddrag.moc" diff --git a/libkdepim/kvcarddrag.h b/libkdepim/kvcarddrag.h deleted file mode 100644 index 31885f6ad..000000000 --- a/libkdepim/kvcarddrag.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2002 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KVCARDDRAG_H -#define KVCARDDRAG_H - -#include -#include - -#include -#include // for KABC_VCARD_ENCODING_FIX define -#include - -class KVCardDragPrivate; - -/** - * A drag-and-drop object for vcards. The according MIME type - * is set to text/x-vcard. - * - * See the TQt drag'n'drop documentation. - */ -class KDE_EXPORT KVCardDrag : public TQStoredDrag -{ - Q_OBJECT - TQ_OBJECT - - public: - /** - * Constructs an empty vcard drag. - */ - KVCardDrag( TQWidget *dragsource = 0, const char *name = 0 ); - - /** - * Constructs a vcard drag with the @p addressee. - */ -#if defined(KABC_VCARD_ENCODING_FIX) - KVCardDrag( const TQByteArray &content, TQWidget *dragsource = 0, const char *name = 0 ); -#else - KVCardDrag( const TQString &content, TQWidget *dragsource = 0, const char *name = 0 ); -#endif - virtual ~KVCardDrag() {} - - /** - * Sets the vcard of the drag to @p content. - */ -#if defined(KABC_VCARD_ENCODING_FIX) - void setVCard( const TQByteArray &content ); -#else - void setVCard( const TQString &content ); -#endif - /** - * Returns true if the MIME source @p e contains a vcard object. - */ - static bool canDecode( TQMimeSource *e ); - - /** - * Decodes the MIME source @p e and puts the resulting vcard into @p content. - */ -#if defined(KABC_VCARD_ENCODING_FIX) - static bool decode( TQMimeSource *e, TQByteArray &content ); -#else - static bool decode( TQMimeSource *e, TQString &content ); -#endif - - /** - * Decodes the MIME source @p e and puts the resulting vcard into @p addresseess. - */ - static bool decode( TQMimeSource *e, KABC::Addressee::List& addressees ); - - protected: - virtual void virtual_hook( int id, void* data ); - - private: - KVCardDragPrivate *d; -}; - -#endif // KVCARDDRAG_H diff --git a/libkdepim/kwidgetlister.cpp b/libkdepim/kwidgetlister.cpp deleted file mode 100644 index b2b839f43..000000000 --- a/libkdepim/kwidgetlister.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- c++ -*- - kwidgetlister.cpp - - This file is part of libkdenetwork. - Copyright (c) 2001 Marc Mutz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - This library 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 library; 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 library with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 "kwidgetlister.h" - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -KWidgetLister::KWidgetLister( int minWidgets, int maxWidgets, TQWidget *parent, const char* name ) - : TQWidget( parent, name ) -{ - mWidgetList.setAutoDelete(TRUE); - - mMinWidgets = TQMAX( minWidgets, 1 ); - mMaxWidgets = TQMAX( maxWidgets, mMinWidgets + 1 ); - - //--------- the button box - mLayout = new TQVBoxLayout(this, 0, 4); - mButtonBox = new TQHBox(this); - mButtonBox->setSpacing( KDialog::spacingHint() ); - mLayout->addWidget( mButtonBox ); - - mBtnMore = new KPushButton( KGuiItem( i18n( "more widgets", "More" ), "button_more" ), mButtonBox ); - mButtonBox->setStretchFactor( mBtnMore, 0 ); - - mBtnFewer = new KPushButton( KGuiItem( i18n( "fewer widgets", "Fewer" ), "button_fewer" ), mButtonBox ); - mButtonBox->setStretchFactor( mBtnFewer, 0 ); - - TQWidget *spacer = new TQWidget( mButtonBox ); - mButtonBox->setStretchFactor( spacer, 1 ); - - // FIXME: We need a KStdGuiItem::clear here and in other locations to be automagically RTL aware - Martijn - mBtnClear = new KPushButton( KGuiItem( i18n( "clear widgets", "Clear" ), "locationbar_erase" ), mButtonBox ); - mButtonBox->setStretchFactor( mBtnClear, 0 ); - - //---------- connect everything - connect( mBtnMore, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotMore()) ); - connect( mBtnFewer, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotFewer()) ); - connect( mBtnClear, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotClear()) ); - - enableControls(); -} - -KWidgetLister::~KWidgetLister() -{ -} - -void KWidgetLister::slotMore() -{ - // the class should make certain that slotMore can't - // be called when mMaxWidgets are on screen. - assert( (int)mWidgetList.count() < mMaxWidgets ); - - addWidgetAtEnd(); - // adjustSize(); - enableControls(); -} - -void KWidgetLister::slotFewer() -{ - // the class should make certain that slotFewer can't - // be called when mMinWidgets are on screen. - assert( (int)mWidgetList.count() > mMinWidgets ); - - removeLastWidget(); - // adjustSize(); - enableControls(); -} - -void KWidgetLister::slotClear() -{ - setNumberOfShownWidgetsTo( mMinWidgets ); - - // clear remaining widgets - TQPtrListIterator it( mWidgetList ); - for ( it.toFirst() ; it.current() ; ++it ) - clearWidget( (*it) ); - - // adjustSize(); - enableControls(); - emit clearWidgets(); -} - -void KWidgetLister::addWidgetAtEnd(TQWidget *w) -{ - if (!w) w = this->createWidget(this); - - mLayout->insertWidget( mLayout->findWidget( mButtonBox ), w ); - mWidgetList.append( w ); - w->show(); - enableControls(); - emit widgetAdded(); - emit widgetAdded(w); -} - -void KWidgetLister::removeLastWidget() -{ - // The tqlayout will take care that the - // widget is removed from screen, too. - mWidgetList.removeLast(); - enableControls(); - emit widgetRemoved(); -} - -void KWidgetLister::clearWidget( TQWidget* /*aWidget*/ ) -{ -} - -TQWidget* KWidgetLister::createWidget( TQWidget* parent ) -{ - return new TQWidget( parent ); -} - -void KWidgetLister::setNumberOfShownWidgetsTo( int aNum ) -{ - int superfluousWidgets = TQMAX( (int)mWidgetList.count() - aNum, 0 ); - int missingWidgets = TQMAX( aNum - (int)mWidgetList.count(), 0 ); - - // remove superfluous widgets - for ( ; superfluousWidgets ; superfluousWidgets-- ) - removeLastWidget(); - - // add missing widgets - for ( ; missingWidgets ; missingWidgets-- ) - addWidgetAtEnd(); -} - -void KWidgetLister::enableControls() -{ - int count = mWidgetList.count(); - bool isMaxWidgets = ( count >= mMaxWidgets ); - bool isMinWidgets = ( count <= mMinWidgets ); - - mBtnMore->setEnabled( !isMaxWidgets ); - mBtnFewer->setEnabled( !isMinWidgets ); -} - -#include "kwidgetlister.moc" diff --git a/libkdepim/kwidgetlister.h b/libkdepim/kwidgetlister.h deleted file mode 100644 index db993297f..000000000 --- a/libkdepim/kwidgetlister.h +++ /dev/null @@ -1,154 +0,0 @@ -/* -*- c++ -*- - kwidgetlister.h - - This file is part of libkdenetwork. - Copyright (c) 2001 Marc Mutz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License, - version 2, as published by the Free Software Foundation. - - This library 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 library; 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 library with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 _KWIDGETLISTER_H_ -#define _KWIDGETLISTER_H_ - -#include -#include -#include - -class TQPushButton; -class TQVBoxLayout; -class TQHBox; - -/** - @short Widget that manages a list of other widgets (incl. 'more', 'fewer' and 'clear' buttons). - - Simple widget that nonetheless does a lot of the dirty work for - the filter edit widgets (KMSearchPatternEdit and - KMFilterActionEdit). It provides a growable and shrinkable area - where widget may be displayed in rows. Widgets can be added by - hitting the provided 'More' button, removed by the 'Fewer' button - and cleared (e.g. reset, if an derived class implements that and - removed for all but @ref mMinWidgets). - - To use this widget, derive from it with the template changed to - the type of widgets this class should list. Then reimplement @ref - addWidgetAtEnd, @ref removeLastWidget, calling the original - implementation as necessary. Instantiate an object of the class and - put it in your dialog. - - @author Marc Mutz - @see KMSearchPatternEdit::WidgetLister KMFilterActionEdit::WidgetLister - -*/ - -class KDE_EXPORT KWidgetLister : public TQWidget -{ - Q_OBJECT - TQ_OBJECT -public: - KWidgetLister( int minWidgets=1, int maxWidgets=8, TQWidget* parent=0, const char* name=0 ); - virtual ~KWidgetLister(); - -protected slots: - /** Called whenever the user clicks on the 'more' button. - Reimplementations should call this method, because this - implementation does all the dirty work with adding the widgets - to the tqlayout (through @ref addWidgetAtEnd) and enabling/disabling - the control buttons. */ - virtual void slotMore(); - /** Called whenever the user clicks on the 'fewer' button. - Reimplementations should call this method, because this - implementation does all the dirty work with removing the widgets - from the tqlayout (through @ref removeLastWidget) and - enabling/disabling the control buttons. */ - virtual void slotFewer(); - /** Called whenever the user clicks on the 'clear' button. - Reimplementations should call this method, because this - implementation does all the dirty work with removing all but - @ref mMinWidgets widgets from the tqlayout and enabling/disabling - the control buttons. */ - virtual void slotClear(); - - - -protected: - /** Adds a single widget. Doesn't care if there are already @ref - mMaxWidgets on screen and whether it should enable/disable any - controls. It simply does what it is asked to do. You want to - reimplement this method if you want to initialize the the widget - when showing it on screen. Make sure you call this - implementaion, though, since you cannot put the widget on screen - from derived classes (@p mLayout is private). - Make sure the parent of the TQWidget to add is this KWidgetLister. */ - virtual void addWidgetAtEnd(TQWidget *w =0); - /** Removes a single (always the last) widget. Doesn't care if there - are still only @ref mMinWidgets left on screen and whether it - should enable/disable any controls. It simply does what it is - asked to do. You want to reimplement this method if you want to - save the the widget's state before removing it from screen. Make - sure you call this implementaion, though, since you should not - remove the widget from screen from derived classes. */ - virtual void removeLastWidget(); - /** Called to clear a given widget. The default implementation does - nothing. */ - virtual void clearWidget( TQWidget* ); - /** Because QT 2.x does not support signals/slots in template - classes, we are forced to emulate this by forcing the - implementers of subclasses of KWidgetLister to reimplement this - function which replaces the "@p new @p T" call. */ - virtual TQWidget* createWidget( TQWidget *parent ); - /** Sets the number of widgets on scrren to exactly @p aNum. Doesn't - check if @p aNum is inside the range @p - [mMinWidgets,mMaxWidgets]. */ - virtual void setNumberOfShownWidgetsTo( int aNum ); - /** The list of widgets. Note that this list is set to auto-delete, - meaning that widgets that are removed from the screen by either - @ref slotFewer or @ref slotClear will be destroyed! */ - TQPtrList mWidgetList; - /** The minimum number of widgets that are to stay on screen. */ - int mMinWidgets; - /** The maximum number of widgets that are to be shown on screen. */ - int mMaxWidgets; - -signals: - /** This signal is emitted whenever a widget was added */ - void widgetAdded(); - /** This signal is emitted whenever a widget was added */ - void widgetAdded(TQWidget *); - /** This signal is emitted whenever a widget was removed */ - void widgetRemoved(); - /** This signal is emitted whenever the clear button is clicked */ - void clearWidgets(); - -private: - void enableControls(); - - TQPushButton *mBtnMore, *mBtnFewer, *mBtnClear; - TQVBoxLayout *mLayout; - TQHBox *mButtonBox; -}; - - - -#endif /* _KWIDGETLISTER_H_ */ diff --git a/libkdepim/kxface.cpp b/libkdepim/kxface.cpp deleted file mode 100644 index 210fefb5f..000000000 --- a/libkdepim/kxface.cpp +++ /dev/null @@ -1,729 +0,0 @@ -/* - This file is part of libtdepim. - - Original compface: - Copyright (c) James Ashton - Sydney University - June 1990. - - Additions for KDE: - Copyright (c) 2004 Jakob Schröter - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kxface.h" - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#define GEN(g) F[h] ^= G.g[k]; break - -#define BITSPERDIG 4 -#define DIGITS (PIXELS / BITSPERDIG) -#define DIGSPERWORD 4 -#define WORDSPERLINE (WIDTH / DIGSPERWORD / BITSPERDIG) - -/* compressed output uses the full range of printable characters. - * in ascii these are in a contiguous block so we just need to know - * the first and last. The total number of printables is needed too */ -#define FIRSTPRINT '!' -#define LASTPRINT '~' -#define NUMPRINTS (LASTPRINT - FIRSTPRINT + 1) - -/* output line length for compressed data */ -#define MAXLINELEN 78 - -/* Portable, very large unsigned integer arithmetic is needed. - * Implementation uses arrays of WORDs. COMPs must have at least - * twice as many bits as WORDs to handle intermediate results */ -#define COMP unsigned long -#define WORDCARRY (1 << BITSPERWORD) -#define WORDMASK (WORDCARRY - 1) - -#define ERR_OK 0 /* successful completion */ -#define ERR_EXCESS 1 /* completed OK but some input was ignored */ -#define ERR_INSUFF -1 /* insufficient input. Bad face format? */ -#define ERR_INTERNAL -2 /* Arithmetic overflow or buffer overflow */ - -#define BLACK 0 -#define GREY 1 -#define WHITE 2 - -#define MAX_XFACE_LENGTH 2048 - -using namespace KPIM; - -KXFace::KXFace() -{ - NumProbs = 0; -} - -KXFace::~KXFace() -{ -} - -TQString KXFace::fromImage( const TQImage &image ) -{ - if( image.isNull() ) - return TQString(); - - TQImage scaledImg = image.smoothScale( 48, 48 ); - TQByteArray ba; - TQBuffer buffer( ba ); - buffer.open( IO_WriteOnly ); - scaledImg.save( &buffer, "XBM" ); - TQString xbm( ba ); - xbm.remove( 0, xbm.find( "{" ) + 1 ); - xbm.truncate( xbm.find( "}" ) ); - xbm.remove( " " ); - xbm.remove( "," ); - xbm.remove( "0x" ); - xbm.remove( "\n" ); - xbm.truncate( 576 ); - TQCString tmp = TQCString( xbm.latin1() ); - uint len = tmp.length(); - for( uint i=0; i MAX_XFACE_LENGTH ) - return TQImage(); - - char *fbuf = (char *)malloc( MAX_XFACE_LENGTH ); - memset( fbuf, '\0', MAX_XFACE_LENGTH ); - strncpy( fbuf, xface.latin1(), xface.length() ); - TQCString img; - if ( !( status = setjmp( comp_env ) ) ) - { - UnCompAll( fbuf );/* compress otherwise */ - UnGenFace(); - img = WriteFace(); - } - free( fbuf ); - TQImage p; - p.loadFromData( img, "XBM" ); - - return p; -} - -//============================================================================ -// more or less original compface 1.4 source - -void KXFace::RevPush(const Prob *p) -{ - if (NumProbs >= PIXELS * 2 - 1) - longjmp(comp_env, ERR_INTERNAL); - ProbBuf[NumProbs++] = (Prob *) p; -} - -void KXFace::BigPush(Prob *p) -{ - static unsigned char tmp; - - BigDiv(p->p_range, &tmp); - BigMul(0); - BigAdd(tmp + p->p_offset); -} - -int KXFace::BigPop(register const Prob *p) -{ - static unsigned char tmp; - register int i; - - BigDiv(0, &tmp); - i = 0; - while ((tmp < p->p_offset) || (tmp >= p->p_range + p->p_offset)) - { - p++; - i++; - } - BigMul(p->p_range); - BigAdd(tmp - p->p_offset); - return i; -} - - -/* Divide B by a storing the result in B and the remainder in the word - * pointer to by r - */ -void KXFace::BigDiv(register unsigned char a, register unsigned char *r) -{ - register int i; - register unsigned char *w; - register COMP c, d; - - a &= WORDMASK; - if ((a == 1) || (B.b_words == 0)) - { - *r = 0; - return; - } - if (a == 0) /* treat this as a == WORDCARRY */ - { /* and just shift everything right a WORD (unsigned char)*/ - i = --B.b_words; - w = B.b_word; - *r = *w; - while (i--) - { - *w = *(w + 1); - w++; - } - *w = 0; - return; - } - w = B.b_word + (i = B.b_words); - c = 0; - while (i--) - { - c <<= BITSPERWORD; - c += (COMP)*--w; - d = c / (COMP)a; - c = c % (COMP)a; - *w = (unsigned char)(d & WORDMASK); - } - *r = c; - if (B.b_word[B.b_words - 1] == 0) - B.b_words--; -} - -/* Multiply a by B storing the result in B - */ -void KXFace::BigMul(register unsigned char a) -{ - register int i; - register unsigned char *w; - register COMP c; - - a &= WORDMASK; - if ((a == 1) || (B.b_words == 0)) - return; - if (a == 0) /* treat this as a == WORDCARRY */ - { /* and just shift everything left a WORD (unsigned char) */ - if ((i = B.b_words++) >= MAXWORDS - 1) - longjmp(comp_env, ERR_INTERNAL); - w = B.b_word + i; - while (i--) - { - *w = *(w - 1); - w--; - } - *w = 0; - return; - } - i = B.b_words; - w = B.b_word; - c = 0; - while (i--) - { - c += (COMP)*w * (COMP)a; - *(w++) = (unsigned char)(c & WORDMASK); - c >>= BITSPERWORD; - } - if (c) - { - if (B.b_words++ >= MAXWORDS) - longjmp(comp_env, ERR_INTERNAL); - *w = (COMP)(c & WORDMASK); - } -} - -/* Add to a to B storing the result in B - */ -void KXFace::BigAdd(unsigned char a) -{ - register int i; - register unsigned char *w; - register COMP c; - - a &= WORDMASK; - if (a == 0) - return; - i = 0; - w = B.b_word; - c = a; - while ((i < B.b_words) && c) - { - c += (COMP)*w; - *w++ = (unsigned char)(c & WORDMASK); - c >>= BITSPERWORD; - i++; - } - if ((i == B.b_words) && c) - { - if (B.b_words++ >= MAXWORDS) - longjmp(comp_env, ERR_INTERNAL); - *w = (COMP)(c & WORDMASK); - } -} - -void KXFace::BigClear() -{ - B.b_words = 0; -} - -TQCString KXFace::WriteFace() -{ - register char *s; - register int i, j, bits, digits, words; - int digsperword = DIGSPERWORD; - int wordsperline = WORDSPERLINE; - TQCString t( "#define noname_width 48\n#define noname_height 48\nstatic char noname_bits[] = {\n " ); - j = t.length() - 1; - - s = F; - bits = digits = words = i = 0; - t.resize( MAX_XFACE_LENGTH ); - digsperword = 2; - wordsperline = 15; - while ( s < F + PIXELS ) - { - if ( ( bits == 0 ) && ( digits == 0 ) ) - { - t[j++] = '0'; - t[j++] = 'x'; - } - if ( *(s++) ) - i = ( i >> 1 ) | 0x8; - else - i >>= 1; - if ( ++bits == BITSPERDIG ) - { - j++; - t[j-( ( digits & 1 ) * 2 )] = *(i + HexDigits); - bits = i = 0; - if ( ++digits == digsperword ) - { - if ( s >= F + PIXELS ) - break; - t[j++] = ','; - digits = 0; - if ( ++words == wordsperline ) - { - t[j++] = '\n'; - t[j++] = ' '; - words = 0; - } - } - } - } - t.resize( j + 1 ); - t += "};\n"; - return t; -} - -void KXFace::UnCompAll(char *fbuf) -{ - register char *p; - - BigClear(); - BigRead(fbuf); - p = F; - while (p < F + PIXELS) - *(p++) = 0; - UnCompress(F, 16, 16, 0); - UnCompress(F + 16, 16, 16, 0); - UnCompress(F + 32, 16, 16, 0); - UnCompress(F + WIDTH * 16, 16, 16, 0); - UnCompress(F + WIDTH * 16 + 16, 16, 16, 0); - UnCompress(F + WIDTH * 16 + 32, 16, 16, 0); - UnCompress(F + WIDTH * 32, 16, 16, 0); - UnCompress(F + WIDTH * 32 + 16, 16, 16, 0); - UnCompress(F + WIDTH * 32 + 32, 16, 16, 0); -} - -void KXFace::UnCompress(char *f, int wid, int hei, int lev) -{ - switch (BigPop(&levels[lev][0])) - { - case WHITE : - return; - case BLACK : - PopGreys(f, wid, hei); - return; - default : - wid /= 2; - hei /= 2; - lev++; - UnCompress(f, wid, hei, lev); - UnCompress(f + wid, wid, hei, lev); - UnCompress(f + hei * WIDTH, wid, hei, lev); - UnCompress(f + wid + hei * WIDTH, wid, hei, lev); - return; - } -} - -void KXFace::BigWrite(register char *fbuf) -{ - static unsigned char tmp; - static char buf[DIGITS]; - register char *s; - register int i; - - s = buf; - while (B.b_words > 0) - { - BigDiv(NUMPRINTS, &tmp); - *(s++) = tmp + FIRSTPRINT; - } - i = 7; // leave room for the field name on the first line - *(fbuf++) = ' '; - while (s-- > buf) - { - if (i == 0) - *(fbuf++) = ' '; - *(fbuf++) = *s; - if (++i >= MAXLINELEN) - { - *(fbuf++) = '\n'; - i = 0; - } - } - if (i > 0) - *(fbuf++) = '\n'; - *(fbuf++) = '\0'; -} - -void KXFace::BigRead(register char *fbuf) -{ - register int c; - - while (*fbuf != '\0') - { - c = *(fbuf++); - if ((c < FIRSTPRINT) || (c > LASTPRINT)) - continue; - BigMul(NUMPRINTS); - BigAdd((unsigned char)(c - FIRSTPRINT)); - } -} - -void KXFace::ReadFace(char *fbuf) -{ - register int c, i; - register char *s, *t; - - t = s = fbuf; - for(i = strlen(s); i > 0; i--) - { - c = (int)*(s++); - if ((c >= '0') && (c <= '9')) - { - if (t >= fbuf + DIGITS) - { - status = ERR_EXCESS; - break; - } - *(t++) = c - '0'; - } - else if ((c >= 'A') && (c <= 'F')) - { - if (t >= fbuf + DIGITS) - { - status = ERR_EXCESS; - break; - } - *(t++) = c - 'A' + 10; - } - else if ((c >= 'a') && (c <= 'f')) - { - if (t >= fbuf + DIGITS) - { - status = ERR_EXCESS; - break; - } - *(t++) = c - 'a' + 10; - } - else if (((c == 'x') || (c == 'X')) && (t > fbuf) && (*(t-1) == 0)) - t--; - } - if (t < fbuf + DIGITS) - longjmp(comp_env, ERR_INSUFF); - s = fbuf; - t = F; - c = 1 << (BITSPERDIG - 1); - while (t < F + PIXELS) - { - *(t++) = (*s & c) ? 1 : 0; - if ((c >>= 1) == 0) - { - s++; - c = 1 << (BITSPERDIG - 1); - } - } -} - -void KXFace::GenFace() -{ - static char newp[PIXELS]; - register char *f1; - register char *f2; - register int i; - - f1 = newp; - f2 = F; - i = PIXELS; - while (i-- > 0) - *(f1++) = *(f2++); - Gen(newp); -} - -void KXFace::UnGenFace() -{ - Gen(F); -} - -// static -void KXFace::Gen(register char *f) -{ - register int m, l, k, j, i, h; - - for (j = 0; j < HEIGHT; j++) - { - for (i = 0; i < WIDTH; i++) - { - h = i + j * WIDTH; - k = 0; - for (l = i - 2; l <= i + 2; l++) - for (m = j - 2; m <= j; m++) - { - if ((l >= i) && (m == j)) - continue; - if ((l > 0) && (l <= WIDTH) && (m > 0)) - k = *(f + l + m * WIDTH) ? k * 2 + 1 : k * 2; - } - switch (i) - { - case 1 : - switch (j) - { - case 1 : GEN(g_22); - case 2 : GEN(g_21); - default : GEN(g_20); - } - break; - case 2 : - switch (j) - { - case 1 : GEN(g_12); - case 2 : GEN(g_11); - default : GEN(g_10); - } - break; - case WIDTH - 1 : - switch (j) - { - case 1 : GEN(g_42); - case 2 : GEN(g_41); - default : GEN(g_40); - } - break; - /* i runs from 0 to WIDTH-1, so case can never occur. I leave the code in - because it appears exactly like this in the original compface code. - case WIDTH : - switch (j) - { - case 1 : GEN(g_32); - case 2 : GEN(g_31); - default : GEN(g_30); - } - break; - */ - default : - switch (j) - { - case 1 : GEN(g_02); - case 2 : GEN(g_01); - default : GEN(g_00); - } - break; - } - } - } -} - -void KXFace::PopGreys(char *f, int wid, int hei) -{ - if (wid > 3) - { - wid /= 2; - hei /= 2; - PopGreys(f, wid, hei); - PopGreys(f + wid, wid, hei); - PopGreys(f + WIDTH * hei, wid, hei); - PopGreys(f + WIDTH * hei + wid, wid, hei); - } - else - { - wid = BigPop(freqs); - if (wid & 1) - *f = 1; - if (wid & 2) - *(f + 1) = 1; - if (wid & 4) - *(f + WIDTH) = 1; - if (wid & 8) - *(f + WIDTH + 1) = 1; - } -} - -void KXFace::CompAll(char *fbuf) -{ - Compress(F, 16, 16, 0); - Compress(F + 16, 16, 16, 0); - Compress(F + 32, 16, 16, 0); - Compress(F + WIDTH * 16, 16, 16, 0); - Compress(F + WIDTH * 16 + 16, 16, 16, 0); - Compress(F + WIDTH * 16 + 32, 16, 16, 0); - Compress(F + WIDTH * 32, 16, 16, 0); - Compress(F + WIDTH * 32 + 16, 16, 16, 0); - Compress(F + WIDTH * 32 + 32, 16, 16, 0); - BigClear(); - while (NumProbs > 0) - BigPush(ProbBuf[--NumProbs]); - BigWrite(fbuf); -} - -void KXFace::Compress(register char *f, register int wid, register int hei, register int lev) -{ - if (AllWhite(f, wid, hei)) - { - RevPush(&levels[lev][WHITE]); - return; - } - if (AllBlack(f, wid, hei)) - { - RevPush(&levels[lev][BLACK]); - PushGreys(f, wid, hei); - return; - } - RevPush(&levels[lev][GREY]); - wid /= 2; - hei /= 2; - lev++; - Compress(f, wid, hei, lev); - Compress(f + wid, wid, hei, lev); - Compress(f + hei * WIDTH, wid, hei, lev); - Compress(f + wid + hei * WIDTH, wid, hei, lev); -} - -int KXFace::AllWhite(char *f, int wid, int hei) -{ - return ((*f == 0) && Same(f, wid, hei)); -} - -int KXFace::AllBlack(char *f, int wid, int hei) -{ - if (wid > 3) - { - wid /= 2; - hei /= 2; - return (AllBlack(f, wid, hei) && AllBlack(f + wid, wid, hei) && - AllBlack(f + WIDTH * hei, wid, hei) && - AllBlack(f + WIDTH * hei + wid, wid, hei)); - } - else - return (*f || *(f + 1) || *(f + WIDTH) || *(f + WIDTH + 1)); -} - -int KXFace::Same(register char *f, register int wid, register int hei) -{ - register char val, *row; - register int x; - - val = *f; - while (hei--) - { - row = f; - x = wid; - while (x--) - if (*(row++) != val) - return(0); - f += WIDTH; - } - return 1; -} - -void KXFace::PushGreys(char *f, int wid, int hei) -{ - if (wid > 3) - { - wid /= 2; - hei /= 2; - PushGreys(f, wid, hei); - PushGreys(f + wid, wid, hei); - PushGreys(f + WIDTH * hei, wid, hei); - PushGreys(f + WIDTH * hei + wid, wid, hei); - } - else - RevPush(freqs + *f + 2 * *(f + 1) + 4 * *(f + WIDTH) + - 8 * *(f + WIDTH + 1)); -} - - -#include "kxface.moc" diff --git a/libkdepim/kxface.h b/libkdepim/kxface.h deleted file mode 100644 index 770232306..000000000 --- a/libkdepim/kxface.h +++ /dev/null @@ -1,594 +0,0 @@ -/* - This file is part of libtdepim. - - Original compface: - Copyright (c) James Ashton - Sydney University - June 1990. - - Additions for KDE: - Copyright (c) 2004 Jakob Schröter - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __KXFACE_H -#define __KXFACE_H - - -#include -#include - -#include - -// #define WIDTH 48 -// #define HEIGHT WIDTH - -/* total number of pixels and digits */ -// #define PIXELS (WIDTH * HEIGHT) -// #define WORD unsigned char -// #define MAXWORDS ((PIXELS * 2 + BITSPERWORD - 1) / BITSPERWORD) -// #define BITSPERWORD 8 - - -typedef struct guesses -{ - char g_00[1<<12]; - char g_01[1<<7]; - char g_02[1<<2]; - char g_10[1<<9]; - char g_20[1<<6]; - char g_30[1<<8]; - char g_40[1<<10]; - char g_11[1<<5]; - char g_21[1<<3]; - char g_31[1<<5]; - char g_41[1<<6]; - char g_12[1<<1]; - char g_22[1<<0]; - char g_32[1<<2]; - char g_42[1<<2]; -} Guesses; - -static const Guesses G = -{ - { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, - 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, - 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, - 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, - 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, - 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, - 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, - 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, - 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, - 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, - 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, - 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, - 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, - 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, - 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, - 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, - 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, - 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, - 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, - 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, - 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - }, - { - 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, - 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, - 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, - 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - }, - { - 0, 1, 0, 1, - }, - { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, - 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, - 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, - 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, - 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - }, - { - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, - }, - { - 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, - 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, - 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, - }, - { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, - 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, - 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - }, - { - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - }, - { - 0, 0, 0, 1, 0, 1, 1, 1, - }, - { - 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, - 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - }, - { - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - }, - { - 0, 1, - }, - { - 0, - }, - { - 0, 0, 0, 1, - }, - { - 0, 0, 0, 1, - } -}; - -typedef struct prob -{ - int p_range; - int p_offset; -} Prob; - - - -static const Prob levels[4][3] = { - {{1, 255}, {251, 0}, {4, 251}}, /* Top of tree almost always grey */ - {{1, 255}, {200, 0}, {55, 200}}, - {{33, 223}, {159, 0}, {64, 159}}, - {{131, 0}, {0, 0}, {125, 131}} /* Grey disallowed at bottom */ -}; - -static const Prob freqs[16] = { - {0, 0}, {38, 0}, {38, 38}, {13, 152}, - {38, 76}, {13, 165}, {13, 178}, {6, 230}, - {38, 114}, {13, 191}, {13, 204}, {6, 236}, - {13, 217}, {6, 242}, {5, 248}, {3, 253} -}; - -static const char HexDigits[] = "0123456789ABCDEF"; - - -class TQImage; -class TQString; - -namespace KPIM { - - class KDE_EXPORT KXFace : public TQObject - { - Q_OBJECT - TQ_OBJECT - - public: - KXFace(); - virtual ~KXFace(); - - /** - * generates the xface string from @p image - */ - TQString fromImage(const TQImage &image); - - /** - * creates a pixmap from @p xface - */ - TQImage toImage(const TQString &xface); - - - private: - static const int WIDTH = 48; - static const int HEIGHT = WIDTH; - static const int PIXELS = (WIDTH * HEIGHT); - static const int BITSPERWORD = 8; - static const int MAXWORDS = ((PIXELS * 2 + BITSPERWORD - 1) / BITSPERWORD); - - int NumProbs; - int status; - int compface_xbitmap; - - char F[PIXELS]; - Prob *ProbBuf[PIXELS * 2]; - - jmp_buf comp_env; - - typedef struct bigint - { - int b_words; - unsigned char b_word[MAXWORDS]; - } BigInt; - - BigInt B; - - void RevPush(const Prob *p); - void BigPush(Prob *p); - int BigPop(register const Prob *p); - void BigDiv(register unsigned char a, register unsigned char *r); - void BigMul(register unsigned char a); - void BigAdd(unsigned char a); - void BigClear(); - - TQCString WriteFace(); - void UnCompAll(char *fbuf); - void UnCompress(register char *f, register int wid, register int hei, register int lev); - void BigWrite(register char *fbuf); - void BigRead(register char *fbuf); - void ReadFace(char *fbuf); - void GenFace(); - void UnGenFace(); - void Gen(register char *f); - void PopGreys(char *f, int wid, int hei); - void CompAll(char *fbuf); - void Compress(register char *f, register int wid, register int hei, register int lev); - int AllWhite(char *f, int wid, int hei); - int AllBlack(char *f, int wid, int hei); - int Same(register char *f, register int wid, register int hei); - void PushGreys(char *f, int wid, int hei); - - - }; -} // namespace KPIM -#endif // __KXFACE_H diff --git a/libkdepim/ldapclient.cpp b/libkdepim/ldapclient.cpp deleted file mode 100644 index f8497f084..000000000 --- a/libkdepim/ldapclient.cpp +++ /dev/null @@ -1,613 +0,0 @@ -/* kldapclient.cpp - LDAP access - * Copyright (C) 2002 Klarälvdalens Datakonsult AB - * - * Author: Steffen Hansen - * - * Ported to KABC by Daniel Molkentin - * - * This file 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 file 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 "ldapclient.h" - -using namespace KPIM; - -KConfig *KPIM::LdapSearch::s_config = 0L; -static KStaticDeleter configDeleter; - -TQString LdapObject::toString() const -{ - TQString result = TQString::tqfromLatin1( "\ndn: %1\n" ).tqarg( dn ); - for ( LdapAttrMap::ConstIterator it = attrs.begin(); it != attrs.end(); ++it ) { - TQString attr = it.key(); - for ( LdapAttrValue::ConstIterator it2 = (*it).begin(); it2 != (*it).end(); ++it2 ) { - result += TQString::fromUtf8( KABC::LDIF::assembleLine( attr, *it2, 76 ) ) + "\n"; - } - } - - return result; -} - -void LdapObject::clear() -{ - dn = TQString(); - objectClass = TQString(); - attrs.clear(); -} - -void LdapObject::assign( const LdapObject& that ) -{ - if ( &that != this ) { - dn = that.dn; - attrs = that.attrs; - client = that.client; - } -} - -LdapClient::LdapClient( int clientNumber, TQObject* parent, const char* name ) - : TQObject( parent, name ), mJob( 0 ), mActive( false ), mReportObjectClass( false ) -{ -// d = new LdapClientPrivate; - mClientNumber = clientNumber; - mCompletionWeight = 50 - mClientNumber; -} - -LdapClient::~LdapClient() -{ - cancelQuery(); -// delete d; d = 0; -} - -void LdapClient::setAttrs( const TQStringList& attrs ) -{ - mAttrs = attrs; - for ( TQStringList::Iterator it = mAttrs.begin(); it != mAttrs.end(); ++it ) - if( (*it).lower() == "objectclass" ){ - mReportObjectClass = true; - return; - } - mAttrs << "objectClass"; // via objectClass we detect distribution lists - mReportObjectClass = false; -} - -void LdapClient::startQuery( const TQString& filter ) -{ - cancelQuery(); - KABC::LDAPUrl url; - - url.setProtocol( ( mServer.security() == LdapServer::SSL ) ? "ldaps" : "ldap" ); - if ( mServer.auth() != LdapServer::Anonymous ) { - url.setUser( mServer.user() ); - url.setPass( mServer.pwdBindDN() ); - } - url.setHost( mServer.host() ); - url.setPort( mServer.port() ); - url.setExtension( "x-ver", TQString::number( mServer.version() ) ); - url.setDn( mServer.baseDN() ); - url.setDn( mServer.baseDN() ); - if ( mServer.security() == LdapServer::TLS ) url.setExtension( "x-tls","" ); - if ( mServer.auth() == LdapServer::SASL ) { - url.setExtension( "x-sasl","" ); - if ( !mServer.bindDN().isEmpty() ) url.setExtension( "x-bindname", mServer.bindDN() ); - if ( !mServer.mech().isEmpty() ) url.setExtension( "x-mech", mServer.mech() ); - } - if ( mServer.timeLimit() != 0 ) url.setExtension( "x-timelimit", - TQString::number( mServer.timeLimit() ) ); - if ( mServer.sizeLimit() != 0 ) url.setExtension( "x-sizelimit", - TQString::number( mServer.sizeLimit() ) ); - - url.setAttributes( mAttrs ); - url.setScope( mScope == "one" ? KABC::LDAPUrl::One : KABC::LDAPUrl::Sub ); - url.setFilter( "("+filter+")" ); - - kdDebug(5300) << "LdapClient: Doing query: " << url.prettyURL() << endl; - - startParseLDIF(); - mActive = true; - mJob = KIO::get( url, false, false ); - connect( mJob, TQT_SIGNAL( data( KIO::Job*, const TQByteArray& ) ), - this, TQT_SLOT( slotData( KIO::Job*, const TQByteArray& ) ) ); - connect( mJob, TQT_SIGNAL( infoMessage( KIO::Job*, const TQString& ) ), - this, TQT_SLOT( slotInfoMessage( KIO::Job*, const TQString& ) ) ); - connect( mJob, TQT_SIGNAL( result( KIO::Job* ) ), - this, TQT_SLOT( slotDone() ) ); -} - -void LdapClient::cancelQuery() -{ - if ( mJob ) { - mJob->kill(); - mJob = 0; - } - - mActive = false; -} - -void LdapClient::slotData( KIO::Job*, const TQByteArray& data ) -{ - parseLDIF( data ); -} - -void LdapClient::slotInfoMessage( KIO::Job*, const TQString & ) -{ - //qDebug("Job said \"%s\"", info.latin1()); -} - -void LdapClient::slotDone() -{ - endParseLDIF(); - mActive = false; -#if 0 - for ( TQValueList::Iterator it = mObjects.begin(); it != mObjects.end(); ++it ) { - qDebug( (*it).toString().latin1() ); - } -#endif - int err = mJob->error(); - if ( err && err != KIO::ERR_USER_CANCELED ) { - emit error( mJob->errorString() ); - } - emit done(); -} - -void LdapClient::startParseLDIF() -{ - mCurrentObject.clear(); - mLdif.startParsing(); -} - -void LdapClient::endParseLDIF() -{ -} - -void LdapClient::finishCurrentObject() -{ - mCurrentObject.dn = mLdif.dn(); - const TQString sClass( mCurrentObject.objectClass.lower() ); - if( sClass == "groupofnames" || sClass == "kolabgroupofnames" ){ - LdapAttrMap::ConstIterator it = mCurrentObject.attrs.find("mail"); - if( it == mCurrentObject.attrs.end() ){ - // No explicit mail address found so far? - // Fine, then we use the address stored in the DN. - TQString sMail; - TQStringList lMail = TQStringList::split(",dc=", mCurrentObject.dn); - const int n = lMail.count(); - if( n ){ - if( lMail.first().lower().startsWith("cn=") ){ - sMail = lMail.first().simplifyWhiteSpace().mid(3); - if( 1 < n ) - sMail.append('@'); - for( int i=1; ireadEntry( prefix + TQString( "Host%1" ).tqarg( j ), "" ).stripWhiteSpace(); - if ( !host.isEmpty() ) - server.setHost( host ); - - int port = config->readNumEntry( prefix + TQString( "Port%1" ).tqarg( j ), 389 ); - server.setPort( port ); - - TQString base = config->readEntry( prefix + TQString( "Base%1" ).tqarg( j ), "" ).stripWhiteSpace(); - if ( !base.isEmpty() ) - server.setBaseDN( base ); - - TQString user = config->readEntry( prefix + TQString( "User%1" ).tqarg( j ) ).stripWhiteSpace(); - if ( !user.isEmpty() ) - server.setUser( user ); - - TQString bindDN = config->readEntry( prefix + TQString( "Bind%1" ).tqarg( j ) ).stripWhiteSpace(); - if ( !bindDN.isEmpty() ) - server.setBindDN( bindDN ); - - TQString pwdBindDN = config->readEntry( prefix + TQString( "PwdBind%1" ).tqarg( j ) ); - if ( !pwdBindDN.isEmpty() ) - server.setPwdBindDN( pwdBindDN ); - - server.setTimeLimit( config->readNumEntry( prefix + TQString( "TimeLimit%1" ).tqarg( j ) ) ); - server.setSizeLimit( config->readNumEntry( prefix + TQString( "SizeLimit%1" ).tqarg( j ) ) ); - server.setVersion( config->readNumEntry( prefix + TQString( "Version%1" ).tqarg( j ), 3 ) ); - server.setSecurity( config->readNumEntry( prefix + TQString( "Security%1" ).tqarg( j ) ) ); - server.setAuth( config->readNumEntry( prefix + TQString( "Auth%1" ).tqarg( j ) ) ); - server.setMech( config->readEntry( prefix + TQString( "Mech%1" ).tqarg( j ) ) ); -} - -void LdapSearch::writeConfig( const LdapServer &server, KConfig *config, int j, bool active ) -{ - TQString prefix; - if ( active ) prefix = "Selected"; - config->writeEntry( prefix + TQString( "Host%1" ).tqarg( j ), server.host() ); - config->writeEntry( prefix + TQString( "Port%1" ).tqarg( j ), server.port() ); - config->writeEntry( prefix + TQString( "Base%1" ).tqarg( j ), server.baseDN() ); - config->writeEntry( prefix + TQString( "User%1" ).tqarg( j ), server.user() ); - config->writeEntry( prefix + TQString( "Bind%1" ).tqarg( j ), server.bindDN() ); - config->writeEntry( prefix + TQString( "PwdBind%1" ).tqarg( j ), server.pwdBindDN() ); - config->writeEntry( prefix + TQString( "TimeLimit%1" ).tqarg( j ), server.timeLimit() ); - config->writeEntry( prefix + TQString( "SizeLimit%1" ).tqarg( j ), server.sizeLimit() ); - config->writeEntry( prefix + TQString( "Version%1" ).tqarg( j ), server.version() ); - config->writeEntry( prefix + TQString( "Security%1" ).tqarg( j ), server.security() ); - config->writeEntry( prefix + TQString( "Auth%1" ).tqarg( j ), server.auth() ); - config->writeEntry( prefix + TQString( "Mech%1" ).tqarg( j ), server.mech() ); -} - -KConfig* LdapSearch::config() -{ - if ( !s_config ) - configDeleter.setObject( s_config, new KConfig( "kabldaprc", false, false ) ); // Open read-write, no kdeglobals - - return s_config; -} - - -LdapSearch::LdapSearch() - : mActiveClients( 0 ), mNoLDAPLookup( false ) -{ - if ( !KProtocolInfo::isKnownProtocol( KURL("ldap://localhost") ) ) { - mNoLDAPLookup = true; - return; - } - - readConfig(); - connect(KDirWatch::self(), TQT_SIGNAL(dirty (const TQString&)),this, - TQT_SLOT(slotFileChanged(const TQString&))); -} - -void LdapSearch::readWeighForClient( LdapClient *client, KConfig *config, int clientNumber ) -{ - const int completionWeight = config->readNumEntry( TQString( "SelectedCompletionWeight%1" ).tqarg( clientNumber ), -1 ); - if ( completionWeight != -1 ) - client->setCompletionWeight( completionWeight ); -} - -void LdapSearch::updateCompletionWeights() -{ - KConfig *config = KPIM::LdapSearch::config(); - config->setGroup( "LDAP" ); - for ( uint i = 0; i < mClients.size(); i++ ) { - readWeighForClient( mClients[i], config, i ); - } -} - -void LdapSearch::readConfig() -{ - cancelSearch(); - TQValueList< LdapClient* >::Iterator it; - for ( it = mClients.begin(); it != mClients.end(); ++it ) - delete *it; - mClients.clear(); - - // stolen from KAddressBook - KConfig *config = KPIM::LdapSearch::config(); - config->setGroup( "LDAP" ); - int numHosts = config->readUnsignedNumEntry( "NumSelectedHosts"); - if ( !numHosts ) { - mNoLDAPLookup = true; - } else { - for ( int j = 0; j < numHosts; j++ ) { - LdapClient* ldapClient = new LdapClient( j, this ); - LdapServer server; - readConfig( server, config, j, true ); - if ( !server.host().isEmpty() ) mNoLDAPLookup = false; - ldapClient->setServer( server ); - - readWeighForClient( ldapClient, config, j ); - - TQStringList attrs; - // note: we need "objectClass" to detect distribution lists - attrs << "cn" << "mail" << "givenname" << "sn" << "objectClass"; - ldapClient->setAttrs( attrs ); - - connect( ldapClient, TQT_SIGNAL( result( const KPIM::LdapObject& ) ), - this, TQT_SLOT( slotLDAPResult( const KPIM::LdapObject& ) ) ); - connect( ldapClient, TQT_SIGNAL( done() ), - this, TQT_SLOT( slotLDAPDone() ) ); - connect( ldapClient, TQT_SIGNAL( error( const TQString& ) ), - this, TQT_SLOT( slotLDAPError( const TQString& ) ) ); - - mClients.append( ldapClient ); - } - - connect( &mDataTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotDataTimer() ) ); - } - mConfigFile = locateLocal( "config", "kabldaprc" ); - KDirWatch::self()->addFile( mConfigFile ); -} - -void LdapSearch::slotFileChanged( const TQString& file ) -{ - if ( file == mConfigFile ) - readConfig(); -} - -void LdapSearch::startSearch( const TQString& txt ) -{ - if ( mNoLDAPLookup ) - return; - - cancelSearch(); - - int pos = txt.find( '\"' ); - if( pos >= 0 ) - { - ++pos; - int pos2 = txt.find( '\"', pos ); - if( pos2 >= 0 ) - mSearchText = txt.mid( pos , pos2 - pos ); - else - mSearchText = txt.mid( pos ); - } else - mSearchText = txt; - - /* The reasoning behind this filter is: - * If it's a person, or a distlist, show it, even if it doesn't have an email address. - * If it's not a person, or a distlist, only show it if it has an email attribute. - * This allows both resource accounts with an email address which are not a person and - * person entries without an email address to show up, while still not showing things - * like structural entries in the ldap tree. */ - TQString filter = TQString( "&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))(|(cn=%1*)(mail=%2*)(mail=*@%3*)(givenName=%4*)(sn=%5*))" ) - .tqarg( mSearchText ).tqarg( mSearchText ).tqarg( mSearchText ).tqarg( mSearchText ).tqarg( mSearchText ); - - TQValueList< LdapClient* >::Iterator it; - for ( it = mClients.begin(); it != mClients.end(); ++it ) { - (*it)->startQuery( filter ); - kdDebug(5300) << "LdapSearch::startSearch() " << filter << endl; - ++mActiveClients; - } -} - -void LdapSearch::cancelSearch() -{ - TQValueList< LdapClient* >::Iterator it; - for ( it = mClients.begin(); it != mClients.end(); ++it ) - (*it)->cancelQuery(); - - mActiveClients = 0; - mResults.clear(); -} - -void LdapSearch::slotLDAPResult( const KPIM::LdapObject& obj ) -{ - mResults.append( obj ); - if ( !mDataTimer.isActive() ) - mDataTimer.start( 500, true ); -} - -void LdapSearch::slotLDAPError( const TQString& ) -{ - slotLDAPDone(); -} - -void LdapSearch::slotLDAPDone() -{ - if ( --mActiveClients > 0 ) - return; - - finish(); -} - -void LdapSearch::slotDataTimer() -{ - TQStringList lst; - LdapResultList reslist; - makeSearchData( lst, reslist ); - if ( !lst.isEmpty() ) - emit searchData( lst ); - if ( !reslist.isEmpty() ) - emit searchData( reslist ); -} - -void LdapSearch::finish() -{ - mDataTimer.stop(); - - slotDataTimer(); // emit final bunch of data - emit searchDone(); -} - -void LdapSearch::makeSearchData( TQStringList& ret, LdapResultList& resList ) -{ - TQString search_text_upper = mSearchText.upper(); - - TQValueList< KPIM::LdapObject >::ConstIterator it1; - for ( it1 = mResults.begin(); it1 != mResults.end(); ++it1 ) { - TQString name, mail, givenname, sn; - TQStringList mails; - bool isDistributionList = false; - bool wasCN = false; - bool wasDC = false; - - //kdDebug(5300) << "\n\nLdapSearch::makeSearchData()\n\n" << endl; - - LdapAttrMap::ConstIterator it2; - for ( it2 = (*it1).attrs.begin(); it2 != (*it1).attrs.end(); ++it2 ) { - TQByteArray val = (*it2).first(); - int len = val.size(); - if( len > 0 && '\0' == val[len-1] ) - --len; - const TQString tmp = TQString::fromUtf8( val, len ); - //kdDebug(5300) << " key: \"" << it2.key() << "\" value: \"" << tmp << "\"" << endl; - if ( it2.key() == "cn" ) { - name = tmp; - if( mail.isEmpty() ) - mail = tmp; - else{ - if( wasCN ) - mail.prepend( "." ); - else - mail.prepend( "@" ); - mail.prepend( tmp ); - } - wasCN = true; - } else if ( it2.key() == "dc" ) { - if( mail.isEmpty() ) - mail = tmp; - else{ - if( wasDC ) - mail.append( "." ); - else - mail.append( "@" ); - mail.append( tmp ); - } - wasDC = true; - } else if( it2.key() == "mail" ) { - mail = tmp; - LdapAttrValue::ConstIterator it3 = it2.data().begin(); - for ( ; it3 != it2.data().end(); ++it3 ) { - mails.append( TQString::fromUtf8( (*it3).data(), (*it3).size() ) ); - } - } else if( it2.key() == "givenName" ) - givenname = tmp; - else if( it2.key() == "sn" ) - sn = tmp; - else if( it2.key() == "objectClass" && - (tmp == "groupOfNames" || tmp == "kolabGroupOfNames") ) { - isDistributionList = true; - } - } - - if( mails.isEmpty()) { - if ( !mail.isEmpty() ) mails.append( mail ); - if( isDistributionList ) { - //kdDebug(5300) << "\n\nLdapSearch::makeSearchData() found a list: " << name << "\n\n" << endl; - ret.append( name ); - // following lines commented out for bugfixing kolab issue #177: - // - // Unlike we thought previously we may NOT append the server name here. - // - // The right server is found by the SMTP server instead: Kolab users - // must use the correct SMTP server, by definition. - // - //mail = (*it1).client->base().simplifyWhiteSpace(); - //mail.replace( ",dc=", ".", false ); - //if( mail.startsWith("dc=", false) ) - // mail.remove(0, 3); - //mail.prepend( '@' ); - //mail.prepend( name ); - //mail = name; - } else { - //kdDebug(5300) << "LdapSearch::makeSearchData() found BAD ENTRY: \"" << name << "\"" << endl; - continue; // nothing, bad entry - } - } else if ( name.isEmpty() ) { - //kdDebug(5300) << "LdapSearch::makeSearchData() mail: \"" << mail << "\"" << endl; - ret.append( mail ); - } else { - //kdDebug(5300) << "LdapSearch::makeSearchData() name: \"" << name << "\" mail: \"" << mail << "\"" << endl; - ret.append( TQString( "%1 <%2>" ).tqarg( name ).tqarg( mail ) ); - } - - LdapResult sr; - sr.clientNumber = (*it1).client->clientNumber(); - sr.completionWeight = (*it1).client->completionWeight(); - sr.name = name; - sr.email = mails; - resList.append( sr ); - } - - mResults.clear(); -} - -bool LdapSearch::isAvailable() const -{ - return !mNoLDAPLookup; -} - - -#include "ldapclient.moc" diff --git a/libkdepim/ldapclient.h b/libkdepim/ldapclient.h deleted file mode 100644 index a2a85f1e3..000000000 --- a/libkdepim/ldapclient.h +++ /dev/null @@ -1,300 +0,0 @@ -/* kldapclient.h - LDAP access - * Copyright (C) 2002 Klar�vdalens Datakonsult AB - * - * Author: Steffen Hansen - * - * This file 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 file 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 KPIM_LDAPCLIENT_H -#define KPIM_LDAPCLIENT_H - - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -namespace KPIM { - -class LdapClient; -typedef TQValueList LdapAttrValue; -typedef TQMap LdapAttrMap; - -class LdapServer -{ - public: - LdapServer() - : mPort( 389 ), - mTimeLimit(0), - mSizeLimit(0), - mVersion(2), - mSecurity(Sec_None), - mAuth( LdapServer::Anonymous ) - {} - - enum Security{ Sec_None, TLS, SSL }; - enum Auth{ Anonymous, Simple, SASL }; - TQString host() const { return mHost; } - int port() const { return mPort; } - const TQString &baseDN() const { return mBaseDN; } - const TQString &user() const { return mUser; } - const TQString &bindDN() const { return mBindDN; } - const TQString &pwdBindDN() const { return mPwdBindDN; } - int timeLimit() const { return mTimeLimit; } - int sizeLimit() const { return mSizeLimit; } - int version() const { return mVersion; } - int security() const { return mSecurity; } - int auth() const { return mAuth; } - const TQString &mech() const { return mMech; } - - void setHost( const TQString &host ) { mHost = host; } - void setPort( int port ) { mPort = port; } - void setBaseDN( const TQString &baseDN ) { mBaseDN = baseDN; } - void setUser( const TQString &user ) { mUser = user; } - void setBindDN( const TQString &bindDN ) { mBindDN = bindDN; } - void setPwdBindDN( const TQString &pwdBindDN ) { mPwdBindDN = pwdBindDN; } - void setTimeLimit( int timelimit ) { mTimeLimit = timelimit; } - void setSizeLimit( int sizelimit ) { mSizeLimit = sizelimit; } - void setVersion( int version ) { mVersion = version; } - void setSecurity( int security ) { mSecurity = security; } //0-No, 1-TLS, 2-SSL - KDE4: add an enum to Lda - void setAuth( int auth ) { mAuth = auth; } //0-Anonymous, 1-simple, 2-SASL - KDE4: add an enum to LdapCon - void setMech( const TQString &mech ) { mMech = mech; } - - private: - TQString mHost; - int mPort; - TQString mBaseDN; - TQString mUser; - TQString mBindDN; - TQString mPwdBindDN; - TQString mMech; - int mTimeLimit, mSizeLimit, mVersion, mSecurity, mAuth; -}; - - -/** - * This class is internal. Binary compatibiliy might be broken any time - * without notification. Do not use it. - * - * We mean it! - * - */ -class LdapObject -{ - public: - LdapObject() - : dn( TQString() ), client( 0 ) {} - explicit LdapObject( const TQString& _dn, LdapClient* _cl ) : dn( _dn ), client( _cl ) {} - LdapObject( const LdapObject& that ) { assign( that ); } - - LdapObject& operator=( const LdapObject& that ) - { - assign( that ); - return *this; - } - - TQString toString() const; - - void clear(); - - TQString dn; - TQString objectClass; - LdapAttrMap attrs; - LdapClient* client; - - protected: - void assign( const LdapObject& that ); - - private: - //class LdapObjectPrivate* d; -}; - -/** - * This class is internal. Binary compatibility might be broken any time - * without notification. Do not use it. - * - * We mean it! - * - */ -class KDE_EXPORT LdapClient : public TQObject -{ - Q_OBJECT - TQ_OBJECT - - public: - LdapClient( int clientNumber, TQObject* parent = 0, const char* name = 0 ); - virtual ~LdapClient(); - - /*! returns true if there is a query running */ - bool isActive() const { return mActive; } - - int clientNumber() const; - int completionWeight() const; - void setCompletionWeight( int ); - - const LdapServer& server() { return mServer; } - void setServer( const LdapServer &server ) { mServer = server; } - /*! Return the attributes that should be - * returned, or an empty list if - * all attributes are wanted - */ - TQStringList attrs() const { return mAttrs; } - - signals: - /*! Emitted when the query is done */ - void done(); - - /*! Emitted in case of error */ - void error( const TQString& ); - - /*! Emitted once for each object returned - * from the query - */ - void result( const KPIM::LdapObject& ); - - public slots: // why are those slots? - /*! Set the attributes that should be - * returned, or an empty list if - * all attributes are wanted - */ - void setAttrs( const TQStringList& attrs ); - - void setScope( const TQString scope ) { mScope = scope; } - - /*! - * Start the query with filter filter - */ - void startQuery( const TQString& filter ); - - /*! - * Abort a running query - */ - void cancelQuery(); - - protected slots: - void slotData( KIO::Job*, const TQByteArray &data ); - void slotInfoMessage( KIO::Job*, const TQString &info ); - void slotDone(); - - protected: - void startParseLDIF(); - void parseLDIF( const TQByteArray& data ); - void endParseLDIF(); - void finishCurrentObject(); - - LdapServer mServer; - TQString mScope; - TQStringList mAttrs; - - TQGuardedPtr mJob; - bool mActive; - bool mReportObjectClass; - - LdapObject mCurrentObject; - - private: - KABC::LDIF mLdif; - int mClientNumber; - int mCompletionWeight; - -// class LdapClientPrivate; -// LdapClientPrivate* d; -}; - -/** - * Structure describing one result returned by a LDAP query - */ -struct LdapResult { - TQString name; ///< full name - TQStringList email; ///< emails - int clientNumber; ///< for sorting in a ldap-only lookup - int completionWeight; ///< for sorting in a completion list -}; -typedef TQValueList LdapResultList; - - -/** - * This class is internal. Binary compatibiliy might be broken any time - * without notification. Do not use it. - * - * We mean it! - * - */ -class KDE_EXPORT LdapSearch : public TQObject -{ - Q_OBJECT - TQ_OBJECT - - public: - LdapSearch(); - - static KConfig *config(); - static void readConfig( LdapServer &server, KConfig *config, int num, bool active ); - static void writeConfig( const LdapServer &server, KConfig *config, int j, bool active ); - - void startSearch( const TQString& txt ); - void cancelSearch(); - bool isAvailable() const; - void updateCompletionWeights(); - - TQValueList< LdapClient* > clients() const { return mClients; } - - signals: - /// Results, assembled as "Full Name " - /// (This signal can be emitted many times) - void searchData( const TQStringList& ); - /// Another form for the results, with separate fields - /// (This signal can be emitted many times) - void searchData( const KPIM::LdapResultList& ); - void searchDone(); - - private slots: - void slotLDAPResult( const KPIM::LdapObject& ); - void slotLDAPError( const TQString& ); - void slotLDAPDone(); - void slotDataTimer(); - void slotFileChanged( const TQString& ); - - private: - void readWeighForClient( LdapClient *client, KConfig *config, int clientNumber ); - void readConfig(); - void finish(); - void makeSearchData( TQStringList& ret, LdapResultList& resList ); - TQValueList< LdapClient* > mClients; - TQString mSearchText; - TQTimer mDataTimer; - int mActiveClients; - bool mNoLDAPLookup; - TQValueList< LdapObject > mResults; - TQString mConfigFile; - - private: - static KConfig *s_config; - class LdapSearchPrivate* d; -}; - -} -#endif // KPIM_LDAPCLIENT_H diff --git a/libkdepim/ldapsearchdialog.cpp b/libkdepim/ldapsearchdialog.cpp deleted file mode 100644 index ed1aa2933..000000000 --- a/libkdepim/ldapsearchdialog.cpp +++ /dev/null @@ -1,480 +0,0 @@ -/* ldapsearchdialogimpl.cpp - LDAP access - * Copyright (C) 2002 Klar�vdalens Datakonsult AB - * - * Author: Steffen Hansen - * - * This file 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 file 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 "ldapsearchdialog.h" -#include "ldapclient.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace KPIM; - -static TQString asUtf8( const TQByteArray &val ) -{ - if ( val.isEmpty() ) - return TQString(); - - const char *data = val.data(); - - //TQString::fromUtf8() bug workaround - if ( data[ val.size() - 1 ] == '\0' ) - return TQString::fromUtf8( data, val.size() - 1 ); - else - return TQString::fromUtf8( data, val.size() ); -} - -static TQString join( const KPIM::LdapAttrValue& lst, const TQString& sep ) -{ - TQString res; - bool alredy = false; - for ( KPIM::LdapAttrValue::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { - if ( alredy ) - res += sep; - alredy = TRUE; - res += asUtf8( *it ); - } - return res; -} - -static TQMap& adrbookattr2ldap() -{ - static TQMap keys; - - if ( keys.isEmpty() ) { - keys[ i18n( "Title" ) ] = "title"; - keys[ i18n( "Full Name" ) ] = "cn"; - keys[ i18n( "Email" ) ] = "mail"; - keys[ i18n( "Home Number" ) ] = "homePhone"; - keys[ i18n( "Work Number" ) ] = "telephoneNumber"; - keys[ i18n( "Mobile Number" ) ] = "mobile"; - keys[ i18n( "Fax Number" ) ] = "facsimileTelephoneNumber"; - keys[ i18n( "Pager" ) ] = "pager"; - keys[ i18n( "Street") ] = "street"; - keys[ i18n( "State" ) ] = "st"; - keys[ i18n( "Country" ) ] = "co"; - keys[ i18n( "City" ) ] = "l"; - keys[ i18n( "Organization" ) ] = "o"; - keys[ i18n( "Company" ) ] = "Company"; - keys[ i18n( "Department" ) ] = "department"; - keys[ i18n( "Zip Code" ) ] = "postalCode"; - keys[ i18n( "Postal Address" ) ] = "postalAddress"; - keys[ i18n( "Description" ) ] = "description"; - keys[ i18n( "User ID" ) ] = "uid"; - } - return keys; -} - -namespace KPIM { - -class ContactListItem : public TQListViewItem -{ - public: - ContactListItem( TQListView* parent, const KPIM::LdapAttrMap& attrs ) - : TQListViewItem( parent ), mAttrs( attrs ) - { - const KPIM::LdapAttrValue &mailAttrs = attrs[ "mail" ]; - if ( mailAttrs.isEmpty() ) { - setSelectable( false ); - setEnabled( false ); - } - } - - KPIM::LdapAttrMap mAttrs; - - virtual TQString text( int col ) const - { - // Look up a suitable attribute for column col - const TQString colName = listView()->columnText( col ); - const TQString ldapAttrName = adrbookattr2ldap()[ colName ]; - return join( mAttrs[ ldapAttrName ], ", " ); - } -}; - -} - -LDAPSearchDialog::LDAPSearchDialog( TQWidget* parent, const char* name ) - : KDialogBase( Plain, i18n( "Search for Addresses in Directory" ), Help | User1 | - User2 | User3 | Cancel, Default, parent, name, false, true ) -{ - setButtonCancel( KStdGuiItem::close() ); - TQFrame *page = plainPage(); - TQVBoxLayout *topLayout = new TQVBoxLayout( page, marginHint(), spacingHint() ); - - TQGroupBox *groupBox = new TQGroupBox( i18n( "Search for Addresses in Directory" ), - page ); - groupBox->setFrameShape( TQGroupBox::Box ); - groupBox->setFrameShadow( TQGroupBox::Sunken ); - groupBox->setColumnLayout( 0, Qt::Vertical ); - TQGridLayout *boxLayout = new TQGridLayout( groupBox->tqlayout(), 2, - 5, spacingHint() ); - boxLayout->setColStretch( 1, 1 ); - - TQLabel *label = new TQLabel( i18n( "Search for:" ), groupBox ); - boxLayout->addWidget( label, 0, 0 ); - - mSearchEdit = new KLineEdit( groupBox ); - boxLayout->addWidget( mSearchEdit, 0, 1 ); - label->setBuddy( mSearchEdit ); - - label = new TQLabel( i18n( "in" ), groupBox ); - boxLayout->addWidget( label, 0, 2 ); - - mFilterCombo = new KComboBox( groupBox ); - mFilterCombo->insertItem( i18n( "Name" ) ); - mFilterCombo->insertItem( i18n( "Email" ) ); - mFilterCombo->insertItem( i18n( "Home Number" ) ); - mFilterCombo->insertItem( i18n( "Work Number" ) ); - boxLayout->addWidget( mFilterCombo, 0, 3 ); - - TQSize buttonSize; - mSearchButton = new TQPushButton( i18n( "Stop" ), groupBox ); - buttonSize = mSearchButton->tqsizeHint(); - mSearchButton->setText( i18n( "Search" ) ); - if ( buttonSize.width() < mSearchButton->tqsizeHint().width() ) - buttonSize = mSearchButton->tqsizeHint(); - mSearchButton->setFixedWidth( buttonSize.width() ); - - mSearchButton->setDefault( true ); - boxLayout->addWidget( mSearchButton, 0, 4 ); - - mRecursiveCheckbox = new TQCheckBox( i18n( "Recursive search" ), groupBox ); - mRecursiveCheckbox->setChecked( true ); - boxLayout->addMultiCellWidget( mRecursiveCheckbox, 1, 1, 0, 4 ); - - mSearchType = new KComboBox( groupBox ); - mSearchType->insertItem( i18n( "Contains" ) ); - mSearchType->insertItem( i18n( "Starts With" ) ); - boxLayout->addMultiCellWidget( mSearchType, 1, 1, 3, 4 ); - - topLayout->addWidget( groupBox ); - - mResultListView = new TQListView( page ); - mResultListView->setSelectionMode( TQListView::Multi ); - mResultListView->setAllColumnsShowFocus( true ); - mResultListView->setShowSortIndicator( true ); - topLayout->addWidget( mResultListView ); - - resize( TQSize( 600, 400).expandedTo( tqminimumSizeHint() ) ); - - setButtonText( User1, i18n( "Unselect All" ) ); - setButtonText( User2, i18n( "Select All" ) ); - setButtonText( User3, i18n( "Add Selected" ) ); - - mNumHosts = 0; - mIsOK = false; - - connect( mRecursiveCheckbox, TQT_SIGNAL( toggled( bool ) ), - this, TQT_SLOT( slotSetScope( bool ) ) ); - connect( mSearchButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( slotStartSearch() ) ); - - setTabOrder(mSearchEdit, mFilterCombo); - setTabOrder(mFilterCombo, mSearchButton); - mSearchEdit->setFocus(); - - restoreSettings(); -} - -LDAPSearchDialog::~LDAPSearchDialog() -{ - saveSettings(); -} - -void LDAPSearchDialog::restoreSettings() -{ - // Create one KPIM::LdapClient per selected server and configure it. - - // First clean the list to make sure it is empty at - // the beginning of the process - mLdapClientList.setAutoDelete( true ); - mLdapClientList.clear(); - - KConfig kabConfig( "kaddressbookrc" ); - kabConfig.setGroup( "LDAPSearch" ); - mSearchType->setCurrentItem( kabConfig.readNumEntry( "SearchType", 0 ) ); - - // then read the config file and register all selected - // server in the list - KConfig* config = KABC::AddressLineEdit::config(); // singleton kabldaprc config object - KConfigGroupSaver saver( config, "LDAP" ); - mNumHosts = config->readUnsignedNumEntry( "NumSelectedHosts" ); - if ( !mNumHosts ) { - KMessageBox::error( this, i18n( "You must select a LDAP server before searching.\nYou can do this from the menu Settings/Configure KAddressBook." ) ); - mIsOK = false; - } else { - mIsOK = true; - for ( int j = 0; j < mNumHosts; ++j ) { - KPIM::LdapServer ldapServer; - - TQString host = config->readEntry( TQString( "SelectedHost%1" ).tqarg( j ), "" ); - if ( !host.isEmpty() ) - ldapServer.setHost( host ); - - int port = config->readUnsignedNumEntry( TQString( "SelectedPort%1" ).tqarg( j ) ); - if ( port ) - ldapServer.setPort( port ); - - TQString base = config->readEntry( TQString( "SelectedBase%1" ).tqarg( j ), "" ); - if ( !base.isEmpty() ) - ldapServer.setBaseDN( base ); - - TQString bindDN = config->readEntry( TQString( "SelectedBind%1" ).tqarg( j ), "" ); - if ( !bindDN.isEmpty() ) - ldapServer.setBindDN( bindDN ); - - TQString pwdBindDN = config->readEntry( TQString( "SelectedPwdBind%1" ).tqarg( j ), "" ); - if ( !pwdBindDN.isEmpty() ) - ldapServer.setPwdBindDN( pwdBindDN ); - - KPIM::LdapClient* ldapClient = new KPIM::LdapClient( 0, TQT_TQOBJECT(this), "ldapclient" ); - ldapClient->setServer( ldapServer ); - - TQStringList attrs; - - for ( TQMap::Iterator it = adrbookattr2ldap().begin(); it != adrbookattr2ldap().end(); ++it ) - attrs << *it; - - ldapClient->setAttrs( attrs ); - - connect( ldapClient, TQT_SIGNAL( result( const KPIM::LdapObject& ) ), - this, TQT_SLOT( slotAddResult( const KPIM::LdapObject& ) ) ); - connect( ldapClient, TQT_SIGNAL( done() ), - this, TQT_SLOT( slotSearchDone() ) ); - connect( ldapClient, TQT_SIGNAL( error( const TQString& ) ), - this, TQT_SLOT( slotError( const TQString& ) ) ); - - mLdapClientList.append( ldapClient ); - } - -/** CHECKIT*/ - while ( mResultListView->header()->count() > 0 ) { - mResultListView->removeColumn(0); - } - - mResultListView->addColumn( i18n( "Full Name" ) ); - mResultListView->addColumn( i18n( "Email" ) ); - mResultListView->addColumn( i18n( "Home Number" ) ); - mResultListView->addColumn( i18n( "Work Number" ) ); - mResultListView->addColumn( i18n( "Mobile Number" ) ); - mResultListView->addColumn( i18n( "Fax Number" ) ); - mResultListView->addColumn( i18n( "Company" ) ); - mResultListView->addColumn( i18n( "Organization" ) ); - mResultListView->addColumn( i18n( "Street" ) ); - mResultListView->addColumn( i18n( "State" ) ); - mResultListView->addColumn( i18n( "Country" ) ); - mResultListView->addColumn( i18n( "Zip Code" ) ); - mResultListView->addColumn( i18n( "Postal Address" ) ); - mResultListView->addColumn( i18n( "City" ) ); - mResultListView->addColumn( i18n( "Department" ) ); - mResultListView->addColumn( i18n( "Description" ) ); - mResultListView->addColumn( i18n( "User ID" ) ); - mResultListView->addColumn( i18n( "Title" ) ); - - mResultListView->clear(); - } -} - -void LDAPSearchDialog::saveSettings() -{ - KConfig config( "kaddressbookrc" ); - config.setGroup( "LDAPSearch" ); - config.writeEntry( "SearchType", mSearchType->currentItem() ); - config.sync(); -} - -void LDAPSearchDialog::cancelQuery() -{ - for ( KPIM::LdapClient* client = mLdapClientList.first(); client; client = mLdapClientList.next() ) { - client->cancelQuery(); - } -} - -void LDAPSearchDialog::slotAddResult( const KPIM::LdapObject& obj ) -{ - new ContactListItem( mResultListView, obj.attrs ); -} - -void LDAPSearchDialog::slotSetScope( bool rec ) -{ - for ( KPIM::LdapClient* client = mLdapClientList.first(); client; client = mLdapClientList.next() ) { - if ( rec ) - client->setScope( "sub" ); - else - client->setScope( "one" ); - } -} - -TQString LDAPSearchDialog::makeFilter( const TQString& query, const TQString& attr, - bool startsWith ) -{ - /* The reasoning behind this filter is: - * If it's a person, or a distlist, show it, even if it doesn't have an email address. - * If it's not a person, or a distlist, only show it if it has an email attribute. - * This allows both resource accounts with an email address which are not a person and - * person entries without an email address to show up, while still not showing things - * like structural entries in the ldap tree. */ - TQString result( "&(|(objectclass=person)(objectclass=groupofnames)(mail=*))(" ); - if( query.isEmpty() ) - // Return a filter that matches everything - return result + "|(cn=*)(sn=*)" + ")"; - - if ( attr == i18n( "Name" ) ) { - result += startsWith ? "|(cn=%1*)(sn=%2*)" : "|(cn=*%1*)(sn=*%2*)"; - result = result.tqarg( query ).tqarg( query ); - } else { - result += (startsWith ? "%1=%2*" : "%1=*%2*"); - if ( attr == i18n( "Email" ) ) { - result = result.tqarg( "mail" ).tqarg( query ); - } else if ( attr == i18n( "Home Number" ) ) { - result = result.tqarg( "homePhone" ).tqarg( query ); - } else if ( attr == i18n( "Work Number" ) ) { - result = result.tqarg( "telephoneNumber" ).tqarg( query ); - } else { - // Error? - result = TQString(); - return result; - } - } - result += ")"; - return result; -} - -void LDAPSearchDialog::slotStartSearch() -{ - cancelQuery(); - - TQApplication::setOverrideCursor( TQt::waitCursor ); - mSearchButton->setText( i18n( "Stop" ) ); - - disconnect( mSearchButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( slotStartSearch() ) ); - connect( mSearchButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( slotStopSearch() ) ); - - bool startsWith = (mSearchType->currentItem() == 1); - - TQString filter = makeFilter( mSearchEdit->text().stripWhiteSpace(), mFilterCombo->currentText(), startsWith ); - - // loop in the list and run the KPIM::LdapClients - mResultListView->clear(); - for( KPIM::LdapClient* client = mLdapClientList.first(); client; client = mLdapClientList.next() ) { - client->startQuery( filter ); - } - - saveSettings(); -} - -void LDAPSearchDialog::slotStopSearch() -{ - cancelQuery(); - slotSearchDone(); -} - -void LDAPSearchDialog::slotSearchDone() -{ - // If there are no more active clients, we are done. - for ( KPIM::LdapClient* client = mLdapClientList.first(); client; client = mLdapClientList.next() ) { - if ( client->isActive() ) - return; - } - - disconnect( mSearchButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( slotStopSearch() ) ); - connect( mSearchButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( slotStartSearch() ) ); - - mSearchButton->setText( i18n( "Search" ) ); - TQApplication::restoreOverrideCursor(); -} - -void LDAPSearchDialog::slotError( const TQString& error ) -{ - TQApplication::restoreOverrideCursor(); - KMessageBox::error( this, error ); -} - -void LDAPSearchDialog::closeEvent( TQCloseEvent* e ) -{ - slotStopSearch(); - e->accept(); -} - -/*! - * Returns a ", " separated list of email addresses that were - * checked by the user - */ -TQString LDAPSearchDialog::selectedEMails() const -{ - TQStringList result; - ContactListItem* cli = static_cast( mResultListView->firstChild() ); - while ( cli ) { - if ( cli->isSelected() ) { - TQString email = asUtf8( cli->mAttrs[ "mail" ].first() ).stripWhiteSpace(); - if ( !email.isEmpty() ) { - TQString name = asUtf8( cli->mAttrs[ "cn" ].first() ).stripWhiteSpace(); - if ( name.isEmpty() ) { - result << email; - } else { - result << KPIM::quoteNameIfNecessary( name ) + " <" + email + ">"; - } - } - } - cli = static_cast( cli->nextSibling() ); - } - - return result.join( ", " ); -} - -void LDAPSearchDialog::slotHelp() -{ - kapp->invokeHelp( "ldap-queries" ); -} - -void LDAPSearchDialog::slotUser1() -{ - mResultListView->selectAll( false ); -} - -void LDAPSearchDialog::slotUser2() -{ - mResultListView->selectAll( true ); -} - -void LDAPSearchDialog::slotUser3() -{ - emit addresseesAdded(); -} - -#include "ldapsearchdialog.moc" diff --git a/libkdepim/ldapsearchdialog.h b/libkdepim/ldapsearchdialog.h deleted file mode 100644 index 45e174efe..000000000 --- a/libkdepim/ldapsearchdialog.h +++ /dev/null @@ -1,93 +0,0 @@ -/* ldapsearchdialogimpl.h - LDAP access - * Copyright (C) 2002 Klar�vdalens Datakonsult AB - * - * Author: Steffen Hansen - * - * This file 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 file 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 LDAPSEARCHDIALOG_H -#define LDAPSEARCHDIALOG_H - -#include - -#include -#include -#include - -class KComboBox; - -class TQCheckBox; -class TQListView; -class TQPushButton; - -namespace KPIM { - -class LDAPSearchDialog : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT - - public: - LDAPSearchDialog( TQWidget* parent, const char* name = 0 ); - ~LDAPSearchDialog(); - - bool isOK() const { return mIsOK; } - - void restoreSettings(); - - void setSearchText( const TQString &text ) { mSearchEdit->setText( text ); } - TQString selectedEMails() const; - signals: - void addresseesAdded(); - - protected slots: - void slotAddResult( const KPIM::LdapObject& obj ); - void slotSetScope( bool rec ); - void slotStartSearch(); - void slotStopSearch(); - void slotSearchDone(); - void slotError( const TQString& ); - virtual void slotHelp(); - virtual void slotUser1(); - virtual void slotUser2(); - virtual void slotUser3(); - - protected: - - virtual void closeEvent( TQCloseEvent* ); - - private: - void saveSettings(); - - TQString makeFilter( const TQString& query, const TQString& attr, bool startsWith ); - - void cancelQuery(); - - int mNumHosts; - TQPtrList mLdapClientList; - bool mIsOK; - KComboBox* mFilterCombo; - KComboBox* mSearchType; - KLineEdit* mSearchEdit; - - TQCheckBox* mRecursiveCheckbox; - TQListView* mResultListView; - TQPushButton* mSearchButton; -}; - - -} -#endif diff --git a/libkdepim/linklocator.cpp b/libkdepim/linklocator.cpp deleted file mode 100644 index 399c5d3b3..000000000 --- a/libkdepim/linklocator.cpp +++ /dev/null @@ -1,466 +0,0 @@ -/** - * linklocator.cpp - * - * Copyright (c) 2002 Dave Corrie - * - * This file is part of KMail. - * - * KMail 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 "linklocator.h" -#include "pimemoticons.h" -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -TQMap *LinkLocator::s_smileyEmoticonNameMap = 0; -TQMap *LinkLocator::s_smileyEmoticonHTMLCache = 0; - -static KStaticDeleter< TQMap > smileyMapDeleter; -static KStaticDeleter< TQMap > smileyCacheDeleter; - -LinkLocator::LinkLocator(const TQString& text, int pos) - : mText(text), mPos(pos), mMaxUrlLen(4096), mMaxAddressLen(255) -{ - // If you change either of the above values for maxUrlLen or - // maxAddressLen, then please also update the documentation for - // setMaxUrlLen()/setMaxAddressLen() in the header file AND the - // default values used for the maxUrlLen/maxAddressLen parameters - // of convertToHtml(). - - if ( !s_smileyEmoticonNameMap ) { - smileyMapDeleter.setObject( s_smileyEmoticonNameMap, - new TQMap() ); - for ( int i = 0; i < EmotIcons::EnumSindex::COUNT; ++i ) { - TQString imageName( EmotIcons::EnumSindex::enumToString[i] ); - imageName.truncate( imageName.length() - 2 ); //remove the _0 bit - s_smileyEmoticonNameMap->insert( EmotIcons::smiley(i), imageName ); - } - } - - if ( !s_smileyEmoticonHTMLCache ) - smileyCacheDeleter.setObject( s_smileyEmoticonHTMLCache, - new TQMap() ); -} - -void LinkLocator::setMaxUrlLen(int length) -{ - mMaxUrlLen = length; -} - -int LinkLocator::maxUrlLen() const -{ - return mMaxUrlLen; -} - -void LinkLocator::setMaxAddressLen(int length) -{ - mMaxAddressLen = length; -} - -int LinkLocator::maxAddressLen() const -{ - return mMaxAddressLen; -} - -TQString LinkLocator::getUrl() -{ - TQString url; - if(atUrl()) - { - // handle cases like this: http://foobar.org/ - int start = mPos; - while(mPos < (int)mText.length() && mText[mPos] > ' ' && mText[mPos] != '"' && - TQString("<>()[]").find(mText[mPos]) == -1) - { - ++mPos; - } - /* some URLs really end with: # / & - _ */ - const TQString allowedSpecialChars = TQString("#/&-_"); - while(mPos > start && mText[mPos-1].isPunct() && - allowedSpecialChars.find(mText[mPos-1]) == -1 ) - { - --mPos; - } - - url = mText.mid(start, mPos - start); - if(isEmptyUrl(url) || mPos - start > maxUrlLen()) - { - mPos = start; - url = ""; - } - else - { - --mPos; - } - } - return url; -} - -// keep this in sync with KMMainWin::slotUrlClicked() -bool LinkLocator::atUrl() const -{ - // the following characters are allowed in a dot-atom (RFC 2822): - // a-z A-Z 0-9 . ! # $ % & ' * + - / = ? ^ _ ` { | } ~ - const TQString allowedSpecialChars = TQString(".!#$%&'*+-/=?^_`{|}~"); - - // the character directly before the URL must not be a letter, a number or - // any other character allowed in a dot-atom (RFC 2822). - if( ( mPos > 0 ) && ( mText[mPos-1].isLetterOrNumber() || - ( allowedSpecialChars.find( mText[mPos-1] ) != -1 ) ) ) - return false; - - TQChar ch = mText[mPos]; - return (ch=='h' && ( mText.mid(mPos, 7) == "http://" || - mText.mid(mPos, 8) == "https://") ) || - (ch=='v' && mText.mid(mPos, 6) == "vnc://") || - (ch=='f' && ( mText.mid(mPos, 7) == "fish://" || - mText.mid(mPos, 6) == "ftp://" || - mText.mid(mPos, 7) == "ftps://") ) || - (ch=='s' && ( mText.mid(mPos, 7) == "sftp://" || - mText.mid(mPos, 6) == "smb://") ) || - (ch=='m' && mText.mid(mPos, 7) == "mailto:") || - (ch=='w' && mText.mid(mPos, 4) == "www.") || - (ch=='f' && mText.mid(mPos, 4) == "ftp.") || - (ch=='n' && mText.mid(mPos, 5) == "news:"); - // note: no "file:" for security reasons -} - -bool LinkLocator::isEmptyUrl(const TQString& url) -{ - return url.isEmpty() || - url == "http://" || - url == "https://" || - url == "fish://" || - url == "ftp://" || - url == "ftps://" || - url == "sftp://" || - url == "smb://" || - url == "vnc://" || - url == "mailto" || - url == "www" || - url == "ftp" || - url == "news" || - url == "news://"; -} - -TQString LinkLocator::getEmailAddress() -{ - TQString address; - - if ( mText[mPos] == '@' ) { - // the following characters are allowed in a dot-atom (RFC 2822): - // a-z A-Z 0-9 . ! # $ % & ' * + - / = ? ^ _ ` { | } ~ - const TQString allowedSpecialChars = TQString(".!#$%&'*+-/=?^_`{|}~"); - - // determine the local part of the email address - int start = mPos - 1; - while ( start >= 0 && mText[start].tqunicode() < 128 && - ( mText[start].isLetterOrNumber() || - mText[start] == '@' || // allow @ to find invalid email addresses - allowedSpecialChars.find( mText[start] ) != -1 ) ) { - if ( mText[start] == '@' ) - return TQString(); // local part contains '@' -> no email address - --start; - } - ++start; - // we assume that an email address starts with a letter or a digit - while ( ( start < mPos ) && !mText[start].isLetterOrNumber() ) - ++start; - if ( start == mPos ) - return TQString(); // local part is empty -> no email address - - // determine the domain part of the email address - int dotPos = INT_MAX; - int end = mPos + 1; - while ( end < (int)mText.length() && - ( mText[end].isLetterOrNumber() || - mText[end] == '@' || // allow @ to find invalid email addresses - mText[end] == '.' || - mText[end] == '-' ) ) { - if ( mText[end] == '@' ) - return TQString(); // domain part contains '@' -> no email address - if ( mText[end] == '.' ) - dotPos = TQMIN( dotPos, end ); // remember index of first dot in domain - ++end; - } - // we assume that an email address ends with a letter or a digit - while ( ( end > mPos ) && !mText[end - 1].isLetterOrNumber() ) - --end; - if ( end == mPos ) - return TQString(); // domain part is empty -> no email address - if ( dotPos >= end ) - return TQString(); // domain part doesn't contain a dot - - if ( end - start > maxAddressLen() ) - return TQString(); // too long -> most likely no email address - address = mText.mid( start, end - start ); - - mPos = end - 1; - } - return address; -} - -TQString LinkLocator::convertToHtml(const TQString& plainText, int flags, - int maxUrlLen, int maxAddressLen) -{ - LinkLocator locator(plainText); - locator.setMaxUrlLen(maxUrlLen); - locator.setMaxAddressLen(maxAddressLen); - - TQString str; - TQString result((TQChar*)0, (int)locator.mText.length() * 2); - TQChar ch; - int x; - bool startOfLine = true; - TQString emoticon; - - for (locator.mPos = 0, x = 0; locator.mPos < (int)locator.mText.length(); locator.mPos++, x++) - { - ch = locator.mText[locator.mPos]; - if ( flags & PreserveSpaces ) - { - if (ch==' ') - { - if (startOfLine) { - result += " "; - locator.mPos++, x++; - startOfLine = false; - } - while (locator.mText[locator.mPos] == ' ') - { - result += " "; - locator.mPos++, x++; - if (locator.mText[locator.mPos] == ' ') { - result += " "; - locator.mPos++, x++; - } - } - locator.mPos--, x--; - continue; - } - else if (ch=='\t') - { - do - { - result += " "; - x++; - } - while((x&7) != 0); - x--; - startOfLine = false; - continue; - } - } - if (ch=='\n') - { - result += "
"; - startOfLine = true; - x = -1; - continue; - } - - startOfLine = false; - if (ch=='&') - result += "&"; - else if (ch=='"') - result += """; - else if (ch=='<') - result += "<"; - else if (ch=='>') - result += ">"; - else - { - const int start = locator.mPos; - if ( !(flags & IgnoreUrls) ) { - str = locator.getUrl(); - if (!str.isEmpty()) - { - TQString hyperlink; - if(str.left(4) == "www.") - hyperlink = "http://" + str; - else if(str.left(4) == "ftp.") - hyperlink = "ftp://" + str; - else - hyperlink = str; - - str = str.replace('&', "&"); - result += "" + str + ""; - x += locator.mPos - start; - continue; - } - str = locator.getEmailAddress(); - if(!str.isEmpty()) - { - // len is the length of the local part - int len = str.find('@'); - TQString localPart = str.left(len); - - // remove the local part from the result (as '&'s have been expanded to - // & we have to take care of the 4 additional characters per '&') - result.truncate(result.length() - len - (localPart.contains('&')*4)); - x -= len; - - result += "" + str + ""; - x += str.length() - 1; - continue; - } - } - if ( flags & ReplaceSmileys ) { - str = locator.getEmoticon(); - if ( ! str.isEmpty() ) { - result += str; - x += locator.mPos - start; - continue; - } - } - if ( flags & HighlightText ) { - str = locator.highlightedText(); - if ( !str.isEmpty() ) { - result += str; - x += locator.mPos - start; - continue; - } - } - result += ch; - } - } - - return result; -} - -TQString LinkLocator::pngToDataUrl( const TQString & iconPath ) -{ - if ( iconPath.isEmpty() ) - return TQString(); - - TQFile pngFile( iconPath ); - if ( !pngFile.open( IO_ReadOnly | IO_Raw ) ) - return TQString(); - - TQByteArray ba = pngFile.readAll(); - pngFile.close(); - return TQString::tqfromLatin1("data:image/png;base64,%1") - .tqarg( KCodecs::base64Encode( ba ).data() ); -} - - -TQString LinkLocator::getEmoticon() -{ - // smileys have to be prepended by whitespace - if ( ( mPos > 0 ) && !mText[mPos-1].isSpace() ) - return TQString(); - - // since smileys start with ':', ';', '(' or '8' short circuit method - const TQChar ch = mText[mPos]; - if ( ch !=':' && ch != ';' && ch != '(' && ch != '8' ) - return TQString(); - - // find the end of the smiley (a smiley is at most 4 chars long and ends at - // lineend or whitespace) - const int MinSmileyLen = 2; - const int MaxSmileyLen = 4; - int smileyLen = 1; - while ( ( smileyLen <= MaxSmileyLen ) && - ( mPos+smileyLen < (int)mText.length() ) && - !mText[mPos+smileyLen].isSpace() ) - smileyLen++; - if ( smileyLen < MinSmileyLen || smileyLen > MaxSmileyLen ) - return TQString(); - - const TQString smiley = mText.mid( mPos, smileyLen ); - if ( !s_smileyEmoticonNameMap->contains( smiley ) ) - return TQString(); // that's not a (known) smiley - - TQString htmlRep; - if ( s_smileyEmoticonHTMLCache->contains( smiley ) ) { - htmlRep = (*s_smileyEmoticonHTMLCache)[smiley]; - } - else { - const TQString imageName = (*s_smileyEmoticonNameMap)[smiley]; - -#if KDE_IS_VERSION( 3, 3, 91 ) - const TQString iconPath = locate( "emoticons", - EmotIcons::theme() + - TQString::tqfromLatin1( "/" ) + - imageName + TQString::tqfromLatin1(".png") ); -#else - const TQString iconPath = locate( "data", - TQString::tqfromLatin1( "kopete/pics/emoticons/" )+ - EmotIcons::theme() + - TQString::tqfromLatin1( "/" ) + - imageName + TQString::tqfromLatin1(".png") ); -#endif - - const TQString dataUrl = pngToDataUrl( iconPath ); - if ( dataUrl.isEmpty() ) { - htmlRep = TQString(); - } - else { - // create an image tag (the text in attribute alt is used - // for copy & paste) representing the smiley - htmlRep = TQString("") - .tqarg( dataUrl, - TQStyleSheet::escape( smiley ), - TQStyleSheet::escape( smiley ) ); - } - s_smileyEmoticonHTMLCache->insert( smiley, htmlRep ); - } - - if ( !htmlRep.isEmpty() ) - mPos += smileyLen - 1; - - return htmlRep; -} - -TQString LinkLocator::highlightedText() -{ - // formating symbols must be prepended with a whitespace - if ( ( mPos > 0 ) && !mText[mPos-1].isSpace() ) - return TQString(); - - const TQChar ch = mText[mPos]; - if ( ch != '/' && ch != '*' && ch != '_' ) - return TQString(); - - TQRegExp re = TQRegExp( TQString("\\%1([0-9A-Za-z]+)\\%2").tqarg( ch ).tqarg( ch ) ); - if ( re.search( mText, mPos ) == mPos ) { - uint length = re.matchedLength(); - // there must be a whitespace after the closing formating symbol - if ( mPos + length < mText.length() && !mText[mPos + length].isSpace() ) - return TQString(); - mPos += length - 1; - switch ( ch.latin1() ) { - case '*': - return "" + re.cap( 1 ) + ""; - case '_': - return "" + re.cap( 1 ) + ""; - case '/': - return "" + re.cap( 1 ) + ""; - } - } - return TQString(); -} - diff --git a/libkdepim/linklocator.h b/libkdepim/linklocator.h deleted file mode 100644 index 4597d836b..000000000 --- a/libkdepim/linklocator.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * linklocator.h - * - * Copyright (c) 2002 Dave Corrie - * - * This file is part of KMail. - * - * KMail 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 LINKLOCATOR_H_INCLUDED -#define LINKLOCATOR_H_INCLUDED - -#include -#include - -#include - -/** - * LinkLocator assists in identifying sections of text that can - * usefully be converted in hyperlinks in html. It is intended - * to be used in two ways: either by calling @ref convertToHtml() - * to convert a plaintext string into html, or to be derived from - * where more control is needed. - * - * @short Identifies URLs and email addresses embedded in plaintext. - * @author Dave Corrie - */ -class KDE_EXPORT LinkLocator -{ -public: - /** - * Constructs a LinkLocator that will search a plaintext string - * from a given starting point. - * - * @param text The string in which to search. - * @param pos An index into 'text' from where the search - * should begin. - */ - LinkLocator(const TQString& text, int pos = 0); - - /** - * Sets the maximum length of URLs that will be matched by - * @ref getUrl(). By default, this is set to 4096 - * characters. The reason for this limit is that there may - * be possible security implications in handling URLs of - * unlimited length. - * - * @param length The new maximum length of URLs that will be - * matched by @ref getUrl(). - */ - void setMaxUrlLen(int length); - - /** - * @return The current limit on the maximum length of a URL. - * - * @see setMaxUrlLen(). - */ - int maxUrlLen() const; - - /** - * Sets the maximum length of email addresses that will be - * matched by @ref getEmailAddress(). By default, this is - * set to 255 characters. The reason for this limit is that - * there may be possible security implications in handling - * addresses of unlimited length. - * - * @param length The new maximum length of email addresses - * that will be matched by @ref getEmailAddress(). - */ - void setMaxAddressLen(int length); - - /** - * @return The current limit on the maximum length of an email - * address. - * - * @see setMaxAddressLen(). - */ - int maxAddressLen() const; - - /** - * Attempts to grab a URL starting at the current scan position. - * If there is no URL at the current scan position, then an empty - * string is returned. If a URL is found, the current scan position - * is set to the index of the last character in the URL. - * - * @return The URL at the current scan position, or an empty string. - */ - TQString getUrl(); - - /** - * Attempts to grab an email address. If there is an @ symbol at the - * current scan position, then the text will be searched both backwards - * and forwards to find the email address. If there is no @ symbol at - * the current scan position, an empty string is returned. If an address - * is found, then the current scan position is set to the index of the - * last character in the address. - * - * @return The email address at the current scan position, or an empty - * string. - */ - TQString getEmailAddress(); - - /** - * Converts plaintext into html. The following characters are converted to HTML - * entities: & " < >. Newlines are also preserved. - * - * @param plainText The text to be converted into HTML. - * @param flags The flags to consider when processing plainText. - * Currently supported flags are: - * - PreserveSpaces, preserves the appearance of - * sequences of space and tab - * characters in the resulting HTML. - * - ReplaceSmileys, replace text smileys with - * emoticon images. - * - IgnoreUrls, doesn't parse any URLs. - * - HighlightText, interprets text highlighting markup - * like *bold*, _underlined_ and - * /italic/. - * @param maxUrlLen The maximum length of permitted URLs. (See - * @ref maxUrlLen().) - * @param maxAddressLen The maximum length of permitted email addresses. - * (See @ref maxAddressLen().) - * @return An HTML version of the text supplied in the 'plainText' parameter, - * suitable for inclusion in the BODY of an HTML document. - */ - static TQString convertToHtml(const TQString& plainText, int flags = 0, - int maxUrlLen = 4096, int maxAddressLen = 255); - - static const int PreserveSpaces = 0x01; - static const int ReplaceSmileys = 0x02; - static const int IgnoreUrls = 0x04; - static const int HighlightText = 0x08; - - /** Embed the given PNG image into a data URL. - * @param iconPath path to the PNG image - * @return A data URL, TQString() if the image could not be read. - */ - static TQString pngToDataUrl( const TQString & iconPath ); - -protected: - /** - * The plaintext string being scanned for URLs and email addresses. - */ - TQString mText; - /** - * The current scan position. - */ - int mPos; - -private: - bool atUrl() const; - bool isEmptyUrl(const TQString& url); - - /** - * Replaces smiley text with an tag containing the relevant image. - * For an emoticon text to be recognised it has to match - * "(^|\s+)text(\s+|$)" - * @return An HTML String with for an emoticon - */ - TQString getEmoticon(); - /** - * Highlight text according to *bold*, /italic/ and _underlined_ markup. - * @return A HTML string. - */ - TQString highlightedText(); - - int mMaxUrlLen; - int mMaxAddressLen; - - // maps the smiley text to the corresponding emoticon name - static TQMap *s_smileyEmoticonNameMap; - // cache for the HTML representation of a smiley - static TQMap *s_smileyEmoticonHTMLCache; -}; - -#endif // LINKLOCATOR_H_INCLUDED - diff --git a/libkdepim/maillistdrag.cpp b/libkdepim/maillistdrag.cpp deleted file mode 100644 index a9e2e9fa0..000000000 --- a/libkdepim/maillistdrag.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Don Sanders - Copyright (c) 2005 George Staikos - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "maillistdrag.h" -#include -#include -#include -#include -#include -#include - -using namespace KPIM; - -MailSummary::MailSummary( TQ_UINT32 serialNumber, TQString messageId, - TQString subject, TQString from, TQString to, - time_t date ) - : mSerialNumber( serialNumber ), mMessageId( messageId ), - mSubject( subject ), mFrom( from ), mTo( to ), mDate( date ) -{} - -TQ_UINT32 MailSummary::serialNumber() const -{ - return mSerialNumber; -} - -TQString MailSummary::messageId() -{ - return mMessageId; -} - -TQString MailSummary::subject() -{ - return mSubject; -} - -TQString MailSummary::from() -{ - return mFrom; -} - -TQString MailSummary::to() -{ - return mTo; -} - -time_t MailSummary::date() -{ - return mDate; -} - -void MailSummary::set( TQ_UINT32 serialNumber, TQString messageId, - TQString subject, TQString from, TQString to, time_t date ) -{ - mSerialNumber = serialNumber; - mMessageId = messageId; - mSubject = subject; - mFrom = from; - mTo = to; - mDate = date; -} - -MailListDrag::MailListDrag( MailList mailList, TQWidget * parent, MailTextSource *src ) - : TQStoredDrag( MailListDrag::format(), parent ), _src(src) -{ - setMailList( mailList ); -} - -MailListDrag::~MailListDrag() -{ - delete _src; - _src = 0; -} - -const char* MailListDrag::format() -{ - return "x-kmail-drag/message-list"; -} - -bool MailListDrag::canDecode( TQMimeSource *e ) -{ - return e->provides( MailListDrag::format() ); -} - -// Have to define before use -TQDataStream& operator<< ( TQDataStream &s, MailSummary &d ) -{ - s << d.serialNumber(); - s << d.messageId(); - s << d.subject(); - s << d.from(); - s << d.to(); - s << d.date(); - return s; -} - -TQDataStream& operator>> ( TQDataStream &s, MailSummary &d ) -{ - TQ_UINT32 serialNumber; - TQString messageId, subject, from, to; - time_t date; - s >> serialNumber; - s >> messageId; - s >> subject; - s >> from; - s >> to; - s >> date; - d.set( serialNumber, messageId, subject, from, to, date ); - return s; -} - -TQDataStream& operator<< ( TQDataStream &s, MailList &mailList ) -{ - MailList::iterator it; - for (it = mailList.begin(); it != mailList.end(); ++it) { - MailSummary mailDrag = *it; - s << mailDrag; - } - return s; -} - -TQDataStream& operator>> ( TQDataStream &s, MailList &mailList ) -{ - mailList.clear(); - MailSummary mailDrag; - while (!s.atEnd()) { - s >> mailDrag; - mailList.append( mailDrag ); - } - return s; -} - -bool MailListDrag::decode( TQDropEvent* e, MailList& mailList ) -{ - TQByteArray payload = e->tqencodedData( MailListDrag::format() ); - TQDataStream buffer( payload, IO_ReadOnly ); - if ( payload.size() ) { - e->accept(); - buffer >> mailList; - return TRUE; - } - return FALSE; -} - -bool MailListDrag::decode( TQByteArray& payload, MailList& mailList ) -{ - TQDataStream stream( payload, IO_ReadOnly ); - if ( payload.size() ) { - stream >> mailList; - return TRUE; - } - return FALSE; -} - -bool MailListDrag::decode( TQDropEvent* e, TQByteArray &a ) -{ - MailList mailList; - if (decode( e, mailList )) { - MailList::iterator it; - TQBuffer buffer( a ); - buffer.open( IO_WriteOnly ); - TQDataStream stream( &buffer ); - for (it = mailList.begin(); it != mailList.end(); ++it) { - MailSummary mailDrag = *it; - stream << mailDrag.serialNumber(); - } - buffer.close(); - return TRUE; - } - return FALSE; -} - -void MailListDrag::setMailList( MailList mailList ) -{ - TQByteArray array; - TQBuffer buffer( array ); - buffer.open( IO_WriteOnly); - TQDataStream stream( array, IO_WriteOnly ); - stream << mailList; - buffer.close(); - setEncodedData( array ); -} - -const char *MailListDrag::format(int i) const -{ - if (_src) { - if (i == 0) { - return "message/rfc822"; - } else { - return TQStoredDrag::format(i - 1); - } - } - - return TQStoredDrag::format(i); -} - -bool MailListDrag::provides(const char *mimeType) const -{ - if (_src && TQCString(mimeType) == "message/rfc822") { - return true; - } - - return TQStoredDrag::provides(mimeType); -} - -TQByteArray MailListDrag::tqencodedData(const char *mimeType) const -{ - if (TQCString(mimeType) != "message/rfc822") { - return TQStoredDrag::tqencodedData(mimeType); - } - - TQByteArray rc; - if (_src) { - MailList ml; - TQByteArray enc = TQStoredDrag::tqencodedData(format()); - decode(enc, ml); - - KProgressDialog *dlg = new KProgressDialog(0, 0, TQString(), i18n("Retrieving and storing messages..."), true); - dlg->setAllowCancel(true); - dlg->progressBar()->setTotalSteps(ml.count()); - int i = 0; - dlg->progressBar()->setValue(i); - dlg->show(); - - TQTextStream *ts = new TQTextStream(rc, IO_WriteOnly); - for (MailList::ConstIterator it = ml.begin(); it != ml.end(); ++it) { - MailSummary mailDrag = *it; - *ts << _src->text(mailDrag.serialNumber()); - if (dlg->wasCancelled()) { - break; - } - dlg->progressBar()->setValue(++i); - kapp->eventLoop()->processEvents(TQEventLoop::ExcludeSocketNotifiers); - } - - delete dlg; - delete ts; - } - return rc; -} - diff --git a/libkdepim/maillistdrag.h b/libkdepim/maillistdrag.h deleted file mode 100644 index f13e59ebf..000000000 --- a/libkdepim/maillistdrag.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Don Sanders - Copyright (c) 2005 George Staikos - -/** - * KDEPIM classes for drag and drop of mails - * - * // Code example for drag and drop enabled widget - * - * void SomeWidget::contentsDropEvent(TQDropEvent *e) - * { - * if (e->provides(MailListDrag::format())) { - * MailList mailList; - * MailListDrag::decode( e, mailList ); - * ... - **/ - -namespace KPIM { - -class KDE_EXPORT MailSummary -{ -public: - MailSummary( TQ_UINT32 serialNumber, TQString messageId, TQString subject, - TQString from, TQString to, time_t date ); - MailSummary() {} - ~MailSummary() {} - - /*** Set fields for this mail summary ***/ - void set( TQ_UINT32, TQString, TQString, TQString, TQString, time_t ); - - /*** KMail unique identification number ***/ - TQ_UINT32 serialNumber() const; - - /*** MD5 checksum of message identification string ***/ - TQString messageId(); - - /*** Subject of the message including prefixes ***/ - TQString subject(); - - /*** Simplified from address ***/ - TQString from(); - - /** Simplified to address ***/ - TQString to(); - - /*** Date the message was sent ***/ - time_t date(); - -private: - TQ_UINT32 mSerialNumber; - TQString mMessageId, mSubject, mFrom, mTo; - time_t mDate; -}; - -// List of mail summaries -typedef TQValueList MailList; - -// Object for the drag object to call-back for message fulltext -class KDE_EXPORT MailTextSource { -public: - MailTextSource() {} - virtual ~MailTextSource() {} - - virtual TQCString text(TQ_UINT32 serialNumber) const = 0; -}; - -// Drag and drop object for mails -class KDE_EXPORT MailListDrag : public TQStoredDrag -{ -public: - // Takes ownership of "src" and deletes it when done - MailListDrag( MailList, TQWidget * parent = 0, MailTextSource *src = 0 ); - ~MailListDrag(); - - const char *format(int i) const; - - bool provides(const char *mimeType) const; - - TQByteArray tqencodedData(const char *) const; - - /* Reset the list of mail summaries */ - void setMailList( MailList ); - - /* The format for this drag - "x-kmail-drag/message-list" */ - static const char* format(); - - /* Returns TRUE if the information in e can be decoded into a TQString; - otherwsie returns FALSE */ - static bool canDecode( TQMimeSource* e ); - - /* Attempts to decode the dropped information; - Returns TRUE if successful; otherwise return false */ - static bool decode( TQDropEvent* e, MailList& s ); - - /* Attempts to decode the serialNumbers of the dropped information; - Returns TRUE if successful; otherwise return false */ - static bool decode( TQDropEvent* e, TQByteArray& a ); - - /* Attempts to decode the encoded MailList; - Returns TRUE if successful; otherwise return false */ - static bool decode( TQByteArray& a, MailList& s ); - -private: - MailTextSource *_src; -}; - -} -#endif /*maillistdrag_h*/ diff --git a/libkdepim/overlaywidget.cpp b/libkdepim/overlaywidget.cpp deleted file mode 100644 index ac05d84fd..000000000 --- a/libkdepim/overlaywidget.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/** -*- c++ -*- - * overlaywidget.h - * - * Copyright (c) 2004 David Faure - * - * 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; version 2 of the License - * - * 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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 "overlaywidget.h" -using namespace KPIM; - -OverlayWidget::OverlayWidget( TQWidget* alignWidget, TQWidget* parent, const char* name ) - : TQHBox( parent, name ), mAlignWidget( 0 ) -{ - setAlignWidget( alignWidget ); -} - -OverlayWidget::~OverlayWidget() -{ -} - -void OverlayWidget::reposition() -{ - if ( !mAlignWidget ) - return; - // p is in the alignWidget's coordinates - TQPoint p; - // We are always above the alignWidget, right-aligned with it. - p.setX( mAlignWidget->width() - width() ); - p.setY( -height() ); - // Position in the toplevelwidget's coordinates - TQPoint pTopLevel = mAlignWidget->mapTo( tqtopLevelWidget(), p ); - // Position in the widget's parentWidget coordinates - TQPoint pParent = parentWidget()->mapFrom( tqtopLevelWidget(), pTopLevel ); - // Move 'this' to that position. - move( pParent ); -} - -void OverlayWidget::setAlignWidget( TQWidget * w ) -{ - if (w == mAlignWidget) - return; - - if (mAlignWidget) - mAlignWidget->removeEventFilter(this); - - mAlignWidget = w; - - if (mAlignWidget) - mAlignWidget->installEventFilter(this); - - reposition(); -} - -bool OverlayWidget::eventFilter( TQObject* o, TQEvent* e) -{ - if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(mAlignWidget) && - ( e->type() == TQEvent::Move || e->type() == TQEvent::Resize ) ) { - reposition(); - } - return TQFrame::eventFilter(o,e); -} - -void OverlayWidget::resizeEvent( TQResizeEvent* ev ) -{ - reposition(); - TQFrame::resizeEvent( ev ); -} - -#include "overlaywidget.moc" diff --git a/libkdepim/overlaywidget.h b/libkdepim/overlaywidget.h deleted file mode 100644 index 9e611fb92..000000000 --- a/libkdepim/overlaywidget.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- c++ -*- - * overlaywidget.h - * - * Copyright (c) 2004 David Faure - * - * 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; version 2 of the License - * - * 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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 OVERLAYWIDGET_H -#define OVERLAYWIDGET_H - -#include - -namespace KPIM { - -/** - * This is a widget that can align itself with another one, without using a tqlayout, - * so that it can actually be on top of other widgets. - * Currently the only supported type of tqalignment is "right aligned, on top of the other widget". - * - * OverlayWidget inherits TQHBox for convenience purposes (tqlayout, and frame) - */ -class OverlayWidget : public TQHBox -{ - Q_OBJECT - TQ_OBJECT - -public: - OverlayWidget( TQWidget* alignWidget, TQWidget* parent, const char* name = 0 ); - ~OverlayWidget(); - - TQWidget * alignWidget() { return mAlignWidget; } - void setAlignWidget( TQWidget * alignWidget ); - -protected: - void resizeEvent( TQResizeEvent* ev ); - bool eventFilter( TQObject* o, TQEvent* e); - -private: - void reposition(); - -private: - TQWidget * mAlignWidget; -}; - -} // namespace - -#endif /* OVERLAYWIDGET_H */ - diff --git a/libkdepim/pics/CMakeLists.txt b/libkdepim/pics/CMakeLists.txt deleted file mode 100644 index 7cbe71d0a..000000000 --- a/libkdepim/pics/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -################################################# -# -# (C) 2010-2011 Serghei Amelian -# serghei (DOT) amelian (AT) gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# - -install( FILES - addresseelineedit.png clicklineedit.png - kdateedit.png ktimeedit.png - DESTINATION ${DATA_INSTALL_DIR}/tdepimwidgets/pics ) diff --git a/libkdepim/pics/Makefile.am b/libkdepim/pics/Makefile.am deleted file mode 100644 index c4c611966..000000000 --- a/libkdepim/pics/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -tdepimwidgetsdata_DATA = addresseelineedit.png \ - clicklineedit.png kdateedit.png ktimeedit.png - -tdepimwidgetsdatadir = $(kde_datadir)/tdepimwidgets/pics - -EXTRA_DIST = $(tdepimwidgetsdata_DATA) diff --git a/libkdepim/pics/addresseelineedit.png b/libkdepim/pics/addresseelineedit.png deleted file mode 100644 index 81d313913..000000000 Binary files a/libkdepim/pics/addresseelineedit.png and /dev/null differ diff --git a/libkdepim/pics/clicklineedit.png b/libkdepim/pics/clicklineedit.png deleted file mode 100644 index ec40fb2f3..000000000 Binary files a/libkdepim/pics/clicklineedit.png and /dev/null differ diff --git a/libkdepim/pics/kdateedit.png b/libkdepim/pics/kdateedit.png deleted file mode 100644 index e2fa34682..000000000 Binary files a/libkdepim/pics/kdateedit.png and /dev/null differ diff --git a/libkdepim/pics/ktimeedit.png b/libkdepim/pics/ktimeedit.png deleted file mode 100644 index 1b0d79afe..000000000 Binary files a/libkdepim/pics/ktimeedit.png and /dev/null differ diff --git a/libkdepim/pimemoticons.kcfg b/libkdepim/pimemoticons.kcfg deleted file mode 100644 index f06a7743a..000000000 --- a/libkdepim/pimemoticons.kcfg +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - Default - - This allows you to change the emoticon theme that should be used. - - - - - angry_0 - angry_1 - - - bat_0 - bat_1 - - - cake_0 - - - cat_0 - - - - - confused_0 - confused_1 - confused_2 - confused_3 - cry_0 - cry_1 - cry_2 - cry_3 - - - dog_0 - embarassed_0 - embarassed_1 - - - film_0 - - - kiss_2 - kiss_3 - kiss_4 - kiss_5 - - - - - - omg_0 - omg_1 - omg_2 - omg_3 - - - - - - - sad_0 - sad_1 - - shade_1 - - smile_0 - smile_1 - smile_2 - star_0 - teeth_0 - teeth_1 - teeth_2 - teeth_3 - - - - - tongue_0 - tongue_1 - tongue_2 - tongue_3 - - - - - wink_0 - wink_1 - - - :-@ - :@ - - - :-[ - :[ - - - (^) - - - (@) - - - - - :-S - :S - :-s - :s - :'( - :'-( - ;-( - ;( - - - (&) - :-$ - :$ - - - (~) - - - :-X - :X - :-x - :x - - - - - - :-O - :O - :-o - :o - - - - - - - :-( - :( - - 8-) - - :-) - :) - :o) - (*) - :-D - :D - :-d - :d - - - - - :-P - :P - :-p - :p - - - - - ;-) - ;) - - - diff --git a/libkdepim/pimemoticons.kcfgc b/libkdepim/pimemoticons.kcfgc deleted file mode 100644 index 9121a7302..000000000 --- a/libkdepim/pimemoticons.kcfgc +++ /dev/null @@ -1,5 +0,0 @@ -File=pimemoticons.kcfg -ClassName=EmotIcons -Singleton=true -#ItemAccessors=true - diff --git a/libkdepim/pluginloader.h b/libkdepim/pluginloader.h deleted file mode 100644 index 6d38bbd18..000000000 --- a/libkdepim/pluginloader.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- c++ -*- - This file is part of libtdepim. - - Copyright (c) 2002,2004 Marc Mutz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __KPIM_SHARED_PLUGINLOADER_H__ -#define __KPIM_SHARED_PLUGINLOADER_H__ - -#include - -namespace KPIM { - - /** - * @short A generic plugin loader for when KPart::Plugin is overkill - * @author Marc Mutz based on KABC's FormatFactory - * - * This is a generic plugin loader / factory for small plugins that - * don't want to be TQObjects. - * - * @section Usage - * - * A PluginLoader takes two template arguments, T and - * T_config: - * - *
- *
T
The type of object to return
- *
T_config::mainfunc
The suffix of the factory function to call - * in the library to obtain a new object of type T. - * The string passed to KLibrary::symbol() is - * libName_mainfunc.
- *
T_config::path
The search pattern for .desktop files - * containing the plugin descriptions. This is the string passed as - * the @p filter argument to - * KStandardDirs::findAllResources.
- *
- * - * The last two parameters being strings, they are passed via an - * encapsulating class, of which mainfunc and - * path are public static members: - * - *
-   * struct MyObjectPluginLoaderConfig {
-   *   static const char * const mainfunc;
-   *   static const char * const path;
-   * };
-   * const char * const MyObjectPluginLoaderConfig::mainfunc = "myapp_create_myobject";
-   * const char * const MyObjectPluginLoaderConfig::path = "myapp/plugins/ *.desktop";
-   * 
- * - * You would then use a typedef to create a less unwieldy - * name for your plugin loader: - * - *
-   * typedef KPIM::PluginLoader< MyObject, MyObjectPluginLoaderConfig > MyObjectPluginLoader;
-   * 
- * - * All of this is what the - * KPIM_DEFINE_PLUGIN_LOADER(pluginloadername,type,mainfunc,path) macro - * achieves. - * - **/ - template< typename T, typename T_config > - class KDE_EXPORT PluginLoader : public PluginLoaderBase { - protected: - PluginLoader() : PluginLoaderBase() {} - - private: - static PluginLoader * mSelf; - - public: - virtual ~PluginLoader() { mSelf = 0; } - - /** Returns the single instance of this loader. */ - static PluginLoader * instance() { - if ( !mSelf ) { - mSelf = new PluginLoader(); - mSelf->scan(); - } - return mSelf; - } - - /** Rescans the plugin directory to find any newly installed - plugins. - **/ - virtual void scan() { - doScan( T_config::path ); - } - - /** Returns a pointer to a plugin object (of type @p T) or a null - pointer if the type wasn't found. You can extend this method - for when you want to handle builtin types */ - virtual T * createForName( const TQString & type ) const { - void * main_func = mainFunc( type, T_config::mainfunc ); - if ( !main_func ) return 0; - - // cast to a pointer to a function returning T*, call it and - // return the result; don't you love C? ;-) - return ((T* (*)())( main_func ))(); - } - }; - - template< typename T, typename T_config > - PluginLoader * PluginLoader::mSelf = 0; - -} - -#define KPIM_DEFINE_PLUGIN_LOADER( pl, t, mf, p ) \ - namespace { /* don't pollute namespaces */ \ - struct KDE_EXPORT pl##Config { \ - static const char * const mainfunc; \ - static const char * const path; \ - }; \ - const char * const pl##Config::mainfunc = mf; \ - const char * const pl##Config::path = p; \ - } \ - typedef KPIM::PluginLoader< t, pl##Config > pl; \ - - -#endif // __KPIM_SHARED_PLUGINLOADER_H__ diff --git a/libkdepim/pluginloaderbase.cpp b/libkdepim/pluginloaderbase.cpp deleted file mode 100644 index 60a925efa..000000000 --- a/libkdepim/pluginloaderbase.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* -*- c++ -*- - This file is part of libtdepim. - - Copyright (c) 2002,2004 Marc Mutz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 - -static kdbgstream warning() { - return kdWarning( 5300 ) << "PluginLoaderBase: "; -} -#ifndef NDEBUG -static kdbgstream debug( bool cond ) -#else -static kndbgstream debug( bool cond ) -#endif -{ - return kdDebug( cond, 5300 ) << "PluginLoaderBase: "; -} - -namespace KPIM { - - PluginLoaderBase::PluginLoaderBase() : d(0) {} - PluginLoaderBase::~PluginLoaderBase() {} - - - TQStringList PluginLoaderBase::types() const { - TQStringList result; - for ( TQMap< TQString, PluginMetaData >::const_iterator it = mPluginMap.begin(); - it != mPluginMap.end() ; ++it ) - result.push_back( it.key() ); - return result; - } - - const PluginMetaData * PluginLoaderBase::infoForName( const TQString & type ) const { - return mPluginMap.contains( type ) ? &(mPluginMap[type]) : 0 ; - } - - - void PluginLoaderBase::doScan( const char * path ) { - mPluginMap.clear(); - - const TQStringList list = - KGlobal::dirs()->findAllResources( "data", path, true, true ); - for ( TQStringList::const_iterator it = list.begin() ; - it != list.end() ; ++it ) { - KSimpleConfig config( *it, true ); - if ( config.hasGroup( "Misc" ) && config.hasGroup( "Plugin" ) ) { - config.setGroup( "Plugin" ); - - const TQString type = config.readEntry( "Type" ).lower(); - if ( type.isEmpty() ) { - warning() << "missing or empty [Plugin]Type value in \"" - << *it << "\" - skipping" << endl; - continue; - } - - const TQString library = config.readEntry( "X-KDE-Library" ); - if ( library.isEmpty() ) { - warning() << "missing or empty [Plugin]X-KDE-Library value in \"" - << *it << "\" - skipping" << endl; - continue; - } - - config.setGroup( "Misc" ); - - TQString name = config.readEntry( "Name" ); - if ( name.isEmpty() ) { - warning() << "missing or empty [Misc]Name value in \"" - << *it << "\" - inserting default name" << endl; - name = i18n("Unnamed plugin"); - } - - TQString comment = config.readEntry( "Comment" ); - if ( comment.isEmpty() ) { - warning() << "missing or empty [Misc]Comment value in \"" - << *it << "\" - inserting default name" << endl; - comment = i18n("No description available"); - } - - mPluginMap.insert( type, PluginMetaData( library, name, comment ) ); - } else { - warning() << "Desktop file \"" << *it - << "\" doesn't seem to describe a plugin " - << "(misses Misc and/or Plugin group)" << endl; - } - } - } - - void * PluginLoaderBase::mainFunc( const TQString & type, - const char * mf_name ) const { - if ( type.isEmpty() || !mPluginMap.contains( type ) ) - return 0; - - const TQString libName = mPluginMap[ type ].library; - if ( libName.isEmpty() ) - return 0; - - const KLibrary * lib = openLibrary( libName ); - if ( !lib ) - return 0; - - mPluginMap[ type ].loaded = true; - - const TQString factory_name = libName + '_' + mf_name; - if ( !lib->hasSymbol( factory_name.latin1() ) ) { - warning() << "No symbol named \"" << factory_name.latin1() << "\" (" - << factory_name << ") was found in library \"" << libName - << "\"" << endl; - return 0; - } - - return lib->symbol( factory_name.latin1() ); - } - - const KLibrary * PluginLoaderBase::openLibrary( const TQString & libName ) const { - - const TQString path = KLibLoader::findLibrary( TQFile::encodeName( libName ) ); - - if ( path.isEmpty() ) { - warning() << "No plugin library named \"" << libName - << "\" was found!" << endl; - return 0; - } - - const KLibrary * library = KLibLoader::self()->library( TQFile::encodeName( path ) ); - - debug( !library ) << "Could not load library '" << libName << "'" << endl; - - return library; - } - - -} // namespace KMime diff --git a/libkdepim/pluginloaderbase.h b/libkdepim/pluginloaderbase.h deleted file mode 100644 index 766372787..000000000 --- a/libkdepim/pluginloaderbase.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- c++ -*- - This file is part of libtdepim. - - Copyright (c) 2002,2004 Marc Mutz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __LIBKDEPIM_PLUGINLOADERBASE_H__ -#define __LIBKDEPIM_PLUGINLOADERBASE_H__ - -#include -#include - -#include - -class KLibrary; -class TQStringList; - -namespace KPIM { - - class KDE_EXPORT PluginMetaData { - public: - PluginMetaData() {} - PluginMetaData( const TQString & lib, const TQString & name, - const TQString & comment ) - : library( lib ), nameLabel( name ), - descriptionLabel( comment ), loaded( false ) {} - TQString library; - TQString nameLabel; - TQString descriptionLabel; - mutable bool loaded; - }; - - class KDE_EXPORT PluginLoaderBase { - protected: - PluginLoaderBase(); - virtual ~PluginLoaderBase(); - - public: - /** Returns a list of all available plugin objects (of kind @p T) */ - TQStringList types() const; - - /** Returns the @ref PluginMetaData structure for a given type */ - const PluginMetaData * infoForName( const TQString & type ) const; - - /** Overload this method in subclasses to call @ref doScan with - the right @p path argument */ - virtual void scan() = 0; - - protected: - /** Rescans the plugin directory to find any newly installed - plugins. Extend this method in subclasses to add any - builtins. Subclasses must call this explicitely. It's not - called for them in the constructor. - **/ - void doScan( const char * path ); - - /** Returns a pointer to symbol @p main_func in the library that - implements the plugin of type @p type */ - void * mainFunc( const TQString & type, const char * main_func ) const; - - private: - const KLibrary * openLibrary( const TQString & libName ) const; - TQMap< TQString, PluginMetaData > mPluginMap; - - class Private; - Private * d; - }; - -} // namespace KMime - -#endif // __LIBKDEPIM_PLUGINLOADERBASE_H__ diff --git a/libkdepim/progressdialog.cpp b/libkdepim/progressdialog.cpp deleted file mode 100644 index bd5b594c6..000000000 --- a/libkdepim/progressdialog.cpp +++ /dev/null @@ -1,437 +0,0 @@ -/** -*- c++ -*- - * progressdialog.cpp - * - * Copyright (c) 2004 Till Adam , - * David Faure - * - * 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; version 2 of the License - * - * 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "progressdialog.h" -#include "progressmanager.h" -#include "ssllabel.h" -#include - -namespace KPIM { - -class TransactionItem; - -TransactionItemView::TransactionItemView( TQWidget * parent, - const char * name, - WFlags f ) - : TQScrollView( parent, name, f ) { - setFrameStyle( NoFrame ); - mBigBox = new TQVBox( viewport() ); - mBigBox->setSpacing( 5 ); - addChild( mBigBox ); - setResizePolicy( TQScrollView::AutoOneFit ); // Fit so that the box expands horizontally -} - -TransactionItem* TransactionItemView::addTransactionItem( ProgressItem* item, bool first ) -{ - TransactionItem *ti = new TransactionItem( mBigBox, item, first ); - ti->hide(); - TQTimer::singleShot( 1000, ti, TQT_SLOT( show() ) ); - return ti; -} - -void TransactionItemView::resizeContents( int w, int h ) -{ - // (handling of TQEvent::LayoutHint in TQScrollView calls this method) - //kdDebug(5300) << k_funcinfo << w << "," << h << endl; - TQScrollView::resizeContents( w, h ); - // Tell the tqlayout in the parent (progressdialog) that our size changed - updateGeometry(); - // Resize the parent (progressdialog) - this works but resize horizontally too often - //parentWidget()->adjustSize(); - - TQApplication::sendPostedEvents( 0, TQEvent::ChildInserted ); - TQApplication::sendPostedEvents( 0, TQEvent::LayoutHint ); - TQSize sz = parentWidget()->tqsizeHint(); - int currentWidth = parentWidget()->width(); - // Don't resize to sz.width() every time when it only reduces a little bit - if ( currentWidth < sz.width() || currentWidth > sz.width() + 100 ) - currentWidth = sz.width(); - parentWidget()->resize( currentWidth, sz.height() ); -} - -TQSize TransactionItemView::tqsizeHint() const -{ - return tqminimumSizeHint(); -} - -TQSize TransactionItemView::tqminimumSizeHint() const -{ - int f = 2 * frameWidth(); - // Make room for a vertical scrollbar in all cases, to avoid a horizontal one - int vsbExt = verticalScrollBar()->tqsizeHint().width(); - int minw = tqtopLevelWidget()->width() / 3; - int maxh = tqtopLevelWidget()->height() / 2; - TQSize sz( mBigBox->tqminimumSizeHint() ); - sz.setWidth( TQMAX( sz.width(), minw ) + f + vsbExt ); - sz.setHeight( TQMIN( sz.height(), maxh ) + f ); - return sz; -} - - -void TransactionItemView::slotLayoutFirstItem() -{ - /* - The below relies on some details in TQt's behaviour regarding deleting - objects. This slot is called from the destroyed signal of an item just - going away. That item is at that point still in the list of chilren, but - since the vtable is already gone, it will have type TQObject. The first - one with both the right name and the right class therefor is what will - be the first item very shortly. That's the one we want to remove the - hline for. - */ - TQObject *o = mBigBox->child( "TransactionItem", "KPIM::TransactionItem" ); - TransactionItem *ti = dynamic_cast( o ); - if ( ti ) { - ti->hideHLine(); - } -} - - -// ---------------------------------------------------------------------------- - -TransactionItem::TransactionItem( TQWidget* parent, - ProgressItem *item, bool first ) - : TQVBox( parent, "TransactionItem" ), mCancelButton( 0 ), mItem( item ) - -{ - setSpacing( 2 ); - setMargin( 2 ); - tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) ); - - mFrame = new TQFrame( this ); - mFrame->setFrameShape( TQFrame::HLine ); - mFrame->setFrameShadow( TQFrame::Raised ); - mFrame->show(); - setStretchFactor( mFrame, 3 ); - - TQHBox *h = new TQHBox( this ); - h->setSpacing( 5 ); - - mItemLabel = new TQLabel( item->label(), h ); - // always interpret the label text as RichText, but disable word wrapping - mItemLabel->setTextFormat( TQt::RichText ); - mItemLabel->tqsetAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::SingleLine ); - h->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) ); - - mProgress = new TQProgressBar( 100, h ); - mProgress->setProgress( item->progress() ); - - if ( item->canBeCanceled() ) { - mCancelButton = new TQPushButton( SmallIcon( "cancel" ), TQString(), h ); - TQToolTip::add( mCancelButton, i18n("Cancel this operation.") ); - connect ( mCancelButton, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( slotItemCanceled() )); - } - - h = new TQHBox( this ); - h->setSpacing( 5 ); - h->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) ); - mSSLLabel = new SSLLabel( h ); - mSSLLabel->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) ); - mItemtqStatus = new TQLabel( item->status(), h ); - // always interpret the status text as RichText, but disable word wrapping - mItemtqStatus->setTextFormat( TQt::RichText ); - mItemtqStatus->tqsetAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::SingleLine ); - // richtext leads to tqsizeHint acting as if wrapping was enabled though, - // so make sure we only ever have the height of one line. - mItemtqStatus->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Ignored ) ); - mItemtqStatus->setFixedHeight( mItemLabel->tqsizeHint().height() ); - setCrypto( item->usesCrypto() ); - if( first ) hideHLine(); -} - -TransactionItem::~TransactionItem() -{ -} - -void TransactionItem::hideHLine() -{ - mFrame->hide(); -} - -void TransactionItem::setProgress( int progress ) -{ - mProgress->setProgress( progress ); -} - -void TransactionItem::setLabel( const TQString& label ) -{ - mItemLabel->setText( label ); -} - -void TransactionItem::setqStatus( const TQString& status ) -{ - mItemtqStatus->setText( status ); -} - -void TransactionItem::setCrypto( bool on ) -{ - if (on) - mSSLLabel->setEncrypted( true ); - else - mSSLLabel->setEncrypted( false ); - - mSSLLabel->setState( mSSLLabel->lastState() ); -} - -void TransactionItem::setTotalSteps( int totalSteps ) -{ - mProgress->setTotalSteps( totalSteps ); -} - -void TransactionItem::slotItemCanceled() -{ - if ( mItem ) - mItem->cancel(); -} - - -void TransactionItem::addSubTransaction( ProgressItem* /*item*/ ) -{ - -} - - -// --------------------------------------------------------------------------- - -ProgressDialog::ProgressDialog( TQWidget* alignWidget, TQWidget* parent, const char* name ) - : OverlayWidget( alignWidget, parent, name ), mWasLastShown( false ) -{ - setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); // TQFrame - setSpacing( 0 ); // TQHBox - setMargin( 1 ); - - mScrollView = new TransactionItemView( this, "ProgressScrollView" ); - - // No more close button for now, since there is no more autoshow - /* - TQVBox* rightBox = new TQVBox( this ); - TQToolButton* pbClose = new TQToolButton( rightBox ); - pbClose->setAutoRaise(true); - pbClose->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) ); - pbClose->setFixedSize( 16, 16 ); - pbClose->setIconSet( KGlobal::iconLoader()->loadIconSet( "fileclose", KIcon::Small, 14 ) ); - TQToolTip::add( pbClose, i18n( "Hide detailed progress window" ) ); - connect(pbClose, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotClose())); - TQWidget* spacer = new TQWidget( rightBox ); // don't let the close button take up all the height - rightBox->setStretchFactor( spacer, 100 ); - */ - - /* - * Get the singleton ProgressManager item which will inform us of - * appearing and vanishing items. - */ - ProgressManager *pm = ProgressManager::instance(); - connect ( pm, TQT_SIGNAL( progressItemAdded( KPIM::ProgressItem* ) ), - this, TQT_SLOT( slotTransactionAdded( KPIM::ProgressItem* ) ) ); - connect ( pm, TQT_SIGNAL( progressItemCompleted( KPIM::ProgressItem* ) ), - this, TQT_SLOT( slotTransactionCompleted( KPIM::ProgressItem* ) ) ); - connect ( pm, TQT_SIGNAL( progressItemProgress( KPIM::ProgressItem*, unsigned int ) ), - this, TQT_SLOT( slotTransactionProgress( KPIM::ProgressItem*, unsigned int ) ) ); - connect ( pm, TQT_SIGNAL( progressItemtqStatus( KPIM::ProgressItem*, const TQString& ) ), - this, TQT_SLOT( slotTransactiontqStatus( KPIM::ProgressItem*, const TQString& ) ) ); - connect ( pm, TQT_SIGNAL( progressItemLabel( KPIM::ProgressItem*, const TQString& ) ), - this, TQT_SLOT( slotTransactionLabel( KPIM::ProgressItem*, const TQString& ) ) ); - connect ( pm, TQT_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*, bool) ), - this, TQT_SLOT( slotTransactionUsesCrypto( KPIM::ProgressItem*, bool ) ) ); - connect ( pm, TQT_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*, bool) ), - this, TQT_SLOT( slotTransactionUsesBusyIndicator( KPIM::ProgressItem*, bool ) ) ); - connect ( pm, TQT_SIGNAL( showProgressDialog() ), - this, TQT_SLOT( slotShow() ) ); -} - -void ProgressDialog::closeEvent( TQCloseEvent* e ) -{ - e->accept(); - hide(); -} - - -/* - * Destructor - */ -ProgressDialog::~ProgressDialog() -{ - // no need to delete child widgets. -} - -void ProgressDialog::slotTransactionAdded( ProgressItem *item ) -{ - TransactionItem *parent = 0; - if ( item->parent() ) { - if ( mTransactionsToListviewItems.contains( item->parent() ) ) { - parent = mTransactionsToListviewItems[ item->parent() ]; - parent->addSubTransaction( item ); - } - } else { - const bool first = mTransactionsToListviewItems.empty(); - TransactionItem *ti = mScrollView->addTransactionItem( item, first ); - if ( ti ) - mTransactionsToListviewItems.replace( item, ti ); - if ( first && mWasLastShown ) - TQTimer::singleShot( 1000, this, TQT_SLOT( slotShow() ) ); - - } -} - -void ProgressDialog::slotTransactionCompleted( ProgressItem *item ) -{ - if ( mTransactionsToListviewItems.contains( item ) ) { - TransactionItem *ti = mTransactionsToListviewItems[ item ]; - mTransactionsToListviewItems.remove( item ); - ti->setItemComplete(); - TQTimer::singleShot( 3000, ti, TQT_SLOT( deleteLater() ) ); - // see the slot for comments as to why that works - connect ( ti, TQT_SIGNAL( destroyed() ), - mScrollView, TQT_SLOT( slotLayoutFirstItem() ) ); - } - // This was the last item, hide. - if ( mTransactionsToListviewItems.empty() ) - TQTimer::singleShot( 3000, this, TQT_SLOT( slotHide() ) ); -} - -void ProgressDialog::slotTransactionCanceled( ProgressItem* ) -{ -} - -void ProgressDialog::slotTransactionProgress( ProgressItem *item, - unsigned int progress ) -{ - if ( mTransactionsToListviewItems.contains( item ) ) { - TransactionItem *ti = mTransactionsToListviewItems[ item ]; - ti->setProgress( progress ); - } -} - -void ProgressDialog::slotTransactiontqStatus( ProgressItem *item, - const TQString& status ) -{ - if ( mTransactionsToListviewItems.contains( item ) ) { - TransactionItem *ti = mTransactionsToListviewItems[ item ]; - ti->setqStatus( status ); - } -} - -void ProgressDialog::slotTransactionLabel( ProgressItem *item, - const TQString& label ) -{ - if ( mTransactionsToListviewItems.contains( item ) ) { - TransactionItem *ti = mTransactionsToListviewItems[ item ]; - ti->setLabel( label ); - } -} - - -void ProgressDialog::slotTransactionUsesCrypto( ProgressItem *item, - bool value ) -{ - if ( mTransactionsToListviewItems.contains( item ) ) { - TransactionItem *ti = mTransactionsToListviewItems[ item ]; - ti->setCrypto( value ); - } -} - -void ProgressDialog::slotTransactionUsesBusyIndicator( KPIM::ProgressItem *item, bool value ) -{ - if ( mTransactionsToListviewItems.contains( item ) ) { - TransactionItem *ti = mTransactionsToListviewItems[ item ]; - if ( value ) - ti->setTotalSteps( 0 ); - else - ti->setTotalSteps( 100 ); - } -} - -void ProgressDialog::slotShow() -{ - setVisible( true ); -} - -void ProgressDialog::slotHide() -{ - // check if a new item showed up since we started the timer. If not, hide - if ( mTransactionsToListviewItems.isEmpty() ) { - setVisible( false ); - } -} - -void ProgressDialog::slotClose() -{ - mWasLastShown = false; - setVisible( false ); -} - -void ProgressDialog::setVisible( bool b ) -{ - if ( b ) - show(); - else - hide(); - emit visibilityChanged( b ); -} - -void ProgressDialog::slotToggleVisibility() -{ - /* Since we are only hiding with a timeout, there is a short period of - * time where the last item is still visible, but clicking on it in - * the statusbarwidget should not display the dialog, because there - * are no items to be shown anymore. Guard against that. - */ - mWasLastShown = !isShown(); - if ( isShown() || !mTransactionsToListviewItems.isEmpty() ) - setVisible( !isShown() ); -} - -} - -#include "progressdialog.moc" diff --git a/libkdepim/progressdialog.h b/libkdepim/progressdialog.h deleted file mode 100644 index b2511624e..000000000 --- a/libkdepim/progressdialog.h +++ /dev/null @@ -1,160 +0,0 @@ -/* -*- c++ -*- - * progressdialog.h - * - * Copyright (c) 2004 Till Adam - * based on imapprogressdialog.cpp ,which is - * Copyright (c) 2002-2003 Klar�vdalens Datakonsult AB - * - * 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; version 2 of the License - * - * 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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 __KPIM_PROGRESSDIALOG_H__ -#define __KPIM_PROGRESSDIALOG_H__ - -#include -#include -#include -#include -#include "overlaywidget.h" -#include - -class TQProgressBar; -class TQScrollView; -class TQFrame; - -namespace KPIM { -class ProgressItem; -class TransactionItemListView; -class TransactionItem; -class SSLLabel; - -class TransactionItemView : public TQScrollView { - Q_OBJECT - TQ_OBJECT -public: - TransactionItemView( TQWidget * parent = 0, - const char * name = 0, - WFlags f = 0 ); - - virtual ~TransactionItemView() - {} - TransactionItem* addTransactionItem( ProgressItem *item, bool first ); - - - TQSize tqsizeHint() const; - TQSize tqminimumSizeHint() const; -public slots: - void slotLayoutFirstItem(); - -protected: - virtual void resizeContents ( int w, int h ); - -private: - TQVBox * mBigBox; -}; - -class TransactionItem : public TQVBox { - - Q_OBJECT - TQ_OBJECT - -public: - TransactionItem( TQWidget * parent, - ProgressItem* item, bool first ); - - ~TransactionItem(); - - void hideHLine(); - - void setProgress( int progress ); - void setLabel( const TQString& ); - void setqStatus( const TQString& ); - void setCrypto( bool ); - void setTotalSteps( int totalSteps ); - - ProgressItem* item() const { return mItem; } - - void addSubTransaction( ProgressItem *item); - - // The progressitem is deleted immediately, we take 5s to go out, - // so better not use mItem during this time. - void setItemComplete() { mItem = 0; } - -public slots: - void slotItemCanceled(); - -protected: - TQProgressBar* mProgress; - TQPushButton* mCancelButton; - TQLabel* mItemLabel; - TQLabel* mItemtqStatus; - TQFrame* mFrame; - SSLLabel* mSSLLabel; - ProgressItem* mItem; -}; - -class KDE_EXPORT ProgressDialog : public OverlayWidget -{ - Q_OBJECT - TQ_OBJECT - -public: - ProgressDialog( TQWidget* alignWidget, TQWidget* parent, const char* name = 0 ); - ~ProgressDialog(); - void setVisible( bool b ); - -public slots: - void slotToggleVisibility(); - -protected slots: -void slotTransactionAdded( KPIM::ProgressItem *item ); - void slotTransactionCompleted( KPIM::ProgressItem *item ); - void slotTransactionCanceled( KPIM::ProgressItem *item ); - void slotTransactionProgress( KPIM::ProgressItem *item, unsigned int progress ); - void slotTransactiontqStatus( KPIM::ProgressItem *item, const TQString& ); - void slotTransactionLabel( KPIM::ProgressItem *item, const TQString& ); - void slotTransactionUsesCrypto( KPIM::ProgressItem *item, bool ); - void slotTransactionUsesBusyIndicator( KPIM::ProgressItem*, bool ); - - void slotClose(); - void slotShow(); - void slotHide(); - -signals: - void visibilityChanged( bool ); - -protected: - virtual void closeEvent( TQCloseEvent* ); - - TransactionItemView* mScrollView; - TransactionItem* mPreviousItem; - TQMap< const ProgressItem*, TransactionItem* > mTransactionsToListviewItems; - bool mWasLastShown; -}; - - -} // namespace KPIM - -#endif // __KPIM_PROGRESSDIALOG_H__ diff --git a/libkdepim/progressmanager.cpp b/libkdepim/progressmanager.cpp deleted file mode 100644 index a00970c5e..000000000 --- a/libkdepim/progressmanager.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/* - progressmanager.cpp - - This file is part of KDEPIM. - - Author: Till Adam (C) 2004 - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include -#include - -#include -#include - -#include "progressmanager.h" - -namespace KPIM { - -KPIM::ProgressManager * KPIM::ProgressManager::mInstance = 0; -unsigned int KPIM::ProgressManager::uID = 42; - -ProgressItem::ProgressItem( - ProgressItem* parent, const TQString& id, - const TQString& label, const TQString& status, bool canBeCanceled, - bool usesCrypto ) - :mId( id ), mLabel( label ), mtqStatus( status ), mParent( parent ), - mCanBeCanceled( canBeCanceled ), mProgress( 0 ), mTotal( 0 ), - mCompleted( 0 ), mWaitingForKids( false ), mCanceled( false ), - mUsesCrypto( usesCrypto ), mUsesBusyIndicator( false ) - {} - -ProgressItem::~ProgressItem() -{ -} - -void ProgressItem::setComplete() -{ -// kdDebug(5300) << "ProgressItem::setComplete - " << label() << endl; - - if ( mChildren.isEmpty() ) { - if ( !mCanceled ) - setProgress( 100 ); - emit progressItemCompleted( this ); - if ( parent() ) - parent()->removeChild( this ); - deleteLater(); - } else { - mWaitingForKids = true; - } -} - -void ProgressItem::addChild( ProgressItem *kiddo ) -{ - mChildren.replace( kiddo, true ); -} - -void ProgressItem::removeChild( ProgressItem *kiddo ) -{ - mChildren.remove( kiddo ); - // in case we were waiting for the last kid to go away, now is the time - if ( mChildren.count() == 0 && mWaitingForKids ) { - emit progressItemCompleted( this ); - deleteLater(); - } -} - -void ProgressItem::cancel() -{ - if ( mCanceled || !mCanBeCanceled ) return; - kdDebug(5300) << "ProgressItem::cancel() - " << label() << endl; - mCanceled = true; - // Cancel all tqchildren. - TQValueList kids = mChildren.keys(); - TQValueList::Iterator it( kids.begin() ); - TQValueList::Iterator end( kids.end() ); - for ( ; it != end; it++ ) { - ProgressItem *kid = *it; - if ( kid->canBeCanceled() ) - kid->cancel(); - } - setqStatus( i18n( "Aborting..." ) ); - emit progressItemCanceled( this ); -} - - -void ProgressItem::setProgress( unsigned int v ) -{ - mProgress = v; - // kdDebug(5300) << "ProgressItem::setProgress(): " << label() << " : " << v << endl; - emit progressItemProgress( this, mProgress ); -} - -void ProgressItem::setLabel( const TQString& v ) -{ - mLabel = v; - emit progressItemLabel( this, mLabel ); -} - -void ProgressItem::setqStatus( const TQString& v ) -{ - mtqStatus = v; - emit progressItemtqStatus( this, mtqStatus ); -} - -void ProgressItem::setUsesCrypto( bool v ) -{ - mUsesCrypto = v; - emit progressItemUsesCrypto( this, v ); -} - -void ProgressItem::setUsesBusyIndicator( bool useBusyIndicator ) -{ - mUsesBusyIndicator = useBusyIndicator; - emit progressItemUsesBusyIndicator( this, useBusyIndicator ); -} - -// ====================================== - -ProgressManager::ProgressManager() :TQObject() { - mInstance = this; -} - -ProgressManager::~ProgressManager() { mInstance = 0; } -static KStaticDeleter progressManagerDeleter; - -ProgressManager* ProgressManager::instance() -{ - if ( !mInstance ) { - progressManagerDeleter.setObject( mInstance, new ProgressManager() ); - } - return mInstance; -} - -ProgressItem* ProgressManager::createProgressItemImpl( - ProgressItem* parent, const TQString& id, - const TQString &label, const TQString &status, - bool cancellable, bool usesCrypto ) -{ - ProgressItem *t = 0; - if ( !mTransactions[ id ] ) { - t = new ProgressItem ( parent, id, label, status, cancellable, usesCrypto ); - mTransactions.insert( id, t ); - if ( parent ) { - ProgressItem *p = mTransactions[ parent->id() ]; - if ( p ) { - p->addChild( t ); - } - } - // connect all signals - connect ( t, TQT_SIGNAL( progressItemCompleted(KPIM::ProgressItem*) ), - this, TQT_SLOT( slotTransactionCompleted(KPIM::ProgressItem*) ) ); - connect ( t, TQT_SIGNAL( progressItemProgress(KPIM::ProgressItem*, unsigned int) ), - this, TQT_SIGNAL( progressItemProgress(KPIM::ProgressItem*, unsigned int) ) ); - connect ( t, TQT_SIGNAL( progressItemAdded(KPIM::ProgressItem*) ), - this, TQT_SIGNAL( progressItemAdded(KPIM::ProgressItem*) ) ); - connect ( t, TQT_SIGNAL( progressItemCanceled(KPIM::ProgressItem*) ), - this, TQT_SIGNAL( progressItemCanceled(KPIM::ProgressItem*) ) ); - connect ( t, TQT_SIGNAL( progressItemtqStatus(KPIM::ProgressItem*, const TQString&) ), - this, TQT_SIGNAL( progressItemtqStatus(KPIM::ProgressItem*, const TQString&) ) ); - connect ( t, TQT_SIGNAL( progressItemLabel(KPIM::ProgressItem*, const TQString&) ), - this, TQT_SIGNAL( progressItemLabel(KPIM::ProgressItem*, const TQString&) ) ); - connect ( t, TQT_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*, bool) ), - this, TQT_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*, bool) ) ); - connect ( t, TQT_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*, bool) ), - this, TQT_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*, bool) ) ); - - emit progressItemAdded( t ); - } else { - // Hm, is this what makes the most sense? - t = mTransactions[id]; - } - return t; -} - -ProgressItem* ProgressManager::createProgressItemImpl( - const TQString& parent, const TQString &id, - const TQString &label, const TQString& status, - bool canBeCanceled, bool usesCrypto ) -{ - ProgressItem * p = mTransactions[parent]; - return createProgressItemImpl( p, id, label, status, canBeCanceled, usesCrypto ); -} - -void ProgressManager::emitShowProgressDialogImpl() -{ - emit showProgressDialog(); -} - - -// slots - -void ProgressManager::slotTransactionCompleted( ProgressItem *item ) -{ - mTransactions.remove( item->id() ); - emit progressItemCompleted( item ); -} - -void ProgressManager::slotStandardCancelHandler( ProgressItem *item ) -{ - item->setComplete(); -} - -ProgressItem* ProgressManager::singleItem() const -{ - ProgressItem *item = 0; - TQDictIterator< ProgressItem > it( mTransactions ); - for ( ; it.current(); ++it ) { - - // No single item for progress possible, as one of them is a busy indicator one. - if ( (*it)->usesBusyIndicator() ) - return 0; - - if ( !(*it)->parent() ) { // if it's a top level one, only those count - if ( item ) - return 0; // we found more than one - else - item = (*it); - } - } - return item; -} - -void ProgressManager::slotAbortAll() -{ - TQDictIterator< ProgressItem > it( mTransactions ); - for ( ; it.current(); ++it ) { - it.current()->cancel(); - } -} - -} // namespace - -#include "progressmanager.moc" diff --git a/libkdepim/progressmanager.h b/libkdepim/progressmanager.h deleted file mode 100644 index a447d49fb..000000000 --- a/libkdepim/progressmanager.h +++ /dev/null @@ -1,438 +0,0 @@ -/* - progressmanager.h - - This file is part of KDEPIM. - - Author: Till Adam (C) 2004 - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __KPIM_PROGRESSMANAGER_H__ -#define __KPIM_PROGRESSMANAGER_H__ - -#include -#include -#include - -#include - -namespace KPIM { - -class ProgressItem; -class ProgressManager; -typedef TQMap ProgressItemMap; - -class KDE_EXPORT ProgressItem : public TQObject -{ - Q_OBJECT - TQ_OBJECT - friend class ProgressManager; - friend class TQDict< ProgressItem >; // so it can be deleted from dicts - - public: - - /** - * @return The id string which uniquely identifies the operation - * represented by this item. - */ - const TQString& id() const { return mId; } - - /** - * @return The parent item of this one, if there is one. - */ - ProgressItem *parent() const { return mParent; } - - /** - * @return The user visible string to be used to represent this item. - */ - const TQString& label() const { return mLabel; } - - /** - * @param v Set the user visible string identifying this item. @p v will - be interpreted as rich text, so it might have to be escaped. - */ - void setLabel( const TQString& v ); - - /** - * @return The string to be used for showing this item's current status. - */ - const TQString& status() const { return mtqStatus; } - /** - * Set the string to be used for showing this item's current status. - * @p v will be interpreted as rich text, so it might have to be escaped. - * @param v The status string. - */ - void setqStatus( const TQString& v ); - - /** - * @return Whether this item can be cancelled. - */ - bool canBeCanceled() const { return mCanBeCanceled; } - - /** - * @return Whether this item uses secure communication - * (Account uses ssl, for example.). - */ - bool usesCrypto() const { return mUsesCrypto; } - - /** - * Set whether this item uses crypted communication, so listeners - * can display a nice crypto icon. - * @param v The value. - */ - void setUsesCrypto( bool v ); - - /** - * @return whether this item uses a busy indicator instead of real progress display - */ - bool usesBusyIndicator() const { return mUsesBusyIndicator; } - - /** - * Sets whether this item uses a busy indicator instead of real progress for its progress bar. - * If it uses a busy indicator, you are still responsible for calling setProgress() from time to - * time to update the busy indicator. - */ - void setUsesBusyIndicator( bool useBusyIndicator ); - - /** - * @return The current progress value of this item in percent. - */ - unsigned int progress() const { return mProgress; } - - /** - * Set the progress (percentage of completion) value of this item. - * @param v The percentage value. - */ - void setProgress( unsigned int v ); - - /** - * Tell the item it has finished. This will emit progressItemCompleted() - * result in the destruction of the item after all slots connected to this - * signal have executed. This is the only way to get rid of an item and - * needs to be called even if the item is cancelled. Don't use the item - * after this has been called on it. - */ - void setComplete(); - - /** - * Reset the progress value of this item to 0 and the status string to - * the empty string. - */ - void reset() { setProgress( 0 ); setqStatus( TQString() ); mCompleted = 0; } - - void cancel(); - - // Often needed values for calculating progress. - void setTotalItems( unsigned int v ) { mTotal = v; } - unsigned int totalItems() const { return mTotal; } - void setCompletedItems( unsigned int v ) { mCompleted = v; } - void incCompletedItems( unsigned int v = 1 ) { mCompleted += v; } - unsigned int completedItems() const { return mCompleted; } - - /** - * Recalculate progress according to total/completed items and update. - */ - void updateProgress() { setProgress( mTotal? mCompleted*100/mTotal: 0 ); } - - void addChild( ProgressItem *kiddo ); - void removeChild( ProgressItem *kiddo ); - - bool canceled() const { return mCanceled; } - -signals: - /** - * Emitted when a new ProgressItem is added. - * @param The ProgressItem that was added. - */ - void progressItemAdded( KPIM::ProgressItem* ); - /** - * Emitted when the progress value of an item changes. - * @param The item which got a new value. - * @param The value, for convenience. - */ - void progressItemProgress( KPIM::ProgressItem*, unsigned int ); - /** - * Emitted when a progress item was completed. The item will be - * deleted afterwards, so slots connected to this are the last - * chance to work with this item. - * @param The completed item. - */ - void progressItemCompleted( KPIM::ProgressItem* ); - /** - * Emitted when an item was cancelled. It will _not_ go away immediately, - * only when the owner sets it complete, which will usually happen. Can be - * used to visually indicate the cancelled status of an item. Should be used - * by the owner of the item to make sure it is set completed even if it is - * cancelled. There is a ProgressManager::slotStandardCancelHandler which - * simply sets the item completed and can be used if no other work needs to - * be done on cancel. - * @param The canceled item; - */ - void progressItemCanceled( KPIM::ProgressItem* ); - /** - * Emitted when the status message of an item changed. Should be used by - * progress dialogs to update the status message for an item. - * @param The updated item. - * @param The new message. - */ - void progressItemtqStatus( KPIM::ProgressItem*, const TQString& ); - /** - * Emitted when the label of an item changed. Should be used by - * progress dialogs to update the label of an item. - * @param The updated item. - * @param The new label. - */ - void progressItemLabel( KPIM::ProgressItem*, const TQString& ); - /** - * Emitted when the crypto status of an item changed. Should be used by - * progress dialogs to update the crypto indicator of an item. - * @param The updated item. - * @param The new state. - */ - void progressItemUsesCrypto( KPIM::ProgressItem*, bool ); - - /** - * Emitted when the busy indicator state of an item changes. Should be used - * by progress dialogs so that they can adjust the display of the progress bar - * to the new mode. - * @param item The updated item - * @param value True if the item uses a busy indicator now, false otherwise - */ - void progressItemUsesBusyIndicator( KPIM::ProgressItem *item, bool value ); - - - protected: - /* Only to be used by our good friend the ProgressManager */ - ProgressItem( ProgressItem* parent, - const TQString& id, - const TQString& label, - const TQString& status, - bool isCancellable, - bool usesCrypto ); - virtual ~ProgressItem(); - - - private: - TQString mId; - TQString mLabel; - TQString mtqStatus; - ProgressItem* mParent; - bool mCanBeCanceled; - unsigned int mProgress; - ProgressItemMap mChildren; - unsigned int mTotal; - unsigned int mCompleted; - bool mWaitingForKids; - bool mCanceled; - bool mUsesCrypto; - bool mUsesBusyIndicator; -}; - -/** - * The ProgressManager singleton keeps track of all ongoing transactions - * and notifies observers (progress dialogs) when their progress percent value - * changes, when they are completed (by their owner), and when they are canceled. - * Each ProgressItem emits those signals individually and the singleton - * broadcasts them. Use the ::createProgressItem() statics to acquire an item - * and then call ->setProgress( int percent ) on it everytime you want to update - * the item and ->setComplete() when the operation is done. This will delete the - * item. Connect to the item's progressItemCanceled() signal to be notified when - * the user cancels the transaction using one of the observing progress dialogs - * or by calling item->cancel() in some other way. The owner is responsible for - * calling setComplete() on the item, even if it is canceled. Use the - * standardCancelHandler() slot if that is all you want to do on cancel. - * - * Note that if you request an item with a certain id and there is already - * one with that id, there will not be a new one created but the existing - * one will be returned. This is convenient for accessing items that are - * needed regularly without the to store a pointer to them or to add child - * items to parents by id. - */ - -class KDE_EXPORT ProgressManager : public TQObject -{ - - Q_OBJECT - TQ_OBJECT - - public: - virtual ~ProgressManager(); - - /** - * @return The singleton instance of this class. - */ - static ProgressManager * instance(); - - /** - * Use this to aquire a unique id number which can be used to discern - * an operation from all others going on at the same time. Use that - * number as the id string for your progressItem to ensure it is unique. - * @return - */ - static TQString getUniqueID() { return TQString::number( ++uID ); } - - /** - * Creates a ProgressItem with a unique id and the given label. - * This is the simplest way to aquire a progress item. It will not - * have a parent and will be set to be cancellable and not using crypto. - * - * @param label The text to be displayed by progress handlers. It will be - * interpreted as rich text, so it might have to be escaped. - */ - static ProgressItem * createProgressItem( const TQString &label ) { - return instance()->createProgressItemImpl( 0, getUniqueID(), label, - TQString(), true, false ); - } - - /** - * Creates a new progressItem with the given parent, id, label and initial - * status. - * - * @param parent Specify an already existing item as the parent of this one. - * @param id Used to identify this operation for cancel and progress info. - * @param label The text to be displayed by progress handlers. It will be - * interpreted as rich text, so it might have to be escaped. - * @param status Additional text to be displayed for the item. It will be - * interpreted as rich text, so it might have to be escaped. - * @param canBeCanceled can the user cancel this operation? - * @param usesCrypto does the operation use secure transports (SSL) - * Cancelling the parent will cancel the tqchildren as well (if they can be - * cancelled) and ongoing tqchildren prevent parents from finishing. - * @return The ProgressItem representing the operation. - */ - static ProgressItem * createProgressItem( ProgressItem* parent, - const TQString& id, - const TQString& label, - const TQString& status = TQString(), - bool canBeCanceled = true, - bool usesCrypto = false ) { - return instance()->createProgressItemImpl( parent, id, label, status, - canBeCanceled, usesCrypto ); - } - - /** - * Use this version if you have the id string of the parent and want to - * add a subjob to it. - */ - static ProgressItem * createProgressItem( const TQString& parent, - const TQString& id, - const TQString& label, - const TQString& status = TQString(), - bool canBeCanceled = true, - bool usesCrypto = false ) { - return instance()->createProgressItemImpl( parent, id, label, - status, canBeCanceled, usesCrypto ); - } - - /** - * Version without a parent. - */ - static ProgressItem * createProgressItem( const TQString& id, - const TQString& label, - const TQString& status = TQString(), - bool canBeCanceled = true, - bool usesCrypto = false ) { - return instance()->createProgressItemImpl( 0, id, label, status, - canBeCanceled, usesCrypto ); - } - - - /** - * @return true when there is no more progress item - */ - bool isEmpty() const { return mTransactions.isEmpty(); } - - /** - * @return the only top level progressitem when there's only one. - * Returns 0 if there is no item, or more than one top level item. - * Since this is used to calculate the overall progress, it will also return - * 0 if there is an item which uses a busy indicator, since that will tqinvalidate - * the overall progress. - */ - ProgressItem* singleItem() const; - - /** - * Ask all listeners to show the progress dialog, because there is - * something that wants to be shown. - */ - static void emitShowProgressDialog() { - instance()->emitShowProgressDialogImpl(); - } - - signals: - /** @see ProgressItem::progressItemAdded() */ - void progressItemAdded( KPIM::ProgressItem* ); - /** @see ProgressItem::progressItemProgress() */ - void progressItemProgress( KPIM::ProgressItem*, unsigned int ); - /** @see ProgressItem::progressItemCompleted() */ - void progressItemCompleted( KPIM::ProgressItem* ); - /** @see ProgressItem::progressItemCanceled() */ - void progressItemCanceled( KPIM::ProgressItem* ); - /** @see ProgressItem::progressItemtqStatus() */ - void progressItemtqStatus( KPIM::ProgressItem*, const TQString& ); - /** @see ProgressItem::progressItemLabel() */ - void progressItemLabel( KPIM::ProgressItem*, const TQString& ); - /** @see ProgressItem::progressItemUsesCrypto() */ - void progressItemUsesCrypto( KPIM::ProgressItem*, bool ); - /** @see ProgressItem::progressItemUsesBusyIndicator */ - void progressItemUsesBusyIndicator( KPIM::ProgressItem*, bool ); - - /** - * Emitted when an operation requests the listeners to be shown. - * Use emitShowProgressDialog() to trigger it. - */ - void showProgressDialog(); - public slots: - - /** - * Calls setCompleted() on the item, to make sure it goes away. - * Provided for convenience. - * @param item the canceled item. - */ - void slotStandardCancelHandler( KPIM::ProgressItem* item ); - - /** - * Aborts all running jobs. Bound to "Esc" - */ - void slotAbortAll(); - - private slots: - void slotTransactionCompleted( KPIM::ProgressItem *item ); - - private: - ProgressManager(); - // prevent unsolicited copies - ProgressManager( const ProgressManager& ); - - virtual ProgressItem* createProgressItemImpl( - ProgressItem* parent, const TQString& id, - const TQString& label, const TQString& status, - bool cancellable, bool usesCrypto ); - virtual ProgressItem* createProgressItemImpl( - const TQString& parent, const TQString& id, - const TQString& label, const TQString& status, - bool cancellable, bool usesCrypto ); - void emitShowProgressDialogImpl(); - - TQDict< ProgressItem > mTransactions; - static ProgressManager *mInstance; - static unsigned int uID; -}; - -} - -#endif // __KPIM_PROGRESSMANAGER_H__ diff --git a/libkdepim/qutf7codec.cpp b/libkdepim/qutf7codec.cpp deleted file mode 100644 index dc8ef2a2f..000000000 --- a/libkdepim/qutf7codec.cpp +++ /dev/null @@ -1,550 +0,0 @@ -/* - qutf7codec.cpp - - A TQTextCodec for UTF-7 (rfc2152). - Copyright (c) 2001 Marc Mutz - See file COPYING for details - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - 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, US - - As a special exception, permission is granted to use this plugin - with any version of TQt by TrollTech AS, Norway. In this case, the - use of this plugin doesn't cause the resulting executable to be - covered by the GNU General Public License. - This exception does not however tqinvalidate any other reasons why the - executable file might be covered by the GNU General Public License. -*/ - - -#include "qutf7codec.h" - -#ifndef TQT_NO_TEXTCODEC - -int TQUtf7Codec::mibEnum() const { - return 1012; -} - -int TQStrictUtf7Codec::mibEnum() const { - return -1012; -} - -const char* TQUtf7Codec::name() const { - return "UTF-7"; -} - -const char* TQStrictUtf7Codec::name() const { - return "X-QT-UTF-7-STRICT"; -} - -const char* TQUtf7Codec::mimeName() const { - return "UTF-7"; -} - -bool TQUtf7Codec::canEncode( TQChar ) const { - return TRUE; -} - -bool TQUtf7Codec::canEncode( const TQString & ) const { - return TRUE; -} - -static uchar base64Set[] = { - 0x00, 0x00, 0x00, 0x00, // '\0' ... - 0x00, 0x11, 0xFF, 0xC0, // ' ' ... '?' - 0x7F, 0xFF, 0xFF, 0xE0, // '@' ... '_' - 0x7F, 0xFF, 0xFF, 0xE0 // '`' ... DEL -}; - -static uchar base64SetWithLastTwoBitsZero[] = { - 0x00, 0x00, 0x00, 0x00, // '\0' ... - 0x00, 0x00, 0x88, 0x80, // ' ' ... '?' - 0x44, 0x44, 0x44, 0x40, // '@' ... '_' - 0x11, 0x11, 0x11, 0x00 // '`' ... DEL -}; - -static uchar directSet[] = { - 0x00, 0x00, 0x00, 0x00, // '\0' ... - 0x01, 0xCF, 0xFF, 0xE1, // ' ' ... '?' - 0x7F, 0xFF, 0xFF, 0xE0, // '@' ... '_' - 0x7F, 0xFF, 0xFF, 0xE0 // '`' ... DEL -}; - -static uchar optDirectSet[] = { - 0x00, 0x00, 0x00, 0x00, // '\0' ... - 0x7E, 0x20, 0x00, 0x1E, // ' ' ... '?' - 0x80, 0x00, 0x00, 0x17, // '@' ... '_' - 0x80, 0x00, 0x00, 0x1C // '`' ... DEL -}; - -static inline bool isOfSet(uchar ch, uchar* set) { - return set[ ch/8 ] & (0x80 >> ( ch%8 )); -} - -int TQUtf7Codec::heuristicContentMatch(const char* chars, int len) const -{ - int stepNo = 0; - int i; - bool shifted = FALSE; - bool rightAfterEscape = FALSE; - bool onlyNullBitsSinceLastBoundary = TRUE; - for ( i = 0; i < len ; i++ ) { - if ((unsigned char)chars[i] >= 128) // 8bit chars not allowed. - break; - if (shifted) { - if ( isOfSet(chars[i],base64Set) ) { - switch (stepNo) { - case 0: - onlyNullBitsSinceLastBoundary = TRUE; - break; - case 3: - onlyNullBitsSinceLastBoundary - = isOfSet(chars[i],base64SetWithLastTwoBitsZero); - break; - case 6: - onlyNullBitsSinceLastBoundary - = ( chars[i] == 'A' || chars[i] == 'Q' || - chars[i] == 'g' || chars[i] == 'w' ); - break; - default: - onlyNullBitsSinceLastBoundary - = onlyNullBitsSinceLastBoundary && (chars[i] == 'A'); - } - stepNo = (stepNo + 1) % 8; - rightAfterEscape = FALSE; - } else { - if (rightAfterEscape && chars[i] != '-') - break; // a '+' must be followed by '-' or a base64 char - if (!onlyNullBitsSinceLastBoundary) - break; // non-zero bits in the tail of the base64 encoding - shifted = FALSE; - stepNo = 0; - } - } else { - if (chars[i] == '+') { - shifted = TRUE; - rightAfterEscape = TRUE; - } - } - } - return i; -} - -class TQUtf7Decoder : public TQTextDecoder { - // the storage for our tqunicode char until it's finished - ushort uc; - // the state of the base64 decoding - // can be 0 (just finished three tqunicode chars) - // 1 (have the upper 6 bits of uc already) - // 2 (have the upper 12 bits of uc already) - // 3 (have the upper 2 bits of uc already) - // .......... - // 7 (have the upper 10 bits of uc already) - // => n (have the upper (n * 6) % 16 bits of uc already) - // "stepNo" cycles through all it's values every three - // tqunicode chars. - char stepNo; - // remembers if we are in shifted-sequence mode - bool shifted; - // remembers if we're just after the initial '+' - // of a shifted-sequence. - bool rightAfterEscape; -public: - TQUtf7Decoder() : uc(0), stepNo(0), shifted(FALSE), rightAfterEscape(FALSE) - { - } - -private: - inline void resetParser() - { - uc = 0; - stepNo = 0; - shifted = FALSE; - rightAfterEscape = FALSE; - } - -public: - TQString toUnicode(const char* chars, int len) - { - TQString result = ""; - for (int i=0; i 127 ) { - qWarning("TQUtf7Decoder: 8bit char found in input. " - "Parser has been re-initialized!"); - resetParser(); - result += TQChar::replacement; - continue; - } - - if (shifted) { // in shifted mode - - // - // first, we check specialities that only occur - // right after the escaping '+': - // - if ( rightAfterEscape && ch == '-' ) { - // a "+-" sequence is a short-circuit encoding - // for just '+': - resetParser(); - result += TQChar('+'); - // we're already done for this "ch", so - continue; - } - - // - // Here we're going to extract the bits represented by "ch": - // - ushort bits; - if ( ch >= 'A' && ch <= 'Z' ) { - bits = ch - 'A'; - } else if ( ch >= 'a' && ch <= 'z' ) { - bits = ch - 'a' + 26; - } else if ( ch >= '0' && ch <= '9' ) { - bits = ch - '0' + 52; - } else if ( ch == '+' ) { - bits = 62; - } else if ( ch == '/' ) { - bits = 63; - } else { - bits = 0; // keep compiler happy - - // - // ch is not of the base64 alphabet. - // Here we are going to check the sequence's validity: - // - if ( rightAfterEscape ) { - // any non-base64 char following an escaping '+' - // makes for an ill-formed sequence. - // Note that we catch (the valid) "+-" pair - // right at the beginning. - qWarning("TQUtf7Decoder: ill-formed input: " - "non-base64 char after escaping \"+\"!"); - } - // pending bits from base64 encoding must be all 0: - if (stepNo >= 1 && uc) { - qWarning("TQUtf7Decoder: ill-formed sequence: " - "non-zero bits in shifted-sequence tail!"); - } - resetParser(); - - // a '-' signifies the end of the shifted-sequence, - // so we just swallow it. - if ( ch == '-' ) - continue; - // end of validity checking. Process ch now... - } - - if ( /*still*/ shifted ) { - // - // now we're going to stuff the "bits" bit bucket into - // the right position inside "uc", emitting a resulting - // TQChar if possible. - // - switch (stepNo) { - // "bits" are the 6 msb's of uc - case 0: uc = bits << 10; break; - - case 1: uc |= bits << 4; break; - - // 4 bits of "bits" complete the first ushort - case 2: uc |= bits >> 2; result += TQChar(uc); - // 2 bits of "bits" make the msb's of the next ushort - uc = bits << 14; break; - case 3: uc |= bits << 8; break; - case 4: uc |= bits << 2; break; - - // 2 bits of "bits" complete the second ushort - case 5: uc |= bits >> 4; result += TQChar(uc); - // 4 bits of "bits" make the msb's of the next ushort - uc = bits << 12; break; - case 6: uc |= bits << 6; break; - - // these 6 bits complete the third ushort - // and also one round of 8 chars -> 3 ushort decoding - case 7: uc |= bits; result += TQChar(uc); - uc = 0; break; - default: ; - } // switch (stepNo) - // increase the step counter - stepNo++; - stepNo %= 8; - rightAfterEscape = FALSE; - // and look at the next char. - continue; - } // fi (still) shifted - } // fi shifted - - // - // if control reaches here, we either weren't in a - // shifted sequence or we just left one by seeing - // a non-base64-char. - // Either way, we have to process "ch" outside - // a shifted-sequence now: - // - if ( ch == '+' ) { - // '+' is the escape char for entering a - // shifted sequence: - shifted = TRUE; - stepNo = 0; - // also, we're right at the beginning where - // special rules apply: - rightAfterEscape = TRUE; - } else { - // US-ASCII values are directly used - result += TQChar(ch); - } - } - - return result; - - } // toUnicode() - -}; // class TQUtf7Decoder - -TQTextDecoder* TQUtf7Codec::makeDecoder() const -{ - return new TQUtf7Decoder; -} - - -class TQUtf7Encoder : public TQTextEncoder { - uchar dontNeedEncodingSet[16]; - ushort outbits; - uint stepNo : 2; - bool shifted : 1; - bool mayContinueShiftedSequence : 1; -public: - TQUtf7Encoder(bool encOpt, bool encLwsp) - : outbits(0), stepNo(0), - shifted(FALSE), mayContinueShiftedSequence(FALSE) - { - for ( int i = 0; i < 16 ; i++) { - dontNeedEncodingSet[i] = directSet[i]; - if (!encOpt) - dontNeedEncodingSet[i] |= optDirectSet[i]; - } - if(!encLwsp) { - dontNeedEncodingSet[' '/8] |= 0x80 >> (' '%8); - dontNeedEncodingSet['\n'/8] |= 0x80 >> ('\n'%8); - dontNeedEncodingSet['\r'/8] |= 0x80 >> ('\r'%8); - dontNeedEncodingSet['\t'/8] |= 0x80 >> ('\t'%8); - } - } - -private: - - char toBase64( ushort u ) { - if ( u < 26 ) - return (char)u + 'A'; - else if ( u < 52 ) - return (char)u - 26 + 'a'; - else if ( u < 62 ) - return (char)u - 52 + '0'; - else if ( u == 62 ) - return '+'; - else - return '/'; - } - - void addToShiftedSequence(TQCString::Iterator & t, ushort u) { - switch (stepNo) { - // no outbits; use uppermost 6 bits of u - case 0: - *t++ = toBase64( u >> 10 ); - *t++ = toBase64( (u & 0x03FF /* umask top 6 bits */ ) >> 4 ); - // save 4 lowest-order bits in outbits[5..2] - outbits = (u & 0x000F) << 2; - break; - - // outbits available; use top two bits of u to complete - // the previous char - case 1: - if (!mayContinueShiftedSequence) { - // if mayContinue, this char has already been written - *t++ = toBase64( outbits | ( u >> 14 ) ); - } - *t++ = toBase64( (u & 0x3F00 /* mask top 2 bits */ ) >> 8 ); - *t++ = toBase64( (u & 0x00FC /* mask msbyte */ ) >> 2 ); - // save 2 lowest-significant bits in outbits[5..4] - outbits = (u & 0x0003) << 4; - break; - - // outbits available; use top four bits of u to complete - // the previous char - case 2: - if (!mayContinueShiftedSequence) { - // if mayContinue, this char has already been written - *t++ = toBase64( outbits | ( u >> 12 ) ); - } - *t++ = toBase64( (u & 0x0FFF) >> 6 ); - *t++ = toBase64( u & 0x003F ); - break; - - default: ; - } - stepNo = (stepNo + 1) % 3; - } - - void endShiftedSequence(TQCString::Iterator & t) { - switch (stepNo) { - case 1: // four outbits still to be written - case 2: // two outbits still to be written - *t++ = toBase64( outbits ); - break; - case 0: // nothing to do - default: ; - } - outbits = 0; - } - - // depending on the stepNo, checks whether we can continue - // an already ended shifted-sequence with char "u". - // This is only possible if the topmost bits fit the - // already written ones (which are all 0 between calls) - bool continueOK( ushort u ) { - return stepNo == 0 || - ( stepNo == 1 && (u & 0xF000) == 0 ) || - ( stepNo == 2 && (u & 0xC000) == 0 ); - } - - void processDoesntNeedEncoding(TQCString::Iterator & t, ushort ch) { - // doesn't need encoding - if (shifted) { - endShiftedSequence(t); - // add "lead-out" to dis-ambiguate following chars: - if (isOfSet((char)ch,base64Set) || ch == '-' ) { - *t++ = '-'; - } - } else if (mayContinueShiftedSequence) { - // if mayContinue is set, this means the - // shifted-sequence needs a lead-out. - mayContinueShiftedSequence = FALSE; - if (isOfSet(ch,base64Set) || ch == '-' ) { - *t++ = '-'; - } - } - *t++ = (uchar)ch; - shifted = FALSE; - stepNo = 0; - } - -public: - TQCString fromUnicode(const TQString & uc, int & len_in_out) - { - // allocate place for worst case: - // len/2 * (5+1) for an alternating sequence of e.g. "A\", - // + 4 for a worst-case of another +ABC encoded char - // + 1 for the trailing \0 - // - int maxreslen = 3 * len_in_out + 5; - TQCString result( maxreslen ); - -#if 0 - // if (len_in_out == 1) { - cout << "\nlen_in_out: " << len_in_out - <<"; shifted: " << (shifted ? "true" : "false") - << ";\n" << "mayContinue: " - << (mayContinueShiftedSequence ? "true" : "false") - << "; stepNo: " << stepNo << ";\n" - << "outbits: " << outbits << endl; - // } -#endif - - // source and destination cursor - const TQChar * s = uc.tqunicode(); - TQCString::Iterator t = result.data(); - - if ( uc.isNull() ) { - // return to ascii requested: - if ( mayContinueShiftedSequence ) - *t++ = '-'; - } else { - // normal operation: - for (int i = 0 ; i < len_in_out ; - i++/*, checkOutBuf(result,maxreslen,t,i,len_in_out,5)*/ ) { - ushort ch = s[i].tqunicode(); - - // - // first, we check whether we might get around encoding: - // - if ( ch < 128 ) { - // - // ch is usAscii, so we have a chance that we don't - // need to encode it. - // - if ( isOfSet((uchar)ch,dontNeedEncodingSet) ) { - processDoesntNeedEncoding(t,ch); - continue; - } else if ( ch == '+' ) { - // '+' is the shift escape character - if (shifted || mayContinueShiftedSequence) { - // if we are already in shifted mode, we just - // encode the '+', too. Compare - // 24bits ("-+-") + some from ending the shifted-sequence - // with 21,33 bits - addToShiftedSequence(t,ch); - mayContinueShiftedSequence = FALSE; - shifted = TRUE; - } else { - // shortcut encoding of '+': - *t++ = '+'; - *t++ = '-'; - } - continue; // done - } // else fall through to encoding - } - // - // need encoding - // - if (!shifted && (!mayContinueShiftedSequence || !continueOK(ch) ) ) { - *t++ = '+'; - stepNo = 0; - } - addToShiftedSequence(t,ch); - shifted = TRUE; - mayContinueShiftedSequence = FALSE; - } - - if ( shifted ) { - endShiftedSequence(t); - mayContinueShiftedSequence = TRUE; - }; - shifted = FALSE; - } - - *t = '\0'; - len_in_out = t - result.data(); - -#if 0 - cout << "len_in_out: " << len_in_out << "; " - << "mayContinue: " << (mayContinueShiftedSequence ? "true" : "false") - << "; stepNo: " << stepNo << endl; -#endif - - Q_ASSERT(len_in_out <= maxreslen-1); - - return result; - } // fromUnicode() - -}; // class TQUtf7Encoder - -TQTextEncoder* TQUtf7Codec::makeEncoder() const { - return new TQUtf7Encoder( false, false ); -} - -TQTextEncoder* TQStrictUtf7Codec::makeEncoder() const { - return new TQUtf7Encoder( true, false ); -} - -#endif // TQT_NO_TEXTCODEC diff --git a/libkdepim/qutf7codec.h b/libkdepim/qutf7codec.h deleted file mode 100644 index 4057d276c..000000000 --- a/libkdepim/qutf7codec.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - qutf7codec.h - - A TQTextCodec for UTF-7 (rfc2152). - Copyright (c) 2001 Marc Mutz - See file COPYING for details - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - 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, US - - As a special exception, permission is granted to use this plugin - with any version of TQt by TrollTech AS, Norway. In this case, the - use of this plugin doesn't cause the resulting executable to be - covered by the GNU General Public License. - This exception does not however tqinvalidate any other reasons why the - executable file might be covered by the GNU General Public License. -*/ - -#ifndef TQUTF7CODEC_H -#define TQUTF7CODEC_H - -#include "tqtextcodec.h" - -#include - -#ifndef TQT_NO_TEXTCODEC - -/** @short A TQTextCodec for the UTF-7 transformation of Unicode. - - This is a TQTextCodec for the UTF-7 transformation of Unicode, - described in RFC2152. - - Use it as you would use any other TQTextCodec. Only if you use the - encoder directly (via makeEncoder), you should bear in mind - that if your application needs the encoder to return to ASCII mode - (like it's the case for RFC2047 mail header encoded words), you - have to tell the encoder by requesting the encoding of a @em null - TQString. - - @author Marc Mutz */ - -class KDE_EXPORT TQUtf7Codec : public TQTextCodec { - bool encOpt, encLwsp; -public: - TQUtf7Codec() : TQTextCodec() {} - - int mibEnum() const; - const char* name() const; - const char* mimeName() const; - - TQTextDecoder* makeDecoder() const; - TQTextEncoder* makeEncoder() const; - - bool canEncode( TQChar ) const; - bool canEncode( const TQString& ) const; - - int heuristicContentMatch( const char* chars, int len ) const; -}; - -/** This is a version of @ref TQUtf7Codec, which should only be used in - MIME transfer. It differs from @ref TQUtf7Codec only in that the - encoder escapes additional characters (the RFC2152 "optional - direct set"), which might not be allowed in RFC822/RFC2047 header - fields. - - You should only use this codec for @em encoding, since it's output - is pure UTF-7 and can equally well be decoded by @ref TQUtf7Codec's - decoder. - - To distinguish between the two variants, this class has MIB enum - -1012 (the nagative of UTF-7) and the somewhat awkward name - "X-QT-UTF-7-STRICT". The MIME preferred charset name is still - "UTF-7", though. - - @short A variant of @ref TQUtf7Codec, which protectes certain - characters in MIME transport - @author Marc Mutz */ -class KDE_EXPORT TQStrictUtf7Codec : public TQUtf7Codec { -public: - TQStrictUtf7Codec() : TQUtf7Codec() {} - - const char* name() const; - int mibEnum() const; - - TQTextEncoder* makeEncoder() const; -}; - -#endif // TQT_NO_TEXTCODEC - -#endif // TQUTF7CODEC_H diff --git a/libkdepim/qutf7codecplugin.cpp b/libkdepim/qutf7codecplugin.cpp deleted file mode 100644 index 49eb92c8f..000000000 --- a/libkdepim/qutf7codecplugin.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - qutf7codecplugin.cpp - - A TQTextCodec for UTF-7 (rfc2152). - Copyright (c) 2001 Marc Mutz - See file COPYING for details - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - 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, US - - As a special exception, permission is granted to use this plugin - with any version of TQt by TrollTech AS, Norway. In this case, the - use of this plugin doesn't cause the resulting executable to be - covered by the GNU General Public License. - This exception does not however tqinvalidate any other reasons why the - executable file might be covered by the GNU General Public License. -*/ - -#include "qutf7codec.h" - -#include -#include -#include -#include - -class TQTextCodec; - -// ######### This file isn't compiled currently - -class TQUtf7CodecPlugin : public TQTextCodecPlugin { -public: - TQUtf7CodecPlugin() {} - - TQStringList names() const { return TQStringList() << "UTF-7" << "X-QT-UTF-7-STRICT"; } - TQValueList mibEnums() const { return TQValueList() << 1012 << -1012; } - TQTextCodec * createForMib( int ); - TQTextCodec * createForName( const TQString & ); -}; - -TQTextCodec * TQUtf7CodecPlugin::createForMib( int mib ) { - if ( mib == 1012 ) - return new TQUtf7Codec(); - else if ( mib == -1012 ) - return new TQStrictUtf7Codec(); - return 0; -} - -TQTextCodec * TQUtf7CodecPlugin::createForName( const TQString & name ) { - if ( name == "UTF-7" ) - return new TQUtf7Codec(); - else if ( name == "X-QT-UTF-7-STRICT" ) - return new TQStrictUtf7Codec(); - return 0; -} - -KDE_TQ_EXPORT_PLUGIN( TQUtf7CodecPlugin ); diff --git a/libkdepim/recentaddresses.cpp b/libkdepim/recentaddresses.cpp deleted file mode 100644 index ac790693d..000000000 --- a/libkdepim/recentaddresses.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* -*- mode: C++; c-file-style: "gnu" -*- - * - * Copyright (c) 2001-2003 Carsten Pfeiffer - * Copyright (c) 2003 Zack Rusin - * - * KMail is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation. - * - * KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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 "recentaddresses.h" -#include "libemailfunctions/email.h" - -#include -#include -#include - -#include -#include -#include - - -#include - -using namespace KRecentAddress; - -static KStaticDeleter sd; - -RecentAddresses * RecentAddresses::s_self = 0; - -RecentAddresses * RecentAddresses::self( KConfig *config) -{ - if ( !s_self ) - sd.setObject( s_self, new RecentAddresses(config) ); - return s_self; -} - -RecentAddresses::RecentAddresses(KConfig * config) -{ - if ( !config ) - load( KGlobal::config() ); - else - load( config ); -} - -RecentAddresses::~RecentAddresses() -{ - // if you want this destructor to get called, use a KStaticDeleter - // on s_self -} - -void RecentAddresses::load( KConfig *config ) -{ - TQStringList addresses; - TQString name; - TQString email; - - m_addresseeList.clear(); - KConfigGroupSaver cs( config, "General" ); - m_maxCount = config->readNumEntry( "Maximum Recent Addresses", 40 ); - addresses = config->readListEntry( "Recent Addresses" ); - for ( TQStringList::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { - KABC::Addressee::parseEmailAddress( *it, name, email ); - if ( !email.isEmpty() ) { - KABC::Addressee addr; - addr.setNameFromString( name ); - addr.insertEmail( email, true ); - m_addresseeList.append( addr ); - } - } - - adjustSize(); -} - -void RecentAddresses::save( KConfig *config ) -{ - KConfigGroupSaver cs( config, "General" ); - config->writeEntry( "Recent Addresses", addresses() ); -} - -void RecentAddresses::add( const TQString& entry ) -{ - if ( !entry.isEmpty() && m_maxCount > 0 ) { - TQStringList list = KPIM::splitEmailAddrList( entry ); - for( TQStringList::const_iterator e_it = list.begin(); e_it != list.end(); ++e_it ) { - KPIM::EmailParseResult errorCode = KPIM::isValidEmailAddress( *e_it ); - if ( errorCode != KPIM::AddressOk ) - continue; - TQString email; - TQString fullName; - KABC::Addressee addr; - - KABC::Addressee::parseEmailAddress( *e_it, fullName, email ); - - for ( KABC::Addressee::List::Iterator it = m_addresseeList.begin(); - it != m_addresseeList.end(); ++it ) - { - if ( email == (*it).preferredEmail() ) { - //already inside, remove it here and add it later at pos==1 - m_addresseeList.remove( it ); - break; - } - } - addr.setNameFromString( fullName ); - addr.insertEmail( email, true ); - m_addresseeList.prepend( addr ); - adjustSize(); - } - } -} - -void RecentAddresses::setMaxCount( int count ) -{ - m_maxCount = count; - adjustSize(); -} - -void RecentAddresses::adjustSize() -{ - while ( m_addresseeList.count() > m_maxCount ) - m_addresseeList.remove( m_addresseeList.fromLast() ); -} - -void RecentAddresses::clear() -{ - m_addresseeList.clear(); - adjustSize(); -} - -TQStringList RecentAddresses::addresses() const -{ - TQStringList addresses; - for ( KABC::Addressee::List::ConstIterator it = m_addresseeList.begin(); - it != m_addresseeList.end(); ++it ) - { - addresses.append( (*it).fullEmail() ); - } - return addresses; -} - -RecentAddressDialog::RecentAddressDialog( TQWidget *parent, const char *name ) - : KDialogBase( Plain, i18n( "Edit Recent Addresses" ), Ok | Cancel, Ok, - parent, name, true ) -{ - TQWidget *page = plainPage(); - TQVBoxLayout *tqlayout = new TQVBoxLayout( page, 0, spacingHint() ); - - mEditor = new KEditListBox( i18n( "Recent Addresses" ), page, "", false, - KEditListBox::Add | KEditListBox::Remove ); - tqlayout->addWidget( mEditor ); -} - -void RecentAddressDialog::setAddresses( const TQStringList &addrs ) -{ - mEditor->clear(); - mEditor->insertStringList( addrs ); -} - -TQStringList RecentAddressDialog::addresses() const -{ - return mEditor->items(); -} diff --git a/libkdepim/recentaddresses.h b/libkdepim/recentaddresses.h deleted file mode 100644 index 446f6c684..000000000 --- a/libkdepim/recentaddresses.h +++ /dev/null @@ -1,132 +0,0 @@ -/* -*- mode: C++; c-file-style: "gnu" -*- - * - * Copyright (c) 2001-2003 Carsten Pfeiffer - * Copyright (c) 2003 Zack Rusin - * - * KMail is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation. - * - * KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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 RECENTADDRESSES_H -#define RECENTADDRESSES_H - -#include -#include - -#include - -#include - -class KConfig; -class KEditListBox; -namespace KRecentAddress { - -class KDE_EXPORT RecentAddressDialog : public KDialogBase -{ - public: - RecentAddressDialog( TQWidget *parent, const char *name = 0 ); - void setAddresses( const TQStringList &addrs ); - TQStringList addresses() const; - private: - KEditListBox *mEditor; -}; - -/** - * Handles a list of "recent email-addresses". Simply set a max-count and - * call @ref add() to add entries. - * - * @author Carsten Pfeiffer - */ - -class KDE_EXPORT RecentAddresses -{ -public: - ~RecentAddresses(); - /** - * @returns the only possible instance of this class. - */ - static RecentAddresses * self(KConfig *config = 0L); - - /* - * @return true if self() was called, i.e. a RecentAddresses instance exists - */ - static bool exists() { return s_self != 0; } - - /** - * @returns the list of recent addresses. - * Note: an entry doesn't have to be one email address, it can be multiple, - * like "Foo , Bar Baz ". - */ - TQStringList addresses() const; - const KABC::Addressee::List& kabcAddresses() const { return m_addresseeList; } - - /** - * Adds an entry to the list. - * Note: an entry doesn't have to be one email address, it can be multiple, - * like "Foo , Bar Baz ". - */ - void add( const TQString& entry ); - - /** - * Sets the maximum number, the list can hold. The list adjusts to this - * size if necessary. Default maximum is 40. - */ - void setMaxCount( int count ); - - /** - * @returns the current maximum number of entries. - */ - uint maxCount() const { return m_maxCount; } - - /** - * Loads the list of recently used addresses from the configfile. - * Automatically done on startup. - */ - void load( KConfig * ); - - /** - * Saves the list of recently used addresses to the configfile. - * Make sure to call KGlobal::config()->sync() afterwards, to really save. - */ - void save( KConfig * ); - - /** - * Removes all entries from the history. - */ - void clear(); - -private: - RecentAddresses(KConfig *config = 0L); - - KABC::Addressee::List m_addresseeList; - - void adjustSize(); - - uint m_maxCount; - - static RecentAddresses *s_self; -}; - -} - -#endif // KMRECENTADDR_H diff --git a/libkdepim/resourceabc.cpp b/libkdepim/resourceabc.cpp deleted file mode 100644 index dbcc98f87..000000000 --- a/libkdepim/resourceabc.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - This file is part of libtdepim. - - 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. - - As a special exception, permission is given to link this program - with any edition of TQt, and distribute the resulting executable, - without including the source code for TQt in the source distribution. -*/ - -#include "resourceabc.h" - -using namespace KPIM; - -ResourceABC::ResourceABC( const KConfig* config ) - : KABC::Resource( config ) -{ -} - -ResourceABC::~ResourceABC() -{ -} - -#include "resourceabc.moc" diff --git a/libkdepim/resourceabc.h b/libkdepim/resourceabc.h deleted file mode 100644 index b6ef3ec98..000000000 --- a/libkdepim/resourceabc.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - This file is part of libtdepim. - - 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. - - As a special exception, permission is given to link this program - with any edition of TQt, and distribute the resulting executable, - without including the source code for TQt in the source distribution. -*/ - -#ifndef RESOURCEABC_H -#define RESOURCEABC_H - -#include -#include -#include - -// This is here because it can't go to kdelibs/kabc yet, but ultimately -// it should probably go there (maybe redesigned to have a real object -// for subresources). - -namespace KPIM { - -/** - * This class is the implementation of subfolder resources for KABC. - * More methods will be added to give KAddressBook the possibility to - * handle subresources. - */ - -class KDE_EXPORT ResourceABC : public KABC::Resource -{ - Q_OBJECT - TQ_OBJECT - -public: - ResourceABC( const KConfig* ); - virtual ~ResourceABC(); - - /** - * Get the UID to subresource map. This is necessary to implement - * the search order. - * The returned map has the UID as key and the resource it's in as - * the data. - */ - virtual TQMap uidToResourceMap() const = 0; - - /** - * If this resource has subresources, return a TQStringList of them. - * In most cases, resources do not have subresources, so this is - * by default just empty. - */ - virtual TQStringList subresources() const { return TQStringList(); } - - /** - * Is this subresource active or not? - */ - virtual bool subresourceActive( const TQString& ) const { return true; } - - /** - * Is the given subresource writable? - */ - virtual bool subresourceWritable( const TQString& ) const = 0; - - /** - * Completion weight for a given subresource - */ - virtual int subresourceCompletionWeight( const TQString& ) const = 0; - - /** - * Label for a given subresource - */ - virtual TQString subresourceLabel( const TQString& ) const = 0; - -public slots: - /** - * (De-)activate a subresource. - */ - virtual void setSubresourceActive( const TQString &, bool active ) = 0; - - /** - * Set completion weight for a given subresource - */ - virtual void setSubresourceCompletionWeight( const TQString&, int weight ) = 0; - -signals: - /** - * This signal is emitted when a subresource is added. - */ - void signalSubresourceAdded( KPIM::ResourceABC *, const TQString &type, - const TQString &subResource ); - - /** - * This signal is emitted when a subresource is removed. - */ - void signalSubresourceRemoved( KPIM::ResourceABC *, const TQString &type, - const TQString &subResource ); - -}; - -} - -#endif // RESOURCEABC_H diff --git a/libkdepim/sendsmsdialog.cpp b/libkdepim/sendsmsdialog.cpp deleted file mode 100644 index 218f9617d..000000000 --- a/libkdepim/sendsmsdialog.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2005 Con Hennessy - Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ -#include -#include -#include - -#include - -#include "sendsmsdialog.h" - -SendSMSDialog::SendSMSDialog( const TQString &recipientName, TQWidget *parent, const char *name ) - : KDialogBase( Plain, i18n( "Send SMS" ), Ok | Cancel, Ok, parent, name, true, true ) -{ - TQWidget *page = plainPage(); - - TQGridLayout *tqlayout = new TQGridLayout( page, 3, 3, marginHint(), spacingHint() ); - - tqlayout->addWidget( new TQLabel( i18n( "Message" ), page ), 0, 0 ); - - mMessageLength = new TQLabel( "0/160", page ); - mMessageLength->tqsetAlignment( TQt::AlignRight ); - tqlayout->addWidget( mMessageLength, 0, 2 ); - - mText = new TQTextEdit( page ); - tqlayout->addMultiCellWidget( mText, 1, 1, 0, 2 ); - - tqlayout->addWidget( new TQLabel( i18n( "Recipient:" ), page ), 2, 0 ); - tqlayout->addWidget( new TQLabel( recipientName, page ), 2, 2 ); - - setButtonText( Ok, i18n( "Send" ) ); - - connect( mText, TQT_SIGNAL( textChanged() ), - this, TQT_SLOT( updateMessageLength() ) ); - connect( mText, TQT_SIGNAL( textChanged() ), - this, TQT_SLOT( updateButtons() ) ); - - updateButtons(); - - mText->setFocus(); -} - -TQString SendSMSDialog::text() const -{ - return mText->text(); -} - -void SendSMSDialog::updateMessageLength() -{ - int length = mText->length(); - - if( length > 480 ) - mMessageLength->setText( TQString( "%1/%2 (%3)" ).tqarg( length ).tqarg( 500 ).tqarg( 4 ) ); - else if( length > 320 ) - mMessageLength->setText( TQString( "%1/%2 (%3)" ).tqarg( length ).tqarg( 480 ).tqarg( 3 ) ); - else if( length > 160 ) - mMessageLength->setText( TQString( "%1/%2 (%3)" ).tqarg( length ).tqarg( 320 ).tqarg( 2 ) ); - else - mMessageLength->setText( TQString( "%1/%2" ).tqarg( length ).tqarg( 160 ) ); -} - -void SendSMSDialog::updateButtons() -{ - enableButton( Ok, mText->length() > 0 ); -} - -#include "sendsmsdialog.moc" diff --git a/libkdepim/sendsmsdialog.h b/libkdepim/sendsmsdialog.h deleted file mode 100644 index af7a97e9b..000000000 --- a/libkdepim/sendsmsdialog.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2005 Con Hennessy - Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ -#ifndef SENDSMSDIALOG_H -#define SENDSMSDIALOG_H - -#include - -class TQLabel; -class TQTextEdit; - -class SendSMSDialog : public KDialogBase -{ - Q_OBJECT - TQ_OBJECT - - public: - SendSMSDialog( const TQString &recipientName, TQWidget *parent, const char *name = 0 ); - - TQString text() const; - - private slots: - void updateMessageLength(); - void updateButtons(); - - private: - TQLabel *mMessageLength; - TQTextEdit *mText; -}; - -#endif - diff --git a/libkdepim/sidebarextension.cpp b/libkdepim/sidebarextension.cpp deleted file mode 100644 index db49dc71f..000000000 --- a/libkdepim/sidebarextension.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2003 Daniel Molkentin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#include "sidebarextension.h" - -#include -#include - -using namespace KParts; - -SideBarExtension::SideBarExtension(TQWidget *exported, KParts::ReadOnlyPart *parent, const char* name) -: TQObject(parent, name), m_exported(exported), d(0) -{ -} - -SideBarExtension::~SideBarExtension() -{ -} - -#include "sidebarextension.moc" - -// vim: ts=2 sw=2 et diff --git a/libkdepim/sidebarextension.h b/libkdepim/sidebarextension.h deleted file mode 100644 index fc39ef6c6..000000000 --- a/libkdepim/sidebarextension.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (C) 2003 Daniel Molkentin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ -#ifndef SIDEBAREXTENSION_H -#define SIDEBAREXTENSION_H - -#include -#include - -class TQWidget; - -namespace KParts -{ - - class ReadOnlyPart; - - /** - * Provides a way to export a widget which will be displayed in Kontacts - * stackview at the left - **/ - class KDE_EXPORT SideBarExtension : public TQObject - { - Q_OBJECT - TQ_OBJECT - - public: - /** - * Constucts a SideBarExtension. - * - * @param exported A TQWidget derived widget that will be provided for the - * users of SideBarExtension. - * @param parent The parent widget. - * @param name The name of the class. - **/ - SideBarExtension(TQWidget *exported, KParts::ReadOnlyPart *parent, const char* name); - ~SideBarExtension(); - - /** - * Retrieve a pointer to the widget. May be 0 if 0 was passed in the constructor - **/ - TQWidget* widget() const { return m_exported; } - - private: - TQWidget* m_exported; - - class SideBarExtensionPrivate; - SideBarExtensionPrivate *d; - }; -} -#endif // SIDEBAREXTENSION_H - -// vim: ts=2 sw=2 et diff --git a/libkdepim/spellingfilter.cpp b/libkdepim/spellingfilter.cpp deleted file mode 100644 index cc94968d4..000000000 --- a/libkdepim/spellingfilter.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/** - * spellingfilter.cpp - * - * Copyright (c) 2002 Dave Corrie - * - * This file is part of KMail. - * - * KMail 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 "spellingfilter.h" - -//----------------------------------------------------------------------------- -// SpellingFilter implementation -// - -SpellingFilter::SpellingFilter(const TQString& text, const TQString& quotePrefix, - UrlFiltering filterUrls, EmailAddressFiltering filterEmailAddresses, - const TQStringList& filterStrings) - : mOriginal(text) -{ - TextCensor c(text); - - if(!quotePrefix.isEmpty()) - c.censorQuotations(quotePrefix); - - if(filterUrls) - c.censorUrls(); - - if(filterEmailAddresses) - c.censorEmailAddresses(); - - TQStringList::const_iterator iter = filterStrings.begin(); - while(iter != filterStrings.end()) - { - c.censorString(*iter); - ++iter; - } - - mFiltered = c.censoredText(); -} - -TQString SpellingFilter::originalText() const -{ - return mOriginal; -} - -TQString SpellingFilter::filteredText() const -{ - return mFiltered; -} - -//----------------------------------------------------------------------------- -// SpellingFilter::TextCensor implementation -// - -SpellingFilter::TextCensor::TextCensor(const TQString& s) - : LinkLocator(s) -{ - -} - -void SpellingFilter::TextCensor::censorQuotations(const TQString& quotePrefix) -{ - mPos = 0; - while(mPos < static_cast(mText.length())) - { - // Find start of quotation - findQuotation(quotePrefix); - if(mPos < static_cast(mText.length())) - { - int start = mPos; - skipQuotation(quotePrefix); - - // Replace quotation with spaces - int len = mPos - start; - TQString spaces; - spaces.fill(' ', len); - mText.replace(start, len, spaces); - - //kdDebug(5006) << "censored quotation [" - // << start << ", " << mPos << ")" << endl; - } - } -} - -void SpellingFilter::TextCensor::censorUrls() -{ - mPos = 0; - while(mPos < static_cast(mText.length())) - { - // Find start of url - TQString url; - while(mPos < static_cast(mText.length()) && url.isEmpty()) - { - url = getUrl(); - ++mPos; - } - - if(mPos < static_cast(mText.length()) && !url.isEmpty()) - { - int start = mPos - url.length(); - - // Replace url with spaces - url.fill(' '); - mText.replace(start, url.length(), url); - - //kdDebug(5006) << "censored url [" - // << start << ", " << mPos << ")" << endl; - } - } -} - -void SpellingFilter::TextCensor::censorEmailAddresses() -{ - mPos = 0; - while(mPos < static_cast(mText.length())) - { - // Find start of email address - findEmailAddress(); - if(mPos < static_cast(mText.length())) - { - TQString address = getEmailAddress(); - ++mPos; - if(!address.isEmpty()) - { - int start = mPos - address.length(); - - // Replace address with spaces - address.fill(' '); - mText.replace(start, address.length(), address); - - //kdDebug(5006) << "censored addr [" - // << start << ", "<< mPos << ")" << endl; - } - } - } -} - -void SpellingFilter::TextCensor::censorString(const TQString& s) -{ - mPos = 0; - while(mPos != -1) - { - // Find start of string - mPos = mText.find(s, mPos); - if(mPos != -1) - { - // Replace string with spaces - TQString spaces; - spaces.fill(' ', s.length()); - mText.replace(mPos, s.length(), spaces); - mPos += s.length(); - - //kdDebug(5006) << "censored string [" - // << mPos << ", "<< mPos+s.length() << ")" << endl; - } - } -} - -TQString SpellingFilter::TextCensor::censoredText() const -{ - return mText; -} - -//----------------------------------------------------------------------------- -// text censorship helper functions -// - -bool SpellingFilter::TextCensor::atLineStart() const -{ - return (mPos == 0 && static_cast(mText.length()) > 0) || (mText[mPos - 1] == '\n'); -} - -void SpellingFilter::TextCensor::skipLine() -{ - mPos = mText.find('\n', mPos); - if(mPos == -1) - mPos = static_cast(mText.length()); - else - ++mPos; -} - -bool SpellingFilter::TextCensor::atQuotation(const TQString& quotePrefix) const -{ - return atLineStart() && - mText.mid(mPos, quotePrefix.length()) == quotePrefix; -} - -void SpellingFilter::TextCensor::skipQuotation(const TQString& quotePrefix) -{ - while(atQuotation(quotePrefix)) - skipLine(); -} - -void SpellingFilter::TextCensor::findQuotation(const TQString& quotePrefix) -{ - while(mPos < static_cast(mText.length()) && !atQuotation(quotePrefix)) - skipLine(); -} - -void SpellingFilter::TextCensor::findEmailAddress() -{ - while(mPos < static_cast(mText.length()) && mText[mPos] != '@') - ++mPos; -} - diff --git a/libkdepim/spellingfilter.h b/libkdepim/spellingfilter.h deleted file mode 100644 index 4178a888e..000000000 --- a/libkdepim/spellingfilter.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * spellingfilter.h - * - * Copyright (c) 2002 Dave Corrie - * - * This file is part of KMail. - * - * KMail 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 SPELLINGFILTER_H_INCLUDED -#define SPELLINGFILTER_H_INCLUDED - -#include -#include -#include "linklocator.h" - -#include - -class KDE_EXPORT SpellingFilter -{ -public: - enum UrlFiltering { DontFilterUrls, FilterUrls }; - enum EmailAddressFiltering { DontFilterEmailAddresses, FilterEmailAddresses }; - - SpellingFilter(const TQString& text, const TQString& quotePrefix, - UrlFiltering filterUrls = FilterUrls, - EmailAddressFiltering filterEmailAddresses = FilterEmailAddresses, - const TQStringList& filterStrings = TQStringList()); - - TQString originalText() const; - TQString filteredText() const; - - class TextCensor; - -private: - const TQString mOriginal; - TQString mFiltered; -}; - -class SpellingFilter::TextCensor : public LinkLocator -{ -public: - TextCensor(const TQString& s); - - void censorQuotations(const TQString& quotePrefix); - void censorUrls(); - void censorEmailAddresses(); - void censorString(const TQString& s); - - TQString censoredText() const; - -private: - bool atLineStart() const; - void skipLine(); - - bool atQuotation(const TQString& quotePrefix) const; - void skipQuotation(const TQString& quotePrefix); - void findQuotation(const TQString& quotePrefix); - - void findEmailAddress(); -}; - -#endif // SPELLINGFILTER_H_INCLUDED - diff --git a/libkdepim/ssllabel.cpp b/libkdepim/ssllabel.cpp deleted file mode 100644 index 8068aa001..000000000 --- a/libkdepim/ssllabel.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- mode: C++; c-file-style: "gnu" -*- - * - * This file is part of KMail, the KDE mail client. - * - * Copyright (c) 2003 Zack Rusin - * - * KMail is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation. - * - * KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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. - */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "ssllabel.h" - -#include -#include - -#include - -namespace KPIM { - -SSLLabel::SSLLabel( TQWidget* parent ) - : TQLabel( parent ) -{ - setState( Done ); -} - -void SSLLabel::setEncrypted( bool enc ) -{ - if ( enc ) { - m_lastEncryptionState = Encrypted; - } else { - m_lastEncryptionState = Unencrypted; - } -} - -SSLLabel::State SSLLabel::lastState() const -{ - return m_lastEncryptionState; -} - -void SSLLabel::setState( State state ) -{ - switch( state ) { - case Encrypted: - TQToolTip::remove( this ); - TQToolTip::add( this, i18n("Connection is encrypted") ); - setPixmap( SmallIcon( "encrypted", KGlobal::instance() ) ); - show(); - break; - case Unencrypted: - TQToolTip::remove( this ); - TQToolTip::add( this, i18n("Connection is unencrypted") ); - setPixmap( SmallIcon( "decrypted" ) ); - show(); - break; - case Done: - TQToolTip::remove( this ); - hide(); - break; - case Clean: - default: - TQToolTip::remove( this ); - hide(); - //we return because we do not save the state as the only - //action we want to perform is to hide ourself - return; - } - m_lastEncryptionState = state; -} - - -} //end namespace KPIM - -//#include "ssllabel.moc" diff --git a/libkdepim/ssllabel.h b/libkdepim/ssllabel.h deleted file mode 100644 index 03a841bed..000000000 --- a/libkdepim/ssllabel.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- mode: C++; c-file-style: "gnu" -*- - * - * This file is part of KMail, the KDE mail client. - * - * Copyright (c) 2003 Zack Rusin - * - * KMail is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation. - * - * KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - * of TQt that use the same license as TQt), 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 - * TQt. 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 SSLLABEL_H -#define SSLLABEL_H - -#include - -namespace KPIM { - - class SSLLabel : public TQLabel - { - public: - enum State { - Encrypted, - Unencrypted, - Clean, - Done - }; - SSLLabel( TQWidget* parent ); - - void setEncrypted( bool enc=true ); - void setState( State state ); - State lastState() const; - private: - State m_lastEncryptionState; - }; - -} - -#endif diff --git a/libkdepim/statusbarprogresswidget.cpp b/libkdepim/statusbarprogresswidget.cpp deleted file mode 100644 index c417905a0..000000000 --- a/libkdepim/statusbarprogresswidget.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* - statusbarprogresswidget.cpp - - This file is part of KMail, the KDE mail client. - - (C) 2004 KMail Authors - Includes StatusbarProgressWidget which is based on KIOLittleProgressDlg - by Matt Koss - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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 "ssllabel.h" -using KPIM::SSLLabel; -#include "progressmanager.h" -using KPIM::ProgressItem; -using KPIM::ProgressManager; - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "progressdialog.h" -#include "statusbarprogresswidget.h" - -using namespace KPIM; - -//----------------------------------------------------------------------------- -StatusbarProgressWidget::StatusbarProgressWidget( ProgressDialog* progressDialog, TQWidget* parent, bool button ) - : TQFrame( parent ), mCurrentItem( 0 ), mProgressDialog( progressDialog ), - mDelayTimer( 0 ), mBusyTimer( 0 ) -{ - m_bShowButton = button; - int w = fontMetrics().width( " 999.9 kB/s 00:00:01 " ) + 8; - box = new TQHBoxLayout( this, 0, 0 ); - - m_pButton = new TQPushButton( this ); - m_pButton->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, - TQSizePolicy::Minimum ) ); - m_pButton->setPixmap( SmallIcon( "up" ) ); - box->addWidget( m_pButton ); - stack = new TQWidgetStack( this ); - stack->setMaximumHeight( fontMetrics().height() ); - box->addWidget( stack ); - - m_sslLabel = new SSLLabel( this ); - box->addWidget( m_sslLabel ); - - TQToolTip::add( m_pButton, i18n("Open detailed progress dialog") ); - - m_pProgressBar = new KProgress( this ); - m_pProgressBar->setLineWidth( 1 ); - m_pProgressBar->setFrameStyle( TQFrame::Box ); - m_pProgressBar->installEventFilter( this ); - m_pProgressBar->setMinimumWidth( w ); - stack->addWidget( m_pProgressBar, 1 ); - - m_pLabel = new TQLabel( TQString(), this ); - m_pLabel->tqsetAlignment( AlignHCenter | AlignVCenter ); - m_pLabel->installEventFilter( this ); - m_pLabel->setMinimumWidth( w ); - stack->addWidget( m_pLabel, 2 ); - m_pButton->setMaximumHeight( fontMetrics().height() ); - setMinimumWidth( tqminimumSizeHint().width() ); - - mode = None; - setMode(); - - connect( m_pButton, TQT_SIGNAL( clicked() ), - progressDialog, TQT_SLOT( slotToggleVisibility() ) ); - - connect ( ProgressManager::instance(), TQT_SIGNAL( progressItemAdded( KPIM::ProgressItem * ) ), - this, TQT_SLOT( slotProgressItemAdded( KPIM::ProgressItem * ) ) ); - connect ( ProgressManager::instance(), TQT_SIGNAL( progressItemCompleted( KPIM::ProgressItem * ) ), - this, TQT_SLOT( slotProgressItemCompleted( KPIM::ProgressItem * ) ) ); - connect ( ProgressManager::instance(), TQT_SIGNAL(progressItemUsesBusyIndicator(KPIM::ProgressItem*,bool)), - this, TQT_SLOT( updateBusyMode() ) ); - - connect ( progressDialog, TQT_SIGNAL( visibilityChanged( bool )), - this, TQT_SLOT( slotProgressDialogVisible( bool ) ) ); - - mDelayTimer = new TQTimer( this ); - connect ( mDelayTimer, TQT_SIGNAL( timeout() ), - this, TQT_SLOT( slotShowItemDelayed() ) ); -} - -// There are three cases: no progressitem, one progressitem (connect to it directly), -// or many progressitems (display busy indicator). Let's call them 0,1,N. -// In slot..Added we can only end up in 1 or N. -// In slot..Removed we can end up in 0, 1, or we can stay in N if we were already. - -void StatusbarProgressWidget::updateBusyMode() -{ - connectSingleItem(); // if going to 1 item - if ( mCurrentItem ) { // Exactly one item - delete mBusyTimer; - mBusyTimer = 0; - mDelayTimer->start( 1000, true ); - } - else { // N items - if ( !mBusyTimer ) { - mBusyTimer = new TQTimer( this ); - connect( mBusyTimer, TQT_SIGNAL( timeout() ), - this, TQT_SLOT( slotBusyIndicator() ) ); - mDelayTimer->start( 1000, true ); - } - } -} - -void StatusbarProgressWidget::slotProgressItemAdded( ProgressItem *item ) -{ - if ( item->parent() ) - return; // we are only interested in top level items - - updateBusyMode(); -} - -void StatusbarProgressWidget::slotProgressItemCompleted( ProgressItem *item ) -{ - if ( item->parent() ) return; // we are only interested in top level items - connectSingleItem(); // if going back to 1 item - if ( ProgressManager::instance()->isEmpty() ) { // No item - // Done. In 5s the progress-widget will close, then we can clean up the statusbar - TQTimer::singleShot( 5000, this, TQT_SLOT( slotClean() ) ); - } else if ( mCurrentItem ) { // Exactly one item - delete mBusyTimer; - mBusyTimer = 0; - activateSingleItemMode(); - } -} - -void StatusbarProgressWidget::connectSingleItem() -{ - if ( mCurrentItem ) { - disconnect ( mCurrentItem, TQT_SIGNAL( progressItemProgress( KPIM::ProgressItem *, unsigned int ) ), - this, TQT_SLOT( slotProgressItemProgress( KPIM::ProgressItem *, unsigned int ) ) ); - mCurrentItem = 0; - } - mCurrentItem = ProgressManager::instance()->singleItem(); - if ( mCurrentItem ) { - connect ( mCurrentItem, TQT_SIGNAL( progressItemProgress( KPIM::ProgressItem *, unsigned int ) ), - this, TQT_SLOT( slotProgressItemProgress( KPIM::ProgressItem *, unsigned int ) ) ); - } -} - -void StatusbarProgressWidget::activateSingleItemMode() -{ - m_pProgressBar->setTotalSteps( 100 ); - m_pProgressBar->setProgress( mCurrentItem->progress() ); - m_pProgressBar->setPercentageVisible( true ); -} - -void StatusbarProgressWidget::slotShowItemDelayed() -{ - bool noItems = ProgressManager::instance()->isEmpty(); - if ( mCurrentItem ) { - activateSingleItemMode(); - } else if ( !noItems ) { // N items - m_pProgressBar->setTotalSteps( 0 ); - m_pProgressBar->setPercentageVisible( false ); - Q_ASSERT( mBusyTimer ); - if ( mBusyTimer ) - mBusyTimer->start( 100 ); - } - - if ( !noItems && mode == None ) { - mode = Progress; - setMode(); - } -} - -void StatusbarProgressWidget::slotBusyIndicator() -{ - int p = m_pProgressBar->progress(); - m_pProgressBar->setProgress( p + 10 ); -} - -void StatusbarProgressWidget::slotProgressItemProgress( ProgressItem *item, unsigned int value ) -{ - Q_ASSERT( item == mCurrentItem); // the only one we should be connected to - m_pProgressBar->setProgress( value ); -} - -void StatusbarProgressWidget::slotSetSSL( bool ssl ) -{ - m_sslLabel->setEncrypted( ssl ); -} - -void StatusbarProgressWidget::setMode() { - switch ( mode ) { - case None: - if ( m_bShowButton ) { - m_pButton->hide(); - } - m_sslLabel->setState( SSLLabel::Done ); - // show the empty label in order to make the status bar look better - stack->show(); - stack->raiseWidget( m_pLabel ); - break; - -#if 0 - case Label: - if ( m_bShowButton ) { - m_pButton->show(); - } - m_sslLabel->setState( m_sslLabel->lastState() ); - stack->show(); - stack->raiseWidget( m_pLabel ); - break; -#endif - - case Progress: - stack->show(); - stack->raiseWidget( m_pProgressBar ); - if ( m_bShowButton ) { - m_pButton->show(); - } - m_sslLabel->setState( m_sslLabel->lastState() ); - break; - } -} - -void StatusbarProgressWidget::slotClean() -{ - // check if a new item showed up since we started the timer. If not, clear - if ( ProgressManager::instance()->isEmpty() ) { - m_pProgressBar->setProgress( 0 ); - //m_pLabel->clear(); - mode = None; - setMode(); - } -} - -bool StatusbarProgressWidget::eventFilter( TQObject *, TQEvent *ev ) -{ - if ( ev->type() == TQEvent::MouseButtonPress ) { - TQMouseEvent *e = (TQMouseEvent*)ev; - - if ( e->button() == Qt::LeftButton && mode != None ) { // toggle view on left mouse button - // Consensus seems to be that we should show/hide the fancy dialog when the user - // clicks anywhere in the small one. - mProgressDialog->slotToggleVisibility(); - return true; - } - } - return false; -} - -void StatusbarProgressWidget::slotProgressDialogVisible( bool b ) -{ - // Update the hide/show button when the detailed one is shown/hidden - if ( b ) { - m_pButton->setPixmap( SmallIcon( "down" ) ); - TQToolTip::remove( m_pButton ); - TQToolTip::add( m_pButton, i18n("Hide detailed progress window") ); - setMode(); - } else { - m_pButton->setPixmap( SmallIcon( "up" ) ); - TQToolTip::remove( m_pButton ); - TQToolTip::add( m_pButton, i18n("Show detailed progress window") ); - } -} - -#include "statusbarprogresswidget.moc" diff --git a/libkdepim/statusbarprogresswidget.h b/libkdepim/statusbarprogresswidget.h deleted file mode 100644 index 8b08d2cf9..000000000 --- a/libkdepim/statusbarprogresswidget.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef __KPIM_STATUSBARPROGRESSWIDGET_H -#define __KPIM_STATUSBARPROGRESSWIDGET_H -/* - statusbarprogresswidget.h - - This file is part of KMail, the KDE mail client. - - (C) 2004 KMail Authors - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - KMail 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 TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), 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 - TQt. 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. -*/ -/** - * A specialized progress widget class, heavily based on - * kio_littleprogress_dlg (it looks similar) - */ - -#include - -class KMMainWidget; -class KProgress; -class TQPushButton; -class TQWidgetStack; -class TQBoxLayout; -class TQLabel; -class TQTimer; - -namespace KPIM { -class SSLLabel; -class ProgressItem; -class ProgressDialog; - -class KDE_EXPORT StatusbarProgressWidget : public TQFrame { - - Q_OBJECT - TQ_OBJECT - -public: - - StatusbarProgressWidget( ProgressDialog* progressDialog, TQWidget* parent, bool button = true ); - -public slots: - - void slotClean(); - void slotSetSSL( bool ); - - void slotProgressItemAdded( KPIM::ProgressItem *i ); - void slotProgressItemCompleted( KPIM::ProgressItem *i ); - void slotProgressItemProgress( KPIM::ProgressItem *i, unsigned int value ); - -protected slots: - void slotProgressDialogVisible( bool ); - void slotShowItemDelayed(); - void slotBusyIndicator(); - void updateBusyMode(); - -protected: - void setMode(); - void connectSingleItem(); - void activateSingleItemMode(); - - virtual bool eventFilter( TQObject *, TQEvent * ); - -private: - KProgress* m_pProgressBar; - TQLabel* m_pLabel; - SSLLabel* m_sslLabel; - TQPushButton* m_pButton; - - enum Mode { None, /*Label,*/ Progress }; - - uint mode; - bool m_bShowButton; - - TQBoxLayout *box; - TQWidgetStack *stack; - ProgressItem *mCurrentItem; - ProgressDialog* mProgressDialog; - TQTimer *mDelayTimer; - TQTimer *mBusyTimer; -}; - -} // namespace - -#endif diff --git a/libkdepim/tests/Makefile.am b/libkdepim/tests/Makefile.am deleted file mode 100644 index 217676cae..000000000 --- a/libkdepim/tests/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -AM_CPPFLAGS = -I$(top_builddir)/libtdepim -I$(top_srcdir)/libtdepim -I$(top_srcdir)/libemailfunctions $(all_includes) -AM_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor -LDADD = ../libtdepim.la $(LIB_KDECORE) - -check_PROGRAMS = testwizard testaddresseelineedit \ - testaddresseeselector \ - testutf7decoder \ - testutf7encoder \ - test_kregexp \ - testdateedit \ - testlinklocator \ - testkincidencechooser - -# disabled because of X dependency -# testdistrlist - -testwizard_SOURCES = testwizard.cpp myconfig.kcfgc -testaddresseelineedit_SOURCES = testaddresseelineedit.cpp -testaddresseeselector_SOURCES = testaddresseeselector.cpp -testutf7encoder_SOURCES = testutf7encoder2.cpp -testutf7decoder_SOURCES = testutf7decoder.cpp -test_kregexp_SOURCES = test_kregexp.cpp -testdateedit_SOURCES = testdateedit.cpp -testlinklocator_SOURCES = testlinklocator.cpp -#testdistrlist_SOURCES = testdistrlist.cpp -testkincidencechooser_SOURCES = testkincidencechooser.cpp - -#TESTS = testdistrlist - -METASOURCES = AUTO - -#example_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor -#example_LDADD = ../libtdepim.la $(LIB_KDECORE) -#example_SOURCES = example.cpp exampleprefs_base.kcfgc - diff --git a/libkdepim/tests/myconfig.kcfgc b/libkdepim/tests/myconfig.kcfgc deleted file mode 100644 index 35e26c996..000000000 --- a/libkdepim/tests/myconfig.kcfgc +++ /dev/null @@ -1,11 +0,0 @@ -# Code generation options for kconfig_compiler -File=propagator_test.kcfg -ClassName=MyConfig -Singleton=true -Mutators=true -#Inherits=KPimPrefs -#IncludeFiles=libtdepim/kpimprefs.h -MemberVariables=public -GlobalEnums=true -ItemAccessors=true -SetUserTexts=true diff --git a/libkdepim/tests/propagator_test.kcfg b/libkdepim/tests/propagator_test.kcfg deleted file mode 100644 index 8fc971771..000000000 --- a/libkdepim/tests/propagator_test.kcfg +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - true - - - - false - - - 0 - - - 1 - - - hallo - - - - - - - - - - - - - - - - - - diff --git a/libkdepim/tests/test_kregexp.cpp b/libkdepim/tests/test_kregexp.cpp deleted file mode 100644 index 511687d07..000000000 --- a/libkdepim/tests/test_kregexp.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include - -int -main() -{ - KInstance app("# "); - - // test for http://bugs.kde.org/show_bug.cgi?id=54886 - KRegExp3 reg("^"); - TQString res = reg.replace(TQString::tqfromLatin1("Fun stuff"), - TQString::tqfromLatin1("[fun] ")); - kdDebug() << res << endl; - -} diff --git a/libkdepim/tests/testaddresseelineedit.cpp b/libkdepim/tests/testaddresseelineedit.cpp deleted file mode 100644 index 12eb3c6b1..000000000 --- a/libkdepim/tests/testaddresseelineedit.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Daniel Molkentin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "../addresseelineedit.h" - -int main(int argc, char* argv[]) -{ - KAboutData aboutData("testaddresseelineedit","Test AddresseeLineEdit","0.1"); - KCmdLineArgs::init(argc,argv,&aboutData); - - KApplication app; - - KPIM::AddresseeLineEdit *kale = new KPIM::AddresseeLineEdit(0); - kale->resize( 400, 20 ); - kale->show(); - - return app.exec(); - -} - diff --git a/libkdepim/tests/testaddresseeselector.cpp b/libkdepim/tests/testaddresseeselector.cpp deleted file mode 100644 index 6b910e4b9..000000000 --- a/libkdepim/tests/testaddresseeselector.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Daniel Molkentin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "../addresseeselector.h" -#include "../addresseeemailselection.h" - -int main( int argc, char **argv ) -{ - KAboutData aboutData( "testaddresseeseletor", "Test AddresseeSelector", "0.1" ); - KCmdLineArgs::init( argc, argv, &aboutData ); - - KApplication app; - - KPIM::AddresseeEmailSelection selection; - - KPIM::AddresseeSelectorDialog dlg( &selection ); - dlg.exec(); - - kdDebug() << "to: " << selection.to() << endl; - kdDebug() << "cc: " << selection.cc() << endl; - kdDebug() << "bcc: " << selection.bcc() << endl; - - kdDebug() << "toDistlists: " << selection.toDistributionLists() << endl; - kdDebug() << "ccDistlists: " << selection.ccDistributionLists() << endl; - kdDebug() << "bccDistlists: " << selection.bccDistributionLists() << endl; - - return 0; -} diff --git a/libkdepim/tests/testdateedit.cpp b/libkdepim/tests/testdateedit.cpp deleted file mode 100644 index 46fabcfe1..000000000 --- a/libkdepim/tests/testdateedit.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. 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 "kdateedit.h" - -#include "testdateedit.h" - -DateEdit::DateEdit( TQWidget *parent, const char *name ) - : TQWidget( parent, name ) -{ - TQVBoxLayout *tqlayout = new TQVBoxLayout( this ); - - KDateEdit *edit = new KDateEdit( this ); - tqlayout->addWidget( edit ); - - connect( edit, TQT_SIGNAL( dateChanged( const TQDate& ) ), - this, TQT_SLOT( dateChanged( const TQDate& ) ) ); -} - -void DateEdit::dateChanged( const TQDate &date ) -{ - if ( date.isValid() ) - qDebug( "%s", date.toString().latin1() ); - else - qDebug( "invalid date entered" ); -} - -int main(int argc,char **argv) -{ - KAboutData aboutData( "testdateedit", "Test KDateEdit", "0.1" ); - KCmdLineArgs::init( argc, argv, &aboutData ); - - KApplication app; - - DateEdit dateEdit; - app.setMainWidget( &dateEdit ); - dateEdit.show(); - - app.exec(); -} - -#include "testdateedit.moc" diff --git a/libkdepim/tests/testdateedit.h b/libkdepim/tests/testdateedit.h deleted file mode 100644 index 8693ffa00..000000000 --- a/libkdepim/tests/testdateedit.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2004 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef TESTDATEEDIT_H -#define TESTDATEEDIT_H - -#include - -class DateEdit : public TQWidget -{ - Q_OBJECT - TQ_OBJECT - - public: - DateEdit( TQWidget *parent = 0, const char *name = 0 ); - - public slots: - void dateChanged( const TQDate& ); -}; - -#endif diff --git a/libkdepim/tests/testdistrlist.cpp b/libkdepim/tests/testdistrlist.cpp deleted file mode 100644 index f588f9a93..000000000 --- a/libkdepim/tests/testdistrlist.cpp +++ /dev/null @@ -1,332 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2004 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "testdistrlist.h" - -#include -using KPIM::DistributionList; - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -int main(int argc, char *argv[]) -{ - // Use another directory than the real one, just to keep things clean - // KDEHOME needs to be writable though, for a ksycoca database - setenv( "KDEHOME", TQFile::encodeName( TQDir::homeDirPath() + "/.kde-testdistrlist" ), true ); - setenv( "KDE_FORK_SLAVES", "yes", true ); // simpler, for the final cleanup - - KApplication::disableAutoDcopRegistration(); - KCmdLineArgs::init(argc,argv,"testdistrlist", 0, 0, 0, 0); - KApplication app( false, false ); - - TestDistrList test; - test.setup(); - test.runAll(); - test.cleanup(); - kdDebug() << "All tests OK." << endl; - return 0; -} - -void TestDistrList::setup() -{ - // We need a std addressbook - KABC::AddressBook *ab = KABC::StdAddressBook::self(); - KABC::StdAddressBook::setAutomaticSave( false ); - - // and two contacts - KABC::Addressee addr1; - addr1.setName( "addr1" ); - addr1.setFormattedName( "addr1" ); - addr1.insertEmail( "addr1@kde.org", true ); - addr1.insertEmail( "addr1-alternate@kde.org" ); - ab->insertAddressee( addr1 ); - assert( addr1.emails().count() == 2 ); - - KABC::Addressee addr2; - addr2.setName( "addr2" ); - addr2.insertEmail( "addr2@kde.org", true ); - addr2.insertEmail( "addr2-alternate@kde.org" ); - ab->insertAddressee( addr2 ); - assert( addr2.emails().count() == 2 ); - - assert( !ab->findByName( "addr1" ).isEmpty() ); - assert( !ab->findByName( "addr2" ).isEmpty() ); -} - -void TestDistrList::runAll() -{ - testEmpty(); - testNewList(); - testInsertEntry(); - testRemoveEntry(); - testDuplicate(); - testDeleteList(); -} - -bool TestDistrList::check(const TQString& txt, TQString a, TQString b) -{ - if (a.isEmpty()) - a = TQString(); - if (b.isEmpty()) - b = TQString(); - if (a == b) { - kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl; - } - else { - kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl; - cleanup(); - exit(1); - } - return true; -} - -// taken from KMail -#include -#include -static bool removeDirAndContentsRecursively( const TQString & path ) -{ - kdDebug() << k_funcinfo << path << endl; - bool success = true; - - TQDir d; - d.setPath( path ); - d.setFilter( TQDir::Files | TQDir::Dirs | TQDir::Hidden ); - - const TQFileInfoList *list = d.entryInfoList(); - TQFileInfoListIterator it( *list ); - TQFileInfo *fi; - - while ( (fi = it.current()) != 0 ) { - if( fi->isDir() && !fi->isSymLink() ) { - if ( fi->fileName() != "." && fi->fileName() != ".." ) - success = success && removeDirAndContentsRecursively( fi->absFilePath() ); - } else { - success = success && d.remove( fi->absFilePath() ); - } - ++it; - } - - if ( success ) { - success = success && d.rmdir( path ); // nuke ourselves, we should be empty now - } - return success; -} - -void TestDistrList::cleanup() -{ - kdDebug() << k_funcinfo << endl; - KABC::AddressBook *ab = KABC::StdAddressBook::self(); - ab->clear(); - KABC::StdAddressBook::close(); - - TQString kdehome = TQFile::decodeName( getenv("KDEHOME") ); - KURL urlkdehome; urlkdehome.setPath( kdehome ); - // don't use KIO::NetAccess here since it needs X - // KIO::NetAccess::del( urlkdehome, 0 )i; - assert( removeDirAndContentsRecursively( kdehome ) ); -} - -void TestDistrList::testEmpty() -{ - kdDebug() << k_funcinfo << endl; - DistributionList dl; - assert( dl.isEmpty() ); -} - -void TestDistrList::testNewList() -{ - kdDebug() << k_funcinfo << endl; - DistributionList dl; - dl.setName( "foo" ); - assert( !dl.isEmpty() ); - check( "name set", dl.formattedName(), "foo" ); - assert( DistributionList::isDistributionList( dl ) ); - - KABC::AddressBook *ab = KABC::StdAddressBook::self(); - ab->insertAddressee( dl ); -#if 0 // can't do that until we have KABC::AddressBook::findByFormattedName, or we use setName() - KABC::Addressee::List addrList = ab->findByName( "foo" ); - assert( addrList.count() == 1 ); - KABC::Addressee addr = addrList.first(); - assert( !addr.isEmpty() ); - check( "correct name", addr.name(), "foo" ); - assert( DistributionList::isDistributionList( addr ) ); -#else - KABC::Addressee addr = dl; -#endif - - DistributionList dl2 = DistributionList::findByName( ab, "foo" ); - assert( !dl2.isEmpty() ); - check( "correct name", dl2.formattedName(), "foo" ); - assert( DistributionList::isDistributionList( dl2 ) ); - - // Test the ctor that takes an addressee - DistributionList dl3( addr ); - assert( !dl3.isEmpty() ); - assert( DistributionList::isDistributionList( dl3 ) ); - check( "correct name", dl3.formattedName(), "foo" ); -} - -void TestDistrList::testInsertEntry() -{ - kdDebug() << k_funcinfo << endl; - KABC::AddressBook *ab = KABC::StdAddressBook::self(); - DistributionList dl = DistributionList::findByName( ab, "foo" ); - assert( !dl.isEmpty() ); - -#if 0 // the usual method - KABC::Addressee addr1 = ab->findByName( "addr1" ).first(); - assert( !addr1.isEmpty() ); - dl.insertEntry( addr1 ); -#else // the kolab-resource method - dl.insertEntry( "addr1" ); -#endif - - KABC::Addressee addr2 = ab->findByName( "addr2" ).first(); - assert( !addr2.isEmpty() ); - dl.insertEntry( addr2, "addr2-alternate@kde.org" ); - - // Try inserting it again, should do nothing - dl.insertEntry( addr2, "addr2-alternate@kde.org" ); - - // And insert it with another email address - dl.insertEntry( addr2, "addr2@kde.org" ); - - // Test entries() - DistributionList::Entry::List entries = dl.entries( ab ); - check( "entries count", TQString::number( entries.count() ), "3" ); - check( "first entry", entries[0].addressee.name(), "addr1" ); - check( "first entry", entries[0].email, TQString() ); - check( "second entry", entries[1].addressee.name(), "addr2" ); - check( "second entry", entries[1].email, "addr2-alternate@kde.org" ); - check( "third entry", entries[2].addressee.name(), "addr2" ); - check( "third entry", entries[2].email, "addr2@kde.org" ); - - // Test emails() - TQStringList emails = dl.emails( ab ); - kdDebug() << emails << endl; - assert( emails.count() == 3 ); - check( "first email", emails[0], "addr1 " ); - check( "second email", emails[1], "addr2 " ); - check( "third email", emails[2], "addr2 " ); - - // Commit changes to the addressbook !! - ab->insertAddressee( dl ); -} - -void TestDistrList::testRemoveEntry() -{ - kdDebug() << k_funcinfo << endl; - KABC::AddressBook *ab = KABC::StdAddressBook::self(); - DistributionList dl = DistributionList::findByName( ab, "foo" ); - assert( !dl.isEmpty() ); - DistributionList::Entry::List entries = dl.entries( ab ); - check( "entries count before removeEntry", TQString::number( entries.count() ), "3" ); - - // Removing an empty entry shouldn't do anything - dl.removeEntry( KABC::Addressee() ); - check( "entries count after removing empty entry", TQString::number( dl.entries(ab).count() ), "3" ); - - KABC::Addressee addr1 = ab->findByName( "addr1" ).first(); - assert( !addr1.isEmpty() ); - // Removing an entry with the wrong email passed, shouldn't do anything - dl.removeEntry( addr1, "foo@foobar.com" ); - check( "entries count after removing entry with invalid email", TQString::number( dl.entries(ab).count() ), "3" ); - - // Now remove entry correctly - dl.removeEntry( addr1 ); - check( "removeEntry(addr1) worked", TQString::number( dl.entries(ab).count() ), "2" ); - TQStringList emails = dl.emails( ab ); - assert( emails.count() == 2 ); - check( "first email", emails[0], "addr2 " ); - - // Now move on to addr2. First remove with no or a wrong email (nothing should happen) - KABC::Addressee addr2 = ab->findByName( "addr2" ).first(); - assert( !addr2.isEmpty() ); - dl.removeEntry( addr2 ); - check( "entries count after removing entry with no email", TQString::number( dl.entries(ab).count() ), "2" ); - - // Now remove addr2 correctly - dl.removeEntry( addr2, "addr2@kde.org" ); - check( "entries count after removing addr2", TQString::number( dl.entries(ab).count() ), "1" ); - dl.removeEntry( addr2, "addr2-alternate@kde.org" ); - check( "entries count after removing alternate addr2", TQString::number( dl.entries(ab).count() ), "0" ); - assert( dl.entries(ab).isEmpty() ); - assert( dl.emails(ab).isEmpty() ); - assert( DistributionList::isDistributionList( dl ) ); - - ab->insertAddressee( dl ); -} - -void TestDistrList::testDuplicate() -{ - kdDebug() << k_funcinfo << endl; - // This is a special test for the case where we have a contact and a distr list with the same name - KABC::AddressBook *ab = KABC::StdAddressBook::self(); - KABC::Addressee addr; - addr.setName( "foo" ); - addr.insertEmail( "foo@kde.org", true ); - ab->insertAddressee( addr ); - -#if 0 // we need a findByFormattedName - KABC::Addressee::List addrList = ab->findByName( "foo" ); - assert( addrList.count() == 2 ); - - bool a = DistributionList::isDistributionList( addrList.first() ); - bool b = DistributionList::isDistributionList( addrList.last() ); - // one is a distr list, but not both - assert( a || b ); - // - assert( ! ( a && b ) ); -#endif - - DistributionList dl = DistributionList::findByName( ab, "foo" ); - assert( !dl.isEmpty() ); - assert( DistributionList::isDistributionList( dl ) ); - assert( dl.formattedName() == "foo" ); -} - -void TestDistrList::testDeleteList() -{ - kdDebug() << k_funcinfo << endl; - - KABC::AddressBook *ab = KABC::StdAddressBook::self(); - DistributionList dl = DistributionList::findByName( ab, "foo" ); - assert( !dl.isEmpty() ); - ab->removeAddressee( dl ); - dl = DistributionList::findByName( ab, "foo" ); - assert( dl.isEmpty() ); -} - -#include "testdistrlist.moc" diff --git a/libkdepim/tests/testdistrlist.h b/libkdepim/tests/testdistrlist.h deleted file mode 100644 index 3f64527e6..000000000 --- a/libkdepim/tests/testdistrlist.h +++ /dev/null @@ -1,47 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2004 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef TESTDISTRLIST_H -#define TESTDISTRLIST_H - -#include - -class TestDistrList : public TQObject -{ - Q_OBJECT - TQ_OBJECT - -public: - TestDistrList() {} - void setup(); - void runAll(); - void cleanup(); - - // tests - void testEmpty(); - void testNewList(); - void testInsertEntry(); - void testRemoveEntry(); - void testDuplicate(); - void testDeleteList(); - -private: - bool check(const TQString& txt, TQString a, TQString b); -}; - -#endif diff --git a/libkdepim/tests/testkincidencechooser.cpp b/libkdepim/tests/testkincidencechooser.cpp deleted file mode 100644 index 1204f8dc2..000000000 --- a/libkdepim/tests/testkincidencechooser.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright (C) 2009 Allen Winter - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include -using namespace KCal; - -#include "kincidencechooser.h" -using namespace KPIM; - -int main( int argc, char **argv ) -{ - KCmdLineArgs::init( argc, argv, "testkincidencechooser", 0, - "KIncidenceChooserTest", "1.0", - "kincidencechooser test app" ); - KApplication app; - KIncidenceChooser *chooser = new KIncidenceChooser(); - - Event event; - event.setSummary( i18n( "Meeting" ) ); - event.setDescription( i18n( "Discuss foo" ) ); - chooser->setIncidence( &event, &event ); - chooser->resize( 600, 600 ); - chooser->show(); - return app.exec(); -} diff --git a/libkdepim/tests/testlinklocator.cpp b/libkdepim/tests/testlinklocator.cpp deleted file mode 100644 index 548f61a9b..000000000 --- a/libkdepim/tests/testlinklocator.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2005 Ingo Kloecker - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// Test program for libtdepim/linklocator.* -#include - -#include -#include -#include - -#include -#include -#include -#include - -static bool check(const TQString& txt, const TQString& a, const TQString& b) -{ - if (a == b) { - kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl; - } - else { - kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl; - exit(1); - } - return true; -} - -static bool checkGetEmailAddress( const TQString & input, - int atPos, - const TQString & expRetVal, - bool allowBadAtPos = false ) -{ - if ( !allowBadAtPos && ( input[atPos] != '@' ) ) { - kdDebug() << "atPos (" << atPos << ") doesn't point to '@' in \"" - << input << "\". Fix the check!" << endl; - exit(1); - } - LinkLocator ll( input, atPos ); - const TQString retVal = ll.getEmailAddress(); - check( "getEmailAddress() \"" + input + "\", " + TQString::number( atPos ), - retVal, expRetVal ); - return true; -} - -int main(int argc, char *argv[]) -{ - KApplication::disableAutoDcopRegistration(); - KCmdLineArgs::init( argc, argv, "testlinklocator", 0, 0, 0, 0 ); - KApplication app( false, false ); - - // empty input - checkGetEmailAddress( TQString(), 0, TQString(), true ); - - // no '@' at scan position - checkGetEmailAddress( "foo@bar.baz", 0, TQString(), true ); - - // '@' in local part - checkGetEmailAddress( "foo@bar@bar.baz", 7, TQString() ); - - // empty local part - checkGetEmailAddress( "@bar.baz", 0, TQString() ); - checkGetEmailAddress( ".@bar.baz", 1, TQString() ); - checkGetEmailAddress( " @bar.baz", 1, TQString() ); - checkGetEmailAddress( ".!#$%&'*+-/=?^_`{|}~@bar.baz", strlen(".!#$%&'*+-/=?^_`{|}~"), TQString() ); - - // allowed special chars in local part of address - checkGetEmailAddress( "a.!#$%&'*+-/=?^_`{|}~@bar.baz", strlen("a.!#$%&'*+-/=?^_`{|}~"), "a.!#$%&'*+-/=?^_`{|}~@bar.baz" ); - - // '@' in domain part - checkGetEmailAddress( "foo@bar@bar.baz", 3, TQString() ); - - // domain part without dot - checkGetEmailAddress( "foo@bar", 3, TQString() ); - checkGetEmailAddress( "foo@bar.", 3, TQString() ); - checkGetEmailAddress( ".foo@bar", 4, TQString() ); - checkGetEmailAddress( "foo@bar ", 3, TQString() ); - checkGetEmailAddress( " foo@bar", 4, TQString() ); - checkGetEmailAddress( "foo@bar-bar", 3, TQString() ); - - // empty domain part - checkGetEmailAddress( "foo@", 3, TQString() ); - checkGetEmailAddress( "foo@.", 3, TQString() ); - checkGetEmailAddress( "foo@-", 3, TQString() ); - - // simple address - checkGetEmailAddress( "foo@bar.baz", 3, "foo@bar.baz" ); - checkGetEmailAddress( "foo@bar.baz.", 3, "foo@bar.baz" ); - checkGetEmailAddress( ".foo@bar.baz", 4, "foo@bar.baz" ); - checkGetEmailAddress( "foo@bar.baz-", 3, "foo@bar.baz" ); - checkGetEmailAddress( "-foo@bar.baz", 4, "foo@bar.baz" ); - checkGetEmailAddress( "foo@bar.baz ", 3, "foo@bar.baz" ); - checkGetEmailAddress( " foo@bar.baz", 4, "foo@bar.baz" ); - checkGetEmailAddress( "foo@bar-bar.baz", 3, "foo@bar-bar.baz" ); - - printf("\nTest OK !\n"); - - return 0; -} - diff --git a/libkdepim/tests/testutf7decoder.cpp b/libkdepim/tests/testutf7decoder.cpp deleted file mode 100644 index b13fb30c3..000000000 --- a/libkdepim/tests/testutf7decoder.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "qutf7codec.h" -#include "qutf7codec.cpp" -#include -#include -#include - -int main( int argc, char * argv[] ) { - if ( argc == 1 ) { - (void)new TQUtf7Codec; - - TQTextCodec * codec = TQTextCodec::codecForName("utf-7"); - assert(codec); - - TQTextIStream my_cin(stdin); - my_cin.setCodec(codec); - - TQTextOStream my_cout(stdout); - - TQString buffer = my_cin.read(); - - my_cout << buffer; - } else { - qWarning("usage: testutf7decoder string_to_decode\n"); - } - TQTextCodec::deleteAllCodecs(); -} diff --git a/libkdepim/tests/testutf7encoder.cpp b/libkdepim/tests/testutf7encoder.cpp deleted file mode 100644 index 2938cd660..000000000 --- a/libkdepim/tests/testutf7encoder.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "qutf7codec.h" -#include "qutf7codec.cpp" -#include -#include - -void main( int argc, char * argv[] ) { - if ( argc == 2 ) { - TQUtf7Codec * codec = new TQUtf7Codec; - - TQTextEncoder * enc; - - TQString arg = TQString::tqfromLatin1( argv[1] ); - int len; - - cout << "Original string:\n" - << "\"" << argv[1] << "\"\n" << endl; - - cout << "Encode optional direct set and whitespace:\n" << endl; - codec->setEncodeWhitespace(TRUE); - codec->setEncodeOptionalDirect(TRUE); - enc = codec->makeEncoder(); - - len = arg.length(); - cout << (enc->fromUnicode( arg, len )).data() - << "\n" << endl; - - cout << "Same as above, but call fromUnicode() char-wise:\n" << endl; - - delete enc; - enc = codec->makeEncoder(); - - for ( int i = 0 ; i < arg.length() ; i++ ) { - len = 1; - cout << (enc->fromUnicode( TQString(arg[i]), len )).data(); - } - cout << "\n" << endl; - - - - delete enc; - - cout << "Encode optional direct set and not whitespace:\n" << endl; - codec->setEncodeWhitespace(FALSE); - codec->setEncodeOptionalDirect(TRUE); - enc = codec->makeEncoder(); - - len = arg.length(); - cout << (enc->fromUnicode( arg, len )).data() - << "\n" << endl; - - delete enc; - - - cout << "Don't encode optional direct set, but whitespace:\n" << endl; - codec->setEncodeWhitespace(TRUE); - codec->setEncodeOptionalDirect(FALSE); - enc = codec->makeEncoder(); - - len = arg.length(); - cout << (enc->fromUnicode( arg, len )).data() - << "\n" << endl; - - delete enc; - - - cout << "Encode neither optional direct set, nor whitespace:\n" << endl; - codec->setEncodeWhitespace(FALSE); - codec->setEncodeOptionalDirect(FALSE); - enc = codec->makeEncoder(); - - len = arg.length(); - cout << (enc->fromUnicode( arg, len )).data() - << "\n" << endl; - - cout << "Same as above, but call fromUnicode() char-wise:\n" << endl; - - delete enc; - enc = codec->makeEncoder(); - - for ( int i = 0 ; i < arg.length() ; i++ ) { - len = 1; - cout << (enc->fromUnicode( TQString(arg[i]), len )).data(); - } - cout << "\n" << endl; - - - delete enc; - - delete codec; - } else { - qWarning("usage: testutf7encoder string_to_encode\n"); - } -} diff --git a/libkdepim/tests/testutf7encoder2.cpp b/libkdepim/tests/testutf7encoder2.cpp deleted file mode 100644 index 65cf8b461..000000000 --- a/libkdepim/tests/testutf7encoder2.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "qutf7codec.h" -#include "qutf7codec.cpp" -#include -#include -#include -#include - -int main( int argc, char * argv[] ) { - if ( argc == 1 ) { - (void)new TQUtf7Codec; - - TQTextCodec * codec = TQTextCodec::codecForName("utf-7"); - assert(codec); - - TQTextIStream my_cin(stdin); - - TQTextOStream my_cout(stdout); - my_cout.setCodec(codec); - - TQString buffer = my_cin.read(); - - // qDebug("buffer == " + buffer); - -#ifdef USE_STREAM - my_cout << buffer << endl; -#else - TQTextEncoder * enc = codec->makeEncoder(); -#ifdef CHAR_WISE - int len; - for ( int i = 0 ; i < buffer.length() ; i++ ) { - len = 1; - cout << (enc->fromUnicode(TQString(buffer[i]),len)).data(); - } - std::cout << std::endl; -#else - int len = buffer.length(); - std::cout << (enc->fromUnicode(buffer,len)).data() << std::endl;; -#endif // CHAR_WISE - delete enc; -#endif // else USE_STREAM - } else { - qWarning("usage: testutf7encoder2 < infile > outfile\n"); - } - TQTextCodec::deleteAllCodecs(); -} diff --git a/libkdepim/tests/testwizard.cpp b/libkdepim/tests/testwizard.cpp deleted file mode 100644 index d9c9d806c..000000000 --- a/libkdepim/tests/testwizard.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "myconfig.h" - -#include - -#include -#include -#include -#include -#include - -#include -#include - -class TestConfigWizard : public KConfigWizard -{ - public: - TestConfigWizard() : - KConfigWizard( new KConfigPropagator( MyConfig::self(), - "propagator_test.kcfg" ) ) - { - TQFrame *page = createWizardPage( "My Wizard Page" ); - TQBoxLayout *topLayout = new TQVBoxLayout( page ); - - mFixKMailCheckBox = new TQCheckBox( i18n("Fix KMail"), page ); - topLayout->addWidget( mFixKMailCheckBox ); - - mFixKMailCheckBox->setChecked( MyConfig::fixKMail() ); - - mBreakKMailCheckBox = new TQCheckBox( i18n("Break KMail"), page ); - topLayout->addWidget( mBreakKMailCheckBox ); - - mBreakKMailCheckBox->setChecked( MyConfig::breakKMail() ); - - setupRulesPage(); - setupChangesPage(); - } - - ~TestConfigWizard() - { - } - - void usrReadConfig() - { - } - - void usrWriteConfig() - { - MyConfig::self()->setFixKMail( mFixKMailCheckBox->isChecked() ); - MyConfig::self()->setBreakKMail( mBreakKMailCheckBox->isChecked() ); - } - - private: - TQCheckBox *mFixKMailCheckBox; - TQCheckBox *mBreakKMailCheckBox; -}; - -static const KCmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - KCmdLineLastOption -}; - -int main(int argc,char **argv) -{ - KAboutData aboutData("testwizard","Test KConfigWizard","0.1"); - KCmdLineArgs::init(argc,argv,&aboutData); - KCmdLineArgs::addCmdLineOptions( options ); - - KApplication app; - - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - - bool verbose = false; - if ( args->isSet( "verbose" ) ) verbose = true; - - TestConfigWizard wizard; - - wizard.exec(); -} diff --git a/libkdepim/weaver.cpp b/libkdepim/weaver.cpp deleted file mode 100644 index b1dba8de7..000000000 --- a/libkdepim/weaver.cpp +++ /dev/null @@ -1,550 +0,0 @@ -/* -*- C++ -*- - - This file implements the Weaver, Job and Thread classes. - - $ Author: Mirko Boehm $ - $ Copyright: (C) 2004, Mirko Boehm $ - $ Contact: mirko@kde.org - http://www.kde.org - http://www.hackerbuero.org $ - $ License: LGPL with the following explicit clarification: - This code may be linked against any version of the TQt toolkit - from Troll Tech, Norway. $ - -*/ - -extern "C" { -#include -} - -#include -#include - -#include "weaver.h" - -namespace KPIM { -namespace ThreadWeaver { - - bool Debug = true; - int DebugLevel = 2; - - Job::Job (TQObject* parent, const char* name) - : TQObject (parent, name), - m_finished (false), - m_mutex (new TQMutex (true) ), - m_thread (0) - { - } - - Job::~Job() - { - } - - void Job::lock() - { - m_mutex->lock(); - } - - void Job::unlock() - { - m_mutex->unlock(); - } - - void Job::execute(Thread *th) - { - m_mutex->lock(); - m_thread = th; - m_mutex->unlock(); - - run (); - - m_mutex->lock(); - setFinished (true); - m_thread = 0; - m_mutex->unlock(); - } - - Thread *Job::thread () - { - TQMutexLocker l (m_mutex); - return m_thread; - } - - bool Job::isFinished() const - { - TQMutexLocker l (m_mutex); - return m_finished; - } - - void Job::setFinished(bool status) - { - TQMutexLocker l (m_mutex); - m_finished = status; - } - - void Job::processEvent (Event *e) - { - switch ( e->action() ) - { - case Event::JobStarted: - emit ( started() ); - break; - case Event::JobFinished: - emit ( done() ); - break; - case Event::JobSPR: - emit ( SPR () ); - m_wc->wakeOne (); - break; - case Event::JobAPR: - emit ( APR () ); - // no wake here ! - break; - default: - break; - } - } - - void Job::triggerSPR () - { - m_mutex->lock (); - m_wc = new TQWaitCondition; - m_mutex->unlock (); - - thread()->post (KPIM::ThreadWeaver::Event::JobSPR, this); - m_wc->wait (); - - m_mutex->lock (); - delete m_wc; - m_wc = 0; - m_mutex->unlock (); - } - - void Job::triggerAPR () - { - m_mutex->lock (); - m_wc = new TQWaitCondition; - m_mutex->unlock (); - - thread()->post (KPIM::ThreadWeaver::Event::JobAPR, this); - m_wc->wait (); - } - - void Job::wakeAPR () - { - TQMutexLocker l(m_mutex); - if ( m_wc!=0 ) - { - m_wc->wakeOne (); - delete m_wc; - m_wc = 0; - } - } - - const int Event::Type = TQEvent::User + 1000; - - Event::Event ( Action action, Thread *thread, Job *job) - : TQCustomEvent ( type () ), - m_action (action), - m_thread (thread), - m_job (job) - { - } - - int Event::type () - { - return Type; - } - - Thread* Event::thread () const - { - if ( m_thread != 0) - { - return m_thread; - } else { - return 0; - } - } - - Job* Event::job () const - { - return m_job; - } - - Event::Action Event::action () const - { - return m_action; - } - - unsigned int Thread::sm_Id; - - Thread::Thread (Weaver *parent) - : TQThread (), - m_parent ( parent ), - m_id ( makeId() ) - { - } - - Thread::~Thread() - { - } - - unsigned int Thread::makeId() - { - static TQMutex mutex; - TQMutexLocker l (&mutex); - - return ++sm_Id; - } - - unsigned int Thread::id() const - { - return m_id; - } - - void Thread::run() - { - Job *job = 0; - - post ( Event::ThreadStarted ); - - while (true) - { - debug ( 3, "Thread::run [%u]: trying to execute the next job.\n", id() ); - - job = m_parent->applyForWork ( this, job ); - - if (job == 0) - { - break; - } else { - post ( Event::JobStarted, job ); - job->execute (this); - post ( Event::JobFinished, job ); - } - } - - post ( Event::ThreadExiting ); - } - - void Thread::post (Event::Action a, Job *j) - { - m_parent->post ( a, this, j); - } - - void Thread::msleep(unsigned long msec) - { - TQThread::msleep(msec); - } - - Weaver::Weaver(TQObject* parent, const char* name, - int inventoryMin, int inventoryMax) - : TQObject(parent, name), - m_active(0), - m_inventoryMin(inventoryMin), - m_inventoryMax(inventoryMax), - m_shuttingDown(false), - m_running (false), - m_suspend (false), - m_mutex ( new TQMutex(true) ) - { - lock(); - - for ( int count = 0; count < m_inventoryMin; ++count) - { - Thread *th = new Thread(this); - m_inventory.append(th); - // this will idle the thread, waiting for a job - th->start(); - - emit (threadCreated (th) ); - } - - unlock(); - } - - Weaver::~Weaver() - { - lock(); - - debug ( 1, "Weaver dtor: destroying inventory.\n" ); - - m_shuttingDown = true; - - unlock(); - - m_jobAvailable.wakeAll(); - - // problem: Some threads might not be asleep yet, just finding - // out if a job is available. Those threads will suspend - // waiting for their next job (a rare case, but not impossible). - // Therefore, if we encounter a thread that has not exited, we - // have to wake it again (which we do in the following for - // loop). - - for ( Thread *th = m_inventory.first(); th; th = m_inventory.next() ) - { - if ( !th->finished() ) - { - m_jobAvailable.wakeAll(); - th->wait(); - } - - emit (threadDestroyed (th) ); - delete th; - - } - - m_inventory.clear(); - - delete m_mutex; - - debug ( 1, "Weaver dtor: done\n" ); - - } - - void Weaver::lock() - { - debug ( 3 , "Weaver::lock: lock (mutex is %s).\n", - ( m_mutex->locked() ? "locked" : "not locked" ) ); - m_mutex->lock(); - } - - void Weaver::unlock() - { - m_mutex->unlock(); - - debug ( 3 , "Weaver::unlock: unlock (mutex is %s).\n", - ( m_mutex->locked() ? "locked" : "not locked" ) ); - } - - int Weaver::threads () const - { - TQMutexLocker l (m_mutex); - return m_inventory.count (); - } - - void Weaver::enqueue(Job* job) - { - lock(); - - m_assignments.append(job); - m_running = true; - - unlock(); - - assignJobs(); - } - - void Weaver::enqueue (TQPtrList jobs) - { - lock(); - - for ( Job * job = jobs.first(); job; job = jobs.next() ) - { - m_assignments.append (job); - } - - unlock(); - - assignJobs(); - } - - bool Weaver::dequeue ( Job* job ) - { - TQMutexLocker l (m_mutex); - return m_assignments.remove (job); - } - - void Weaver::dequeue () - { - TQMutexLocker l (m_mutex); - m_assignments.clear(); - } - - void Weaver::suspend (bool state) - { - lock(); - - if (state) - { - // no need to wake any threads here - m_suspend = true; - if ( m_active == 0 && isEmpty() ) - { // instead of waking up threads: - post (Event::Suspended); - } - } else { - m_suspend = false; - // make sure we emit suspended () even if all threads are sleeping: - assignJobs (); - debug (2, "Weaver::suspend: queueing resumed.\n" ); - } - - unlock(); - } - - void Weaver::assignJobs() - { - m_jobAvailable.wakeAll(); - } - - bool Weaver::event (TQEvent *e ) - { - if ( e->type() >= TQEvent::User ) - { - - if ( e->type() == Event::type() ) - { - Event *event = (Event*) e; - - switch (event->action() ) - { - case Event::JobFinished: - if ( event->job() !=0 ) - { - emit (jobDone (event->job() ) ); - } - break; - case Event::Finished: - emit ( finished() ); - break; - case Event::Suspended: - emit ( suspended() ); - break; - case Event::ThreadSuspended: - if (!m_shuttingDown ) - { - emit (threadSuspended ( event->thread() ) ); - } - break; - case Event::ThreadBusy: - if (!m_shuttingDown ) - { - emit (threadBusy (event->thread() ) ); - } - break; - default: - break; - } - - if ( event->job() !=0 ) - { - event->job()->processEvent (event); - } - } else { - debug ( 0, "Weaver::event: Strange: received unknown user event.\n" ); - } - return true; - } else { - // others - please make sure we are a TQObject! - return TQObject::event ( e ); - } - } - - void Weaver::post (Event::Action a, Thread* t, Job* j) - { - Event *e = new Event ( a, t, j); - TQApplication::postEvent (this, e); - } - - bool Weaver::isEmpty() const - { - TQMutexLocker l (m_mutex); - return m_assignments.count()==0; - } - - Job* Weaver::applyForWork(Thread *th, Job* previous) - { - Job *rc = 0; - bool lastjob = false; - bool suspended = false; - - while (true) - { - lock(); - - if (previous != 0) - { // cleanup and send events: - --m_active; - - debug ( 3, "Weaver::applyForWork: job done, %i jobs left, " - "%i active jobs left.\n", - queueLength(), m_active ); - - if ( m_active == 0 && isEmpty() ) - { - lastjob = true; - m_running = false; - post (Event::Finished); - debug ( 3, "Weaver::applyForWork: last job.\n" ); - } - - if (m_active == 0 && m_suspend == true) - { - suspended = true; - post (Event::Suspended); - debug ( 2, "Weaver::applyForWork: queueing suspended.\n" ); - } - - m_jobFinished.wakeOne(); - } - - previous = 0; - - if (m_shuttingDown == true) - { - unlock(); - - return 0; - } else { - if ( !isEmpty() && m_suspend == false ) - { - rc = m_assignments.getFirst(); - m_assignments.removeFirst (); - ++m_active; - - debug ( 3, "Weaver::applyForWork: job assigned, " - "%i jobs in queue (%i active).\n", - m_assignments.count(), m_active ); - unlock(); - - post (Event::ThreadBusy, th); - - return rc; - } else { - unlock(); - - post (Event::ThreadSuspended, th); - m_jobAvailable.wait(); - } - } - } - } - - int Weaver::queueLength() - { - TQMutexLocker l (m_mutex); - return m_assignments.count(); - } - - bool Weaver::isIdle () const - { - TQMutexLocker l (m_mutex); - return isEmpty() && m_active == 0; - } - - void Weaver::finish() - { - while ( !isIdle() ) - { - debug (2, "Weaver::finish: not done, waiting.\n" ); - m_jobFinished.wait(); - } - debug (1, "Weaver::finish: done.\n\n\n" ); - } - -} -} - -#include "weaver.moc" diff --git a/libkdepim/weaver.h b/libkdepim/weaver.h deleted file mode 100644 index 8e82b5811..000000000 --- a/libkdepim/weaver.h +++ /dev/null @@ -1,451 +0,0 @@ -/* -*- C++ -*- - - This file declares the Weaver, Job and Thread classes. - - $ Author: Mirko Boehm $ - $ Copyright: (C) 2004, Mirko Boehm $ - $ Contact: mirko@kde.org - http://www.kde.org - http://www.hackerbuero.org $ - $ License: LGPL with the following explicit clarification: - This code may be linked against any version of the TQt toolkit - from Troll Tech, Norway. $ - -*/ - -#ifndef WEAVER_H -#define WEAVER_H - -extern "C" -{ -#include -#include -#include -} - -#include -#include -#include -#include -#include -#include - -#include - -namespace KPIM { -namespace ThreadWeaver { - - /** This method prints a text message on the screen, if debugging is - enabled. Otherwise, it does nothing. The message is thread safe, - therefore providing that the messages appear in the order they where - issued by the different threads. - All messages are suppressed when Debug is false. All messages with a - lower importance (higher number) than DebugLevel will be suppressed, - too. Debug level 0 messages will always be printed as long as - Debug is true. - We use our own debugging method, since debugging threads is a more - complicated experience than debugging single threaded - contexts. This might change in future in the way that debug - prints it's messages to another logging facility provided by - the platform. - Use setDebugLevel () to integrate adapt debug () to your platform. - */ - - KDE_EXPORT extern bool Debug; - KDE_EXPORT extern int DebugLevel; - - KDE_EXPORT inline void setDebugLevel (bool debug, int level) - { - Debug = debug; - DebugLevel = level; - } - - KDE_EXPORT inline void debug(int severity, const char * cformat, ...) -#ifdef __GNUC__ - __attribute__ ( (format (printf, 2, 3 ) ) ) -#endif -; - - KDE_EXPORT inline void debug(int severity, const char * cformat, ...) - { - if ( Debug == true && ( severity<=DebugLevel || severity == 0) ) - { - static TQMutex mutex; - TQString text; - - mutex.lock(); - va_list ap; - va_start( ap, cformat ); - vprintf (cformat, ap); - va_end (ap); - mutex.unlock(); - } - } - - - class Thread; - class Job; - - /** A class to represent the events threads generate and send to the - Weaver object. Examples include the start or end of the processing of a - job. Threads create the event objects and discard them after posting - the event, since the event receiver will assume ownership of the - event. - Events are associated to the sending thread and possibly to a - processed job. - - Note: Do not create and use SPR/APR events, use Job::triggerSPR or - Job::triggerAPR to create the requests. */ - - class KDE_EXPORT Event : public TQCustomEvent - { - public: - enum Action { - NoAction = 0, - Finished, /// All jobs in the queue are done. - Suspended, /// Thread queueing halted. - ThreadStarted, - ThreadExiting, - ThreadBusy, - ThreadSuspended, - JobStarted, - JobFinished, - JobSPR, /// Synchronous Process Request - JobAPR /// Asynchronous Process Request - }; - Event ( Action = NoAction, Thread * = 0, Job *job = 0); - /** Return the (custom defined) event type. */ - static int type (); - /** The ID of the sender thread. */ - Thread* thread () const; - /** The associated job. */ - Job* job () const; - /** The action. */ - Action action () const; - private: - Action m_action; - Thread *m_thread; - Job *m_job; - static const int Type; - }; - - /** A Job is a simple abstraction of an action that is to be - executed in a thread context. - It is essential for the ThreadWeaver library that as a kind of - convention, the different creators of Job objects do not touch the - protected data members of the Job until somehow notified by the - Job. See the SPR signal for an example. - - Jobs may emit process requests as signals. Consider process requests - as a kind of synchronized call to the main thread. - Process Requests are a generic means for Job derivate programmers to have - the jobs interact with the creators (in the main thread) during - processing time. To avoid race - conditions and extensive locking and unlocking, the thread executing the - job is suspended during the period needed to process the request. - - There are two kinds of process requests (we introduce abbreviations, - also in the signal names and the code, - only to save typing). Both are emitted by signals in the main thread: - - Synchronous Process Requests (SPR): Synchronous requests expect that the - complete request is performed in the slots connected to the signals. For - example, to update a widget according to the progress of the job, a SPR - may be used. In such cases, the Job's execution will be resumed - immediately after the signal has been processed. - - Asynchronous Process Requests (APR): For APRs, the job emitting the - signal does not assume anything about the amount of time needed to - perform the operation. Therefore, the thread is not waked after the - signal returns. The creator has to wake to thread whenever it is - ready by calling the wakeAPR method. - - Note: When using an APR, you better make sure to receive the signal - with some object, otherwise the calling thread will block forever! - */ - class KDE_EXPORT Job : public TQObject - { - Q_OBJECT - TQ_OBJECT - public: - /** Construct a Job object. */ - Job(TQObject* parent=0, const char* name=0); - - /** Destructor. */ - virtual ~Job(); - - /** Perform the job. The thread in which this job is executed - is given as a parameter. - Do not overload this method to create your own Job - implementation, overload run(). */ - virtual void execute(Thread*); - - /** Returns true if the jobs's execute method finished. */ - virtual bool isFinished() const; - - /** Wake the thread after an APR has been processed. */ - void wakeAPR (); - - /** Process events related to this job (created by the processing - thread or the weaver or whoever). */ - virtual void processEvent ( Event* ); - - signals: - /** This signal is emitted when a thread starts to process a job. */ - void started (); - /** This signal is emitted when a job has been finished. */ - void done (); - /** This signal is emitted when the job needs some operation done by - the main thread (usually the creator of the job). - It is important to understand that the emitting thread is - suspended until the signal returns. - When - the operation requested has been performed and this signal is - finished, the thread is automatically waked. - What operation needs to be performed has to be negotiated between - the two objects. - Note: This signal is an attempt to provide job programmers with a - generic way to interact while the job is executed. I am interested - in feedback about it's use. */ - void SPR (); - /** Perform an Asynchronous Process Request. See SPR and the generic - Job documentation for a comparison. */ - void APR (); - protected: - /** Lock this Job's mutex. */ - void lock(); - /** Unlock this Job's mutex. */ - void unlock(); - /** The method that actually performs the job. It is called from - execute(). This method is the one to overload it with the - job's task. */ - virtual void run () = 0; - /** Return the thread that executes this job. - Returns zero of the job is not currently executed. */ - Thread *thread(); - /** Call with status = true to mark this job as done. */ - virtual void setFinished(bool status); - /** Trigger a SPR. - This emits a signal in the main thread indicating the necessity of - a synchronized operation. */ - void triggerSPR (); - /** Trigger an APR. - This emit a signal in the main thread indicating the necessity of - an unsynchronized operation. - The calling thread needs to ensure to wake the thread when the - operation is done. */ - void triggerAPR (); - - bool m_finished; - - TQMutex *m_mutex; - - Thread * m_thread; - - TQWaitCondition *m_wc; - }; - - class Weaver; - - /** The class Thread is used to represent the worker threads in - the weaver's inventory. It is not meant to be overloaded. */ - class KDE_EXPORT Thread : public TQThread - { - public: - /** Create a thread. - These thread objects are only used inside the Weaver parent - object. */ - Thread(Weaver *parent); - - /** The destructor. */ - ~Thread(); - - /** Overloaded to execute the assigned job. - This will NOT return until shutdown() is called. The - thread will try to execute one job after the other, asking - the Weaver parent for a new job when the assigned one is - finished. - If no jobs are available, the thread will suspend. - After shutdown() is called, the thread will end as soon as - the currently assigned job is done. - */ - void run(); - - /* Provide the msleep() method (protected in TQThread) to be - available for executed jobs. */ - void msleep(unsigned long msec); - - /** Returns the thread id. - This id marks the respective Thread object, and must - therefore not be confused with, e.g., the pthread thread - ID. */ - unsigned int id() const; - - /** Post an event, will be received and processed by the Weaver. */ - void post (Event::Action, Job* = 0); - - private: - Weaver *m_parent; - - const unsigned int m_id; - - static unsigned int sm_Id; - - static unsigned int makeId(); - }; - - /** A weaver is the manager of worker threads (Thread objects) to - which it assigns jobs from it's queue. */ - class KDE_EXPORT Weaver : public TQObject - { - Q_OBJECT - TQ_OBJECT - public: - Weaver (TQObject* parent=0, const char* name=0, - int inventoryMin = 4, // minimal number of provided threads - int inventoryMax = 32); // maximum number of provided threads - virtual ~Weaver (); - /** Add a job to be executed. */ - virtual void enqueue (Job*); - /** Enqueue all jobs in the given list. - This is an atomic operation, no jobs will start - before all jobs in the list are enqueued. - If you need a couple of jobs done and want to receive the - finished () signal afterwards, use this method to queue - them. Otherwise, when enqueueing your jobs - individually, there is a chance that you receive more than - one finished signal. */ - void enqueue (TQPtrList jobs); - /** Remove a job from the queue. - If the job qas queued but not started so far, it is simple - removed from the queue. For now, it is unsupported to - dequeue a job once its execution has started. - For that case, you will have to provide a method to interrupt your - job's execution (and receive the done signal). - Returns true if the job has been dequeued, false if the - job has already been started or is not found in the - queue. */ - virtual bool dequeue (Job*); - /** Remove all queued jobs. - Please note that this will not kill the threads, therefore - all jobs that are being processed will be continued. */ - virtual void dequeue (); - /** Get notified when a thread has finished a job. - This is done automatically. */ - // virtual void jobFinished(Thread *); - /** Finish all queued operations, then return. - This method is used in imperative programs that cannot react on - events to have the controlling (main) thread wait wait for the - jobs to finish. - Warning: This will suspend your thread! - Warning: If your jobs enter for example an infinite loop, this - will never return! */ - virtual void finish(); - /** Suspend job execution if state = true, otherwise resume - job execution if it was suspended. - When suspending, all threads are allowed to finish the - currently assigned job but will not receive a new - assignment. - When all threads are done processing the assigned job, the - signal suspended will() be emitted. - If you call suspend (true) and there are no jobs left to - be done, you will immidiately receive the suspended() - signal. */ - virtual void suspend (bool state); - /** Is the queue empty? */ - bool isEmpty () const; - /** Is the weaver idle? - The weaver is idle if no jobs are queued and no jobs are processed - by the threads (m_active is zero). */ - bool isIdle () const; - /** Returns the number of pending jobs. */ - int queueLength (); - /** Assign a job to the calling thread. - This is supposed to be called from the Thread objects in - the inventory. - Returns 0 if the weaver is shutting down, telling the - calling thread to finish and exit. - If no jobs are available and shut down is not in progress, - the calling thread is suspended until either condition is - met. - In previous, threads give the job they have completed. If this is - the first job, previous is zero. */ - virtual Job* applyForWork (Thread *thread, Job *previous); - /** Lock the mutex for this weaver. The threads in the - inventory need to lock the weaver's mutex to synchronize - the job management. */ - void lock (); - /** Unlock. See lock(). */ - void unlock (); - /** Post an event that is handled by this object, but in the main - (GUI) thread. Different threads may use this method to communicate - with the main thread. - thread and job mark the objects associated with this event. */ - void post (Event::Action, Thread* = 0, Job* = 0); - /** Returns the current number of threads in the inventory. */ - int threads () const; - signals: - /** This signal is emitted when the Weaver has finished ALL currently - queued jobs. - If a number of jobs is enqueued sequentially, this signal might be - emitted a couple of times (what happens is that all already queued - jobs have been processed while you still add new ones). This is - not a bug, but the intended behaviour. */ - void finished (); - /** Thread queueing has been suspended. - When suspend is called with state = true, all threads are - allowed to finish their job. When the last thread - finished, this signal is emitted. */ - void suspended (); - /** This signal is emitted when a job is done. It is up to the - programmer if this signal or the done signal of the job is more - handy. */ - void jobDone (Job*); -// The following signals are used mainly for debugging purposes. - void threadCreated (Thread *); - void threadDestroyed (Thread *); - void threadBusy (Thread *); - void threadSuspended (Thread *); - - protected: - /** Schedule enqueued jobs to be executed by idle threads. - This will try to distribute as many jobs as possible - to all idle threads. */ - void assignJobs(); - /** Check incoming events for user defined ones. The threads use user - defined events to communicate with the Weaver. */ - bool event ( TQEvent* ); - /** The thread inventory. */ - TQPtrList m_inventory; - /** The job queue. */ - TQPtrList m_assignments; - /** The number of jobs that are assigned to the worker - threads, but not finished. */ - int m_active; - /** Stored setting. */ - int m_inventoryMin; - /** Stored setting . */ - int m_inventoryMax; - /** Wait condition all idle or done threads wait for. */ - TQWaitCondition m_jobAvailable; - /** Wait for a job to finish. */ - TQWaitCondition m_jobFinished; - /** Indicates if the weaver is shutting down and exiting it's - threads. */ - bool m_shuttingDown; - /** m_running is set to true when a job is enqueued and set to false - when the job finishes that was the last in the queue. - E.g., this will flip from false to true to false when you - continuously enqueue one single job. */ - bool m_running; - /** If m_suspend is true, no new jobs will be assigned to - threads. - Jobs may be queued, but will not be processed until suspend - (false) is called. */ - bool m_suspend; - private: - /** Mutex to serialize operations. */ - TQMutex *m_mutex; - }; -} // namespace ThreadWeaver -} // namespace KPIM - -#endif // defined WEAVER_H diff --git a/libkdepim/weaverextensions.cpp b/libkdepim/weaverextensions.cpp deleted file mode 100644 index 9859b6d6b..000000000 --- a/libkdepim/weaverextensions.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- C++ -*- - - This file implements the Weaver Extensions basics. - - $ Author: Mirko Boehm $ - $ Copyright: (C) 2004, Mirko Boehm $ - $ Contact: mirko@kde.org - http://www.kde.org - http://www.hackerbuero.org $ - $ License: LGPL with the following explicit clarification: - This code may be linked against any version of the TQt toolkit - from Troll Tech, Norway. $ - -*/ - -#include "weaverextensions.h" -#include "weaver.h" - -namespace KPIM { -namespace ThreadWeaver { - - WeaverExtension::WeaverExtension ( TQObject *parent, const char *name) - : TQObject (parent, name) - { - } - - void WeaverExtension::attach (Weaver *w) - { - connect (w, TQT_SIGNAL (threadCreated (Thread *) ), - TQT_SLOT (threadCreated (Thread *) ) ); - connect (w, TQT_SIGNAL (threadDestroyed (Thread *) ), - TQT_SLOT (threadDestroyed (Thread *) ) ); - connect (w, TQT_SIGNAL (threadBusy (Thread *) ), - TQT_SLOT (threadBusy (Thread *) ) ); - connect (w, TQT_SIGNAL (threadSuspended (Thread *) ), - TQT_SLOT (threadSuspended (Thread *) ) ); - } - - WeaverExtension::~WeaverExtension() - { - } - - void WeaverExtension::threadCreated (Thread *) - { - } - - void WeaverExtension::threadDestroyed (Thread *) - { - } - - void WeaverExtension::threadBusy (Thread *) - { - } - - void WeaverExtension::threadSuspended (Thread *) - { - } - -} -} - -#include "weaverextensions.moc" diff --git a/libkdepim/weaverextensions.h b/libkdepim/weaverextensions.h deleted file mode 100644 index 26bccadea..000000000 --- a/libkdepim/weaverextensions.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- C++ -*- - - This file declares the Weaver Extensions basics. - - $ Author: Mirko Boehm $ - $ Copyright: (C) 2004, Mirko Boehm $ - $ Contact: mirko@kde.org - http://www.kde.org - http://www.hackerbuero.org $ - $ License: LGPL with the following explicit clarification: - This code may be linked against any version of the TQt toolkit - from Troll Tech, Norway. $ - -*/ - -#ifndef WEAVEREXTENSIONS_H -#define WEAVEREXTENSIONS_H - -#include - -namespace KPIM { -namespace ThreadWeaver { - - class Weaver; - class Thread; - - /** A WeaverExtension can be attached to an existing Weaver object and - will then receive signals on actions the Weaver takes, like starting - to process a specific job, assigning a job to a thread or suspending a - thread. It can be used to monitor the state of a program, but also, - for example, to provide visualization of the Weaver's work load in GUI - programs. Derive from it to actually create an extension. */ - class WeaverExtension : public TQObject - { - Q_OBJECT - TQ_OBJECT - public: - WeaverExtension ( TQObject *parent = 0, const char *name = 0); - /** Attach() is a convenience method that will connect all our - slots to signals emitted by the weaver. It is also possible to - avoid attach() and only connect necessary signals. */ - void attach (Weaver *); - virtual ~WeaverExtension() = 0; - public slots: - // these methods are implemented, but do nothing in the default configuration - // a thread is created: - virtual void threadCreated (Thread *); - // a thread is destroyed: - virtual void threadDestroyed (Thread *); - // the thread is processing a job - virtual void threadBusy (Thread *); - // the thread is suspended and will be waked when jobs become - // available - virtual void threadSuspended (Thread *); - }; - -} // namespace ThreadWeaver -} - -#endif // WEAVEREXTENSIONS_H diff --git a/libkdepim/weaverlogger.cpp b/libkdepim/weaverlogger.cpp deleted file mode 100644 index e5164c804..000000000 --- a/libkdepim/weaverlogger.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- C++ -*- - - This file implements the Thread Logger. - - $ Author: Mirko Boehm $ - $ Copyright: (C) 2004, Mirko Boehm $ - $ Contact: mirko@kde.org - http://www.kde.org - http://www.hackerbuero.org $ - $ License: LGPL with the following explicit clarification: - This code may be linked against any version of the TQt toolkit - from Troll Tech, Norway. $ - -*/ - -#include -#include "weaverlogger.h" - -namespace KPIM { -namespace ThreadWeaver { - - extern void debug(int severity, const char * cformat, ...); - - WeaverThreadLogger::WeaverThreadLogger( TQObject *parent, const char *name) - : WeaverExtension (parent, name) - { - } - - WeaverThreadLogger::~WeaverThreadLogger () - { - } - - void WeaverThreadLogger::threadCreated (KPIM::ThreadWeaver::Thread *thread) - { - debug ( 1, "WeaverThreadLogger: thread (ID: %i) created.\n", - thread->id() ); - } - - void WeaverThreadLogger::threadDestroyed (KPIM::ThreadWeaver::Thread *thread) - { - debug ( 1, "WeaverThreadLogger: thread (ID: %i) destroyed.\n", - thread->id() ); - } - - void WeaverThreadLogger::threadBusy (KPIM::ThreadWeaver::Thread *thread) - { - debug ( 1, "WeaverThreadLogger: thread (ID: %i) is processing a job.\n", - thread->id() ); - } - - void WeaverThreadLogger::threadSuspended (KPIM::ThreadWeaver::Thread *thread) - { - debug ( 1, "WeaverThreadLogger: thread (ID: %i) suspended.\n", - thread->id() ); - } - -} -} - -#include "weaverlogger.moc" diff --git a/libkdepim/weaverlogger.h b/libkdepim/weaverlogger.h deleted file mode 100644 index d4d35ff4f..000000000 --- a/libkdepim/weaverlogger.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- C++ -*- - - This file declares the Thread Logger. - - $ Author: Mirko Boehm $ - $ Copyright: (C) 2004, Mirko Boehm $ - $ Contact: mirko@kde.org - http://www.kde.org - http://www.hackerbuero.org $ - $ License: LGPL with the following explicit clarification: - This code may be linked against any version of the TQt toolkit - from Troll Tech, Norway. $ - -*/ - -#ifndef WEAVERLOGGER_H -#define WEAVERLOGGER_H - -#include "weaverextensions.h" - -namespace KPIM { -namespace ThreadWeaver { - - /** A WeaverThreadLogger may be attached to a Weaver to gain debug - information about thread execution. */ - class WeaverThreadLogger : public WeaverExtension - { - Q_OBJECT - TQ_OBJECT - public: - WeaverThreadLogger( TQObject *parent = 0, const char *name = 0); - ~WeaverThreadLogger(); - void threadCreated (Thread *); - void threadDestroyed (Thread *); - void threadBusy (Thread *); - void threadSuspended (Thread *); - }; - -} -} - -#endif // WEAVERLOGGER_H diff --git a/libtdepim/CMakeLists.txt b/libtdepim/CMakeLists.txt new file mode 100644 index 000000000..19ca1d524 --- /dev/null +++ b/libtdepim/CMakeLists.txt @@ -0,0 +1,108 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +project( libtdepim ) + +include( ConfigureChecks.cmake ) + +tde_import( libkmime ) +tde_import( libkcal ) +tde_import( ktnef ) + +add_subdirectory( icons ) +add_subdirectory( pics ) +add_subdirectory( kpartsdesignerplugin ) +add_subdirectory( about ) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/libtdepim + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### headers ################################### + +install( FILES + tdepimmacros.h kpimprefs.h + DESTINATION ${INCLUDE_INSTALL_DIR}/kde ) + + +##### other data ################################ + +install( FILES pimemoticons.kcfg DESTINATION ${KCFG_INSTALL_DIR} ) + + +##### tdepimwidgets (module) #################### + +add_custom_command( OUTPUT tdepimwidgets.cpp + COMMAND + ${KDE3_MAKEKDEWIDGETS_EXECUTABLE} + -o tdepimwidgets.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tdepim.widgets + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/tdepim.widgets ) + +set_source_files_properties( tdepimwidgets.cpp PROPERTIES COMPILE_FLAGS "-DQT_PLUGIN" ) + +tde_add_kpart( tdepimwidgets + SOURCES tdepimwidgets.cpp + LINK tdepim-shared + DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/designer +) + + +##### tdepim (shared) ########################### + +set( KDE3_DCOPIDL_EXECUTABLE ${KDE3_DCOPIDLNG_EXECUTABLE} ) + +tde_add_library( tdepim SHARED AUTOMOC + SOURCES + ktimeedit.cpp alarmclient.cpp kprefsdialog.cpp kpimprefs.cpp + categoryselectdialog_base.ui categoryselectdialog.cpp + categoryeditdialog_base.ui categoryeditdialog.cpp kdateedit.cpp + kimportdialog.cpp kvcarddrag.cpp sidebarextension.cpp + infoextension.cpp addressesdialog.cpp addresspicker.ui + addresseeview.cpp maillistdrag.cpp interfaces/MailTransportServiceIface.skel + interfaces/AddressBookServiceIface.skel kconfigpropagator.cpp kconfigwizard.cpp + weaver.cpp weaverextensions.cpp weaverlogger.cpp pluginloaderbase.cpp + addresseelineedit.cpp addresseelineedit.skel kdatepickerpopup.cpp + kfileio.cpp clicklineedit.cpp configmanager.cpp collectingprocess.cpp + ldapclient.cpp overlaywidget.cpp progressmanager.cpp progressdialog.cpp + statusbarprogresswidget.cpp ssllabel.cpp completionordereditor.cpp + resourceabc.cpp diffalgo.cpp addresseediffalgo.cpp calendardiffalgo.cpp + htmldiffalgodisplay.cpp ldapsearchdialog.cpp broadcaststatus.cpp + kresourceprefs.cpp kpixmapregionselectorwidget.cpp + kpixmapregionselectordialog.cpp kabcresourcecached.cpp + kxface.cpp kaccount.cpp kaddrbook.cpp kfoldertree.cpp kregexp3.cpp + kscoring.cpp kscoringeditor.cpp ksubscription.cpp kwidgetlister.cpp + linklocator.cpp qutf7codec.cpp recentaddresses.cpp spellingfilter.cpp + addresseeselector.cpp addresseeemailselection.cpp designerfields.cpp + kcmdesignerfields.cpp embeddedurlpage.cpp kincidencechooser.cpp + groupwarejob.cpp pimemoticons.kcfgc krsqueezedtextlabel.cpp + csshelper.cpp distributionlist.cpp kpimurlrequesterdlg.cpp + sendsmsdialog.cpp kmailcompletion.cpp + VERSION 1.0.0 + LINK kcal-shared kimproxy-shared kparts-shared qui + DESTINATION ${LIB_INSTALL_DIR} +) + + +##### install import cmake modules ############### + +tde_install_export( ) diff --git a/libtdepim/ConfigureChecks.cmake b/libtdepim/ConfigureChecks.cmake new file mode 100644 index 000000000..96e1e621a --- /dev/null +++ b/libtdepim/ConfigureChecks.cmake @@ -0,0 +1,10 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# diff --git a/libtdepim/Makefile.am b/libtdepim/Makefile.am new file mode 100644 index 000000000..b5db77f6f --- /dev/null +++ b/libtdepim/Makefile.am @@ -0,0 +1,71 @@ +SUBDIRS = cfgc interfaces tests icons pics kpartsdesignerplugin about + +INCLUDES = -I$(top_srcdir) $(all_includes) + +lib_LTLIBRARIES = libtdepim.la +libtdepim_la_SOURCES = \ + ktimeedit.cpp \ + alarmclient.cpp \ + kprefsdialog.cpp kpimprefs.cpp \ + categoryselectdialog_base.ui categoryselectdialog.cpp \ + categoryeditdialog_base.ui categoryeditdialog.cpp \ + kdateedit.cpp kimportdialog.cpp kvcarddrag.cpp \ + sidebarextension.cpp infoextension.cpp \ + addressesdialog.cpp addresspicker.ui addresseeview.cpp \ + maillistdrag.cpp MailTransportServiceIface.skel \ + AddressBookServiceIface.skel \ + kconfigpropagator.cpp kconfigwizard.cpp \ + weaver.cpp weaverextensions.cpp weaverlogger.cpp \ + pluginloaderbase.cpp addresseelineedit.cpp addresseelineedit.skel \ + kdatepickerpopup.cpp kfileio.cpp \ + clicklineedit.cpp configmanager.cpp \ + collectingprocess.cpp ldapclient.cpp \ + overlaywidget.cpp progressmanager.cpp progressdialog.cpp \ + statusbarprogresswidget.cpp ssllabel.cpp completionordereditor.cpp \ + resourceabc.cpp diffalgo.cpp addresseediffalgo.cpp calendardiffalgo.cpp \ + htmldiffalgodisplay.cpp ldapsearchdialog.cpp broadcaststatus.cpp kresourceprefs.cpp \ + kpixmapregionselectorwidget.cpp kpixmapregionselectordialog.cpp \ + kabcresourcecached.cpp kxface.cpp \ + kaccount.cpp kaddrbook.cpp kfoldertree.cpp kregexp3.cpp \ + kscoring.cpp kscoringeditor.cpp ksubscription.cpp kwidgetlister.cpp \ + linklocator.cpp qutf7codec.cpp \ + recentaddresses.cpp spellingfilter.cpp \ + addresseeselector.cpp addresseeemailselection.cpp \ + designerfields.cpp kcmdesignerfields.cpp \ + embeddedurlpage.cpp kincidencechooser.cpp \ + groupwarejob.cpp pimemoticons.kcfgc \ + krsqueezedtextlabel.cpp csshelper.cpp distributionlist.cpp \ + kpimurlrequesterdlg.cpp sendsmsdialog.cpp kmailcompletion.cpp + +MailTransportServiceIface_DCOPIDLNG = true +MailTransportServiceIface_DIR = $(srcdir)/interfaces + +AddressBookServiceIface_DIR = $(srcdir)/interfaces + +libtdepim_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 1:0:0 $(LIB_QT) -ltdecore +libtdepim_la_LIBADD = $(top_builddir)/libkcal/libkcal.la \ + $(top_builddir)/libemailfunctions/libemailfunctions.la \ + $(LIB_KIO) $(LIB_KABC) $(LIB_KPARTS) $(LIB_KIMPROXY) $(LIB_POLL) -lqui +# $top_builddir)/libtdepim/resources/libkpimresources.la + +include_HEADERS = tdepimmacros.h kpimprefs.h + +AM_CXXFLAGS = -DQT_PLUGIN +kde_widget_LTLIBRARIES = tdepimwidgets.la +tdepimwidgets_la_LDFLAGS = $(KDE_PLUGIN) -module $(all_libraries) $(LIB_QT) -ltdecore +tdepimwidgets_la_LIBADD = $(LIB_KIO) libtdepim.la +tdepimwidgets_la_SOURCES = tdepimwidgets.cpp + +tdepimwidgets.cpp: $(srcdir)/tdepim.widgets + $(MAKEKDEWIDGETS) -o tdepimwidgets.cpp $(srcdir)/tdepim.widgets + +CLEANFILES = tdepimwidgets.cpp + +kde_kcfg_DATA = pimemoticons.kcfg + +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) ../libkpimidentities/*.cpp ../libemailfunctions/*.cpp *.cpp -o $(podir)/libtdepim.pot + +include $(top_srcdir)/admin/Doxyfile.am diff --git a/libtdepim/README b/libtdepim/README new file mode 100644 index 000000000..dfaefe79f --- /dev/null +++ b/libtdepim/README @@ -0,0 +1,36 @@ +This directory contains the library for the kdenetwork package. + +Contents: + ksieve_* The beginning of a Sieve parser and interpreter + library. + Maintainer: Marc Mutz + License: GPL v2 + + kscoring/ scoring engine & rule editor + kscoringeditor Maintainer: Mathias Waack + License: GPL + + qutf7codec A QTextCodec for UTF-7. + Will hopefully be assimilated by the trolls. + Maintainer: Marc Mutz + License: GPL v2 + + kwidgetlister a small and nice widget which enables one to dynamically + add or delete widgets. Used by the filter and scoring + dialogs, which needs to display for instance a variable + number of conditions. + Maintainer: Marc Mutz + License: GPL v2 + + kregexp3 A KRegExp replacement based on QRegExp from Qt3.x + Maintainer: Marc Mutz + License: GPL + + kfoldertree/ Base classes for KNode's and KMail's folder lists, + ksubscription/ subscription dialogs and accounts. + kaccount Maintainer: Carsten Burghardt + License: LGPL v2 + + cryptplugwrapper* C++ wrapper around the CryptPlug interface. + Maintainer: Karl-Heinz Zimmer + License: GPL v2 diff --git a/libtdepim/TODO b/libtdepim/TODO new file mode 100644 index 000000000..f6c5214c3 --- /dev/null +++ b/libtdepim/TODO @@ -0,0 +1,10 @@ +KConfigPropagator: + +- Title for all changes. +- Write DTD for extended kcfg file. +- Check validity of rules against the installed kcfg files. +- Turn public members of Change, Rule, Condition into proper accessors/mutators + +KConfigWizard: + +- More pretty changes view. diff --git a/libtdepim/about/CMakeLists.txt b/libtdepim/about/CMakeLists.txt new file mode 100644 index 000000000..97a53d764 --- /dev/null +++ b/libtdepim/about/CMakeLists.txt @@ -0,0 +1,19 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +install( FILES + bar-bottom-left.png bar-top-right.png bar-bottom-middle.png bottom-left.png + box-middle-left.png top-left.png bar-bottom-right.png bottom-middle.png + box-middle-right.png top-middle.png bar-middle-left.png bottom-right.png + box-top-left.png bar-middle-right.png box-bottom-left.png box-top-middle.png + bar-top-left.png box-bottom-middle.png box-top-right.png bar-top-middle.png + box-bottom-right.png kde_infopage.css kde_infopage_rtl.css + DESTINATION ${DATA_INSTALL_DIR}/libtdepim/about ) diff --git a/libtdepim/about/Makefile.am b/libtdepim/about/Makefile.am new file mode 100644 index 000000000..6481c5bcb --- /dev/null +++ b/libtdepim/about/Makefile.am @@ -0,0 +1,9 @@ + +tdepim_infopage_datadir = $(kde_datadir)/libtdepim/about +tdepim_infopage_data_DATA = \ + bar-bottom-left.png bar-top-right.png bar-bottom-middle.png bottom-left.png \ + box-middle-left.png top-left.png bar-bottom-right.png bottom-middle.png \ + box-middle-right.png top-middle.png bar-middle-left.png bottom-right.png \ + box-top-left.png bar-middle-right.png box-bottom-left.png box-top-middle.png \ + bar-top-left.png box-bottom-middle.png box-top-right.png bar-top-middle.png \ + box-bottom-right.png kde_infopage.css kde_infopage_rtl.css diff --git a/libtdepim/about/bar-bottom-left.png b/libtdepim/about/bar-bottom-left.png new file mode 100644 index 000000000..30a323592 Binary files /dev/null and b/libtdepim/about/bar-bottom-left.png differ diff --git a/libtdepim/about/bar-bottom-middle.png b/libtdepim/about/bar-bottom-middle.png new file mode 100644 index 000000000..b2ebbbed5 Binary files /dev/null and b/libtdepim/about/bar-bottom-middle.png differ diff --git a/libtdepim/about/bar-bottom-right.png b/libtdepim/about/bar-bottom-right.png new file mode 100644 index 000000000..e664e1511 Binary files /dev/null and b/libtdepim/about/bar-bottom-right.png differ diff --git a/libtdepim/about/bar-middle-left.png b/libtdepim/about/bar-middle-left.png new file mode 100644 index 000000000..72fda9ec2 Binary files /dev/null and b/libtdepim/about/bar-middle-left.png differ diff --git a/libtdepim/about/bar-middle-right.png b/libtdepim/about/bar-middle-right.png new file mode 100644 index 000000000..d482ab178 Binary files /dev/null and b/libtdepim/about/bar-middle-right.png differ diff --git a/libtdepim/about/bar-top-left.png b/libtdepim/about/bar-top-left.png new file mode 100644 index 000000000..b05fd216c Binary files /dev/null and b/libtdepim/about/bar-top-left.png differ diff --git a/libtdepim/about/bar-top-middle.png b/libtdepim/about/bar-top-middle.png new file mode 100644 index 000000000..387f81017 Binary files /dev/null and b/libtdepim/about/bar-top-middle.png differ diff --git a/libtdepim/about/bar-top-right.png b/libtdepim/about/bar-top-right.png new file mode 100644 index 000000000..a552ff91d Binary files /dev/null and b/libtdepim/about/bar-top-right.png differ diff --git a/libtdepim/about/bottom-left.png b/libtdepim/about/bottom-left.png new file mode 100644 index 000000000..78c9fece3 Binary files /dev/null and b/libtdepim/about/bottom-left.png differ diff --git a/libtdepim/about/bottom-middle.png b/libtdepim/about/bottom-middle.png new file mode 100644 index 000000000..41e52dd8a Binary files /dev/null and b/libtdepim/about/bottom-middle.png differ diff --git a/libtdepim/about/bottom-right.png b/libtdepim/about/bottom-right.png new file mode 100644 index 000000000..ef81b04a8 Binary files /dev/null and b/libtdepim/about/bottom-right.png differ diff --git a/libtdepim/about/box-bottom-left.png b/libtdepim/about/box-bottom-left.png new file mode 100644 index 000000000..ef68ffa6a Binary files /dev/null and b/libtdepim/about/box-bottom-left.png differ diff --git a/libtdepim/about/box-bottom-middle.png b/libtdepim/about/box-bottom-middle.png new file mode 100644 index 000000000..2bcd3ea03 Binary files /dev/null and b/libtdepim/about/box-bottom-middle.png differ diff --git a/libtdepim/about/box-bottom-right.png b/libtdepim/about/box-bottom-right.png new file mode 100644 index 000000000..993e1a6b0 Binary files /dev/null and b/libtdepim/about/box-bottom-right.png differ diff --git a/libtdepim/about/box-middle-left.png b/libtdepim/about/box-middle-left.png new file mode 100644 index 000000000..62a720178 Binary files /dev/null and b/libtdepim/about/box-middle-left.png differ diff --git a/libtdepim/about/box-middle-right.png b/libtdepim/about/box-middle-right.png new file mode 100644 index 000000000..aa94c0c90 Binary files /dev/null and b/libtdepim/about/box-middle-right.png differ diff --git a/libtdepim/about/box-top-left.png b/libtdepim/about/box-top-left.png new file mode 100644 index 000000000..3825a7de4 Binary files /dev/null and b/libtdepim/about/box-top-left.png differ diff --git a/libtdepim/about/box-top-middle.png b/libtdepim/about/box-top-middle.png new file mode 100644 index 000000000..79e714cba Binary files /dev/null and b/libtdepim/about/box-top-middle.png differ diff --git a/libtdepim/about/box-top-right.png b/libtdepim/about/box-top-right.png new file mode 100644 index 000000000..45ba201ea Binary files /dev/null and b/libtdepim/about/box-top-right.png differ diff --git a/libtdepim/about/kde_infopage.css b/libtdepim/about/kde_infopage.css new file mode 100644 index 000000000..69085675e --- /dev/null +++ b/libtdepim/about/kde_infopage.css @@ -0,0 +1,239 @@ + +/* + * text styles + */ + +img {margin: 0px; padding: 0px} +body {margin: 0px; padding: 0px; background-color: #418ade;} +.bar_text a {color: #008;} + +#subtext { + font-size: 10pt; + font-style: italic; +} + +#nextlink { + margin-bottom: 0px; + text-align: right; + font-size: 10pt; +} + +/* + * the header + */ + +#header { + background-image: url(top-middle.png); + width: 100%; + height: 131px; +} + +#headerL { + position: absolute; + background-image: url(top-left.png); + left: 0px; + height: 131px; + width: 147px; + z-index: 1; +} + +#headerR { + position: absolute; + right: 0px; +} + +/* title and tagline are part of the header diff */ +#title { + position: absolute; + top: 63px; + right: 100px; + margin-top: -1em; + text-align: right; + font-size: xx-large; + font-weight: bold; + text-shadow: #fff 0px 0px 5px; + color: #444; + z-index: 5; +} + +#tagline { + position: absolute; + top: 70px; + right: 100px; + text-align: right; + font-size: large; + font-weight: bold; + text-shadow: #fff 0px 0px 5px; + color: #444; + z-index: 5; +} + +/* + * the nav bar + */ + +#bar { + width: 100%; + background-color: #5babe5; + padding-top: 0.5ex; + border-bottom: 1px solid black; + padding-bottom: 0.5ex; +} + +#barCenter { + text-align: center; + color: #282828; + font-weight: bold; + font-size: small; +} + +#barCenter a.selected, #barCenter a.selected:hover { + color: #282828; + text-decoration: none; + text-shadow: #fff 0px 0px 5px; +} + + +#barCenter li a:link, #barCenter li a:visited, #barCenter li a:active { + color: #282828; + text-decoration: none; + text-shadow: none; +} + +#barCenter li a:hover { + color: #282828; + text-decoration: none; + text-shadow: #fff 0px 0px 6px; +} + +#barCenter ul { + margin: 0; + padding: 0; +} + +#barCenter li { + display: inline; +} + +#barCenter li:not(:first-child):before { /* Aren't css3 selectors great? */ + content: " · "; +} + +/* + * the main box + */ + +#box { + width: 90%; + margin-left: 5%; + margin-right: 5%; + margin-top: 10px; + margin-bottom: 10px; +} + +#boxT { + width: 100%; + height: 22px; +} + +#boxTL { + width: 25px; + height: 22px; + float: left; + background-image: url(box-top-left.png); +} + +#boxTR { + width: 25px; + height: 22px; + float: right; + background-image: url(box-top-right.png); +} + +#boxTC { + height: 22px; + margin-left: 25px; + margin-right: 25px; + background-image: url(box-top-middle.png); + background-repeat: repeat-x; +} + +#boxL { + background-image: url(box-middle-left.png); + background-repeat: repeat-y; + background-position: left; + padding-left: 20px; +} + +#boxCenter { + background-color: #dfe7f3; + background-position: center; + text-align: left; +} + +#boxR { + background-image: url(box-middle-right.png); + background-repeat: repeat-y; + background-position: right; + padding-right: 20px; +} + +#boxB { + width: 100%; + height: 22px; +} + +#boxBL { + width: 25px; + height: 22px; + float: left; + background-image: url(box-bottom-left.png); +} + +#boxBR { + width: 25px; + height: 22px; + float: right; + background-image: url(box-bottom-right.png); +} + +#boxBC { + height: 22px; + margin-left: 25px; + margin-right: 25px; + background-image: url(box-bottom-middle.png); + background-repeat: repeat-x; +} + +/* + * the footer + */ + +#footer { + position: fixed; + background-image: url(bottom-middle.png); + width: 100%; + height: 100px; + z-index: -2; + bottom:0; +} + +#footerL { + position: fixed; + background-image: url(bottom-left.png); + left: 0px; + width: 155px; + height: 100px; + z-index: -2; +} + +#footerR { + position: fixed; + background-image: url(bottom-right.png); + right: 0px; + width: 429px; + height: 100px; + z-index: -1; +} + +/* vim:set sw=2 et nocindent smartindent: */ diff --git a/libtdepim/about/kde_infopage_rtl.css b/libtdepim/about/kde_infopage_rtl.css new file mode 100644 index 000000000..003330196 --- /dev/null +++ b/libtdepim/about/kde_infopage_rtl.css @@ -0,0 +1,11 @@ +body {direction: rtl} + +#boxCenter { + text-align: right; +} + +#nextlink { + text-align: left; +} + +/* vim:set sw=2 et nocindent smartindent: */ diff --git a/libtdepim/about/top-left.png b/libtdepim/about/top-left.png new file mode 100644 index 000000000..d7551c0d5 Binary files /dev/null and b/libtdepim/about/top-left.png differ diff --git a/libtdepim/about/top-middle.png b/libtdepim/about/top-middle.png new file mode 100644 index 000000000..bb3fe7428 Binary files /dev/null and b/libtdepim/about/top-middle.png differ diff --git a/libtdepim/addresseediffalgo.cpp b/libtdepim/addresseediffalgo.cpp new file mode 100644 index 000000000..d36b7ac94 --- /dev/null +++ b/libtdepim/addresseediffalgo.cpp @@ -0,0 +1,146 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "addresseediffalgo.h" + +using namespace KPIM; + +static bool compareString( const TQString &left, const TQString &right ) +{ + if ( left.isEmpty() && right.isEmpty() ) + return true; + else + return left == right; +} + +AddresseeDiffAlgo::AddresseeDiffAlgo( const KABC::Addressee &leftAddressee, + const KABC::Addressee &rightAddressee ) + : mLeftAddressee( leftAddressee ), mRightAddressee( rightAddressee ) +{ +} + +void AddresseeDiffAlgo::run() +{ + begin(); + + if ( !compareString( mLeftAddressee.uid(), mRightAddressee.uid() ) ) + conflictField( KABC::Addressee::uidLabel(), mLeftAddressee.uid(), mRightAddressee.uid() ); + + if ( !compareString( mLeftAddressee.name(), mRightAddressee.name() ) ) + conflictField( KABC::Addressee::nameLabel(), mLeftAddressee.name(), mRightAddressee.name() ); + + if ( !compareString( mLeftAddressee.formattedName(), mRightAddressee.formattedName() ) ) + conflictField( KABC::Addressee::formattedNameLabel(), mLeftAddressee.formattedName(), mRightAddressee.formattedName() ); + + if ( !compareString( mLeftAddressee.familyName(), mRightAddressee.familyName() ) ) + conflictField( KABC::Addressee::familyNameLabel(), mLeftAddressee.familyName(), mRightAddressee.familyName() ); + + if ( !compareString( mLeftAddressee.givenName(), mRightAddressee.givenName() ) ) + conflictField( KABC::Addressee::givenNameLabel(), mLeftAddressee.givenName(), mRightAddressee.givenName() ); + + if ( !compareString( mLeftAddressee.additionalName(), mRightAddressee.additionalName() ) ) + conflictField( KABC::Addressee::additionalNameLabel(), mLeftAddressee.additionalName(), mRightAddressee.additionalName() ); + + if ( !compareString( mLeftAddressee.prefix(), mRightAddressee.prefix() ) ) + conflictField( KABC::Addressee::prefixLabel(), mLeftAddressee.prefix(), mRightAddressee.prefix() ); + + if ( !compareString( mLeftAddressee.suffix(), mRightAddressee.suffix() ) ) + conflictField( KABC::Addressee::suffixLabel(), mLeftAddressee.suffix(), mRightAddressee.suffix() ); + + if ( !compareString( mLeftAddressee.nickName(), mRightAddressee.nickName() ) ) + conflictField( KABC::Addressee::nickNameLabel(), mLeftAddressee.nickName(), mRightAddressee.nickName() ); + + if ( mLeftAddressee.birthday() != mRightAddressee.birthday() ) + conflictField( KABC::Addressee::birthdayLabel(), mLeftAddressee.birthday().toString(), + mRightAddressee.birthday().toString() ); + + if ( !compareString( mLeftAddressee.mailer(), mRightAddressee.mailer() ) ) + conflictField( KABC::Addressee::mailerLabel(), mLeftAddressee.mailer(), mRightAddressee.mailer() ); + + if ( mLeftAddressee.timeZone() != mRightAddressee.timeZone() ) + conflictField( KABC::Addressee::timeZoneLabel(), mLeftAddressee.timeZone().asString(), mRightAddressee.timeZone().asString() ); + + if ( mLeftAddressee.geo() != mRightAddressee.geo() ) + conflictField( KABC::Addressee::geoLabel(), mLeftAddressee.geo().asString(), mRightAddressee.geo().asString() ); + + if ( !compareString( mLeftAddressee.title(), mRightAddressee.title() ) ) + conflictField( KABC::Addressee::titleLabel(), mLeftAddressee.title(), mRightAddressee.title() ); + + if ( !compareString( mLeftAddressee.role(), mRightAddressee.role() ) ) + conflictField( KABC::Addressee::roleLabel(), mLeftAddressee.role(), mRightAddressee.role() ); + + if ( !compareString( mLeftAddressee.organization(), mRightAddressee.organization() ) ) + conflictField( KABC::Addressee::organizationLabel(), mLeftAddressee.organization(), mRightAddressee.organization() ); + + if ( !compareString( mLeftAddressee.note(), mRightAddressee.note() ) ) + conflictField( KABC::Addressee::noteLabel(), mLeftAddressee.note(), mRightAddressee.note() ); + + if ( !compareString( mLeftAddressee.productId(), mRightAddressee.productId() ) ) + conflictField( KABC::Addressee::productIdLabel(), mLeftAddressee.productId(), mRightAddressee.productId() ); + + if ( !compareString( mLeftAddressee.sortString(), mRightAddressee.sortString() ) ) + conflictField( KABC::Addressee::sortStringLabel(), mLeftAddressee.sortString(), mRightAddressee.sortString() ); + + if ( mLeftAddressee.secrecy() != mRightAddressee.secrecy() ) { + conflictField( KABC::Addressee::secrecyLabel(), mLeftAddressee.secrecy().asString(), mRightAddressee.secrecy().asString() ); + } + if ( mLeftAddressee.url()!= mRightAddressee.url() ) + conflictField( KABC::Addressee::urlLabel(), mLeftAddressee.url().prettyURL(), + mRightAddressee.url().prettyURL() ); + + if ( mLeftAddressee.logo() != mRightAddressee.logo() ) { + } + + if ( mLeftAddressee.photo() != mRightAddressee.photo() ) { + } + + diffList( "emails", mLeftAddressee.emails(), mRightAddressee.emails() ); + + diffList( "Phone Numbers", mLeftAddressee.phoneNumbers(), mRightAddressee.phoneNumbers() ); + diffList( "Addresses", mLeftAddressee.addresses(), mRightAddressee.addresses() ); + + end(); +} + +TQString AddresseeDiffAlgo::toString( const KABC::PhoneNumber &number ) +{ + return number.number(); +} + +TQString AddresseeDiffAlgo::toString( const KABC::Address &addr ) +{ + return addr.formattedAddress(); +} + +template +void AddresseeDiffAlgo::diffList( const TQString &id, + const TQValueList &left, const TQValueList &right ) +{ + for ( uint i = 0; i < left.count(); ++i ) { + if ( right.find( left[ i ] ) == right.end() ) + additionalLeftField( id, toString( left[ i ] ) ); + } + + for ( uint i = 0; i < right.count(); ++i ) { + if ( left.find( right[ i ] ) == left.end() ) + additionalRightField( id, toString( right[ i ] ) ); + } +} diff --git a/libtdepim/addresseediffalgo.h b/libtdepim/addresseediffalgo.h new file mode 100644 index 000000000..f3c6632a7 --- /dev/null +++ b/libtdepim/addresseediffalgo.h @@ -0,0 +1,50 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KPIM_ADDRESSEEDIFFALGO_H +#define KPIM_ADDRESSEEDIFFALGO_H + +#include +#include + +namespace KPIM { + +class KDE_EXPORT AddresseeDiffAlgo : public DiffAlgo +{ + public: + AddresseeDiffAlgo( const KABC::Addressee &leftAddressee, const KABC::Addressee &rightAddressee ); + + void run(); + + private: + template + void diffList( const TQString &id, const TQValueList &left, const TQValueList &right ); + + TQString toString( const KABC::PhoneNumber &number ); + TQString toString( const KABC::Address &address ); + + KABC::Addressee mLeftAddressee; + KABC::Addressee mRightAddressee; +}; + +} + +#endif diff --git a/libtdepim/addresseeemailselection.cpp b/libtdepim/addresseeemailselection.cpp new file mode 100644 index 000000000..dde8f7dd4 --- /dev/null +++ b/libtdepim/addresseeemailselection.cpp @@ -0,0 +1,264 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include "recentaddresses.h" + +#include "addresseeemailselection.h" + +using namespace KPIM; +using KRecentAddress::RecentAddresses; + +AddresseeEmailSelection::AddresseeEmailSelection() + : Selection() +{ +} + +uint AddresseeEmailSelection::fieldCount() const +{ + return 3; +} + +TQString AddresseeEmailSelection::fieldTitle( uint index ) const +{ + switch ( index ) { + case 0: + return i18n( "To" ); + break; + case 1: + return i18n( "Cc" ); + break; + case 2: + return i18n( "Bcc" ); + break; + default: + return TQString(); + } +} + +TQStringList AddresseeEmailSelection::to() const +{ + return mToEmailList; +} + +TQStringList AddresseeEmailSelection::cc() const +{ + return mCcEmailList; +} + +TQStringList AddresseeEmailSelection::bcc() const +{ + return mBccEmailList; +} + +KABC::Addressee::List AddresseeEmailSelection::toAddresses() const +{ + return mToAddresseeList; +} + +KABC::Addressee::List AddresseeEmailSelection::ccAddresses() const +{ + return mCcAddresseeList; +} + +KABC::Addressee::List AddresseeEmailSelection::bccAddresses() const +{ + return mBccAddresseeList; +} + +TQStringList AddresseeEmailSelection::toDistributionLists() const +{ + return mToDistributionList; +} + +TQStringList AddresseeEmailSelection::ccDistributionLists() const +{ + return mCcDistributionList; +} + +TQStringList AddresseeEmailSelection::bccDistributionLists() const +{ + return mBccDistributionList; +} + +void AddresseeEmailSelection::setSelectedTo( const TQStringList &emails ) +{ + setSelectedItem( 0, emails ); +} + +void AddresseeEmailSelection::setSelectedCC( const TQStringList &emails ) +{ + setSelectedItem( 1, emails ); +} + +void AddresseeEmailSelection::setSelectedBCC( const TQStringList &emails ) +{ + setSelectedItem( 2, emails ); +} + + +uint AddresseeEmailSelection::itemCount( const KABC::Addressee &addressee ) const +{ + return addressee.emails().count(); +} + +TQString AddresseeEmailSelection::itemText( const KABC::Addressee &addressee, uint index ) const +{ + return addressee.formattedName() + " " + email( addressee, index ); +} + +TQPixmap AddresseeEmailSelection::itemIcon( const KABC::Addressee &addressee, uint ) const +{ + if ( !addressee.photo().data().isNull() ) + return addressee.photo().data().smoothScale( 16, 16 ); + else + return KGlobal::iconLoader()->loadIcon( "personal", KIcon::Small ); +} + +bool AddresseeEmailSelection::itemEnabled( const KABC::Addressee &addressee, uint ) const +{ + return addressee.emails().count() != 0; +} + +bool AddresseeEmailSelection::itemMatches( const KABC::Addressee &addressee, uint index, const TQString &pattern ) const +{ + return addressee.formattedName().tqstartsWith( pattern, false ) || + email( addressee, index ).tqstartsWith( pattern, false ); +} + +bool AddresseeEmailSelection::itemEquals( const KABC::Addressee &addressee, uint index, const TQString &pattern ) const +{ + return (pattern == addressee.formattedName() + " " + email( addressee, index )) || + (addressee.emails().contains( pattern )); +} + +TQString AddresseeEmailSelection::distributionListText( const KABC::DistributionList *distributionList ) const +{ + return distributionList->name(); +} + +TQPixmap AddresseeEmailSelection::distributionListIcon( const KABC::DistributionList* ) const +{ + return KGlobal::iconLoader()->loadIcon( "kdmconfig", KIcon::Small ); +} + +bool AddresseeEmailSelection::distributionListEnabled( const KABC::DistributionList* ) const +{ + return true; +} + +bool AddresseeEmailSelection::distributionListMatches( const KABC::DistributionList *distributionList, + const TQString &pattern ) const +{ + // check whether the name of the distribution list matches the pattern or one of its entries. + bool ok = distributionList->name().tqstartsWith( pattern, false ); + + KABC::DistributionList::Entry::List entries = distributionList->entries(); + KABC::DistributionList::Entry::List::ConstIterator it; + for ( it = entries.begin(); it != entries.end(); ++it ) { + ok = ok || (*it).addressee.formattedName().tqstartsWith( pattern, false ) || + (*it).email.tqstartsWith( pattern, false ); + } + + return ok; +} + +uint AddresseeEmailSelection::addressBookCount() const +{ + // we provide the recent email addresses via the custom addressbooks + return 1; +} + +TQString AddresseeEmailSelection::addressBookTitle( uint index ) const +{ + if ( index == 0 ) + return i18n( "Recent Addresses" ); + else + return TQString(); +} + +KABC::Addressee::List AddresseeEmailSelection::addressBookContent( uint index ) const +{ + if ( index == 0 ) { + KConfig config( "kmailrc" ); + return RecentAddresses::self( &config )->kabcAddresses(); + } else { + return KABC::Addressee::List(); + } +} + +TQString AddresseeEmailSelection::email( const KABC::Addressee &addressee, uint index ) const +{ + return addressee.emails()[ index ]; +} + +void AddresseeEmailSelection::setSelectedItem( uint fieldIndex, const TQStringList &emails ) +{ + TQStringList::ConstIterator it; + for ( it = emails.begin(); it != emails.end(); ++it ) { + KABC::Addressee addr; + addr.insertEmail( *it, true ); + + selector()->setItemSelected( fieldIndex, addr, 0, *it ); + } +} + +void AddresseeEmailSelection::addSelectedAddressees( uint fieldIndex, const KABC::Addressee &addressee, uint itemIndex ) +{ + switch ( fieldIndex ) { + case 0: + mToAddresseeList.append( addressee ); + mToEmailList.append( email( addressee, itemIndex ) ); + break; + case 1: + mCcAddresseeList.append( addressee ); + mCcEmailList.append( email( addressee, itemIndex ) ); + break; + case 2: + mBccAddresseeList.append( addressee ); + mBccEmailList.append( email( addressee, itemIndex ) ); + break; + default: + // oops + break; + } +} + +void AddresseeEmailSelection::addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList *list ) +{ + switch ( fieldIndex ) { + case 0: + mToDistributionList.append( list->name() ); + break; + case 1: + mCcDistributionList.append( list->name() ); + break; + case 2: + mBccDistributionList.append( list->name() ); + break; + default: + // oops + break; + } +} diff --git a/libtdepim/addresseeemailselection.h b/libtdepim/addresseeemailselection.h new file mode 100644 index 000000000..4ecb946e3 --- /dev/null +++ b/libtdepim/addresseeemailselection.h @@ -0,0 +1,148 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KPIM_ADDRESSEE_EMAILSELECTION_H +#define KPIM_ADDRESSEE_EMAILSELECTION_H + +#include + +namespace KPIM { + +class KDE_EXPORT AddresseeEmailSelection : public Selection +{ + public: + AddresseeEmailSelection(); + + /** + Returns the number of fields the selection offers. + */ + virtual uint fieldCount() const; + + /** + Returns the title for the field specified by index. + */ + virtual TQString fieldTitle( uint index ) const; + + /** + Returns the number of items for the given addressee. + */ + virtual uint itemCount( const KABC::Addressee &addresse ) const; + + /** + Returns the text that's used for the item specified by index. + */ + virtual TQString itemText( const KABC::Addressee &addresse, uint index ) const; + + /** + Returns the icon that's used for the item specified by index. + */ + virtual TQPixmap itemIcon( const KABC::Addressee &addresse, uint index ) const; + + /** + Returns whether the item specified by index is enabled. + */ + virtual bool itemEnabled( const KABC::Addressee &addresse, uint index ) const; + + /** + Returns whether the item specified by index matches the passed pattern. + */ + virtual bool itemMatches( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const; + + /** + Returns whether the item specified by index equals the passed pattern. + */ + virtual bool itemEquals( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const; + + /** + Returns the text that's used for the given distribution list. + */ + virtual TQString distributionListText( const KABC::DistributionList *distributionList ) const; + + /** + Returns the icon that's used for the given distribution list. + */ + virtual TQPixmap distributionListIcon( const KABC::DistributionList *distributionList ) const; + + /** + Returns whether the given distribution list is enabled. + */ + virtual bool distributionListEnabled( const KABC::DistributionList *distributionList ) const; + + /** + Returns whether the given distribution list matches the passed pattern. + */ + virtual bool distributionListMatches( const KABC::DistributionList *distributionList, + const TQString &pattern ) const; + + /** + Returns the number of additional address books. + */ + virtual uint addressBookCount() const; + + /** + Returns the title for an additional address book. + */ + virtual TQString addressBookTitle( uint index ) const; + + /** + Returns the content for an additional address book. + */ + virtual KABC::Addressee::List addressBookContent( uint index ) const; + + TQStringList to() const; + TQStringList cc() const; + TQStringList bcc() const; + + KABC::Addressee::List toAddresses() const; + KABC::Addressee::List ccAddresses() const; + KABC::Addressee::List bccAddresses() const; + + TQStringList toDistributionLists() const; + TQStringList ccDistributionLists() const; + TQStringList bccDistributionLists() const; + + void setSelectedTo( const TQStringList &emails ); + void setSelectedCC( const TQStringList &emails ); + void setSelectedBCC( const TQStringList &emails ); + + private: + virtual void addSelectedAddressees( uint fieldIndex, const KABC::Addressee&, uint itemIndex ); + virtual void addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList* ); + + TQString email( const KABC::Addressee&, uint ) const; + void setSelectedItem( uint fieldIndex, const TQStringList& ); + + KABC::Addressee::List mToAddresseeList; + KABC::Addressee::List mCcAddresseeList; + KABC::Addressee::List mBccAddresseeList; + + TQStringList mToEmailList; + TQStringList mCcEmailList; + TQStringList mBccEmailList; + + TQStringList mToDistributionList; + TQStringList mCcDistributionList; + TQStringList mBccDistributionList; +}; + +} + +#endif diff --git a/libtdepim/addresseelineedit.cpp b/libtdepim/addresseelineedit.cpp new file mode 100644 index 000000000..50d19e07b --- /dev/null +++ b/libtdepim/addresseelineedit.cpp @@ -0,0 +1,1285 @@ +/* + This file is part of libtdepim. + Copyright (c) 2002 Helge Deller + 2002 Lubos Lunak + 2001,2003 Carsten Pfeiffer + 2001 Waldo Bastian + 2004 Daniel Molkentin + 2004 Karl-Heinz Zimmer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "addresseelineedit.h" + +#include "resourceabc.h" +#include "completionordereditor.h" +#include "ldapclient.h" + +#include + +#ifdef KDEPIM_NEW_DISTRLISTS +#include "distributionlist.h" +#else +#include +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace KPIM; + +KMailCompletion * AddresseeLineEdit::s_completion = 0L; +KPIM::CompletionItemsMap* AddresseeLineEdit::s_completionItemMap = 0L; +TQStringList* AddresseeLineEdit::s_completionSources = 0L; +bool AddresseeLineEdit::s_addressesDirty = false; +TQTimer* AddresseeLineEdit::s_LDAPTimer = 0L; +KPIM::LdapSearch* AddresseeLineEdit::s_LDAPSearch = 0L; +TQString* AddresseeLineEdit::s_LDAPText = 0L; +AddresseeLineEdit* AddresseeLineEdit::s_LDAPLineEdit = 0L; + +// The weights associated with the completion sources in s_completionSources. +// Both are maintained by addCompletionSource(), don't attempt to modifiy those yourself. +TQMap* s_completionSourceWeights = 0; + +// maps LDAP client indices to completion source indices +// the assumption that they are always the first n indices in s_completion +// does not hold when clients are added later on +TQMap* AddresseeLineEdit::s_ldapClientToCompletionSourceMap = 0; + +static KStaticDeleter completionDeleter; +static KStaticDeleter completionItemsDeleter; +static KStaticDeleter ldapTimerDeleter; +static KStaticDeleter ldapSearchDeleter; +static KStaticDeleter ldapTextDeleter; +static KStaticDeleter completionSourcesDeleter; +static KStaticDeleter > completionSourceWeightsDeleter; +static KStaticDeleter > ldapClientToCompletionSourceMapDeleter; + +// needs to be unique, but the actual name doesn't matter much +static TQCString newLineEditDCOPObjectName() +{ + static int s_count = 0; + TQCString name( "KPIM::AddresseeLineEdit" ); + if ( s_count++ ) { + name += '-'; + name += TQCString().setNum( s_count ); + } + return name; +} + +static const TQString s_completionItemIndentString = " "; + +static bool itemIsHeader( const TQListBoxItem* item ) +{ + return item && !item->text().startsWith( s_completionItemIndentString ); +} + + + +AddresseeLineEdit::AddresseeLineEdit( TQWidget* parent, bool useCompletion, + const char *name ) + : ClickLineEdit( parent, TQString(), name ), DCOPObject( newLineEditDCOPObjectName() ), + m_useSemiColonAsSeparator( false ), m_allowDistLists( true ) +{ + m_useCompletion = useCompletion; + m_completionInitialized = false; + m_smartPaste = false; + m_addressBookConnected = false; + m_searchExtended = false; + + init(); + + if ( m_useCompletion ) + s_addressesDirty = true; +} + +void AddresseeLineEdit::updateLDAPWeights() +{ + /* Add completion sources for all ldap server, 0 to n. Added first so + * that they map to the ldapclient::clientNumber() */ + s_LDAPSearch->updateCompletionWeights(); + TQValueList< LdapClient* > clients = s_LDAPSearch->clients(); + int clientIndex = 0; + for ( TQValueList::iterator it = clients.begin(); it != clients.end(); ++it, ++clientIndex ) { + const int sourceIndex = addCompletionSource( "LDAP server: " + (*it)->server().host(), (*it)->completionWeight() ); + s_ldapClientToCompletionSourceMap->insert( clientIndex, sourceIndex ); + } +} + +void AddresseeLineEdit::init() +{ + if ( !s_completion ) { + completionDeleter.setObject( s_completion, new KMailCompletion() ); + s_completion->setOrder( completionOrder() ); + s_completion->setIgnoreCase( true ); + + completionItemsDeleter.setObject( s_completionItemMap, new KPIM::CompletionItemsMap() ); + completionSourcesDeleter.setObject( s_completionSources, new TQStringList() ); + completionSourceWeightsDeleter.setObject( s_completionSourceWeights, new TQMap ); + ldapClientToCompletionSourceMapDeleter.setObject( s_ldapClientToCompletionSourceMap, new TQMap ); + } +// connect( s_completion, TQT_SIGNAL( match( const TQString& ) ), +// this, TQT_SLOT( slotMatched( const TQString& ) ) ); + + if ( m_useCompletion ) { + if ( !s_LDAPTimer ) { + ldapTimerDeleter.setObject( s_LDAPTimer, new TQTimer( 0, "ldapTimerDeleter" ) ); + ldapSearchDeleter.setObject( s_LDAPSearch, new KPIM::LdapSearch ); + ldapTextDeleter.setObject( s_LDAPText, new TQString ); + } + + updateLDAPWeights(); + + if ( !m_completionInitialized ) { + setCompletionObject( s_completion, false ); + connect( this, TQT_SIGNAL( completion( const TQString& ) ), + this, TQT_SLOT( slotCompletion() ) ); + connect( this, TQT_SIGNAL( returnPressed( const TQString& ) ), + this, TQT_SLOT( slotReturnPressed( const TQString& ) ) ); + + KCompletionBox *box = completionBox(); + connect( box, TQT_SIGNAL( highlighted( const TQString& ) ), + this, TQT_SLOT( slotPopupCompletion( const TQString& ) ) ); + connect( box, TQT_SIGNAL( userCancelled( const TQString& ) ), + TQT_SLOT( slotUserCancelled( const TQString& ) ) ); + + // The emitter is always called KPIM::IMAPCompletionOrder by contract + if ( !connectDCOPSignal( 0, "KPIM::IMAPCompletionOrder", "orderChanged()", + "slotIMAPCompletionOrderChanged()", false ) ) + kdError() << "AddresseeLineEdit: connection to orderChanged() failed" << endl; + + connect( s_LDAPTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotStartLDAPLookup() ) ); + connect( s_LDAPSearch, TQT_SIGNAL( searchData( const KPIM::LdapResultList& ) ), + TQT_SLOT( slotLDAPSearchData( const KPIM::LdapResultList& ) ) ); + + m_completionInitialized = true; + } + } +} + +AddresseeLineEdit::~AddresseeLineEdit() +{ + if ( s_LDAPSearch && s_LDAPLineEdit == this ) + stopLDAPLookup(); +} + +void AddresseeLineEdit::setFont( const TQFont& font ) +{ + KLineEdit::setFont( font ); + if ( m_useCompletion ) + completionBox()->setFont( font ); +} + +void AddresseeLineEdit::allowSemiColonAsSeparator( bool useSemiColonAsSeparator ) +{ + m_useSemiColonAsSeparator = useSemiColonAsSeparator; +} + +void AddresseeLineEdit::allowDistributionLists( bool allowDistLists ) +{ + m_allowDistLists = allowDistLists; +} + +void AddresseeLineEdit::keyPressEvent( TQKeyEvent *e ) +{ + bool accept = false; + + if ( KStdAccel::shortcut( KStdAccel::SubstringCompletion ).contains( KKey( e ) ) ) { + //TODO: add LDAP substring lookup, when it becomes available in KPIM::LDAPSearch + updateSearchString(); + doCompletion( true ); + accept = true; + } else if ( KStdAccel::shortcut( KStdAccel::TextCompletion ).contains( KKey( e ) ) ) { + int len = text().length(); + + if ( len == cursorPosition() ) { // at End? + updateSearchString(); + doCompletion( true ); + accept = true; + } + } + + const TQString oldContent = text(); + if ( !accept ) + KLineEdit::keyPressEvent( e ); + + // if the text didn't change (eg. because a cursor navigation key was pressed) + // we don't need to trigger a new search + if ( oldContent == text() ) + return; + + if ( e->isAccepted() ) { + updateSearchString(); + TQString searchString( m_searchString ); + //LDAP does not know about our string manipulation, remove it + if ( m_searchExtended ) + searchString = m_searchString.mid( 1 ); + + if ( m_useCompletion && s_LDAPTimer != NULL ) { + if ( *s_LDAPText != searchString || s_LDAPLineEdit != this ) + stopLDAPLookup(); + + *s_LDAPText = searchString; + s_LDAPLineEdit = this; + s_LDAPTimer->start( 500, true ); + } + } +} + +void AddresseeLineEdit::insert( const TQString &t ) +{ + if ( !m_smartPaste ) { + KLineEdit::insert( t ); + return; + } + + //kdDebug(5300) << " AddresseeLineEdit::insert( \"" << t << "\" )" << endl; + + TQString newText = t.stripWhiteSpace(); + if ( newText.isEmpty() ) + return; + + // remove newlines in the to-be-pasted string + TQStringList lines = TQStringList::split( TQRegExp("\r?\n"), newText, false ); + for ( TQStringList::iterator it = lines.begin(); + it != lines.end(); ++it ) { + // remove trailing commas and whitespace + (*it).remove( TQRegExp(",?\\s*$") ); + } + newText = lines.join( ", " ); + + if ( newText.startsWith("mailto:") ) { + KURL url( newText ); + newText = url.path(); + } + else if ( newText.find(" at ") != -1 ) { + // Anti-spam stuff + newText.replace( " at ", "@" ); + newText.replace( " dot ", "." ); + } + else if ( newText.find("(at)") != -1 ) { + newText.replace( TQRegExp("\\s*\\(at\\)\\s*"), "@" ); + } + + TQString contents = text(); + int start_sel = 0; + int pos = cursorPosition( ); + + if ( hasSelectedText() ) { + // Cut away the selection. + start_sel = selectionStart(); + pos = start_sel; + contents = contents.left( start_sel ) + contents.mid( start_sel + selectedText().length() ); + } + + int eot = contents.length(); + while ( ( eot > 0 ) && contents[ eot - 1 ].isSpace() ) { + eot--; + } + if ( eot == 0 ) { + contents = TQString(); + } else if ( pos >= eot ) { + if ( contents[ eot - 1 ] == ',' ) { + eot--; + } + contents.truncate( eot ); + contents += ", "; + pos = eot + 2; + } + + contents = contents.left( pos ) + newText + contents.mid( pos ); + setText( contents ); + setEdited( true ); + setCursorPosition( pos + newText.length() ); +} + +void AddresseeLineEdit::setText( const TQString & text ) +{ + ClickLineEdit::setText( text.stripWhiteSpace() ); +} + +void AddresseeLineEdit::paste() +{ + if ( m_useCompletion ) + m_smartPaste = true; + + KLineEdit::paste(); + m_smartPaste = false; +} + +void AddresseeLineEdit::mouseReleaseEvent( TQMouseEvent *e ) +{ + // reimplemented from TQLineEdit::mouseReleaseEvent() + if ( m_useCompletion + && TQApplication::tqclipboard()->supportsSelection() + && !isReadOnly() + && e->button() == Qt::MidButton ) { + m_smartPaste = true; + } + + KLineEdit::mouseReleaseEvent( e ); + m_smartPaste = false; +} + +void AddresseeLineEdit::dropEvent( TQDropEvent *e ) +{ + KURL::List uriList; + if ( !isReadOnly() ) { + if ( KURLDrag::canDecode(e) && KURLDrag::decode( e, uriList ) ) { + TQString contents = text(); + // remove trailing white space and comma + int eot = contents.length(); + while ( ( eot > 0 ) && contents[ eot - 1 ].isSpace() ) + eot--; + if ( eot == 0 ) + contents = TQString(); + else if ( contents[ eot - 1 ] == ',' ) { + eot--; + contents.truncate( eot ); + } + bool mailtoURL = false; + // append the mailto URLs + for ( KURL::List::Iterator it = uriList.begin(); + it != uriList.end(); ++it ) { + if ( !contents.isEmpty() ) + contents.append( ", " ); + KURL u( *it ); + if ( u.protocol() == "mailto" ) { + mailtoURL = true; + contents.append( (*it).path() ); + } + } + if ( mailtoURL ) { + setText( contents ); + setEdited( true ); + return; + } + } else { + // Let's see if this drop contains a comma separated list of emails + TQString dropData = TQString::fromUtf8( e->tqencodedData( "text/plain" ) ); + TQStringList addrs = splitEmailAddrList( dropData ); + if ( addrs.count() > 0 ) { + setText( normalizeAddressesAndDecodeIDNs( dropData ) ); + setEdited( true ); + return; + } + } + } + + if ( m_useCompletion ) + m_smartPaste = true; + TQLineEdit::dropEvent( e ); + m_smartPaste = false; +} + +void AddresseeLineEdit::cursorAtEnd() +{ + setCursorPosition( text().length() ); +} + +void AddresseeLineEdit::enableCompletion( bool enable ) +{ + m_useCompletion = enable; +} + +void AddresseeLineEdit::doCompletion( bool ctrlT ) +{ + m_lastSearchMode = ctrlT; + + KGlobalSettings::Completion mode = completionMode(); + + if ( mode == KGlobalSettings::CompletionNone ) + return; + + if ( s_addressesDirty ) { + loadContacts(); // read from local address book + s_completion->setOrder( completionOrder() ); + } + + // cursor at end of string - or Ctrl+T pressed for substring completion? + if ( ctrlT ) { + const TQStringList completions = getAdjustedCompletionItems( false ); + + if ( completions.count() > 1 ) + ; //m_previousAddresses = prevAddr; + else if ( completions.count() == 1 ) + setText( m_previousAddresses + completions.first().stripWhiteSpace() ); + + setCompletedItems( completions, true ); // this makes sure the completion popup is closed if no matching items were found + + cursorAtEnd(); + setCompletionMode( mode ); //set back to previous mode + return; + } + + + switch ( mode ) { + case KGlobalSettings::CompletionPopupAuto: + { + if ( m_searchString.isEmpty() ) + break; + } + + case KGlobalSettings::CompletionPopup: + { + const TQStringList items = getAdjustedCompletionItems( true ); + setCompletedItems( items, false ); + break; + } + + case KGlobalSettings::CompletionShell: + { + TQString match = s_completion->makeCompletion( m_searchString ); + if ( !match.isNull() && match != m_searchString ) { + setText( m_previousAddresses + match ); + setEdited( true ); + cursorAtEnd(); + } + break; + } + + case KGlobalSettings::CompletionMan: // Short-Auto in fact + case KGlobalSettings::CompletionAuto: + { + //force autoSuggest in KLineEdit::keyPressed or setCompletedText will have no effect + setCompletionMode( completionMode() ); + + if ( !m_searchString.isEmpty() ) { + + //if only our \" is left, remove it since user has not typed it either + if ( m_searchExtended && m_searchString == "\"" ){ + m_searchExtended = false; + m_searchString = TQString(); + setText( m_previousAddresses ); + break; + } + + TQString match = s_completion->makeCompletion( m_searchString ); + + if ( !match.isEmpty() ) { + if ( match != m_searchString ) { + TQString adds = m_previousAddresses + match; + setCompletedText( adds ); + } + } else { + if ( !m_searchString.startsWith( "\"" ) ) { + //try with quoted text, if user has not type one already + match = s_completion->makeCompletion( "\"" + m_searchString ); + if ( !match.isEmpty() && match != m_searchString ) { + m_searchString = "\"" + m_searchString; + m_searchExtended = true; + setText( m_previousAddresses + m_searchString ); + setCompletedText( m_previousAddresses + match ); + } + } else if ( m_searchExtended ) { + //our added \" does not work anymore, remove it + m_searchString = m_searchString.mid( 1 ); + m_searchExtended = false; + setText( m_previousAddresses + m_searchString ); + //now try again + match = s_completion->makeCompletion( m_searchString ); + if ( !match.isEmpty() && match != m_searchString ) { + TQString adds = m_previousAddresses + match; + setCompletedText( adds ); + } + } + } + } + break; + } + + case KGlobalSettings::CompletionNone: + default: // fall through + break; + } +} + +void AddresseeLineEdit::slotPopupCompletion( const TQString& completion ) +{ + setText( m_previousAddresses + completion.stripWhiteSpace() ); + cursorAtEnd(); +// slotMatched( m_previousAddresses + completion ); + updateSearchString(); +} + +void AddresseeLineEdit::slotReturnPressed( const TQString& item ) +{ + Q_UNUSED( item ); + TQListBoxItem* i = completionBox()->selectedItem(); + if ( i != 0 ) + slotPopupCompletion( i->text() ); +} + +void AddresseeLineEdit::loadContacts() +{ + s_completion->clear(); + s_completionItemMap->clear(); + s_addressesDirty = false; + //m_contactMap.clear(); + + TQApplication::setOverrideCursor( KCursor::waitCursor() ); // loading might take a while + + KConfig config( "kpimcompletionorder" ); // The weights for non-imap kabc resources is there. + config.setGroup( "CompletionWeights" ); + + KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); + // Can't just use the addressbook's iterator, we need to know which subresource + // is behind which contact. + TQPtrList resources( addressBook->resources() ); + for( TQPtrListIterator resit( resources ); *resit; ++resit ) { + KABC::Resource* resource = *resit; + KPIM::ResourceABC* resabc = dynamic_cast( resource ); + if ( resabc ) { // IMAP KABC resource; need to associate each contact with the subresource + const TQMap uidToResourceMap = resabc->uidToResourceMap(); + KABC::Resource::Iterator it; + for ( it = resource->begin(); it != resource->end(); ++it ) { + TQString uid = (*it).uid(); + TQMap::const_iterator wit = uidToResourceMap.find( uid ); + const TQString subresourceLabel = resabc->subresourceLabel( *wit ); + const int weight = ( wit != uidToResourceMap.end() ) ? resabc->subresourceCompletionWeight( *wit ) : 80; + const int idx = addCompletionSource( subresourceLabel, weight ); + + //kdDebug(5300) << (*it).fullEmail() << " subres=" << *wit << " weight=" << weight << endl; + addContact( *it, weight, idx ); + } + } else { // KABC non-imap resource + int weight = config.readNumEntry( resource->identifier(), 60 ); + int sourceIndex = addCompletionSource( resource->resourceName(), weight ); + KABC::Resource::Iterator it; + for ( it = resource->begin(); it != resource->end(); ++it ) { + addContact( *it, weight, sourceIndex ); + } + } + } + +#ifndef KDEPIM_NEW_DISTRLISTS // new distr lists are normal contact, already done above + int weight = config.readNumEntry( "DistributionLists", 60 ); + KABC::DistributionListManager manager( addressBook ); + manager.load(); + const TQStringList distLists = manager.listNames(); + TQStringList::const_iterator listIt; + int idx = addCompletionSource( i18n( "Distribution Lists" ) ); + for ( listIt = distLists.begin(); listIt != distLists.end(); ++listIt ) { + + //for KGlobalSettings::CompletionAuto + addCompletionItem( (*listIt).simplifyWhiteSpace(), weight, idx ); + + //for CompletionShell, CompletionPopup + TQStringList sl( (*listIt).simplifyWhiteSpace() ); + addCompletionItem( (*listIt).simplifyWhiteSpace(), weight, idx, &sl ); + + } +#endif + + TQApplication::restoreOverrideCursor(); + + if ( !m_addressBookConnected ) { + connect( addressBook, TQT_SIGNAL( addressBookChanged( AddressBook* ) ), TQT_SLOT( loadContacts() ) ); + m_addressBookConnected = true; + } +} + +void AddresseeLineEdit::addContact( const KABC::Addressee& addr, int weight, int source ) +{ +#ifdef KDEPIM_NEW_DISTRLISTS + if ( KPIM::DistributionList::isDistributionList( addr ) ) { + //kdDebug(5300) << "AddresseeLineEdit::addContact() distribution list \"" << addr.formattedName() << "\" weight=" << weight << endl; + + if ( m_allowDistLists ) { + //for CompletionAuto + addCompletionItem( addr.formattedName(), weight, source ); + + //for CompletionShell, CompletionPopup + TQStringList sl( addr.formattedName() ); + addCompletionItem( addr.formattedName(), weight, source, &sl ); + } + + return; + } +#endif + //m_contactMap.insert( addr.realName(), addr ); + const TQStringList emails = addr.emails(); + TQStringList::ConstIterator it; + const int prefEmailWeight = 1; //increment weight by prefEmailWeight + int isPrefEmail = prefEmailWeight; //first in list is preferredEmail + for ( it = emails.begin(); it != emails.end(); ++it ) { + //TODO: highlight preferredEmail + const TQString email( (*it) ); + const TQString givenName = addr.givenName(); + const TQString familyName= addr.familyName(); + const TQString nickName = addr.nickName(); + const TQString domain = email.mid( email.find( '@' ) + 1 ); + TQString fullEmail = addr.fullEmail( email ); + //TODO: let user decide what fields to use in lookup, e.g. company, city, ... + + //for CompletionAuto + if ( givenName.isEmpty() && familyName.isEmpty() ) { + addCompletionItem( fullEmail, weight + isPrefEmail, source ); // use whatever is there + } else { + const TQString byFirstName= "\"" + givenName + " " + familyName + "\" <" + email + ">"; + const TQString byLastName = "\"" + familyName + ", " + givenName + "\" <" + email + ">"; + addCompletionItem( byFirstName, weight + isPrefEmail, source ); + addCompletionItem( byLastName, weight + isPrefEmail, source ); + } + + addCompletionItem( email, weight + isPrefEmail, source ); + + if ( !nickName.isEmpty() ){ + const TQString byNick = "\"" + nickName + "\" <" + email + ">"; + addCompletionItem( byNick, weight + isPrefEmail, source ); + } + + if ( !domain.isEmpty() ){ + const TQString byDomain = "\"" + domain + " " + familyName + " " + givenName + "\" <" + email + ">"; + addCompletionItem( byDomain, weight + isPrefEmail, source ); + } + + //for CompletionShell, CompletionPopup + TQStringList keyWords; + const TQString realName = addr.realName(); + + if ( !givenName.isEmpty() && !familyName.isEmpty() ) { + keyWords.append( givenName + " " + familyName ); + keyWords.append( familyName + " " + givenName ); + keyWords.append( familyName + ", " + givenName); + }else if ( !givenName.isEmpty() ) + keyWords.append( givenName ); + else if ( !familyName.isEmpty() ) + keyWords.append( familyName ); + + if ( !nickName.isEmpty() ) + keyWords.append( nickName ); + + if ( !realName.isEmpty() ) + keyWords.append( realName ); + + if ( !domain.isEmpty() ) + keyWords.append( domain ); + + keyWords.append( email ); + + /* KMailCompletion does not have knowledge about identities, it stores emails and + * keywords for each email. KMailCompletion::allMatches does a lookup on the + * keywords and returns an ordered list of emails. In order to get the preferred + * email before others for each identity we use this little trick. + * We remove the in getAdjustedCompletionItems. + */ + if ( isPrefEmail == prefEmailWeight ) + fullEmail.replace( " <", " <" ); + + addCompletionItem( fullEmail, weight + isPrefEmail, source, &keyWords ); + isPrefEmail = 0; + +#if 0 + int len = (*it).length(); + if ( len == 0 ) continue; + if( '\0' == (*it)[len-1] ) + --len; + const TQString tmp = (*it).left( len ); + const TQString fullEmail = addr.fullEmail( tmp ); + //kdDebug(5300) << "AddresseeLineEdit::addContact() \"" << fullEmail << "\" weight=" << weight << endl; + addCompletionItem( fullEmail.simplifyWhiteSpace(), weight, source ); + // Try to guess the last name: if found, we add an extra + // entry to the list to make sure completion works even + // if the user starts by typing in the last name. + TQString name( addr.realName().simplifyWhiteSpace() ); + if( name.endsWith("\"") ) + name.truncate( name.length()-1 ); + if( name.startsWith("\"") ) + name = name.mid( 1 ); + + // While we're here also add "email (full name)" for completion on the email + if ( !name.isEmpty() ) + addCompletionItem( addr.preferredEmail() + " (" + name + ")", weight, source ); + + bool bDone = false; + int i = -1; + while( ( i = name.findRev(' ') ) > 1 && !bDone ) { + TQString sLastName( name.mid( i+1 ) ); + if( ! sLastName.isEmpty() && + 2 <= sLastName.length() && // last names must be at least 2 chars long + ! sLastName.endsWith(".") ) { // last names must not end with a dot (like "Jr." or "Sr.") + name.truncate( i ); + if( !name.isEmpty() ){ + sLastName.prepend( "\"" ); + sLastName.append( ", " + name + "\" <" ); + } + TQString sExtraEntry( sLastName ); + sExtraEntry.append( tmp.isEmpty() ? addr.preferredEmail() : tmp ); + sExtraEntry.append( ">" ); + //kdDebug(5300) << "AddresseeLineEdit::addContact() added extra \"" << sExtraEntry.simplifyWhiteSpace() << "\" weight=" << weight << endl; + addCompletionItem( sExtraEntry.simplifyWhiteSpace(), weight, source ); + bDone = true; + } + if( !bDone ) { + name.truncate( i ); + if( name.endsWith("\"") ) + name.truncate( name.length()-1 ); + } + } +#endif + } +} + +void AddresseeLineEdit::addCompletionItem( const TQString& string, int weight, int completionItemSource, const TQStringList * keyWords ) +{ + // Check if there is an exact match for item already, and use the max weight if so. + // Since there's no way to get the information from KCompletion, we have to keep our own TQMap + CompletionItemsMap::iterator it = s_completionItemMap->find( string ); + if ( it != s_completionItemMap->end() ) { + weight = TQMAX( ( *it ).first, weight ); + ( *it ).first = weight; + } else { + s_completionItemMap->insert( string, tqMakePair( weight, completionItemSource ) ); + } + if ( keyWords == 0 ) + s_completion->addItem( string, weight ); + else + s_completion->addItemWithKeys( string, weight, keyWords ); +} + +void AddresseeLineEdit::slotStartLDAPLookup() +{ + KGlobalSettings::Completion mode = completionMode(); + + if ( mode == KGlobalSettings::CompletionNone ) + return; + + if ( !s_LDAPSearch->isAvailable() ) { + return; + } + if ( s_LDAPLineEdit != this ) + return; + + startLoadingLDAPEntries(); +} + +void AddresseeLineEdit::stopLDAPLookup() +{ + s_LDAPSearch->cancelSearch(); + s_LDAPLineEdit = NULL; +} + +void AddresseeLineEdit::startLoadingLDAPEntries() +{ + TQString s( *s_LDAPText ); + // TODO cache last? + TQString prevAddr; + int n = s.findRev( ',' ); + if ( n >= 0 ) { + prevAddr = s.left( n + 1 ) + ' '; + s = s.mid( n + 1, 255 ).stripWhiteSpace(); + } + + if ( s.isEmpty() ) + return; + + //loadContacts(); // TODO reuse these? + s_LDAPSearch->startSearch( s ); +} + +void AddresseeLineEdit::slotLDAPSearchData( const KPIM::LdapResultList& adrs ) +{ + if ( adrs.isEmpty() || s_LDAPLineEdit != this ) + return; + + for ( KPIM::LdapResultList::ConstIterator it = adrs.begin(); it != adrs.end(); ++it ) { + KABC::Addressee addr; + addr.setNameFromString( (*it).name ); + addr.setEmails( (*it).email ); + + if ( !s_ldapClientToCompletionSourceMap->contains( (*it).clientNumber ) ) + updateLDAPWeights(); // we got results from a new source, so update the completion sources + + addContact( addr, (*it).completionWeight, (*s_ldapClientToCompletionSourceMap)[ (*it ).clientNumber ] ); + } + + if ( (hasFocus() || completionBox()->hasFocus() ) + && completionMode() != KGlobalSettings::CompletionNone + && completionMode() != KGlobalSettings::CompletionShell ) { + setText( m_previousAddresses + m_searchString ); + // only complete again if the user didn't change the selection while we were waiting + // otherwise the completion box will be closed + if ( m_searchString.stripWhiteSpace() != completionBox()->currentText().stripWhiteSpace() ) + doCompletion( m_lastSearchMode ); + } +} + +void AddresseeLineEdit::setCompletedItems( const TQStringList& items, bool autoSuggest ) +{ + KCompletionBox* completionBox = this->completionBox(); + + if ( !items.isEmpty() && + !(items.count() == 1 && m_searchString == items.first()) ) + { + TQString oldCurrentText = completionBox->currentText(); + TQListBoxItem *itemUnderMouse = completionBox->itemAt( + completionBox->viewport()->mapFromGlobal(TQCursor::pos()) ); + TQString oldTextUnderMouse; + TQPoint oldPosOfItemUnderMouse; + if ( itemUnderMouse ) { + oldTextUnderMouse = itemUnderMouse->text(); + oldPosOfItemUnderMouse = completionBox->tqitemRect( itemUnderMouse ).topLeft(); + } + + completionBox->setItems( items ); + + if ( !completionBox->isVisible() ) { + if ( !m_searchString.isEmpty() ) + completionBox->setCancelledText( m_searchString ); + completionBox->popup(); + // we have to install the event filter after popup(), since that + // calls show(), and that's where KCompletionBox installs its filter. + // We want to be first, though, so do it now. + if ( s_completion->order() == KCompletion::Weighted ) + tqApp->installEventFilter( this ); + } + + // Try to re-select what was selected before, otherrwise use the first + // item, if there is one + TQListBoxItem* item = 0; + if ( oldCurrentText.isEmpty() + || ( item = completionBox->findItem( oldCurrentText ) ) == 0 ) { + item = completionBox->item( 1 ); + } + if ( item ) + { + if ( itemUnderMouse ) { + TQListBoxItem *newItemUnderMouse = completionBox->findItem( oldTextUnderMouse ); + // if the mouse was over an item, before, but now that's elsewhere, + // move the cursor, so folks don't accidently click the wrong item + if ( newItemUnderMouse ) { + TQRect r = completionBox->tqitemRect( newItemUnderMouse ); + TQPoint target = r.topLeft(); + if ( oldPosOfItemUnderMouse != target ) { + target.setX( target.x() + r.width()/2 ); + TQCursor::setPos( completionBox->viewport()->mapToGlobal(target) ); + } + } + } + completionBox->blockSignals( true ); + completionBox->setSelected( item, true ); + completionBox->setCurrentItem( item ); + completionBox->ensureCurrentVisible(); + + completionBox->blockSignals( false ); + } + + if ( autoSuggest ) + { + int index = items.first().find( m_searchString ); + TQString newText = items.first().mid( index ); + setUserSelection(false); + setCompletedText(newText,true); + } + } + else + { + if ( completionBox && completionBox->isVisible() ) { + completionBox->hide(); + completionBox->setItems( TQStringList() ); + } + } +} + +TQPopupMenu* AddresseeLineEdit::createPopupMenu() +{ + TQPopupMenu *menu = KLineEdit::createPopupMenu(); + if ( !menu ) + return 0; + + if ( m_useCompletion ){ + menu->setItemVisible( ShortAutoCompletion, false ); + menu->setItemVisible( PopupAutoCompletion, false ); + menu->insertItem( i18n( "Configure Completion Order..." ), + this, TQT_SLOT( slotEditCompletionOrder() ) ); + } + return menu; +} + +void AddresseeLineEdit::slotEditCompletionOrder() +{ + init(); // for s_LDAPSearch + CompletionOrderEditor editor( s_LDAPSearch, this ); + editor.exec(); + if ( m_useCompletion ) { + updateLDAPWeights(); + s_addressesDirty = true; + } +} + +void KPIM::AddresseeLineEdit::slotIMAPCompletionOrderChanged() +{ + if ( m_useCompletion ) + s_addressesDirty = true; +} + +void KPIM::AddresseeLineEdit::slotUserCancelled( const TQString& cancelText ) +{ + if ( s_LDAPSearch && s_LDAPLineEdit == this ) + stopLDAPLookup(); + userCancelled( m_previousAddresses + cancelText ); // in KLineEdit +} + +void AddresseeLineEdit::updateSearchString() +{ + m_searchString = text(); + + int n = -1; + bool inQuote = false; + uint searchStringLength = m_searchString.length(); + for ( uint i = 0; i < searchStringLength; ++i ) { + if ( m_searchString[ i ] == '"' ) { + inQuote = !inQuote; + } + if ( m_searchString[ i ] == '\\' && + (i + 1) < searchStringLength && m_searchString[ i + 1 ] == '"' ) { + ++i; + } + if ( inQuote ) { + continue; + } + if ( i < searchStringLength && + ( m_searchString[ i ] == ',' || + ( m_useSemiColonAsSeparator && m_searchString[ i ] == ';' ) ) ) { + n = i; + } + } + + if ( n >= 0 ) { + ++n; // Go past the "," + + int len = m_searchString.length(); + + // Increment past any whitespace... + while ( n < len && m_searchString[ n ].isSpace() ) + ++n; + + m_previousAddresses = m_searchString.left( n ); + m_searchString = m_searchString.mid( n ).stripWhiteSpace(); + } else { + m_previousAddresses = TQString(); + } +} + +void KPIM::AddresseeLineEdit::slotCompletion() +{ + // Called by KLineEdit's keyPressEvent for CompletionModes Auto,Popup -> new text, update search string + // not called for CompletionShell, this is been taken care of in AddresseeLineEdit::keyPressEvent + updateSearchString(); + if ( completionBox() ) + completionBox()->setCancelledText( m_searchString ); + doCompletion( false ); +} + +// not cached, to make sure we get an up-to-date value when it changes +KCompletion::CompOrder KPIM::AddresseeLineEdit::completionOrder() +{ + KConfig config( "kpimcompletionorder" ); + config.setGroup( "General" ); + const TQString order = config.readEntry( "CompletionOrder", "Weighted" ); + + if ( order == "Weighted" ) + return KCompletion::Weighted; + else + return KCompletion::Sorted; +} + +int KPIM::AddresseeLineEdit::addCompletionSource( const TQString &source, int weight ) +{ + TQMap::iterator it = s_completionSourceWeights->find( source ); + if ( it == s_completionSourceWeights->end() ) + s_completionSourceWeights->insert( source, weight ); + else + (*s_completionSourceWeights)[source] = weight; + + int sourceIndex = s_completionSources->findIndex( source ); + if ( sourceIndex == -1 ) { + s_completionSources->append( source ); + return s_completionSources->size() - 1; + } + else + return sourceIndex; +} + +bool KPIM::AddresseeLineEdit::eventFilter(TQObject *obj, TQEvent *e) +{ + if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(completionBox()) ) { + if ( e->type() == TQEvent::MouseButtonPress || + e->type() == TQEvent::MouseMove || + e->type() == TQEvent::MouseButtonRelease || + e->type() == TQEvent::MouseButtonDblClick ) { + TQMouseEvent* me = TQT_TQMOUSEEVENT( e ); + // find list box item at the event position + TQListBoxItem *item = completionBox()->itemAt( me->pos() ); + if ( !item ) { + // In the case of a mouse move outside of the box we don't want + // the parent to fuzzy select a header by mistake. + bool eat = e->type() == TQEvent::MouseMove; + return eat; + } + // avoid selection of headers on button press, or move or release while + // a button is pressed + if ( e->type() == TQEvent::MouseButtonPress + || me->state() & Qt::LeftButton || me->state() & Qt::MidButton + || me->state() & Qt::RightButton ) { + if ( itemIsHeader(item) ) { + return true; // eat the event, we don't want anything to happen + } else { + // if we are not on one of the group heading, make sure the item + // below or above is selected, not the heading, inadvertedly, due + // to fuzzy auto-selection from TQListBox + completionBox()->setCurrentItem( item ); + completionBox()->setSelected( completionBox()->index( item ), true ); + if ( e->type() == TQEvent::MouseMove ) + return true; // avoid fuzzy selection behavior + } + } + } + } + if ( ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(this) ) && + ( e->type() == TQEvent::AccelOverride ) ) { + TQKeyEvent *ke = TQT_TQKEYEVENT( e ); + if ( ke->key() == Key_Up || ke->key() == Key_Down || ke->key() == Key_Tab ) { + ke->accept(); + return true; + } + } + if ( ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(this) ) && + ( e->type() == TQEvent::KeyPress || e->type() == TQEvent::KeyRelease ) && + completionBox()->isVisible() ) { + TQKeyEvent *ke = TQT_TQKEYEVENT( e ); + int currentIndex = completionBox()->currentItem(); + if ( currentIndex < 0 ) { + return true; + } + + if ( ke->key() == Key_Up ) { + //kdDebug() << "EVENTFILTER: Key_Up currentIndex=" << currentIndex << endl; + // figure out if the item we would be moving to is one we want + // to ignore. If so, go one further + TQListBoxItem *itemAbove = completionBox()->item( currentIndex ); + if ( itemAbove && itemIsHeader(itemAbove) ) { + // there is a header above us, check if there is even further up + // and if so go one up, so it'll be selected + if ( currentIndex > 0 && completionBox()->item( currentIndex - 1 ) ) { + //kdDebug() << "EVENTFILTER: Key_Up -> skipping " << currentIndex - 1 << endl; + completionBox()->setCurrentItem( itemAbove->prev() ); + completionBox()->setSelected( currentIndex - 1, true ); + } else if ( currentIndex == 0 ) { + // nothing to skip to, let's stay where we are, but make sure the + // first header becomes visible, if we are the first real entry + completionBox()->ensureVisible( 0, 0 ); + //Kolab issue 2941: be sure to add email even if it's the only element. + if ( itemIsHeader( completionBox()->item( currentIndex ) ) ) { + currentIndex++; + } + completionBox()->setCurrentItem( itemAbove ); + completionBox()->setSelected( currentIndex, true ); + } + return true; + } + } else if ( ke->key() == Key_Down ) { + // same strategy for downwards + //kdDebug() << "EVENTFILTER: Key_Down. currentIndex=" << currentIndex << endl; + TQListBoxItem *itemBelow = completionBox()->item( currentIndex ); + if ( itemBelow && itemIsHeader( itemBelow ) ) { + if ( completionBox()->item( currentIndex + 1 ) ) { + //kdDebug() << "EVENTFILTER: Key_Down -> skipping " << currentIndex+1 << endl; + completionBox()->setCurrentItem( itemBelow->next() ); + completionBox()->setSelected( currentIndex + 1, true ); + } else { + // nothing to skip to, let's stay where we are + completionBox()->setCurrentItem( itemBelow ); + completionBox()->setSelected( currentIndex, true ); + } + return true; + } + // special case of the last and only item in the list needing selection + if ( !itemBelow && currentIndex == 1 ) { + completionBox()->setSelected( currentIndex, true ); + } + // special case of the initial selection, which is unfortunately a header. + // Setting it to selected tricks KCompletionBox into not treating is special + // and selecting making it current, instead of the one below. + TQListBoxItem *item = completionBox()->item( currentIndex ); + if ( item && itemIsHeader(item) ) { + completionBox()->setSelected( currentIndex, true ); + } + } else if ( e->type() == TQEvent::KeyRelease && + ( ke->key() == Key_Tab || ke->key() == Key_Backtab ) ) { + //kdDebug() << "EVENTFILTER: Key_Tab. currentIndex=" << currentIndex << endl; + /// first, find the header of the current section + TQListBoxItem *myHeader = 0; + const int iterationstep = ke->key() == Key_Tab ? 1 : -1; + int i = TQMIN( TQMAX( currentIndex - iterationstep, 0 ), completionBox()->count() - 1 ); + while ( i>=0 ) { + if ( itemIsHeader( completionBox()->item(i) ) ) { + myHeader = completionBox()->item( i ); + break; + } + i--; + } + Q_ASSERT( myHeader ); // we should always be able to find a header + + // find the next header (searching backwards, for Key_Backtab) + TQListBoxItem *nextHeader = 0; + // when iterating forward, start at the currentindex, when backwards, + // one up from our header, or at the end + uint j; + if ( ke->key() == Key_Tab ) { + j = currentIndex; + } else { + i = completionBox()->index( myHeader ); + if ( i == 0 ) { + j = completionBox()->count() - 1; + } else { + j = ( i - 1 ) % completionBox()->count(); + } + } + while ( ( nextHeader = completionBox()->item( j ) ) && nextHeader != myHeader ) { + if ( itemIsHeader(nextHeader) ) { + break; + } + j = (j + iterationstep) % completionBox()->count(); + } + if ( nextHeader && nextHeader != myHeader ) { + TQListBoxItem *item = completionBox()->item( j + 1 ); + if ( item && !itemIsHeader(item) ) { + completionBox()->setSelected( item, true ); + completionBox()->setCurrentItem( item ); + completionBox()->ensureCurrentVisible(); + } + } + return true; + } + } + return ClickLineEdit::eventFilter( obj, e ); +} + +class SourceWithWeight { + public: + int weight; // the weight of the source + TQString sourceName; // the name of the source, e.g. "LDAP Server" + int index; // index into s_completionSources + + bool operator< ( const SourceWithWeight &other ) { + if ( weight > other.weight ) + return true; + if ( weight < other.weight ) + return false; + return sourceName < other.sourceName; + } +}; + +const TQStringList KPIM::AddresseeLineEdit::getAdjustedCompletionItems( bool fullSearch ) +{ + TQStringList items = fullSearch ? + s_completion->allMatches( m_searchString ) + : s_completion->substringCompletion( m_searchString ); + + // For weighted mode, the algorithm is the following: + // In the first loop, we add each item to its section (there is one section per completion source) + // We also add spaces in front of the items. + // The sections are appended to the items list. + // In the second loop, we then walk through the sections and add all the items in there to the + // sorted item list, which is the final result. + // + // The algo for non-weighted mode is different. + + int lastSourceIndex = -1; + unsigned int i = 0; + + // Maps indices of the items list, which are section headers/source items, + // to a TQStringList which are the items of that section/source. + TQMap sections; + TQStringList sortedItems; + for ( TQStringList::Iterator it = items.begin(); it != items.end(); ++it, ++i ) { + CompletionItemsMap::const_iterator cit = s_completionItemMap->find(*it); + if ( cit == s_completionItemMap->end() ) + continue; + int idx = (*cit).second; + + if ( s_completion->order() == KCompletion::Weighted ) { + if ( lastSourceIndex == -1 || lastSourceIndex != idx ) { + const TQString sourceLabel( (*s_completionSources)[idx] ); + if ( sections.find(idx) == sections.end() ) { + items.insert( it, sourceLabel ); + } + lastSourceIndex = idx; + } + (*it) = (*it).prepend( s_completionItemIndentString ); + // remove preferred email sort added in addContact() + (*it).replace( " <", " <" ); + } + sections[idx].append( *it ); + + if ( s_completion->order() == KCompletion::Sorted ) { + sortedItems.append( *it ); + } + } + + if ( s_completion->order() == KCompletion::Weighted ) { + + // Sort the sections + TQValueList sourcesAndWeights; + for ( uint i = 0; i < s_completionSources->size(); i++ ) { + SourceWithWeight sww; + sww.sourceName = (*s_completionSources)[i]; + sww.weight = (*s_completionSourceWeights)[sww.sourceName]; + sww.index = i; + sourcesAndWeights.append( sww ); + } + qHeapSort( sourcesAndWeights ); + + // Add the sections and their items to the final sortedItems result list + for( uint i = 0; i < sourcesAndWeights.size(); i++ ) { + TQStringList sectionItems = sections[sourcesAndWeights[i].index]; + if ( !sectionItems.isEmpty() ) { + sortedItems.append( sourcesAndWeights[i].sourceName ); + TQStringList sectionItems = sections[sourcesAndWeights[i].index]; + for ( TQStringList::Iterator sit( sectionItems.begin() ), send( sectionItems.end() ); + sit != send; ++sit ) { + sortedItems.append( *sit ); + } + } + } + } else { + sortedItems.sort(); + } + return sortedItems; +} +#include "addresseelineedit.moc" diff --git a/libtdepim/addresseelineedit.h b/libtdepim/addresseelineedit.h new file mode 100644 index 000000000..209151b6e --- /dev/null +++ b/libtdepim/addresseelineedit.h @@ -0,0 +1,183 @@ +/* + This file is part of libtdepim. + Copyright (c) 2002 Helge Deller + 2002 Lubos Lunak + 2001,2003 Carsten Pfeiffer + 2001 Waldo Bastian + 2004 Daniel Molkentin + 2004 Karl-Heinz Zimmer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef ADDRESSEELINEEDIT_H +#define ADDRESSEELINEEDIT_H + +#include +#include +#include +#include +#include + +#include + +#include "clicklineedit.h" +#include "kmailcompletion.h" +#include +#include + +class KConfig; + +namespace KPIM { +class LdapSearch; +class LdapResult; +typedef TQValueList LdapResultList; +typedef TQMap< TQString, TQPair > CompletionItemsMap; +} + +namespace KPIM { + +class KDE_EXPORT AddresseeLineEdit : public ClickLineEdit, public DCOPObject +{ + K_DCOP + Q_OBJECT + TQ_OBJECT + + public: + AddresseeLineEdit( TQWidget* parent, bool useCompletion = true, + const char *name = 0L); + virtual ~AddresseeLineEdit(); + + virtual void setFont( const TQFont& ); + void allowSemiColonAsSeparator( bool ); + + /// Sets if distribution lists will be used for completion. + /// This is true by default. + /// Call this right after the constructor, before anything calls loadContacts(), + /// otherwise this has no effect. + void allowDistributionLists( bool allowDistLists ); + + public slots: + void cursorAtEnd(); + void enableCompletion( bool enable ); + /** Reimplemented for stripping whitespace after completion */ + virtual void setText( const TQString& txt ); + + protected slots: + virtual void loadContacts(); + protected: + void addContact( const KABC::Addressee&, int weight, int source = -1 ); + virtual void keyPressEvent( TQKeyEvent* ); + /** + * Reimplemented for smart insertion of email addresses. + * Features: + * - Automatically adds ',' if necessary to separate email addresses + * - Correctly decodes mailto URLs + * - Recognizes email addresses which are protected against address + * harvesters, i.e. "name at kde dot org" and "name(at)kde.org" + */ + virtual void insert( const TQString &text ); + /** Reimplemented for smart insertion of pasted email addresses. */ + virtual void paste(); + /** Reimplemented for smart insertion with middle mouse button. */ + virtual void mouseReleaseEvent( TQMouseEvent *e ); + /** Reimplemented for smart insertion of dragged email addresses. */ + virtual void dropEvent( TQDropEvent *e ); + void doCompletion( bool ctrlT ); + virtual TQPopupMenu *createPopupMenu(); + + /** + * Adds the name of a completion source to the internal list of + * such sources and returns its index, such that that can be used + * for insertion of items associated with that source. + * + * If the source already exists, the weight will be updated. + */ + int addCompletionSource( const TQString&, int weight ); + + /** return whether we are using sorted or weighted display */ + static KCompletion::CompOrder completionOrder(); + + k_dcop: + // Connected to the DCOP signal + void slotIMAPCompletionOrderChanged(); + + private slots: + void slotCompletion(); + void slotPopupCompletion( const TQString& ); + void slotReturnPressed( const TQString& ); + void slotStartLDAPLookup(); + void slotLDAPSearchData( const KPIM::LdapResultList& ); + void slotEditCompletionOrder(); + void slotUserCancelled( const TQString& ); + + private: + virtual bool eventFilter(TQObject *o, TQEvent *e); + void init(); + void startLoadingLDAPEntries(); + void stopLDAPLookup(); + void updateLDAPWeights(); + + void setCompletedItems( const TQStringList& items, bool autoSuggest ); + void addCompletionItem( const TQString& string, int weight, int source, const TQStringList * keyWords=0 ); + TQString completionSearchText( TQString& ); + const TQStringList getAdjustedCompletionItems( bool fullSearch ); + void updateSearchString(); + + TQString m_previousAddresses; + TQString m_searchString; + bool m_useCompletion; + bool m_completionInitialized; + bool m_smartPaste; + bool m_addressBookConnected; + bool m_lastSearchMode; + bool m_searchExtended; //has \" been added? + bool m_useSemiColonAsSeparator; + bool m_allowDistLists; + + //TQMap m_contactMap; + + static bool s_addressesDirty; + static KMailCompletion *s_completion; + static CompletionItemsMap* s_completionItemMap; + static TQTimer *s_LDAPTimer; + static KPIM::LdapSearch *s_LDAPSearch; + static TQString *s_LDAPText; + static AddresseeLineEdit *s_LDAPLineEdit; + static TQStringList *s_completionSources; + static TQMap *s_ldapClientToCompletionSourceMap; + + class AddresseeLineEditPrivate; + AddresseeLineEditPrivate *d; + + //until MenuID moves into protected in KLineEdit, we keep a copy here + //Constants that represent the ID's of the popup menu. + enum MenuID + { + Default = 42, + NoCompletion, + AutoCompletion, + ShellCompletion, + PopupCompletion, + ShortAutoCompletion, + PopupAutoCompletion + }; + +}; + +} + +#endif diff --git a/libtdepim/addresseeselector.cpp b/libtdepim/addresseeselector.cpp new file mode 100644 index 000000000..792d57625 --- /dev/null +++ b/libtdepim/addresseeselector.cpp @@ -0,0 +1,581 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "addresseeselector.h" + +using namespace KPIM; + +class AddresseeSelector::AddressBookManager +{ + public: + TQStringList titles() const; + + void addResource( KABC::Resource* ); + void addAddressBook( const TQString &title, SelectionItem::List &list ); + + void clear(); + bool contains( uint index, const SelectionItem& ); + + private: + struct AddressBookEntry { + TQString title; + SelectionItem::List list; + }; + + TQValueList mResources; + TQValueList mAddressBooks; +}; + +TQStringList AddresseeSelector::AddressBookManager::titles() const +{ + TQStringList titles; + + // we've always an 'all' entry + titles.append( i18n( "All" ) ); + + TQValueList::ConstIterator resIt; + for ( resIt = mResources.begin(); resIt != mResources.end(); ++resIt ) + titles.append( (*resIt)->resourceName() ); + + TQValueList::ConstIterator abIt; + for ( abIt = mAddressBooks.begin(); abIt != mAddressBooks.end(); ++abIt ) + titles.append( (*abIt).title ); + + return titles; +} + +void AddresseeSelector::AddressBookManager::addResource( KABC::Resource *resource ) +{ + if ( mResources.find( resource ) == mResources.end() ) + mResources.append( resource ); +} + +void AddresseeSelector::AddressBookManager::addAddressBook( const TQString &title, + SelectionItem::List &list ) +{ + AddressBookEntry entry; + entry.title = title; + entry.list = list; + + + // TODO: check for duplicates + mAddressBooks.append( entry ); +} + +void AddresseeSelector::AddressBookManager::clear() +{ + mResources.clear(); + mAddressBooks.clear(); +} + +bool AddresseeSelector::AddressBookManager::contains( uint index, const SelectionItem &item ) +{ + if ( index == 0 ) // the 'all' entry + return true; + + if ( mResources.count() > 0 ) { + if ( index <= mResources.count() ) { + index--; + if ( item.addressee().resource() == mResources[ index ] ) + return true; + else + return false; + } + } + + index = index - mResources.count(); + + if ( mAddressBooks.count() > 0 ) { + if ( index <= mAddressBooks.count() ) { + index--; + AddressBookEntry entry = mAddressBooks[ index ]; + SelectionItem::List::ConstIterator it; + for ( it = entry.list.begin(); it != entry.list.end(); ++it ) + if ( (*it).addressee() == item.addressee() ) + return true; + + return false; + } + } + + return false; +} + + +SelectionItem::SelectionItem( const KABC::Addressee &addressee, uint index ) + : mAddressee( addressee ), mDistributionList( 0 ), mIndex( index ) +{ + mField.fill( false, 10 ); +} + +SelectionItem::SelectionItem( KABC::DistributionList *list, uint index ) + : mDistributionList( list ), mIndex( index ) +{ + mField.fill( false, 10 ); +} + +SelectionItem::SelectionItem() + : mDistributionList( 0 ), mIndex( 0 ) +{ + mField.fill( false, 10 ); +} + +void SelectionItem::addToField( int index ) +{ + mField.setBit( index ); +} + +void SelectionItem::removeFromField( int index ) +{ + mField.clearBit( index ); +} + +bool SelectionItem::isInField( int index ) +{ + return mField.testBit( index ); +} + +KABC::Addressee SelectionItem::addressee() const +{ + return mAddressee; +} + +KABC::DistributionList* SelectionItem::distributionList() const +{ + return mDistributionList; +} + +uint SelectionItem::index() const +{ + return mIndex; +} + + +class SelectionViewItem : public TQListViewItem +{ + public: + SelectionViewItem( TQListView *parent, Selection *selection, + SelectionItem *item ) + : TQListViewItem( parent, "" ), mSelection( selection ), mItem( item ) + { + if ( mItem->distributionList() == 0 ) + mIcon = mSelection->itemIcon( mItem->addressee(), mItem->index() ); + else + mIcon = mSelection->distributionListIcon( mItem->distributionList() ); + } + + TQString text( int column ) const + { + if ( column == 0 ) { + if ( mItem->distributionList() == 0 ) + return mSelection->itemText( mItem->addressee(), mItem->index() ); + else + return mSelection->distributionListText( mItem->distributionList() ); + } else + return TQString(); + } + + const TQPixmap* pixmap( int column ) const + { + if ( column == 0 ) { + return &mIcon; + } else + return 0; + } + + SelectionItem* item() const { return mItem; } + + private: + Selection *mSelection; + SelectionItem *mItem; + TQPixmap mIcon; +}; + +AddresseeSelector::AddresseeSelector( Selection *selection, TQWidget *parent, const char *name ) + : TQWidget( parent, name ), mSelection( selection ), mManager( 0 ) +{ + mMoveMapper = new TQSignalMapper( TQT_TQOBJECT(this) ); + mRemoveMapper = new TQSignalMapper( TQT_TQOBJECT(this) ); + + mAddressBookManager = new AddressBookManager(); + + initGUI(); + + init(); + + mSelection->setSelector( this ); +} + +AddresseeSelector::~AddresseeSelector() +{ + delete mManager; + mManager = 0; + + delete mAddressBookManager; + mAddressBookManager = 0; +} + +void AddresseeSelector::init() +{ + connect( KABC::StdAddressBook::self( true ), TQT_SIGNAL( addressBookChanged( AddressBook* ) ), + this, TQT_SLOT( reloadAddressBook() ) ); + connect( mAddresseeFilter, TQT_SIGNAL( textChanged( const TQString& ) ), + this, TQT_SLOT( updateAddresseeView() ) ); + connect( mAddressBookCombo, TQT_SIGNAL( activated( int ) ), + this, TQT_SLOT( updateAddresseeView() ) ); + + connect( mMoveMapper, TQT_SIGNAL( mapped( int ) ), + this, TQT_SLOT( move( int ) ) ); + connect( mRemoveMapper, TQT_SIGNAL( mapped( int ) ), + this, TQT_SLOT( remove( int ) ) ); + + reloadAddressBook(); +} + +void AddresseeSelector::initGUI() +{ + TQGridLayout *tqlayout = new TQGridLayout( this, 2, 3, KDialog::marginHint(), KDialog::spacingHint() ); + TQGridLayout *topLayout = new TQGridLayout( this, 2, 2, KDialog::marginHint() ); + + TQLabel *label = new TQLabel( i18n( "Address book:" ), this ); + mAddressBookCombo = new KComboBox( false, this ); + + topLayout->addWidget( label, 0, 0 ); + topLayout->addWidget( mAddressBookCombo, 0, 1 ); + + label = new TQLabel( i18n( "Search:" ), this ); + mAddresseeFilter = new KLineEdit( this ); + + topLayout->addWidget( label, 1, 0 ); + topLayout->addWidget( mAddresseeFilter, 1, 1 ); + + topLayout->setColStretch( 1, 1 ); + + tqlayout->addMultiCellLayout( topLayout, 0, 0, 0, 2 ); + + int row = 1; + + TQIconSet moveSet = KGlobal::iconLoader()->loadIconSet( "next", KIcon::Small ); + TQIconSet removeSet = KGlobal::iconLoader()->loadIconSet( "previous", KIcon::Small ); + + uint count = mSelection->fieldCount(); + for ( uint i = 0; i < count; ++i, ++row ) { + KListView *listView = new KListView( this ); + listView->addColumn( mSelection->fieldTitle( i ) ); + listView->setFullWidth( true ); + mSelectionViews.append( listView ); + + connect( listView, TQT_SIGNAL( doubleClicked( TQListViewItem*, const TQPoint&, int ) ), + mRemoveMapper, TQT_SLOT( map() ) ); + mRemoveMapper->setMapping( TQT_TQOBJECT(listView), i ); + + TQVBoxLayout *buttonLayout = new TQVBoxLayout( this ); + buttonLayout->tqsetAlignment( TQt::AlignBottom ); + tqlayout->addLayout( buttonLayout, row, 1 ); + + // move button + TQToolButton *moveButton = new TQToolButton( this ); + moveButton->setIconSet( moveSet ); + moveButton->setFixedSize( 30, 30 ); + + connect( moveButton, TQT_SIGNAL( clicked() ), + mMoveMapper, TQT_SLOT( map() ) ); + mMoveMapper->setMapping( TQT_TQOBJECT(moveButton), i ); + + // remove button + TQToolButton *removeButton = new TQToolButton( this ); + removeButton->setIconSet( removeSet ); + removeButton->setFixedSize( 30, 30 ); + + connect( removeButton, TQT_SIGNAL( clicked() ), + mRemoveMapper, TQT_SLOT( map() ) ); + mRemoveMapper->setMapping( TQT_TQOBJECT(removeButton), i ); + + buttonLayout->addWidget( moveButton ); + buttonLayout->addWidget( removeButton ); + + tqlayout->addWidget( listView, row, 2 ); + } + + mAddresseeView = new KListView( this ); + mAddresseeView->addColumn( "" ); + mAddresseeView->header()->hide(); + mAddresseeView->setFullWidth( true ); + + tqlayout->addMultiCellWidget( mAddresseeView, 1, row, 0, 0 ); +} + +void AddresseeSelector::finish() +{ + SelectionItem::List::Iterator it; + + for ( uint field = 0; field < mSelection->fieldCount(); ++field ) { + for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { + if ( (*it).isInField( field ) ) { + if ( (*it).distributionList() == 0 ) + mSelection->addSelectedAddressees( field, (*it).addressee(), (*it).index() ); + else + mSelection->addSelectedDistributionList( field, (*it).distributionList() ); + } + } + } +} + +void AddresseeSelector::updateAddresseeView() +{ + mAddresseeView->clear(); + + int addressBookIndex = mAddressBookCombo->currentItem(); + + SelectionItem::List::Iterator it; + for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { + if ( mAddressBookManager->contains( addressBookIndex, *it ) ) { + if ( (*it).distributionList() == 0 ) { + if ( mAddresseeFilter->text().isEmpty() || + mSelection->itemMatches( (*it).addressee(), (*it).index(), + mAddresseeFilter->text() ) ) + new SelectionViewItem( mAddresseeView, mSelection, &(*it) ); + } else { + if ( mAddresseeFilter->text().isEmpty() || + mSelection->distributionListMatches( (*it).distributionList(), + mAddresseeFilter->text() ) ) + new SelectionViewItem( mAddresseeView, mSelection, &(*it) ); + } + } + } + + updateSelectionViews(); +} + +void AddresseeSelector::move( int index ) +{ + SelectionViewItem *item = dynamic_cast( mAddresseeView->selectedItem() ); + if ( item ) { + item->item()->addToField( index ); + updateSelectionView( index ); + } +} + +void AddresseeSelector::remove( int index ) +{ + KListView *view = mSelectionViews[ index ]; + + SelectionViewItem *item = dynamic_cast( view->selectedItem() ); + if ( item ) { + item->item()->removeFromField( index ); + updateSelectionView( index ); + } +} + +void AddresseeSelector::setItemSelected( uint fieldIndex, const KABC::Addressee &addr, uint itemIndex ) +{ + bool found = false; + + SelectionItem::List::Iterator it; + for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { + if ( (*it).addressee() == addr && (*it).index() == itemIndex ) { + (*it).addToField( fieldIndex ); + found = true; + } + } + + if ( !found ) { + SelectionItem item( addr, itemIndex ); + item.addToField( fieldIndex ); + + mSelectionItems.append( item ); + } + + updateSelectionView( fieldIndex ); +} + +void AddresseeSelector::setItemSelected( uint fieldIndex, const KABC::Addressee &addr, + uint itemIndex, const TQString &text ) +{ + bool found = false; + + SelectionItem::List::Iterator it; + for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { + if ( mSelection->itemEquals( (*it).addressee(), (*it).index(), text ) ) { + (*it).addToField( fieldIndex ); + found = true; + } + } + + if ( !found ) { + SelectionItem item( addr, itemIndex ); + item.addToField( fieldIndex ); + + mSelectionItems.append( item ); + } + + updateSelectionView( fieldIndex ); +} + +void AddresseeSelector::updateSelectionView( int index ) +{ + KListView *view = mSelectionViews[ index ]; + view->clear(); + + SelectionItem::List::Iterator it; + for ( it = mSelectionItems.begin(); it != mSelectionItems.end(); ++it ) { + if ( (*it).isInField( index ) ) + new SelectionViewItem( view, mSelection, &(*it) ); + } +} + +void AddresseeSelector::updateSelectionViews() +{ + for ( uint i = 0; i < mSelection->fieldCount(); ++i ) + updateSelectionView( i ); +} + +void AddresseeSelector::reloadAddressBook() +{ + // load contacts + KABC::Addressee::List list = KABC::StdAddressBook::self( true )->allAddressees(); + KABC::Addressee::List::Iterator it; + + SelectionItem::List selectedItems; + + SelectionItem::List::Iterator itemIt; + for ( itemIt = mSelectionItems.begin(); itemIt != mSelectionItems.end(); ++itemIt ) { + bool isSelected = false; + for ( uint i = 0; i < mSelection->fieldCount(); ++i ) { + if ( (*itemIt).isInField( i ) ) { + isSelected = true; + break; + } + } + + // we don't save distribution lists, since this leads to crashes + if ( isSelected && (*itemIt).distributionList() == 0 ) { + selectedItems.append( *itemIt ); + } + } + + mSelectionItems.clear(); + mSelectionItems = selectedItems; + + for ( it = list.begin(); it != list.end(); ++it ) { + uint itemCount = mSelection->itemCount( *it ); + for ( uint index = 0; index < itemCount; ++index ) { + bool available = false; + for ( itemIt = mSelectionItems.begin(); itemIt != mSelectionItems.end(); ++itemIt ) { + if ( (*itemIt).addressee() == (*it) && (*itemIt).index() == index ) { + available = true; + break; + } + } + + if ( !available ) { + SelectionItem item( *it, index ); + mSelectionItems.append( item ); + } + } + } + + // load distribution lists + delete mManager; + mManager = new KABC::DistributionListManager( KABC::StdAddressBook::self( true ) ); + + mManager->load(); + + TQStringList lists = mManager->listNames(); + + TQStringList::Iterator listIt; + for ( listIt = lists.begin(); listIt != lists.end(); ++listIt ) { + KABC::DistributionList *list = mManager->list( *listIt ); + SelectionItem item( list, 0 ); + mSelectionItems.append( item ); + } + + mAddressBookManager->clear(); + + // update address book combo + mAddressBookCombo->clear(); + + TQPtrList resources = KABC::StdAddressBook::self( true )->resources(); + TQPtrListIterator resIt( resources ); + while ( resIt.current() ) { + if ( resIt.current()->isActive() ) + mAddressBookManager->addResource( resIt ); + + ++resIt; + } + + for ( uint i = 0; i < mSelection->addressBookCount(); ++i ) { + SelectionItem::List itemList; + + KABC::Addressee::List addrList = mSelection->addressBookContent( i ); + for ( it = addrList.begin(); it != addrList.end(); ++it ) { + uint itemCount = mSelection->itemCount( *it ); + for ( uint index = 0; index < itemCount; ++index ) { + SelectionItem item( *it, index ); + mSelectionItems.append( item ); + itemList.append( item ); + } + } + + mAddressBookManager->addAddressBook( mSelection->addressBookTitle( i ), + itemList ); + } + + mAddressBookCombo->insertStringList( mAddressBookManager->titles() ); + + updateAddresseeView(); +} + + +AddresseeSelectorDialog::AddresseeSelectorDialog( Selection *selection, + TQWidget *parent, const char *name ) + : KDialogBase( Plain, "", Ok | Cancel, Ok, parent, name, true ) +{ + TQFrame *frame = plainPage(); + TQVBoxLayout *tqlayout = new TQVBoxLayout( frame ); + mSelector = new KPIM::AddresseeSelector( selection, frame ); + tqlayout->addWidget( mSelector ); + + resize( 500, 490 ); +} + +void AddresseeSelectorDialog::accept() +{ + mSelector->finish(); + TQDialog::accept(); +} + +#include "addresseeselector.moc" diff --git a/libtdepim/addresseeselector.h b/libtdepim/addresseeselector.h new file mode 100644 index 000000000..7ce70fb84 --- /dev/null +++ b/libtdepim/addresseeselector.h @@ -0,0 +1,234 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KPIM_ADDRESSEESELECTOR_H +#define KPIM_ADDRESSEESELECTOR_H + +#include +#include +#include +#include +#include + +#include +#include +#include + +class KComboBox; +class KLineEdit; +class KListView; +class TQSignalMapper; + +namespace KPIM { + +class AddresseeSelector; + +class KDE_EXPORT Selection +{ + friend class AddresseeSelector; + + public: + virtual ~Selection() {} + + /** + Returns the number of fields the selection offers. + */ + virtual uint fieldCount() const = 0; + + /** + Returns the title for the field specified by index. + */ + virtual TQString fieldTitle( uint index ) const = 0; + + /** + Returns the number of items for the given addressee. + */ + virtual uint itemCount( const KABC::Addressee &addresse ) const = 0; + + /** + Returns the text that's used for the item specified by index. + */ + virtual TQString itemText( const KABC::Addressee &addresse, uint index ) const = 0; + + /** + Returns the icon that's used for the item specified by index. + */ + virtual TQPixmap itemIcon( const KABC::Addressee &addresse, uint index ) const = 0; + + /** + Returns whether the item specified by index is enabled. + */ + virtual bool itemEnabled( const KABC::Addressee &addresse, uint index ) const = 0; + + /** + Returns whether the item specified by index matches the passed pattern. + */ + virtual bool itemMatches( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0; + + /** + Returns whether the item specified by index equals the passed pattern. + */ + virtual bool itemEquals( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0; + + /** + Returns the text that's used for the given distribution list. + */ + virtual TQString distributionListText( const KABC::DistributionList *distributionList ) const = 0; + + /** + Returns the icon that's used for the given distribution list. + */ + virtual TQPixmap distributionListIcon( const KABC::DistributionList *distributionList ) const = 0; + + /** + Returns whether the given distribution list is enabled. + */ + virtual bool distributionListEnabled( const KABC::DistributionList *distributionList ) const = 0; + + /** + Returns whether the given distribution list matches the passed pattern. + */ + virtual bool distributionListMatches( const KABC::DistributionList *distributionList, + const TQString &pattern ) const = 0; + + /** + Returns the number of additional address books. + */ + virtual uint addressBookCount() const = 0; + + /** + Returns the title for an additional address book. + */ + virtual TQString addressBookTitle( uint index ) const = 0; + + /** + Returns the content for an additional address book. + */ + virtual KABC::Addressee::List addressBookContent( uint index ) const = 0; + + protected: + AddresseeSelector* selector() { return mSelector; } + + private: + virtual void addSelectedAddressees( uint fieldIndex, const KABC::Addressee&, uint itemIndex ) = 0; + virtual void addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList* ) = 0; + + void setSelector( AddresseeSelector *selector ) { mSelector = selector; } + + AddresseeSelector *mSelector; +}; + +/** + Internal helper class + */ +class SelectionItem +{ + public: + typedef TQValueList List; + + SelectionItem( const KABC::Addressee &addressee, uint index ); + SelectionItem( KABC::DistributionList *list, uint index ); + SelectionItem(); + + void addToField( int index ); + void removeFromField( int index ); + bool isInField( int index ); + + KABC::Addressee addressee() const; + KABC::DistributionList* distributionList() const; + uint index() const; + + private: + KABC::Addressee mAddressee; + KABC::DistributionList *mDistributionList; + uint mIndex; + TQBitArray mField; +}; + +class KDE_EXPORT AddresseeSelector : public TQWidget +{ + Q_OBJECT + TQ_OBJECT + + public: + AddresseeSelector( Selection *selection, + TQWidget *parent, const char *name = 0 ); + ~AddresseeSelector(); + + /** + Writes back the selected items to the selection. + */ + void finish(); + + void setItemSelected( uint fieldIndex, const KABC::Addressee&, uint itemIndex ); + void setItemSelected( uint fieldIndex, const KABC::Addressee&, + uint itemIndex, const TQString& ); + + private slots: + void move( int index ); + void remove( int index ); + + void updateAddresseeView(); + void reloadAddressBook(); + + private: + void init(); + void initGUI(); + + void updateSelectionView( int index ); + void updateSelectionViews(); + + Selection *mSelection; + + KComboBox *mAddressBookCombo; + KLineEdit *mAddresseeFilter; + KListView *mAddresseeView; + SelectionItem::List mSelectionItems; + + TQValueList mSelectionViews; + TQSignalMapper *mMoveMapper; + TQSignalMapper *mRemoveMapper; + + KABC::DistributionListManager *mManager; + + class AddressBookManager; + AddressBookManager *mAddressBookManager; +}; + +class KDE_EXPORT AddresseeSelectorDialog : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT + + public: + AddresseeSelectorDialog( Selection *selection, + TQWidget *parent = 0, const char *name = 0 ); + + protected slots: + void accept(); + + private: + AddresseeSelector *mSelector; +}; + +} + +#endif diff --git a/libtdepim/addresseeview.cpp b/libtdepim/addresseeview.cpp new file mode 100644 index 000000000..15c7215ed --- /dev/null +++ b/libtdepim/addresseeview.cpp @@ -0,0 +1,792 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "addresseeview.h" +#include "sendsmsdialog.h" +#include "resourceabc.h" + +using namespace KPIM; + +AddresseeView::AddresseeView( TQWidget *parent, const char *name, + KConfig *config ) + : KTextBrowser( parent, name ), mDefaultConfig( false ), mImageJob( 0 ), + mLinkMask( AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks | CustomFields ) +{ + setWrapPolicy( TQTextEdit::AtWordBoundary ); + setLinkUnderline( false ); + setVScrollBarMode( TQScrollView::AlwaysOff ); + setHScrollBarMode( TQScrollView::AlwaysOff ); + + TQStyleSheet *sheet = styleSheet(); + TQStyleSheetItem *link = sheet->item( "a" ); + link->setColor( KGlobalSettings::linkColor() ); + + connect( this, TQT_SIGNAL( mailClick( const TQString&, const TQString& ) ), + this, TQT_SLOT( slotMailClicked( const TQString&, const TQString& ) ) ); + connect( this, TQT_SIGNAL( urlClick( const TQString& ) ), + this, TQT_SLOT( slotUrlClicked( const TQString& ) ) ); + connect( this, TQT_SIGNAL( highlighted( const TQString& ) ), + this, TQT_SLOT( slotHighlighted( const TQString& ) ) ); + + setNotifyClick( true ); + + mActionShowBirthday = new KToggleAction( i18n( "Show Birthday" ) ); + mActionShowBirthday->setCheckedState( i18n( "Hide Birthday" ) ); + mActionShowAddresses = new KToggleAction( i18n( "Show Postal Addresses" ) ); + mActionShowAddresses->setCheckedState( i18n( "Hide Postal Addresses" ) ); + mActionShowEmails = new KToggleAction( i18n( "Show Email Addresses" ) ); + mActionShowEmails->setCheckedState( i18n( "Hide Email Addresses" ) ); + mActionShowPhones = new KToggleAction( i18n( "Show Telephone Numbers" ) ); + mActionShowPhones->setCheckedState( i18n( "Hide Telephone Numbers" ) ); + mActionShowURLs = new KToggleAction( i18n( "Show Web Pages (URLs)" ) ); + mActionShowURLs->setCheckedState( i18n( "Hide Web Pages (URLs)" ) ); + mActionShowIMAddresses = new KToggleAction( i18n( "Show Instant Messaging Addresses" ) ); + mActionShowIMAddresses->setCheckedState( i18n( "Hide Instant Messaging Addresses" ) ); + mActionShowCustomFields = new KToggleAction( i18n( "Show Custom Fields" ) ); + mActionShowCustomFields->setCheckedState( i18n( "Hide Custom Fields" ) ); + + connect( mActionShowBirthday, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); + connect( mActionShowAddresses, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); + connect( mActionShowEmails, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); + connect( mActionShowPhones, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); + connect( mActionShowURLs, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); + connect( mActionShowIMAddresses, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); + connect( mActionShowCustomFields, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) ); + + if ( !config ) { + mConfig = new KConfig( "kaddressbookrc" ); + mDefaultConfig = true; + } else + mConfig = config; + + load(); + + // set up IMProxy to display contacts' IM presence and make connections to keep the display live + mKIMProxy = ::KIMProxy::instance( kapp->dcopClient() ); + connect( mKIMProxy, TQT_SIGNAL( sigContactPresenceChanged( const TQString& ) ), + this, TQT_SLOT( slotPresenceChanged( const TQString& ) ) ); + connect( mKIMProxy, TQT_SIGNAL( sigPresenceInfoExpired() ), + this, TQT_SLOT( slotPresenceInfoExpired() ) ); +} + +AddresseeView::~AddresseeView() +{ + if ( mDefaultConfig ) + delete mConfig; + mConfig = 0; + + delete mActionShowBirthday; + delete mActionShowAddresses; + delete mActionShowEmails; + delete mActionShowPhones; + delete mActionShowURLs; + delete mActionShowIMAddresses; + delete mActionShowCustomFields; + + mKIMProxy = 0; +} + +void AddresseeView::setAddressee( const KABC::Addressee& addr ) +{ + mAddressee = addr; + + if ( mImageJob ) { + mImageJob->kill(); + mImageJob = 0; + } + + mImageData.truncate( 0 ); + + updateView(); +} + +void AddresseeView::enableLinks( int linkMask ) +{ + mLinkMask = linkMask; +} + +TQString AddresseeView::vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask, + bool internalLoading, FieldMask fieldMask ) +{ + TQString image = TQString( "contact_%1_image" ).tqarg( addr.uid() ); + + // Style strings from Gentix; this is just an initial version. + // + // These will be substituted into various HTML strings with .tqarg(). + // Search for @STYLE@ to find where. Note how we use %1 as a + // placeholder where we fill in something else (in this case, + // the global background color). + // + TQString backgroundColor = KGlobalSettings::alternateBackgroundColor().name(); + TQString cellStyle = TQString::tqfromLatin1( + "style=\"" + "padding-right: 2px; " + "border-right: #000 dashed 1px; " + "background: %1;\"").tqarg(backgroundColor); + TQString backgroundColor2 = KGlobalSettings::baseColor().name(); + TQString cellStyle2 = TQString::tqfromLatin1( + "style=\"" + "padding-left: 2px; " + "background: %1;\"").tqarg(backgroundColor2); + TQString tableStyle = TQString::tqfromLatin1( + "style=\"" + "border: solid 1px; " + "margin: 0em;\""); + + // We'll be building a table to display the vCard in. + // Each row of the table will be built using this string for its HTML. + // + TQString rowFmtStr = TQString::tqfromLatin1( + "" + "" // Close tag + "%1" + "" + "" // Close tag + "%2" + "" + "\n" + ) ); + + // Build the table's rows here + TQString dynamicPart; + + + if ( !internalLoading ) { + KABC::Picture pic = addr.photo(); + if ( pic.isIntern() && !pic.data().isNull() ) { + image = pixmapAsDataUrl( pic.data() ); + } else if ( !pic.url().isEmpty() ) { + image = (pic.url().startsWith( "http://" ) || pic.url().startsWith( "https://" ) ? pic.url() : "http://" + pic.url()); + } else { + image = "file:" + KGlobal::iconLoader()->iconPath( "personal", KIcon::Desktop ); + } + } + + if ( fieldMask & BirthdayFields ) { + TQDate date = addr.birthday().date(); + + if ( date.isValid() ) + dynamicPart += rowFmtStr + .tqarg( KABC::Addressee::birthdayLabel() ) + .tqarg( KGlobal::locale()->formatDate( date, true ) ); + } + + if ( fieldMask & PhoneFields ) { + KABC::PhoneNumber::List phones = addr.phoneNumbers(); + KABC::PhoneNumber::List::ConstIterator phoneIt; + for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { + TQString number = TQStyleSheet::escape( (*phoneIt).number() ); + + TQString url; + if ( (*phoneIt).type() & KABC::PhoneNumber::Fax ) + url = TQString::tqfromLatin1( "fax:" ) + number; + else + url = TQString::tqfromLatin1( "phone:" ) + number; + + if ( linkMask & PhoneLinks ) { + TQString smsURL; + if ( (*phoneIt).type() & KABC::PhoneNumber::Cell ) + smsURL = TQString(" (%2)" ).tqarg( number ).tqarg( i18n( "SMS") ); + + dynamicPart += rowFmtStr + .tqarg( (*phoneIt).typeLabel().replace( " ", " " ) ) + .tqarg( TQString::tqfromLatin1( "%2%3" ).tqarg( url ).tqarg( number ).tqarg( smsURL ) ); + } else { + dynamicPart += rowFmtStr + .tqarg( (*phoneIt).typeLabel().replace( " ", " " ) ) + .tqarg( number ); + } + } + } + + if ( fieldMask & EmailFields ) { + TQStringList emails = addr.emails(); + TQStringList::ConstIterator emailIt; + TQString type = i18n( "Email" ); + for ( emailIt = emails.begin(); emailIt != emails.end(); ++emailIt ) { + TQString fullEmail = addr.fullEmail( *emailIt ); + TQUrl::encode( fullEmail ); + + if ( linkMask & EmailLinks ) { + dynamicPart += rowFmtStr.tqarg( type ) + .tqarg( TQString::tqfromLatin1( "%2" ) + .tqarg( fullEmail, TQStyleSheet::escape( *emailIt ) ) ); + } else { + dynamicPart += rowFmtStr.tqarg( type ).tqarg( *emailIt ); + } + } + } + + if ( fieldMask & URLFields ) { + if ( !addr.url().url().isEmpty() ) { + TQString url; + if ( linkMask & URLLinks ) { + url = (addr.url().url().startsWith( "http://" ) || addr.url().url().startsWith( "https://" ) ? addr.url().prettyURL() : + "http://" + addr.url().prettyURL()); + url = KStringHandler::tagURLs( url ); + } else { + url = addr.url().prettyURL(); + } + dynamicPart += rowFmtStr.tqarg( i18n("Homepage") ).tqarg( url ); + } + + TQString blog = addr.custom( "KADDRESSBOOK", "BlogFeed" ); + if ( !blog.isEmpty() ) { + if ( linkMask & URLLinks ) { + blog = KStringHandler::tagURLs( blog ); + } + dynamicPart += rowFmtStr.tqarg( i18n("Blog Feed") ).tqarg( blog ); + } + } + + if ( fieldMask & AddressFields ) { + KABC::Address::List addresses = addr.addresses(); + KABC::Address::List::ConstIterator addrIt; + for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { + if ( (*addrIt).label().isEmpty() ) { + TQString formattedAddress; + + formattedAddress = TQStyleSheet::escape( (*addrIt).formattedAddress().stripWhiteSpace() ); + formattedAddress = formattedAddress.replace( '\n', "
" ); + + TQString link = "" + + formattedAddress + ""; + + if ( linkMask & AddressLinks ) { + dynamicPart += rowFmtStr + .tqarg( KABC::Address::typeLabel( (*addrIt).type() ) ) + .tqarg( link ); + } else { + dynamicPart += rowFmtStr + .tqarg( KABC::Address::typeLabel( (*addrIt).type() ) ) + .tqarg( formattedAddress ); + } + } else { + TQString link = "" + + (*addrIt).label().replace( '\n', "
" ) + "
"; + + if ( linkMask & AddressLinks ) { + dynamicPart += rowFmtStr + .tqarg( KABC::Address::typeLabel( (*addrIt).type() ) ) + .tqarg( link ); + } else { + dynamicPart += rowFmtStr + .tqarg( KABC::Address::typeLabel( (*addrIt).type() ) ) + .tqarg( (*addrIt).label().replace( '\n', "
" ) ); + } + } + } + } + + TQString notes; + if ( !addr.note().isEmpty() ) { + // @STYLE@ - substitute the cell style in first, and append + // the data afterwards (keeps us safe from possible % signs + // in either one). + notes = TQStyleSheet::escape( addr.note() ); + notes = rowFmtStr.tqarg( i18n( "Notes" ) ).tqarg( notes.replace( '\n', "
" ) ) ; + } + + TQString customData; + if ( fieldMask & CustomFields ) { + static TQMap titleMap; + if ( titleMap.isEmpty() ) { + titleMap.insert( "Department", i18n( "Department" ) ); + titleMap.insert( "Profession", i18n( "Profession" ) ); + titleMap.insert( "AssistantsName", i18n( "Assistant's Name" ) ); + titleMap.insert( "ManagersName", i18n( "Manager's Name" ) ); + titleMap.insert( "SpousesName", i18n( "Partner's Name" ) ); + titleMap.insert( "Office", i18n( "Office" ) ); + titleMap.insert( "Anniversary", i18n( "Anniversary" ) ); + } + + if ( !addr.customs().empty() ) { + TQStringList customs = addr.customs(); + TQStringList::Iterator it( customs.begin() ); + const TQStringList::Iterator endIt( customs.end() ); + for ( ; it != endIt; ++it ) { + TQString customEntry = *it; + if ( customEntry.startsWith ( "KADDRESSBOOK-" ) ) { + customEntry.remove( "KADDRESSBOOK-X-" ); + customEntry.remove( "KADDRESSBOOK-" ); + + int pos = customEntry.find( ':' ); + TQString key = customEntry.left( pos ); + const TQString value = customEntry.mid( pos + 1 ); + + // blog and im address is handled separated + if ( key == "BlogFeed" || key == "IMAddress" ) + continue; + + const TQMap::ConstIterator keyIt = titleMap.find( key ); + if ( keyIt != titleMap.end() ) + key = keyIt.data(); + + customData += rowFmtStr.tqarg( key ).tqarg( TQStyleSheet::escape( value ) ) ; + } + } + } + } + + TQString name( TQStyleSheet::escape( addr.realName() ) ); + TQString role( TQStyleSheet::escape( addr.role() ) ); + TQString organization( TQStyleSheet::escape( addr.organization() ) ); + + if ( fieldMask & IMFields ) { + + const TQString imAddress = addr.custom( "KADDRESSBOOK", "X-IMAddress" ); + if ( !imAddress.isEmpty() ) { + customData += rowFmtStr.tqarg( i18n( "IM Address" ) ).tqarg( TQStyleSheet::escape( imAddress ) ) ; + } + + if ( proxy ) { + if ( proxy->isPresent( addr.uid() ) && proxy->presenceNumeric( addr.uid() ) > 0 ) { + // set image source to either a TQMimeSourceFactory key or a data:/ URL + TQString imgSrc; + if ( internalLoading ) { + imgSrc = TQString::tqfromLatin1( "im_status_%1_image").tqarg( addr.uid() ); + TQMimeSourceFactory::defaultFactory()->setPixmap( imgSrc, proxy->presenceIcon( addr.uid() ) ); + } else + imgSrc = pixmapAsDataUrl( proxy->presenceIcon( addr.uid() ) ); + + // make the status a link, if required + TQString imtqStatus; + if ( linkMask & IMLinks ) + imtqStatus = TQString::tqfromLatin1( " (%2)" ); + else + imtqStatus = TQString::tqfromLatin1( " (%2)" ); + + // append our status to the rest of the dynamic part of the addressee + dynamicPart += rowFmtStr + .tqarg( i18n( "Presence" ) ) + .tqarg( imtqStatus + .tqarg( imgSrc ) + .tqarg( proxy->presenceString( addr.uid() ) ) + ); + } + } + } + + // @STYLE@ - construct the string by parts, substituting in + // the styles first. There are lots of appends, but we need to + // do it this way to avoid cases where the substituted string + // contains %1 and the like. + // + TQString strAddr = TQString::tqfromLatin1( + "
" + "" + "").tqarg(tableStyle); + + strAddr.append( TQString::tqfromLatin1( + "") + .tqarg( image ) ); + strAddr.append( TQString::tqfromLatin1( + "" // name + "") + .tqarg( name ) ); + strAddr.append( TQString::tqfromLatin1( + "" + "" // role + "") + .tqarg( role ) ); + strAddr.append( TQString::tqfromLatin1( + "" + "" // organization + "") + .tqarg( organization ) ); + strAddr.append( TQString::tqfromLatin1( + "") + .tqarg( cellStyle2 ) ); + strAddr.append( dynamicPart ); + strAddr.append( notes ); + strAddr.append( customData ); + strAddr.append( TQString::tqfromLatin1( "
") + .tqarg( cellStyle ) ); + strAddr.append( TQString::tqfromLatin1( + "" // image + "") + .tqarg( cellStyle2 ) ); + strAddr.append( TQString::tqfromLatin1( + "%2
") + .tqarg( cellStyle2 ) ); + strAddr.append( TQString::tqfromLatin1( + "%3
") + .tqarg( cellStyle2 ) ); + strAddr.append( TQString::tqfromLatin1( + "%4
") + .tqarg( cellStyle ) ); + strAddr.append( TQString::tqfromLatin1( + "  
\n" ) ); + + if ( addr.resource() ) { + TQString addrBookName = addr.resource()->resourceName(); + ResourceABC *r = dynamic_cast( addr.resource() ); + if ( r && !r->subresources().isEmpty() ) { + const TQString subRes = r->uidToResourceMap()[ addr.uid() ]; + const TQString label = r->subresourceLabel( subRes ); + if ( !label.isEmpty() ) + addrBookName = label; + } + strAddr.append( i18n( "

Address book: %1

" ).tqarg( addrBookName ) ); + } + return strAddr; +} + +TQString AddresseeView::pixmapAsDataUrl( const TQPixmap& pixmap ) +{ + TQByteArray ba; + TQBuffer buffer( ba ); + buffer.open( IO_WriteOnly ); + pixmap.save( &buffer, "PNG" ); + TQString encoded( "data:image/png;base64," ); + encoded.append( KCodecs::base64Encode( ba ) ); + return encoded; +} + +void AddresseeView::updateView() +{ + // clear view + setText( TQString() ); + + if ( mAddressee.isEmpty() ) + return; + + if ( mImageJob ) { + mImageJob->kill(); + mImageJob = 0; + + mImageData.truncate( 0 ); + } + + int fieldMask = NoFields; + if ( mActionShowBirthday->isChecked() ) + fieldMask |= ( FieldMask )BirthdayFields; + if ( mActionShowAddresses->isChecked() ) + fieldMask |= AddressFields; + if ( mActionShowEmails->isChecked() ) + fieldMask |= EmailFields; + if ( mActionShowPhones->isChecked() ) + fieldMask |= PhoneFields; + if ( mActionShowURLs->isChecked() ) + fieldMask |= URLFields; + if ( mActionShowIMAddresses->isChecked() ) + fieldMask |= IMFields; + if ( mActionShowCustomFields->isChecked() ) + fieldMask |= CustomFields; + + TQString strAddr = vCardAsHTML( mAddressee, mKIMProxy, (LinkMask)mLinkMask, + true, (FieldMask)fieldMask ); + + strAddr = TQString::tqfromLatin1( + "" + "" // text and background color + "%3" // dynamic part + "" + "" ) + .tqarg( KGlobalSettings::textColor().name() ) + .tqarg( KGlobalSettings::baseColor().name() ) + .tqarg( strAddr ); + + TQString imageURL = TQString( "contact_%1_image" ).tqarg( mAddressee.uid() ); + + KABC::Picture picture = mAddressee.photo(); + if ( picture.isIntern() && !picture.data().isNull() ) + TQMimeSourceFactory::defaultFactory()->setImage( imageURL, picture.data() ); + else { + if ( !picture.url().isEmpty() ) { + if ( mImageData.count() > 0 ) + TQMimeSourceFactory::defaultFactory()->setImage( imageURL, TQImage(mImageData) ); + else { + mImageJob = KIO::get( KURL( picture.url() ), false, false ); + connect( mImageJob, TQT_SIGNAL( data( KIO::Job*, const TQByteArray& ) ), + this, TQT_SLOT( data( KIO::Job*, const TQByteArray& ) ) ); + connect( mImageJob, TQT_SIGNAL( result( KIO::Job* ) ), + this, TQT_SLOT( result( KIO::Job* ) ) ); + } + } else { + TQMimeSourceFactory::defaultFactory()->setPixmap( imageURL, + KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 128 ) ); + } + } + + // at last display it... + setText( strAddr ); +} + +KABC::Addressee AddresseeView::addressee() const +{ + return mAddressee; +} + +void AddresseeView::urlClicked( const TQString &url ) +{ + kapp->invokeBrowser( url ); +} + +void AddresseeView::emailClicked( const TQString &email ) +{ + if ( email.startsWith( "mailto:" ) ) + kapp->invokeMailer( email.mid( 7 ), TQString() ); + else + kapp->invokeMailer( email, TQString() ); +} + +void AddresseeView::phoneNumberClicked( const TQString &number ) +{ + KConfig config( "kaddressbookrc" ); + config.setGroup( "General" ); + TQString commandLine = config.readEntry( "PhoneHookApplication" ); + + if ( commandLine.isEmpty() ) { + KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) ); + return; + } + + commandLine.replace( "%N", number ); + KRun::runCommand( commandLine ); +} + +void AddresseeView::smsTextClicked( const TQString &number ) +{ + KConfig config( "kaddressbookrc" ); + config.setGroup( "General" ); + TQString commandLine = config.readEntry( "SMSHookApplication" ); + + if ( commandLine.isEmpty() ) { + KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) ); + return; + } + + SendSMSDialog dlg( mAddressee.realName(), this ); + + if ( dlg.exec() ) + sendSMS ( number, dlg.text() ); +} + +void AddresseeView::sendSMS( const TQString &number, const TQString &text ) +{ + KConfig config( "kaddressbookrc" ); + config.setGroup( "General" ); + TQString commandLine = config.readEntry( "SMSHookApplication" ); + + KTempFile file ; + TQTextStream* stream = file.textStream(); + *stream << text; + file.close(); + + commandLine.replace( "%N", number ); + commandLine.replace( "%F", file.name() ); + + KRun::runCommand( commandLine ); +} + +void AddresseeView::faxNumberClicked( const TQString &number ) +{ + KConfig config( "kaddressbookrc" ); + config.setGroup( "General" ); + TQString commandLine = config.readEntry( "FaxHookApplication", "tdeprintfax --phone %N" ); + + if ( commandLine.isEmpty() ) { + KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) ); + return; + } + + commandLine.replace( "%N", number ); + KRun::runCommand( commandLine ); +} + +void AddresseeView::imAddressClicked() +{ + mKIMProxy->chatWithContact( mAddressee.uid() ); +} + +TQPopupMenu *AddresseeView::createPopupMenu( const TQPoint& ) +{ + TQPopupMenu *menu = new TQPopupMenu( this ); + mActionShowBirthday->plug( menu ); + mActionShowAddresses->plug( menu ); + mActionShowEmails->plug( menu ); + mActionShowPhones->plug( menu ); + mActionShowURLs->plug( menu ); + mActionShowIMAddresses->plug( menu ); + mActionShowCustomFields->plug( menu ); + + return menu; +} + +void AddresseeView::slotMailClicked( const TQString&, const TQString &email ) +{ + emailClicked( email ); +} + +void AddresseeView::slotUrlClicked( const TQString &url ) +{ + if ( url.startsWith( "phone:" ) ) + phoneNumberClicked( strippedNumber( url.mid( 8 ) ) ); + else if ( url.startsWith( "sms:" ) ) + smsTextClicked( strippedNumber( url.mid( 6 ) ) ); + else if ( url.startsWith( "fax:" ) ) + faxNumberClicked( strippedNumber( url.mid( 6 ) ) ); + else if ( url.startsWith( "addr:" ) ) + emit addressClicked( url.mid( 7 ) ); + else if ( url.startsWith( "im:" ) ) + imAddressClicked(); + else + urlClicked( url ); +} + +void AddresseeView::slotHighlighted( const TQString &link ) +{ + if ( link.startsWith( "mailto:" ) ) { + TQString email = link.mid( 7 ); + + emit emailHighlighted( email ); + emit highlightedMessage( i18n( "Send mail to '%1'" ).tqarg( email ) ); + } else if ( link.startsWith( "phone:" ) ) { + TQString number = link.mid( 8 ); + + emit phoneNumberHighlighted( strippedNumber( number ) ); + emit highlightedMessage( i18n( "Call number %1" ).tqarg( number ) ); + } else if ( link.startsWith( "fax:" ) ) { + TQString number = link.mid( 6 ); + + emit faxNumberHighlighted( strippedNumber( number ) ); + emit highlightedMessage( i18n( "Send fax to %1" ).tqarg( number ) ); + } else if ( link.startsWith( "addr:" ) ) { + emit highlightedMessage( i18n( "Show address on map" ) ); + } else if ( link.startsWith( "sms:" ) ) { + TQString number = link.mid( 6 ); + emit highlightedMessage( i18n( "Send SMS to %1" ).tqarg( number ) ); + } else if ( link.startsWith( "http:" ) || link.startsWith( "https:" ) ) { + emit urlHighlighted( link ); + emit highlightedMessage( i18n( "Open URL %1" ).tqarg( link ) ); + } else if ( link.startsWith( "im:" ) ) { + emit highlightedMessage( i18n( "Chat with %1" ).tqarg( mAddressee.realName() ) ); + } else + emit highlightedMessage( "" ); +} + +void AddresseeView::slotPresenceChanged( const TQString &uid ) +{ + kdDebug() << k_funcinfo << " uid is: " << uid << " mAddressee is: " << mAddressee.uid() << endl; + if ( uid == mAddressee.uid() ) + updateView(); +} + + +void AddresseeView::slotPresenceInfoExpired() +{ + updateView(); +} + +void AddresseeView::configChanged() +{ + save(); + updateView(); +} + +void AddresseeView::data( KIO::Job*, const TQByteArray &d ) +{ + unsigned int oldSize = mImageData.size(); + mImageData.resize( oldSize + d.size() ); + memcpy( mImageData.data() + oldSize, d.data(), d.size() ); +} + +void AddresseeView::result( KIO::Job *job ) +{ + mImageJob = 0; + + if ( job->error() ) + mImageData.truncate( 0 ); + else + updateView(); +} + +void AddresseeView::load() +{ + mConfig->setGroup( "AddresseeViewSettings" ); + mActionShowBirthday->setChecked( mConfig->readBoolEntry( "ShowBirthday", false ) ); + mActionShowAddresses->setChecked( mConfig->readBoolEntry( "ShowAddresses", true ) ); + mActionShowEmails->setChecked( mConfig->readBoolEntry( "ShowEmails", true ) ); + mActionShowPhones->setChecked( mConfig->readBoolEntry( "ShowPhones", true ) ); + mActionShowURLs->setChecked( mConfig->readBoolEntry( "ShowURLs", true ) ); + mActionShowIMAddresses->setChecked( mConfig->readBoolEntry( "ShowIMAddresses", false ) ); + mActionShowCustomFields->setChecked( mConfig->readBoolEntry( "ShowCustomFields", false ) ); +} + +void AddresseeView::save() +{ + mConfig->setGroup( "AddresseeViewSettings" ); + mConfig->writeEntry( "ShowBirthday", mActionShowBirthday->isChecked() ); + mConfig->writeEntry( "ShowAddresses", mActionShowAddresses->isChecked() ); + mConfig->writeEntry( "ShowEmails", mActionShowEmails->isChecked() ); + mConfig->writeEntry( "ShowPhones", mActionShowPhones->isChecked() ); + mConfig->writeEntry( "ShowURLs", mActionShowURLs->isChecked() ); + mConfig->writeEntry( "ShowIMAddresses", mActionShowIMAddresses->isChecked() ); + mConfig->writeEntry( "ShowCustomFields", mActionShowCustomFields->isChecked() ); + mConfig->sync(); +} + +TQString AddresseeView::strippedNumber( const TQString &number ) +{ + TQString retval; + + for ( uint i = 0; i < number.length(); ++i ) { + TQChar c = number[ i ]; + if ( c.isDigit() || (((c == '*') || (c == '#') || (c == '+')) && (i == 0)) ) + retval.append( c ); + } + + return retval; +} + +#include "addresseeview.moc" diff --git a/libtdepim/addresseeview.h b/libtdepim/addresseeview.h new file mode 100644 index 000000000..0b7c13b05 --- /dev/null +++ b/libtdepim/addresseeview.h @@ -0,0 +1,205 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KPIM_ADDRESSEEVIEW_H +#define KPIM_ADDRESSEEVIEW_H + +#include + +#include +#include +#include +#include + +namespace KIO { +class Job; +} +class KToggleAction; + +class TQPopupMenu; + + +namespace KPIM { + + +class KDE_EXPORT AddresseeView : public KTextBrowser +{ + Q_OBJECT + TQ_OBJECT + public: + /** + Constructor. + + @param config The config object where the settings are stored + which fields will be shown. + */ + AddresseeView( TQWidget *parent = 0, const char *name = 0, + KConfig *config = 0 ); + + ~AddresseeView(); + + /** + Sets the addressee object. The addressee is displayed immediately. + + @param addr The addressee object. + */ + void setAddressee( const KABC::Addressee& addr ); + + /** + Returns the current addressee object. + */ + KABC::Addressee addressee() const; + + + /** + This enums are used by enableLinks to set which kind of links shall + be enabled. + */ + enum LinkMask { + NoLinks = 0, + AddressLinks = 1, + EmailLinks = 2, + PhoneLinks = 4, + URLLinks = 8, + IMLinks = 16, + DefaultLinks = AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks + }; + + /** + Sets which parts of the contact shall be presented as links. + The mask can be OR'ed LinkMask. By default all links are enabled. + */ + void enableLinks( int linkMask ); + + /** + This enums are used by vCardAsHTML to decide which fields shall be + shown. + */ + enum FieldMask { + NoFields = 0, + BirthdayFields = 1, + AddressFields = 2, + EmailFields = 4, + PhoneFields = 8, + URLFields = 16, + IMFields = 32, + CustomFields = 64, + DefaultFields = AddressFields | EmailFields | PhoneFields | URLFields + }; + + /** + Returns the HTML representation of a contact. + The HTML code looks like +
+ + ... +
+
+ + @param addr The addressee object. + @param linkMask The mask for which parts of the contact will + be displayed as links. + The links looks like this: + "addr://" for addresses + "mailto:" for emails + "phone://" for phone numbers + "http://" for urls + "im:" for instant messaging addresses + "sms://" for sending a sms + @param internalLoading If true, the loading of internal pictures is done automatically. + @param fieldMask The mask for which fields of the contact will + be displayed. + */ + static TQString vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask = DefaultLinks, + bool internalLoading = true, FieldMask fieldMask = DefaultFields ); + + /** + * Encodes a TQPixmap as a PNG into a data: URL (rfc2397), readable by the data kio protocol + * @param pixmap the pixmap to encode + * @return a data: URL + */ + static TQString pixmapAsDataUrl( const TQPixmap& pixmap ); + + signals: + void urlHighlighted( const TQString &url ); + void emailHighlighted( const TQString &email ); + void phoneNumberHighlighted( const TQString &number ); + void faxNumberHighlighted( const TQString &number ); + + void highlightedMessage( const TQString &message ); + + void addressClicked( const TQString &uid ); + + protected: + virtual void urlClicked( const TQString &url ); + virtual void emailClicked( const TQString &mail ); + virtual void phoneNumberClicked( const TQString &number ); + virtual void smsTextClicked( const TQString &number ); + virtual void sendSMS( const TQString &number, const TQString &msg ); + virtual void faxNumberClicked( const TQString &number ); + virtual void imAddressClicked(); + + virtual TQPopupMenu *createPopupMenu( const TQPoint& ); + + private slots: + void slotMailClicked( const TQString&, const TQString& ); + void slotUrlClicked( const TQString& ); + void slotHighlighted( const TQString& ); + void slotPresenceChanged( const TQString & ); + void slotPresenceInfoExpired(); + void configChanged(); + + void data( KIO::Job*, const TQByteArray& ); + void result( KIO::Job* ); + + private: + void load(); + void save(); + + void updateView(); + + TQString strippedNumber( const TQString &number ); + + KConfig *mConfig; + bool mDefaultConfig; + + TQByteArray mImageData; + KIO::Job *mImageJob; + + KToggleAction *mActionShowBirthday; + KToggleAction *mActionShowAddresses; + KToggleAction *mActionShowEmails; + KToggleAction *mActionShowPhones; + KToggleAction *mActionShowURLs; + KToggleAction *mActionShowIMAddresses; + KToggleAction *mActionShowCustomFields; + + KABC::Addressee mAddressee; + int mLinkMask; + + class AddresseeViewPrivate; + AddresseeViewPrivate *d; + ::KIMProxy *mKIMProxy; +}; + +} + +#endif diff --git a/libtdepim/addressesdialog.cpp b/libtdepim/addressesdialog.cpp new file mode 100644 index 000000000..27f601833 --- /dev/null +++ b/libtdepim/addressesdialog.cpp @@ -0,0 +1,1197 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- + * + * This file is part of libtdepim. + * + * Copyright (c) 2003 Zack Rusin + * Copyright (c) 2003 Aaron J. Seigo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "addressesdialog.h" +#include "addresspicker.h" +#include "ldapsearchdialog.h" + +#include + +#include + +#ifdef KDEPIM_NEW_DISTRLISTS +#include "distributionlist.h" +#include +#include +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace KPIM { + +// private start : +struct AddresseeViewItem::AddresseeViewItemPrivate { + KABC::Addressee address; + AddresseeViewItem::Category category; + KABC::Addressee::List addresses; +}; + +struct AddressesDialog::AddressesDialogPrivate { + AddressesDialogPrivate() : + ui(0), personal(0), recent(0), + toItem(0), ccItem(0), bccItem(0), + ldapSearchDialog(0) + {} + + AddressPickerUI *ui; + + AddresseeViewItem *personal; + AddresseeViewItem *recent; + AddresseeViewItem *topdist; + TQPtrList dists; + + AddresseeViewItem *toItem; + AddresseeViewItem *ccItem; + AddresseeViewItem *bccItem; + + TQDict groupDict; + + KABC::Addressee::List recentAddresses; + LDAPSearchDialog *ldapSearchDialog; +}; +// privates end + +AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent, const KABC::Addressee& addr, + int emailIndex ) + : TQObject( 0 ), KListViewItem( parent, addr.realName(), + ( emailIndex == 0 ? addr.preferredEmail() : addr.emails()[ emailIndex ] ) ) +{ + d = new AddresseeViewItemPrivate; + d->address = addr; + d->category = Entry; + + if ( text( 0 ).stripWhiteSpace().isEmpty() ) + setText( 0, addr.preferredEmail() ); + + if ( addr.photo().url().isEmpty() ) { + if ( addr.photo().data().isNull() ) + setPixmap( 0, KGlobal::iconLoader()->loadIcon( "personal", KIcon::Small ) ); + else + setPixmap( 0, addr.photo().data().smoothScale( 16, 16 ) ); + } else { + setPixmap( 0, KGlobal::iconLoader()->loadIcon( addr.photo().url(), KIcon::Small ) ); + } +} + +AddresseeViewItem::AddresseeViewItem( KListView *lv, const TQString& name, Category cat ) + : TQObject(0), KListViewItem( lv, name ) +{ + d = new AddresseeViewItemPrivate; + d->category = cat; +} + +AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent, const TQString& name, + const KABC::Addressee::List &lst ) + : TQObject(0), KListViewItem( parent, name, i18n("") ) +{ + d = new AddresseeViewItemPrivate; + d->category = FilledGroup; + d->addresses = lst; +} + +AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent, const TQString& name ) + : TQObject(0), KListViewItem( parent, name, i18n("") ) +{ + d = new AddresseeViewItemPrivate; + d->category = DistList; + + setPixmap( 0, KGlobal::iconLoader()->loadIcon( "kdmconfig", KIcon::Small ) ); +} + +AddresseeViewItem::~AddresseeViewItem() +{ + delete d; + d = 0; +} + +KABC::Addressee +AddresseeViewItem::addressee() const +{ + return d->address; +} + +KABC::Addressee::List +AddresseeViewItem::addresses() const +{ + return d->addresses; +} + +AddresseeViewItem::Category +AddresseeViewItem::category() const +{ + return d->category; +} + +TQString +AddresseeViewItem::name() const +{ + return text(0); +} + +TQString +AddresseeViewItem::email() const +{ + return text(1); +} + +bool AddresseeViewItem::matches(const TQString& txt) const +{ + return d->address.realName().contains(txt, false) || d->address.preferredEmail().contains(txt, false); +} + +void AddresseeViewItem::setSelected(bool selected) +{ + if (selected == isSelected()) + { + return; + } + + emit addressSelected( this, selected ); + TQListViewItem::setSelected(selected); +} + +int +AddresseeViewItem::compare( TQListViewItem * i, int col, bool ascending ) const +{ + if ( category() == Group || category() == Entry ) + return KListViewItem::compare( i , col, ascending ); + + AddresseeViewItem *item = static_cast( i ); + int a = static_cast( category() ); + int b = static_cast( item->category() ); + + if ( ascending ) + if ( a < b ) + return -1; + else + return 1; + else + if ( a < b ) + return 1; + else + return -1; +} + +AddressesDialog::AddressesDialog( TQWidget *widget, const char *name ) + : KDialogBase( widget, name, true, i18n("Address Selection"), + Ok|Cancel, Ok, true ) +{ + TQVBox *page = makeVBoxMainWidget(); + d = new AddressesDialogPrivate; + d->ui = new AddressPickerUI( page ); + + KABC::StdAddressBook::self( true ); + updateAvailableAddressees(); + initConnections(); + + d->ui->mAvailableView->setFocus(); + + setMainWidget( page ); + page->setMinimumSize( 750, 400 ); +} + +AddressesDialog::~AddressesDialog() +{ + delete d; + d = 0; +} + +AddresseeViewItem* AddressesDialog::selectedToItem() +{ + if ( !d->toItem ) + { + d->toItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("To"), AddresseeViewItem::To ); + connect(d->toItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + } + return d->toItem; +} + +AddresseeViewItem* AddressesDialog::selectedCcItem() +{ + if ( !d->ccItem ) + { + d->ccItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("CC"), AddresseeViewItem::CC ); + connect(d->ccItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + } + return d->ccItem; +} + +AddresseeViewItem* AddressesDialog::selectedBccItem() +{ + if ( !d->bccItem ) + { + d->bccItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("BCC"), AddresseeViewItem::BCC ); + connect(d->bccItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + } + return d->bccItem; +} + +void +AddressesDialog::setSelectedTo( const TQStringList& l ) +{ + TQString name, email; + for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) { + KABC::Addressee addr; + KABC::Addressee::parseEmailAddress( *it, name, email ); + addr.setNameFromString( name ); + addr.insertEmail( email ); + addAddresseeToSelected( addr, selectedToItem() ); + } +} + +void +AddressesDialog::setSelectedCC( const TQStringList& l ) +{ + TQString name, email; + for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) { + KABC::Addressee addr; + KABC::Addressee::parseEmailAddress( *it, name, email ); + addr.setNameFromString( name ); + addr.insertEmail( email ); + addAddresseeToSelected( addr, selectedCcItem() ); + } +} + +void +AddressesDialog::setSelectedBCC( const TQStringList& l ) +{ + TQString name, email; + for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) { + KABC::Addressee addr; + KABC::Addressee::parseEmailAddress( *it, name, email ); + addr.setNameFromString( name ); + addr.insertEmail( email ); + addAddresseeToSelected( addr, selectedBccItem() ); + } +} + +void +AddressesDialog::setRecentAddresses( const KABC::Addressee::List& list ) +{ + d->recentAddresses = list; + + updateRecentAddresses(); + + checkForSingleAvailableGroup(); +} + +void +AddressesDialog::updateRecentAddresses() +{ + static const TQString &recentGroup = KGlobal::staticQString( i18n( "Recent Addresses" ) ); + + if ( !d->recent ) { + d->recent = new AddresseeViewItem( d->ui->mAvailableView, recentGroup ); + connect(d->recent, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(availableAddressSelected(AddresseeViewItem*, bool))); + d->recent->setVisible( false ); + d->groupDict.insert( recentGroup, d->recent ); + } + + KABC::Addressee::List::ConstIterator it; + for ( it = d->recentAddresses.begin(); it != d->recentAddresses.end(); ++it ) + addAddresseeToAvailable( *it, d->recent ); + + if ( d->recent->childCount() > 0 ) { + d->recent->setOpen( true ); + d->recent->setVisible( true ); + } +} + +void +AddressesDialog::setShowCC( bool b ) +{ + d->ui->mCCButton->setShown( b ); +} + +void +AddressesDialog::setShowBCC( bool b ) +{ + d->ui->mBCCButton->setShown( b ); +} + +TQStringList +AddressesDialog::to() const +{ + TQStringList emails = allDistributionLists( d->toItem ); + KABC::Addressee::List l = toAddresses(); + emails += entryToString( l ); + + return emails; +} + +TQStringList +AddressesDialog::cc() const +{ + TQStringList emails = allDistributionLists( d->ccItem ); + KABC::Addressee::List l = ccAddresses(); + emails += entryToString( l ); + + return emails; +} + +TQStringList +AddressesDialog::bcc() const +{ + TQStringList emails = allDistributionLists( d->bccItem ); + + KABC::Addressee::List l = bccAddresses(); + emails += entryToString( l ); + + return emails; +} + +KABC::Addressee::List +AddressesDialog::toAddresses() const +{ + return allAddressee( d->toItem ); +} +KABC::Addressee::List +AddressesDialog::allToAddressesNoDuplicates() const +{ + KABC::Addressee::List aList = allAddressee( d->toItem ); + const TQStringList dList = toDistributionLists(); + KABC::AddressBook* abook = KABC::StdAddressBook::self( true ); +#ifdef KDEPIM_NEW_DISTRLISTS + for ( TQStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) { + const TQValueList eList + = KPIM::DistributionList::findByName(abook, *it).entries(abook); + TQValueList::ConstIterator eit; + for( eit = eList.begin(); eit != eList.end(); ++eit ) { + KABC::Addressee a = (*eit).addressee; + if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) { + aList.append( a ) ; + } + } + } +#else + KABC::DistributionListManager manager( abook ); + manager.load(); + for ( TQStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) { + const TQValueList eList = manager.list( *it )->entries(); + TQValueList::ConstIterator eit; + for( eit = eList.begin(); eit != eList.end(); ++eit ) { + KABC::Addressee a = (*eit).addressee; + if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) { + aList.append( a ) ; + } + } + } +#endif + return aList; +} + +KABC::Addressee::List +AddressesDialog::ccAddresses() const +{ + return allAddressee( d->ccItem ); +} + +KABC::Addressee::List +AddressesDialog::bccAddresses() const +{ + return allAddressee( d->bccItem ); +} + + +TQStringList +AddressesDialog::toDistributionLists() const +{ + return allDistributionLists( d->toItem ); +} + +TQStringList +AddressesDialog::ccDistributionLists() const +{ + return allDistributionLists( d->ccItem ); +} + +TQStringList +AddressesDialog::bccDistributionLists() const +{ + return allDistributionLists( d->bccItem ); +} + +void +AddressesDialog::updateAvailableAddressees() +{ + d->ui->mAvailableView->clear(); + d->groupDict.clear(); + + static const TQString &personalGroup = KGlobal::staticQString( i18n( "Other Addresses" ) ); + d->ui->mAvailableView->setRootIsDecorated( true ); + d->personal = new AddresseeViewItem( d->ui->mAvailableView, personalGroup ); + //connect(d->personal, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + // this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + d->personal->setVisible( false ); + d->groupDict.insert( personalGroup, d->personal ); + + KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); + for( KABC::AddressBook::Iterator it = addressBook->begin(); + it != addressBook->end(); ++it ) { + addAddresseeToAvailable( *it, d->personal ); + } + + d->recent = 0; + updateRecentAddresses(); + + d->topdist = 0; + addDistributionLists(); + if ( d->personal->childCount() > 0 ) { + d->personal->setOpen( true ); + d->personal->setVisible( true ); + } + + checkForSingleAvailableGroup(); +} + +void AddressesDialog::checkForSingleAvailableGroup() +{ + TQListViewItem* item = d->ui->mAvailableView->firstChild(); + TQListViewItem* firstGroup = 0; + int found = 0; + while (item) + { + if (item->isVisible()) + { + if (!firstGroup && static_cast(item)->category() != AddresseeViewItem::Entry) + { + firstGroup = item; + } + ++found; + } + item = item->nextSibling(); + } + + if (found == 1 && firstGroup) + { + firstGroup->setOpen(true); + } +} + +void +AddressesDialog::availableSelectionChanged() +{ + bool selection = !selectedAvailableAddresses.isEmpty(); + d->ui->mToButton->setEnabled(selection); + d->ui->mCCButton->setEnabled(selection); + d->ui->mBCCButton->setEnabled(selection); +} + +void +AddressesDialog::selectedSelectionChanged() +{ + bool selection = !selectedSelectedAddresses.isEmpty(); + d->ui->mRemoveButton->setEnabled(selection); +} + +void +AddressesDialog::availableAddressSelected( AddresseeViewItem* item, bool selected ) +{ + if (selected) + { + selectedAvailableAddresses.append(item); + } + else + { + selectedAvailableAddresses.remove(item); + } +} + +void +AddressesDialog::selectedAddressSelected( AddresseeViewItem* item, bool selected ) +{ + // we have to avoid that a parent and a child is selected together + // because in this case we get a double object deletion ( program crashes ) + // when removing the selected items from list + AddresseeViewItem* parent = static_cast(((TQListViewItem*)item)->parent()); + if ( parent && selected ) + parent->setSelected( false ); + if (selected) + { + selectedSelectedAddresses.append(item); + } + else + { + selectedSelectedAddresses.remove(item); + } + if ( selected ) { + AddresseeViewItem* child = static_cast(item->firstChild()); + while (child) { + child->setSelected( false ); + child = static_cast(child->nextSibling()); + } + } +} + +void +AddressesDialog::initConnections() +{ + connect( d->ui->mFilterEdit, TQT_SIGNAL(textChanged(const TQString &)), + TQT_SLOT(filterChanged(const TQString &)) ); + connect( d->ui->mToButton, TQT_SIGNAL(clicked()), + TQT_SLOT(addSelectedTo()) ); + connect( d->ui->mCCButton, TQT_SIGNAL(clicked()), + TQT_SLOT(addSelectedCC()) ); + connect( d->ui->mBCCButton, TQT_SIGNAL(clicked()), + TQT_SLOT(addSelectedBCC()) ); + connect( d->ui->mSaveAs, TQT_SIGNAL(clicked()), + TQT_SLOT(saveAs()) ); + connect( d->ui->mLdapSearch, TQT_SIGNAL(clicked()), + TQT_SLOT(searchLdap()) ); + connect( d->ui->mRemoveButton, TQT_SIGNAL(clicked()), + TQT_SLOT(removeEntry()) ); + connect( d->ui->mAvailableView, TQT_SIGNAL(selectionChanged()), + TQT_SLOT(availableSelectionChanged()) ); + connect( d->ui->mAvailableView, TQT_SIGNAL(doubleClicked(TQListViewItem*)), + TQT_SLOT(addSelectedTo()) ); + connect( d->ui->mSelectedView, TQT_SIGNAL(selectionChanged()), + TQT_SLOT(selectedSelectionChanged()) ); + connect( d->ui->mSelectedView, TQT_SIGNAL(doubleClicked(TQListViewItem*)), + TQT_SLOT(removeEntry()) ); + +#ifndef KDEPIM_NEW_DISTRLISTS + connect( KABC::DistributionListWatcher::self(), TQT_SIGNAL( changed() ), + this, TQT_SLOT( updateAvailableAddressees() ) ); +#endif + + connect( KABC::StdAddressBook::self( true ), TQT_SIGNAL( addressBookChanged(AddressBook*) ), + this, TQT_SLOT( updateAvailableAddressees() ) ); +} + +void +AddressesDialog::addAddresseeToAvailable( const KABC::Addressee& addr, AddresseeViewItem* defaultParent, bool useCategory ) +{ + if ( addr.preferredEmail().isEmpty() ) + return; + + if ( useCategory ) { + TQStringList categories = addr.categories(); + + for ( TQStringList::Iterator it = categories.begin(); it != categories.end(); ++it ) { + if ( !d->groupDict[ *it ] ) { //we don't have the category yet + AddresseeViewItem* category = new AddresseeViewItem( d->ui->mAvailableView, *it ); + d->groupDict.insert( *it, category ); + } + + for ( uint i = 0; i < addr.emails().count(); ++i ) { + AddresseeViewItem* addressee = new AddresseeViewItem( d->groupDict[ *it ], addr, i ); + connect(addressee, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(availableAddressSelected(AddresseeViewItem*, bool))); + } + } + } + + bool noCategory = false; + if ( useCategory ) { + if ( addr.categories().isEmpty() ) + noCategory = true; + } else + noCategory = true; + + if ( defaultParent && noCategory ) { // only non-categorized items here + AddresseeViewItem* addressee = new AddresseeViewItem( defaultParent, addr ); + connect(addressee, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(availableAddressSelected(AddresseeViewItem*, bool))); + } +} + +void +AddressesDialog::addAddresseeToSelected( const KABC::Addressee& addr, AddresseeViewItem* defaultParent ) +{ + if ( addr.preferredEmail().isEmpty() ) + return; + + if ( defaultParent ) { + AddresseeViewItem *myChild = static_cast( defaultParent->firstChild() ); + while( myChild ) { + if ( myChild->addressee().preferredEmail() == addr.preferredEmail() ) + return;//already got it + myChild = static_cast( myChild->nextSibling() ); + } + AddresseeViewItem* addressee = new AddresseeViewItem( defaultParent, addr ); + connect(addressee, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + defaultParent->setOpen( true ); + } + + d->ui->mSaveAs->setEnabled(true); +} + +void +AddressesDialog::addAddresseesToSelected( AddresseeViewItem *parent, + const TQPtrList& addresses ) +{ + Q_ASSERT( parent ); + + TQPtrListIterator itr( addresses ); + + if (itr.current()) + { + d->ui->mSaveAs->setEnabled(true); + } + + while ( itr.current() ) { + AddresseeViewItem* address = itr.current(); + ++itr; + + if (selectedToAvailableMapping.find(address) != 0) + { + continue; + } + + AddresseeViewItem* newItem = 0; + if (address->category() == AddresseeViewItem::Entry) + { + newItem = new AddresseeViewItem( parent, address->addressee() ); + } + else if (address->category() == AddresseeViewItem::DistList) + { + newItem = new AddresseeViewItem( parent, address->name() ); + } + else + { + newItem = new AddresseeViewItem( parent, address->name(), allAddressee( address ) ); + } + + address->setSelected( false ); + address->setVisible( false ); + selectedToAvailableMapping.insert(address, newItem); + selectedToAvailableMapping.insert(newItem, address); + connect(newItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + } + + parent->setOpen( true ); +} + +TQStringList +AddressesDialog::entryToString( const KABC::Addressee::List& l ) const +{ + TQStringList entries; + + for( KABC::Addressee::List::ConstIterator it = l.begin(); it != l.end(); ++it ) { + entries += (*it).fullEmail(); + } + return entries; +} + +void +AddressesDialog::addSelectedTo() +{ + if ( !d->toItem ) + { + d->toItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("To"), AddresseeViewItem::To ); + connect(d->toItem, TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + } + + addAddresseesToSelected( d->toItem, selectedAvailableAddresses ); + selectedAvailableAddresses.clear(); + + if ( d->toItem->childCount() > 0 ) { + d->toItem->setVisible( true ); + } else { + delete d->toItem; + d->toItem = 0; + } +} + +void +AddressesDialog::addSelectedCC() +{ + if ( !d->ccItem ) + { + d->ccItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("CC"), AddresseeViewItem::CC ); + connect(d->ccItem , TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + } + + addAddresseesToSelected( d->ccItem, selectedAvailableAddresses ); + selectedAvailableAddresses.clear(); + + if ( d->ccItem->childCount() > 0 ) { + d->ccItem->setVisible( true ); + } else { + delete d->ccItem; + d->ccItem = 0; + } +} + +void +AddressesDialog::addSelectedBCC() +{ + if ( !d->bccItem ) + { + d->bccItem = new AddresseeViewItem( d->ui->mSelectedView, i18n("BCC"), AddresseeViewItem::BCC ); + connect(d->bccItem , TQT_SIGNAL(addressSelected(AddresseeViewItem*, bool)), + this, TQT_SLOT(selectedAddressSelected(AddresseeViewItem*, bool))); + } + + addAddresseesToSelected( d->bccItem, selectedAvailableAddresses ); + selectedAvailableAddresses.clear(); + + if ( d->bccItem->childCount() > 0 ) { + d->bccItem->setVisible( true ); + } else { + delete d->bccItem; + d->bccItem = 0; + } +} + +void AddressesDialog::unmapSelectedAddress(AddresseeViewItem* item) +{ + AddresseeViewItem* correspondingItem = selectedToAvailableMapping[item]; + if (correspondingItem) + { + correspondingItem->setVisible( true ); + selectedToAvailableMapping.remove( item ); + selectedToAvailableMapping.remove( correspondingItem ); + } + + AddresseeViewItem* child = static_cast(item->firstChild()); + while (child) + { + unmapSelectedAddress(child); + child = static_cast(child->nextSibling()); + } +} + +void +AddressesDialog::removeEntry() +{ + TQPtrList lst; + bool resetTo = false; + bool resetCC = false; + bool resetBCC = false; + + lst.setAutoDelete( false ); + TQPtrListIterator it( selectedSelectedAddresses ); + while ( it.current() ) { + AddresseeViewItem* item = it.current(); + ++it; + if ( d->toItem == item ) + resetTo = true; + else if ( d->ccItem == item ) + resetCC = true; + else if( d->bccItem == item ) + resetBCC = true; + // we may only append parent items + unmapSelectedAddress(item); + lst.append( item ); + } + selectedSelectedAddresses.clear(); + lst.setAutoDelete( true ); + lst.clear(); + if ( resetTo ) + d->toItem = 0; + else if ( d->toItem && d->toItem->childCount() == 0 ) + { + delete d->toItem; + d->toItem = 0; + } + if ( resetCC ) + d->ccItem = 0; + else if ( d->ccItem && d->ccItem->childCount() == 0 ) + { + delete d->ccItem; + d->ccItem = 0; + } + if ( resetBCC ) + d->bccItem = 0; + else if ( d->bccItem && d->bccItem->childCount() == 0 ) + { + delete d->bccItem; + d->bccItem = 0; + } + d->ui->mSaveAs->setEnabled(d->ui->mSelectedView->firstChild() != 0); +} + +#ifdef KDEPIM_NEW_DISTRLISTS + +// copied from kabcore.cpp :( +// KDE4: should be in libkabc I think +static KABC::Resource *requestResource( KABC::AddressBook* abook, TQWidget *parent ) +{ + TQPtrList kabcResources = abook->resources(); + + TQPtrList kresResources; + TQPtrListIterator resIt( kabcResources ); + KABC::Resource *resource; + while ( ( resource = resIt.current() ) != 0 ) { + ++resIt; + if ( !resource->readOnly() ) { + KRES::Resource *res = static_cast( resource ); + if ( res ) + kresResources.append( res ); + } + } + + KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); + return static_cast( res ); +} +#endif + +void +AddressesDialog::saveAs() +{ +#ifndef KDEPIM_NEW_DISTRLISTS + KABC::DistributionListManager manager( KABC::StdAddressBook::self( true ) ); + manager.load(); +#endif + + if ( !d->ui->mSelectedView->firstChild() ) { + KMessageBox::information( 0, + i18n("There are no addresses in your list. " + "First add some addresses from your address book, " + "then try again.") ); + return; + } + + bool ok = false; + TQString name = KInputDialog::getText( i18n("New Distribution List"), + i18n("Please enter name:"), + TQString(), &ok, + this ); + if ( !ok || name.isEmpty() ) + return; + + bool alreadyExists = false; +#ifdef KDEPIM_NEW_DISTRLISTS + KABC::AddressBook* abook = KABC::StdAddressBook::self( true ); + KPIM::DistributionList dlist = KPIM::DistributionList::findByName( abook, name ); + alreadyExists = !dlist.isEmpty(); +#else + alreadyExists = manager.list( name ); +#endif + + if ( alreadyExists ) { + KMessageBox::information( 0, + i18n( "Distribution list with the given name %1 " + "already exists. Please select a different name." ) + .tqarg( name ) ); + return; + } + +#ifdef KDEPIM_NEW_DISTRLISTS + KABC::Resource* resource = requestResource( abook, this ); + if ( !resource ) + return; + + dlist.setResource( resource ); + dlist.setName( name ); + KABC::Addressee::List addrl = allAddressee( d->ui->mSelectedView, false ); + for ( KABC::Addressee::List::iterator itr = addrl.begin(); + itr != addrl.end(); ++itr ) { + dlist.insertEntry( *itr ); + } + abook->insertAddressee( dlist ); +#else + KABC::DistributionList *dlist = new KABC::DistributionList( &manager, name ); + KABC::Addressee::List addrl = allAddressee( d->ui->mSelectedView, false ); + for ( KABC::Addressee::List::iterator itr = addrl.begin(); + itr != addrl.end(); ++itr ) { + dlist->insertEntry( *itr ); + } + + manager.save(); +#endif +} + +void +AddressesDialog::searchLdap() +{ + if ( !d->ldapSearchDialog ) { + d->ldapSearchDialog = new LDAPSearchDialog( this ); + connect( d->ldapSearchDialog, TQT_SIGNAL( addresseesAdded() ), + TQT_SLOT(ldapSearchResult() ) ); + } + d->ldapSearchDialog->show(); +} + +void +AddressesDialog::ldapSearchResult() +{ + TQStringList emails = KPIM::splitEmailAddrList( d->ldapSearchDialog->selectedEMails() ); + TQStringList::iterator it( emails.begin() ); + TQStringList::iterator end( emails.end() ); + for ( ; it != end; ++it ){ + TQString name; + TQString email; + KPIM::getNameAndMail( (*it), name, email ); + KABC::Addressee ad; + ad.setNameFromString( name ); + ad.insertEmail( email ); + addAddresseeToSelected( ad, selectedToItem() ); + } +} + +void +AddressesDialog::launchAddressBook() +{ + kapp->startServiceByDesktopName( "kaddressbook", TQString() ); +} + +void +AddressesDialog::filterChanged( const TQString& txt ) +{ + TQListViewItemIterator it( d->ui->mAvailableView ); + bool showAll = false; + + if ( txt.isEmpty() ) + showAll = true; + + int personalVisible = 0; + int recentVisible = 0; + while ( it.current() ) { + AddresseeViewItem* item = static_cast( it.current() ); + ++it; + + if ( showAll ) { + item->setOpen( true ); + item->setVisible( true ); + // allen: I do not like the following behavior. comment out and see if anyone screams + //if ( item->category() == AddresseeViewItem::Group ) + // item->setOpen( false );//close to not have too many entries + continue; + } + + if ( item->category() == AddresseeViewItem::Entry ) { + bool matches = item->matches( txt ); + item->setVisible( matches ); + TQListViewItem *parent = static_cast( item )->parent(); + if ( matches && parent ) { + if ( parent == d->personal ) { + personalVisible++; + } else if ( parent == d->recent ) { + recentVisible++; + } + } + } + if ( item->category() == AddresseeViewItem::Group ) { + item->setOpen( true ); + item->setVisible( true ); + } + } + + if ( !showAll && personalVisible == 0 ) { + d->personal->setOpen( false ); + d->personal->setVisible( false ); + } + if ( !showAll && recentVisible == 0 ) { + d->recent->setOpen( false ); + d->recent->setVisible( false ); + } + + int distlistgroupVisible = 0; + if ( !showAll ) { + TQPtrListIterator it( d->dists ); + for ( ; it.current(); ++it ) { + TQListViewItem *p = *it; + p->setVisible( true ); + AddresseeViewItem *p2 = static_cast( p->firstChild() ); + int pcount = 0; + while ( p2 ) { + if ( p2->matches( txt ) ) { + p2->setVisible( true ); + pcount++; + } else { + p2->setVisible( false ); + } + p2 = static_cast( p2->nextSibling() ); + } + if ( !pcount && !p->text( 0 ).contains( txt, false ) ) { + p->setVisible( false ); + } + distlistgroupVisible += pcount; + if ( p->text( 0 ).contains( txt, false ) ) { + distlistgroupVisible++; + } + } + } + if ( d->topdist ) { + if ( showAll || distlistgroupVisible > 0 ) { + d->topdist->setOpen( true ); + } else { + d->topdist->setOpen( false ); + d->topdist->setVisible( false ); + } + } +} + +KABC::Addressee::List +AddressesDialog::allAddressee( KListView* view, bool onlySelected ) const +{ + KABC::Addressee::List lst; + TQListViewItemIterator it( view ); + while ( it.current() ) { + AddresseeViewItem* item = static_cast( it.current() ); + if ( !onlySelected || item->isSelected() ) { + if ( item->category() != AddresseeViewItem::Entry ) { + AddresseeViewItem *myChild = static_cast( item->firstChild() ); + while( myChild ) { + lst.append( myChild->addressee() ); + myChild = static_cast( myChild->nextSibling() ); + } + } else { + lst.append( item->addressee() ); + } + } + ++it; + } + + return lst; +} + +KABC::Addressee::List +AddressesDialog::allAddressee( AddresseeViewItem* parent ) const +{ + KABC::Addressee::List lst; + + if ( !parent ) return lst; + + if ( parent->category() == AddresseeViewItem::Entry ) + { + lst.append( parent->addressee() ); + return lst; + } + + AddresseeViewItem *myChild = static_cast( parent->firstChild() ); + while( myChild ) { + if ( myChild->category() == AddresseeViewItem::FilledGroup ) + lst += myChild->addresses(); + else if ( !myChild->addressee().isEmpty() ) + lst.append( myChild->addressee() ); + myChild = static_cast( myChild->nextSibling() ); + } + + return lst; +} + +TQStringList +AddressesDialog::allDistributionLists( AddresseeViewItem* parent ) const +{ + TQStringList lists; + + if ( !parent ) + return TQStringList(); + + AddresseeViewItem *item = static_cast( parent->firstChild() ); + while ( item ) { + if ( item->category() == AddresseeViewItem::DistList && !item->name().isEmpty() ) + lists.append( item->name() ); + + item = static_cast( item->nextSibling() ); + } + + return lists; +} + +void +AddressesDialog::addDistributionLists() +{ + KABC::AddressBook* abook = KABC::StdAddressBook::self( true ); + +#ifdef KDEPIM_NEW_DISTRLISTS + const TQValueList distLists = + KPIM::DistributionList::allDistributionLists( abook ); +#else + KABC::DistributionListManager manager( abook ); + manager.load(); + + TQStringList distLists = manager.listNames(); +#endif + + if ( distLists.isEmpty() ) + return; + + if ( !d->topdist ) { + d->topdist = new AddresseeViewItem( d->ui->mAvailableView, i18n( "Distribution Lists" ) ); + } + +#ifdef KDEPIM_NEW_DISTRLISTS + TQValueList::ConstIterator listIt; +#else + TQStringList::Iterator listIt; +#endif + int total = 0; + for ( listIt = distLists.begin(); listIt != distLists.end(); ++listIt ) { +#ifdef KDEPIM_NEW_DISTRLISTS + KPIM::DistributionList dlist = *listIt; + KPIM::DistributionList::Entry::List entries = dlist.entries(abook); +#else + KABC::DistributionList& dlist = *manager.list( *listIt ); + KABC::DistributionList::Entry::List entries = dlist.entries(); +#endif + + AddresseeViewItem *item = new AddresseeViewItem( d->topdist, dlist.name() ); + d->dists.append( item ); + connect( item, TQT_SIGNAL( addressSelected( AddresseeViewItem*, bool ) ), + this, TQT_SLOT( availableAddressSelected( AddresseeViewItem*, bool ) ) ); + +#ifdef KDEPIM_NEW_DISTRLISTS + KPIM::DistributionList::Entry::List::Iterator itemIt; +#else + KABC::DistributionList::Entry::List::Iterator itemIt; +#endif + for ( itemIt = entries.begin(); itemIt != entries.end(); ++itemIt ) { + addAddresseeToAvailable( (*itemIt).addressee, item, false ); + } + if ( item->childCount() > 0 ) { + item->setOpen( true ); + item->setVisible( true ); + } + total += item->childCount(); + } + if ( total > 0 ) { + d->topdist->setOpen( true ); + d->topdist->setVisible( true ); + } +} + +} // namespace + +#include "addressesdialog.moc" diff --git a/libtdepim/addressesdialog.h b/libtdepim/addressesdialog.h new file mode 100644 index 000000000..c553c6421 --- /dev/null +++ b/libtdepim/addressesdialog.h @@ -0,0 +1,223 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- + * + * This file is part of libtdepim. + * + * Copyright (c) 2003 Zack Rusin + * Copyright (c) 2003 Aaron J. Seigo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef ADDRESSESDIALOG_H +#define ADDRESSESDIALOG_H + +#include +#include +#include +#include +#include +#include +#include + +namespace KPIM { + + class AddresseeViewItem : public TQObject, public KListViewItem + { + Q_OBJECT + TQ_OBJECT + + public: + enum Category { + To =0, + CC =1, + BCC =2, + Group =3, + Entry =4, + FilledGroup =5, + DistList =6 + }; + AddresseeViewItem( AddresseeViewItem *parent, const KABC::Addressee& addr, int emailIndex = 0 ); + AddresseeViewItem( KListView *lv, const TQString& name, Category cat=Group ); + AddresseeViewItem( AddresseeViewItem *parent, const TQString& name, const KABC::Addressee::List &lst ); + AddresseeViewItem( AddresseeViewItem *parent, const TQString& name ); + ~AddresseeViewItem(); + + KABC::Addressee addressee() const; + KABC::Addressee::List addresses() const; + Category category() const; + + TQString name() const; + TQString email() const; + + bool matches( const TQString& ) const; + + virtual int compare( TQListViewItem * i, int col, bool ascending ) const; + virtual void setSelected( bool ); + + signals: + void addressSelected( AddresseeViewItem*, bool ); + + private: + struct AddresseeViewItemPrivate; + AddresseeViewItemPrivate *d; + }; + + class KDE_EXPORT AddressesDialog : public KDialogBase + { + Q_OBJECT + TQ_OBJECT + public: + AddressesDialog( TQWidget *widget=0, const char *name=0 ); + ~AddressesDialog(); + + /** + * Returns the list of picked "To" addresses as a TQStringList. + */ + TQStringList to() const; + /** + * Returns the list of picked "CC" addresses as a TQStringList. + */ + TQStringList cc() const; + /** + * Returns the list of picked "BCC" addresses as a TQStringList. + */ + TQStringList bcc() const; + + /** + * Returns the list of picked "To" addresses as KABC::Addressee::List. + * Note that this doesn't include the distribution lists + */ + KABC::Addressee::List toAddresses() const; + /** + * Returns the list of picked "To" addresses as KABC::Addressee::List. + * Note that this does include the distribution lists + * Multiple Addressees are removed + */ + KABC::Addressee::List allToAddressesNoDuplicates() const; + /** + * Returns the list of picked "CC" addresses as KABC::Addressee::List. + * Note that this doesn't include the distribution lists + */ + KABC::Addressee::List ccAddresses() const; + /** + * Returns the list of picked "BCC" addresses as KABC::Addressee::List. + * Note that this doesn't include the distribution lists + */ + KABC::Addressee::List bccAddresses() const; + + /** + * Returns the list of picked "To" distribution lists. + * This complements @ref toAddresses. + */ + TQStringList toDistributionLists() const; + /** + * Returns the list of picked "CC" distribution lists. + * This complements @ref ccAddresses. + */ + TQStringList ccDistributionLists() const; + /** + * Returns the list of picked "BCC" distribution lists. + * This complements @ref bccAddresses. + */ + TQStringList bccDistributionLists() const; + + public slots: + /** + * Displays the CC field if @p b is true, else + * hides it. By default displays it. + */ + void setShowCC( bool b ); + /** + * Displays the BCC field if @p b is true, else + * hides it. By default displays it. + */ + void setShowBCC( bool b ); + /** + * If called adds "Recent Addresses" item to the picker list view, + * with the addresses given in @p addr. + */ + void setRecentAddresses( const KABC::Addressee::List& addr ); + /** + * Adds addresses in @p l to the selected "To" group. + */ + void setSelectedTo( const TQStringList& l ); + /** + * Adds addresses in @p l to the selected "CC" group. + */ + void setSelectedCC( const TQStringList& l ); + /** + * Adds addresses in @p l to the selected "BCC" group. + */ + void setSelectedBCC( const TQStringList& l ); + + protected slots: + void addSelectedTo(); + void addSelectedCC(); + void addSelectedBCC(); + + void removeEntry(); + void saveAs(); + void searchLdap(); + void ldapSearchResult(); + void launchAddressBook(); + + void filterChanged( const TQString & ); + + void updateAvailableAddressees(); + void availableSelectionChanged(); + void selectedSelectionChanged(); + void availableAddressSelected( AddresseeViewItem* item, bool selected ); + void selectedAddressSelected( AddresseeViewItem* item, bool selected ); + + protected: + AddresseeViewItem* selectedToItem(); + AddresseeViewItem* selectedCcItem(); + AddresseeViewItem* selectedBccItem(); + + void initConnections(); + void addDistributionLists(); + void addAddresseeToAvailable( const KABC::Addressee& addr, + AddresseeViewItem* defaultParent=0, bool useCategory=true ); + void addAddresseeToSelected( const KABC::Addressee& addr, + AddresseeViewItem* defaultParent=0 ); + void addAddresseesToSelected( AddresseeViewItem *parent, + const TQPtrList& addresses ); + TQStringList entryToString( const KABC::Addressee::List& l ) const; + KABC::Addressee::List allAddressee( AddresseeViewItem* parent ) const; + KABC::Addressee::List allAddressee( KListView* view, bool onlySelected = true ) const; + TQStringList allDistributionLists( AddresseeViewItem* parent ) const; + + private: + // if there's only one group in the available list, open it + void checkForSingleAvailableGroup(); + + // used to re-show items in the available list + // it is recursive, but should only ever recurse once so should be fine + void unmapSelectedAddress(AddresseeViewItem* item); + void updateRecentAddresses(); + + struct AddressesDialogPrivate; + AddressesDialogPrivate *d; + + TQPtrList selectedAvailableAddresses; + TQPtrList selectedSelectedAddresses; + TQPtrDict selectedToAvailableMapping; + }; + +} + +#endif /* ADDRESSESDIALOG_H */ diff --git a/libtdepim/addresspicker.ui b/libtdepim/addresspicker.ui new file mode 100644 index 000000000..fc88d52a0 --- /dev/null +++ b/libtdepim/addresspicker.ui @@ -0,0 +1,327 @@ + +AddressPickerUI + + + AddressPickerUI + + + + 0 + 0 + 591 + 442 + + + + Address Selection + + + + unnamed + + + + + Name + + + true + + + true + + + + + Email Address + + + true + + + true + + + + mAvailableView + + + Extended + + + true + + + true + + + true + + + AllColumns + + + true + + + + + tqlayout10 + + + + unnamed + + + + spacer1 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + mToButton + + + false + + + &To >> + + + + + mCCButton + + + false + + + &CC >> + + + + + mBCCButton + + + false + + + &BCC >> + + + + + spacer2 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + mRemoveButton + + + false + + + << &Remove + + + + + spacer2_2 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + textLabel2 + + + + 1 + + + + &Selected Addresses + + + WordBreak|AlignCenter + + + mSelectedView + + + + + textLabel1 + + + + 1 + + + + &Address Book + + + WordBreak|AlignCenter + + + mAvailableView + + + + + tqlayout1 + + + + unnamed + + + + TextLabel2 + + + &Filter on: + + + mFilterEdit + + + + + mFilterEdit + + + + 7 + 0 + 1 + 0 + + + + + + + + + + + + Name + + + true + + + true + + + + + Email Address + + + true + + + true + + + + mSelectedView + + + Extended + + + true + + + true + + + true + + + AllColumns + + + true + + + + + mSaveAs + + + false + + + Save as &Distribution List... + + + Alt+D + + + + + mLdapSearch + + + &Search Directory Service + + + + + + + + + klistview.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + klistview.h + + diff --git a/libtdepim/alarmclient.cpp b/libtdepim/alarmclient.cpp new file mode 100644 index 000000000..5616cd029 --- /dev/null +++ b/libtdepim/alarmclient.cpp @@ -0,0 +1,60 @@ +/* + This file is part of KOrganizer. + + Copyright (c) 2003 Cornelius Schumacher + Copyright (c) 2005 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "alarmclient.h" + +#include +#include +#include + +#include +#include + +AlarmClient::AlarmClient() +{ + kdDebug(5850) << "AlarmClient::AlarmClient()" << endl; +} + +void AlarmClient::startDaemon() +{ + if ( kapp->dcopClient()->isApplicationRegistered( "korgac" ) ) { + // Alarm daemon already runs + return; + } + + KGlobal::dirs()->addResourceType("autostart", "share/autostart"); + TQString desktopFile = locate( "autostart", "korgac.desktop" ); + if ( desktopFile.isEmpty() ) { + kdWarning() << "Couldn't find autostart/korgac.desktop!" << endl; + } + else { + TQString error; + if ( kapp->startServiceByDesktopPath( desktopFile, TQStringList(), &error ) != 0 ) + kdWarning() << "Failure starting korgac:" << error << endl; + } +} + +void AlarmClient::stopDaemon() +{ + DCOPRef ref( "korgac", "ac" ); + ref.send( "quit" ); +} diff --git a/libtdepim/alarmclient.h b/libtdepim/alarmclient.h new file mode 100644 index 000000000..2d294143d --- /dev/null +++ b/libtdepim/alarmclient.h @@ -0,0 +1,44 @@ +/* + This file is part of the KOrganizer interfaces. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef ALARMCLIENT_H +#define ALARMCLIENT_H + +/** + This class provides the interface for communicating with the alarm daemon. It + can be subclassed for specific daemons. +*/ +class AlarmClient +{ + public: + AlarmClient(); + + /** + Start alarm daemon. + */ + virtual void startDaemon(); + + /** + Stop alarm daemon. + */ + virtual void stopDaemon(); +}; + +#endif diff --git a/libtdepim/broadcaststatus.cpp b/libtdepim/broadcaststatus.cpp new file mode 100644 index 000000000..a50479195 --- /dev/null +++ b/libtdepim/broadcaststatus.cpp @@ -0,0 +1,165 @@ +/* + broadcaststatus.cpp + + This file is part of KDEPIM. + + Author: Don Sanders + + Copyright (C) 2000 Don Sanders + + License GPL +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include + +#include "broadcaststatus.h" +#include "progressmanager.h" + +KPIM::BroadcastStatus* KPIM::BroadcastStatus::instance_ = 0; +static KStaticDeleter broadcasStatusDeleter; + +namespace KPIM { + +BroadcastStatus* BroadcastStatus::instance() +{ + if (!instance_) + broadcasStatusDeleter.setObject( instance_, new BroadcastStatus() ); + + return instance_; +} + +BroadcastStatus::BroadcastStatus() + :mTransientActive( false ) +{ +} + +BroadcastStatus::~BroadcastStatus() +{ + instance_ = 0; +} + +void BroadcastStatus::seStatusMsg( const TQString& message ) +{ + mStatusMsg = message; + if( !mTransientActive ) + emit statusMsg( message ); +} + +void BroadcastStatus::seStatusMsgWithTimestamp( const TQString& message ) +{ + KLocale* locale = KGlobal::locale(); + seStatusMsg( i18n( "%1 is a time, %2 is a status message", "[%1] %2" ) + .tqarg( locale->formatTime( TQTime::currentTime(), + true /* with seconds */ ) ) + .tqarg( message ) ); +} + +void BroadcastStatus::seStatusMsgTransmissionCompleted( int numMessages, + int numBytes, + int numBytesRead, + int numBytesToRead, + bool mLeaveOnServer, + KPIM::ProgressItem* item ) +{ + TQString statusMsg; + if( numMessages > 0 ) { + if( numBytes != -1 ) { + if( ( numBytesToRead != numBytes ) && mLeaveOnServer ) + statusMsg = i18n( "Transmission complete. %n new message in %1 KB " + "(%2 KB remaining on the server).", + "Transmission complete. %n new messages in %1 KB " + "(%2 KB remaining on the server).", + numMessages ) + .tqarg( numBytesRead / 1024 ) + .tqarg( numBytes / 1024 ); + else + statusMsg = i18n( "Transmission complete. %n message in %1 KB.", + "Transmission complete. %n messages in %1 KB.", + numMessages ) + .tqarg( numBytesRead / 1024 ); + } + else + statusMsg = i18n( "Transmission complete. %n new message.", + "Transmission complete. %n new messages.", + numMessages ); + } + else + statusMsg = i18n( "Transmission complete. No new messages." ); + + seStatusMsgWithTimestamp( statusMsg ); + if ( item ) + item->setqStatus( statusMsg ); +} + +void BroadcastStatus::seStatusMsgTransmissionCompleted( const TQString& account, + int numMessages, + int numBytes, + int numBytesRead, + int numBytesToRead, + bool mLeaveOnServer, + KPIM::ProgressItem* item ) +{ + TQString statusMsg; + if( numMessages > 0 ) { + if( numBytes != -1 ) { + if( ( numBytesToRead != numBytes ) && mLeaveOnServer ) + statusMsg = i18n( "Transmission for account %3 complete. " + "%n new message in %1 KB " + "(%2 KB remaining on the server).", + "Transmission for account %3 complete. " + "%n new messages in %1 KB " + "(%2 KB remaining on the server).", + numMessages ) + .tqarg( numBytesRead / 1024 ) + .tqarg( numBytes / 1024 ) + .tqarg( account ); + else + statusMsg = i18n( "Transmission for account %2 complete. " + "%n message in %1 KB.", + "Transmission for account %2 complete. " + "%n messages in %1 KB.", + numMessages ) + .tqarg( numBytesRead / 1024 ) + .tqarg( account ); + } + else + statusMsg = i18n( "Transmission for account %1 complete. " + "%n new message.", + "Transmission for account %1 complete. " + "%n new messages.", + numMessages ) + .tqarg( account ); + } + else + statusMsg = i18n( "Transmission for account %1 complete. No new messages.") + .tqarg( account ); + + seStatusMsgWithTimestamp( statusMsg ); + if ( item ) + item->setqStatus( statusMsg ); +} + +void BroadcastStatus::setTransienStatusMsg( const TQString& msg ) +{ + mTransientActive = true; + emit statusMsg( msg ); +} + +void BroadcastStatus::reset() +{ + mTransientActive = false; + // restore + emit statusMsg( mStatusMsg ); +} + +} + +#include "broadcaststatus.moc" diff --git a/libtdepim/broadcaststatus.h b/libtdepim/broadcaststatus.h new file mode 100644 index 000000000..c29e0ff05 --- /dev/null +++ b/libtdepim/broadcaststatus.h @@ -0,0 +1,94 @@ +/* + broadcaststatus.h + + This file is part of KDEPIM. + + Copyright (C) 2000 Don Sanders + + License GPL +*/ + +#ifndef __kpim_broadcast_status_h +#define __kpim_broadcast_status_h + +#include +#include + +#include + +#undef None + +namespace KPIM { + +class ProgressItem; + +/** + Provides a singleton which broadcasts status messages by emitting + signals. Interested mainwindows can connect to the statusMsg() + signal and update statusBars or whatever they use for showing status. + */ + + +class KDE_EXPORT BroadcastStatus : public TQObject +{ + + Q_OBJECT + TQ_OBJECT + +public: + virtual ~BroadcastStatus(); + + /** Return the instance of the singleton object for this class */ + static BroadcastStatus *instance(); + + /** Return the last status message from seStatusMsg() */ + TQString statusMsg() const { return mStatusMsg; } + /** Sets a status bar message with timestamp */ + void seStatusMsgWithTimestamp( const TQString& message ); + /** Sets a transmission completed status bar message */ + void seStatusMsgTransmissionCompleted( int numMessages, + int numBytes = -1, + int numBytesRead = -1, + int numBytesToRead = -1, + bool mLeaveOnServer = false, + KPIM::ProgressItem* progressItem = 0 ); // set the same status in this progress item + void seStatusMsgTransmissionCompleted( const TQString& account, + int numMessages, + int numBytes = -1, + int numBytesRead = -1, + int numBytesToRead = -1, + bool mLeaveOnServer = false, + KPIM::ProgressItem* progressItem = 0 ); // set the same status in this progress item + +public slots: + /** Emit an update status bar signal. It's a slot so it can be hooked up + to other signals. */ + void seStatusMsg( const TQString& message ); + + /** + Set a status message that will go away again with the next call of + reset(). + */ + void setTransienStatusMsg( const TQString& msg ); + /** + Reset the status message to what ever non-transient message was last + active or has since been set. + */ + void reset(); + +signals: + + /** Emitted when seStatusMsg is called. */ + void statusMsg( const TQString& ); + +protected: + + BroadcastStatus(); + TQString mStatusMsg; + bool mTransientActive; + static BroadcastStatus* instance_; +}; + + +} +#endif diff --git a/libtdepim/calendardiffalgo.cpp b/libtdepim/calendardiffalgo.cpp new file mode 100644 index 000000000..587d0dc0c --- /dev/null +++ b/libtdepim/calendardiffalgo.cpp @@ -0,0 +1,213 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +#include "calendardiffalgo.h" + +using namespace KPIM; + +#ifndef KDE_USE_FINAL +static bool compareString( const TQString &left, const TQString &right ) +{ + if ( left.isEmpty() && right.isEmpty() ) + return true; + else + return left == right; +} +#endif + +static TQString toString( KCal::Attendee *attendee ) +{ + return attendee->name() + "<" + attendee->email() + ">"; +} + +static TQString toString( KCal::Alarm * ) +{ + return TQString(); +} + +static TQString toString( KCal::Incidence * ) +{ + return TQString(); +} + +static TQString toString( KCal::Attachment * ) +{ + return TQString(); +} + +static TQString toString( const TQDate &date ) +{ + return date.toString(); +} + +static TQString toString( const TQDateTime &dateTime ) +{ + return dateTime.toString(); +} + +static TQString toString( const TQString str ) +{ + return str; +} + +static TQString toString( bool value ) +{ + if ( value ) + return i18n( "Yes" ); + else + return i18n( "No" ); +} + +CalendarDiffAlgo::CalendarDiffAlgo( KCal::Incidence *leftIncidence, + KCal::Incidence *rightIncidence ) + : mLeftIncidence( leftIncidence ), mRightIncidence( rightIncidence ) +{ +} + +void CalendarDiffAlgo::run() +{ + begin(); + + diffIncidenceBase( mLeftIncidence, mRightIncidence ); + diffIncidence( mLeftIncidence, mRightIncidence ); + + KCal::Event *leftEvent = dynamic_cast( mLeftIncidence ); + KCal::Event *rightEvent = dynamic_cast( mRightIncidence ); + if ( leftEvent && rightEvent ) { + diffEvent( leftEvent, rightEvent ); + } else { + KCal::Todo *leftTodo = dynamic_cast( mLeftIncidence ); + KCal::Todo *rightTodo = dynamic_cast( mRightIncidence ); + if ( leftTodo && rightTodo ) { + diffTodo( leftTodo, rightTodo ); + } + } + + end(); +} + +void CalendarDiffAlgo::diffIncidenceBase( KCal::IncidenceBase *left, KCal::IncidenceBase *right ) +{ + diffList( i18n( "Attendees" ), left->attendees(), right->attendees() ); + + if ( left->dtStart() != right->dtStart() ) + conflictField( i18n( "Start time" ), left->dtStartStr(), right->dtStartStr() ); + + if ( !compareString( left->organizer().fullName(), right->organizer().fullName() ) ) + conflictField( i18n( "Organizer" ), left->organizer().fullName(), right->organizer().fullName() ); + + if ( !compareString( left->uid(), right->uid() ) ) + conflictField( i18n( "UID" ), left->uid(), right->uid() ); + + if ( left->doesFloat() != right->doesFloat() ) + conflictField( i18n( "Is floating" ), toString( left->doesFloat() ), toString( right->doesFloat() ) ); + + if ( left->hasDuration() != right->hasDuration() ) + conflictField( i18n( "Has duration" ), toString( left->hasDuration() ), toString( right->hasDuration() ) ); + + if ( left->duration() != right->duration() ) + conflictField( i18n( "Duration" ), TQString::number( left->duration() ), TQString::number( right->duration() ) ); +} + +void CalendarDiffAlgo::diffIncidence( KCal::Incidence *left, KCal::Incidence *right ) +{ + if ( !compareString( left->description(), right->description() ) ) + conflictField( i18n( "Description" ), left->description(), right->description() ); + + if ( !compareString( left->summary(), right->summary() ) ) + conflictField( i18n( "Summary" ), left->summary(), right->summary() ); + + if ( left->status() != right->status() ) + conflictField( i18n( "Status" ), left->statusStr(), right->statusStr() ); + + if ( left->secrecy() != right->secrecy() ) + conflictField( i18n( "Secrecy" ), toString( left->secrecy() ), toString( right->secrecy() ) ); + + if ( left->priority() != right->priority() ) + conflictField( i18n( "Priority" ), toString( left->priority() ), toString( right->priority() ) ); + + if ( !compareString( left->location(), right->location() ) ) + conflictField( i18n( "Location" ), left->location(), right->location() ); + + diffList( i18n( "Categories" ), left->categories(), right->categories() ); + diffList( i18n( "Alarms" ), left->alarms(), right->alarms() ); + diffList( i18n( "Resources" ), left->resources(), right->resources() ); + diffList( i18n( "Relations" ), left->relations(), right->relations() ); + diffList( i18n( "Attachments" ), left->attachments(), right->attachments() ); + diffList( i18n( "Exception Dates" ), left->recurrence()->exDates(), right->recurrence()->exDates() ); + diffList( i18n( "Exception Times" ), left->recurrence()->exDateTimes(), right->recurrence()->exDateTimes() ); + // TODO: recurrence dates and date/times, exrules, rrules + + if ( left->created() != right->created() ) + conflictField( i18n( "Created" ), left->created().toString(), right->created().toString() ); + + if ( !compareString( left->relatedToUid(), right->relatedToUid() ) ) + conflictField( i18n( "Related Uid" ), left->relatedToUid(), right->relatedToUid() ); +} + +void CalendarDiffAlgo::diffEvent( KCal::Event *left, KCal::Event *right ) +{ + if ( left->hasEndDate() != right->hasEndDate() ) + conflictField( i18n( "Has End Date" ), toString( left->hasEndDate() ), toString( right->hasEndDate() ) ); + + if ( left->dtEnd() != right->dtEnd() ) + conflictField( i18n( "End Date" ), left->dtEndStr(), right->dtEndStr() ); + + // TODO: check transparency +} + +void CalendarDiffAlgo::diffTodo( KCal::Todo *left, KCal::Todo *right ) +{ + if ( left->hasStartDate() != right->hasStartDate() ) + conflictField( i18n( "Has Start Date" ), toString( left->hasStartDate() ), toString( right->hasStartDate() ) ); + + if ( left->hasDueDate() != right->hasDueDate() ) + conflictField( i18n( "Has Due Date" ), toString( left->hasDueDate() ), toString( right->hasDueDate() ) ); + + if ( left->dtDue() != right->dtDue() ) + conflictField( i18n( "Due Date" ), left->dtDue().toString(), right->dtDue().toString() ); + + if ( left->hasCompletedDate() != right->hasCompletedDate() ) + conflictField( i18n( "Has Complete Date" ), toString( left->hasCompletedDate() ), toString( right->hasCompletedDate() ) ); + + if ( left->percentComplete() != right->percentComplete() ) + conflictField( i18n( "Complete" ), TQString::number( left->percentComplete() ), TQString::number( right->percentComplete() ) ); + + if ( left->completed() != right->completed() ) + conflictField( i18n( "Completed" ), toString( left->completed() ), toString( right->completed() ) ); +} + +template +void CalendarDiffAlgo::diffList( const TQString &id, + const TQValueList &left, const TQValueList &right ) +{ + for ( uint i = 0; i < left.count(); ++i ) { + if ( right.find( left[ i ] ) == right.end() ) + additionalLeftField( id, toString( left[ i ] ) ); + } + + for ( uint i = 0; i < right.count(); ++i ) { + if ( left.find( right[ i ] ) == left.end() ) + additionalRightField( id, toString( right[ i ] ) ); + } +} diff --git a/libtdepim/calendardiffalgo.h b/libtdepim/calendardiffalgo.h new file mode 100644 index 000000000..9ccd6c8c0 --- /dev/null +++ b/libtdepim/calendardiffalgo.h @@ -0,0 +1,54 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KPIM_CALENDARDIFFALGO_H +#define KPIM_CALENDARDIFFALGO_H + +#include "diffalgo.h" + +#include +#include + +namespace KPIM { + +class KDE_EXPORT CalendarDiffAlgo : public DiffAlgo +{ + public: + CalendarDiffAlgo( KCal::Incidence *leftIncidence, KCal::Incidence *rightIncidence ); + + void run(); + + private: + template + void diffList( const TQString &id, const TQValueList &left, const TQValueList &right ); + + void diffIncidenceBase( KCal::IncidenceBase*, KCal::IncidenceBase* ); + void diffIncidence( KCal::Incidence*, KCal::Incidence* ); + void diffEvent( KCal::Event*, KCal::Event* ); + void diffTodo( KCal::Todo*, KCal::Todo* ); + + KCal::Incidence *mLeftIncidence; + KCal::Incidence *mRightIncidence; +}; + +} + +#endif diff --git a/libtdepim/categoryeditdialog.cpp b/libtdepim/categoryeditdialog.cpp new file mode 100644 index 000000000..72e1de8ae --- /dev/null +++ b/libtdepim/categoryeditdialog.cpp @@ -0,0 +1,193 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2000, 2001, 2002 Cornelius Schumacher + Copyright (C) 2003-2004 Reinhold Kainhofer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "kpimprefs.h" + +#include "categoryeditdialog.h" + +using namespace KPIM; + +class CategoryEditDialog::Private +{ + public: + TQListView *mView; + TQPushButton *mAddButton; + TQPushButton *mEditButton; + TQPushButton *mDeleteButton; +}; + +class CategoryListViewItem : public TQListViewItem +{ + public: + CategoryListViewItem( TQListView *view, const TQString &text ) : + TQListViewItem( view, text ) + { + } + + void okRename ( int col ) // we need that public to explicitly accept renaming when closing the dialog + { + TQListViewItem::okRename( col ); + } +}; + +CategoryEditDialog::CategoryEditDialog( KPimPrefs *prefs, TQWidget* parent, + const char* name, bool modal ) + : KDialogBase::KDialogBase( parent, name, modal, + i18n("Edit Categories"), Ok|Apply|Cancel|Help, Ok, true ), + mPrefs( prefs ), d( new Private ) +{ + TQWidget *widget = new TQWidget( this ); + setMainWidget( widget ); + + TQGridLayout *tqlayout = new TQGridLayout( widget, 4, 2, marginHint(), spacingHint() ); + + d->mView = new TQListView( widget ); + d->mView->addColumn( "" ); + d->mView->header()->hide(); + d->mView->setDefaultRenameAction( TQListView::Accept ); + + tqlayout->addMultiCellWidget( d->mView, 0, 3, 0, 0 ); + + d->mAddButton = new TQPushButton( i18n( "Add" ), widget ); + tqlayout->addWidget( d->mAddButton, 0, 1 ); + + d->mEditButton = new TQPushButton( i18n( "Edit" ), widget ); + tqlayout->addWidget( d->mEditButton, 1, 1 ); + + d->mDeleteButton = new TQPushButton( i18n( "Remove" ), widget ); + tqlayout->addWidget( d->mDeleteButton, 2, 1 ); + + + fillList(); + + connect( d->mAddButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( add() ) ); + connect( d->mEditButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( edit() ) ); + connect( d->mDeleteButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( remove() ) ); +} + +/* + * Destroys the object and frees any allocated resources + */ +CategoryEditDialog::~CategoryEditDialog() +{ + delete d; +} + +void CategoryEditDialog::fillList() +{ + d->mView->clear(); + TQStringList::Iterator it; + bool categoriesExist=false; + for ( it = mPrefs->mCustomCategories.begin(); + it != mPrefs->mCustomCategories.end(); ++it ) { + + TQListViewItem *item = new CategoryListViewItem( d->mView, *it ); + item->setRenameEnabled( 0, true ); + + categoriesExist = true; + } + + d->mEditButton->setEnabled( categoriesExist ); + d->mDeleteButton->setEnabled( categoriesExist ); + d->mView->setSelected( d->mView->firstChild(), true ); +} + +void CategoryEditDialog::add() +{ + if ( d->mView->firstChild() ) + d->mView->setCurrentItem( d->mView->firstChild() ); + + TQListViewItem *item = new CategoryListViewItem( d->mView, i18n( "New category" ) ); + item->setRenameEnabled( 0, true ); + + d->mView->setSelected( item, true ); + d->mView->ensureItemVisible( item ); + item->startRename( 0 ); + + bool itemCount = d->mView->childCount() > 0; + d->mEditButton->setEnabled( itemCount ); + d->mDeleteButton->setEnabled( itemCount ); +} + +void CategoryEditDialog::edit() +{ + if ( d->mView->currentItem() ) + d->mView->currentItem()->startRename( 0 ); +} + +void CategoryEditDialog::remove() +{ + if ( d->mView->currentItem() ) { + delete d->mView->currentItem(); + + d->mView->setSelected( d->mView->currentItem(), true ); + + bool itemCount = d->mView->childCount() > 0; + d->mEditButton->setEnabled( itemCount ); + d->mDeleteButton->setEnabled( itemCount ); + } +} + +void CategoryEditDialog::slotOk() +{ + // accept the currently ongoing rename + if ( d->mView->selectedItem() ) + static_cast( d->mView->selectedItem() )->okRename( 0 ); + slotApply(); + accept(); +} + +void CategoryEditDialog::slotApply() +{ + mPrefs->mCustomCategories.clear(); + + TQListViewItem *item = d->mView->firstChild(); + while ( item ) { + if ( !item->text( 0 ).isEmpty() ) + mPrefs->mCustomCategories.append( item->text( 0 ) ); + item = item->nextSibling(); + } + mPrefs->writeConfig(); + + emit categoryConfigChanged(); +} + +void CategoryEditDialog::slotCancel() +{ + reload(); + KDialogBase::slotCancel(); +} + +void CategoryEditDialog::reload() +{ + fillList(); +} + +#include "categoryeditdialog.moc" diff --git a/libtdepim/categoryeditdialog.h b/libtdepim/categoryeditdialog.h new file mode 100644 index 000000000..064f8b682 --- /dev/null +++ b/libtdepim/categoryeditdialog.h @@ -0,0 +1,67 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2000, 2001, 2002 Cornelius Schumacher + Copyright (C) 2003-2004 Reinhold Kainhofer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KPIM_CATEGORYEDITDIALOG_H +#define KPIM_CATEGORYEDITDIALOG_H + +#include +#include + +class KPimPrefs; + +namespace KPIM { + +class KDE_EXPORT CategoryEditDialog : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT + public: + CategoryEditDialog( KPimPrefs *prefs, TQWidget* parent = 0, + const char* name = 0, + bool modal = false ); + ~CategoryEditDialog(); + + public slots: + void reload(); + + protected slots: + void slotOk(); + void slotApply(); + void slotCancel(); + void add(); + void edit(); + void remove(); + + signals: + void categoryConfigChanged(); + + protected: + void fillList(); + + private: + KPimPrefs *mPrefs; + class Private; + Private* const d; +}; + +} + +#endif diff --git a/libtdepim/categoryeditdialog_base.ui b/libtdepim/categoryeditdialog_base.ui new file mode 100644 index 000000000..11cd98740 --- /dev/null +++ b/libtdepim/categoryeditdialog_base.ui @@ -0,0 +1,107 @@ + +CategoryEditDialog_base + + + CategoryEditDialog_base + + + + 0 + 0 + 386 + 270 + + + + Edit Categories + + + + unnamed + + + 0 + + + 6 + + + + mEdit + + + + + + Category + + + true + + + true + + + + mCategories + + + true + + + AllColumns + + + + + tqlayout103 + + + + unnamed + + + + mButtonAdd + + + A&dd + + + + + mButtonRemove + + + &Remove + + + + + Spacer3 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + + mCategories + mEdit + mButtonAdd + mButtonRemove + + + diff --git a/libtdepim/categoryselectdialog.cpp b/libtdepim/categoryselectdialog.cpp new file mode 100644 index 000000000..36996614e --- /dev/null +++ b/libtdepim/categoryselectdialog.cpp @@ -0,0 +1,146 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2000, 2001, 2002 Cornelius Schumacher + Copyright (C) 2003-2004 Reinhold Kainhofer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include "categoryselectdialog_base.h" +#include +#include "categoryselectdialog.h" + +#include "kpimprefs.h" + +using namespace KPIM; + +CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, TQWidget* parent, + const char* name, bool modal ) + : KDialogBase::KDialogBase( parent, name, modal, + i18n("Select Categories"), Ok|Apply|Cancel|Help, Ok, true ), + mPrefs( prefs ) +{ + mWidget = new CategorySelectDialog_base( this, "CategorySelection" ); + mWidget->mCategories->header()->hide(); + setMainWidget( mWidget ); + + setCategories(); + + connect( mWidget->mButtonEdit, TQT_SIGNAL(clicked()), + TQT_SIGNAL(editCategories()) ); + connect( mWidget->mButtonClear, TQT_SIGNAL(clicked()), + TQT_SLOT(clear()) ); +} + +void CategorySelectDialog::setCategories( const TQStringList &categoryList ) +{ + mWidget->mCategories->clear(); + mCategoryList.clear(); + + TQStringList::ConstIterator it; + + for ( it = categoryList.begin(); it != categoryList.end(); ++it ) + if ( mPrefs->mCustomCategories.find( *it ) == mPrefs->mCustomCategories.end() ) + mPrefs->mCustomCategories.append( *it ); + + for ( it = mPrefs->mCustomCategories.begin(); + it != mPrefs->mCustomCategories.end(); ++it ) { + new TQCheckListItem( mWidget->mCategories, *it, TQCheckListItem::CheckBox ); + } +} + +CategorySelectDialog::~CategorySelectDialog() +{ +} + +void CategorySelectDialog::setSelected(const TQStringList &selList) +{ + clear(); + + TQStringList::ConstIterator it; + for ( it = selList.begin(); it != selList.end(); ++it ) { + TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); + while (item) { + if (item->text() == *it) { + item->setOn(true); + break; + } + item = (TQCheckListItem *)item->nextSibling(); + } + } +} + +TQStringList CategorySelectDialog::selectedCategories() const +{ + return mCategoryList; +} + +void CategorySelectDialog::slotApply() +{ + TQStringList categories; + TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); + while (item) { + if (item->isOn()) { + categories.append(item->text()); + } + item = (TQCheckListItem *)item->nextSibling(); + } + + TQString categoriesStr = categories.join(", "); + + mCategoryList = categories; + + emit categoriesSelected(categories); + emit categoriesSelected(categoriesStr); +} + +void CategorySelectDialog::slotOk() +{ + slotApply(); + accept(); +} + +void CategorySelectDialog::clear() +{ + TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); + while (item) { + item->setOn(false); + item = (TQCheckListItem *)item->nextSibling(); + } +} + +void CategorySelectDialog::updateCategoryConfig() +{ + TQStringList selected; + TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); + while (item) { + if (item->isOn()) { + selected.append(item->text()); + } + item = (TQCheckListItem *)item->nextSibling(); + } + + setCategories(); + + setSelected(selected); +} + +#include "categoryselectdialog.moc" diff --git a/libtdepim/categoryselectdialog.h b/libtdepim/categoryselectdialog.h new file mode 100644 index 000000000..3cff0313c --- /dev/null +++ b/libtdepim/categoryselectdialog.h @@ -0,0 +1,72 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2000, 2001, 2002 Cornelius Schumacher + Copyright (C) 2003-2004 Reinhold Kainhofer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KPIM_CATEGORYSELECTDIALOG_H +#define KPIM_CATEGORYSELECTDIALOG_H + +#include +#include + +class KPimPrefs; +class CategorySelectDialog_base; + +namespace KPIM { + +class KDE_EXPORT CategorySelectDialog : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT + public: + CategorySelectDialog( KPimPrefs *prefs, TQWidget *parent = 0, + const char *name = 0, bool modal = false ); + ~CategorySelectDialog(); + + /** + Adds this categories to the default categories. + */ + void setCategories( const TQStringList &categoryList = TQStringList() ); + void setSelected( const TQStringList &selList ); + + TQStringList selectedCategories() const; + + public slots: + void slotOk(); + void slotApply(); + void clear(); + void updateCategoryConfig(); + + signals: + void categoriesSelected( const TQString & ); + void categoriesSelected( const TQStringList & ); + void editCategories(); + + private: + KPimPrefs *mPrefs; + CategorySelectDialog_base *mWidget; + TQStringList mCategoryList; + + class CategorySelectDialogPrivate; + CategorySelectDialogPrivate *d; +}; + +} + +#endif diff --git a/libtdepim/categoryselectdialog_base.ui b/libtdepim/categoryselectdialog_base.ui new file mode 100644 index 000000000..1e45bd468 --- /dev/null +++ b/libtdepim/categoryselectdialog_base.ui @@ -0,0 +1,101 @@ + +CategorySelectDialog_base + + + CategorySelectDialog_base + + + + 0 + 0 + 387 + 280 + + + + Select Categories + + + + unnamed + + + 0 + + + 6 + + + + + Category + + + true + + + true + + + + mCategories + + + + + Layout12 + + + + unnamed + + + 0 + + + 6 + + + + mButtonClear + + + &Clear Selection + + + + + Spacer3 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + mButtonEdit + + + &Edit Categories... + + + + + + + + mCategories + mButtonClear + mButtonEdit + + + diff --git a/libtdepim/cfgc/Makefile.am b/libtdepim/cfgc/Makefile.am new file mode 100644 index 000000000..ec9f505f0 --- /dev/null +++ b/libtdepim/cfgc/Makefile.am @@ -0,0 +1,14 @@ +AM_CPPFLAGS = -I$(top_builddir)/libtdepim -I$(top_srcdir) $(all_includes) + +check_PROGRAMS = example +#autoexample + +example_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +example_LDADD = ../libtdepim.la $(LIB_KDECORE) +example_SOURCES = example.cpp exampleprefs_base.kcfgc + +#autoexample_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +#autoexample_LDADD = ../libtdepim.la $(LIB_KDECORE) +#autoexample_SOURCES = general_base.ui myoptions_base.ui autoexample.cpp + +METASOURCES = AUTO diff --git a/libtdepim/cfgc/README b/libtdepim/cfgc/README new file mode 100644 index 000000000..6a7783817 --- /dev/null +++ b/libtdepim/cfgc/README @@ -0,0 +1,6 @@ +This directory contains text and example code for automatic creation of +configuration dialogs based on KConfigSkeleton, kconfig_compiler and +KPrefsDialog. + +If you have questions or comments please contact Cornelius Schumacher +. diff --git a/libtdepim/cfgc/autoexample.cpp b/libtdepim/cfgc/autoexample.cpp new file mode 100644 index 000000000..45617e6f6 --- /dev/null +++ b/libtdepim/cfgc/autoexample.cpp @@ -0,0 +1,66 @@ +/* + This file is part of KDE. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "general_base.h" +#include "myoptions_base.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +int main( int argc, char **argv ) +{ + KAboutData aboutData( "example", I18N_NOOP("autoconfig example"), "0.1" ); + aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); + + KCmdLineArgs::init( argc, argv, &aboutData ); + + KApplication app; + + // Create a new dialog with the same name as the above checking code. + KAutoConfigDialog *dialog = new KAutoConfigDialog(0, "settings"); + + // Add the general page. Store the settings in the General group and + // use the icon package_settings. + GeneralBase *general = new GeneralBase( 0 ); + dialog->addPage( general, i18n("General"), "General", "" ); + + MyOptionsBase *myOptions = new MyOptionsBase( 0 ); + +// myOptions->show(); + dialog->addPage( myOptions, i18n("MyOptions"), "MyOptions", "" ); + +// app.setMainWidget( dialog ); + + dialog->show(); + + return app.exec(); +} diff --git a/libtdepim/cfgc/example.cfg b/libtdepim/cfgc/example.cfg new file mode 100644 index 000000000..18c7b8b15 --- /dev/null +++ b/libtdepim/cfgc/example.cfg @@ -0,0 +1,40 @@ + + + + + + + + + + OneOption + + true + + + Another Option + + 5 + + + + One + Two + Three + + ListOption + One + + + + + MyString + + Default String + + + MyStringList + up,down + + + diff --git a/libtdepim/cfgc/example.cpp b/libtdepim/cfgc/example.cpp new file mode 100644 index 000000000..4f818e900 --- /dev/null +++ b/libtdepim/cfgc/example.cpp @@ -0,0 +1,55 @@ +/* + This file is part of KDE. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "exampleprefs_base.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +int main( int argc, char **argv ) +{ + KAboutData aboutData( "example", I18N_NOOP("cfgc example"), "0.1" ); + aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); + + KCmdLineArgs::init( argc, argv, &aboutData ); + + KApplication app; + + ExamplePrefsBase *prefs = ExamplePrefsBase::self(); + + KPrefsDialog *dialog = new KPrefsDialog( prefs ); + + dialog->autoCreate(); + + app.setMainWidget( dialog ); + + dialog->show(); + + return app.exec(); +} diff --git a/libtdepim/cfgc/exampleprefs_base.kcfg b/libtdepim/cfgc/exampleprefs_base.kcfg new file mode 100644 index 000000000..e197ae7cd --- /dev/null +++ b/libtdepim/cfgc/exampleprefs_base.kcfg @@ -0,0 +1,42 @@ + + + + + + + true + + + + 5 + + + + And this is a longer description of this option. Just wondering, how will the translations of those be handled? + + + + + + + + + + + + One + + + + + + Default String + + + up,down + + + diff --git a/libtdepim/cfgc/exampleprefs_base.kcfgc b/libtdepim/cfgc/exampleprefs_base.kcfgc new file mode 100644 index 000000000..36e5ed4e6 --- /dev/null +++ b/libtdepim/cfgc/exampleprefs_base.kcfgc @@ -0,0 +1,11 @@ +# Code generation options for kconfig_compiler +File=exampleprefs_base.kcfg +ClassName=ExamplePrefsBase +Singleton=true +Mutators=true +Inherits=KPimPrefs +IncludeFiles=libtdepim/kpimprefs.h +MemberVariables=public +GlobalEnums=true +ItemAccessors=true +SetUserTexts=true diff --git a/libtdepim/cfgc/general_base.ui b/libtdepim/cfgc/general_base.ui new file mode 100644 index 000000000..7cafaa011 --- /dev/null +++ b/libtdepim/cfgc/general_base.ui @@ -0,0 +1,46 @@ + +GeneralBase + + + GeneralBase + + + + 0 + 0 + 600 + 480 + + + + AutoExampleDialog + + + + unnamed + + + + OneOption + + + OneOption + + + + + Another_Option + + + + + textLabel1 + + + AnotherOption: + + + + + + diff --git a/libtdepim/cfgc/myoptions_base.ui b/libtdepim/cfgc/myoptions_base.ui new file mode 100644 index 000000000..4d4f8247f --- /dev/null +++ b/libtdepim/cfgc/myoptions_base.ui @@ -0,0 +1,46 @@ + +MyOptionsBase + + + MyOptionsBase + + + + 0 + 0 + 600 + 480 + + + + + textLabel1 + + + + 30 + 180 + 70 + 20 + + + + MyString: + + + + + MyString + + + + 130 + 180 + 123 + 22 + + + + + + diff --git a/libtdepim/clicklineedit.cpp b/libtdepim/clicklineedit.cpp new file mode 100644 index 000000000..28e66a0ba --- /dev/null +++ b/libtdepim/clicklineedit.cpp @@ -0,0 +1,85 @@ +/* + This file is part of libtdepim. + Copyright (c) 2004 Daniel Molkentin + based on code by Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#include "clicklineedit.h" + +#include "tqpainter.h" + +using namespace KPIM; + +ClickLineEdit::ClickLineEdit(TQWidget *parent, const TQString &msg, const char* name) : + KLineEdit(parent, name) +{ + mDrawClickMsg = true; + setClickMessage( msg ); +} + +ClickLineEdit::~ClickLineEdit() {} + + +void ClickLineEdit::setClickMessage( const TQString &msg ) +{ + mClickMessage = msg; + tqrepaint(); +} + +void ClickLineEdit::setText( const TQString &txt ) +{ + mDrawClickMsg = txt.isEmpty(); + tqrepaint(); + KLineEdit::setText( txt ); +} + +void ClickLineEdit::drawContents( TQPainter *p ) +{ + KLineEdit::drawContents( p ); + + if ( mDrawClickMsg == true && !hasFocus() ) { + TQPen tmp = p->pen(); + p->setPen( palette().color( TQPalette::Disabled, TQColorGroup::Text ) ); + TQRect cr = contentsRect(); + p->drawText( cr, AlignAuto|AlignVCenter, mClickMessage ); + p->setPen( tmp ); + } +} + +void ClickLineEdit::focusInEvent( TQFocusEvent *ev ) +{ + if ( mDrawClickMsg == true ) + { + mDrawClickMsg = false; + tqrepaint(); + } + TQLineEdit::focusInEvent( ev ); +} + +void ClickLineEdit::focusOutEvent( TQFocusEvent *ev ) +{ + if ( text().isEmpty() ) + { + mDrawClickMsg = true; + tqrepaint(); + } + TQLineEdit::focusOutEvent( ev ); +} + +#include "clicklineedit.moc" diff --git a/libtdepim/clicklineedit.h b/libtdepim/clicklineedit.h new file mode 100644 index 000000000..28b771ff5 --- /dev/null +++ b/libtdepim/clicklineedit.h @@ -0,0 +1,65 @@ +/* + This file is part of libtdepim. + Copyright (c) 2004 Daniel Molkentin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef CLICKLINEEDIT_H +#define CLICKLINEEDIT_H + +#include +#include + +namespace KPIM { + +/** + This class provides a KLineEdit which contains a greyed-out hinting + text as long as the user didn't enter any text + + @short LineEdit with customizable "Click here" text + @author Daniel Molkentin +*/ +class KDE_EXPORT ClickLineEdit : public KLineEdit +{ + Q_OBJECT + TQ_OBJECT + TQ_PROPERTY( TQString clickMessage READ clickMessage WRITE setClickMessage ) + public: + ClickLineEdit( TQWidget *parent, const TQString &msg = TQString(), const char* name = 0 ); + ~ClickLineEdit(); + + void setClickMessage( const TQString &msg ); + TQString clickMessage() const { return mClickMessage; } + + virtual void setText( const TQString& txt ); + + protected: + virtual void drawContents( TQPainter *p ); + virtual void focusInEvent( TQFocusEvent *ev ); + virtual void focusOutEvent( TQFocusEvent *ev ); + + private: + TQString mClickMessage; + bool mDrawClickMsg; + +}; + +} + +#endif // CLICKLINEEDIT_H + + diff --git a/libtdepim/collectingprocess.cpp b/libtdepim/collectingprocess.cpp new file mode 100644 index 000000000..58cdcb5ee --- /dev/null +++ b/libtdepim/collectingprocess.cpp @@ -0,0 +1,140 @@ +/* + collectingprocess.cpp + + This file is part of libtdepim. + Copyright (c) 2004 Ingo Kloecker + + This library 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 library 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 "collectingprocess.h" + +#include + +#include + +using namespace KPIM; + +struct CollectingProcess::Private { + Private() : stdoutSize( 0 ), stderrSize( 0 ) + {} + + uint stdoutSize; + TQValueList stdoutBuffer; + uint stderrSize; + TQValueList stderrBuffer; +}; + + +CollectingProcess::CollectingProcess( TQObject * parent, const char * name ) + : KProcess( parent, name ) +{ + d = new Private(); +} + +CollectingProcess::~CollectingProcess() { + delete d; d = 0; +} + +bool CollectingProcess::start( RunMode runmode, Communication comm ) { + // prevent duplicate connection + disconnect( this, TQT_SIGNAL( receivedStdout( KProcess *, char *, int ) ), + this, TQT_SLOT( slotReceivedStdout( KProcess *, char *, int ) ) ); + if ( comm & Stdout ) { + connect( this, TQT_SIGNAL( receivedStdout( KProcess *, char *, int ) ), + this, TQT_SLOT( slotReceivedStdout( KProcess *, char *, int ) ) ); + } + // prevent duplicate connection + disconnect( this, TQT_SIGNAL( receivedStderr( KProcess *, char *, int ) ), + this, TQT_SLOT( slotReceivedStderr( KProcess *, char *, int ) ) ); + if ( comm & Stderr ) { + connect( this, TQT_SIGNAL( receivedStderr( KProcess *, char *, int ) ), + this, TQT_SLOT( slotReceivedStderr( KProcess *, char *, int ) ) ); + } + return KProcess::start( runmode, comm ); +} + +void CollectingProcess::slotReceivedStdout( KProcess *, char *buf, int len ) +{ + TQByteArray b; + b.duplicate( buf, len ); + d->stdoutBuffer.append( b ); + d->stdoutSize += len; +} + +void CollectingProcess::slotReceivedStderr( KProcess *, char *buf, int len ) +{ + TQByteArray b; + b.duplicate( buf, len ); + d->stderrBuffer.append( b ); + d->stderrSize += len; +} + +TQByteArray CollectingProcess::collectedStdout() +{ + if ( d->stdoutSize == 0 ) { + return TQByteArray(); + } + + uint offset = 0; + TQByteArray b( d->stdoutSize ); + for ( TQValueList::const_iterator it = d->stdoutBuffer.begin(); + it != d->stdoutBuffer.end(); + ++it ) { + memcpy( b.data() + offset, (*it).data(), (*it).size() ); + offset += (*it).size(); + } + d->stdoutBuffer.clear(); + d->stdoutSize = 0; + + return b; +} + +TQByteArray CollectingProcess::collectedStderr() +{ + if ( d->stderrSize == 0 ) { + return TQByteArray(); + } + + uint offset = 0; + TQByteArray b( d->stderrSize ); + for ( TQValueList::const_iterator it = d->stderrBuffer.begin(); + it != d->stderrBuffer.end(); + ++it ) { + memcpy( b.data() + offset, (*it).data(), (*it).size() ); + offset += (*it).size(); + } + d->stderrBuffer.clear(); + d->stderrSize = 0; + + return b; +} + +void CollectingProcess::virtual_hook( int id, void * data ) { + KProcess::virtual_hook( id, data ); +} + +#include "collectingprocess.moc" diff --git a/libtdepim/collectingprocess.h b/libtdepim/collectingprocess.h new file mode 100644 index 000000000..ae7378264 --- /dev/null +++ b/libtdepim/collectingprocess.h @@ -0,0 +1,79 @@ +/* -*- mode: C++ -*- + collectingprocess.h + + This file is part of libtdepim. + Copyright (c) 2004 Ingo Kloecker + + This library 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 library 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 __KPIM_COLLECTINGPROCESS_H__ +#define __KPIM_COLLECTINGPROCESS_H__ + +#include +#include + +namespace KPIM { + +/** + * @short An output collecting KProcess class. + * + * This class simplifies the usage of KProcess by collecting all output + * (stdout/stderr) of the process. + * + * @author Ingo Kloecker + */ +class KDE_EXPORT CollectingProcess : public KProcess { + Q_OBJECT + TQ_OBJECT +public: + CollectingProcess( TQObject * parent = 0, const char * name = 0 ); + ~CollectingProcess(); + + /** Starts the process in NotifyOnExit mode and writes in to stdin of + the process. + */ + bool start( RunMode runmode, Communication comm ); + + /** Returns the contents of the stdout buffer and clears it afterwards. */ + TQByteArray collectedStdout(); + /** Returns the contents of the stderr buffer and clears it afterwards. */ + TQByteArray collectedStderr(); + +private slots: + void slotReceivedStdout( KProcess *, char *, int ); + void slotReceivedStderr( KProcess *, char *, int ); + +private: + class Private; + Private * d; +protected: + void virtual_hook( int id, void * data ); +}; + +} // namespace KPIM + +#endif // __KPIM_COLLECTINGPROCESS_H__ diff --git a/libtdepim/completionordereditor.cpp b/libtdepim/completionordereditor.cpp new file mode 100644 index 000000000..2687188d0 --- /dev/null +++ b/libtdepim/completionordereditor.cpp @@ -0,0 +1,307 @@ +/** -*- c++ -*- + * completionordereditor.cpp + * + * Copyright (c) 2004 David Faure + * + * 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; version 2 of the License + * + * 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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 // FOR KDEPIM_NEW_DISTRLISTS + +#include "completionordereditor.h" +#include "ldapclient.h" +#include "resourceabc.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* + +Several items are used in addresseelineedit's completion object: + LDAP servers, KABC resources (imap and non-imap), Recent addresses (in kmail only). + +The default completion weights are as follow: + Recent addresses (kmail) : 10 (see kmail/kmlineeditspell.cpp) + LDAP: 50, 49, 48 etc. (see ldapclient.cpp) + KABC non-imap resources: 60 (see addresseelineedit.cpp and SimpleCompletionItem here) + Distribution lists: 60 (see addresseelineedit.cpp and SimpleCompletionItem here) + KABC imap resources: 80 (see kresources/imap/kabc/resourceimap.cpp) + +This dialog allows to change those weights, by showing one item per: + - LDAP server + - KABC non-imap resource + - KABC imap subresource + plus one item for Distribution Lists. + + Maybe 'recent addresses' should be configurable too, but first it might + be better to add support for them in korganizer too. + +*/ + +using namespace KPIM; + +namespace KPIM { + +int CompletionItemList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 ) +{ + int w1 = ( (CompletionItem*)s1 )->completionWeight(); + int w2 = ( (CompletionItem*)s2 )->completionWeight(); + // s1 < s2 if it has a higher completion value, i.e. w1 > w2. + return w2 - w1; +} + +class LDAPCompletionItem : public CompletionItem +{ +public: + LDAPCompletionItem( LdapClient* ldapClient ) : mLdapClient( ldapClient ) {} + virtual TQString label() const { return i18n( "LDAP server %1" ).tqarg( mLdapClient->server().host() ); } + virtual int completionWeight() const { return mLdapClient->completionWeight(); } + virtual void save( CompletionOrderEditor* ); +protected: + virtual void setCompletionWeight( int weight ) { mWeight = weight; } +private: + LdapClient* mLdapClient; + int mWeight; +}; + +void LDAPCompletionItem::save( CompletionOrderEditor* ) +{ + KConfig * config = LdapSearch::config(); + config->setGroup( "LDAP" ); + config->writeEntry( TQString( "SelectedCompletionWeight%1" ).tqarg( mLdapClient->clientNumber() ), + mWeight ); + config->sync(); +} + +// A simple item saved into kpimcompletionorder (no subresources, just name/identifier/weight) +class SimpleCompletionItem : public CompletionItem +{ +public: + SimpleCompletionItem( CompletionOrderEditor* editor, const TQString& label, const TQString& identifier, int weight ) + : mLabel( label ), mIdentifier( identifier ) { + KConfigGroup group( editor->configFile(), "CompletionWeights" ); + mWeight = group.readNumEntry( mIdentifier, weight ); + } + virtual TQString label() const { return mLabel; } + virtual int completionWeight() const { return mWeight; } + virtual void save( CompletionOrderEditor* ); +protected: + virtual void setCompletionWeight( int weight ) { mWeight = weight; } +private: + TQString mLabel, mIdentifier; + int mWeight; +}; + +void SimpleCompletionItem::save( CompletionOrderEditor* editor ) +{ + // Maybe KABC::Resource could have a completionWeight setting (for readConfig/writeConfig) + // But for kdelibs-3.2 compat purposes I can't do that. + KConfigGroup group( editor->configFile(), "CompletionWeights" ); + group.writeEntry( mIdentifier, mWeight ); +} + +// An imap subresource for kabc +class KABCImapSubResCompletionItem : public CompletionItem +{ +public: + KABCImapSubResCompletionItem( ResourceABC* resource, const TQString& subResource ) + : mResource( resource ), mSubResource( subResource ), mWeight( completionWeight() ) {} + virtual TQString label() const { + return TQString( "%1 %2" ).tqarg( mResource->resourceName() ).tqarg( mResource->subresourceLabel( mSubResource ) ); + } + virtual int completionWeight() const { + return mResource->subresourceCompletionWeight( mSubResource ); + } + virtual void setCompletionWeight( int weight ) { + mWeight = weight; + } + virtual void save( CompletionOrderEditor* ) { + mResource->setSubresourceCompletionWeight( mSubResource, mWeight ); + } +private: + ResourceABC* mResource; + TQString mSubResource; + int mWeight; +}; + +///////// + +class CompletionViewItem : public TQListViewItem +{ +public: + CompletionViewItem( TQListView* lv, CompletionItem* item ) + : TQListViewItem( lv, lv->lastItem(), item->label() ), mItem( item ) {} + CompletionItem* item() const { return mItem; } + void setItem( CompletionItem* i ) { mItem = i; setText( 0, mItem->label() ); } + +private: + CompletionItem* mItem; +}; + +CompletionOrderEditor::CompletionOrderEditor( KPIM::LdapSearch* ldapSearch, + TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n("Edit Completion Order"), Ok|Cancel, Ok, true ), + mConfig( "kpimcompletionorder" ), mDirty( false ) +{ + mItems.setAutoDelete( true ); + // The first step is to gather all the data, creating CompletionItem objects + TQValueList< LdapClient* > ldapClients = ldapSearch->clients(); + for( TQValueList::const_iterator it = ldapClients.begin(); it != ldapClients.end(); ++it ) { + //kdDebug(5300) << "LDAP: host " << (*it)->host() << " weight " << (*it)->completionWeight() << endl; + mItems.append( new LDAPCompletionItem( *it ) ); + } + KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); + TQPtrList resources = addressBook->resources(); + for( TQPtrListIterator resit( resources ); *resit; ++resit ) { + //kdDebug(5300) << "KABC Resource: " << (*resit)->className() << endl; + ResourceABC* res = dynamic_cast( *resit ); + if ( res ) { // IMAP KABC resource + const TQStringList subresources = res->subresources(); + for( TQStringList::const_iterator it = subresources.begin(); it != subresources.end(); ++it ) { + mItems.append( new KABCImapSubResCompletionItem( res, *it ) ); + } + } else { // non-IMAP KABC resource + mItems.append( new SimpleCompletionItem( this, (*resit)->resourceName(), + (*resit)->identifier(), 60 ) ); + } + } + +#ifndef KDEPIM_NEW_DISTRLISTS // new distr lists are normal contact, so no separate item if using them + // Add an item for distribution lists + mItems.append( new SimpleCompletionItem( this, i18n( "Distribution Lists" ), "DistributionLists" ), 60 ); +#endif + + mItems.append( new SimpleCompletionItem( this, i18n( "Recent Addresses" ), "Recent Addresses", 10 ) ); + + // Now sort the items, then create the GUI + mItems.sort(); + + TQHBox* page = makeHBoxMainWidget(); + mListView = new KListView( page ); + mListView->setSorting( -1 ); + mListView->addColumn( TQString() ); + mListView->header()->hide(); + + for( TQPtrListIterator compit( mItems ); *compit; ++compit ) { + new CompletionViewItem( mListView, *compit ); + kdDebug(5300) << " " << (*compit)->label() << " " << (*compit)->completionWeight() << endl; + } + + TQVBox* upDownBox = new TQVBox( page ); + mUpButton = new KPushButton( upDownBox, "mUpButton" ); + mUpButton->setIconSet( BarIconSet( "up", KIcon::SizeSmall ) ); + mUpButton->setEnabled( false ); // b/c no item is selected yet + mUpButton->setFocusPolicy( TQ_StrongFocus ); + + mDownButton = new KPushButton( upDownBox, "mDownButton" ); + mDownButton->setIconSet( BarIconSet( "down", KIcon::SizeSmall ) ); + mDownButton->setEnabled( false ); // b/c no item is selected yet + mDownButton->setFocusPolicy( TQ_StrongFocus ); + + TQWidget* spacer = new TQWidget( upDownBox ); + upDownBox->setStretchFactor( spacer, 100 ); + + connect( mListView, TQT_SIGNAL( selectionChanged( TQListViewItem* ) ), + TQT_SLOT( slotSelectionChanged( TQListViewItem* ) ) ); + connect( mUpButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotMoveUp() ) ); + connect( mDownButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotMoveDown() ) ); +} + +CompletionOrderEditor::~CompletionOrderEditor() +{ +} + +void CompletionOrderEditor::slotSelectionChanged( TQListViewItem *item ) +{ + mDownButton->setEnabled( item && item->itemBelow() ); + mUpButton->setEnabled( item && item->itemAbove() ); +} + +static void swapItems( CompletionViewItem *one, CompletionViewItem *other ) +{ + CompletionItem* i = one->item(); + one->setItem( other->item() ); + other->setItem( i ); +} + +void CompletionOrderEditor::slotMoveUp() +{ + CompletionViewItem *item = static_cast( mListView->selectedItem() ); + if ( !item ) return; + CompletionViewItem *above = static_cast( item->itemAbove() ); + if ( !above ) return; + swapItems( item, above ); + mListView->setCurrentItem( above ); + mListView->setSelected( above, true ); + mDirty = true; +} + +void CompletionOrderEditor::slotMoveDown() +{ + CompletionViewItem *item = static_cast( mListView->selectedItem() ); + if ( !item ) return; + CompletionViewItem *below = static_cast( item->itemBelow() ); + if ( !below ) return; + swapItems( item, below ); + mListView->setCurrentItem( below ); + mListView->setSelected( below, true ); + mDirty = true; +} + +void CompletionOrderEditor::slotOk() +{ + if ( mDirty ) { + int w = 100; + for ( TQListViewItem* it = mListView->firstChild(); it; it = it->nextSibling() ) { + CompletionViewItem *item = static_cast( it ); + item->item()->setCompletionWeight( w ); + item->item()->save( this ); + kdDebug(5300) << "slotOk: " << item->item()->label() << " " << w << endl; + --w; + } + + // Emit DCOP signal + // The emitter is always set to KPIM::IMAPCompletionOrder, so that the connect works + // This is why we can't use k_dcop_signals here, but need to use emitDCOPSignal + kapp->dcopClient()->emitDCOPSignal( "KPIM::IMAPCompletionOrder", "orderChanged()", TQByteArray() ); + } + KDialogBase::slotOk(); +} + +} // namespace KPIM + +#include "completionordereditor.moc" diff --git a/libtdepim/completionordereditor.h b/libtdepim/completionordereditor.h new file mode 100644 index 000000000..50cc3b3cb --- /dev/null +++ b/libtdepim/completionordereditor.h @@ -0,0 +1,93 @@ +/* -*- c++ -*- + * completionordereditor.h + * + * Copyright (c) 2004 David Faure + * + * 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; version 2 of the License + * + * 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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 COMPLETIONORDEREDITOR_H +#define COMPLETIONORDEREDITOR_H + +#include +#include + +class KPushButton; +class KListView; +namespace KPIM { + +class LdapSearch; +class CompletionOrderEditor; + +// Base class for items in the list +class CompletionItem +{ +public: + virtual ~CompletionItem() {} + virtual TQString label() const = 0; + virtual int completionWeight() const = 0; + virtual void setCompletionWeight( int weight ) = 0; + virtual void save( CompletionOrderEditor* ) = 0; +}; + + +// I don't like TQPtrList much, but it has compareItems, which TQValueList doesn't +class CompletionItemList : public TQPtrList +{ +public: + CompletionItemList() {} + virtual int compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 ); +}; + +class CompletionOrderEditor : public KDialogBase { + Q_OBJECT + TQ_OBJECT + +public: + CompletionOrderEditor( KPIM::LdapSearch* ldapSearch, TQWidget* parent, const char* name = 0 ); + ~CompletionOrderEditor(); + + KConfig* configFile() { return &mConfig; } + +private slots: + void slotSelectionChanged( TQListViewItem* ); + void slotMoveUp(); + void slotMoveDown(); + virtual void slotOk(); + +private: + KConfig mConfig; + CompletionItemList mItems; + KListView* mListView; + KPushButton* mUpButton; + KPushButton* mDownButton; + + bool mDirty; +}; + +} // namespace + +#endif /* COMPLETIONORDEREDITOR_H */ + diff --git a/libtdepim/configmanager.cpp b/libtdepim/configmanager.cpp new file mode 100644 index 000000000..64b4562fc --- /dev/null +++ b/libtdepim/configmanager.cpp @@ -0,0 +1,35 @@ +/* + configmanager.cpp + + KMail, the KDE mail client. + Copyright (c) 2002 the KMail authors. + See file AUTHORS for details + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License, + version 2.0, as published by the Free Software Foundation. + 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, US +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "configmanager.h" + +using namespace KPIM; + +ConfigManager::ConfigManager( TQObject * parent, const char * name ) + : TQObject( parent, name ) +{ + +} + +ConfigManager::~ConfigManager() +{ + +} + +#include "configmanager.moc" diff --git a/libtdepim/configmanager.h b/libtdepim/configmanager.h new file mode 100644 index 000000000..832a0f70f --- /dev/null +++ b/libtdepim/configmanager.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- + configmanager.h + + KMail, the KDE mail client. + Copyright (c) 2002 the KMail authors. + See file AUTHORS for details + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License, + version 2.0, as published by the Free Software Foundation. + 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, US +*/ + + +#ifndef _KMAIL_CONFIGMANAGER_H_ +#define _KMAIL_CONFIGMANAGER_H_ + +#include + +#include + +class KMKernel; + +namespace KPIM { + +/** + * @short Class for managing a set of config options. + * @author Marc Mutz + **/ +class KDE_EXPORT ConfigManager : public TQObject { + Q_OBJECT + TQ_OBJECT +public: + /** Commit changes to disk and emit changed() if necessary. */ + virtual void commit() = 0; + /** Re-read the config from disk and forget changes. */ + virtual void rollback() = 0; + + /** Check whether there are any unsaved changes. */ + virtual bool hasPendingChanges() const = 0; + +signals: + /** Emitted whenever a commit changes any configure option */ + void changed(); + +protected: + ConfigManager( TQObject * parent=0, const char * name=0 ); + virtual ~ConfigManager(); +}; + +} + +#endif // _KMAIL_CONFIGMANAGER_H_ diff --git a/libtdepim/configure.in.in b/libtdepim/configure.in.in new file mode 100644 index 000000000..c405f31c4 --- /dev/null +++ b/libtdepim/configure.in.in @@ -0,0 +1,14 @@ +AC_MSG_CHECKING([whether to use new-style distribution lists]) +AC_ARG_ENABLE(newdistrlists, +AC_HELP_STRING([--disable-newdistrlists], + [Disables the new distribution lists (which are saved as addressee in the address book as normal contacts, useful for Kolab)]), + [ enable_new_distrlists=$enableval], [enable_new_distrlists=yes])dnl +if test "$enable_new_distrlists" = "yes" ; then + AC_DEFINE_UNQUOTED(KDEPIM_NEW_DISTRLISTS, 1, [Define if you want to use the new distribution lists]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + +AM_CONDITIONAL(compile_newdistrlists, test "x$enable_new_distrlists" = "xyes") + diff --git a/libtdepim/csshelper.cpp b/libtdepim/csshelper.cpp new file mode 100644 index 000000000..05f20e390 --- /dev/null +++ b/libtdepim/csshelper.cpp @@ -0,0 +1,647 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- + csshelper.cpp + + This file is part of KMail, the KDE mail client. + Copyright (c) 2003 Marc Mutz + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 "csshelper.h" + +#include +#include +#include +#include + +#include +#include + +namespace KPIM { + + namespace { + // some TQColor manipulators that hide the ugly TQColor API w.r.t. HSV: + inline TQColor darker( const TQColor & c ) { + int h, s, v; + c.hsv( &h, &s, &v ); + return TQColor( h, s, v*4/5, TQColor::Hsv ); + } + + inline TQColor desaturate( const TQColor & c ) { + int h, s, v; + c.hsv( &h, &s, &v ); + return TQColor( h, s/8, v, TQColor::Hsv ); + } + + inline TQColor fixValue( const TQColor & c, int newV ) { + int h, s, v; + c.hsv( &h, &s, &v ); + return TQColor( h, s, newV, TQColor::Hsv ); + } + + inline int getValueOf( const TQColor & c ) { + int h, s, v; + c.hsv( &h, &s, &v ); + return v; + } + } + + CSSHelper::CSSHelper( const TQPaintDeviceMetrics &pdm ) : + mShrinkQuotes( false ), + mMetrics( pdm ) + { + // initialize with defaults - should match the corresponding application defaults + mForegroundColor = TQApplication::tqpalette().active().text(); + mLinkColor = KGlobalSettings::linkColor(); + mVisitedLinkColor = KGlobalSettings::visitedLinkColor(); + mBackgroundColor = TQApplication::tqpalette().active().base(); + cHtmlWarning = TQColor( 0xFF, 0x40, 0x40 ); // warning frame color: light red + + cPgpEncrH = TQColor( 0x00, 0x80, 0xFF ); // light blue + cPgpOk1H = TQColor( 0x40, 0xFF, 0x40 ); // light green + cPgpOk0H = TQColor( 0xFF, 0xFF, 0x40 ); // light yellow + cPgpWarnH = TQColor( 0xFF, 0xFF, 0x40 ); // light yellow + cPgpErrH = TQt::red; + + for ( int i = 0 ; i < 3 ; ++i ) + mQuoteColor[i] = TQColor( 0x00, 0x80 - i * 0x10, 0x00 ); // shades of green + mRecycleQuoteColors = false; + + TQFont defaultFont = KGlobalSettings::generalFont(); + TQFont defaultFixedFont = KGlobalSettings::fixedFont(); + mBodyFont = mPrintFont = defaultFont; + mFixedFont = mFixedPrintFont = defaultFixedFont; + defaultFont.setItalic( true ); + for ( int i = 0 ; i < 3 ; ++i ) + mQuoteFont[i] = defaultFont; + + mBackingPixmapOn = false; + + recalculatePGPColors(); + } + + void CSSHelper::recalculatePGPColors() { + // determine the frame and body color for PGP messages from the header color + // if the header color equals the background color then the other colors are + // also set to the background color (-> old style PGP message viewing) + // else + // the brightness of the frame is set to 4/5 of the brightness of the header + // and in case of a light background color + // the saturation of the body is set to 1/8 of the saturation of the header + // while in case of a dark background color + // the value of the body is set to the value of the background color + + // Check whether the user uses a light color scheme + const int vBG = getValueOf( mBackgroundColor ); + const bool lightBG = vBG >= 128; + if ( cPgpOk1H == mBackgroundColor ) { + cPgpOk1F = mBackgroundColor; + cPgpOk1B = mBackgroundColor; + } else { + cPgpOk1F= darker( cPgpOk1H ); + cPgpOk1B = lightBG ? desaturate( cPgpOk1H ) : fixValue( cPgpOk1H, vBG ); + } + if ( cPgpOk0H == mBackgroundColor ) { + cPgpOk0F = mBackgroundColor; + cPgpOk0B = mBackgroundColor; + } else { + cPgpOk0F = darker( cPgpOk0H ); + cPgpOk0B = lightBG ? desaturate( cPgpOk0H ) : fixValue( cPgpOk0H, vBG ); + } + if ( cPgpWarnH == mBackgroundColor ) { + cPgpWarnF = mBackgroundColor; + cPgpWarnB = mBackgroundColor; + } else { + cPgpWarnF = darker( cPgpWarnH ); + cPgpWarnB = lightBG ? desaturate( cPgpWarnH ) : fixValue( cPgpWarnH, vBG ); + } + if ( cPgpErrH == mBackgroundColor ) { + cPgpErrF = mBackgroundColor; + cPgpErrB = mBackgroundColor; + } else { + cPgpErrF = darker( cPgpErrH ); + cPgpErrB = lightBG ? desaturate( cPgpErrH ) : fixValue( cPgpErrH, vBG ); + } + if ( cPgpEncrH == mBackgroundColor ) { + cPgpEncrF = mBackgroundColor; + cPgpEncrB = mBackgroundColor; + } else { + cPgpEncrF = darker( cPgpEncrH ); + cPgpEncrB = lightBG ? desaturate( cPgpEncrH ) : fixValue( cPgpEncrH, vBG ); + } + } + + TQString CSSHelper::cssDefinitions( bool fixed ) const { + return + commonCssDefinitions() + + + "@media screen {\n\n" + + + screenCssDefinitions( this, fixed ) + + + "}\n" + "@media print {\n\n" + + + printCssDefinitions( fixed ) + + + "}\n"; + } + + TQString CSSHelper::htmlHead( bool /*fixed*/ ) const { + return + "\n" + "\n" + "\n"; + } + + TQString CSSHelper::quoteFontTag( int level ) const { + if ( level < 0 ) + level = 0; + static const int numQuoteLevels = sizeof mQuoteFont / sizeof *mQuoteFont; + const int effectiveLevel = mRecycleQuoteColors + ? level % numQuoteLevels + 1 + : kMin( level + 1, numQuoteLevels ) ; + if ( level >= numQuoteLevels ) + return TQString( "
" ).tqarg( effectiveLevel ); + else + return TQString( "
" ).tqarg( effectiveLevel ); + } + + TQString CSSHelper::nonQuotedFontTag() const { + return "
"; + } + + TQFont CSSHelper::bodyFont( bool fixed, bool print ) const { + return fixed ? ( print ? mFixedPrintFont : mFixedFont ) + : ( print ? mPrintFont : mBodyFont ); + } + + int CSSHelper::fontSize( bool fixed, bool print ) const { + return bodyFont( fixed, print ).pointSize(); + } + + + namespace { + int pointsToPixel( const TQPaintDeviceMetrics & metrics, int pointSize ) { + return ( pointSize * metrics.logicalDpiY() + 36 ) / 72 ; + } + } + + static const char * const quoteFontSizes[] = { "85", "80", "75" }; + + TQString CSSHelper::printCssDefinitions( bool fixed ) const { + const TQString headerFont = TQString( " font-family: \"%1\" ! important;\n" + " font-size: %2pt ! important;\n" ) + .tqarg( mPrintFont.family() ) + .tqarg( mPrintFont.pointSize() ); + const TQColorGroup & cg = TQApplication::tqpalette().active(); + + const TQFont printFont = bodyFont( fixed, true /* print */ ); + TQString quoteCSS; + if ( printFont.italic() ) + quoteCSS += " font-style: italic ! important;\n"; + if ( printFont.bold() ) + quoteCSS += " font-weight: bold ! important;\n"; + if ( !quoteCSS.isEmpty() ) + quoteCSS = "div.noquote {\n" + quoteCSS + "}\n\n"; + + return + TQString( "body {\n" + " font-family: \"%1\" ! important;\n" + " font-size: %2pt ! important;\n" + " color: #000000 ! important;\n" + " background-color: #ffffff ! important\n" + "}\n\n" ) + .tqarg( printFont.family(), + TQString::number( printFont.pointSize() ) ) + + + TQString( "tr.textAtmH,\n" + "tr.signInProgressH,\n" + "tr.rfc822H,\n" + "tr.encrH,\n" + "tr.signOkKeyOkH,\n" + "tr.signOkKeyBadH,\n" + "tr.signWarnH,\n" + "tr.signErrH,\n" + "div.header {\n" + "%1" + "}\n\n" + + "div.fancy.header > div {\n" + " background-color: %2 ! important;\n" + " color: %3 ! important;\n" + " padding: 4px ! important;\n" + " border: solid %3 1px ! important;\n" + "}\n\n" + + "div.fancy.header > div a[href] { color: %3 ! important; }\n\n" + + "div.fancy.header > table.outer{\n" + " background-color: %2 ! important;\n" + " color: %3 ! important;\n" + " border-bottom: solid %3 1px ! important;\n" + " border-left: solid %3 1px ! important;\n" + " border-right: solid %3 1px ! important;\n" + "}\n\n" + + "div.spamheader {\n" + " display:none ! important;\n" + "}\n\n" + + "div.htmlWarn {\n" + " border: 2px solid #ffffff ! important;\n" + "}\n\n" + + "div.senderpic{\n" + " font-size:0.8em ! important;\n" + " border:1px solid black ! important;\n" + " background-color:%2 ! important;\n" + "}\n\n" + + "div.senderstatus{\n" + " text-align:center ! important;\n" + "}\n\n" + + "div.noprint {\n" + " display:none ! important;\n" + "}\n\n" + ) + .tqarg( headerFont, + cg.background().name(), + cg.foreground().name() ) + + quoteCSS; + } + + TQString CSSHelper::screenCssDefinitions( const CSSHelper * helper, bool fixed ) const { + const TQString fgColor = mForegroundColor.name(); + const TQString bgColor = mBackgroundColor.name(); + const TQString linkColor = mLinkColor.name(); + const TQString headerFont = TQString(" font-family: \"%1\" ! important;\n" + " font-size: %2px ! important;\n") + .tqarg( mBodyFont.family() ) + .tqarg( pointsToPixel( helper->mMetrics, mBodyFont.pointSize() ) ); + const TQString background = ( mBackingPixmapOn + ? TQString( " background-image:url(file://%1) ! important;\n" ) + .tqarg( mBackingPixmapStr ) + : TQString( " background-color: %1 ! important;\n" ) + .tqarg( bgColor ) ); + const TQString bodyFontSize = TQString::number( pointsToPixel( helper->mMetrics, fontSize( fixed ) ) ) + "px" ; + const TQColorGroup & cg = TQApplication::tqpalette().active(); + + TQString quoteCSS; + if ( bodyFont( fixed ).italic() ) + quoteCSS += " font-style: italic ! important;\n"; + if ( bodyFont( fixed ).bold() ) + quoteCSS += " font-weight: bold ! important;\n"; + if ( !quoteCSS.isEmpty() ) + quoteCSS = "div.noquote {\n" + quoteCSS + "}\n\n"; + + // CSS definitions for quote levels 1-3 + for ( int i = 0 ; i < 3 ; ++i ) { + quoteCSS += TQString( "div.quotelevel%1 {\n" + " color: %2 ! important;\n" ) + .tqarg( TQString::number(i+1), mQuoteColor[i].name() ); + if ( mQuoteFont[i].italic() ) + quoteCSS += " font-style: italic ! important;\n"; + if ( mQuoteFont[i].bold() ) + quoteCSS += " font-weight: bold ! important;\n"; + if ( mShrinkQuotes ) + quoteCSS += " font-size: " + TQString::tqfromLatin1( quoteFontSizes[i] ) + + "% ! important;\n"; + quoteCSS += "}\n\n"; + } + + // CSS definitions for quote levels 4+ + for ( int i = 0 ; i < 3 ; ++i ) { + quoteCSS += TQString( "div.deepquotelevel%1 {\n" + " color: %2 ! important;\n" ) + .tqarg( TQString::number(i+1), mQuoteColor[i].name() ); + if ( mQuoteFont[i].italic() ) + quoteCSS += " font-style: italic ! important;\n"; + if ( mQuoteFont[i].bold() ) + quoteCSS += " font-weight: bold ! important;\n"; + if ( mShrinkQuotes ) + quoteCSS += " font-size: 70% ! important;\n"; + quoteCSS += "}\n\n"; + } + + return + TQString( "body {\n" + " font-family: \"%1\" ! important;\n" + " font-size: %2 ! important;\n" + " color: %3 ! important;\n" + "%4" + "}\n\n" ) + .tqarg( bodyFont( fixed ).family(), + bodyFontSize, + fgColor, + background ) + + + TQString( "a {\n" + " color: %1 ! important;\n" + " text-decoration: none ! important;\n" + "}\n\n" + + "a.white {\n" + " color: white ! important;\n" + "}\n\n" + + "a.black {\n" + " color: black ! important;\n" + "}\n\n" + + "table.textAtm { background-color: %2 ! important; }\n\n" + + "tr.textAtmH {\n" + " background-color: %3 ! important;\n" + "%4" + "}\n\n" + + "tr.textAtmB {\n" + " background-color: %3 ! important;\n" + "}\n\n" + + "table.signInProgress,\n" + "table.rfc822 {\n" + " background-color: %3 ! important;\n" + "}\n\n" + + "tr.signInProgressH,\n" + "tr.rfc822H {\n" + "%4" + "}\n\n" ) + .tqarg( linkColor, fgColor, bgColor, headerFont ) + + + TQString( "table.encr {\n" + " background-color: %1 ! important;\n" + "}\n\n" + + "tr.encrH {\n" + " background-color: %2 ! important;\n" + "%3" + "}\n\n" + + "tr.encrB { background-color: %4 ! important; }\n\n" ) + .tqarg( cPgpEncrF.name(), + cPgpEncrH.name(), + headerFont, + cPgpEncrB.name() ) + + + TQString( "table.signOkKeyOk {\n" + " background-color: %1 ! important;\n" + "}\n\n" + + "tr.signOkKeyOkH {\n" + " background-color: %2 ! important;\n" + "%3" + "}\n\n" + + "tr.signOkKeyOkB { background-color: %4 ! important; }\n\n" ) + .tqarg( cPgpOk1F.name(), + cPgpOk1H.name(), + headerFont, + cPgpOk1B.name() ) + + + TQString( "table.signOkKeyBad {\n" + " background-color: %1 ! important;\n" + "}\n\n" + + "tr.signOkKeyBadH {\n" + " background-color: %2 ! important;\n" + "%3" + "}\n\n" + + "tr.signOkKeyBadB { background-color: %4 ! important; }\n\n" ) + .tqarg( cPgpOk0F.name(), + cPgpOk0H.name(), + headerFont, + cPgpOk0B.name() ) + + + TQString( "table.signWarn {\n" + " background-color: %1 ! important;\n" + "}\n\n" + + "tr.signWarnH {\n" + " background-color: %2 ! important;\n" + "%3" + "}\n\n" + + "tr.signWarnB { background-color: %4 ! important; }\n\n" ) + .tqarg( cPgpWarnF.name(), + cPgpWarnH.name(), + headerFont, + cPgpWarnB.name() ) + + + TQString( "table.signErr {\n" + " background-color: %1 ! important;\n" + "}\n\n" + + "tr.signErrH {\n" + " background-color: %2 ! important;\n" + "%3" + "}\n\n" + + "tr.signErrB { background-color: %4 ! important; }\n\n" ) + .tqarg( cPgpErrF.name(), + cPgpErrH.name(), + headerFont, + cPgpErrB.name() ) + + + TQString( "div.htmlWarn {\n" + " border: 2px solid %1 ! important;\n" + "}\n\n" ) + .tqarg( cHtmlWarning.name() ) + + + TQString( "div.header {\n" + "%1" + "}\n\n" + + "div.fancy.header > div {\n" + " background-color: %2 ! important;\n" + " color: %3 ! important;\n" + " border: solid %4 1px ! important;\n" + "}\n\n" + + "div.fancy.header > div a[href] { color: %3 ! important; }\n\n" + + "div.fancy.header > div a[href]:hover { text-decoration: underline ! important; }\n\n" + + "div.fancy.header > div.spamheader {\n" + " background-color: #cdcdcd ! important;\n" + " border-top: 0px ! important;\n" + " padding: 3px ! important;\n" + " color: black ! important;\n" + " font-weight: bold ! important;\n" + " font-size: smaller ! important;\n" + "}\n\n" + + "div.fancy.header > table.outer {\n" + " background-color: %5 ! important;\n" + " color: %4 ! important;\n" + " border-bottom: solid %4 1px ! important;\n" + " border-left: solid %4 1px ! important;\n" + " border-right: solid %4 1px ! important;\n" + "}\n\n" + + "div.senderpic{\n" + " padding: 0px ! important;\n" + " font-size:0.8em ! important;\n" + " border:1px solid %6 ! important;\n" + // FIXME: InfoBackground crashes KHTML + //" background-color:InfoBackground ! important;\n" + " background-color:%5 ! important;\n" + "}\n\n" + + "div.senderstatus{\n" + " text-align:center ! important;\n" + "}\n\n" + ) + + .tqarg( headerFont ) + .tqarg( cg.highlight().name(), + cg.highlightedText().name(), + cg.foreground().name(), + cg.background().name() ) + .tqarg( cg.mid().name() ) + + quoteCSS; + } + + TQString CSSHelper::commonCssDefinitions() const { + return + "div.header {\n" + " margin-bottom: 10pt ! important;\n" + "}\n\n" + + "table.textAtm {\n" + " margin-top: 10pt ! important;\n" + " margin-bottom: 10pt ! important;\n" + "}\n\n" + + "tr.textAtmH,\n" + "tr.textAtmB,\n" + "tr.rfc822B {\n" + " font-weight: normal ! important;\n" + "}\n\n" + + "tr.signInProgressH,\n" + "tr.rfc822H,\n" + "tr.encrH,\n" + "tr.signOkKeyOkH,\n" + "tr.signOkKeyBadH,\n" + "tr.signWarnH,\n" + "tr.signErrH {\n" + " font-weight: bold ! important;\n" + "}\n\n" + + "tr.textAtmH td,\n" + "tr.textAtmB td {\n" + " padding: 3px ! important;\n" + "}\n\n" + + "table.rfc822 {\n" + " width: 100% ! important;\n" + " border: solid 1px black ! important;\n" + " margin-top: 10pt ! important;\n" + " margin-bottom: 10pt ! important;\n" + "}\n\n" + + "table.textAtm,\n" + "table.encr,\n" + "table.signWarn,\n" + "table.signErr,\n" + "table.signOkKeyBad,\n" + "table.signOkKeyOk,\n" + "table.signInProgress,\n" + "div.fancy.header table {\n" + " width: 100% ! important;\n" + " border-width: 0px ! important;\n" + "}\n\n" + + "div.htmlWarn {\n" + " margin: 0px 5% ! important;\n" + " padding: 10px ! important;\n" + " text-align: left ! important;\n" + "}\n\n" + + "div.fancy.header > div {\n" + " font-weight: bold ! important;\n" + " padding: 4px ! important;\n" + "}\n\n" + + "div.fancy.header table {\n" + " padding: 2px ! important;\n" // ### khtml bug: this is ignored + " text-align: left ! important\n" + "}\n\n" + + "div.fancy.header table th {\n" + " padding: 0px ! important;\n" + " white-space: nowrap ! important;\n" + " border-spacing: 0px ! important;\n" + " text-align: left ! important;\n" + " vertical-align: top ! important;\n" + "}\n\n" + + "div.fancy.header table td {\n" + " padding: 0px ! important;\n" + " border-spacing: 0px ! important;\n" + " text-align: left ! important;\n" + " vertical-align: top ! important;\n" + " width: 100% ! important;\n" + "}\n\n" + + "span.pimsmileytext {\n" + " position: absolute;\n" + " top: 0px;\n" + " left: 0px;\n" + " visibility: hidden;\n" + "}\n\n" + + "img.pimsmileyimg {\n" + "}\n\n" + + "div.quotelevelmark {\n" + " position: absolute;\n" + " margin-left:-10px;\n" + "}\n\n" + ; + } + + + void CSSHelper::setBodyFont( const TQFont& font ) + { + mBodyFont = font; + } + + void CSSHelper::setPrintFont( const TQFont& font ) + { + mPrintFont = font; + } + + TQColor CSSHelper::pgpWarnColor() const + { + return cPgpWarnH; + } + +} // namespace KPIM diff --git a/libtdepim/csshelper.h b/libtdepim/csshelper.h new file mode 100644 index 000000000..ab9190cf8 --- /dev/null +++ b/libtdepim/csshelper.h @@ -0,0 +1,111 @@ +/* -*- c++ -*- + csshelper.h + + This file is part of KMail, the KDE mail client. + Copyright (c) 2003 Marc Mutz + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 KPIM_CSSHELPER_H +#define KPIM_CSSHELPER_H + +#include +#include +#include + +class TQString; + +namespace KPIM { + +class CSSHelper { + public: + /** Construct a CSSHelper object and set its font and color settings to + default values. + Sub-Classes should put their config loading here. + */ + CSSHelper( const TQPaintDeviceMetrics &pdm ); + + /** @return HTML head including style sheet definitions and the + >body< tag */ + TQString htmlHead( bool fixedFont = false ) const; + + /** @return The collected CSS definitions as a string */ + TQString cssDefinitions( bool fixedFont = false ) const; + + /** @return a <div> start tag with embedded style + information suitable for quoted text with quote level @p level */ + TQString quoteFontTag( int level ) const; + /** @return a <div> start tag with embedded style + information suitable for non-quoted text */ + TQString nonQuotedFontTag() const; + + TQFont bodyFont( bool fixedFont = false, bool printing = false ) const; + + void setBodyFont( const TQFont& font ); + void setPrintFont( const TQFont& font ); + + TQColor pgpWarnColor() const; + + protected: + /** Recalculate PGP frame and body colors (should be called after changing + color settings) */ + void recalculatePGPColors(); + + protected: + TQFont mBodyFont, mPrintFont, mFixedFont, mFixedPrintFont; + TQFont mQuoteFont[3]; + TQColor mQuoteColor[3]; + bool mRecycleQuoteColors; + bool mBackingPixmapOn; + bool mShrinkQuotes; + TQString mBackingPixmapStr; + TQColor mForegroundColor, mLinkColor, mVisitedLinkColor, mBackgroundColor; + // colors for PGP (Frame, Header, Body) + TQColor cPgpOk1F, cPgpOk1H, cPgpOk1B, + cPgpOk0F, cPgpOk0H, cPgpOk0B, + cPgpWarnF, cPgpWarnH, cPgpWarnB, + cPgpErrF, cPgpErrH, cPgpErrB, + cPgpEncrF, cPgpEncrH, cPgpEncrB; + // color of frame of warning preceding the source of HTML messages + TQColor cHtmlWarning; + + private: + int fontSize( bool fixed, bool print = false ) const; + // returns CSS rules specific to the print media type + TQString printCssDefinitions( bool fixed ) const; + // returns CSS rules specific to the screen media type + TQString screenCssDefinitions( const CSSHelper * helper, bool fixed ) const; + // returns CSS rules common to both screen and print media types + TQString commonCssDefinitions() const; + + private: + const TQPaintDeviceMetrics mMetrics; + +}; + +} // namespace KPIM + +#endif // KPIM_CSSHELPER_H diff --git a/libtdepim/designerfields.cpp b/libtdepim/designerfields.cpp new file mode 100644 index 000000000..1a07655f7 --- /dev/null +++ b/libtdepim/designerfields.cpp @@ -0,0 +1,251 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + Copyright (c) 2004 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "designerfields.h" + +using namespace KPIM; + +DesignerFields::DesignerFields( const TQString &uiFile, TQWidget *parent, + const char *name ) + : TQWidget( parent, name ) +{ + initGUI( uiFile ); +} + +void DesignerFields::initGUI( const TQString &uiFile ) +{ + TQVBoxLayout *tqlayout = new TQVBoxLayout( this ); + + TQWidget *wdg = TQWidgetFactory::create( uiFile, 0, this ); + if ( !wdg ) { + kdError() << "No ui file found" << endl; + return; + } + + mTitle = wdg->caption(); + mIdentifier = wdg->name(); + + tqlayout->addWidget( wdg ); + + TQObjectList *list = wdg->queryList( TQWIDGET_OBJECT_NAME_STRING ); + TQObjectListIt it( *list ); + + TQStringList allowedTypes; + allowedTypes << TQLINEEDIT_OBJECT_NAME_STRING + << TQTEXTEDIT_OBJECT_NAME_STRING + << TQSPINBOX_OBJECT_NAME_STRING + << TQCHECKBOX_OBJECT_NAME_STRING + << TQCOMBOBOX_OBJECT_NAME_STRING + << TQDATETIMEEDIT_OBJECT_NAME_STRING + << "KLineEdit" + << "KDateTimeWidget" + << "KDatePicker"; + + while ( it.current() ) { + if ( allowedTypes.contains( it.current()->className() ) ) { + TQString name = it.current()->name(); + if ( name.startsWith( "X_" ) ) { + name = name.mid( 2 ); + + TQWidget *widget = TQT_TQWIDGET( it.current() ); + if ( !name.isEmpty() ) + mWidgets.insert( name, widget ); + + if ( it.current()->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) ) + connect( it.current(), TQT_SIGNAL( textChanged( const TQString& ) ), + TQT_SIGNAL( modified() ) ); + else if ( it.current()->inherits( TQSPINBOX_OBJECT_NAME_STRING ) ) + connect( it.current(), TQT_SIGNAL( valueChanged( int ) ), + TQT_SIGNAL( modified() ) ); + else if ( it.current()->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) ) + connect( it.current(), TQT_SIGNAL( toggled( bool ) ), + TQT_SIGNAL( modified() ) ); + else if ( it.current()->inherits( TQCOMBOBOX_OBJECT_NAME_STRING ) ) + connect( it.current(), TQT_SIGNAL( activated( const TQString& ) ), + TQT_SIGNAL( modified() ) ); + else if ( it.current()->inherits( TQDATETIMEEDIT_OBJECT_NAME_STRING ) ) + connect( it.current(), TQT_SIGNAL( valueChanged( const TQDateTime& ) ), + TQT_SIGNAL( modified() ) ); + else if ( it.current()->inherits( "KDateTimeWidget" ) ) + connect( it.current(), TQT_SIGNAL( valueChanged( const TQDateTime& ) ), + TQT_SIGNAL( modified() ) ); + else if ( it.current()->inherits( "KDatePicker" ) ) + connect( it.current(), TQT_SIGNAL( dateChanged( TQDate ) ), + TQT_SIGNAL( modified() ) ); + else if ( it.current()->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) ) + connect( it.current(), TQT_SIGNAL( textChanged() ), + TQT_SIGNAL( modified() ) ); + + if ( !widget->isEnabled() ) + mDisabledWidgets.append( widget ); + } + } + + ++it; + } + + delete list; +} + +TQString DesignerFields::identifier() const +{ + return mIdentifier; +} + +TQString DesignerFields::title() const +{ + return mTitle; +} + +void DesignerFields::load( DesignerFields::Storage *storage ) +{ + TQStringList keys = storage->keys(); + + // clear all custom page widgets + // we can't do this in the following loop, as it works on the + // custom fields of the vcard, which may not be set. + TQMap::ConstIterator widIt; + for ( widIt = mWidgets.begin(); widIt != mWidgets.end(); ++widIt ) { + TQString value; + if ( widIt.data()->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) ) { + TQLineEdit *wdg = static_cast( widIt.data() ); + wdg->setText( TQString() ); + } else if ( widIt.data()->inherits( TQSPINBOX_OBJECT_NAME_STRING ) ) { + TQSpinBox *wdg = static_cast( widIt.data() ); + wdg->setValue( wdg->minValue() ); + } else if ( widIt.data()->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) ) { + TQCheckBox *wdg = static_cast( widIt.data() ); + wdg->setChecked( false ); + } else if ( widIt.data()->inherits( TQDATETIMEEDIT_OBJECT_NAME_STRING ) ) { + TQDateTimeEdit *wdg = static_cast( widIt.data() ); + wdg->setDateTime( TQDateTime::tqcurrentDateTime() ); + } else if ( widIt.data()->inherits( "KDateTimeWidget" ) ) { + KDateTimeWidget *wdg = static_cast( widIt.data() ); + wdg->setDateTime( TQDateTime::tqcurrentDateTime() ); + } else if ( widIt.data()->inherits( "KDatePicker" ) ) { + KDatePicker *wdg = static_cast( widIt.data() ); + wdg->setDate( TQDate::tqcurrentDate() ); + } else if ( widIt.data()->inherits( TQCOMBOBOX_OBJECT_NAME_STRING ) ) { + TQComboBox *wdg = static_cast( widIt.data() ); + wdg->setCurrentItem( 0 ); + } else if ( widIt.data()->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) ) { + TQTextEdit *wdg = static_cast( widIt.data() ); + wdg->setText( TQString() ); + } + } + + TQStringList::ConstIterator it2; + for ( it2 = keys.begin(); it2 != keys.end(); ++it2 ) { + TQString value = storage->read( *it2 ); + + TQMap::ConstIterator it = mWidgets.find( *it2 ); + if ( it != mWidgets.end() ) { + if ( it.data()->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) ) { + TQLineEdit *wdg = static_cast( it.data() ); + wdg->setText( value ); + } else if ( it.data()->inherits( TQSPINBOX_OBJECT_NAME_STRING ) ) { + TQSpinBox *wdg = static_cast( it.data() ); + wdg->setValue( value.toInt() ); + } else if ( it.data()->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) ) { + TQCheckBox *wdg = static_cast( it.data() ); + wdg->setChecked( value == "true" || value == "1" ); + } else if ( it.data()->inherits( TQDATETIMEEDIT_OBJECT_NAME_STRING ) ) { + TQDateTimeEdit *wdg = static_cast( it.data() ); + wdg->setDateTime( TQDateTime::fromString( value, Qt::ISODate ) ); + } else if ( it.data()->inherits( "KDateTimeWidget" ) ) { + KDateTimeWidget *wdg = static_cast( it.data() ); + wdg->setDateTime( TQDateTime::fromString( value, Qt::ISODate ) ); + } else if ( it.data()->inherits( "KDatePicker" ) ) { + KDatePicker *wdg = static_cast( it.data() ); + wdg->setDate( TQDate::fromString( value, Qt::ISODate ) ); + } else if ( it.data()->inherits( TQCOMBOBOX_OBJECT_NAME_STRING ) ) { + TQComboBox *wdg = static_cast( it.data() ); + wdg->setCurrentText( value ); + } else if ( it.data()->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) ) { + TQTextEdit *wdg = static_cast( it.data() ); + wdg->setText( value ); + } + } + } +} + +void DesignerFields::save( DesignerFields::Storage *storage ) +{ + TQMap::Iterator it; + for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) { + TQString value; + if ( it.data()->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) ) { + TQLineEdit *wdg = static_cast( it.data() ); + value = wdg->text(); + } else if ( it.data()->inherits( TQSPINBOX_OBJECT_NAME_STRING ) ) { + TQSpinBox *wdg = static_cast( it.data() ); + value = TQString::number( wdg->value() ); + } else if ( it.data()->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) ) { + TQCheckBox *wdg = static_cast( it.data() ); + value = ( wdg->isChecked() ? "true" : "false" ); + } else if ( it.data()->inherits( TQDATETIMEEDIT_OBJECT_NAME_STRING ) ) { + TQDateTimeEdit *wdg = static_cast( it.data() ); + value = wdg->dateTime().toString( Qt::ISODate ); + } else if ( it.data()->inherits( "KDateTimeWidget" ) ) { + KDateTimeWidget *wdg = static_cast( it.data() ); + value = wdg->dateTime().toString( Qt::ISODate ); + } else if ( it.data()->inherits( "KDatePicker" ) ) { + KDatePicker *wdg = static_cast( it.data() ); + value = wdg->date().toString( Qt::ISODate ); + } else if ( it.data()->inherits( TQCOMBOBOX_OBJECT_NAME_STRING ) ) { + TQComboBox *wdg = static_cast( it.data() ); + value = wdg->currentText(); + } else if ( it.data()->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) ) { + TQTextEdit *wdg = static_cast( it.data() ); + value = wdg->text(); + } + + storage->write( it.key(), value ); + } +} + +void DesignerFields::setReadOnly( bool readOnly ) +{ + TQMap::Iterator it; + for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) + if ( mDisabledWidgets.find( it.data() ) == mDisabledWidgets.end() ) + it.data()->setEnabled( !readOnly ); +} + +#include "designerfields.moc" diff --git a/libtdepim/designerfields.h b/libtdepim/designerfields.h new file mode 100644 index 000000000..c7c2d22ca --- /dev/null +++ b/libtdepim/designerfields.h @@ -0,0 +1,75 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + Copyright (c) 2004 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KPIM_DESIGNERFIELDS_H +#define KPIM_DESIGNERFIELDS_H + +#include + +#include +#include +#include + +#include + +namespace KPIM { + +class KDE_EXPORT DesignerFields : public TQWidget +{ + Q_OBJECT + TQ_OBJECT + public: + DesignerFields( const TQString &uiFile, TQWidget *parent, + const char *name = 0 ); + + class Storage + { + public: + virtual ~Storage() {} + + virtual TQStringList keys() = 0; + virtual TQString read( const TQString &key ) = 0; + virtual void write( const TQString &key, const TQString &value ) = 0; + }; + + void load( Storage * ); + void save( Storage * ); + + void setReadOnly( bool readOnly ); + + TQString identifier() const; + TQString title() const; + + signals: + void modified(); + + private: + void initGUI( const TQString& ); + + TQMap mWidgets; + TQValueList mDisabledWidgets; + TQString mTitle; + TQString mIdentifier; +}; + +} + +#endif diff --git a/libtdepim/diffalgo.cpp b/libtdepim/diffalgo.cpp new file mode 100644 index 000000000..b2cfc40eb --- /dev/null +++ b/libtdepim/diffalgo.cpp @@ -0,0 +1,85 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +using namespace KPIM; + +void DiffAlgo::begin() +{ + TQValueList::Iterator it; + for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) + (*it)->begin(); +} + +void DiffAlgo::end() +{ + TQValueList::Iterator it; + for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) + (*it)->end(); +} + +void DiffAlgo::setLeftSourceTitle( const TQString &title ) +{ + TQValueList::Iterator it; + for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) + (*it)->setLeftSourceTitle( title ); +} + +void DiffAlgo::setRightSourceTitle( const TQString &title ) +{ + TQValueList::Iterator it; + for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) + (*it)->setRightSourceTitle( title ); +} + +void DiffAlgo::additionalLeftField( const TQString &id, const TQString &value ) +{ + TQValueList::Iterator it; + for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) + (*it)->additionalLeftField( id, value ); +} + +void DiffAlgo::additionalRightField( const TQString &id, const TQString &value ) +{ + TQValueList::Iterator it; + for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) + (*it)->additionalRightField( id, value ); +} + +void DiffAlgo::conflictField( const TQString &id, const TQString &leftValue, + const TQString &rightValue ) +{ + TQValueList::Iterator it; + for ( it = mDisplays.begin(); it != mDisplays.end(); ++it ) + (*it)->conflictField( id, leftValue, rightValue ); +} + +void DiffAlgo::addDisplay( DiffAlgoDisplay *display ) +{ + if ( mDisplays.find( display ) == mDisplays.end() ) + mDisplays.append( display ); +} + +void DiffAlgo::removeDisplay( DiffAlgoDisplay *display ) +{ + mDisplays.remove( display ); +} diff --git a/libtdepim/diffalgo.h b/libtdepim/diffalgo.h new file mode 100644 index 000000000..513db7e33 --- /dev/null +++ b/libtdepim/diffalgo.h @@ -0,0 +1,138 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef DIFFALGO_H +#define DIFFALGO_H + +#include +#include + +namespace KPIM { + +/** + DiffAlgo and DiffAlgoDisplay work together for displaying differences between + two PIM objects like contacts, events or todos. + DiffAlgo is the bas class for the diffing algorithm and DiffAlgoDisplay is + responsible for representation. The separation makes it possible to use one + display for all diffing algorithm and vice versa. + */ +class DiffAlgoDisplay +{ + public: + + /** + Is called on the start of the diff. + */ + virtual void begin() = 0; + + /** + Is called on the end of the diff. + */ + virtual void end() = 0; + + /** + Sets the title of the left data source. + */ + virtual void setLeftSourceTitle( const TQString &title ) = 0; + + /** + Sets the title of the right data source. + */ + virtual void setRightSourceTitle( const TQString &title ) = 0; + + /** + Adds a field which is only available in the left data source. + */ + virtual void additionalLeftField( const TQString &id, const TQString &value ) = 0; + + /** + Adds a field which is only available in the right data source. + */ + virtual void additionalRightField( const TQString &id, const TQString &value ) = 0; + + /** + Adds a conflict between two fields. + */ + virtual void conflictField( const TQString &id, const TQString &leftValue, + const TQString &rightValue ) = 0; +}; + + +class KDE_EXPORT DiffAlgo +{ + public: + /** + Destructor. + */ + virtual ~DiffAlgo() {} + + /** + Starts the diffing algorithm. + */ + virtual void run() = 0; + + /** + Must be called on the start of the diff. + */ + void begin(); + + /** + Must be called on the end of the diff. + */ + void end(); + + /** + Sets the title of the left data source. + */ + void setLeftSourceTitle( const TQString &title ); + + /** + Sets the title of the right data source. + */ + void setRightSourceTitle( const TQString &title ); + + /** + Adds a field which is only available in the left data source. + */ + void additionalLeftField( const TQString &id, const TQString &value ); + + /** + Adds a field which is only available in the right data source. + */ + void additionalRightField( const TQString &id, const TQString &value ); + + /** + Adds a conflict between two fields. + */ + void conflictField( const TQString &id, const TQString &leftValue, + const TQString &rightValue ); + + void addDisplay( DiffAlgoDisplay *display ); + void removeDisplay( DiffAlgoDisplay *display ); + + + private: + TQValueList mDisplays; +}; + +} + +#endif diff --git a/libtdepim/distributionlist.cpp b/libtdepim/distributionlist.cpp new file mode 100644 index 000000000..4cf079c76 --- /dev/null +++ b/libtdepim/distributionlist.cpp @@ -0,0 +1,223 @@ +#include "distributionlist.h" +#include + +static const char* s_customFieldName = "DistributionList"; + +KPIM::DistributionList::DistributionList() + : KABC::Addressee() +{ + // can't insert the custom entry here, we need to remain a null addressee +} + +KPIM::DistributionList::DistributionList( const KABC::Addressee& addr ) + : KABC::Addressee( addr ) +{ +} + +void KPIM::DistributionList::setName( const TQString &name ) +{ + // We can't use Addressee::setName, the name isn't saved/loaded in the vcard (fixed in 3.4) + Addressee::setFormattedName( name ); + // Also set family name, just in case this entry appears in the normal contacts list (e.g. old kaddressbook) + Addressee::setFamilyName( name ); + // We're not an empty addressee anymore + // Set the custom field to non-empty, so that isDistributionList works + if ( custom( "KADDRESSBOOK", s_customFieldName ).isEmpty() ) + insertCustom( "KADDRESSBOOK", s_customFieldName, ";" ); +} + +// Helper function, to parse the contents of the custom field +// Returns a list of { uid, email } +typedef TQValueList > ParseList; +static ParseList parseCustom( const TQString& str ) +{ + ParseList res; + const TQStringList lst = TQStringList::split( ';', str ); + for( TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { + if ( (*it).isEmpty() ) + continue; + // parse "uid,email" + TQStringList helpList = TQStringList::split( ',', (*it), true ); + Q_ASSERT( !helpList.isEmpty() ); + if ( helpList.isEmpty() ) + continue; + Q_ASSERT( helpList.count() < 3 ); // 1 or 2 items, but not more + const TQString uid = helpList.first(); + const TQString email = helpList.last(); + res.append( tqMakePair( uid, email ) ); + } + return res; +} + +void KPIM::DistributionList::insertEntry( const Addressee& addr, const TQString& email ) +{ + // insertEntry will removeEntry(uid), but not with formattedName + removeEntry( addr.formattedName(), email ); + insertEntry( addr.uid(), email ); +} + +void KPIM::DistributionList::insertEntry( const TQString& uid, const TQString& email ) +{ + Q_ASSERT( !email.isEmpty() || email.isNull() ); // hopefully never called with "", would lead to confusion + removeEntry( uid, email ); // avoid duplicates + TQString str = custom( "KADDRESSBOOK", s_customFieldName ); + // Assumption: UIDs don't contain ; nor , + str += ";" + uid + "," + email; + insertCustom( "KADDRESSBOOK", s_customFieldName, str ); // replace old value +} + +void KPIM::DistributionList::removeEntry( const Addressee& addr, const TQString& email ) +{ + removeEntry( addr.uid(), email ); + // Also remove entries with the full name as uid (for the kolab thing) + removeEntry( addr.formattedName(), email ); +} + +void KPIM::DistributionList::removeEntry( const TQString& uid, const TQString& email ) +{ + Q_ASSERT( !email.isEmpty() || email.isNull() ); // hopefully never called with "", would lead to confusion + ParseList parseList = parseCustom( custom( "KADDRESSBOOK", s_customFieldName ) ); + TQString str; + for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) { + const TQString thisUid = (*it).first; + const TQString thisEmail = (*it).second; + if ( thisUid == uid && thisEmail == email ) { + continue; // remove that one + } + str += ";" + thisUid + "," + thisEmail; + } + if ( str.isEmpty() ) + str = ";"; // keep something, for isDistributionList to work + insertCustom( "KADDRESSBOOK", s_customFieldName, str ); // replace old value +} + +bool KPIM::DistributionList::isDistributionList( const KABC::Addressee& addr ) +{ + const TQString str = addr.custom( "KADDRESSBOOK", s_customFieldName ); + return !str.isEmpty(); +} + +// ###### KDE4: add findByFormattedName to KABC::AddressBook +static KABC::Addressee::List findByFormattedName( KABC::AddressBook* book, + const TQString& name, + bool caseSensitive = true ) +{ + KABC::Addressee::List res; + KABC::AddressBook::Iterator abIt; + for ( abIt = book->begin(); abIt != book->end(); ++abIt ) + { + if ( caseSensitive && (*abIt).formattedName() == name ) + res.append( *abIt ); + if ( !caseSensitive && (*abIt).formattedName().lower() == name.lower() ) + res.append( *abIt ); + } + return res; +} + +KPIM::DistributionList KPIM::DistributionList::findByName( KABC::AddressBook* book, + const TQString& name, + bool caseSensitive ) +{ + KABC::AddressBook::Iterator abIt; + for ( abIt = book->begin(); abIt != book->end(); ++abIt ) + { + if ( isDistributionList( *abIt ) ) { + if ( caseSensitive && (*abIt).formattedName() == name ) + return *abIt; + if ( !caseSensitive && (*abIt).formattedName().lower() == name.lower() ) + return *abIt; + } + } + return DistributionList(); +} + +static KABC::Addressee findByUidOrName( KABC::AddressBook* book, const TQString& uidOrName, const TQString& email ) +{ + KABC::Addressee a = book->findByUid( uidOrName ); + if ( a.isEmpty() ) { + // UID not found, maybe it is a name instead. + // If we have an email, let's use that for the lookup. + // [This is used by e.g. the Kolab resource] + if ( !email.isEmpty() ) { + KABC::Addressee::List lst = book->findByEmail( email ); + KABC::Addressee::List::ConstIterator listit = lst.begin(); + for ( ; listit != lst.end(); ++listit ) + if ( (*listit).formattedName() == uidOrName ) { + a = *listit; + break; + } + if ( !lst.isEmpty() && a.isEmpty() ) { // found that email, but no match on the fullname + a = lst.first(); // probably the last name changed + } + } + // If we don't have an email, or if we didn't find any match for it, look up by full name + if ( a.isEmpty() ) { + // (But this has to be done here, since when loading we might not have the entries yet) + KABC::Addressee::List lst = findByFormattedName( book, uidOrName ); + if ( !lst.isEmpty() ) + a = lst.first(); + } + } + return a; +} + +KPIM::DistributionList::Entry::List KPIM::DistributionList::entries( KABC::AddressBook* book ) const +{ + Entry::List res; + const TQString str = custom( "KADDRESSBOOK", s_customFieldName ); + const ParseList parseList = parseCustom( str ); + for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) { + const TQString uid = (*it).first; + const TQString email = (*it).second; + // look up contact + KABC::Addressee a = findByUidOrName( book, uid, email ); + if ( a.isEmpty() ) { + // ## The old DistributionListManager had a "missing entries" list... + kdWarning() << "Addressee not found: " << uid << endl; + } else { + res.append( Entry( a, email ) ); + } + } + return res; +} + +TQStringList KPIM::DistributionList::emails( KABC::AddressBook* book ) const +{ + TQStringList emails; + + const TQString str = custom( "KADDRESSBOOK", s_customFieldName ); + ParseList parseList = parseCustom( str ); + for( ParseList::ConstIterator it = parseList.begin(); it != parseList.end(); ++it ) { + const TQString thisUid = (*it).first; + const TQString thisEmail = (*it).second; + + // look up contact + KABC::Addressee a = findByUidOrName( book, thisUid, thisEmail ); + if ( a.isEmpty() ) { + // ## The old DistributionListManager had a "missing entries" list... + continue; + } + + const TQString email = thisEmail.isEmpty() ? a.fullEmail() : + a.fullEmail( thisEmail ); + if ( !email.isEmpty() ) { + emails.append( email ); + } + } + + return emails; +} + +TQValueList + KPIM::DistributionList::allDistributionLists( KABC::AddressBook* book ) +{ + TQValueList lst; + KABC::AddressBook::Iterator abIt; + for ( abIt = book->begin(); abIt != book->end(); ++abIt ) + { + if ( isDistributionList( *abIt ) ) { + lst.append( KPIM::DistributionList( *abIt ) ); + } + } + return lst; +} diff --git a/libtdepim/distributionlist.h b/libtdepim/distributionlist.h new file mode 100644 index 000000000..99391fca3 --- /dev/null +++ b/libtdepim/distributionlist.h @@ -0,0 +1,140 @@ +/* + This file is part of libtdepim. + Copyright (c) 2004-2005 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef DISTRIBUTIONLIST_H +#define DISTRIBUTIONLIST_H + +#include + +namespace KABC { +class AddressBook; +} + +namespace KPIM { + +/** + * @short Distribution list of email addresses + * + * This class represents a list of email addresses. Each email address is + * associated with an address book entry. If the address book entry changes, the + * entry in the distribution list is automatically updated. + * + * This should go into kdelibs in KDE4. + * + * @author David Faure + */ +class DistributionList : public KABC::Addressee +{ + public: + /** + * @short Distribution List Entry + * + * This class represents an entry of a distribution list. It consists of an + * addressee and an email address. If the email address is null, the + * preferred email address of the addressee is used. + */ + struct Entry + { + typedef TQValueList List; + + Entry() {} + Entry( const Addressee &_addressee, const TQString &_email ) : + addressee( _addressee ), email( _email ) {} + + Addressee addressee; + TQString email; + }; + + typedef TQValueList List; + + /** + * Create a distribution list. + */ + DistributionList(); + /** + * Create a distribution list from an addressee object + * (this is a kind of down-cast) + */ + DistributionList( const KABC::Addressee& addr ); + + /** + * Destructor. + */ + ~DistributionList() {} + + /// HACK: reimplemented from Addressee, but it's NOT virtual there + void setName( const TQString &name ); + + /// HACK: reimplemented from Addressee, but it's NOT virtual there + TQString name() const { return formattedName(); } + + /** + Insert an entry into this distribution list. If the entry already exists + nothing happens. + */ + void insertEntry( const Addressee &, const TQString &email=TQString() ); + + /** + Remove an entry from this distribution list. If the entry doesn't exist + nothing happens. + */ + void removeEntry( const Addressee &, const TQString &email=TQString() ); + + /// Overload, used by resources to avoid looking up the addressee + void insertEntry( const TQString& uid, const TQString& email=TQString() ); + /// Overload, used by resources to avoid looking up the addressee + void removeEntry( const TQString& uid, const TQString& email=TQString() ); + + + /** + Return list of email addresses, which belong to this distributon list. + These addresses can be directly used by e.g. a mail client. + @param book necessary to look up entries + */ + TQStringList emails( KABC::AddressBook* book ) const; + + /** + Return list of entries belonging to this distribution list. This function + is mainly useful for a distribution list editor. + @param book necessary to look up entries + */ + Entry::List entries( KABC::AddressBook* book ) const; + + // KDE4: should be a method of Addressee + static bool isDistributionList( const KABC::Addressee& addr ); + + // KDE4: should be a method of AddressBook + static DistributionList findByName( KABC::AddressBook* book, + const TQString& name, + bool caseSensitive = true ); + // KDE4: should be a method of AddressBook + // A bit slow (but no more than findByName). + // From KAddressbook, use Core::distributionLists() instead. + static TQValueList allDistributionLists( KABC::AddressBook* book ); + + + private: + // can't have any data here, use Addressee's methods instead +}; + +} + +#endif /* DISTRIBUTIONLIST_H */ + diff --git a/libtdepim/embeddedurlpage.cpp b/libtdepim/embeddedurlpage.cpp new file mode 100644 index 000000000..3971bf367 --- /dev/null +++ b/libtdepim/embeddedurlpage.cpp @@ -0,0 +1,71 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2005 Reinhold Kainhofer + Part of loadContents() copied from the kpartsdesignerplugin: + Copyright (C) 2005, David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "embeddedurlpage.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace KPIM; + +EmbeddedURLPage::EmbeddedURLPage( const TQString &url, const TQString &mimetype, + TQWidget *parent, const char *name ) + : TQWidget( parent, name ), mUri(url), mMimeType( mimetype ), mPart( 0 ) +{ + initGUI( url, mimetype ); +} + +void EmbeddedURLPage::initGUI( const TQString &url, const TQString &/*mimetype*/ ) +{ + TQVBoxLayout *tqlayout = new TQVBoxLayout( this ); + tqlayout->setAutoAdd( true ); + new TQLabel( i18n("Showing URL %1").tqarg( url ), this ); +} + +void EmbeddedURLPage::loadContents() +{ + if ( !mPart ) { + if ( mMimeType.isEmpty() || mUri.isEmpty() ) + return; + TQString mimetype = mMimeType; + if ( mimetype == "auto" ) + mimetype == KMimeType::findByURL( mUri )->name(); + // "this" is both the parent widget and the parent object + mPart = KParts::ComponentFactory::createPartInstanceFromQuery( mimetype, TQString(), TQT_TQWIDGET(this), 0, TQT_TQOBJECT(this), 0 ); + if ( mPart ) { + mPart->openURL( mUri ); + mPart->widget()->show(); + } +//void KParts::BrowserExtension::openURLRequestDelayed( const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() ) + KParts::BrowserExtension* be = KParts::BrowserExtension::childObject( mPart ); + connect( be, TQT_SIGNAL( openURLRequestDelayed( const KURL &, const KParts::URLArgs & ) ), +// mPart, TQT_SLOT( openURL( const KURL & ) ) ); + this, TQT_SIGNAL( openURL( const KURL & ) ) ); + } +} + +#include "embeddedurlpage.moc" diff --git a/libtdepim/embeddedurlpage.h b/libtdepim/embeddedurlpage.h new file mode 100644 index 000000000..c306466cd --- /dev/null +++ b/libtdepim/embeddedurlpage.h @@ -0,0 +1,54 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2005 Reinhold Kainhofer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KPIM_EMBEDDEDURLPAGE_H +#define KPIM_EMBEDDEDURLPAGE_H + +#include +#include +#include + +namespace KParts { class ReadOnlyPart; } + +namespace KPIM { + +class KDE_EXPORT EmbeddedURLPage : public TQWidget +{ + Q_OBJECT + TQ_OBJECT + public: + EmbeddedURLPage( const TQString &url, const TQString &mimetype, + TQWidget *parent, const char *name = 0 ); + + public slots: + void loadContents(); + signals: + void openURL( const KURL &url ); + private: + void initGUI( const TQString &url, const TQString &mimetype ); + + TQString mUri; + TQString mMimeType; + KParts::ReadOnlyPart* mPart; +}; + +} + +#endif diff --git a/libtdepim/groupwarejob.cpp b/libtdepim/groupwarejob.cpp new file mode 100644 index 000000000..bd413e12b --- /dev/null +++ b/libtdepim/groupwarejob.cpp @@ -0,0 +1,47 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "groupwarejob.h" + +#include +#include + +using namespace KIO; + +KIO::TransferJob *GroupwareJob::getCalendar( const KURL &u ) +{ + KURL url = u; + url.setPath( "/calendar/" ); + + kdDebug() << "GroupwareJob::getCalendar(): URL: " << url << endl; + + return KIO::get( url, false, false ); +} + +KIO::TransferJob *GroupwareJob::getAddressBook( const KURL &u ) +{ + KURL url = u; + url.setPath( "/addressbook/" ); + + kdDebug() << "GroupwareJob::getAddressBook(): URL: " << url << endl; + + return KIO::get( url, false, false ); +} diff --git a/libtdepim/groupwarejob.h b/libtdepim/groupwarejob.h new file mode 100644 index 000000000..bf5a33f6e --- /dev/null +++ b/libtdepim/groupwarejob.h @@ -0,0 +1,37 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KIO_GROUPWAREJOB_H +#define KIO_GROUPWAREJOB_H + +#include + +namespace KIO { + +class GroupwareJob +{ + public: + static KIO::TransferJob *getCalendar( const KURL & ); + static KIO::TransferJob *getAddressBook( const KURL & ); +}; + +} + +#endif diff --git a/libtdepim/htmldiffalgodisplay.cpp b/libtdepim/htmldiffalgodisplay.cpp new file mode 100644 index 000000000..726854e4e --- /dev/null +++ b/libtdepim/htmldiffalgodisplay.cpp @@ -0,0 +1,97 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +#include + +using namespace KPIM; + +static TQString textToHTML( const TQString &text ) +{ + return TQStyleSheet::convertFromPlainText( text ); +} + +HTMLDiffAlgoDisplay::HTMLDiffAlgoDisplay( TQWidget *parent ) + : KTextBrowser( parent ) +{ + setWrapPolicy( TQTextEdit::AtWordBoundary ); + setVScrollBarMode( TQScrollView::AlwaysOff ); + setHScrollBarMode( TQScrollView::AlwaysOff ); +} + +void HTMLDiffAlgoDisplay::begin() +{ + clear(); + mText = ""; + + mText.append( "" ); + mText.append( TQString( "" ) + .tqarg( KGlobalSettings::textColor().name() ) + .tqarg( KGlobalSettings::baseColor().name() ) ); + + mText.append( "
" ); + mText.append( TQString( "" ) + .tqarg( mLeftTitle ) + .tqarg( mRightTitle ) ); +} + +void HTMLDiffAlgoDisplay::end() +{ + mText.append( "
%1 %2
" + "" + "" ); + + setText( mText ); +} + +void HTMLDiffAlgoDisplay::setLeftSourceTitle( const TQString &title ) +{ + mLeftTitle = title; +} + +void HTMLDiffAlgoDisplay::setRightSourceTitle( const TQString &title ) +{ + mRightTitle = title; +} + +void HTMLDiffAlgoDisplay::additionalLeftField( const TQString &id, const TQString &value ) +{ + mText.append( TQString( "%1:%2" ) + .tqarg( id ) + .tqarg( textToHTML( value ) ) ); +} + +void HTMLDiffAlgoDisplay::additionalRightField( const TQString &id, const TQString &value ) +{ + mText.append( TQString( "%1:%2" ) + .tqarg( id ) + .tqarg( textToHTML( value ) ) ); +} + +void HTMLDiffAlgoDisplay::conflictField( const TQString &id, const TQString &leftValue, + const TQString &rightValue ) +{ + mText.append( TQString( "%1:%2%3" ) + .tqarg( id ) + .tqarg( textToHTML( leftValue ) ) + .tqarg( textToHTML( rightValue ) ) ); +} diff --git a/libtdepim/htmldiffalgodisplay.h b/libtdepim/htmldiffalgodisplay.h new file mode 100644 index 000000000..35d95f5c8 --- /dev/null +++ b/libtdepim/htmldiffalgodisplay.h @@ -0,0 +1,54 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KPIM_HTMLDIFFALGODISPLAY_H +#define KPIM_HTMLDIFFALGODISPLAY_H + +#include "diffalgo.h" + +#include +#include + +namespace KPIM { + +class KDE_EXPORT HTMLDiffAlgoDisplay : virtual public DiffAlgoDisplay, public KTextBrowser +{ + public: + HTMLDiffAlgoDisplay( TQWidget *parent ); + + void begin(); + void end(); + void setLeftSourceTitle( const TQString &title ); + void setRightSourceTitle( const TQString &title ); + void additionalLeftField( const TQString &id, const TQString &value ); + void additionalRightField( const TQString &id, const TQString &value ); + void conflictField( const TQString &id, const TQString &leftValue, + const TQString &rightValue ); + + private: + TQString mLeftTitle; + TQString mRightTitle; + TQString mText; +}; + +} + +#endif diff --git a/libtdepim/icons/CMakeLists.txt b/libtdepim/icons/CMakeLists.txt new file mode 100644 index 000000000..189a3a200 --- /dev/null +++ b/libtdepim/icons/CMakeLists.txt @@ -0,0 +1,12 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +tde_install_icons() diff --git a/libtdepim/icons/Makefile.am b/libtdepim/icons/Makefile.am new file mode 100644 index 000000000..2e31aecbf --- /dev/null +++ b/libtdepim/icons/Makefile.am @@ -0,0 +1,2 @@ +KDE_ICON=AUTO + diff --git a/libtdepim/icons/cr22-action-button_fewer.png b/libtdepim/icons/cr22-action-button_fewer.png new file mode 100644 index 000000000..96919575a Binary files /dev/null and b/libtdepim/icons/cr22-action-button_fewer.png differ diff --git a/libtdepim/icons/cr22-action-button_more.png b/libtdepim/icons/cr22-action-button_more.png new file mode 100644 index 000000000..31c064ba9 Binary files /dev/null and b/libtdepim/icons/cr22-action-button_more.png differ diff --git a/libtdepim/infoextension.cpp b/libtdepim/infoextension.cpp new file mode 100644 index 000000000..25f7e8ba7 --- /dev/null +++ b/libtdepim/infoextension.cpp @@ -0,0 +1,38 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2003 Sven Lüppken + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + #include "infoextension.h" + +#include +#include + +using namespace KParts; + +InfoExtension::InfoExtension( KParts::ReadOnlyPart *parent, const char* name) +: TQObject(parent, name), d(0) +{ +} + +InfoExtension::~InfoExtension() +{ +} + +#include "infoextension.moc" diff --git a/libtdepim/infoextension.h b/libtdepim/infoextension.h new file mode 100644 index 000000000..b857dc4a5 --- /dev/null +++ b/libtdepim/infoextension.h @@ -0,0 +1,62 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2003 Sven Lüppken + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef INFOEXTENSION_H +#define INFOEXTENSION_H + +#include +#include + +class TQWidget; + +namespace KParts +{ + + class ReadOnlyPart; + + /** + * Provides a way to get information out of a PIM-Part + **/ + class KDE_EXPORT InfoExtension : public TQObject + { + Q_OBJECT + TQ_OBJECT + + public: + /** + * Constucts an InfoExtension. + * + * @param parent The parent widget. + * @param name The name of the class. + **/ + InfoExtension( KParts::ReadOnlyPart *parent, const char* name); + ~InfoExtension(); + + private: + class InfoExtensionPrivate; + InfoExtensionPrivate *d; + + signals: + void textChanged( const TQString& ); + void iconChanged( const TQPixmap& ); + }; +} +#endif // INFOEXTENSION_H diff --git a/libtdepim/interfaces/AddressBookServiceIface.h b/libtdepim/interfaces/AddressBookServiceIface.h new file mode 100644 index 000000000..e07ac3e76 --- /dev/null +++ b/libtdepim/interfaces/AddressBookServiceIface.h @@ -0,0 +1,59 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef ADDRESSBOOKSERVICEIFACE_H +#define ADDRESSBOOKSERVICEIFACE_H + +#include +#include +#include +#include +#include +#include + +namespace KPIM { + +#define AddressBookServiceIface KDE_EXPORT AddressBookServiceIface + class AddressBookServiceIface : virtual public DCOPObject +#undef AddressBookServiceIface + { + K_DCOP + + k_dcop: + /** + This method will add a vcard to the address book. + + @param vCard The vCard in string representation. + */ + virtual void importVCardFromData( const TQString& vCard ) = 0; + + /** + This method will add a vcard to the address book. + + @param url The url where the vcard is located. + */ + virtual void importVCard( const KURL& url ) = 0; + }; + +} + +#endif + diff --git a/libtdepim/interfaces/MailTransportServiceIface.h b/libtdepim/interfaces/MailTransportServiceIface.h new file mode 100644 index 000000000..d256775a3 --- /dev/null +++ b/libtdepim/interfaces/MailTransportServiceIface.h @@ -0,0 +1,93 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Daniel Molkentin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef MAILTRANSPORTSERVICEIFACE_H +#define MAILTRANSPORTSERVICEIFACE_H + +#include +#include +#include +#include +#include + +#include + +namespace KPim { + +#define MailTransportServiceIface KDE_EXPORT MailTransportServiceIface + class MailTransportServiceIface : virtual public DCOPObject +#undef MailTransportServiceIface + { + K_DCOP + + k_dcop: + /** + * This method will compose a message and send it using the mailers + * preferred transport. The mimetype of the attachments passed is + * determined using mime magic. + * + * @return true when the message was send successfully, false on failure. + **/ + virtual bool sendMessage( const TQString& from, const TQString& to, + const TQString& cc, const TQString& bcc, + const TQString& subject, const TQString& body, + const KURL::List& attachments ) = 0; + + /** + * This method basically behaves like the one above, but takes only one + * attachment as TQByteArray. This is useful if you want to attach simple + * text files (e.g. a vCalendar). The mimetype is determined using + * mime magic. + * + * @return true when the message was send successfully, false on failure. + **/ + virtual bool sendMessage( const TQString& from, const TQString& to, + const TQString& cc, const TQString& bcc, + const TQString& subject, const TQString& body, + const TQByteArray& attachment ) = 0; + + k_dcop_hidden: + /** + * This method is deprecated. Use the corresponding method with the + * additional parameter from instead. + **/ + // FIXME KDE 4.0: Remove this. + virtual bool sendMessage( const TQString& to, + const TQString& cc, const TQString& bcc, + const TQString& subject, const TQString& body, + const KURL::List& attachments ) = 0; + + /** + * This method is deprecated. Use the corresponding method with the + * additional parameter from instead. + **/ + // FIXME KDE 4.0: Remove this. + virtual bool sendMessage( const TQString& to, + const TQString& cc, const TQString& bcc, + const TQString& subject, const TQString& body, + const TQByteArray& attachment ) = 0; + + }; + +} + +#endif // MAILTRANSPORTSERVICEIFACE_H + diff --git a/libtdepim/interfaces/Makefile.am b/libtdepim/interfaces/Makefile.am new file mode 100644 index 000000000..e69de29bb diff --git a/libtdepim/kabcresourcecached.cpp b/libtdepim/kabcresourcecached.cpp new file mode 100644 index 000000000..eece76351 --- /dev/null +++ b/libtdepim/kabcresourcecached.cpp @@ -0,0 +1,417 @@ +/* + This file is part of libtdepim. + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "kabcresourcecached.h" + +using namespace KABC; + +ResourceCached::ResourceCached( const KConfig *config ) + : KABC::Resource( config ), mIdMapper( "kabc/uidmaps/" ), + mReloadPolicy( ReloadInterval ), mReloadInterval( 10 ), + mKABCReloadTimer( 0, "mKABCReloadTimer" ), mReloaded( false ), + mSavePolicy( SaveDelayed ), mSaveInterval( 10 ), + mKABCSaveTimer( 0, "mKABCSaveTimer" ) +{ + connect( &mKABCReloadTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotKABCReload() ) ); + connect( &mKABCSaveTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotKABCSave() ) ); + + if (config) + this->readConfig(const_cast(config)); +} + +ResourceCached::~ResourceCached() +{ +} + +void ResourceCached::setReloadPolicy( int i ) +{ + mReloadPolicy = i; + + setupReloadTimer(); +} + +int ResourceCached::reloadPolicy() const +{ + return mReloadPolicy; +} + +void ResourceCached::setReloadInterval( int minutes ) +{ + mReloadInterval = minutes; +} + +int ResourceCached::reloadInterval() const +{ + return mReloadInterval; +} + +void ResourceCached::setSavePolicy( int i ) +{ + mSavePolicy = i; + + setupSaveTimer(); +} + +int ResourceCached::savePolicy() const +{ + return mSavePolicy; +} + +void ResourceCached::setSaveInterval( int minutes ) +{ + mSaveInterval = minutes; +} + +int ResourceCached::saveInterval() const +{ + return mSaveInterval; +} + +void ResourceCached::writeConfig( KConfig *config ) +{ + config->writeEntry( "ReloadPolicy", mReloadPolicy ); + config->writeEntry( "ReloadInterval", mReloadInterval ); + + config->writeEntry( "SavePolicy", mSavePolicy ); + config->writeEntry( "SaveInterval", mSaveInterval ); + + config->writeEntry( "LastLoad", mLastLoad ); + config->writeEntry( "LastSave", mLastSave ); + + KABC::Resource::writeConfig( config ); +} + +void ResourceCached::readConfig( KConfig *config ) +{ + mReloadPolicy = config->readNumEntry( "ReloadPolicy", ReloadNever ); + mReloadInterval = config->readNumEntry( "ReloadInterval", 10 ); + + mSaveInterval = config->readNumEntry( "SaveInterval", 10 ); + mSavePolicy = config->readNumEntry( "SavePolicy", SaveNever ); + + mLastLoad = config->readDateTimeEntry( "LastLoad" ); + mLastSave = config->readDateTimeEntry( "LastSave" ); + + setupSaveTimer(); + setupReloadTimer(); +} + +void ResourceCached::setupSaveTimer() +{ + if ( mSavePolicy == SaveInterval ) { + kdDebug(5800) << "ResourceCached::setSavePolicy(): start save timer (interval " + << mSaveInterval << " minutes)." << endl; + mKABCSaveTimer.start( mSaveInterval * 60 * 1000 ); // n minutes + } else { + mKABCSaveTimer.stop(); + } +} + +void ResourceCached::setupReloadTimer() +{ + if ( mReloadPolicy == ReloadInterval ) { + kdDebug(5800) << "ResourceCached::setSavePolicy(): start reload timer " + "(interval " << mReloadInterval << " minutes)" << endl; + mKABCReloadTimer.start( mReloadInterval * 60 * 1000 ); // n minutes + } else { + mKABCReloadTimer.stop(); + } +} + +void ResourceCached::slotKABCReload() +{ + if ( !isActive() ) return; + + kdDebug(5800) << "ResourceCached::slotKABCReload()" << endl; + + load(); +} + +void ResourceCached::slotKABCSave() +{ + if ( !isActive() ) return; + + kdDebug(5800) << "ResourceCached::slotKABCSave()" << endl; + + KABC::Ticket *ticket = requestSaveTicket(); + if ( ticket ) { + save( ticket ); + } +} + +void ResourceCached::insertAddressee( const Addressee &addr ) +{ + if ( !mAddrMap.contains( addr.uid() ) ) { // new contact + if ( mDeletedAddressees.contains( addr.uid() ) ) { + // it was first removed, then added, so it's an update... + mDeletedAddressees.remove( addr.uid() ); + + mAddrMap.insert( addr.uid(), addr ); + mChangedAddressees.insert( addr.uid(), addr ); + return; + } + + mAddrMap.insert( addr.uid(), addr ); + mAddedAddressees.insert( addr.uid(), addr ); + } else { + KABC::Addressee oldAddressee = mAddrMap.find( addr.uid() ).data(); + if ( oldAddressee != addr ) { + mAddrMap.remove( addr.uid() ); + mAddrMap.insert( addr.uid(), addr ); + mChangedAddressees.insert( addr.uid(), addr ); + } + } +} + +void ResourceCached::removeAddressee( const Addressee &addr ) +{ + if ( mAddedAddressees.contains( addr.uid() ) ) { + mAddedAddressees.remove( addr.uid() ); + return; + } + + if ( mDeletedAddressees.find( addr.uid() ) == mDeletedAddressees.end() ) + mDeletedAddressees.insert( addr.uid(), addr ); + + mAddrMap.remove( addr.uid() ); +} + +void ResourceCached::loadCache() +{ + mAddrMap.clear(); + + setIdMapperIdentifier(); + mIdMapper.load(); + + // load cache + TQFile file( cacheFile() ); + if ( !file.open( IO_ReadOnly ) ) + return; + + + KABC::VCardConverter converter; +#if defined(KABC_VCARD_ENCODING_FIX) + KABC::Addressee::List list = converter.parseVCardsRaw( file.readAll().data() ); +#else + KABC::Addressee::List list = converter.parseVCards( TQString::fromUtf8( file.readAll() ) ); +#endif + KABC::Addressee::List::Iterator it; + + for ( it = list.begin(); it != list.end(); ++it ) { + (*it).setResource( this ); + (*it).setChanged( false ); + mAddrMap.insert( (*it).uid(), *it ); + } + + file.close(); +} + +void ResourceCached::saveCache() +{ + setIdMapperIdentifier(); + mIdMapper.save(); + + // save cache + TQFile file( cacheFile() ); + if ( !file.open( IO_WriteOnly ) ) + return; + + KABC::Addressee::List list = mAddrMap.values(); + + KABC::VCardConverter converter; +#if defined(KABC_VCARD_ENCODING_FIX) + TQCString vCard = converter.createVCardsRaw( list ); + file.writeBlock( vCard, vCard.length() ); +#else + TQString vCard = converter.createVCards( list ); + file.writeBlock( vCard.utf8(), vCard.utf8().length() ); +#endif + file.close(); +} + +void ResourceCached::clearCache() +{ + // TEST ME + mAddrMap.clear(); +} + +void ResourceCached::cleanUpCache( const KABC::Addressee::List &addrList ) +{ + // load cache + TQFile file( cacheFile() ); + if ( !file.open( IO_ReadOnly ) ) + return; + + + KABC::VCardConverter converter; +#if defined(KABC_VCARD_ENCODING_FIX) + KABC::Addressee::List list = converter.parseVCardsRaw( file.readAll().data() ); +#else + KABC::Addressee::List list = converter.parseVCards( TQString::fromUtf8( file.readAll() ) ); +#endif + KABC::Addressee::List::Iterator cacheIt; + KABC::Addressee::List::ConstIterator it; + + for ( cacheIt = list.begin(); cacheIt != list.end(); ++cacheIt ) { + bool found = false; + for ( it = addrList.begin(); it != addrList.end(); ++it ) { + if ( (*it).uid() == (*cacheIt).uid() ) + found = true; + } + + if ( !found ) { + mIdMapper.removeRemoteId( mIdMapper.remoteId( (*cacheIt).uid() ) ); + mAddrMap.remove( (*cacheIt).uid() ); + } + } + + file.close(); +} + +KPIM::IdMapper& ResourceCached::idMapper() +{ + return mIdMapper; +} + +bool ResourceCached::hasChanges() const +{ + return !( mAddedAddressees.isEmpty() && + mChangedAddressees.isEmpty() && + mDeletedAddressees.isEmpty() ); +} + +void ResourceCached::clearChanges() +{ + mAddedAddressees.clear(); + mChangedAddressees.clear(); + mDeletedAddressees.clear(); +} + +void ResourceCached::clearChange( const KABC::Addressee &addr ) +{ + mAddedAddressees.remove( addr.uid() ); + mChangedAddressees.remove( addr.uid() ); + mDeletedAddressees.remove( addr.uid() ); +} + +void ResourceCached::clearChange( const TQString &uid ) +{ + mAddedAddressees.remove( uid ); + mChangedAddressees.remove( uid ); + mDeletedAddressees.remove( uid ); +} + +KABC::Addressee::List ResourceCached::addedAddressees() const +{ + return mAddedAddressees.values(); +} + +KABC::Addressee::List ResourceCached::changedAddressees() const +{ + return mChangedAddressees.values(); +} + +KABC::Addressee::List ResourceCached::deletedAddressees() const +{ + return mDeletedAddressees.values(); +} + +TQString ResourceCached::cacheFile() const +{ + return locateLocal( "cache", "kabc/kresources/" + identifier() ); +} + +TQString ResourceCached::changesCacheFile( const TQString &type ) const +{ + return locateLocal( "cache", "kabc/changescache/" + identifier() + "_" + type ); +} + +void ResourceCached::saveChangesCache( const TQMap &map, const TQString &type ) +{ + TQFile file( changesCacheFile( type ) ); + + const KABC::Addressee::List list = map.values(); + if ( list.isEmpty() ) { + file.remove(); + } else { + if ( !file.open( IO_WriteOnly ) ) { + kdError() << "Can't open changes cache file '" << file.name() << "' for saving." << endl; + return; + } + + KABC::VCardConverter converter; +#if defined(KABC_VCARD_ENCODING_FIX) + const TQCString vCards = converter.createVCardsRaw( list ); + file.writeBlock( vCards, vCards.length() ); +#else + const TQString vCards = converter.createVCards( list ); + TQCString content = vCards.utf8(); + file.writeBlock( content, content.length() ); +#endif + } +} + +void ResourceCached::saveChangesCache() +{ + saveChangesCache( mAddedAddressees, "added" ); + saveChangesCache( mDeletedAddressees, "deleted" ); + saveChangesCache( mChangedAddressees, "changed" ); +} + +void ResourceCached::loadChangesCache( TQMap &map, const TQString &type ) +{ + TQFile file( changesCacheFile( type ) ); + if ( !file.open( IO_ReadOnly ) ) + return; + + KABC::VCardConverter converter; + +#if defined(KABC_VCARD_ENCODING_FIX) + const KABC::Addressee::List list = converter.parseVCardsRaw( file.readAll().data() ); +#else + const KABC::Addressee::List list = converter.parseVCards( TQString::fromUtf8( file.readAll() ) ); +#endif + KABC::Addressee::List::ConstIterator it; + for ( it = list.begin(); it != list.end(); ++it ) + map.insert( (*it).uid(), *it ); + + file.close(); +} + +void ResourceCached::loadChangesCache() +{ + loadChangesCache( mAddedAddressees, "added" ); + loadChangesCache( mDeletedAddressees, "deleted" ); + loadChangesCache( mChangedAddressees, "changed" ); +} + +void ResourceCached::setIdMapperIdentifier() +{ + mIdMapper.setIdentifier( type() + "_" + identifier() ); +} + +#include "kabcresourcecached.moc" diff --git a/libtdepim/kabcresourcecached.h b/libtdepim/kabcresourcecached.h new file mode 100644 index 000000000..2cf0352ef --- /dev/null +++ b/libtdepim/kabcresourcecached.h @@ -0,0 +1,195 @@ +/* + This file is part of libtdepim. + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KABC_RESOURCECACHED_H +#define KABC_RESOURCECACHED_H + +#include +#include + +#include +#include + +#include "libemailfunctions/idmapper.h" + +namespace KABC { + +class KDE_EXPORT ResourceCached : public Resource +{ + Q_OBJECT + TQ_OBJECT + + public: + /** + Reload policy. + + @see setReloadPolicy(), reloadPolicy() + */ + enum { ReloadNever, ReloadOnStartup, ReloadInterval }; + /** + Save policy. + + @see setSavePolicy(), savePolicy() + */ + enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways }; + + ResourceCached( const KConfig* ); + ~ResourceCached(); + + /** + Set reload policy. This controls when the cache is refreshed. + + ReloadNever never reload + ReloadOnStartup reload when resource is started + ReloadInterval reload regularly after given interval + */ + void setReloadPolicy( int policy ); + /** + Return reload policy. + + @see setReloadPolicy() + */ + int reloadPolicy() const; + + /** + Set reload interval in minutes which is used when reload policy is + ReloadInterval. + */ + void setReloadInterval( int minutes ); + + /** + Return reload interval in minutes. + */ + int reloadInterval() const; + + /** + Set save policy. This controls when the cache is refreshed. + + SaveNever never save + SaveOnExit save when resource is exited + SaveInterval save regularly after given interval + SaveDelayed save after small delay + SaveAlways save on every change + */ + void setSavePolicy( int policy ); + /** + Return save policy. + + @see setsavePolicy() + */ + int savePolicy() const; + + /** + Set save interval in minutes which is used when save policy is + SaveInterval. + */ + void setSaveInterval( int minutes ); + + /** + Return save interval in minutes. + */ + int saveInterval() const; + + void setupSaveTimer(); + void setupReloadTimer(); + + /** + Reads the resource specific config from disk. + */ + virtual void readConfig( KConfig *config ); + + /** + Writes the resource specific config to disk. + */ + virtual void writeConfig( KConfig *config ); + + /** + Insert an addressee into the resource. + */ + virtual void insertAddressee( const Addressee& ); + + /** + Removes an addressee from resource. + */ + virtual void removeAddressee( const Addressee& addr ); + + void loadCache(); + void saveCache(); + void clearCache(); + void cleanUpCache( const KABC::Addressee::List &list ); + + /** + Returns a reference to the id mapper. + */ + KPIM::IdMapper& idMapper(); + + bool hasChanges() const; + void clearChanges(); + void clearChange( const KABC::Addressee& ); + void clearChange( const TQString& ); + + KABC::Addressee::List addedAddressees() const; + KABC::Addressee::List changedAddressees() const; + KABC::Addressee::List deletedAddressees() const; + + protected: + virtual TQString cacheFile() const; + + /** + Functions for keeping the changes persistent. + */ + virtual TQString changesCacheFile( const TQString& ) const; + void loadChangesCache( TQMap&, const TQString& ); + void loadChangesCache(); + void saveChangesCache( const TQMap&, const TQString& ); + void saveChangesCache(); + + void setIdMapperIdentifier(); + + private: + TQMap mAddedAddressees; + TQMap mChangedAddressees; + TQMap mDeletedAddressees; + + KPIM::IdMapper mIdMapper; + + class ResourceCachedPrivate; + ResourceCachedPrivate *d; + + int mReloadPolicy; + int mReloadInterval; + TQTimer mKABCReloadTimer; + bool mReloaded; + + int mSavePolicy; + int mSaveInterval; + TQTimer mKABCSaveTimer; + + TQDateTime mLastLoad; + TQDateTime mLastSave; + + protected slots: + void slotKABCReload(); + void slotKABCSave(); +}; + +} + +#endif diff --git a/libtdepim/kabcresourcenull.h b/libtdepim/kabcresourcenull.h new file mode 100644 index 000000000..7d77b89b7 --- /dev/null +++ b/libtdepim/kabcresourcenull.h @@ -0,0 +1,46 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KABC_RESOURCENULL_H +#define KABC_RESOURCENULL_H + +#include + +namespace KABC { + +/** + This resource does nothing. +*/ +class ResourceNull : public Resource +{ + public: + ResourceNull( const KConfig *cfg ) : Resource( cfg ) {} + ResourceNull() : Resource( 0 ) {} + virtual ~ResourceNull() {} + + Ticket *requestSaveTicket() { return 0; } + void releaseSaveTicket( Ticket * ) {} + bool load() { return false; } + bool save( Ticket * ) { return false; } +}; + +} + +#endif diff --git a/libtdepim/kaccount.cpp b/libtdepim/kaccount.cpp new file mode 100644 index 000000000..392fea265 --- /dev/null +++ b/libtdepim/kaccount.cpp @@ -0,0 +1,62 @@ +/* -*- c++ -*- + kaccount.cpp + + This file is part of KMail, the KDE mail client. + + Copyright (C) 2002 Carsten Burghardt + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 "kaccount.h" + +#include + +KAccount::KAccount( const uint id, const TQString &name, const Type type ) + : mId( id ), mName( name ), mType( type ) +{ +} + +void KAccount::writeConfig( KConfig &config, const TQString &group ) +{ + TQString oldGroup = config.group(); + if (!group.isEmpty()) + config.setGroup(group); + config.writeEntry("Id", mId); + config.writeEntry("Name", mName); + if (!group.isEmpty()) // restore + config.setGroup(oldGroup); +} + +void KAccount::readConfig( KConfig &config, const TQString &group ) +{ + TQString oldGroup = config.group(); + if (!group.isEmpty()) + config.setGroup(group); + mId = config.readUnsignedNumEntry("Id", 0); + mName = config.readEntry("Name"); + if (!group.isEmpty()) // restore + config.setGroup(oldGroup); +} diff --git a/libtdepim/kaccount.h b/libtdepim/kaccount.h new file mode 100644 index 000000000..d0a1b7f21 --- /dev/null +++ b/libtdepim/kaccount.h @@ -0,0 +1,92 @@ +/* -*- c++ -*- + kaccount.h + + This file is part of KMail, the KDE mail client. + Copyright (C) 2002 Carsten Burghardt + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 __KACCOUNT +#define __KACCOUNT + +#include +#include + +class KConfig; + +class KDE_EXPORT KAccount +{ + public: + /** Type information */ + enum Type { + Imap, + MBox, + Maildir, + News, + DImap, + Other + }; + + KAccount( const uint id = 0, const TQString &name = TQString(), + const Type type = Other ); + + /** + * Get/Set name + */ + TQString name() const { return mName; } + void setName( const TQString& name ) { mName = name; } + + /** + * Get/Set id + */ + uint id() const { return mId; } + void setId( const uint id ) { mId = id; } + + /** + * Get/Set type + */ + Type type() const { return mType; } + void setType( const Type type ) { mType = type; } + + /** + * Save the settings + * If the group is empty it must be preset in the KConfig + */ + void writeConfig( KConfig &config, const TQString &group = TQString() ); + + /** + * Read the settings + * If the group is empty it must be preset in the KConfig + */ + void readConfig( KConfig &config, const TQString &group = TQString() ); + + protected: + uint mId; + TQString mName; + Type mType; +}; + +#endif diff --git a/libtdepim/kaddrbook.cpp b/libtdepim/kaddrbook.cpp new file mode 100644 index 000000000..1036a263b --- /dev/null +++ b/libtdepim/kaddrbook.cpp @@ -0,0 +1,285 @@ +// -*- mode: C++; c-file-style: "gnu" -*- +// kaddrbook.cpp +// Author: Stefan Taferner +// This code is under GPL + +#include + +#include "kaddrbook.h" + +#ifdef KDEPIM_NEW_DISTRLISTS +#include "distributionlist.h" +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +//----------------------------------------------------------------------------- +void KAddrBookExternal::openEmail( const TQString &addr, TQWidget *parent ) { + TQString email; + TQString name; + + KABC::Addressee::parseEmailAddress( addr, name, email ); + + KABC::AddressBook *ab = KABC::StdAddressBook::self( true ); + + // force a reload of the address book file so that changes that were made + // by other programs are loaded + ab->asyncLoad(); + + // if we have to reload the address book then we should also wait until + // it's completely reloaded +#if KDE_IS_VERSION(3,4,89) + // This ugly hack will be removed in 4.0 + while ( !ab->loadingHasFinished() ) { + TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput ); + + // use sleep here to reduce cpu usage + usleep( 100 ); + } +#endif + + KABC::Addressee::List addressees = ab->findByEmail( email ); + + if ( addressees.count() > 0 ) { + if ( kapp->dcopClient()->isApplicationRegistered( "kaddressbook" ) ){ + //make sure kaddressbook is loaded, otherwise showContactEditor + //won't work as desired, see bug #87233 + DCOPRef call ( "kaddressbook", "kaddressbook" ); + call.send( "newInstance()" ); + } else { + kapp->startServiceByDesktopName( "kaddressbook" ); + } + + DCOPRef call( "kaddressbook", "KAddressBookIface" ); + call.send( "showContactEditor(TQString)", addressees.first().uid() ); + } else { + //TODO: Enable the better message at the next string unfreeze +#if 0 + TQString text = i18n("The email address %1 cannot be " + "found in your addressbook.").tqarg( email ); +#else + TQString text = email + " " + i18n( "is not in address book" ); +#endif + KMessageBox::information( parent, text, TQString(), "notInAddressBook" ); + } +} + +//----------------------------------------------------------------------------- +void KAddrBookExternal::addEmail( const TQString& addr, TQWidget *parent) { + TQString email; + TQString name; + + KABC::Addressee::parseEmailAddress( addr, name, email ); + + KABC::AddressBook *ab = KABC::StdAddressBook::self( true ); + + ab->setErrorHandler( new KABC::GuiErrorHandler( parent ) ); + + // force a reload of the address book file so that changes that were made + // by other programs are loaded + ab->asyncLoad(); + + // if we have to reload the address book then we should also wait until + // it's completely reloaded +#if KDE_IS_VERSION(3,4,89) + // This ugly hack will be removed in 4.0 + while ( !ab->loadingHasFinished() ) { + TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput ); + + // use sleep here to reduce cpu usage + usleep( 100 ); + } +#endif + + KABC::Addressee::List addressees = ab->findByEmail( email ); + + if ( addressees.isEmpty() ) { + KABC::Addressee a; + a.setNameFromString( name ); + a.insertEmail( email, true ); + + { + KConfig config( "kaddressbookrc" ); + config.setGroup( "General" ); + int type = config.readNumEntry( "FormattedNameType", 1 ); + + TQString name; + switch ( type ) { + case 1: + name = a.givenName() + " " + a.familyName(); + break; + case 2: + name = a.assembledName(); + break; + case 3: + name = a.familyName() + ", " + a.givenName(); + break; + case 4: + name = a.familyName() + " " + a.givenName(); + break; + case 5: + name = a.organization(); + break; + default: + name = ""; + break; + } + name.simplifyWhiteSpace(); + + a.setFormattedName( name ); + } + + if ( KAddrBookExternal::addAddressee( a ) ) { + TQString text = i18n("The email address %1 was added to your " + "addressbook; you can add more information to this " + "entry by opening the addressbook.").tqarg( addr ); + KMessageBox::information( parent, text, TQString(), "addedtokabc" ); + } + } else { + TQString text = i18n("The email address %1 is already in your " + "addressbook.").tqarg( addr ); + KMessageBox::information( parent, text, TQString(), + "alreadyInAddressBook" ); + } + ab->setErrorHandler( 0 ); +} + +void KAddrBookExternal::openAddressBook(TQWidget *) { + kapp->startServiceByDesktopName( "kaddressbook" ); +} + +void KAddrBookExternal::addNewAddressee( TQWidget* ) +{ + kapp->startServiceByDesktopName("kaddressbook"); + DCOPRef call("kaddressbook", "KAddressBookIface"); + call.send("newContact()"); +} + +bool KAddrBookExternal::addVCard( const KABC::Addressee& addressee, TQWidget *parent ) +{ + KABC::AddressBook *ab = KABC::StdAddressBook::self( true ); + bool inserted = false; + + ab->setErrorHandler( new KABC::GuiErrorHandler( parent ) ); + + KABC::Addressee::List addressees = + ab->findByEmail( addressee.preferredEmail() ); + + if ( addressees.isEmpty() ) { + if ( KAddrBookExternal::addAddressee( addressee ) ) { + TQString text = i18n("The VCard was added to your addressbook; " + "you can add more information to this " + "entry by opening the addressbook."); + KMessageBox::information( parent, text, TQString(), "addedtokabc" ); + inserted = true; + } + } else { + TQString text = i18n("The VCard's primary email address is already in " + "your addressbook; however, you may save the VCard " + "into a file and import it into the addressbook " + "manually."); + KMessageBox::information( parent, text ); + inserted = true; + } + + ab->setErrorHandler( 0 ); + return inserted; +} + +bool KAddrBookExternal::addAddressee( const KABC::Addressee& addr ) +{ + KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); + KABC::Resource *kabcResource = selectResourceForSaving( addressBook ); + if( !kabcResource ) + return false; + KABC::Ticket *ticket = addressBook->requestSaveTicket( kabcResource ); + bool saved = false; + if ( ticket ) { + KABC::Addressee addressee( addr ); + addressee.setResource( kabcResource ); + addressBook->insertAddressee( addressee ); + saved = addressBook->save( ticket ); + if ( !saved ) + addressBook->releaseSaveTicket( ticket ); + } + + addressBook->emitAddressBookChanged(); + + return saved; +} + +TQString KAddrBookExternal::expandDistributionList( const TQString& listName ) +{ + if ( listName.isEmpty() ) + return TQString(); + + const TQString lowerListName = listName.lower(); + KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); +#ifdef KDEPIM_NEW_DISTRLISTS + KPIM::DistributionList distrList = KPIM::DistributionList::findByName( addressBook, lowerListName, false ); + if ( !distrList.isEmpty() ) { + return distrList.emails( addressBook ).join( ", " ); + } +#else + KABC::DistributionListManager manager( addressBook ); + manager.load(); + const TQStringList listNames = manager.listNames(); + + for ( TQStringList::ConstIterator it = listNames.begin(); + it != listNames.end(); ++it) { + if ( (*it).lower() == lowerListName ) { + const TQStringList addressList = manager.list( *it )->emails(); + return addressList.join( ", " ); + } + } +#endif + return TQString(); +} + +KABC::Resource* KAddrBookExternal::selectResourceForSaving( KABC::AddressBook *addressBook ) +{ +#if KDE_IS_VERSION(3,4,89) + // This ugly hack will be removed in 4.0 + while ( !addressBook->loadingHasFinished() ) { + TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput ); + + // use sleep here to reduce cpu usage + usleep( 100 ); + } +#endif + + // Select a resource + TQPtrList kabcResources = addressBook->resources(); + + TQPtrList kresResources; + TQPtrListIterator resIt( kabcResources ); + KABC::Resource *kabcResource; + while ( ( kabcResource = resIt.current() ) != 0 ) { + ++resIt; + if ( !kabcResource->readOnly() ) { + KRES::Resource *res = static_cast( kabcResource ); + if ( res ) + kresResources.append( res ); + } + } + + return static_cast( KRES::SelectDialog::getResource( kresResources, 0 ) ); +} diff --git a/libtdepim/kaddrbook.h b/libtdepim/kaddrbook.h new file mode 100644 index 000000000..f2bab1003 --- /dev/null +++ b/libtdepim/kaddrbook.h @@ -0,0 +1,45 @@ +/* Simple Addressbook for KMail + * Author: Stefan Taferner + * This code is under GPL + */ +#ifndef KAddrBook_h +#define KAddrBook_h + +#include + +#include +#include +#include + +namespace KABC { + class AddressBook; +} + +class TQWidget; + +class KDE_EXPORT KAddrBookExternal { +public: + static void addEmail( const TQString &addr, TQWidget *parent ); + static void addNewAddressee( TQWidget* ); + static void openEmail( const TQString &addr, TQWidget *parent ); + static void openAddressBook( TQWidget *parent ); + + static bool addVCard( const KABC::Addressee& addressee, TQWidget *parent ); + + static TQString expandDistributionList( const TQString& listName ); + + /** + * Pops up a dialog to ask the user to select a resource for saving something, and + * returns the selected resource or 0 on failure or if the user cancelled. + * + * The addressbook used to get the resource list from. If the addressbook was loaded + * async and loading is not yet finished, this method will run an eventloop until the + * addressbook is loaded. + */ + static KABC::Resource* selectResourceForSaving( KABC::AddressBook *addressBook ); + +private: + static bool addAddressee( const KABC::Addressee& addressee ); +}; + +#endif /*KAddrBook_h*/ diff --git a/libtdepim/kcmdesignerfields.cpp b/libtdepim/kcmdesignerfields.cpp new file mode 100644 index 000000000..870d89ce2 --- /dev/null +++ b/libtdepim/kcmdesignerfields.cpp @@ -0,0 +1,430 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + Copyright (c) 2004 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "kcmdesignerfields.h" + +using namespace KPIM; + +class PageItem : public TQCheckListItem +{ + public: + PageItem( TQListView *parent, const TQString &path ) + : TQCheckListItem( parent, "", TQCheckListItem::CheckBox ), + mPath( path ), mIsActive( false ) + { + mName = path.mid( path.findRev( '/' ) + 1 ); + + TQWidget *wdg = TQWidgetFactory::create( mPath, 0, 0 ); + if ( wdg ) { + setText( 0, wdg->caption() ); + + TQPixmap pm = TQPixmap::grabWidget( wdg ); + TQImage img = pm.convertToImage().smoothScale( 300, 300, TQ_ScaleMin ); + mPreview = img; + + TQObjectList *list = wdg->queryList( TQWIDGET_OBJECT_NAME_STRING ); + TQObjectListIt it( *list ); + + TQMap allowedTypes; + allowedTypes.insert( TQLINEEDIT_OBJECT_NAME_STRING, i18n( "Text" ) ); + allowedTypes.insert( TQTEXTEDIT_OBJECT_NAME_STRING, i18n( "Text" ) ); + allowedTypes.insert( TQSPINBOX_OBJECT_NAME_STRING, i18n( "Numeric Value" ) ); + allowedTypes.insert( TQCHECKBOX_OBJECT_NAME_STRING, i18n( "Boolean" ) ); + allowedTypes.insert( TQCOMBOBOX_OBJECT_NAME_STRING, i18n( "Selection" ) ); + allowedTypes.insert( TQDATETIMEEDIT_OBJECT_NAME_STRING, i18n( "Date & Time" ) ); + allowedTypes.insert( "KLineEdit", i18n( "Text" ) ); + allowedTypes.insert( "KDateTimeWidget", i18n( "Date & Time" ) ); + allowedTypes.insert( "KDatePicker", i18n( "Date" ) ); + + while ( it.current() ) { + if ( allowedTypes.find( it.current()->className() ) != allowedTypes.end() ) { + TQString name = it.current()->name(); + if ( name.startsWith( "X_" ) ) { + new TQListViewItem( this, name, + allowedTypes[ it.current()->className() ], + it.current()->className(), + TQWhatsThis::textFor( TQT_TQWIDGET( it.current() ) ) ); + } + } + + ++it; + } + + delete list; + } + } + + TQString name() const { return mName; } + TQString path() const { return mPath; } + + TQPixmap preview() + { + return mPreview; + } + + void setIsActive( bool isActive ) { mIsActive = isActive; } + bool isActive() const { return mIsActive; } + + protected: + void paintBranches( TQPainter *p, const TQColorGroup & cg, int w, int y, int h ) + { + TQListViewItem::paintBranches( p, cg, w, y, h ); + } + + private: + TQString mName; + TQString mPath; + TQPixmap mPreview; + bool mIsActive; +}; + +KCMDesignerFields::KCMDesignerFields( TQWidget *parent, const char *name ) + : KCModule( parent, name ) +{ + TQTimer::singleShot( 0, this, TQT_SLOT( delayedInit() ) ); + + KAboutData *about = new KAboutData( I18N_NOOP( "KCMDesignerfields" ), + I18N_NOOP( "TQt Designer Fields Dialog" ), + 0, 0, KAboutData::License_LGPL, + I18N_NOOP( "(c), 2004 Tobias Koenig" ) ); + + about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" ); + about->addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); + setAboutData( about ); +} + +void KCMDesignerFields::delayedInit() +{ + kdDebug() << "KCMDesignerFields::delayedInit()" << endl; + + initGUI(); + + connect( mPageView, TQT_SIGNAL( selectionChanged( TQListViewItem* ) ), + this, TQT_SLOT( updatePreview( TQListViewItem* ) ) ); + connect( mPageView, TQT_SIGNAL( clicked( TQListViewItem* ) ), + this, TQT_SLOT( itemClicked( TQListViewItem* ) ) ); + + connect( mDeleteButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( deleteFile() ) ); + connect( mImportButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( importFile() ) ); + connect( mDesignerButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( startDesigner() ) ); + + load(); + + // Install a dirwatcher that will detect newly created or removed designer files + KDirWatch *dw = new KDirWatch( TQT_TQOBJECT(this) ); + KStandardDirs::makeDir(localUiDir()); + dw->addDir( localUiDir(), true ); + connect( dw, TQT_SIGNAL( created(const TQString&) ), TQT_SLOT( rebuildList() ) ); + connect( dw, TQT_SIGNAL( deleted(const TQString&) ), TQT_SLOT( rebuildList() ) ); + connect( dw, TQT_SIGNAL( dirty(const TQString&) ), TQT_SLOT( rebuildList() ) ); +} + +void KCMDesignerFields::deleteFile() +{ + TQListViewItem *item = mPageView->selectedItem(); + if ( item ) { + PageItem *pageItem = static_cast( item->parent() ? item->parent() : item ); + if (KMessageBox::warningContinueCancel(this, + i18n( "Do you really want to delete '%1'?").tqarg( pageItem->text(0) ), "", KStdGuiItem::del() ) + == KMessageBox::Continue) + KIO::NetAccess::del( pageItem->path(), 0 ); + } + // The actual view refresh will be done automagically by the slots connected to kdirwatch +} + +void KCMDesignerFields::importFile() +{ + KURL src = KFileDialog::getOpenFileName( TQDir::homeDirPath(), i18n("*.ui|Designer Files"), + this, i18n("Import Page") ); + KURL dest = localUiDir(); + dest.setFileName(src.fileName()); + KIO::NetAccess::file_copy( src, dest, -1, true, false, this ); + // The actual view refresh will be done automagically by the slots connected to kdirwatch +} + + +void KCMDesignerFields::loadUiFiles() +{ + TQStringList list = KGlobal::dirs()->findAllResources( "data", uiPath() + "/*.ui", true, true ); + for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) { + new PageItem( mPageView, *it ); + } +} + +void KCMDesignerFields::rebuildList() +{ + TQStringList ai = saveActivePages(); + updatePreview( 0 ); + mPageView->clear(); + loadUiFiles(); + loadActivePages(ai); +} + +void KCMDesignerFields::loadActivePages(const TQStringList& ai) +{ + TQListViewItemIterator it( mPageView ); + while ( it.current() ) { + if ( it.current()->parent() == 0 ) { + PageItem *item = static_cast( it.current() ); + if ( ai.find( item->name() ) != ai.end() ) { + item->setOn( true ); + item->setIsActive( true ); + } + } + + ++it; + } +} + +void KCMDesignerFields::load() +{ + loadActivePages( readActivePages() ); +} + +TQStringList KCMDesignerFields::saveActivePages() +{ + TQListViewItemIterator it( mPageView, TQListViewItemIterator::Checked | + TQListViewItemIterator::Selectable ); + + TQStringList activePages; + while ( it.current() ) { + if ( it.current()->parent() == 0 ) { + PageItem *item = static_cast( it.current() ); + activePages.append( item->name() ); + } + + ++it; + } + + return activePages; +} + +void KCMDesignerFields::save() +{ + writeActivePages( saveActivePages() ); +} + +void KCMDesignerFields::defaults() +{ +} + +void KCMDesignerFields::initGUI() +{ + TQVBoxLayout *tqlayout = new TQVBoxLayout( this, KDialog::marginHint(), + KDialog::spacingHint() ); + + bool noDesigner = KStandardDirs::findExe("designer").isEmpty(); + + if ( noDesigner ) + { + TQString txt = + i18n("Warning: TQt Designer could not be found. It is probably not " + "installed. You will only be able to import existing designer files."); + TQLabel *lbl = new TQLabel( txt, this ); + tqlayout->addWidget( lbl ); + } + + TQHBoxLayout *hbox = new TQHBoxLayout( tqlayout, KDialog::spacingHint() ); + + mPageView = new KListView( this ); + mPageView->addColumn( i18n( "Available Pages" ) ); + mPageView->setRootIsDecorated( true ); + mPageView->setAllColumnsShowFocus( true ); + mPageView->setFullWidth( true ); + hbox->addWidget( mPageView ); + + TQGroupBox *box = new TQGroupBox(1, Qt::Horizontal, i18n("Preview of Selected Page"), this ); + + mPagePreview = new TQLabel( box ); + mPagePreview->setMinimumWidth( 300 ); + + mPageDetails = new TQLabel( box ); + + hbox->addWidget( box ); + + loadUiFiles(); + + hbox = new TQHBoxLayout( tqlayout, KDialog::spacingHint() ); + + TQString cwHowto = i18n("

This section allows you to add your own GUI" + " Elements ('Widgets') to store your own values" + " into %1. Proceed as described below:

" + "
    " + "
  1. Click on 'Edit with TQt Designer'" + "
  2. In the dialog, select 'Widget', then click OK" + "
  3. Add your widgets to the form" + "
  4. Save the file in the directory proposed by TQt Designer" + "
  5. Close TQt Designer" + "
" + "

In case you already have a designer file (*.ui) located" + " somewhere on your hard disk, simply choose 'Import Page'

" + "

Important: The name of each input widget you place within" + " the form must start with 'X_'; so if you want the widget to" + " correspond to your custom entry 'X-Foo', set the widget's" + " name property to 'X_Foo'.

" + "

Important: The widget will edit custom fields with an" + " application name of %2. To change the application name" + " to be edited, set the widget name in TQt Designer.

" ) + .tqarg( applicationName(), applicationName() ); + + KActiveLabel *activeLabel = new KActiveLabel( + i18n( "How does this work?" ).tqarg(cwHowto), this ); + hbox->addWidget( activeLabel ); + + // ### why is this needed? Looks like a KActiveLabel bug... + activeLabel->tqsetSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Maximum ); + + hbox->addStretch( 1 ); + + mDeleteButton = new TQPushButton( i18n( "Delete Page" ), this); + mDeleteButton->setEnabled( false ); + hbox->addWidget( mDeleteButton ); + mImportButton = new TQPushButton( i18n( "Import Page..." ), this); + hbox->addWidget( mImportButton ); + mDesignerButton = new TQPushButton( i18n( "Edit with TQt Designer..." ), this ); + hbox->addWidget( mDesignerButton ); + + if ( noDesigner ) + mDesignerButton->setEnabled( false ); + + // FIXME: Why do I have to call show() for all widgets? A this->show() doesn't + // seem to work. + mPageView->show(); + box->show(); + activeLabel->show(); + mDeleteButton->show(); + mImportButton->show(); + mDesignerButton->show(); +} + +void KCMDesignerFields::updatePreview( TQListViewItem *item ) +{ + bool widgetItemSelected = false; + + if ( item ) { + if ( item->parent() ) { + TQString details = TQString( "" + "" + "" + "" + "" + "
%1%2
%3%4
%5%6
%7%8
" ) + .tqarg( i18n( "Key:" ) ) + .tqarg( item->text( 0 ).replace("X_","X-") ) + .tqarg( i18n( "Type:" ) ) + .tqarg( item->text( 1 ) ) + .tqarg( i18n( "Classname:" ) ) + .tqarg( item->text( 2 ) ) + .tqarg( i18n( "Description:" ) ) + .tqarg( item->text( 3 ) ); + + mPageDetails->setText( details ); + + PageItem *pageItem = static_cast( item->parent() ); + mPagePreview->setPixmap( pageItem->preview() ); + } else { + mPageDetails->setText( TQString() ); + + PageItem *pageItem = static_cast( item ); + mPagePreview->setPixmap( pageItem->preview() ); + + widgetItemSelected = true; + } + + mPagePreview->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + } else { + mPagePreview->setPixmap( TQPixmap() ); + mPagePreview->setFrameStyle( 0 ); + mPageDetails->setText( TQString() ); + } + + mDeleteButton->setEnabled( widgetItemSelected ); +} + +void KCMDesignerFields::itemClicked( TQListViewItem *item ) +{ + if ( !item || item->parent() != 0 ) + return; + + PageItem *pageItem = static_cast( item ); + + if ( pageItem->isOn() != pageItem->isActive() ) { + emit changed( true ); + pageItem->setIsActive( pageItem->isOn() ); + } +} + +void KCMDesignerFields::startDesigner() +{ + TQString cmdLine = "designer"; + + // check if path exists and create one if not. + TQString cepPath = localUiDir(); + if( !KGlobal::dirs()->exists(cepPath) ) { + KIO::NetAccess::mkdir( cepPath, this ); + } + + // finally jump there + chdir(cepPath.local8Bit()); + + TQListViewItem *item = mPageView->selectedItem(); + if ( item ) { + PageItem *pageItem = static_cast( item->parent() ? item->parent() : item ); + cmdLine += " " + KProcess::quote( pageItem->path() ); + } + + KRun::runCommand( cmdLine ); +} + +#include "kcmdesignerfields.moc" diff --git a/libtdepim/kcmdesignerfields.h b/libtdepim/kcmdesignerfields.h new file mode 100644 index 000000000..820506f93 --- /dev/null +++ b/libtdepim/kcmdesignerfields.h @@ -0,0 +1,81 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + Copyright (c) 2004 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KPIM_KCMDESIGNERFIELDS_H +#define KPIM_KCMDESIGNERFIELDS_H + +#include +#include + +class KListView; + +class TQLabel; +class TQListViewItem; +class TQPushButton; + +namespace KPIM { + +class KDE_EXPORT KCMDesignerFields : public KCModule +{ + Q_OBJECT + TQ_OBJECT + + public: + KCMDesignerFields( TQWidget *parent = 0, const char *name = 0 ); + + virtual void load(); + virtual void save(); + virtual void defaults(); + + protected: + void loadUiFiles(); + void loadActivePages(const TQStringList&); + TQStringList saveActivePages(); + + virtual TQString localUiDir() = 0; + virtual TQString uiPath() = 0; + virtual void writeActivePages( const TQStringList & ) = 0; + virtual TQStringList readActivePages() = 0; + virtual TQString applicationName() = 0; + + private slots: + void updatePreview( TQListViewItem* ); + void itemClicked( TQListViewItem* ); + void startDesigner(); + void rebuildList(); + void deleteFile(); + void importFile(); + void delayedInit(); + + private: + void initGUI(); + + KListView *mPageView; + TQLabel *mPagePreview; + TQLabel *mPageDetails; + TQPushButton *mDeleteButton; + TQPushButton *mImportButton; + TQPushButton *mDesignerButton; +}; + +} + +#endif diff --git a/libtdepim/kconfigpropagator.cpp b/libtdepim/kconfigpropagator.cpp new file mode 100644 index 000000000..d22805db9 --- /dev/null +++ b/libtdepim/kconfigpropagator.cpp @@ -0,0 +1,289 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kconfigpropagator.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +KConfigPropagator::Change::~Change() +{ +} + +KConfigPropagator::ChangeConfig::ChangeConfig() + : KConfigPropagator::Change( i18n("Change Config Value") ), + hideValue( false ) +{ +} + +TQString KConfigPropagator::ChangeConfig::arg1() const +{ + return file + "/" + group + "/" + name; +} + +TQString KConfigPropagator::ChangeConfig::arg2() const +{ + if ( hideValue ) return "*"; + else return value; +} + +void KConfigPropagator::ChangeConfig::apply() +{ + KConfig cfg( file ); + cfg.setGroup( group ); + cfg.writeEntry( name, value ); + + cfg.sync(); +} + +KConfigPropagator::KConfigPropagator() + : mSkeleton( 0 ) +{ + init(); +} + +KConfigPropagator::KConfigPropagator( KConfigSkeleton *skeleton, + const TQString &kcfgFile ) + : mSkeleton( skeleton ), mKcfgFile( kcfgFile ) +{ + init(); + + readKcfgFile(); +} + +void KConfigPropagator::init() +{ + mChanges.setAutoDelete( true ); +} + +void KConfigPropagator::readKcfgFile() +{ + TQString filename = locate( "kcfg", mKcfgFile ); + if ( filename.isEmpty() ) { + kdError() << "Unable to find kcfg file '" << mKcfgFile << "'" << endl; + return; + } + + TQFile input( filename ); + TQDomDocument doc; + TQString errorMsg; + int errorRow; + int errorCol; + if ( !doc.setContent( &input, &errorMsg, &errorRow, &errorCol ) ) { + kdError() << "Parse error in " << mKcfgFile << ", line " << errorRow << ", col " << errorCol << ": " << errorMsg << endl; + return; + } + + TQDomElement cfgElement = doc.documentElement(); + + if ( cfgElement.isNull() ) { + kdError() << "No document in kcfg file" << endl; + return; + } + + mRules.clear(); + + TQDomNode n; + for ( n = cfgElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + TQDomElement e = n.toElement(); + + TQString tag = e.tagName(); + + if ( tag == "propagation" ) { + Rule rule = parsePropagation( e ); + mRules.append( rule ); + } else if ( tag == "condition" ) { + Condition condition = parseCondition( e ); + TQDomNode n2; + for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { + TQDomElement e2 = n2.toElement(); + if ( e2.tagName() == "propagation" ) { + Rule rule = parsePropagation( e2 ); + rule.condition = condition; + mRules.append( rule ); + } else { + kdError() << "Unknow tag: " << e2.tagName() << endl; + } + } + } + } +} + +KConfigPropagator::Rule KConfigPropagator::parsePropagation( const TQDomElement &e ) +{ + Rule r; + + TQString source = e.attribute( "source" ); + parseConfigEntryPath( source, r.sourceFile, r.sourceGroup, r.sourceEntry ); + + TQString target = e.attribute( "target" ); + parseConfigEntryPath( target, r.targetFile, r.targetGroup, r.targetEntry ); + + r.hideValue = e.hasAttribute( "hidevalue" ) && + e.attribute( "hidevalue" ) == "true"; + + return r; +} + +void KConfigPropagator::parseConfigEntryPath( const TQString &path, + TQString &file, + TQString &group, + TQString &entry ) +{ + TQStringList p = TQStringList::split( "/", path ); + + if ( p.count() != 3 ) { + kdError() << "Path has to be of form file/group/entry" << endl; + file = TQString(); + group = TQString(); + entry = TQString(); + return; + } + + file = p[ 0 ]; + group = p[ 1 ]; + entry = p[ 2 ]; + + return; +} + +KConfigPropagator::Condition KConfigPropagator::parseCondition( const TQDomElement &e ) +{ + Condition c; + + TQString key = e.attribute( "key" ); + + parseConfigEntryPath( key, c.file, c.group, c.key ); + + c.value = e.attribute( "value" ); + + c.isValid = true; + + return c; +} + +void KConfigPropagator::commit() +{ + updateChanges(); + + Change *c; + for( c = mChanges.first(); c; c = mChanges.next() ) { + c->apply(); + } +} + +KConfigSkeletonItem *KConfigPropagator::findItem( const TQString &group, + const TQString &name ) +{ +// kdDebug() << "KConfigPropagator::findItem()" << endl; + + if ( !mSkeleton ) return 0; + + KConfigSkeletonItem::List items = mSkeleton->items(); + KConfigSkeletonItem::List::ConstIterator it; + for( it = items.begin(); it != items.end(); ++it ) { +// kdDebug() << " Item: " << (*it)->name() << " Type: " +// << (*it)->property().typeName() << endl; + if ( (*it)->group() == group && (*it)->name() == name ) { + break; + } + } + if ( it == items.end() ) return 0; + else return *it; +} + +TQString KConfigPropagator::itemValueAsString( KConfigSkeletonItem *item ) +{ + TQVariant p = item->property(); + + if ( p.type() == TQVariant::Bool ) { + if ( p.toBool() ) return "true"; + else return "false"; + } + + return p.toString(); +} + +void KConfigPropagator::updateChanges() +{ + mChanges.clear(); + + Rule::List::ConstIterator it; + for( it = mRules.begin(); it != mRules.end(); ++it ) { + Rule r = *it; + Condition c = r.condition; + if ( c.isValid ) { + KConfigSkeletonItem *item = findItem( c.group, c.key ); + kdDebug() << "Item " << c.group << "/" << c.key << ":" << endl; + if ( !item ) { + kdError() << " Item not found." << endl; + } else { + TQString value = itemValueAsString( item ); + kdDebug() << " Value: " << value << endl; + if ( value != c.value ) { + continue; + } + } + } + + KConfigSkeletonItem *item = findItem( r.sourceGroup, r.sourceEntry ); + if ( !item ) { + kdError() << "Item " << r.sourceGroup << "/" << r.sourceEntry + << " not found." << endl; + continue; + } + TQString value = itemValueAsString( item ); + + KConfig target( r.targetFile ); + target.setGroup( r.targetGroup ); + TQString targetValue = target.readEntry( r.targetEntry ); + if ( r.hideValue ) targetValue = KStringHandler::obscure( targetValue ); + if ( targetValue != value ) { + ChangeConfig *change = new ChangeConfig(); + change->file = r.targetFile; + change->group = r.targetGroup; + change->name = r.targetEntry; + if ( r.hideValue ) value = KStringHandler::obscure( value ); + change->value = value; + change->hideValue = r.hideValue; + mChanges.append( change ); + } + } + + addCustomChanges( mChanges ); +} + +KConfigPropagator::Change::List KConfigPropagator::changes() +{ + return mChanges; +} + +KConfigPropagator::Rule::List KConfigPropagator::rules() +{ + return mRules; +} diff --git a/libtdepim/kconfigpropagator.h b/libtdepim/kconfigpropagator.h new file mode 100644 index 000000000..3e52eb7c4 --- /dev/null +++ b/libtdepim/kconfigpropagator.h @@ -0,0 +1,165 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KCONFIGPROPAGATOR_H +#define KCONFIGPROPAGATOR_H + +#include +#include +#include +#include + +#include + +class KConfigSkeleton; +class KConfigSkeletonItem; + +class KDE_EXPORT KConfigPropagator +{ + public: + + /** + Create KConfigPropagator object without associated source configuration. + */ + KConfigPropagator(); + /** + Create KConfigPropagator object. + + @param skeleton KConfigSkeleton object used as source for the propagation + @param kcfgFile file name of kcfg file containing the propagation rules + */ + KConfigPropagator( KConfigSkeleton *skeleton, const TQString &kcfgFile ); + virtual ~KConfigPropagator() {} + + KConfigSkeleton *skeleton() { return mSkeleton; } + + /* + Commit changes according to propagation rules. + */ + void commit(); + + class KDE_EXPORT Condition + { + public: + Condition() : isValid( false ) {} + + TQString file; + TQString group; + TQString key; + TQString value; + + bool isValid; + }; + + class KDE_EXPORT Rule + { + public: + typedef TQValueList List; + + Rule() : hideValue( false ) {} + + TQString sourceFile; + TQString sourceGroup; + TQString sourceEntry; + + TQString targetFile; + TQString targetGroup; + TQString targetEntry; + + Condition condition; + + bool hideValue; + }; + + class KDE_EXPORT Change + { + public: + typedef TQPtrList List; + + Change( const TQString &title ) : mTitle( title ) {} + virtual ~Change(); + + void setTitle( const TQString &title ) { mTitle = title; } + TQString title() const { return mTitle; } + + virtual TQString arg1() const { return TQString(); } + virtual TQString arg2() const { return TQString(); } + + virtual void apply() = 0; + + private: + TQString mTitle; + }; + + class KDE_EXPORT ChangeConfig : public Change + { + public: + ChangeConfig(); + ~ChangeConfig() {} + + TQString arg1() const; + TQString arg2() const; + + void apply(); + + TQString file; + TQString group; + TQString name; + TQString label; + TQString value; + bool hideValue; + }; + + void updateChanges(); + + Change::List changes(); + + Rule::List rules(); + + protected: + void init(); + + /** + Implement this function in a subclass if you want to add changes which + can't be expressed as propagations in the kcfg file. + */ + virtual void addCustomChanges( Change::List & ) {} + + KConfigSkeletonItem *findItem( const TQString &group, const TQString &name ); + + TQString itemValueAsString( KConfigSkeletonItem * ); + + void readKcfgFile(); + + Rule parsePropagation( const TQDomElement &e ); + Condition parseCondition( const TQDomElement &e ); + + void parseConfigEntryPath( const TQString &path, TQString &file, + TQString &group, TQString &entry ); + + private: + KConfigSkeleton *mSkeleton; + TQString mKcfgFile; + + Rule::List mRules; + Change::List mChanges; +}; + +#endif diff --git a/libtdepim/kconfigwizard.cpp b/libtdepim/kconfigwizard.cpp new file mode 100644 index 000000000..bceacd656 --- /dev/null +++ b/libtdepim/kconfigwizard.cpp @@ -0,0 +1,197 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kconfigwizard.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +KConfigWizard::KConfigWizard( TQWidget *parent, + char *name, bool modal ) + : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent, + name, modal ), + mPropagator( 0 ), mChangesPage( 0 ) +{ + init(); +} + +KConfigWizard::KConfigWizard( KConfigPropagator *propagator, TQWidget *parent, + char *name, bool modal ) + : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent, + name, modal ), + mPropagator( propagator ), mChangesPage( 0 ) +{ + init(); +} + +KConfigWizard::~KConfigWizard() +{ + delete mPropagator; +} + +void KConfigWizard::init() +{ + connect( this, TQT_SIGNAL( aboutToShowPage( TQWidget * ) ), + TQT_SLOT( slotAboutToShowPage( TQWidget * ) ) ); + + TQTimer::singleShot( 0, this, TQT_SLOT( readConfig() ) ); +} + +void KConfigWizard::setPropagator( KConfigPropagator *p ) +{ + mPropagator = p; +} + +void KConfigWizard::slotAboutToShowPage( TQWidget *page ) +{ + if ( page == mChangesPage ) { + updateChanges(); + } +} + +TQFrame *KConfigWizard::createWizardPage( const TQString &title ) +{ + return addPage( title ); +} + +void KConfigWizard::setupRulesPage() +{ + TQFrame *topFrame = addPage( i18n("Rules") ); + TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame ); + + mRuleView = new TQListView( topFrame ); + topLayout->addWidget( mRuleView ); + + mRuleView->addColumn( i18n("Source") ); + mRuleView->addColumn( i18n("Target") ); + mRuleView->addColumn( i18n("Condition") ); + + updateRules(); +} + +void KConfigWizard::updateRules() +{ + if ( !mPropagator ) { + kdError() << "KConfigWizard: No KConfigPropagator set." << endl; + return; + } + + mRuleView->clear(); + + KConfigPropagator::Rule::List rules = mPropagator->rules(); + KConfigPropagator::Rule::List::ConstIterator it; + for( it = rules.begin(); it != rules.end(); ++it ) { + KConfigPropagator::Rule r = *it; + TQString source = r.sourceFile + "/" + r.sourceGroup + "/" + + r.sourceEntry; + TQString target = r.targetFile + "/" + r.targetGroup + "/" + + r.targetEntry; + TQString condition; + KConfigPropagator::Condition c = r.condition; + if ( c.isValid ) { + condition = c.file + "/" + c.group + "/" + c.key + " = " + c.value; + } + new TQListViewItem( mRuleView, source, target, condition ); + } +} + +void KConfigWizard::setupChangesPage() +{ + TQFrame *topFrame = addPage( i18n("Changes") ); + TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame ); + + mChangeView = new TQListView( topFrame ); + topLayout->addWidget( mChangeView ); + + mChangeView->addColumn( i18n("Action") ); + mChangeView->addColumn( i18n("Option") ); + mChangeView->addColumn( i18n("Value") ); + mChangeView->setSorting( -1 ); + + mChangesPage = topFrame; +} + +void KConfigWizard::updateChanges() +{ + kdDebug() << "KConfigWizard::updateChanges()" << endl; + + if ( !mPropagator ) { + kdError() << "KConfigWizard: No KConfigPropagator set." << endl; + return; + } + + usrWriteConfig(); + + mPropagator->updateChanges(); + + mChangeView->clear(); + + KConfigPropagator::Change::List changes = mPropagator->changes(); + KConfigPropagator::Change *c; + for( c = changes.first(); c; c = changes.next() ) { + new TQListViewItem( mChangeView, mChangeView->lastItem(), c->title(), c->arg1(), c->arg2() ); + } +} + +void KConfigWizard::readConfig() +{ + kdDebug() << "KConfigWizard::readConfig()" << endl; + + int result = KMessageBox::warningContinueCancel( this, + i18n("Please make sure that the programs which are " + "configured by the wizard do not run in parallel to the wizard; " + "otherwise, changes done by the wizard could be lost."), + i18n("Warning"), i18n("Run Wizard Now"), "warning_running_instances" ); + if ( result != KMessageBox::Continue ) kapp->quit(); + + usrReadConfig(); +} + +void KConfigWizard::slotOk() +{ + TQString error = validate(); + if ( error.isNull() ) { + usrWriteConfig(); + + if ( !mPropagator ) { + kdError() << "KConfigWizard: No KConfigPropagator set." << endl; + return; + } else { + if ( mPropagator->skeleton() ) { + mPropagator->skeleton()->writeConfig(); + } + mPropagator->commit(); + } + + accept(); + } else { + KMessageBox::sorry( this, error ); + } +} + +#include "kconfigwizard.moc" diff --git a/libtdepim/kconfigwizard.h b/libtdepim/kconfigwizard.h new file mode 100644 index 000000000..71455277c --- /dev/null +++ b/libtdepim/kconfigwizard.h @@ -0,0 +1,110 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KCONFIGWIZARD_H +#define KCONFIGWIZARD_H + +#include +#include +#include + +class TQListView; + +/** + @short Configuration wizard base class +*/ +class KDE_EXPORT KConfigWizard : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT + public: + /** + Create wizard. You have to set a propgator with setPropagator() later. + */ + KConfigWizard( TQWidget *parent = 0, char *name = 0, bool modal = false ); + /** + Create wizard for given KConfigPropagator. The wizard takes ownership of + the propagator. + */ + KConfigWizard( KConfigPropagator *propagator, TQWidget *parent = 0, + char *name = 0, bool modal = false ); + /** + Destructor. + */ + virtual ~KConfigWizard(); + + /** + Set propagator the wizard operates on. + */ + void setPropagator( KConfigPropagator * ); + /** + Return propagator the wizard operates on. + */ + KConfigPropagator *propagator() { return mPropagator; } + + /** + Create wizard page with given title. + */ + TQFrame *createWizardPage( const TQString &title ); + + /** + Use this function to read the configuration from the KConfigSkeleton + object to the GUI. + */ + virtual void usrReadConfig() = 0; + + /** + This function is called when the wizard is finished. You have to save all + settings from the GUI to the KConfigSkeleton object here, so that the + KConfigPropagator can take them up from there. + */ + virtual void usrWriteConfig() = 0; + + /** + Validates the supplied data. Returns a appropiate error when some data + is invalid. Return TQString() if all data is valid. + */ + virtual TQString validate() { return TQString(); } + + protected slots: + void readConfig(); + + void slotOk(); + + void slotAboutToShowPage( TQWidget *page ); + + protected: + void init(); + + void setupRulesPage(); + void updateRules(); + void setupChangesPage(); + void updateChanges(); + + private: + KConfigPropagator *mPropagator; + + TQListView *mRuleView; + TQListView *mChangeView; + + TQWidget *mChangesPage; +}; + +#endif diff --git a/libtdepim/kdateedit.cpp b/libtdepim/kdateedit.cpp new file mode 100644 index 000000000..44c4e696a --- /dev/null +++ b/libtdepim/kdateedit.cpp @@ -0,0 +1,364 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Cornelius Schumacher + Copyright (c) 2002 David Jarvie + Copyright (c) 2003-2004 Reinhold Kainhofer + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "kdateedit.h" + +class DateValidator : public TQValidator +{ + public: + DateValidator( const TQStringList &keywords, TQWidget* parent, const char* name = 0 ) + : TQValidator( TQT_TQOBJECT(parent), name ), mKeywords( keywords ) + {} + + virtual State validate( TQString &str, int& ) const + { + int length = str.length(); + + // empty string is intermediate so one can clear the edit line and start from scratch + if ( length <= 0 ) + return Intermediate; + + if ( mKeywords.contains( str.lower() ) ) + return Acceptable; + + bool ok = false; + KGlobal::locale()->readDate( str, &ok ); + if ( ok ) + return Acceptable; + else + return Intermediate; + } + + private: + TQStringList mKeywords; +}; + +KDateEdit::KDateEdit( TQWidget *parent, const char *name ) + : TQComboBox( true, parent, name ), + mReadOnly( false ), + mDiscardNextMousePress( false ) +{ + // need at least one entry for popup to work + setMaxCount( 1 ); + + mDate = TQDate::tqcurrentDate(); + TQString today = KGlobal::locale()->formatDate( mDate, true ); + + insertItem( today ); + setCurrentItem( 0 ); + changeItem( today, 0 ); + setMinimumSize( tqsizeHint() ); + + connect( lineEdit(), TQT_SIGNAL( returnPressed() ), + this, TQT_SLOT( lineEnterPressed() ) ); + connect( this, TQT_SIGNAL( textChanged( const TQString& ) ), + TQT_SLOT( slotTextChanged( const TQString& ) ) ); + + mPopup = new KDatePickerPopup( KDatePickerPopup::DatePicker | KDatePickerPopup::Words ); + mPopup->hide(); + mPopup->installEventFilter( this ); + + connect( mPopup, TQT_SIGNAL( dateChanged( TQDate ) ), + TQT_SLOT( dateSelected( TQDate ) ) ); + + // handle keyword entry + setupKeywords(); + lineEdit()->installEventFilter( this ); + + setValidator( new DateValidator( mKeywordMap.keys(), this ) ); + + mTextChanged = false; +} + +KDateEdit::~KDateEdit() +{ + delete mPopup; + mPopup = 0; +} + +void KDateEdit::setDate( const TQDate& date ) +{ + assignDate( date ); + updateView(); +} + +TQDate KDateEdit::date() const +{ + return mDate; +} + +void KDateEdit::setReadOnly( bool readOnly ) +{ + mReadOnly = readOnly; + lineEdit()->setReadOnly( readOnly ); +} + +bool KDateEdit::isReadOnly() const +{ + return mReadOnly; +} + +void KDateEdit::popup() +{ + if ( mReadOnly ) + return; + + TQRect desk = KGlobalSettings::desktopGeometry( this ); + + TQPoint popupPoint = mapToGlobal( TQPoint( 0,0 ) ); + + int dateFrameHeight = mPopup->tqsizeHint().height(); + if ( popupPoint.y() + height() + dateFrameHeight > desk.bottom() ) + popupPoint.setY( popupPoint.y() - dateFrameHeight ); + else + popupPoint.setY( popupPoint.y() + height() ); + + int dateFrameWidth = mPopup->tqsizeHint().width(); + if ( popupPoint.x() + dateFrameWidth > desk.right() ) + popupPoint.setX( desk.right() - dateFrameWidth ); + + if ( popupPoint.x() < desk.left() ) + popupPoint.setX( desk.left() ); + + if ( popupPoint.y() < desk.top() ) + popupPoint.setY( desk.top() ); + + if ( mDate.isValid() ) + mPopup->setDate( mDate ); + else + mPopup->setDate( TQDate::tqcurrentDate() ); + + mPopup->popup( popupPoint ); + + // The combo box is now shown pressed. Make it show not pressed again + // by causing its (invisible) list box to emit a 'selected' signal. + // First, ensure that the list box contains the date currently displayed. + TQDate date = parseDate(); + assignDate( date ); + updateView(); + // Now, simulate an Enter to unpress it + TQListBox *lb = listBox(); + if (lb) { + lb->setCurrentItem(0); + TQKeyEvent* keyEvent = new TQKeyEvent(TQEvent::KeyPress, TQt::Key_Enter, 0, 0); + TQApplication::postEvent(lb, keyEvent); + } +} + +void KDateEdit::dateSelected( TQDate date ) +{ + if (assignDate( date ) ) { + updateView(); + emit dateChanged( date ); + emit dateEntered( date ); + + if ( date.isValid() ) { + mPopup->hide(); + } + } +} + +void KDateEdit::lineEnterPressed() +{ + bool replaced = false; + + TQDate date = parseDate( &replaced ); + + if (assignDate( date ) ) { + if ( replaced ) + updateView(); + + emit dateChanged( date ); + emit dateEntered( date ); + } +} + +TQDate KDateEdit::parseDate( bool *replaced ) const +{ + TQString text = currentText(); + TQDate result; + + if ( replaced ) + (*replaced) = false; + + if ( text.isEmpty() ) + result = TQDate(); + else if ( mKeywordMap.contains( text.lower() ) ) { + TQDate today = TQDate::tqcurrentDate(); + int i = mKeywordMap[ text.lower() ]; + if ( i >= 100 ) { + /* A day name has been entered. Convert to offset from today. + * This uses some math tricks to figure out the offset in days + * to the next date the given day of the week occurs. There + * are two cases, that the new day is >= the current day, which means + * the new day has not occurred yet or that the new day < the current day, + * which means the new day is already passed (so we need to find the + * day in the next week). + */ + i -= 100; + int currentDay = today.dayOfWeek(); + if ( i >= currentDay ) + i -= currentDay; + else + i += 7 - currentDay; + } + + result = today.addDays( i ); + if ( replaced ) + (*replaced) = true; + } else { + result = KGlobal::locale()->readDate( text ); + } + + return result; +} + +bool KDateEdit::eventFilter( TQObject *object, TQEvent *event ) +{ + if ( TQT_BASE_OBJECT(object) == TQT_BASE_OBJECT(lineEdit()) ) { + // We only process the focus out event if the text has changed + // since we got focus + if ( (event->type() == TQEvent::FocusOut) && mTextChanged ) { + lineEnterPressed(); + mTextChanged = false; + } else if ( event->type() == TQEvent::KeyPress ) { + // Up and down arrow keys step the date + TQKeyEvent* keyEvent = (TQKeyEvent*)event; + + if ( keyEvent->key() == TQt::Key_Return ) { + lineEnterPressed(); + return true; + } + + int step = 0; + if ( keyEvent->key() == TQt::Key_Up ) + step = 1; + else if ( keyEvent->key() == TQt::Key_Down ) + step = -1; + // TODO: If it's not an input key, but something like Return, Enter, Tab, etc..., don't eat the keypress, but handle it through to the default eventfilter! + if ( step && !mReadOnly ) { + TQDate date = parseDate(); + if ( date.isValid() ) { + date = date.addDays( step ); + if ( assignDate( date ) ) { + updateView(); + emit dateChanged( date ); + emit dateEntered( date ); + return true; + } + } + } + } + } else { + // It's a date picker event + switch ( event->type() ) { + case TQEvent::MouseButtonDblClick: + case TQEvent::MouseButtonPress: { + TQMouseEvent *mouseEvent = (TQMouseEvent*)event; + if ( !TQT_TQRECT_OBJECT(mPopup->rect()).contains( mouseEvent->pos() ) ) { + TQPoint globalPos = mPopup->mapToGlobal( mouseEvent->pos() ); + if ( TQApplication::widgetAt( globalPos, true ) == this ) { + // The date picker is being closed by a click on the + // KDateEdit widget. Avoid popping it up again immediately. + mDiscardNextMousePress = true; + } + } + + break; + } + default: + break; + } + } + + return false; +} + +void KDateEdit::mousePressEvent( TQMouseEvent *event ) +{ + if ( event->button() == Qt::LeftButton && mDiscardNextMousePress ) { + mDiscardNextMousePress = false; + return; + } + + TQComboBox::mousePressEvent( event ); +} + +void KDateEdit::slotTextChanged( const TQString& ) +{ + TQDate date = parseDate(); + + if ( assignDate( date ) ) + emit dateChanged( date ); + + mTextChanged = true; +} + +void KDateEdit::setupKeywords() +{ + // Create the keyword list. This will be used to match against when the user + // enters information. + mKeywordMap.insert( i18n( "tomorrow" ), 1 ); + mKeywordMap.insert( i18n( "today" ), 0 ); + mKeywordMap.insert( i18n( "yesterday" ), -1 ); + + TQString dayName; + for ( int i = 1; i <= 7; ++i ) { + dayName = KGlobal::locale()->calendar()->weekDayName( i ).lower(); + mKeywordMap.insert( dayName, i + 100 ); + } +} + +bool KDateEdit::assignDate( const TQDate& date ) +{ + mDate = date; + mTextChanged = false; + return true; +} + +void KDateEdit::updateView() +{ + TQString dateString; + if ( mDate.isValid() ) + dateString = KGlobal::locale()->formatDate( mDate, true ); + + // We do not want to generate a signal here, + // since we explicitly setting the date + bool blocked = signalsBlocked(); + blockSignals( true ); + changeItem( dateString, 0 ); + blockSignals( blocked ); +} + +#include "kdateedit.moc" diff --git a/libtdepim/kdateedit.h b/libtdepim/kdateedit.h new file mode 100644 index 000000000..02a7701cc --- /dev/null +++ b/libtdepim/kdateedit.h @@ -0,0 +1,150 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Cornelius Schumacher + Copyright (c) 2002 David Jarvie + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDATEEDIT_H +#define KDATEEDIT_H + +#include +#include +#include + +#include + +#include "kdatepickerpopup.h" + +class TQEvent; + +/** + A date editing widget that consists of an editable combo box. + The combo box contains the date in text form, and clicking the combo + box arrow will display a 'popup' style date picker. + + This widget also supports advanced features like allowing the user + to type in the day name to get the date. The following keywords + are supported (in the native language): tomorrow, yesturday, today, + monday, tuesday, wednesday, thursday, friday, saturday, sunday. + + @image html kdateedit.png "This is how it looks" + + @author Cornelius Schumacher + @author Mike Pilone + @author David Jarvie + @author Tobias Koenig +*/ +class KDE_EXPORT KDateEdit : public TQComboBox +{ + Q_OBJECT + TQ_OBJECT + + public: + KDateEdit( TQWidget *parent = 0, const char *name = 0 ); + virtual ~KDateEdit(); + + /** + @return The date entered. This date could be invalid, + you have to check validity yourself. + */ + TQDate date() const; + + /** + Sets whether the widget is read-only for the user. If read-only, + the date picker pop-up is inactive, and the displayed date cannot be edited. + + @param readOnly True to set the widget read-only, false to set it read-write. + */ + void setReadOnly( bool readOnly ); + + /** + @return True if the widget is read-only, false if read-write. + */ + bool isReadOnly() const; + + virtual void popup(); + + signals: + /** + This signal is emitted whenever the user has entered a new date. + When the user changes the date by editing the line edit field, + the signal is not emitted until focus leaves the line edit field. + The passed date can be invalid. + */ + void dateEntered( const TQDate &date ); + + /** + This signal is emitted whenever the user modifies the date. + The passed date can be invalid. + */ + void dateChanged( const TQDate &date ); + + public slots: + /** + Sets the date. + + @param date The new date to display. This date must be valid or + it will not be set + */ + void setDate( const TQDate &date ); + + protected slots: + void lineEnterPressed(); + void slotTextChanged( const TQString& ); + void dateSelected( TQDate ); + + protected: + virtual bool eventFilter( TQObject*, TQEvent* ); + virtual void mousePressEvent( TQMouseEvent* ); + + /** + Sets the date, without altering the display. + This method is used internally to set the widget's date value. + As a virtual method, it allows derived classes to perform additional validation + on the date value before it is set. Derived classes should return true if + TQDate::isValid(@p date) returns false. + + @param date The new date to set. + @return True if the date was set, false if it was considered invalid and + remains unchanged. + */ + virtual bool assignDate( const TQDate &date ); + + /** + Fills the keyword map. Reimplement it if you want additional + keywords. + */ + void setupKeywords(); + + private: + TQDate parseDate( bool* = 0 ) const; + void updateView(); + + KDatePickerPopup *mPopup; + + TQDate mDate; + bool mReadOnly; + bool mTextChanged; + bool mDiscardNextMousePress; + + TQMap mKeywordMap; +}; + +#endif diff --git a/libtdepim/kdatepickerpopup.cpp b/libtdepim/kdatepickerpopup.cpp new file mode 100644 index 000000000..998c44e4a --- /dev/null +++ b/libtdepim/kdatepickerpopup.cpp @@ -0,0 +1,123 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Bram Schoenmakers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include + +#include "kdatepickerpopup.h" + +KDatePickerPopup::KDatePickerPopup( int items, const TQDate &date, TQWidget *parent, + const char *name ) + : TQPopupMenu( parent, name ) +{ + mItems = items; + + mDatePicker = new KDatePicker( this ); + mDatePicker->setCloseButton( false ); + + connect( mDatePicker, TQT_SIGNAL( dateEntered( TQDate ) ), + TQT_SLOT( slotDateChanged( TQDate ) ) ); + connect( mDatePicker, TQT_SIGNAL( dateSelected( TQDate ) ), + TQT_SLOT( slotDateChanged( TQDate ) ) ); + + mDatePicker->setDate( date ); + + buildMenu(); +} + +void KDatePickerPopup::buildMenu() +{ + if ( isVisible() ) return; + clear(); + + if ( mItems & DatePicker ) { + insertItem( mDatePicker ); + + if ( ( mItems & NoDate ) || ( mItems & Words ) ) + insertSeparator(); + } + + if ( mItems & Words ) { + insertItem( i18n("&Today"), this, TQT_SLOT( slotToday() ) ); + insertItem( i18n("To&morrow"), this, TQT_SLOT( slotTomorrow() ) ); + insertItem( i18n("Next &Week"), this, TQT_SLOT( slotNextWeek() ) ); + insertItem( i18n("Next M&onth"), this, TQT_SLOT( slotNextMonth() ) ); + + if ( mItems & NoDate ) + insertSeparator(); + } + + if ( mItems & NoDate ) + insertItem( i18n("No Date"), this, TQT_SLOT( slotNoDate() ) ); +} + +KDatePicker *KDatePickerPopup::datePicker() const +{ + return mDatePicker; +} + +void KDatePickerPopup::setDate( const TQDate &date ) +{ + mDatePicker->setDate( date ); +} + +#if 0 +void KDatePickerPopup::setItems( int items ) +{ + mItems = items; + buildMenu(); +} +#endif + +void KDatePickerPopup::slotDateChanged( TQDate date ) +{ + emit dateChanged( date ); + hide(); +} + +void KDatePickerPopup::slotToday() +{ + emit dateChanged( TQDate::tqcurrentDate() ); +} + +void KDatePickerPopup::slotTomorrow() +{ + emit dateChanged( TQDate::tqcurrentDate().addDays( 1 ) ); +} + +void KDatePickerPopup::slotNoDate() +{ + emit dateChanged( TQDate() ); +} + +void KDatePickerPopup::slotNextWeek() +{ + emit dateChanged( TQDate::tqcurrentDate().addDays( 7 ) ); +} + +void KDatePickerPopup::slotNextMonth() +{ + emit dateChanged( TQDate::tqcurrentDate().addMonths( 1 ) ); +} + +#include "kdatepickerpopup.moc" diff --git a/libtdepim/kdatepickerpopup.h b/libtdepim/kdatepickerpopup.h new file mode 100644 index 000000000..44dc7c668 --- /dev/null +++ b/libtdepim/kdatepickerpopup.h @@ -0,0 +1,104 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Bram Schoenmakers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KDATEPICKERPOPUP_H +#define KDATEPICKERPOPUP_H + +#include +#include + +#include +#include + +/** + @short This menu helps the user to select a date quickly. + + This menu helps the user to select a date quicly. It offers various ways of selecting, e.g. with a KDatePicker or with words like "Tomorrow". + + The available items are: + + @li NoDate: A menu-item with "No Date". If choosen, the datepicker will emit a null TQDate. + @li DatePicker: Show a KDatePicker-widget. + @li Words: Show items like "Today", "Tomorrow" or "Next Week". + + When supplying multiple items, separate each item with a bitwise OR. + + @author Bram Schoenmakers +*/ +class KDE_EXPORT KDatePickerPopup: public TQPopupMenu +{ + Q_OBJECT + TQ_OBJECT + public: + enum { NoDate = 1, DatePicker = 2, Words = 4 }; + + /** + A constructor for the KDatePickerPopup. + + @param items List of all desirable items, separated with a bitwise OR. + @param date Initial date of datepicker-widget. + @param parent The object's parent. + @param name The object's name. + */ + KDatePickerPopup( int items = DatePicker, const TQDate &date = TQDate::tqcurrentDate(), + TQWidget *parent = 0, const char *name = 0 ); + + /** + @return A pointer to the private variable mDatePicker, an instance of + KDatePicker. + */ + KDatePicker *datePicker() const; + + void setDate( const TQDate &date ); + +#if 0 + /** Set items which should be shown and rebuilds the menu afterwards. Only if the menu is not visible. + @param items List of all desirable items, separated with a bitwise OR. + */ + void setItems( int items = 1 ); +#endif + /** @return Returns the bitwise result of the active items in the popup. */ + int items() const { return mItems; } + + signals: + + /** + This signal emits the new date (selected with datepicker or other + menu-items). + */ + void dateChanged ( TQDate ); + + protected slots: + void slotDateChanged ( TQDate ); + + void slotToday(); + void slotTomorrow(); + void slotNextWeek(); + void slotNextMonth(); + void slotNoDate(); + + private: + void buildMenu(); + + KDatePicker *mDatePicker; + int mItems; +}; + +#endif diff --git a/libtdepim/kfileio.cpp b/libtdepim/kfileio.cpp new file mode 100644 index 000000000..e167662bb --- /dev/null +++ b/libtdepim/kfileio.cpp @@ -0,0 +1,390 @@ +// kfileio.cpp +// Author: Stefan Taferner +// License: GPL + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +namespace KPIM { + +//----------------------------------------------------------------------------- +static void msgDialog(const TQString &msg) +{ + KMessageBox::sorry(0, msg, i18n("File I/O Error")); +} + + +//----------------------------------------------------------------------------- +KDE_EXPORT TQCString kFileToString(const TQString &aFileName, bool aEnsureNL, bool aVerbose) +{ + TQCString result; + TQFileInfo info(aFileName); + unsigned int readLen; + unsigned int len = info.size(); + TQFile file(aFileName); + + //assert(aFileName!=0); + if( aFileName.isEmpty() ) + return ""; + + if (!info.exists()) + { + if (aVerbose) + msgDialog(i18n("The specified file does not exist:\n%1").tqarg(aFileName)); + return TQCString(); + } + if (info.isDir()) + { + if (aVerbose) + msgDialog(i18n("This is a folder and not a file:\n%1").tqarg(aFileName)); + return TQCString(); + } + if (!info.isReadable()) + { + if (aVerbose) + msgDialog(i18n("You do not have read permissions " + "to the file:\n%1").tqarg(aFileName)); + return TQCString(); + } + if (len <= 0) return TQCString(); + + if (!file.open(IO_Raw|IO_ReadOnly)) + { + if (aVerbose) switch(file.status()) + { + case IO_ReadError: + msgDialog(i18n("Could not read file:\n%1").tqarg(aFileName)); + break; + case IO_OpenError: + msgDialog(i18n("Could not open file:\n%1").tqarg(aFileName)); + break; + default: + msgDialog(i18n("Error while reading file:\n%1").tqarg(aFileName)); + } + return TQCString(); + } + + result.resize(len + (int)aEnsureNL + 1); + readLen = file.readBlock(result.data(), len); + if (aEnsureNL && result[len-1]!='\n') + { + result[len++] = '\n'; + readLen++; + } + result[len] = '\0'; + + if (readLen < len) + { + TQString msg = i18n("Could only read %1 bytes of %2.") + .tqarg(readLen).tqarg(len); + msgDialog(msg); + return TQCString(); + } + + return result; +} + +//----------------------------------------------------------------------------- +#if 0 // unused +TQByteArray kFileToBytes(const TQString &aFileName, bool aVerbose) +{ + TQByteArray result; + TQFileInfo info(aFileName); + unsigned int readLen; + unsigned int len = info.size(); + TQFile file(aFileName); + + //assert(aFileName!=0); + if( aFileName.isEmpty() ) + return result; + + if (!info.exists()) + { + if (aVerbose) + msgDialog(i18n("The specified file does not exist:\n%1") + .tqarg(aFileName)); + return result; + } + if (info.isDir()) + { + if (aVerbose) + msgDialog(i18n("This is a folder and not a file:\n%1") + .tqarg(aFileName)); + return result; + } + if (!info.isReadable()) + { + if (aVerbose) + msgDialog(i18n("You do not have read permissions " + "to the file:\n%1").tqarg(aFileName)); + return result; + } + if (len <= 0) return result; + + if (!file.open(IO_Raw|IO_ReadOnly)) + { + if (aVerbose) switch(file.status()) + { + case IO_ReadError: + msgDialog(i18n("Could not read file:\n%1").tqarg(aFileName)); + break; + case IO_OpenError: + msgDialog(i18n("Could not open file:\n%1").tqarg(aFileName)); + break; + default: + msgDialog(i18n("Error while reading file:\n%1").tqarg(aFileName)); + } + return result; + } + + result.resize(len); + readLen = file.readBlock(result.data(), len); + kdDebug(5300) << TQString( "len %1" ).tqarg(len) << endl; + + if (readLen < len) + { + TQString msg; + msg = i18n("Could only read %1 bytes of %2.") + .tqarg(readLen).tqarg(len); + msgDialog(msg); + return result; + } + + return result; +} +#endif + +//----------------------------------------------------------------------------- +KDE_EXPORT bool kBytesToFile(const char* aBuffer, int len, + const TQString &aFileName, + bool aAskIfExists, bool aBackup, bool aVerbose) +{ + // TODO: use KSaveFile + TQFile file(aFileName); + int writeLen, rc; + + //assert(aFileName!=0); + if(aFileName.isEmpty()) + return FALSE; + + if (file.exists()) + { + if (aAskIfExists) + { + TQString str; + str = i18n("File %1 exists.\nDo you want to replace it?") + .tqarg(aFileName); + rc = KMessageBox::warningContinueCancel(0, + str, i18n("Save to File"), i18n("&Replace")); + if (rc != KMessageBox::Continue) return FALSE; + } + if (aBackup) + { + // make a backup copy + // TODO: use KSaveFile::backupFile() + TQString bakName = aFileName; + bakName += '~'; + TQFile::remove(bakName); + if( !TQDir::current().rename(aFileName, bakName) ) + { + // failed to rename file + if (!aVerbose) return FALSE; + rc = KMessageBox::warningContinueCancel(0, + i18n("Failed to make a backup copy of %1.\nContinue anyway?") + .tqarg(aFileName), + i18n("Save to File"), KStdGuiItem::save() ); + if (rc != KMessageBox::Continue) return FALSE; + } + } + } + + if (!file.open(IO_Raw|IO_WriteOnly|IO_Truncate)) + { + if (aVerbose) switch(file.status()) + { + case IO_WriteError: + msgDialog(i18n("Could not write to file:\n%1").tqarg(aFileName)); + break; + case IO_OpenError: + msgDialog(i18n("Could not open file for writing:\n%1") + .tqarg(aFileName)); + break; + default: + msgDialog(i18n("Error while writing file:\n%1").tqarg(aFileName)); + } + return FALSE; + } + + writeLen = file.writeBlock(aBuffer, len); + + if (writeLen < 0) + { + if (aVerbose) + msgDialog(i18n("Could not write to file:\n%1").tqarg(aFileName)); + return FALSE; + } + else if (writeLen < len) + { + TQString msg = i18n("Could only write %1 bytes of %2.") + .tqarg(writeLen).tqarg(len); + if (aVerbose) + msgDialog(msg); + return FALSE; + } + + return TRUE; +} + +KDE_EXPORT bool kCStringToFile(const TQCString& aBuffer, const TQString &aFileName, + bool aAskIfExists, bool aBackup, bool aVerbose) +{ + return kBytesToFile(aBuffer, aBuffer.length(), aFileName, aAskIfExists, + aBackup, aVerbose); +} + +KDE_EXPORT bool kByteArrayToFile(const TQByteArray& aBuffer, const TQString &aFileName, + bool aAskIfExists, bool aBackup, bool aVerbose) +{ + return kBytesToFile(aBuffer, aBuffer.size(), aFileName, aAskIfExists, + aBackup, aVerbose); +} + + +TQString checkAndCorrectPermissionsIfPossible( const TQString &toCheck, + const bool recursive, const bool wantItReadable, + const bool wantItWritable ) +{ + // First we have to find out which type the toCheck is. This can be + // a directory (follow if recursive) or a file (check permissions). + // Symlinks are followed as expected. + TQFileInfo fiToCheck(toCheck); + fiToCheck.setCaching(false); + TQCString toCheckEnc = TQFile::encodeName(toCheck); + TQString error; + struct stat statbuffer; + + if ( !fiToCheck.exists() ) { + error.append( i18n("%1 does not exist") + .tqarg(toCheck) + "\n"); + } + + // check the access bit of a folder. + if ( fiToCheck.isDir() ) { + if ( stat( toCheckEnc,&statbuffer ) != 0 ) { + kdDebug() << "wantItA: Can't read perms of " << toCheck << endl; + } + TQDir g( toCheck ); + if ( !g.isReadable() ) { + if ( chmod( toCheckEnc, statbuffer.st_mode + S_IXUSR ) != 0 ) { + error.append( i18n("%1 is not accessible and that is " + "unchangeable.").tqarg(toCheck) + "\n"); + } else { + kdDebug() << "Changed access bit for " << toCheck << endl; + } + } + } + + // For each file or folder we can check if the file is readable + // and writable, as requested. + if ( fiToCheck.isFile() || fiToCheck.isDir() ) { + + if ( !fiToCheck.isReadable() && wantItReadable ) { + // Get the current permissions. No need to do anything with an + // error, it will het added to errors anyhow, later on. + if ( stat(toCheckEnc,&statbuffer) != 0 ) { + kdDebug() << "wantItR: Can't read perms of " << toCheck << endl; + } + + // Lets try changing it. + if ( chmod( toCheckEnc, statbuffer.st_mode + S_IRUSR ) != 0 ) { + error.append( i18n("%1 is not readable and that is unchangeable.") + .tqarg(toCheck) + "\n"); + } else { + kdDebug() << "Changed the read bit for " << toCheck << endl; + } + } + + if ( !fiToCheck.isWritable() && wantItWritable ) { + // Gets the current persmissions. Needed because it can be changed + // curing previous operation. + if (stat(toCheckEnc,&statbuffer) != 0) { + kdDebug() << "wantItW: Can't read perms of " << toCheck << endl; + } + + // Lets try changing it. + if ( chmod (toCheckEnc, statbuffer.st_mode + S_IWUSR ) != 0 ) { + error.append( i18n("%1 is not writable and that is unchangeable.") + .tqarg(toCheck) + "\n"); + } else { + kdDebug() << "Changed the write bit for " << toCheck << endl; + } + } + } + + // If it is a folder and recursive is true, then we check the contents of + // the folder. + if ( fiToCheck.isDir() && recursive ){ + TQDir g(toCheck); + // First check if the folder is readable for us. If not, we get + // some ugly crashes. + if ( !g.isReadable() ){ + error.append(i18n("Folder %1 is inaccessible.").tqarg(toCheck) + "\n"); + } else { + const TQFileInfoList *list = g.entryInfoList(); + TQFileInfoListIterator it( *list ); + TQFileInfo *fi; + while ((fi = it.current()) != 0) { + TQString newToCheck = toCheck + "/" + fi->fileName(); + TQFileInfo fiNewToCheck(newToCheck); + if ( fi->fileName() != "." && fi->fileName() != ".." ) { + error.append ( checkAndCorrectPermissionsIfPossible( newToCheck, + recursive, wantItReadable, wantItWritable) ); + } + ++it; + } + } + } + return error; +} + +bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( TQWidget *parent, + const TQString &toCheck, const bool recursive, const bool wantItReadable, + const bool wantItWritable ) +{ + TQString error = checkAndCorrectPermissionsIfPossible(toCheck, recursive, + wantItReadable, wantItWritable); + // There is no KMessageBox with Retry, Cancel and Details. + // so, I can't provide a functionality to recheck. So it now + // it is just a warning. + if ( !error.isEmpty() ) { + kdDebug() << "checkPermissions found:" << error << endl; + KMessageBox::detailedSorry(parent, + i18n("Some files or folders do not have " + "the right permissions, please correct them " + "manually."), + error, i18n("Permissions Check"), false); + return false; + } else { + return true; + } +} + +} diff --git a/libtdepim/kfileio.h b/libtdepim/kfileio.h new file mode 100644 index 000000000..15db09338 --- /dev/null +++ b/libtdepim/kfileio.h @@ -0,0 +1,105 @@ +/* Load / save entire (local) files with nice diagnostics dialog messages. + * These functions load/save the whole buffer in one i/o call, so they + * should be pretty efficient. + * + * Author: Stefan Taferner + * This code is under GPL. + */ +#ifndef kpim_kfileio_h +#define kpim_kfileio_h + +#include +#include + +#include + +class TQString; + +namespace KPIM { + +/** Load a file. Returns a pointer to the memory-block that contains + * the loaded file. Returns a null string if the file could not be loaded. + * If withDialogs is FALSE no warning dialogs are opened if there are + * problems. + * The string returned is always zero-terminated and therefore one + * byte longer than the file itself. + * If ensureNewline is TRUE the string will always have a trailing newline. + */ +TQCString kFileToString(const TQString &fileName, bool ensureNewline=true, + bool withDialogs=true) KDE_EXPORT; + +// unused +//TQByteArray kFileToBytes(const TQString &fileName, bool withDialogs=true); + + +/** Save a file. If withDialogs is FALSE no warning dialogs are opened if + * there are problems. Returns TRUE on success and FALSE on failure. + * Replaces existing files without warning if askIfExists==FALSE. + * Makes a copy if the file exists to filename~ if createBackup==TRUE. + */ +bool kBytesToFile(const char* aBuffer, int len, + const TQString &aFileName, + bool aAskIfExists, bool aBackup, bool aVerbose) KDE_EXPORT; + +bool kCStringToFile(const TQCString& buffer, const TQString &fileName, + bool askIfExists=false, bool createBackup=true, + bool withDialogs=true) KDE_EXPORT; +/** Does not stop at NUL */ +KDE_EXPORT bool kByteArrayToFile(const TQByteArray& buffer, const TQString &fileName, + bool askIfExists=false, bool createBackup=true, + bool withDialogs=true) KDE_EXPORT; + + + /** + * Checks and corrects the permissions of a file or folder, and if requested + * all files and folders below. It gives back a list of files which do not + * have the right permissions. This list can be used to show to the user. + * + * @param toCheck The file or folder of which the permissions should + * be checked. + * @param recursive Set to true, it will check the contents of a folder + * for the permissions recursively. If false only + * toCheck will be checked. + * @param wantItReadable Set to true, it will check for read permissions. + * If the read permissions are not available, there will + * be a attempt to correct this. + * @param wantItWritable Set to true, it will check for write permissions. + * If the write permissions are not available, there + * will be a attempt to correct this. + * @return It will return a string with all files and folders which do not + * have the right permissions. If empty, then all permissions are ok. + */ +TQString checkAndCorrectPermissionsIfPossible( const TQString &toCheck, + const bool recursive, const bool wantItReadable, + const bool wantItWritable ); + + /** + * Checks and corrects the permissions of a file or folder, and if requested + * all files and folders below. If the permissions are not ok, it tries to correct + * them. If that fails then a warning with detailled information is given. + * + * @param parent If parent is 0, then the message box becomes an + * application-global modal dialog box. If parent + * is a widget, the message box becomes modal + * relative to parent. + * @param toCheck The file or folder of which the permissions should + * be checked. + * @param recursive Set to true, it will check the contents of a folder + * for the permissions recursively. If false only + * toCheck will be checked. + * @param wantItReadable Set to true, it will check for read permissions. + * If the read permissions are not available, there will + * be a attempt to correct this. + * @param wantItWritable Set to true, it will check for write permissions. + * If the write permissions are not available, there + * will be a attempt to correct this. + * @return It will return true if all permissions in the end are ok. If false + * then the permissions are not ok and it was not possible to correct + * all errors. + */ +bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( TQWidget *parent, + const TQString &toCheck, const bool recursive, const bool wantItReadable, + const bool wantItWritable ); +} + +#endif /*kpim_kfileio_h*/ diff --git a/libtdepim/kfoldertree.cpp b/libtdepim/kfoldertree.cpp new file mode 100644 index 000000000..64859199a --- /dev/null +++ b/libtdepim/kfoldertree.cpp @@ -0,0 +1,542 @@ +// -*- c-basic-offset: 2 -*- + +#include "kfoldertree.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//----------------------------------------------------------------------------- +KFolderTreeItem::KFolderTreeItem( KFolderTree *parent, const TQString & label, + Protocol protocol, Type type ) + : KListViewItem( parent, label ), mProtocol( protocol ), mType( type ), + mUnread(-1), mTotal(0), mSize(0), mFolderIsCloseToQuota( false ) +{ +} + +//----------------------------------------------------------------------------- +KFolderTreeItem::KFolderTreeItem( KFolderTreeItem *parent, + const TQString & label, Protocol protocol, Type type, + int unread, int total ) + : KListViewItem( parent, label ), mProtocol( protocol ), mType( type ), + mUnread( unread ), mTotal( total ), mSize(0), mFolderIsCloseToQuota( false ) +{ +} + +//----------------------------------------------------------------------------- +int KFolderTreeItem::protocolSortingKey() const +{ + // protocol dependant sorting order: + // local < imap < news < search < other + switch ( mProtocol ) { + case Local: + return 1; + case CachedImap: + case Imap: + return 2; + case News: + return 3; + case Search: + return 4; + default: + return 42; + } +} + +//----------------------------------------------------------------------------- +int KFolderTreeItem::typeSortingKey() const +{ + // type dependant sorting order: + // inbox < outbox < sent-mail < trash < drafts + // < calendar < contacts < notes < tasks + // < normal folders + switch ( mType ) { + case Inbox: + return 1; + case Outbox: + return 2; + case SentMail: + return 3; + case Trash: + return 4; + case Drafts: + return 5; + case Templates: + return 6; + case Calendar: + return 7; + case Contacts: + return 8; + case Notes: + return 9; + case Tasks: + return 10; + default: + return 42; + } +} + +//----------------------------------------------------------------------------- +int KFolderTreeItem::compare( TQListViewItem * i, int col, bool ) const +{ + KFolderTreeItem* other = static_cast( i ); + + if (col == 0) + { + // sort by folder + + // local root-folder + if ( depth() == 0 && mProtocol == NONE ) + return -1; + if ( other->depth() == 0 && other->protocol() == NONE ) + return 1; + + // first compare by protocol + int thisKey = protocolSortingKey(); + int thatKey = other->protocolSortingKey(); + if ( thisKey < thatKey ) + return -1; + if ( thisKey > thatKey ) + return 1; + + // then compare by type + thisKey = typeSortingKey(); + thatKey = other->typeSortingKey(); + if ( thisKey < thatKey ) + return -1; + if ( thisKey > thatKey ) + return 1; + + // and finally compare by name + return text( 0 ).localeAwareCompare( other->text( 0 ) ); + } + else + { + // sort by unread or total-column + TQ_INT64 a = 0, b = 0; + if (col == static_cast(listView())->unreadIndex()) + { + a = mUnread; + b = other->unreadCount(); + } + else if (col == static_cast(listView())->totalIndex()) + { + a = mTotal; + b = other->totalCount(); + } + else if (col == static_cast(listView())->sizeIndex()) + { + a = mSize; + b = other->folderSize(); + } + + if ( a == b ) + return 0; + else + return (a < b ? -1 : 1); + } +} + +//----------------------------------------------------------------------------- +void KFolderTreeItem::setUnreadCount( int aUnread ) +{ + if ( aUnread < 0 ) return; + + mUnread = aUnread; + + TQString unread = TQString(); + if (mUnread == 0) + unread = "- "; + else { + unread.setNum(mUnread); + unread += " "; + } + + setText( static_cast(listView())->unreadIndex(), + unread ); +} + +//----------------------------------------------------------------------------- +void KFolderTreeItem::setTotalCount( int aTotal ) +{ + if ( aTotal < 0 ) return; + + mTotal = aTotal; + + TQString total = TQString(); + if (mTotal == 0) + total = "- "; + else { + total.setNum(mTotal); + total += " "; + } + + setText( static_cast(listView())->totalIndex(), + total ); +} + +//----------------------------------------------------------------------------- +void KFolderTreeItem::setFolderSize( TQ_INT64 aSize ) +{ + if ( aSize < 0 ) return; // we need to update even if nothing changed, kids ... + + mSize = aSize; + + TQString size; + if (mType != Root) { + if (mSize == 0 && (childCount() == 0 || isOpen() ) ) + size = "- "; + else + size = KIO::convertSize(mSize); + } + if ( childCount() > 0 && !isOpen() ) { + TQ_INT64 recursiveSize = recursiveFolderSize(); + if ( recursiveSize != mSize ) { + if ( mType != Root ) + size += TQString::tqfromLatin1(" + %1").tqarg( KIO::convertSize( recursiveSize - mSize ) ); + else + size = KIO::convertSize( recursiveSize ); + } + } + size += " "; + + setText( static_cast(listView())->sizeIndex(), size ); +} + +//----------------------------------------------------------------------------- +TQ_INT64 KFolderTreeItem::recursiveFolderSize() const +{ + TQ_INT64 size = mSize; + + for ( TQListViewItem *item = firstChild() ; + item ; item = item->nextSibling() ) + { + size += static_cast(item)->recursiveFolderSize(); + } + return size; +} + + + +//----------------------------------------------------------------------------- +int KFolderTreeItem::countUnreadRecursive() +{ + int count = (mUnread > 0) ? mUnread : 0; + + for ( TQListViewItem *item = firstChild() ; + item ; item = item->nextSibling() ) + { + count += static_cast(item)->countUnreadRecursive(); + } + + return count; +} + +//----------------------------------------------------------------------------- +void KFolderTreeItem::paintCell( TQPainter * p, const TQColorGroup & cg, + int column, int width, int align ) +{ + KFolderTree *ft = static_cast(listView()); + + const int unreadRecursiveCount = countUnreadRecursive(); + const int unreadCount = ( mUnread > 0 ) ? mUnread : 0; + + + // use a special color for folders which are close to their quota + TQColorGroup mycg = cg; + if ( ( column == 0 || column == ft->sizeIndex() ) && folderIsCloseToQuota() ) + { + mycg.setColor( TQColorGroup::Text, ft->paintInfo().colCloseToQuota ); + } + + // use a bold-font for the folder- and the unread-columns + if ( (column == 0 || column == ft->unreadIndex()) + && ( unreadCount > 0 + || ( !isOpen() && unreadRecursiveCount > 0 ) ) ) + { + TQFont f = p->font(); + f.setWeight(TQFont::Bold); + p->setFont(f); + } + + + // most cells can be handled by KListView::paintCell, we only need to + // deal with the folder column if the unread column is not shown + + /* The below is exceedingly silly, but Ingo insists that the unread + * count that is shown in parenthesis after the folder name must + * be configurable in color. That means that paintCell needs to do + * two painting passes which flickers. Since that flicker is not + * needed when there is the unread column, special case that. */ + if ( ft->isUnreadActive() || column != 0 ) { + KListViewItem::paintCell( p, mycg, column, width, align ); + } else { + TQListView *lv = listView(); + TQString oldText = text(column); + + // set an empty text so that we can have our own implementation (see further down) + // but still benefit from KListView::paintCell + setText( column, "" ); + + KListViewItem::paintCell( p, mycg, column, width, align ); + + const TQPixmap *icon = pixmap( column ); + int marg = lv ? lv->itemMargin() : 1; + int r = marg; + + setText( column, oldText ); + if ( isSelected() ) + p->setPen( mycg.highlightedText() ); + else + p->setPen( mycg.color( TQColorGroup::Text ) ); + + if ( icon ) { + r += icon->width() + marg; + } + TQString t = text( column ); + if (t.isEmpty()) + return; + + // draw the unread-count if the unread-column is not active + TQString unread; + + if ( unreadCount > 0 || ( !isOpen() && unreadRecursiveCount > 0 ) ) { + if ( isOpen() ) + unread = " (" + TQString::number( unreadCount ) + ")"; + else if ( unreadRecursiveCount == unreadCount || mType == Root ) + unread = " (" + TQString::number( unreadRecursiveCount ) + ")"; + else + unread = " (" + TQString::number( unreadCount ) + " + " + + TQString::number( unreadRecursiveCount-unreadCount ) + ")"; + } + + // check if the text needs to be squeezed + TQFontMetrics fm( p->fontMetrics() ); + int unreadWidth = fm.width( unread ); + if ( fm.width( t ) + marg + r + unreadWidth > width ) + t = squeezeFolderName( t, fm, width - marg - r - unreadWidth ); + + TQRect br; + p->drawText( r, 0, width-marg-r, height(), + align | AlignVCenter, t, -1, &br ); + + if ( !unread.isEmpty() ) { + if (!isSelected()) + p->setPen( ft->paintInfo().colUnread ); + p->drawText( br.right(), 0, width-marg-br.right(), height(), + align | AlignVCenter, unread ); + } + } +} + + +TQString KFolderTreeItem::squeezeFolderName( const TQString &text, + const TQFontMetrics &fm, + uint width ) const +{ + return KStringHandler::rPixelSqueeze( text, fm, width ); +} + +bool KFolderTreeItem::folderIsCloseToQuota() const +{ + return mFolderIsCloseToQuota; +} + +void KFolderTreeItem::setFolderIsCloseToQuota( bool v ) +{ + if ( mFolderIsCloseToQuota != v) { + mFolderIsCloseToQuota = v; + tqrepaint(); + } +} + + +//============================================================================= + + +KFolderTree::KFolderTree( TQWidget *parent, const char* name ) + : KListView( parent, name ), mUnreadIndex(-1), mTotalIndex(-1), mSizeIndex(-1) +{ + // GUI-options + setStyleDependantFrameWidth(); + setAcceptDrops(true); + setDropVisualizer(false); + setAllColumnsShowFocus(true); + setShowSortIndicator(true); + setUpdatesEnabled(true); + setItemsRenameable(false); + setRootIsDecorated(true); + setSelectionModeExt(Extended); + setAlternateBackground(TQColor()); +#if KDE_IS_VERSION( 3, 3, 90 ) + setShadeSortColumn ( false ); +#endif + setFullWidth(true); + disableAutoSelection(); + setColumnWidth( 0, 120 ); //reasonable default size + + disconnect( header(), TQT_SIGNAL( sizeChange( int, int, int ) ) ); + connect( header(), TQT_SIGNAL( sizeChange( int, int, int ) ), + TQT_SLOT( slotSizeChanged( int, int, int ) ) ); +} + +//----------------------------------------------------------------------------- +void KFolderTree::setStyleDependantFrameWidth() +{ + // set the width of the frame to a reasonable value for the current GUI style + int frameWidth; + if( tqstyle().isA("KeramikStyle") ) + frameWidth = tqstyle().tqpixelMetric( TQStyle::PM_DefaultFrameWidth ) - 1; + else + frameWidth = tqstyle().tqpixelMetric( TQStyle::PM_DefaultFrameWidth ); + if ( frameWidth < 0 ) + frameWidth = 0; + if ( frameWidth != lineWidth() ) + setLineWidth( frameWidth ); +} + +//----------------------------------------------------------------------------- +void KFolderTree::styleChange( TQStyle& oldStyle ) +{ + setStyleDependantFrameWidth(); + KListView::styleChange( oldStyle ); +} + +//----------------------------------------------------------------------------- +void KFolderTree::drawContentsOffset( TQPainter * p, int ox, int oy, + int cx, int cy, int cw, int ch ) +{ + bool oldUpdatesEnabled = isUpdatesEnabled(); + setUpdatesEnabled(false); + KListView::drawContentsOffset( p, ox, oy, cx, cy, cw, ch ); + setUpdatesEnabled(oldUpdatesEnabled); +} + +//----------------------------------------------------------------------------- +void KFolderTree::contentsMousePressEvent( TQMouseEvent *e ) +{ + setSelectionModeExt(Single); + KListView::contentsMousePressEvent(e); +} + +//----------------------------------------------------------------------------- +void KFolderTree::contentsMouseReleaseEvent( TQMouseEvent *e ) +{ + KListView::contentsMouseReleaseEvent(e); + setSelectionModeExt(Extended); +} + +//----------------------------------------------------------------------------- +void KFolderTree::addAcceptableDropMimetype( const char *mimeType, bool outsideOk ) +{ + int oldSize = mAcceptableDropMimetypes.size(); + mAcceptableDropMimetypes.resize(oldSize+1); + mAcceptOutside.resize(oldSize+1); + + mAcceptableDropMimetypes.at(oldSize) = mimeType; + mAcceptOutside.setBit(oldSize, outsideOk); +} + +//----------------------------------------------------------------------------- +bool KFolderTree::acceptDrag( TQDropEvent* event ) const +{ + TQListViewItem* item = itemAt(contentsToViewport(event->pos())); + + for (uint i = 0; i < mAcceptableDropMimetypes.size(); i++) + { + if (event->provides(mAcceptableDropMimetypes[i])) + { + if (item) + return (static_cast(item))->acceptDrag(event); + else + return mAcceptOutside[i]; + } + } + return false; +} + +//----------------------------------------------------------------------------- +void KFolderTree::addUnreadColumn( const TQString & name, int width ) +{ + mUnreadIndex = addColumn( name, width ); + setColumnAlignment( mUnreadIndex, tqApp->reverseLayout() ? TQt::AlignLeft : TQt::AlignRight ); + header()->adjustHeaderSize(); +} + +//----------------------------------------------------------------------------- +void KFolderTree::addTotalColumn( const TQString & name, int width ) +{ + mTotalIndex = addColumn( name, width ); + setColumnAlignment( mTotalIndex, tqApp->reverseLayout() ? TQt::AlignLeft : TQt::AlignRight ); + header()->adjustHeaderSize(); +} + +//----------------------------------------------------------------------------- +void KFolderTree::removeUnreadColumn() +{ + if ( !isUnreadActive() ) return; + removeColumn( mUnreadIndex ); + if ( isTotalActive() && mTotalIndex > mUnreadIndex ) + mTotalIndex--; + if ( isSizeActive() && mSizeIndex > mUnreadIndex ) + mSizeIndex--; + + mUnreadIndex = -1; + header()->adjustHeaderSize(); +} + +//----------------------------------------------------------------------------- +void KFolderTree::removeTotalColumn() +{ + if ( !isTotalActive() ) return; + removeColumn( mTotalIndex ); + if ( isUnreadActive() && mTotalIndex < mUnreadIndex ) + mUnreadIndex--; + if ( isSizeActive() && mTotalIndex < mSizeIndex ) + mSizeIndex--; + mTotalIndex = -1; + header()->adjustHeaderSize(); +} + +//----------------------------------------------------------------------------- +void KFolderTree::addSizeColumn( const TQString & name, int width ) +{ + mSizeIndex = addColumn( name, width ); + setColumnAlignment( mSizeIndex, tqApp->reverseLayout() ? TQt::AlignLeft : TQt::AlignRight ); + header()->adjustHeaderSize(); +} + +//----------------------------------------------------------------------------- +void KFolderTree::removeSizeColumn() +{ + if ( !isSizeActive() ) return; + removeColumn( mSizeIndex ); + if ( isUnreadActive() && mSizeIndex < mUnreadIndex ) + mUnreadIndex--; + if ( isTotalActive() && mSizeIndex < mTotalIndex ) + mTotalIndex--; + mSizeIndex = -1; + header()->adjustHeaderSize(); +} + + +//----------------------------------------------------------------------------- +void KFolderTree::setFullWidth( bool fullWidth ) +{ + if (fullWidth) + header()->setStretchEnabled( true, 0 ); +} + +//----------------------------------------------------------------------------- +void KFolderTree::slotSizeChanged( int section, int, int newSize ) +{ + viewport()->tqrepaint( + header()->sectionPos(section), 0, newSize, visibleHeight(), false ); +} + +#include "kfoldertree.moc" diff --git a/libtdepim/kfoldertree.h b/libtdepim/kfoldertree.h new file mode 100644 index 000000000..5ee255731 --- /dev/null +++ b/libtdepim/kfoldertree.h @@ -0,0 +1,319 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- + + This file is part of libtdepim. + + Copyright (C) 2002 Carsten Burghardt + Copyright (C) 2002 Marc Mutz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef __KFOLDERTREE +#define __KFOLDERTREE + +#include +#include +#include +#include +#include +#include + +class KFolderTree; + +/** Information shared by all items in a list view */ +struct KPaintInfo { + + // Popup ids for toggle-able columns + enum ColumnIds + { + COL_SIZE, + COL_ATTACHMENT, + COL_INVITATION, + COL_IMPORTANT, + COL_TODO, + COL_SPAM_HAM, + COL_WATCHED_IGNORED, + COL_STATUS, + COL_SIGNED, + COL_CRYPTO, + COL_RECEIVER, + COL_SCORE + }; + + KPaintInfo() : + pixmapOn(false), + + showSize(false), + showAttachment(false), + showInvitation(false), + showImportant(false), + showTodo(false), + showSpamHam(false), + showWatchedIgnored(false), + showtqStatus(false), + showSigned(false), + showCrypto(false), + showReceiver(false), + showScore(false), + + scoreCol(-1), + flagCol(-1), + senderCol(-1), + receiverCol(-1), + subCol(-1), + dateCol(-1), + sizeCol(-1), + attachmentCol(-1), + invitationCol(-1), + importantCol(-1), + todoCol(-1), + spamHamCol(-1), + watchedIgnoredCol(-1), + statusCol(-1), + signedCol(-1), + cryptoCol(-1), + + orderOfArrival(false), + status(false), + showCryptoIcons(false), + showAttachmentIcon(false), + showInvitationIcon(false) + {} + + bool pixmapOn; + TQPixmap pixmap; + TQColor colFore; + TQColor colBack; + TQColor colNew; + TQColor colUnread; + TQColor colFlag; + TQColor colTodo; + TQColor colCloseToQuota; + + bool showSize; + bool showAttachment; + bool showInvitation; + bool showImportant; + bool showTodo; + bool showSpamHam; + bool showWatchedIgnored; + bool showtqStatus; + bool showSigned; + bool showCrypto; + bool showReceiver; + bool showScore; + + int scoreCol; + int flagCol; + int senderCol; + int receiverCol; + int subCol; + int dateCol; + int sizeCol; + int attachmentCol; + int invitationCol; + int importantCol; + int todoCol; + int spamHamCol; + int watchedIgnoredCol; + int statusCol; + int signedCol; + int cryptoCol; + + bool orderOfArrival; + bool status; + bool showCryptoIcons; + bool showAttachmentIcon; + bool showInvitationIcon; +}; + +//========================================================================== + +class KDE_EXPORT KFolderTreeItem : public KListViewItem +{ + public: + /** Protocol information */ + enum Protocol { + Imap, + Local, + News, + CachedImap, + Search, + NONE + }; + + /** Type information */ + enum Type { + Inbox, + Outbox, + SentMail, + Trash, + Drafts, + Templates, + Root, + Calendar, + Tasks, + Journals, + Contacts, + Notes, + Other + }; + + /** constructs a root-item */ + KFolderTreeItem( KFolderTree *parent, const TQString & label=TQString(), + Protocol protocol=NONE, Type type=Root ); + + /** constructs a child-item */ + KFolderTreeItem( KFolderTreeItem *parent, const TQString & label=TQString(), + Protocol protocol=NONE, Type type=Other, int unread=0, int total=0 ); + + /** compare */ + virtual int compare( TQListViewItem * i, int col, + bool ascending ) const; + + /** set/get the unread-count */ + int unreadCount() { return mUnread; } + virtual void setUnreadCount( int aUnread ); + + /** set/get the total-count */ + int totalCount() { return mTotal; } + virtual void setTotalCount( int aTotal ); + + /** set/get the total-count */ + TQ_INT64 folderSize() { return mSize; } + virtual void setFolderSize( TQ_INT64 aSize ); + + /** set/get the protocol of the item */ + Protocol protocol() const { return mProtocol; } + virtual void setProtocol( Protocol aProtocol ) { mProtocol = aProtocol; } + + /** set/get the type of the item */ + Type type() const { return mType; } + virtual void setType( Type aType ) { mType = aType; } + + /** recursive unread count */ + virtual int countUnreadRecursive(); + + virtual TQ_INT64 recursiveFolderSize() const; + + /** paints the cell */ + virtual void paintCell( TQPainter * p, const TQColorGroup & cg, + int column, int width, int align ); + + /** dnd */ + virtual bool acceptDrag(TQDropEvent* ) const { return true; } + + void setFolderIsCloseToQuota( bool ); + bool folderIsCloseToQuota() const; + + private: + /** returns a sorting key based on the folder's protocol */ + int protocolSortingKey() const; + /** returns a sorting key based on the folder's type */ + int typeSortingKey() const; + + protected: + /** reimplement to use special squeezing algorithm for the folder name */ + virtual TQString squeezeFolderName( const TQString &text, + const TQFontMetrics &fm, + uint width ) const; + + Protocol mProtocol; + Type mType; + int mUnread; + int mTotal; + TQ_INT64 mSize; + bool mFolderIsCloseToQuota; +}; + +//========================================================================== + +class KDE_EXPORT KFolderTree : public KListView +{ + Q_OBJECT + TQ_OBJECT + + public: + KFolderTree( TQWidget *parent, const char *name=0 ); + + /** registers MIMETypes that are handled + @param mimeType the name of the MIMEType + @param outsideOk accept drops of this type even if + the mouse cursor is not on top of an item */ + virtual void addAcceptableDropMimetype( const char *mimeType, bool outsideOk ); + + /** checks if the drag is acceptable */ + virtual bool acceptDrag( TQDropEvent* event ) const; + + /** returns the KPaintInfo */ + KPaintInfo paintInfo() const { return mPaintInfo; } + + /** add/remove unread/total-columns */ + virtual void addUnreadColumn( const TQString & name, int width=70 ); + virtual void removeUnreadColumn(); + virtual void addTotalColumn( const TQString & name, int width=70 ); + virtual void removeTotalColumn(); + virtual void addSizeColumn( const TQString & name, int width=70 ); + virtual void removeSizeColumn(); + + + /** the current index of the unread/total column */ + int unreadIndex() const { return mUnreadIndex; } + int totalIndex() const { return mTotalIndex; } + int sizeIndex() const { return mSizeIndex; } + + /** is the unread/total-column active? */ + bool isUnreadActive() const { return mUnreadIndex >= 0; } + bool isTotalActive() const { return mTotalIndex >= 0; } + bool isSizeActive() const { return mSizeIndex >= 0; } + + /** reimp to set full width of the _first_ column */ + virtual void setFullWidth( bool fullWidth ); + + protected: + /** reimplemented in order to update the frame width in case of a changed + GUI style */ + void styleChange( TQStyle& oldStyle ); + + /** Set the width of the frame to a reasonable value for the current GUI + style */ + void setStyleDependantFrameWidth(); + + virtual void drawContentsOffset( TQPainter * p, int ox, int oy, + int cx, int cy, int cw, int ch ); + + virtual void contentsMousePressEvent( TQMouseEvent *e ); + virtual void contentsMouseReleaseEvent( TQMouseEvent *e ); + + /** for mimetypes */ + TQMemArray mAcceptableDropMimetypes; + TQBitArray mAcceptOutside; + + /** shared information */ // ### why isn't it then static? ;-) + KPaintInfo mPaintInfo; + + /** current index of unread/total-column + * -1 is deactivated */ + int mUnreadIndex; + int mTotalIndex; + int mSizeIndex; + + private slots: + /** repaints the complete column (instead of only parts of it as done in + TQListView) if the size has changed */ + void slotSizeChanged( int section, int oldSize, int newSize ); + +}; + +#endif diff --git a/libtdepim/kimportdialog.cpp b/libtdepim/kimportdialog.cpp new file mode 100644 index 000000000..da6c98fad --- /dev/null +++ b/libtdepim/kimportdialog.cpp @@ -0,0 +1,767 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Cornelius Schumacher + Copyright (c) 2002 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// Generic CSV import. Please do not add application specific code to this +// class. Application specific code should go to a subclass provided by the +// application using this dialog. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kimportdialog.h" +#include "kimportdialog.moc" + +KImportColumn::KImportColumn(KImportDialog *dlg,const TQString &header, int count) + : m_maxCount(count), + m_refCount(0), + m_header(header), + mDialog(dlg) +{ + mFormats.append(FormatPlain); + mFormats.append(FormatUnquoted); +// mFormats.append(FormatBracketed); + + mDefaultFormat = FormatUnquoted; + + mDialog->addColumn(this); +} + +TQValueList KImportColumn::formats() +{ + return mFormats; +} + +TQString KImportColumn::formatName(int format) +{ + switch (format) { + case FormatPlain: + return i18n("Plain"); + case FormatUnquoted: + return i18n("Unquoted"); + case FormatBracketed: + return i18n("Bracketed"); + default: + return i18n("Undefined"); + } +} + +int KImportColumn::defaultFormat() +{ + return mDefaultFormat; +} + +TQString KImportColumn::preview(const TQString &value, int format) +{ + if (format == FormatBracketed) { + return "(" + value + ")"; + } else if (format == FormatUnquoted) { + if (value.left(1) == "\"" && value.right(1) == "\"") { + return value.mid(1,value.length()-2); + } else { + return value; + } + } else { + return value; + } +} + +void KImportColumn::addColId(int id) +{ + mColIds.append(id); +} + +void KImportColumn::removeColId(int id) +{ + mColIds.remove(id); +} + +TQValueList KImportColumn::colIdList() +{ + return mColIds; +} + +TQString KImportColumn::convert() +{ + TQValueList::ConstIterator it = mColIds.begin(); + if (it == mColIds.end()) return ""; + else return mDialog->cell(*it); +} + + +class ColumnItem : public TQListViewItem { + public: + ColumnItem(KImportColumn *col,TQListView *parent) : TQListViewItem(parent), mColumn(col) + { + setText(0,mColumn->header()); + } + + KImportColumn *column() { return mColumn; } + + private: + KImportColumn *mColumn; +}; + +/** + This is a generic class for importing line-oriented data from text files. It + provides a dialog for file selection, preview, separator selection and column + assignment as well as generic conversion routines. For conversion to special + data objects, this class has to be inherited by a special class, which + reimplements the convertRow() function. +*/ +KImportDialog::KImportDialog(TQWidget* parent) + : KDialogBase(parent,"importdialog",true,i18n("Import Text File"),Ok|Cancel), + mSeparator(","), + mCurrentRow(0) +{ + mData.setAutoDelete( true ); + + TQVBox *topBox = new TQVBox(this); + setMainWidget(topBox); + topBox->setSpacing(spacingHint()); + + TQHBox *fileBox = new TQHBox(topBox); + fileBox->setSpacing(spacingHint()); + new TQLabel(i18n("File to import:"),fileBox); + KURLRequester *urlRequester = new KURLRequester(fileBox); + urlRequester->setFilter( "*.csv" ); + connect(urlRequester,TQT_SIGNAL(returnPressed(const TQString &)), + TQT_SLOT(setFile(const TQString &))); + connect(urlRequester,TQT_SIGNAL(urlSelected(const TQString &)), + TQT_SLOT(setFile(const TQString &))); + connect(urlRequester->lineEdit(),TQT_SIGNAL(textChanged ( const TQString & )), + TQT_SLOT(slotUrlChanged(const TQString & ))); + mTable = new TQTable(5,5,topBox); + mTable->setMinimumHeight( 150 ); + connect(mTable,TQT_SIGNAL(selectionChanged()),TQT_SLOT(tableSelected())); + + TQHBox *separatorBox = new TQHBox( topBox ); + separatorBox->setSpacing( spacingHint() ); + + new TQLabel( i18n( "Separator:" ), separatorBox ); + + mSeparatorCombo = new KComboBox( separatorBox ); + mSeparatorCombo->insertItem( "," ); + mSeparatorCombo->insertItem( i18n( "Tab" ) ); + mSeparatorCombo->insertItem( i18n( "Space" ) ); + mSeparatorCombo->insertItem( "=" ); + mSeparatorCombo->insertItem( ";" ); + connect(mSeparatorCombo, TQT_SIGNAL( activated(int) ), + this, TQT_SLOT( separatorClicked(int) ) ); + mSeparatorCombo->setCurrentItem( 0 ); + + TQHBox *rowsBox = new TQHBox( topBox ); + rowsBox->setSpacing( spacingHint() ); + + new TQLabel( i18n( "Import starts at row:" ), rowsBox ); + mStartRow = new TQSpinBox( rowsBox ); + mStartRow->setMinValue( 1 ); +/* + new TQLabel( i18n( "And ends at row:" ), rowsBox ); + mEndRow = new TQSpinBox( rowsBox ); + mEndRow->setMinValue( 1 ); +*/ + TQVBox *assignBox = new TQVBox(topBox); + assignBox->setSpacing(spacingHint()); + + TQHBox *listsBox = new TQHBox(assignBox); + listsBox->setSpacing(spacingHint()); + + mHeaderList = new TQListView(listsBox); + mHeaderList->addColumn(i18n("Header")); + connect(mHeaderList, TQT_SIGNAL(selectionChanged(TQListViewItem*)), + this, TQT_SLOT(headerSelected(TQListViewItem*))); + connect(mHeaderList,TQT_SIGNAL(doubleClicked(TQListViewItem*)), + TQT_SLOT(assignColumn(TQListViewItem *))); + + mFormatCombo = new KComboBox( listsBox ); + mFormatCombo->setDuplicatesEnabled( false ); + + TQPushButton *assignButton = new TQPushButton(i18n("Assign to Selected Column"), + assignBox); + connect(assignButton,TQT_SIGNAL(clicked()),TQT_SLOT(assignColumn())); + + TQPushButton *removeButton = new TQPushButton(i18n("Remove Assignment From Selected Column"), + assignBox); + connect(removeButton,TQT_SIGNAL(clicked()),TQT_SLOT(removeColumn())); + + TQPushButton *assignTemplateButton = new TQPushButton(i18n("Assign with Template..."), + assignBox); + connect(assignTemplateButton,TQT_SIGNAL(clicked()),TQT_SLOT(assignTemplate())); + + TQPushButton *saveTemplateButton = new TQPushButton(i18n("Save Current Template"), + assignBox); + connect(saveTemplateButton,TQT_SIGNAL(clicked()),TQT_SLOT(saveTemplate())); + + resize(500,300); + + connect(this,TQT_SIGNAL(okClicked()),TQT_SLOT(applyConverter())); + connect(this,TQT_SIGNAL(applyClicked()),TQT_SLOT(applyConverter())); + enableButtonOK(!urlRequester->lineEdit()->text().isEmpty()); +} + +void KImportDialog::slotUrlChanged(const TQString & text) +{ + enableButtonOK(!text.isEmpty()); +} + +bool KImportDialog::setFile(const TQString& file) +{ + enableButtonOK(!file.isEmpty()); + kdDebug(5300) << "KImportDialog::setFile(): " << file << endl; + + TQFile f(file); + + if (f.open(IO_ReadOnly)) { + mFile = ""; + TQTextStream t(&f); + mFile = t.read(); +// while (!t.eof()) mFile.append(t.readLine()); + f.close(); + + readFile(); + +// mEndRow->setValue( mData.count() ); + + return true; + } else { + kdDebug(5300) << " Open failed" << endl; + return false; + } +} + +void KImportDialog::registerColumns() +{ + TQPtrListIterator colIt(mColumns); + for (; colIt.current(); ++colIt) { + new ColumnItem(*colIt,mHeaderList); + } + mHeaderList->setSelected(mHeaderList->firstChild(),true); +} + +void KImportDialog::fillTable() +{ +// kdDebug(5300) << "KImportDialog::fillTable()" << endl; + + int row, column; + + for (row = 0; row < mTable->numRows(); ++row) + for (column = 0; column < mTable->numCols(); ++column) + mTable->clearCell(row, column); + + for ( row = 0; row < int(mData.count()); ++row ) { + TQValueVector *rowVector = mData[ row ]; + for( column = 0; column < int(rowVector->size()); ++column ) { + setCellText( row, column, rowVector->at( column ) ); + } + } +} + +void KImportDialog::readFile( int rows ) +{ + kdDebug(5300) << "KImportDialog::readFile(): " << rows << endl; + + mData.clear(); + + int row, column; + enum { S_START, S_TQUOTED_FIELD, S_MAYBE_END_OF_TQUOTED_FIELD, S_END_OF_TQUOTED_FIELD, + S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; + + TQChar m_textquote = '"'; + int m_startline = 0; + + TQChar x; + TQString field = ""; + + row = column = 0; + TQTextStream inputStream(mFile, IO_ReadOnly); + inputStream.setEncoding(TQTextStream::Locale); + + KProgressDialog pDialog(this, 0, i18n("Loading Progress"), + i18n("Please wait while the file is loaded."), true); + pDialog.setAllowCancel(true); + pDialog.showCancelButton(true); + pDialog.setAutoClose(true); + + KProgress *progress = pDialog.progressBar(); + progress->setTotalSteps( mFile.contains(mSeparator, false) ); + progress->setValue(0); + int progressValue = 0; + + if (progress->totalSteps() > 0) // We have data + pDialog.show(); + + while (!inputStream.atEnd() && !pDialog.wasCancelled()) { + inputStream >> x; // read one char + + // update the dialog if needed + if (x == mSeparator) + { + progress->setValue(progressValue++); + if (progressValue % 15 == 0) // try not to constantly tqrepaint + kapp->processEvents(); + } + + if (x == '\r') inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly + + switch (state) { + case S_START : + if (x == m_textquote) { + field += x; + state = S_TQUOTED_FIELD; + } else if (x == mSeparator) { + ++column; + } else if (x == '\n') { + ++row; + column = 0; + } else { + field += x; + state = S_MAYBE_NORMAL_FIELD; + } + break; + case S_TQUOTED_FIELD : + if (x == m_textquote) { + field += x; + state = S_MAYBE_END_OF_TQUOTED_FIELD; + } else if (x == '\n') { + setData(row - m_startline, column, field); + field = ""; + if (x == '\n') { + ++row; + column = 0; + } else { + ++column; + } + state = S_START; + } else { + field += x; + } + break; + case S_MAYBE_END_OF_TQUOTED_FIELD : + if (x == m_textquote) { + field += x; + state = S_TQUOTED_FIELD; + } else if (x == mSeparator || x == '\n') { + setData(row - m_startline, column, field); + field = ""; + if (x == '\n') { + ++row; + column = 0; + } else { + ++column; + } + state = S_START; + } else { + state = S_END_OF_TQUOTED_FIELD; + } + break; + case S_END_OF_TQUOTED_FIELD : + if (x == mSeparator || x == '\n') { + setData(row - m_startline, column, field); + field = ""; + if (x == '\n') { + ++row; + column = 0; + } else { + ++column; + } + state = S_START; + } else { + state = S_END_OF_TQUOTED_FIELD; + } + break; + case S_MAYBE_NORMAL_FIELD : + if (x == m_textquote) { + field = ""; + state = S_TQUOTED_FIELD; + } + case S_NORMAL_FIELD : + if (x == mSeparator || x == '\n') { + setData(row - m_startline, column, field); + field = ""; + if (x == '\n') { + ++row; + column = 0; + } else { + ++column; + } + state = S_START; + } else { + field += x; + } + } + + if ( rows > 0 && row > rows ) break; + } + + fillTable(); +} + +void KImportDialog::setCellText(int row, int col, const TQString& text) +{ + if (row < 0) return; + + if ((mTable->numRows() - 1) < row) mTable->setNumRows(row + 1); + if ((mTable->numCols() - 1) < col) mTable->setNumCols(col + 1); + + KImportColumn *c = mColumnDict.find(col); + TQString formattedText; + if (c) formattedText = c->preview(text,findFormat(col)); + else formattedText = text; + mTable->setText(row, col, formattedText); +} + +void KImportDialog::formatSelected(TQListViewItem*) +{ +// kdDebug(5300) << "KImportDialog::formatSelected()" << endl; +} + +void KImportDialog::headerSelected(TQListViewItem* item) +{ + KImportColumn *col = ((ColumnItem *)item)->column(); + + if (!col) return; + + mFormatCombo->clear(); + + TQValueList formats = col->formats(); + + TQValueList::ConstIterator it = formats.begin(); + TQValueList::ConstIterator end = formats.end(); + while(it != end) { + mFormatCombo->insertItem( col->formatName(*it), *it - 1 ); + ++it; + } + + TQTableSelection selection = mTable->selection(mTable->currentSelection()); + + updateFormatSelection(selection.leftCol()); +} + +void KImportDialog::updateFormatSelection(int column) +{ + int format = findFormat(column); + + if ( format == KImportColumn::FormatUndefined ) + mFormatCombo->setCurrentItem( 0 ); + else + mFormatCombo->setCurrentItem( format - 1 ); +} + +void KImportDialog::tableSelected() +{ + TQTableSelection selection = mTable->selection(mTable->currentSelection()); + + TQListViewItem *item = mHeaderList->firstChild(); + KImportColumn *col = mColumnDict.find(selection.leftCol()); + if (col) { + while(item) { + if (item->text(0) == col->header()) { + break; + } + item = item->nextSibling(); + } + } + if (item) { + mHeaderList->setSelected(item,true); + } + + updateFormatSelection(selection.leftCol()); +} + +void KImportDialog::separatorClicked(int id) +{ + switch(id) { + case 0: + mSeparator = ','; + break; + case 1: + mSeparator = '\t'; + break; + case 2: + mSeparator = ' '; + break; + case 3: + mSeparator = '='; + break; + case 4: + mSeparator = ';'; + break; + default: + mSeparator = ','; + break; + } + + readFile(); +} + +void KImportDialog::assignColumn(TQListViewItem *item) +{ + if (!item) return; + +// kdDebug(5300) << "KImportDialog::assignColumn(): current Col: " << mTable->currentColumn() +// << endl; + + ColumnItem *colItem = (ColumnItem *)item; + + TQTableSelection selection = mTable->selection(mTable->currentSelection()); + +// kdDebug(5300) << " l: " << selection.leftCol() << " r: " << selection.rightCol() << endl; + + for(int i=selection.leftCol();i<=selection.rightCol();++i) { + if (i >= 0) { + mTable->horizontalHeader()->setLabel(i,colItem->text(0)); + mColumnDict.replace(i,colItem->column()); + int format = mFormatCombo->currentItem() + 1; + mFormats.replace(i,format); + colItem->column()->addColId(i); + } + } + + readFile(); +} + +void KImportDialog::assignColumn() +{ + assignColumn(mHeaderList->currentItem()); +} + +void KImportDialog::assignTemplate() +{ + TQMap columnMap; + TQMap fileMap; + TQStringList templates; + + // load all template files + TQStringList list = KGlobal::dirs()->findAllResources( "data" , TQString( kapp->name() ) + + "/csv-templates/*.desktop", true, true ); + + for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) + { + KSimpleConfig config( *it, true ); + + if ( !config.hasGroup( "csv column map" ) ) + continue; + + config.setGroup( "Misc" ); + templates.append( config.readEntry( "Name" ) ); + fileMap.insert( config.readEntry( "Name" ), *it ); + } + + // let the user chose, what to take + bool ok = false; + TQString tmp; + tmp = KInputDialog::getItem( i18n( "Template Selection" ), + i18n( "Please select a template, that matches the CSV file:" ), + templates, 0, false, &ok, this ); + + if ( !ok ) + return; + + KSimpleConfig config( fileMap[ tmp ], true ); + config.setGroup( "General" ); + uint numColumns = config.readUnsignedNumEntry( "Columns" ); + int format = config.readNumEntry( "Format" ); + + // create the column map + config.setGroup( "csv column map" ); + for ( uint i = 0; i < numColumns; ++i ) { + int col = config.readNumEntry( TQString::number( i ) ); + columnMap.insert( i, col ); + } + + // apply the column map + for ( uint i = 0; i < columnMap.count(); ++i ) { + int tableColumn = columnMap[i]; + if ( tableColumn == -1 ) + continue; + KImportColumn *col = mColumns.at(i); + mTable->horizontalHeader()->setLabel( tableColumn, col->header() ); + mColumnDict.replace( tableColumn, col ); + mFormats.replace( tableColumn, format ); + col->addColId( tableColumn ); + } + + readFile(); +} + +void KImportDialog::removeColumn() +{ + TQTableSelection selection = mTable->selection(mTable->currentSelection()); + +// kdDebug(5300) << " l: " << selection.leftCol() << " r: " << selection.rightCol() << endl; + + for(int i=selection.leftCol();i<=selection.rightCol();++i) { + if (i >= 0) { + mTable->horizontalHeader()->setLabel(i,TQString::number(i+1)); + KImportColumn *col = mColumnDict.find(i); + if (col) { + mColumnDict.remove(i); + mFormats.remove(i); + col->removeColId(i); + } + } + } + + readFile(); +} + +void KImportDialog::applyConverter() +{ + kdDebug(5300) << "KImportDialog::applyConverter" << endl; + + KProgressDialog pDialog(this, 0, i18n("Importing Progress"), + i18n("Please wait while the data is imported."), true); + pDialog.setAllowCancel(true); + pDialog.showCancelButton(true); + pDialog.setAutoClose(true); + + KProgress *progress = pDialog.progressBar(); + progress->setTotalSteps( mTable->numRows()-1 ); + progress->setValue(0); + + readFile( 0 ); + + pDialog.show(); + for( uint i = mStartRow->value() - 1; i < mData.count() && !pDialog.wasCancelled(); ++i ) { + mCurrentRow = i; + progress->setValue(i); + if (i % 5 == 0) // try to avoid constantly processing events + kapp->processEvents(); + + convertRow(); + } +} + +int KImportDialog::findFormat(int column) +{ + TQMap::ConstIterator formatIt = mFormats.find(column); + int format; + if (formatIt == mFormats.end()) format = KImportColumn::FormatUndefined; + else format = *formatIt; + +// kdDebug(5300) << "KImportDialog::findformat(): " << column << ": " << format << endl; + + return format; +} + +TQString KImportDialog::cell(uint col) +{ + if ( col >= mData[ mCurrentRow ]->size() ) return ""; + else return data( mCurrentRow, col ); +} + +void KImportDialog::addColumn(KImportColumn *col) +{ + mColumns.append(col); +} + +void KImportDialog::setData( uint row, uint col, const TQString &value ) +{ + TQString val = value; + val.replace( "\\n", "\n" ); + + if ( row >= mData.count() ) { + mData.resize( row + 1 ); + } + + TQValueVector *rowVector = mData[ row ]; + if ( !rowVector ) { + rowVector = new TQValueVector; + mData.insert( row, rowVector ); + } + if ( col >= rowVector->size() ) { + rowVector->resize( col + 1 ); + } + + KImportColumn *c = mColumnDict.find( col ); + if ( c ) + rowVector->at( col ) = c->preview( val, findFormat(col) ); + else + rowVector->at( col ) = val; +} + +TQString KImportDialog::data( uint row, uint col ) +{ + return mData[ row ]->at( col ); +} + +void KImportDialog::saveTemplate() +{ + TQString fileName = KFileDialog::getSaveFileName( + locateLocal( "data", TQString( kapp->name() ) + "/csv-templates/" ), + "*.desktop", this ); + + if ( fileName.isEmpty() ) + return; + + if ( !fileName.contains( ".desktop" ) ) + fileName += ".desktop"; + + TQString name = KInputDialog::getText( i18n( "Template Name" ), i18n( "Please enter a name for the template:" ) ); + + if ( name.isEmpty() ) + return; + + KConfig config( fileName ); + config.setGroup( "General" ); + config.writeEntry( "Columns", mColumns.count() ); + config.writeEntry( "Format", mFormatCombo->currentItem() + 1 ); + + config.setGroup( "Misc" ); + config.writeEntry( "Name", name ); + + config.setGroup( "csv column map" ); + + KImportColumn *column; + uint counter = 0; + for ( column = mColumns.first(); column; column = mColumns.next() ) { + TQValueList list = column->colIdList(); + if ( list.count() > 0 ) + config.writeEntry( TQString::number( counter ), list[ 0 ] ); + else + config.writeEntry( TQString::number( counter ), -1 ); + counter++; + } + + config.sync(); +} diff --git a/libtdepim/kimportdialog.h b/libtdepim/kimportdialog.h new file mode 100644 index 000000000..abcbb3181 --- /dev/null +++ b/libtdepim/kimportdialog.h @@ -0,0 +1,137 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Cornelius Schumacher + Copyright (c) 2002 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KIMPORTDIALOG_H +#define KIMPORTDIALOG_H + +#include +#include +#include +#include +#include + +#include + +class TQTable; +class TQListView; + +class KImportDialog; +class KComboBox; + +class KImportColumn +{ + public: + enum { FormatUndefined = 0, FormatPlain, FormatUnquoted, FormatBracketed, FormatLast }; + + KImportColumn(KImportDialog *dlg, const TQString &header, int count = 0); + virtual ~KImportColumn() {} + + TQString header() const { return m_header; } + + TQValueList formats(); + TQString formatName(int format); + int defaultFormat(); + + TQString convert(); +// virtual void convert(const TQString &value,int format) = 0; + TQString preview(const TQString &value,int format); + + void addColId(int i); + void removeColId(int i); + + TQValueList colIdList(); + + protected: + + private: + int m_maxCount, m_refCount; + + TQString m_header; + TQValueList mFormats; + int mDefaultFormat; + + TQValueList mColIds; + + KImportDialog *mDialog; +}; + +class KImportDialog : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT + public: + KImportDialog(TQWidget* parent); + + public slots: + bool setFile(const TQString& file); + + TQString cell(uint row); + + void addColumn(KImportColumn *); + + protected: + void readFile( int rows = 10 ); + + void fillTable(); + void registerColumns(); + int findFormat(int column); + + virtual void convertRow() {} + + protected slots: + void separatorClicked(int id); + void formatSelected(TQListViewItem* item); + void headerSelected(TQListViewItem* item); + void assignColumn(TQListViewItem *); + void assignColumn(); + void assignTemplate(); + void removeColumn(); + void applyConverter(); + void tableSelected(); + void slotUrlChanged(const TQString & ); + void saveTemplate(); + + private: + void updateFormatSelection(int column); + void setCellText(int row, int col, const TQString& text); + + void setData( uint row, uint col, const TQString &text ); + TQString data( uint row, uint col ); + + TQListView *mHeaderList; + TQSpinBox *mStartRow; + TQSpinBox *mEndRow; + TQTable *mTable; + + KComboBox *mFormatCombo; + KComboBox *mSeparatorCombo; + + TQString mSeparator; + int mCurrentRow; + TQString mFile; + TQIntDict mColumnDict; + TQIntDict mTemplateDict; + TQMap mFormats; + TQPtrList mColumns; + TQPtrVector > mData; +}; + +#endif diff --git a/libtdepim/kincidencechooser.cpp b/libtdepim/kincidencechooser.cpp new file mode 100644 index 000000000..fee89bbb6 --- /dev/null +++ b/libtdepim/kincidencechooser.cpp @@ -0,0 +1,326 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Lutz Rogowski + + 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. + + As a special exception, permission is given to link this program + with any edition of TQt, and distribute the resulting executable, + without including the source code for TQt in the source distribution. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include + +#include "kincidencechooser.h" +#include "libkcal/incidence.h" +#include "libkcal/incidenceformatter.h" + +int KIncidenceChooser::chooseMode = KIncidenceChooser::ask ; + +KIncidenceChooser::KIncidenceChooser(TQWidget *parent, char *name) : + KDialog(parent,name,true) +{ + KDialog *topFrame = this; + TQGridLayout *topLayout = new TQGridLayout(topFrame,5,3); + int iii = 0; + setCaption( i18n("Conflict Detected")); + TQLabel * lab; + lab = new TQLabel( i18n( + "A conflict was detected. This probably means someone edited the same entry on the server while you changed it locally." + "
NOTE: You have to check mail again to apply your changes to the server.
"), topFrame); + topLayout->addMultiCellWidget(lab, iii,iii,0,2); + ++iii; + TQHBox * b_box = new TQHBox( topFrame ); + topLayout->addMultiCellWidget(b_box, iii,iii,0,2); + ++iii; + TQPushButton* button = new TQPushButton( i18n("Take Local"), b_box ); + connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeIncidence1() ) ); + button = new TQPushButton( i18n("Take New"), b_box ); + connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeIncidence2() ) ); + button = new TQPushButton( i18n("Take Both"), b_box ); + connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT (takeBoth() ) ); + topLayout->setSpacing(spacingHint()); + topLayout->setMargin(marginHint()); + // text is not translated, because text has to be set later + mInc1lab = new TQLabel ( i18n("Local incidence"), topFrame); + topLayout->addWidget(mInc1lab ,iii,0); + mInc1Sumlab = new TQLabel ( i18n("Local incidence summary"), topFrame); + topLayout->addMultiCellWidget(mInc1Sumlab, iii,iii,1,2); + ++iii; + topLayout->addWidget( new TQLabel ( i18n("Last modified:"), topFrame) ,iii,0); + mMod1lab = new TQLabel ( "Set Last modified", topFrame); + topLayout->addWidget(mMod1lab,iii,1); + mShowDetails1 = new TQPushButton( i18n("Show Details"),topFrame ); + connect ( mShowDetails1, TQT_SIGNAL( clicked()), this, TQT_SLOT (showIncidence1() ) ); + topLayout->addWidget(mShowDetails1,iii,2); + ++iii; + + mInc2lab = new TQLabel ( "Local incidence", topFrame); + topLayout->addWidget(mInc2lab,iii,0); + mInc2Sumlab = new TQLabel ( "Local incidence summary", topFrame); + topLayout->addMultiCellWidget(mInc2Sumlab, iii,iii,1,2); + ++iii; + topLayout->addWidget( new TQLabel ( i18n("Last modified:"), topFrame) ,iii,0); + mMod2lab = new TQLabel ( "Set Last modified", topFrame); + topLayout->addWidget(mMod2lab,iii,1); + mShowDetails2 = new TQPushButton( i18n("Show Details"), topFrame); + connect ( mShowDetails2, TQT_SIGNAL( clicked()), this, TQT_SLOT (showIncidence2() ) ); + topLayout->addWidget(mShowDetails2,iii,2); + ++iii; + // +#if 0 + // commented out for now, because the diff code has too many bugs + mDiffBut = new TQPushButton( i18n("Show Differences"), topFrame ); + connect ( mDiffBut, TQT_SIGNAL( clicked()), this, TQT_SLOT ( showDiff() ) ); + topLayout->addMultiCellWidget(mDiffBut, iii,iii,0,2); + ++iii; +#else + mDiffBut = 0; +#endif + mBg = new TQButtonGroup ( 1, Qt::Horizontal, i18n("Sync Preferences"), topFrame); + topLayout->addMultiCellWidget(mBg, iii,iii,0,2); + ++iii; + mBg->insert( new TQRadioButton ( i18n("Take local entry on conflict"), mBg ), KIncidenceChooser::local); + mBg->insert( new TQRadioButton ( i18n("Take new (remote) entry on conflict"), mBg ), KIncidenceChooser::remote); + mBg->insert( new TQRadioButton ( i18n("Take newest entry on conflict"), mBg ), KIncidenceChooser::newest ); + mBg->insert( new TQRadioButton ( i18n("Ask for every entry on conflict"), mBg ),KIncidenceChooser::ask ); + mBg->insert( new TQRadioButton ( i18n("Take both on conflict"), mBg ), KIncidenceChooser::both ); + mBg->setButton ( chooseMode ); + mTbL = 0; + mTbN = 0; + mDisplayDiff = 0; + mSelIncidence = 0; + button = new TQPushButton( i18n("Apply This to All Conflicts of This Sync"), topFrame ); + connect ( button, TQT_SIGNAL( clicked()), this, TQT_SLOT ( setSyncMode() ) ); + topLayout->addMultiCellWidget(button, iii,iii,0,2); +} + +KIncidenceChooser::~KIncidenceChooser() +{ + if ( mTbL ) delete mTbL; + if ( mTbN ) delete mTbN; + if ( mDisplayDiff ) { + delete mDisplayDiff; + delete diff; + } +} + +void KIncidenceChooser::setIncidence( KCal::Incidence* local ,KCal::Incidence* remote ) +{ + mInc1 = local; + mInc2 = remote; + setLabels(); + +} +KCal::Incidence* KIncidenceChooser::getIncidence( ) +{ + + KCal::Incidence* retval = mSelIncidence; + if ( chooseMode == KIncidenceChooser::local ) + retval = mInc1; + else if ( chooseMode == KIncidenceChooser::remote ) + retval = mInc2; + else if ( chooseMode == KIncidenceChooser::both ) { + retval = 0; + } + else if ( chooseMode == KIncidenceChooser::newest ) { + if ( mInc1->lastModified() == mInc2->lastModified()) + retval = 0; + if ( mInc1->lastModified() > mInc2->lastModified() ) + retval = mInc1; + else + retval = mInc2; + } + return retval; +} + +void KIncidenceChooser::setSyncMode() +{ + chooseMode = mBg->selectedId (); + if ( chooseMode != KIncidenceChooser::ask ) + TQDialog::accept(); + +} + +void KIncidenceChooser::useGlobalMode() +{ + if ( chooseMode != KIncidenceChooser::ask ) + TQDialog::reject(); +} + +void KIncidenceChooser::setLabels() +{ + KCal::Incidence* inc = mInc1; + TQLabel* des = mInc1lab; + TQLabel * sum = mInc1Sumlab; + + + if ( inc->type() == "Event" ) { + des->setText( i18n( "Local Event") ); + sum->setText( inc->summary().left( 30 )); + if ( mDiffBut ) + mDiffBut->setEnabled( true ); + } + else if ( inc->type() == "Todo" ) { + des->setText( i18n( "Local Todo") ); + sum->setText( inc->summary().left( 30 )); + if ( mDiffBut ) + mDiffBut->setEnabled( true ); + + } + else if ( inc->type() == "Journal" ) { + des->setText( i18n( "Local Journal") ); + sum->setText( inc->description().left( 30 )); + if ( mDiffBut ) + mDiffBut->setEnabled( false ); + } + mMod1lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() )); + inc = mInc2; + des = mInc2lab; + sum = mInc2Sumlab; + if ( inc->type() == "Event" ) { + des->setText( i18n( "New Event") ); + sum->setText( inc->summary().left( 30 )); + } + else if ( inc->type() == "Todo" ) { + des->setText( i18n( "New Todo") ); + sum->setText( inc->summary().left( 30 )); + + } + else if ( inc->type() == "Journal" ) { + des->setText( i18n( "New Journal") ); + sum->setText( inc->description().left( 30 )); + + } + mMod2lab->setText( KGlobal::locale()->formatDateTime(inc->lastModified() )); +} + +void KIncidenceChooser::showIncidence1() +{ + if ( mTbL ) { + if ( mTbL->isVisible() ) { + mShowDetails1->setText( i18n("Show Details")); + mTbL->hide(); + } else { + mShowDetails1->setText( i18n("Hide Details")); + mTbL->show(); + mTbL->raise(); + } + return; + } + mTbL = new KDialogBase( this, "", false /*not modal*/, mInc1lab->text(), KDialogBase::Ok ); + mTbL->setEscapeButton( KDialogBase::Ok ); + connect( mTbL, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( detailsDialogClosed() ) ); + TQTextBrowser* textBrowser = new TQTextBrowser( mTbL ); + mTbL->setMainWidget( textBrowser ); + textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc1 ) ); + mTbL->setMinimumSize( 400, 400 ); + mShowDetails1->setText( i18n("Hide Details")); + mTbL->show(); + mTbL->raise(); +} + +void KIncidenceChooser::detailsDialogClosed() +{ + KDialogBase* dialog = static_cast( TQT_TQWIDGET( const_cast(sender()) ) ); + if ( dialog == mTbL ) + mShowDetails1->setText( i18n( "Show details..." ) ); + else + mShowDetails2->setText( i18n( "Show details..." ) ); +} + +void KIncidenceChooser::showDiff() +{ + if ( mDisplayDiff ) { + mDisplayDiff->show(); + mDisplayDiff->raise(); + return; + } + mDisplayDiff = new KPIM::HTMLDiffAlgoDisplay (this); + if ( mInc1->summary().left( 20 ) != mInc2->summary().left( 20 ) ) + mDisplayDiff->setCaption( i18n( "Differences of %1 and %2").tqarg( mInc1->summary().left( 20 ) ).tqarg( mInc2->summary().left( 20 ) ) ); + else + mDisplayDiff->setCaption( i18n( "Differences of %1").tqarg( mInc1->summary().left( 20 ) ) ); + + diff = new KPIM::CalendarDiffAlgo( mInc1, mInc2); + diff->setLeftSourceTitle( i18n( "Local entry")); + diff->setRightSourceTitle(i18n( "New (remote) entry") ); + diff->addDisplay( mDisplayDiff ); + diff->run(); + mDisplayDiff->show(); + mDisplayDiff->raise(); +} + +void KIncidenceChooser::showIncidence2() +{ + if ( mTbN ) { + if ( mTbN->isVisible() ) { + mShowDetails2->setText( i18n("Show Details")); + mTbN->hide(); + } else { + mShowDetails2->setText( i18n("Hide Details")); + mTbN->show(); + mTbN->raise(); + } + return; + } + mTbN = new KDialogBase( this, "", false /*not modal*/, mInc2lab->text(), KDialogBase::Ok ); + mTbN->setEscapeButton( KDialogBase::Ok ); + connect( mTbN, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( detailsDialogClosed() ) ); + TQTextBrowser* textBrowser = new TQTextBrowser( mTbN ); + mTbN->setMainWidget( textBrowser ); + textBrowser->setText( KCal::IncidenceFormatter::extensiveDisplayString( mInc2 ) ); + mTbN->setMinimumSize( 400, 400 ); + mShowDetails2->setText( i18n("Hide Details")); + mTbN->show(); + mTbN->raise(); +} + +void KIncidenceChooser::takeIncidence1() +{ + mSelIncidence = mInc1; + TQDialog::accept(); +} + +void KIncidenceChooser::takeIncidence2() +{ + mSelIncidence = mInc2; + TQDialog::accept(); +} + +void KIncidenceChooser::takeBoth() +{ + + mSelIncidence = 0; + TQDialog::accept(); +} + + +#include "kincidencechooser.moc" diff --git a/libtdepim/kincidencechooser.h b/libtdepim/kincidencechooser.h new file mode 100644 index 000000000..0d8107f05 --- /dev/null +++ b/libtdepim/kincidencechooser.h @@ -0,0 +1,84 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Lutz Rogowski + + 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. + + As a special exception, permission is given to link this program + with any edition of TQt, and distribute the resulting executable, + without including the source code for TQt in the source distribution. +*/ +#ifndef _KINCIDENCECHOOSER_H +#define _KINCIDENCECHOOSER_H + +#include "calendardiffalgo.h" +#include "htmldiffalgodisplay.h" + +#include + +namespace KCal { + class Incidence; +} +using namespace KCal; + +class TQButtonGroup; + +/** Dialog to change the korganizer configuration. + */ + +class KDE_EXPORT KIncidenceChooser : public KDialog +{ + Q_OBJECT + TQ_OBJECT + public: + enum mode { + local, remote, newest, ask, both + }; + /** Initialize dialog and pages */ + KIncidenceChooser( TQWidget *parent=0, char *name=0 ); + ~KIncidenceChooser(); + //void setChooseText( TQString ); + void setIncidence( KCal::Incidence *, KCal::Incidence * ); + KCal::Incidence *getIncidence(); + static int chooseMode; + + public slots: + void useGlobalMode(); + + protected slots: + void showIncidence1(); + void showIncidence2(); + void showDiff(); + void takeIncidence1(); + void takeIncidence2(); + void takeBoth(); + void setLabels(); + void setSyncMode(); + void detailsDialogClosed(); + + private: + KPIM::HTMLDiffAlgoDisplay *mDisplayDiff; + KPIM::CalendarDiffAlgo *diff; + KDialogBase *mTbL, *mTbN; + KCal::Incidence *mSelIncidence; + KCal::Incidence *mInc1, *mInc2; + TQButtonGroup *mBg; + TQPushButton *mDiffBut,*mShowDetails1,*mShowDetails2; + TQLabel *mInc1lab, *mInc2lab,* mInc1Sumlab, *mInc2Sumlab,*mMod1lab,*mMod2lab; + +}; + +#endif diff --git a/libtdepim/kmailcompletion.cpp b/libtdepim/kmailcompletion.cpp new file mode 100644 index 000000000..d7fcc8ce4 --- /dev/null +++ b/libtdepim/kmailcompletion.cpp @@ -0,0 +1,103 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2006 Christian Schaarschmidt + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kmailcompletion.h" +#include + +#include + +using namespace KPIM; + +KMailCompletion::KMailCompletion() +{ + setIgnoreCase( true ); +} + +void KMailCompletion::clear() +{ + m_keyMap.clear(); + KCompletion::clear(); +} + +TQString KMailCompletion::makeCompletion( const TQString &string ) +{ + TQString match = KCompletion::makeCompletion( string ); + + // this should be in postProcessMatch, but postProcessMatch is const and will not allow nextMatch + if ( !match.isEmpty() ){ + const TQString firstMatch( match ); + while ( match.find( TQRegExp( "(@)|(<.*>)" ) ) == -1 ) { + /* local email do not require @domain part, if match is an address we'll find + * last+first in m_keyMap and we'll know that match is already a valid email. + * + * Distribution list do not have last+first entry, they will be in mailAddr + */ + const TQStringList &mailAddr = m_keyMap[ match ]; //get all mailAddr for this keyword + bool isEmail = false; + for ( TQStringList::ConstIterator sit ( mailAddr.begin() ), sEnd( mailAddr.end() ); sit != sEnd; ++sit ) + if ( (*sit).find( "<" + match + ">" ) != -1 || (*sit) == match ) { + isEmail = true; + break; + } + + if ( !isEmail ) { + // match is a keyword, skip it and try to find match + match = nextMatch(); + if ( firstMatch == match ){ + match = TQString(); + break; + } + } else + break; + } + } + return match; +} + +void KMailCompletion::addItemWithKeys( const TQString& email, int weight, const TQStringList* keyWords) +{ + Q_ASSERT( keyWords != 0 ); + for ( TQStringList::ConstIterator it( keyWords->begin() ); it != keyWords->end(); ++it ) { + TQStringList &emailList = m_keyMap[ (*it) ]; //lookup email-list for given keyword + if ( emailList.find( email ) == emailList.end() ) //add email if not there + emailList.append( email ); + addItem( (*it),weight ); //inform KCompletion about keyword + } +} + +void KMailCompletion::postProcessMatches( TQStringList * pMatches )const +{ + Q_ASSERT( pMatches != 0 ); + if ( pMatches->isEmpty() ) + return; + + //KCompletion has found the keywords for us, we can now map them to mail-addr + TQMap< TQString, bool > mailAddrDistinct; //TODO replace with TQSet in KDE4 + for ( TQStringList::ConstIterator sit ( pMatches->begin() ), sEnd( pMatches->end() ); sit != sEnd; ++sit ) { + const TQStringList &mailAddr = m_keyMap[ (*sit) ]; //get all mailAddr for this keyword + for ( TQStringList::ConstIterator sit ( mailAddr.begin() ), sEnd( mailAddr.end() ); sit != sEnd; ++sit ) { + mailAddrDistinct[ (*sit) ] = true; //store mailAddr, TQMap will make them unique + } + } + pMatches->clear(); //delete keywords + (*pMatches) += mailAddrDistinct.keys(); //add emailAddr +} +#include "kmailcompletion.moc" diff --git a/libtdepim/kmailcompletion.h b/libtdepim/kmailcompletion.h new file mode 100644 index 000000000..9251c2797 --- /dev/null +++ b/libtdepim/kmailcompletion.h @@ -0,0 +1,79 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2006 Christian Schaarschmidt + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KPIM_KMAILCOMPLETION_H +#define KPIM_KMAILCOMPLETION_H + +#include +#include +#include "kcompletion.h" + + +namespace KPIM { + +/** + * KMailCompletion allows lookup of email addresses by keyword. + * Typically a keywods would be firstname, lastname, nickname or domain. + */ +class KMailCompletion : public KCompletion +{ + Q_OBJECT + TQ_OBJECT + + public: + KMailCompletion(); + + /** + * Clears internal keyword map and calls KCompletion::clear. + */ + virtual void clear(); + + /** + * Uses KCompletion::makeCompletion to find email addresses which starts with string. + * ignores keywords. + * + * @returns email address + */ + TQString makeCompletion( const TQString &string ); + + /** + * Specify keywords for email. + * + * Items may be added with KCompletion::addItem, those will only be returned as match if they + * are in one of these formats: + * \li contains localpart@domain + * \li contains + * or if they have also been added with this function. + */ + void addItemWithKeys( const TQString& email, int weight, const TQStringList * keyWords); + + /** + * Uses an internal map to replace all keywords in pMatches whith corrsesponding email addresses. + */ + virtual void postProcessMatches( TQStringList * pMatches )const; + + private: + TQMap< TQString, TQStringList > m_keyMap; +}; + +} + +#endif diff --git a/libtdepim/komposer/Makefile.am b/libtdepim/komposer/Makefile.am new file mode 100644 index 000000000..13509925e --- /dev/null +++ b/libtdepim/komposer/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = core plugins test diff --git a/libtdepim/komposer/core/Makefile.am b/libtdepim/komposer/core/Makefile.am new file mode 100644 index 000000000..b494e7151 --- /dev/null +++ b/libtdepim/komposer/core/Makefile.am @@ -0,0 +1,28 @@ +AM_CPPFLAGS = -I$(top_builddir)/libtdepim $(all_includes) +METASOURCES = AUTO + +lib_LTLIBRARIES = libkomposer.la + +libkomposer_la_SOURCES = plugin.cpp editor.cpp core.cpp attachment.cpp corewidget.cpp \ + settings.kcfgc pluginmanager.cpp komposerIface.skel +libkomposer_la_LDFLAGS = -no-undefined $(KDE_RPATH) -version-info 1:0:0 $(all_libraries) +libkomposer_la_LIBADD = $(LIB_KPARTS) $(top_builddir)/libtdepim/libtdepim.la -lkutils + +#kde_module_LTLIBRARIES = kcm_komposer.la + +#kcm_komposer_la_SOURCES = prefsmodule.cpp +#kcm_komposer_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries) +#kcm_komposer_la_LIBADD = libkomposer.la $(top_builddir)/libtdepim/libtdepim.la $(LIB_KDECORE) + +kpincludedir = $(includedir)/komposer +kpinclude_HEADERS = plugin.h editor.h core.h + +rcdir = $(kde_datadir)/komposer +rc_DATA = komposerui.rc + +kde_kcfg_DATA = komposer.kcfg + +servicetypedir = $(kde_servicetypesdir) +servicetype_DATA = komposerplugin.desktop komposereditor.desktop + +kde_services_DATA = komposerconfig.desktop diff --git a/libtdepim/komposer/core/attachment.cpp b/libtdepim/komposer/core/attachment.cpp new file mode 100644 index 000000000..df803de60 --- /dev/null +++ b/libtdepim/komposer/core/attachment.cpp @@ -0,0 +1,112 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * attachment.cpp + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "attachment.h" + +using namespace Komposer; + +class Attachment::Private +{ +public: + TQString name; + TQCString cte; + TQByteArray data; + TQCString type; + TQCString subType; + TQCString paramAttr; + TQString paramValue; + TQCString contDisp; +}; + +Attachment::Attachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ) + : d( new Private ) +{ + d->name = name; + d->cte = cte; + d->data = data; + d->type = type; + d->subType = subType; + d->paramAttr = paramAttr; + d->paramValue = paramValue; + d->contDisp = contDisp; +} + +Attachment::~Attachment() +{ + delete d; d = 0; +} + +TQString +Attachment::name() const +{ + return d->name; +} + +TQCString +Attachment::cte() const +{ + return d->cte; +} + +TQByteArray +Attachment::data() const +{ + return d->data; +} + +TQCString +Attachment::type() const +{ + return d->type; +} + + +TQCString +Attachment::subType() const +{ + return d->subType; +} + +TQCString +Attachment::paramAttr() const +{ + return d->paramAttr; +} + +TQString +Attachment::paramValue() const +{ + return d->paramValue; +} + +TQCString +Attachment::contentDisposition() const +{ + return d->contDisp; +} + diff --git a/libtdepim/komposer/core/attachment.h b/libtdepim/komposer/core/attachment.h new file mode 100644 index 000000000..5c4e1ebf2 --- /dev/null +++ b/libtdepim/komposer/core/attachment.h @@ -0,0 +1,61 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * attachment.h + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSER_ATTACHMENT_H +#define KOMPOSER_ATTACHMENT_H + +#include +#include +#include + +namespace Komposer +{ + + class Attachment + { + public: + Attachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ); + ~Attachment(); + + TQString name() const; + TQCString cte() const; + TQByteArray data() const; + TQCString type() const; + TQCString subType() const; + TQCString paramAttr() const; + TQString paramValue() const; + TQCString contentDisposition() const; + + private: + class Private; + Private *d; + }; + typedef TQValueList AttachmentList; +} + +#endif diff --git a/libtdepim/komposer/core/core.cpp b/libtdepim/komposer/core/core.cpp new file mode 100644 index 000000000..f93e59cc9 --- /dev/null +++ b/libtdepim/komposer/core/core.cpp @@ -0,0 +1,357 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * core.cpp + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "core.h" + +#include "pluginmanager.h" +#include "editor.h" +#include "plugin.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace Komposer; + +Core::Core( TQWidget *parent, const char *name ) + : KomposerIface( "KomposerIface" ), + KMainWindow( parent, name ), m_currentEditor( 0 ) +{ + initWidgets(); + initCore(); + initConnections(); + setInstance( new KInstance( "komposer" ) ); + + createActions(); + setXMLFile( "komposerui.rc" ); + + createGUI( 0 ); + + resize( 600, 400 ); // initial size + setAutoSaveSettings(); + + loadSettings(); +} + +Core::~Core() +{ + saveSettings(); + + //Prefs::self()->writeConfig(); +} + +void +Core::addEditor( Komposer::Editor *editor ) +{ + if ( editor->widget() ) { + m_stack->addWidget( editor->widget() ); + m_stack->raiseWidget( editor->widget() ); + editor->widget()->show(); + m_currentEditor = editor; + } + + // merge the editors GUI into the main window + //insertChildClient( editor ); + guiFactory()->addClient( editor ); +} + +void +Core::addPlugin( Komposer::Plugin *plugin ) +{ + //insertChildClient( plugin ); + guiFactory()->addClient( plugin ); +} + +void +Core::slotPluginLoaded( Plugin *plugin ) +{ + kdDebug() << "Plugin loaded "<( plugin ); + if ( editor ) { + addEditor( editor ); + } else { + addPlugin( plugin ); + } +} + +void +Core::slotAllPluginsLoaded() +{ + TQValueList plugins = m_pluginManager->availablePlugins(); + kdDebug()<<"Number of available plugins is "<< plugins.count() <::iterator it = plugins.begin(); it != plugins.end(); ++it ) { + KPluginInfo *i = ( *it ); + kdDebug()<<"\tAvailable plugin "<< i->pluginName() + <<", comment = "<< i->comment() <visibleWidget() ) { + m_pluginManager->loadPlugin( "komposer_defaulteditor", PluginManager::LoadAsync ); + } +} + +#if 0 +void +Core::slotActivePartChanged( KParts::Part *part ) +{ + if ( !part ) { + createGUI( 0 ); + return; + } + + kdDebug() << "Part activated: " << part << " with stack id. " + << m_stack->id( part->widget() )<< endl; + + createGUI( part ); +} + +void +Core::selectEditor( Komposer::Editor *editor ) +{ + if ( !editor ) + return; + + KParts::Part *part = editor->part(); + + editor->select(); + + TQPtrList *partList = const_cast*>( + m_partManager->parts() ); + if ( partList->find( part ) == -1 ) + addPart( part ); + + m_partManager->setActivePart( part ); + TQWidget *view = part->widget(); + Q_ASSERT( view ); + + kdDebug()<<"Raising view "<raiseWidget( view ); + view->show(); + view->setFocus(); + m_currentEditor = editor; + } +} + +void +Core::selectEditor( const TQString &editorName ) +{ + +} +#endif + +void +Core::loadSettings() +{ + //kdDebug()<<"Trying to select "<< Prefs::self()->m_activeEditor <m_activeEditor ); + + //m_activeEditors = Prefs::self()->m_activeEditors; +} + +void +Core::saveSettings() +{ + //if ( m_currentEditor ) + //Prefs::self()->m_activeEditor = m_currentEditor->identifier(); +} + +void +Core::slotQuit() +{ + kdDebug()<<"exit"<shutdown(); +} + +void +Core::slotPreferences() +{ + if ( m_dlg == 0 ) + m_dlg = new KSettings::Dialog( this ); + m_dlg->show(); +} + +void +Core::initWidgets() +{ + statusBar()->show(); + TQHBox *topWidget = new TQHBox( this ); + setCentralWidget( topWidget ); + m_stack = new TQWidgetStack( topWidget ); +} + +void +Core::initCore() +{ + m_pluginManager = new PluginManager( this ); + connect( m_pluginManager, TQT_SIGNAL(pluginLoaded(Plugin*)), + TQT_SLOT(slotPluginLoaded(Plugin*)) ); + connect( m_pluginManager, TQT_SIGNAL(allPluginsLoaded()), + TQT_SLOT(slotAllPluginsLoaded()) ); + + + m_pluginManager->loadAllPlugins(); + kdDebug()<<"Loading"<setText( body ); +} + +void +Core::addAttachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ) +{ + +} + +#include "core.moc" diff --git a/libtdepim/komposer/core/core.h b/libtdepim/komposer/core/core.h new file mode 100644 index 000000000..91487572a --- /dev/null +++ b/libtdepim/komposer/core/core.h @@ -0,0 +1,108 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * core.h + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSER_CORE_H +#define KOMPOSER_CORE_H + +#include "komposerIface.h" + +#include +#include + +namespace KSettings { + class Dialog; +} +class TQWidgetStack; + +namespace Komposer +{ + + class Editor; + class Plugin; + class PluginManager; + + /** + * This class provides the interface to the Komposer core for the editor. + */ + class Core : public KMainWindow, virtual public KomposerIface + { + Q_OBJECT + TQ_OBJECT + public: + Core( TQWidget *parentWidget = 0, const char *name = 0 ); + virtual ~Core(); + + public slots: + virtual void send( int how ); + virtual void addAttachment( const KURL &url, const TQString &comment ); + virtual void setBody( const TQString &body ); + virtual void addAttachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ); + + + + protected slots: + //void slotActivePartChanged( KParts::Part *part ); + void slotPluginLoaded( Plugin* ); + void slotAllPluginsLoaded(); + void slotPreferences(); + void slotQuit(); + void slotClose(); + + void slotSendNow(); + void slotSendLater(); + void slotSaveDraft(); + void slotInsertFile(); + void slotAddrBook(); + void slotNewComposer(); + void slotAttachFile(); + + protected: + virtual void initWidgets(); + void initCore(); + void initConnections(); + void loadSettings(); + void saveSettings(); + void createActions(); + + void addEditor( Komposer::Editor *editor ); + void addPlugin( Komposer::Plugin *plugin ); + + private: + TQWidgetStack *m_stack; + Editor *m_currentEditor; + PluginManager *m_pluginManager; + + KSettings::Dialog *m_dlg; + + class Private; + Private *d; +}; + +} + +#endif diff --git a/libtdepim/komposer/core/corewidget.cpp b/libtdepim/komposer/core/corewidget.cpp new file mode 100644 index 000000000..c65893766 --- /dev/null +++ b/libtdepim/komposer/core/corewidget.cpp @@ -0,0 +1,32 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * corewidget.cpp + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "corewidget.h" + +using namespace Komposer; + +CoreWidget::CoreWidget( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ +} + +#include "corewidget.moc" diff --git a/libtdepim/komposer/core/corewidget.h b/libtdepim/komposer/core/corewidget.h new file mode 100644 index 000000000..7d2acc6db --- /dev/null +++ b/libtdepim/komposer/core/corewidget.h @@ -0,0 +1,49 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * corewidget.h + * + * Copyright (C) 2003-2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef COREWIDGET_H +#define COREWIDGET_H + +#include "attachment.h" + +#include + +namespace Komposer +{ + + class CoreWidget : public TQWidget + { + Q_OBJECT + TQ_OBJECT + public: + CoreWidget( TQWidget *parent, const char *name=0 ); + + virtual TQString subject() const =0; + virtual TQStringList to() const =0; + virtual TQStringList cc() const =0; + virtual TQStringList bcc() const =0; + virtual TQString from() const =0; + virtual TQString replyTo() const =0; + virtual AttachmentList attachments() const =0; + }; +} + +#endif diff --git a/libtdepim/komposer/core/editor.cpp b/libtdepim/komposer/core/editor.cpp new file mode 100644 index 000000000..5dada393f --- /dev/null +++ b/libtdepim/komposer/core/editor.cpp @@ -0,0 +1,51 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * editor.cpp + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "editor.h" +#include "core.h" + +namespace Komposer { + +class Editor::Private { +public: + TQString id; +}; + +Editor::Editor( TQObject *parent, const char *name, const TQStringList &args ) + : Plugin( parent, name, args ), d( new Private ) +{ +} + +Editor::~Editor() +{ + delete d; d = 0; +} + +void +Editor::select() +{ +} + + +} + +#include "editor.moc" diff --git a/libtdepim/komposer/core/editor.h b/libtdepim/komposer/core/editor.h new file mode 100644 index 000000000..cdc05710d --- /dev/null +++ b/libtdepim/komposer/core/editor.h @@ -0,0 +1,105 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * editor.h + * + * Copyright (C) 2003-2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef KOMPOSER_EDITOR_H +#define KOMPOSER_EDITOR_H + +#include "plugin.h" + +#include + +namespace KParts { + class Part; +} + +namespace Komposer { + + class Core; + + class Editor : public Plugin + { + Q_OBJECT + TQ_OBJECT + public: + enum TextType { + Plain = 1 << 0, + RichText = 1 << 1, + HTML = 1 << 2 + }; + virtual ~Editor(); + + /** + * This is the magic function that all derivatives have to reimplement. + * It returns the actual editor component. + */ + virtual TQWidget *widget() =0; + + int supportedTextFormats() const; + + /** + * Returns the full text inside the editor. + */ + virtual TQString text() const =0; + + /** + * This function is called when the plugin is selected by the user before the + * widget of the KPart belonging to the plugin is raised. + */ + virtual void select(); + + /** + * Reimplement this method and return a @ref TQStringList of all config + * modules your application part should offer via Komposer. Note that the + * part and the module will have to take care for config syncing themselves. + * Usually @p DCOP used for that purpose. + * + * @note Make sure you offer the modules in the form: + * "pathrelativetosettings/mysettings.desktop" + */ + virtual TQStringList configModules() const { return TQStringList(); } + + + public slots: + /** + * Sets the text of the opened editor. + * Most commonly used on replaying. + * If any text is present if will be deleted. + */ + virtual void setText( const TQString &txt ) =0; + + /** + * Changes currently used signature. If no signature is present + * a new one should be appened. + */ + virtual void changeSignature( const TQString &txt ) =0; + + protected: + Editor( TQObject *parent, const char *name, const TQStringList &args ); + + private: + class Private; + Private *d; + }; + +} + +#endif diff --git a/libtdepim/komposer/core/komposer.kcfg b/libtdepim/komposer/core/komposer.kcfg new file mode 100644 index 000000000..111584b88 --- /dev/null +++ b/libtdepim/komposer/core/komposer.kcfg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + #ff0000 + #00ff00 + #0000ff + #ffff00 + + + + + diff --git a/libtdepim/komposer/core/komposerIface.h b/libtdepim/komposer/core/komposerIface.h new file mode 100644 index 000000000..eecab2f3a --- /dev/null +++ b/libtdepim/komposer/core/komposerIface.h @@ -0,0 +1,85 @@ +/* + * komposerIface.h + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSERIFACE_H +#define KOMPOSERIFACE_H + +#include +#include + +namespace Komposer +{ + +/** + DCOP interface for mail composer window. The address header fields are set, + when the composer is constructed. KMailIface::openComposer() returns a + reference to the DCOP interface of the new composer window, which provides the + functions defined in the MailComposerIface. +*/ +class KomposerIface : virtual public DCOPObject +{ + K_DCOP +k_dcop: + /** + Send message. + + @param how 0 for deafult method, 1 for sending now, 2 for sending later. + */ + virtual void send(int how) = 0; + + /** + Add url as attachment with a user-defined comment. + */ + virtual void addAttachment( const KURL &url, const TQString &comment) = 0; + + /** + Set message body. + */ + virtual void setBody( const TQString &body ) = 0; + + /** + Add attachment. + + @param name Name of Attachment + @param cte Content Transfer Encoding + @param data Data to be attached + @param type MIME content type + @param subType MIME content sub type + @param paramAttr Attribute name of parameter of content type + @param paramValue Value of parameter of content type + @param contDisp Content disposition + */ + virtual void addAttachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ) = 0; +public: + KomposerIface( const char *name ) + : DCOPObject( name ) + {} +}; + +} + +#endif diff --git a/libtdepim/komposer/core/komposerconfig.desktop b/libtdepim/komposer/core/komposerconfig.desktop new file mode 100644 index 000000000..58c8bd765 --- /dev/null +++ b/libtdepim/komposer/core/komposerconfig.desktop @@ -0,0 +1,56 @@ +[Desktop Entry] +Exec=kcmshell komposerconfig +Icon=komposer +Type=Application +Terminal=false + +X-KDE-ModuleType=Library +X-KDE-Library=komposer +X-KDE-FactoryName=komposerconfig +X-KDE-HasReadOnlyMode=false + +Name=Komposer +Name[cy]=Kyfansoddydd +Name[da]=Brevskriver +Name[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° +Name[ms]=Penggubah +Name[ne]=कमà¥à¤ªà¥‹à¤œà¤° +Name[pt]=Kompositor +Name[ta]=கமà¯à®ªà¯‹à®šà®°à¯ +Comment=KDE Komposer +Comment[bg]=ПиÑане на форматиран текÑÑ‚ +Comment[br]=Komposer KDE +Comment[ca]=Compositor per a KDE +Comment[cy]=Cyfansoddydd KDE +Comment[da]=KDE Brevskriver +Comment[de]=KDE-Komposer +Comment[fr]=Komposer KDE +Comment[ga]=Komposer KDE +Comment[hi]=केडीई कमà¥à¤ªà¥‹à¤œà¤¼à¤° +Comment[ms]=Penggubah KDE +Comment[nds]=Nettbreef-Editor vun KDE +Comment[ne]=केडीई कमà¥à¤ªà¥‹à¤œà¤° +Comment[nn]=KDE, tekstredigerar for e-post +Comment[pl]=Komposer dla KDE +Comment[pt]=Kompositor do KDE +Comment[pt_BR]=Konposer do KDE +Comment[ru]=Композитор KDE +Comment[ta]=கேடிஇ கமà¯à®ªà¯‹à®šà®°à¯ +Comment[tg]=Композитори KDE +Keywords=komposer +Keywords[bg]=редактор, ÑÑŠÑтавител, форматиране, текÑÑ‚, komposer +Keywords[ca]=compositor +Keywords[cy]=komposer,kyfansoddydd +Keywords[da]=brevskriver +Keywords[de]=Komposer +Keywords[fy]=komposer,opstellen, opsteller +Keywords[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° +Keywords[nds]=Komposer +Keywords[ne]=कमà¥à¤ªà¥‹à¤œà¤° +Keywords[nl]=komposer,opstellen +Keywords[nn]=komposer,tekstredigerar,epost +Keywords[ru]=komposer,ноты +Keywords[sr]=komposer,ÑаÑтављач +Keywords[sr@Latn]=komposer,sastavljaÄ +Keywords[ta]=கமà¯à®ªà¯‹à®šà®°à¯ +Keywords[tg]=komposer,нотаҳо diff --git a/libtdepim/komposer/core/komposereditor.desktop b/libtdepim/komposer/core/komposereditor.desktop new file mode 100644 index 000000000..fd1c1341e --- /dev/null +++ b/libtdepim/komposer/core/komposereditor.desktop @@ -0,0 +1,56 @@ +[Desktop Entry] +Type=ServiceType +X-KDE-ServiceType=Komposer/Editor +X-KDE-Derived=Komposer/Plugin +Comment=Komposer Editor +Comment[af]=Komposer Redigeerder +Comment[bg]=ПиÑане на форматиран текÑÑ‚ +Comment[br]=Aozer Komposer +Comment[bs]=Komposer editor +Comment[ca]=Compositor per a KDE +Comment[cs]=Komposer editor +Comment[da]=Komposer editor +Comment[el]=ΕπεξεÏγαστής Komposer +Comment[eo]=Komposer-redaktilo +Comment[es]=Editor Komposer +Comment[et]=Komposeri redaktor +Comment[eu]=Komposer editorea +Comment[fa]=ویرایشگر Komposer +Comment[fi]=Komposer-muokkain +Comment[fr]=Éditeur Komposer +Comment[fy]=Komposer-bewurker +Comment[ga]=Eagarthóir Komposer +Comment[gl]=Editor Komposer +Comment[he]=עורך של Komposer +Comment[hu]=Komposer +Comment[is]=Komposer ritill +Comment[it]=Komposer editor +Comment[ja]=Komposer,エディタ +Comment[kk]=Komposer өңдегіші +Comment[km]=កម្មវិធី​និពន្ធ Komposer +Comment[ko]=Komposer 편집기 +Comment[lt]=Komposer redaktorius +Comment[ms]=Editor Komposer +Comment[nb]=Komposer redigerer +Comment[nds]=Komposer-Editor +Comment[ne]=कमà¥à¤ªà¥‹à¤œà¤° समà¥à¤ªà¤¾à¤¦à¤• +Comment[nl]=Komposer-editor +Comment[nn]=Komposer redigerar +Comment[pl]=Edytor Komposer +Comment[pt]=Editor Kompositor +Comment[pt_BR]=Editor de Mensagens +Comment[ru]=Редактор Komposer +Comment[sk]=Editor Komposer +Comment[sl]=Urejevalnik Komposer +Comment[sr]=Уређивач Komposer +Comment[sr@Latn]=UreÄ‘ivaÄ Komposer +Comment[sv]=Komposer editor +Comment[ta]=கமà¯à®ªà¯‹à®šà®°à¯ தொகà¯à®ªà¯à®ªà®¾à®©à¯ +Comment[tg]=Муҳаррири Komposer +Comment[tr]=Komposer Düzenleyicisi +Comment[uk]=Редактор Komposer +Comment[zh_CN]=Komposer 编辑器 +Comment[zh_TW]=Komposer 編輯器 + +[PropertyDef::X-Komposer-Weight] +Type=int diff --git a/libtdepim/komposer/core/komposerplugin.desktop b/libtdepim/komposer/core/komposerplugin.desktop new file mode 100644 index 000000000..b398e1c67 --- /dev/null +++ b/libtdepim/komposer/core/komposerplugin.desktop @@ -0,0 +1,59 @@ +[Desktop Entry] +Type=ServiceType +X-KDE-ServiceType=Komposer/Plugin +X-KDE-Derived=KPluginInfo +Name=Komposer Plugin +Name[af]=Komposer inprop module +Name[bg]=ПриÑтавка за Komposer +Name[br]=Lugent Komposer +Name[bs]=Komposer dodatak +Name[ca]=Endollable Komposer +Name[cs]=Komposer modul +Name[cy]=Ategyn Kyfansoddydd +Name[da]=Brevskriver-plugin +Name[de]=Komposer-Modul +Name[el]=ΠÏόσθετο του Komposer +Name[eo]=Komposer-kromaĵo +Name[es]=Accesorio Komposer +Name[et]=Komposeri plugin +Name[eu]=Komposer plugin-a +Name[fa]=وصلۀ Komposer +Name[fi]=Komposer-liitännäinen +Name[fr]=Module de Komposer +Name[fy]=Komposer-plugin +Name[ga]=Breiseán Komposer +Name[gl]=Extensión Komposer +Name[he]=תןסף Kompoer +Name[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° पà¥à¤²à¤—इन +Name[hu]=Komposer bÅ‘vítÅ‘modul +Name[is]=Komposer íforrit +Name[it]=Plugin Komposer +Name[ja]=Komposer プラグイン +Name[kk]=Komposer плагин модулі +Name[km]=កម្មវិធី​ជំនួយ Komposer +Name[ko]=Komposer í”ŒëŸ¬ê·¸ì¸ +Name[lt]=Komposer priedas +Name[ms]=Plugin Komposer +Name[nb]=Komposer-programtillegg +Name[nds]=Komposer-Moduul +Name[ne]=कमà¥à¤ªà¥‹à¤œà¤° पà¥à¤²à¤—इन +Name[nn]=Komposer-programtillegg +Name[pl]=Wtyczka Komposer +Name[pt]='Plugin' do Kompositor +Name[pt_BR]=Plug-in do Komposer +Name[ro]=Modul Komposer +Name[ru]=Модуль Komposer +Name[sk]=Modul Komposer +Name[sl]=Vstavek za Komposer +Name[sr]=Прикључак Komposer-а +Name[sr@Latn]=PrikljuÄak Komposer-a +Name[sv]=Komposer-insticksprogram +Name[ta]=கமà¯à®ªà¯‹à®šà®°à¯ சொரà¯à®•à¯à®ªà¯à®ªà¯Šà®°à¯à®³à¯ +Name[tg]=Модули Komposer +Name[tr]=Komposer Eklentisi +Name[uk]=Втулок Komposer +Name[zh_CN]=Komposer æ’件 +Name[zh_TW]=Komposer å¤–æŽ›ç¨‹å¼ + +[PropertyDef::X-Komposer-Version] +Type=int diff --git a/libtdepim/komposer/core/komposerui.rc b/libtdepim/komposer/core/komposerui.rc new file mode 100644 index 000000000..83ec4d299 --- /dev/null +++ b/libtdepim/komposer/core/komposerui.rc @@ -0,0 +1,51 @@ + + + + + &Message + + + + + + + + + + + + + + + + + &Attach + + + + + + + + &Tools + + + + + &Settings + + + + + +Main Toolbar + + + + + + + + + + diff --git a/libtdepim/komposer/core/plugin.cpp b/libtdepim/komposer/core/plugin.cpp new file mode 100644 index 000000000..41af47cd9 --- /dev/null +++ b/libtdepim/komposer/core/plugin.cpp @@ -0,0 +1,80 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * plugin.cpp + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "plugin.h" + +#include "core.h" + +#include +#include + +namespace Komposer +{ + +class Plugin::Private +{ +public: + //Core* core; +}; + +Plugin::Plugin( TQObject *parent, const char *name, const TQStringList & ) + : TQObject( parent, name ), d( new Private ) +{ + //d->core = core; +} + +Plugin::~Plugin() +{ + delete d; d = 0; +} + +void +Plugin::startedComposing() +{ +} + +void +Plugin::sendClicked() +{ +} + +void +Plugin::quitClicked() +{ +} + +void +Plugin::aboutToUnload() +{ + kdDebug()<<"plugin unloading"<core; +} + +}//end namespace Komposer + +#include "plugin.moc" diff --git a/libtdepim/komposer/core/plugin.h b/libtdepim/komposer/core/plugin.h new file mode 100644 index 000000000..7acd7f70f --- /dev/null +++ b/libtdepim/komposer/core/plugin.h @@ -0,0 +1,76 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * plugin.h + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSER_PLUGIN_H +#define KOMPOSER_PLUGIN_H + +#include +#include + +namespace Komposer +{ + class Core; + + class Plugin : public TQObject, + virtual public KXMLGUIClient + { + Q_OBJECT + TQ_OBJECT + public: + virtual ~Plugin(); + + signals: + void statusMessage( const TQString & ); + void readyForUnload(); + + protected slots: + /** + * Called when a new message is created. + */ + virtual void startedComposing(); + + /** + * Called after the send button has been pressed + * and before the message has been sent. + */ + virtual void sendClicked(); + + /** + * Called after the quit button has been pressed + */ + virtual void quitClicked(); + + virtual void aboutToUnload(); + + protected: + Core *core() const; + protected: + friend class PluginManager; + Plugin( TQObject *parent, const char *name, const TQStringList& args = TQStringList() ); + + private: + class Private; + Private *d; + }; + +} + +#endif diff --git a/libtdepim/komposer/core/pluginmanager.cpp b/libtdepim/komposer/core/pluginmanager.cpp new file mode 100644 index 000000000..dcfea6f4b --- /dev/null +++ b/libtdepim/komposer/core/pluginmanager.cpp @@ -0,0 +1,489 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- +/** + * pluginmanager.cpp + * Most of this code has been lifted from Martijn's KopetePluginManager class + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "pluginmanager.h" + +#include "plugin.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace Komposer +{ + +class PluginManager::Private +{ +public: + // All available plugins, regardless of category, and loaded or not + TQValueList plugins; + + // Dict of all currently loaded plugins, mapping the KPluginInfo to + // a plugin + TQMap loadedPlugins; + + // The plugin manager's mode. The mode is StartingUp until loadAllPlugins() + // has finished loading the plugins, after which it is set to Running. + // ShuttingDown and DoneShutdown are used during Komposer shutdown by the + // async unloading of plugins. + enum ShutdownMode { StartingUp, Running, ShuttingDown, DoneShutdown }; + ShutdownMode shutdownMode; + + KSharedConfig::Ptr config; + // Plugins pending for loading + TQValueStack pluginsToLoad; +}; + +PluginManager::PluginManager( TQObject *parent ) + : TQObject( parent ) +{ + d = new Private; + + // We want to add a reference to the application's event loop so we + // can remain in control when all windows are removed. + // This way we can unload plugins asynchronously, which is more + // robust if they are still doing processing. + kapp->ref(); + d->shutdownMode = Private::StartingUp; + + KSettings::Dispatcher::self()->registerInstance( KGlobal::instance(), + this, TQT_SLOT( loadAllPlugins() ) ); + + d->plugins = KPluginInfo::fromServices( + KTrader::self()->query( TQString::tqfromLatin1( "Komposer/Plugin" ), + TQString::tqfromLatin1( "[X-Komposer-Version] == 1" ) ) ); +} + +PluginManager::~PluginManager() +{ + if ( d->shutdownMode != Private::DoneShutdown ) { + slotShutdownTimeout(); +#if 0 + kdWarning() << k_funcinfo + << "Destructing plugin manager without going through " + << "the shutdown process!" + << endl + << kdBacktrace(10) << endl; +#endif + } + + // Quick cleanup of the remaining plugins, hope it helps + TQMap::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); /* EMPTY */ ) + { + // Remove causes the iterator to become invalid, so pre-increment first + TQMap::ConstIterator nextIt( it ); + ++nextIt; + kdWarning() << k_funcinfo << "Deleting stale plugin '" + << it.data()->name() << "'" << endl; + delete it.data(); + it = nextIt; + } + + delete d; +} + +TQValueList +PluginManager::availablePlugins( const TQString &category ) const +{ + if ( category.isEmpty() ) + return d->plugins; + + TQValueList result; + TQValueList::ConstIterator it; + for ( it = d->plugins.begin(); it != d->plugins.end(); ++it ) + { + if ( ( *it )->category() == category ) + result.append( *it ); + } + + return result; +} + +TQMap +PluginManager::loadedPlugins( const TQString &category ) const +{ + TQMap result; + TQMap::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( category.isEmpty() || it.key()->category() == category ) + result.insert( it.key(), it.data() ); + } + + return result; +} + +void +PluginManager::shutdown() +{ + d->shutdownMode = Private::ShuttingDown; + + // Remove any pending plugins to load, we're shutting down now :) + d->pluginsToLoad.clear(); + + // Ask all plugins to unload + if ( d->loadedPlugins.empty() ) { + d->shutdownMode = Private::DoneShutdown; + } else { + TQMap::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); /* EMPTY */ ) + { + // Remove causes the iterator to become invalid, so pre-increment first + TQMap::ConstIterator nextIt( it ); + ++nextIt; + it.data()->aboutToUnload(); + it = nextIt; + } + } + + TQTimer::singleShot( 3000, this, TQT_SLOT(slotShutdownTimeout()) ); +} + +void +PluginManager::slotPluginReadyForUnload() +{ + // Using TQObject::sender() is on purpose here, because otherwise all + // plugins would have to pass 'this' as parameter, which makes the API + // less clean for plugin authors + Plugin* plugin = dynamic_cast( const_cast( sender() ) ); + if ( !plugin ) + { + kdWarning() << k_funcinfo << "Calling object is not a plugin!" << endl; + return; + + } + kdDebug()<<"manager unloading"<deleteLater(); +} + +void +PluginManager::slotShutdownTimeout() +{ + // When we were already done the timer might still fire. + // Do nothing in that case. + if ( d->shutdownMode == Private::DoneShutdown ) + return; + +#ifndef NDEBUG + TQStringList remaining; + for ( TQMap::ConstIterator it = d->loadedPlugins.begin(); + it != d->loadedPlugins.end(); ++it ) + remaining.append( it.key()->pluginName() ); + + kdWarning() << k_funcinfo << "Some plugins didn't shutdown in time!" << endl + << "Remaining plugins: " + << remaining.join( TQString::tqfromLatin1( ", " ) ) << endl + << "Forcing Komposer shutdown now." << endl; +#endif + + slotShutdownDone(); +} + +void +PluginManager::slotShutdownDone() +{ + d->shutdownMode = Private::DoneShutdown; + + kapp->deref(); +} + +void +PluginManager::loadAllPlugins() +{ + // FIXME: We need session management here - Martijn + + if ( !d->config ) + d->config = KSharedConfig::openConfig( "komposerrc" ); + + TQMap entries = d->config->entryMap( + TQString::tqfromLatin1( "Plugins" ) ); + + TQMap::Iterator it; + for ( it = entries.begin(); it != entries.end(); ++it ) + { + TQString key = it.key(); + if ( key.endsWith( TQString::tqfromLatin1( "Enabled" ) ) ) + { + key.setLength( key.length() - 7 ); + //kdDebug() << k_funcinfo << "Set " << key << " to " << it.data() << endl; + + if ( it.data() == TQString::tqfromLatin1( "true" ) ) + { + if ( !plugin( key ) ) + d->pluginsToLoad.push( key ); + } + else + { + // FIXME: Does this ever happen? As loadAllPlugins is only called on startup + // I'd say 'no'. If it does, it should be made async + // though. - Martijn + if ( plugin( key ) ) + unloadPlugin( key ); + } + } + } + + // Schedule the plugins to load + TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); +} + +void PluginManager::slotLoadNextPlugin() +{ + if ( d->pluginsToLoad.isEmpty() ) + { + if ( d->shutdownMode == Private::StartingUp ) + { + d->shutdownMode = Private::Running; + emit allPluginsLoaded(); + } + return; + } + + TQString key = d->pluginsToLoad.pop(); + loadPluginInternal( key ); + + // Schedule the next run unconditionally to avoid code duplication on the + // allPluginsLoaded() signal's handling. This has the added benefit that + // the signal is delayed one event loop, so the accounts are more likely + // to be instantiated. + TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); +} + +Plugin* +PluginManager::loadPlugin( const TQString &pluginId, + PluginLoadMode mode /* = LoadSync */ ) +{ + if ( mode == LoadSync ) { + return loadPluginInternal( pluginId ); + } else { + d->pluginsToLoad.push( pluginId ); + TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); + return 0; + } +} + +Plugin* +PluginManager::loadPluginInternal( const TQString &pluginId ) +{ + KPluginInfo* info = infoForPluginId( pluginId ); + if ( !info ) { + kdWarning() << k_funcinfo << "Unable to find a plugin named '" + << pluginId << "'!" << endl; + return 0; + } + + if ( d->loadedPlugins.contains( info ) ) + return d->loadedPlugins[ info ]; + + int error = 0; + Plugin *plugin = KParts::ComponentFactory::createInstanceFromQuery( + TQString::tqfromLatin1( "Komposer/Plugin" ), + TQString::tqfromLatin1( "[X-KDE-PluginInfo-Name]=='%1'" ).tqarg( pluginId ), + this, 0, TQStringList(), &error ); + + if ( plugin ) { + d->loadedPlugins.insert( info, plugin ); + info->setPluginEnabled( true ); + + connect( plugin, TQT_SIGNAL(destroyed(TQObject*)), + this, TQT_SLOT(slotPluginDestroyed(TQObject*)) ); + connect( plugin, TQT_SIGNAL(readyForUnload()), + this, TQT_SLOT(slotPluginReadyForUnload()) ); + + kdDebug() << k_funcinfo << "Successfully loaded plugin '" + << pluginId << "'" << endl; + + emit pluginLoaded( plugin ); + } else { + switch ( error ) { + case KParts::ComponentFactory::ErrNoServiceFound: + kdDebug() << k_funcinfo << "No service implementing the given mimetype " + << "and fullfilling the given constraint expression can be found." + << endl; + break; + + case KParts::ComponentFactory::ErrServiceProvidesNoLibrary: + kdDebug() << "the specified service provides no shared library." << endl; + break; + + case KParts::ComponentFactory::ErrNoLibrary: + kdDebug() << "the specified library could not be loaded." << endl; + break; + + case KParts::ComponentFactory::ErrNoFactory: + kdDebug() << "the library does not export a factory for creating components." + << endl; + break; + + case KParts::ComponentFactory::ErrNoComponent: + kdDebug() << "the factory does not support creating components " + << "of the specified type." + << endl; + break; + } + + kdDebug() << k_funcinfo << "Loading plugin '" << pluginId + << "' failed, KLibLoader reported error: '" + << KLibLoader::self()->lastErrorMessage() + << "'" << endl; + } + + return plugin; +} + +bool +PluginManager::unloadPlugin( const TQString &spec ) +{ + TQMap::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.key()->pluginName() == spec ) + { + it.data()->aboutToUnload(); + return true; + } + } + + return false; +} + +void +PluginManager::slotPluginDestroyed( TQObject *plugin ) +{ + TQMap::Iterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.data() == plugin ) + { + d->loadedPlugins.erase( it ); + break; + } + } + + if ( d->shutdownMode == Private::ShuttingDown && d->loadedPlugins.isEmpty() ) + { + // Use a timer to make sure any pending deleteLater() calls have + // been handled first + TQTimer::singleShot( 0, this, TQT_SLOT(slotShutdownDone()) ); + } +} + +Plugin* +PluginManager::plugin( const TQString &pluginId ) const +{ + KPluginInfo *info = infoForPluginId( pluginId ); + if ( !info ) + return 0; + + if ( d->loadedPlugins.contains( info ) ) + return d->loadedPlugins[ info ]; + else + return 0; +} + +TQString +PluginManager::pluginName( const Plugin *plugin ) const +{ + TQMap::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.data() == plugin ) + return it.key()->name(); + } + + return TQString::tqfromLatin1( "Unknown" ); +} + +TQString +PluginManager::pluginId( const Plugin *plugin ) const +{ + TQMap::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.data() == plugin ) + return it.key()->pluginName(); + } + + return TQString::tqfromLatin1( "unknown" ); +} + +TQString +PluginManager::pluginIcon( const Plugin *plugin ) const +{ + TQMap::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.data() == plugin ) + return it.key()->icon(); + } + + return TQString::tqfromLatin1( "Unknown" ); +} + +KPluginInfo* +PluginManager::infoForPluginId( const TQString &pluginId ) const +{ + TQValueList::ConstIterator it; + for ( it = d->plugins.begin(); it != d->plugins.end(); ++it ) + { + if ( ( *it )->pluginName() == pluginId ) + return *it; + } + + return 0; +} + +bool +PluginManager::setPluginEnabled( const TQString &pluginId, bool enabled /* = true */ ) +{ + if ( !d->config ) + d->config = KSharedConfig::openConfig( "komposerrc" ); + + d->config->setGroup( "Plugins" ); + + + if ( !infoForPluginId( pluginId ) ) + return false; + + d->config->writeEntry( pluginId + TQString::tqfromLatin1( "Enabled" ), enabled ); + d->config->sync(); + + return true; +} + +} + +#include "pluginmanager.moc" diff --git a/libtdepim/komposer/core/pluginmanager.h b/libtdepim/komposer/core/pluginmanager.h new file mode 100644 index 000000000..34cc6b9c5 --- /dev/null +++ b/libtdepim/komposer/core/pluginmanager.h @@ -0,0 +1,252 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * pluginmanager.h + * + * Copyright (C) 2004 Zack Rusin + * Copyright (C) 2003 Martijn Klingens + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef KOMPOSER_PLUGINMANAGER_H +#define KOMPOSER_PLUGINMANAGER_H + +#include +#include +#include +#include +#include + +class KPluginInfo; + +namespace Komposer +{ + + class Plugin; + + class PluginManager : public TQObject + { + Q_OBJECT + TQ_OBJECT + + public: + PluginManager( TQObject * ); + + ~PluginManager(); + + /** + * Returns a list of all available plugins for the given category. + * Currently there are two categories, "Plugins" and "Editors", but + * you can add your own categories if you want. + * + * If you pass an empty string you get the complete list of ALL plugins. + * + * You can query all information on the plugins through the @ref KPluginInfo + * interface. + */ + TQValueList availablePlugins( const TQString &category + = TQString() ) const; + + /** + * Returns a list of all plugins that are actually loaded. + * If you omit the category you get all, otherwise it's a filtered list. + * See also @ref availablePlugins(). + */ + TQMap loadedPlugins( const TQString &category + = TQString() ) const; + + /** + * @brief Search by plugin name. This is the key used as X-KDE-PluginInfo-Name + * in the .desktop file, e.g. "komposer_attachment" + * + * @return The @ref Plugin object found by the search, or a null + * pointer if the plugin is not loaded. + * + * If you want to also load the plugin you can better use @ref loadPlugin, + * which returns + * the pointer to the plugin if it's already loaded. + */ + Plugin* plugin( const TQString &pluginName ) const; + + /** + * @brief Return the short user-visible name of the plugin. + * + * If you want to have the internal name, use @ref pluginId() instead. + * + * @return The name of the protocol, in the user's locale. + */ + TQString pluginName( const Plugin *plugin ) const; + + /** + * @brief Return the internal name of the plugin. + * + * You cannot display this name on the screen, it's used internally for + * passing around IDs. Use @ref pluginName() for a string ready for display. + * + * @return The name of the protocol, in the user's locale. + */ + TQString pluginId( const Plugin *plugin ) const; + + /** + * @brief Unload the plugin specified by @p pluginName + */ + bool unloadPlugin( const TQString &pluginName ); + + /** + * @brief Retrieve the name of the icon for a @ref Plugin. + * + * @return An empty string if the given plugin is not loaded + * or the filename of the icon to use. + */ + TQString pluginIcon( const Plugin *plugin ) const; + + /** + * Shuts down the plugin manager on Komposer shutdown, but first + * unloads all plugins asynchronously. + * + * After 3 seconds all plugins should be removed; what's still left + * by then is unloaded through a hard delete instead. + * + * Note that this call also derefs the plugin manager from the event + * loop, so do NOT call this method when not terminating Komposer! + */ + void shutdown(); + + /** + * Enable a plugin. + * + * This marks a plugin as enabled in the config file, so loadAll() + * can pick it up later. + * + * This method does not actually load a plugin, it only edits the + * config file. + * + * @param name is the name of the plugin as it is listed in the .desktop + * file in the X-KDE-Library field. + * + * Returns false when no appropriate plugin can be found. + */ + bool setPluginEnabled( const TQString &name, bool enabled = true ); + + /** + * Plugin loading mode. Used by @loadPlugin. Code that doesn't want to block + * the GUI and/or lot a lot of plugins at once should use Async loading. + * The default is sync loading. + */ + enum PluginLoadMode { LoadSync, LoadAsync }; + + public slots: + /** + * @brief Load a single plugin by plugin name. Returns an existing plugin + * if one is already loaded in memory. + * + * If mode is set to Async, the plugin will be queued and loaded in + * the background. This method will return a null pointer. To get + * the loaded plugin you can track the @ref pluginLoaded() signal. + * + * See also @ref plugin(). + */ + Plugin* loadPlugin( const TQString &pluginId, PluginLoadMode mode = LoadSync ); + + /** + * @brief Loads all the enabled plugins. Also used to reread the + * config file when the configuration has changed. + */ + void loadAllPlugins(); + + signals: + /** + * @brief Signals a new plugin has just been loaded. + */ + void pluginLoaded( Plugin *plugin ); + + /** + * @brief All plugins have been loaded by the plugin manager. + * + * This signal is emitted exactly ONCE, when the plugin manager has emptied + * its plugin queue for the first time. This means that if you call an async + * loadPlugin() before loadAllPlugins() this signal is probably emitted after + * the initial call completes, unless you are quick enough to fill the queue + * before it completes, which is a dangerous race you shouldn't count upon :) + * + * The signal is delayed one event loop iteration through a singleShot timer, + * but that is not guaranteed to be enough for account instantiation. You may + * need an additional timer for it in the code if you want to programmatically + * act on it. + * + * If you use the signal for enabling/disabling GUI objects there is little + * chance a user is able to activate them in the short while that's remaining, + * the slow part of the code is over now and the remaining processing time + * is neglectable for the user. + */ + void allPluginsLoaded(); + + private slots: + /** + * @brief Cleans up some references if the plugin is destroyed + */ + void slotPluginDestroyed( TQObject *plugin ); + + /** + * shutdown() starts a timer, when it fires we force all plugins + * to be unloaded here by deref()-ing the event loop to trigger the plugin + * manager's destruction + */ + void slotShutdownTimeout(); + + /** + * Common entry point to deref() the KApplication. Used both by the clean + * shutdown and the timeout condition of slotShutdownTimeout() + */ + void slotShutdownDone(); + + /** + * Emitted by a Plugin when it's ready for unload + */ + void slotPluginReadyForUnload(); + + /** + * Load a plugin from our queue. Does nothing if the queue is empty. + * Schedules itself again if more plugins are pending. + */ + void slotLoadNextPlugin(); + + private: + /** + * @internal + * + * The internal method for loading plugins. + * Called by @ref loadPlugin directly or through the queue for async plugin + * loading. + */ + Plugin *loadPluginInternal( const TQString &pluginId ); + + /** + * @internal + * + * Find the KPluginInfo structure by key. Reduces some code duplication. + * + * Returns a null pointer when no plugin info is found. + */ + KPluginInfo *infoForPluginId( const TQString &pluginId ) const; + private: + class Private; + Private *d; + }; + +} + +#endif // KOMPOSER_PLUGINMANAGER_H diff --git a/libtdepim/komposer/core/prefsmodule.cpp b/libtdepim/komposer/core/prefsmodule.cpp new file mode 100644 index 000000000..77e1c264b --- /dev/null +++ b/libtdepim/komposer/core/prefsmodule.cpp @@ -0,0 +1,142 @@ +/** + * prefsmodule.cpp + * + * Copyright (C) 2003-2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "prefsmodule.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +extern "C" +{ + KDE_EXPORT KCModule *create_komposerconfig( TQWidget *parent, const char * ) { + return new Komposer::PrefsModule( parent, "komposerprefs" ); + } +} +using namespace Komposer; + +PrefsModule::PrefsModule( TQWidget *parent, const char *name ) + : KPrefsModule( Komposer::Prefs::self(), parent, name ) +{ + TQVBoxLayout *topLayout = new TQVBoxLayout( this ); + + EditorSelection *editors = new EditorSelection( i18n( "Editors" ), + Komposer::Prefs::self()->m_activeEditor, + this ); + topLayout->addWidget( editors->groupBox() ); + + addWid( editors ); + + load(); +} + +const KAboutData* +PrefsModule::aboutData() const +{ + KAboutData *about = new KAboutData( I18N_NOOP( "komposerconfig" ), + I18N_NOOP( "KDE Komposer" ), + 0, 0, KAboutData::License_LGPL, + I18N_NOOP( "(c), 2003-2004 Zack Rusin" ) ); + + about->addAuthor( "Zack Rusin", 0, "zack@kde.org" );; + + return about; +} + + +EditorSelection::EditorSelection( const TQString &text, TQString &reference, + TQWidget *parent ) + : m_reference( reference ) +{ + m_box = new TQGroupBox( 0, TQt::Vertical, text, parent ); + TQVBoxLayout *boxLayout = new TQVBoxLayout( m_box->tqlayout() ); + boxLayout->tqsetAlignment( TQt::AlignTop ); + + m_editorsCombo = new KComboBox( m_box ); + boxLayout->addWidget( m_editorsCombo ); + + connect( m_editorsCombo, TQT_SIGNAL(activated(const TQString&)), + TQT_SLOT(slotActivated(const TQString&)) ); +} + +EditorSelection::~EditorSelection() +{ +} + +TQGroupBox* +EditorSelection::groupBox() const +{ + return m_box; +} + +void +EditorSelection::readConfig() +{ + m_editorsCombo->clear(); + + KTrader::OfferList editors = KTrader::self()->query( + TQString::tqfromLatin1( "Komposer/Editor" ) ); + KTrader::OfferList::ConstIterator it; + int i = 0; + for ( it = editors.begin(); it != editors.end(); ++it, ++i ) { + if ( !(*it)->hasServiceType( TQString::tqfromLatin1( "Komposer/Editor" ) ) ) + continue; + + TQString name = (*it)->property( "X-KDE-KomposerIdentifier" ).toString(); + m_editorsCombo->insertItem( name ); + if ( m_reference.contains( name ) ) + m_editorsCombo->setCurrentItem( i ); + } +} + +void EditorSelection::writeConfig() +{ + m_reference = m_services[ m_editorsCombo->currentText()]-> + property( "X-KDE-KomposerIdentifier" ).toString(); +} + +void +EditorSelection::slotActivated( const TQString &editor ) +{ + if ( !editor.isEmpty() ) + emit changed(); +} + +void +EditorSelection::setItem( const TQString &str ) +{ + for ( int i = 0; i < m_editorsCombo->count(); ++i ) { + if ( m_editorsCombo->text( i ) == str ) { + m_editorsCombo->setCurrentItem( i ); + break; + } + } +} + +#include "prefsmodule.moc" diff --git a/libtdepim/komposer/core/prefsmodule.h b/libtdepim/komposer/core/prefsmodule.h new file mode 100644 index 000000000..aba969f16 --- /dev/null +++ b/libtdepim/komposer/core/prefsmodule.h @@ -0,0 +1,72 @@ +/* + * prefsmodule.h + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSER_PREFSMODULE_H +#define KOMPOSER_PREFSMODULE_H + +#include +#include +#include +class TQGroupBox; +class TQListViewItem; + +class KAboutData; +class KComboBox; + +namespace Komposer { + + class PrefsModule : public KPrefsModule + { + Q_OBJECT + TQ_OBJECT + public: + PrefsModule( TQWidget *parent=0, const char *name=0 ); + virtual const KAboutData *aboutData() const; + }; + + class EditorSelection : public KPrefsWid + { + Q_OBJECT + TQ_OBJECT + + public: + EditorSelection( const TQString &text, TQString &reference, TQWidget *parent ); + ~EditorSelection(); + + void readConfig(); + void writeConfig(); + + TQGroupBox *groupBox() const; + + private slots: + void slotActivated( const TQString & ); + + private: + void setItem( const TQString & ); + private: + TQString &m_reference; + + TQGroupBox *m_box; + KComboBox *m_editorsCombo; + TQMap m_services; + }; +} + +#endif diff --git a/libtdepim/komposer/core/settings.kcfgc b/libtdepim/komposer/core/settings.kcfgc new file mode 100644 index 000000000..fc98478a9 --- /dev/null +++ b/libtdepim/komposer/core/settings.kcfgc @@ -0,0 +1,9 @@ +# Code generation options for kconfig_compiler +File=komposer.kcfg +NameSpace=Komposer +ClassName=Config +Singleton=true +Mutators=true +#MemberVariables=public +GlobalEnums=true +#SetUserTexts=true diff --git a/libtdepim/komposer/core/tests/Makefile.am b/libtdepim/komposer/core/tests/Makefile.am new file mode 100644 index 000000000..fbf127956 --- /dev/null +++ b/libtdepim/komposer/core/tests/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = -I$(top_builddir)/libtdepim/komposer/core $(all_includes) + +check_PROGRAMS = testfactory testmanager testkomposer + +METASOURCES = AUTO + +testfactory_SOURCES = main.cpp managertest.cpp +testfactory_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +testfactory_LDADD = ../libkomposer.la + +testmanager_SOURCES = testmanager.cpp +testmanager_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +testmanager_LDADD = ../libkomposer.la + +testkomposer_SOURCES = testkomposer.cpp +testkomposer_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +testkomposer_LDADD = ../libkomposer.la + +check: testfactory + @./testfactory 2>&1 | grep "tests:" diff --git a/libtdepim/komposer/core/tests/main.cpp b/libtdepim/komposer/core/tests/main.cpp new file mode 100644 index 000000000..4a33a2f13 --- /dev/null +++ b/libtdepim/komposer/core/tests/main.cpp @@ -0,0 +1,52 @@ +/** + * main.cpp + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "testfactory.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +static const KCmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + KCmdLineLastOption +}; +int main( int argc, char** argv ) +{ + KAboutData aboutData( "tests","Test","0.1" ); + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + Q_UNUSED( args ); + + TestFactory t; + return t.runTests(); +} diff --git a/libtdepim/komposer/core/tests/managertest.cpp b/libtdepim/komposer/core/tests/managertest.cpp new file mode 100644 index 000000000..487a84c59 --- /dev/null +++ b/libtdepim/komposer/core/tests/managertest.cpp @@ -0,0 +1,43 @@ +/** + * managertest.cpp + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "managertest.h" + +#include "pluginmanager.h" +using namespace Komposer; + +ManagerTest::ManagerTest( TQObject* parent ) + : TQObject( parent ) +{ + m_manager = new PluginManager( this ); +} + + +void ManagerTest::allTests() +{ + CHECK( m_manager->availablePlugins().isEmpty(), true ); + CHECK( m_manager->loadedPlugins().empty(), true ); + CHECK( m_manager->plugin( "non-existing" ), ( Plugin* )0 ); + m_manager->loadAllPlugins(); + CHECK( m_manager->loadedPlugins().empty(), true ); + m_manager->shutdown(); +} + +#include "managertest.moc" diff --git a/libtdepim/komposer/core/tests/managertest.h b/libtdepim/komposer/core/tests/managertest.h new file mode 100644 index 000000000..f02510e67 --- /dev/null +++ b/libtdepim/komposer/core/tests/managertest.h @@ -0,0 +1,45 @@ +/* + * managertest.h + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef MANAGERTEST_H +#define MANAGERTEST_H + +#include +#include "tester.h" + +namespace Komposer { + class PluginManager; +} + +class ManagerTest : public TQObject, + public Tester +{ + Q_OBJECT + TQ_OBJECT +public: + ManagerTest( TQObject* parent = 0 ); + +public slots: + void allTests(); +private: + Komposer::PluginManager* m_manager; +}; + +#endif diff --git a/libtdepim/komposer/core/tests/tester.cpp b/libtdepim/komposer/core/tests/tester.cpp new file mode 100644 index 000000000..b32c89644 --- /dev/null +++ b/libtdepim/komposer/core/tests/tester.cpp @@ -0,0 +1,30 @@ +/** + * tester.cpp + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "tester.h" + + +Tester::Tester( TQObject* parent ) + : TQObject( parent ) +{ +} + + +#include "tester.moc" diff --git a/libtdepim/komposer/core/tests/tester.h b/libtdepim/komposer/core/tests/tester.h new file mode 100644 index 000000000..5981d681d --- /dev/null +++ b/libtdepim/komposer/core/tests/tester.h @@ -0,0 +1,71 @@ +/* + * tester.h + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef TESTER_H +#define TESTER_H + +#include +#include + +#define CHECK( x, y ) check( __FILE__, __LINE__, #x, x, y ) + +class Tester +{ +public: + Tester() : m_tests( 0 ) {} + virtual ~Tester() {} + +public: + virtual void allTests() = 0; + +public: + int testsFinished() const { + return m_tests; + } + int testsFailed() const { + return m_errorList.count(); + } + TQStringList errorList() const { + return m_errorList; + } + +protected: + template + void check( const char* file, int line, const char* str, + const T& result, const T& expectedResult ) + { + if ( result != expectedResult ) { + TQString error; + TQTextStream ts( &error, IO_WriteOnly ); + ts << file << "["<< line <<"]:" + <<" failed on \""<< str <<"\"" + << "\ntests:\t\t result = " + << result + << ", expected = "<< expectedResult; + m_errorList.append( error ); + } + ++m_tests; + } +private: + TQStringList m_errorList; + int m_tests; +}; + +#endif diff --git a/libtdepim/komposer/core/tests/testfactory.h b/libtdepim/komposer/core/tests/testfactory.h new file mode 100644 index 000000000..9354e52ad --- /dev/null +++ b/libtdepim/komposer/core/tests/testfactory.h @@ -0,0 +1,71 @@ +/* + * testfactory.h + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef TESTFACTORY_H +#define TESTFACTORY_H + +#include "managertest.h" + +#include + +#define ADD_TEST(x) addTest( #x, new x ) + +class TestFactory +{ +public: + TestFactory() + { + ADD_TEST( ManagerTest ); + m_tests.setAutoDelete( true ); + } + + int runTests() + { + int result = 0; + kdDebug()<<"Running tests..."< it( m_tests ); + for( ; it.current(); ++it ) { + Tester* test = it.current(); + test->allTests(); + TQStringList errorList = test->errorList(); + if ( !errorList.empty() ) { + ++result; + kdDebug()<< it.currentKey() <<" errors:" << endl; + for ( TQStringList::Iterator itr = errorList.begin(); + itr != errorList.end(); ++itr ) { + kdDebug()<< "\t" << (*itr).latin1() < m_tests; +}; + +#endif diff --git a/libtdepim/komposer/core/tests/testkomposer.cpp b/libtdepim/komposer/core/tests/testkomposer.cpp new file mode 100644 index 000000000..b7997e8c3 --- /dev/null +++ b/libtdepim/komposer/core/tests/testkomposer.cpp @@ -0,0 +1,18 @@ +#include "core.h" + +#include +#include +#include +#include + +int main( int argc, char **argv ) +{ + KCmdLineArgs::init( argc, argv, "test", "test", "test", "0.1" ); + KApplication app; + + Komposer::Core *core = new Komposer::Core(); + app.setMainWidget( core ); + core->show(); + + return app.exec(); +} diff --git a/libtdepim/komposer/core/tests/testmanager.cpp b/libtdepim/komposer/core/tests/testmanager.cpp new file mode 100644 index 000000000..0fcba16b9 --- /dev/null +++ b/libtdepim/komposer/core/tests/testmanager.cpp @@ -0,0 +1,53 @@ +#include "testmanager.h" +#include "testmanager.moc" + +#include "pluginmanager.h" +#include "plugin.h" + +#include +#include +#include +#include + +using namespace Komposer; + +TestManager::TestManager( TQObject *parent ) + : TQObject( parent ) +{ + m_manager = new PluginManager( this ); + connect( m_manager, TQT_SIGNAL(pluginLoaded(Plugin*)), + TQT_SLOT(slotPluginLoaded(Plugin*)) ); + connect( m_manager, TQT_SIGNAL(allPluginsLoaded()), + TQT_SLOT(slotAllPluginsLoaded()) ); + m_manager->loadAllPlugins(); + + TQValueList plugins = m_manager->availablePlugins(); + kdDebug()<<"Number of available plugins is "<< plugins.count() <::iterator it = plugins.begin(); it != plugins.end(); ++it ) { + KPluginInfo *i = ( *it ); + kdDebug()<<"\tAvailable plugin "<< i->name() + <<", comment = "<< i->comment() <shutdown(); + tqApp->exit(); +} + +void TestManager::slotPluginLoaded( Plugin *plugin ) +{ + kdDebug()<<"A plugin "<< m_manager->pluginName( plugin ) << " has been loaded"< + +namespace Komposer { + class Plugin; + class PluginManager; +} +using Komposer::Plugin; + +class TestManager : public TQObject +{ + Q_OBJECT + TQ_OBJECT +public: + TestManager( TQObject *parent ); + +public slots: + void slotPluginLoaded( Plugin *plugin ); + void slotAllPluginsLoaded(); +private: + Komposer::PluginManager *m_manager; +}; + +#endif diff --git a/libtdepim/komposer/plugins/Makefile.am b/libtdepim/komposer/plugins/Makefile.am new file mode 100644 index 000000000..dcc4764a7 --- /dev/null +++ b/libtdepim/komposer/plugins/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = default diff --git a/libtdepim/komposer/plugins/default/Makefile.am b/libtdepim/komposer/plugins/default/Makefile.am new file mode 100644 index 000000000..7ae32dc08 --- /dev/null +++ b/libtdepim/komposer/plugins/default/Makefile.am @@ -0,0 +1,15 @@ +AM_CPPFLAGS = -I$(top_builddir)/libtdepim/komposer/core $(all_includes) + +kde_module_LTLIBRARIES = libkomposer_defaulteditor.la +libkomposer_defaulteditor_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) +libkomposer_defaulteditor_la_LIBADD = ../../core/libkomposer.la $(LIB_KPARTS) + +libkomposer_defaulteditor_la_SOURCES = defaulteditor.cpp + +METASOURCES = AUTO + +servicedir = $(kde_servicesdir)/komposer +service_DATA = defaulteditor.desktop + +rcdir = $(kde_datadir)/komposer_defaulteditor +rc_DATA = defaulteditorui.rc diff --git a/libtdepim/komposer/plugins/default/defaulteditor.cpp b/libtdepim/komposer/plugins/default/defaulteditor.cpp new file mode 100644 index 000000000..27018ce5a --- /dev/null +++ b/libtdepim/komposer/plugins/default/defaulteditor.cpp @@ -0,0 +1,361 @@ +/** + * defaulteditor.cpp + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "defaulteditor.h" +#include "core.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +typedef KGenericFactory DefaultEditorFactory; +K_EXPORT_COMPONENT_FACTORY( libkomposer_defaulteditor, + DefaultEditorFactory( "komposer_defaulteditor" ) ) + +DefaultEditor::DefaultEditor( TQObject *parent, const char *name, const TQStringList &args ) + : Editor( parent, name, args ), m_textEdit( 0 ) +{ + setInstance( DefaultEditorFactory::instance() ); + + m_textEdit = new TQTextEdit( 0 ); + + createActions( actionCollection() ); + + setXMLFile( "defaulteditorui.rc" ); +} + +DefaultEditor::~DefaultEditor() +{ +} + + +TQWidget* +DefaultEditor::widget() +{ + return m_textEdit; +} + +TQString +DefaultEditor::text() const +{ + return m_textEdit->text(); +} + +void +DefaultEditor::setText( const TQString &text ) +{ + m_textEdit->setText( text ); +} + +void +DefaultEditor::changeSignature( const TQString &sig ) +{ + TQString text = m_textEdit->text(); + + int sigStart = text.findRev( "-- " ); + TQString sigText = TQString( "-- \n%1" ).tqarg( sig ); + + text.replace( sigStart, text.length(), sigText ); +} + +void +DefaultEditor::createActions( KActionCollection *ac ) +{ + // + // File Actions + // + (void) KStdAction::open( this, TQT_SLOT(open()), ac ); + (void) KStdAction::openRecent( this, TQT_SLOT(openURL(const KURL &)), ac ); + (void) KStdAction::save( this, TQT_SLOT(save()), ac ); + (void) KStdAction::saveAs( this, TQT_SLOT(saveAs()), ac ); + + // + // Edit Actions + // + KAction *actionUndo = KStdAction::undo( m_textEdit, TQT_SLOT(undo()), ac ); + actionUndo->setEnabled( false ); + connect( m_textEdit, TQT_SIGNAL(undoAvailable(bool)), + actionUndo, TQT_SLOT(setEnabled(bool)) ); + + KAction *actionRedo = KStdAction::redo( m_textEdit, TQT_SLOT(redo()), ac ); + actionRedo->setEnabled( false ); + connect( m_textEdit, TQT_SIGNAL(redoAvailable(bool)), + actionRedo, TQT_SLOT(setEnabled(bool)) ); + + KAction *action_cut = KStdAction::cut( m_textEdit, TQT_SLOT(cut()), ac ); + action_cut->setEnabled( false ); + connect( m_textEdit, TQT_SIGNAL(copyAvailable(bool)), + action_cut, TQT_SLOT(setEnabled(bool)) ); + + KAction *action_copy = KStdAction::copy( m_textEdit, TQT_SLOT(copy()), ac ); + action_copy->setEnabled( false ); + connect( m_textEdit, TQT_SIGNAL(copyAvailable(bool)), + action_copy, TQT_SLOT(setEnabled(bool)) ); + + (void) KStdAction::print( this, TQT_SLOT(print()), ac ); + + (void) KStdAction::paste( m_textEdit, TQT_SLOT(paste()), ac ); + (void) new KAction( i18n( "C&lear" ), 0, + m_textEdit, TQT_SLOT(removeSelectedText()), + ac, "edit_clear" ); + + (void) KStdAction::selectAll( m_textEdit, TQT_SLOT(selectAll()), ac ); + + // + // View Actions + // + (void) KStdAction::zoomIn( m_textEdit, TQT_SLOT(zoomIn()), ac ); + (void) KStdAction::zoomOut( m_textEdit, TQT_SLOT(zoomOut()), ac ); + + // + // Character Formatting + // + m_actionBold = new KToggleAction( i18n("&Bold"), "text_bold", CTRL+Key_B, + ac, "format_bold" ); + connect( m_actionBold, TQT_SIGNAL(toggled(bool)), + m_textEdit, TQT_SLOT(setBold(bool)) ); + + m_actionItalic = new KToggleAction( i18n("&Italic"), "text_italic", CTRL+Key_I, + ac, "format_italic" ); + + connect( m_actionItalic, TQT_SIGNAL(toggled(bool)), + m_textEdit, TQT_SLOT(setItalic(bool) )); + + m_actionUnderline = new KToggleAction( i18n("&Underline"), "text_under", CTRL+Key_U, + ac, "format_underline" ); + + connect( m_actionUnderline, TQT_SIGNAL(toggled(bool)), + m_textEdit, TQT_SLOT(setUnderline(bool)) ); + + (void) new KAction( i18n("Text &Color..."), "colorpicker", 0, + this, TQT_SLOT(formatColor()), + ac, "format_color" ); + + // + // Font + // + m_actionFont = new KFontAction( i18n("&Font"), 0, + ac, "format_font" ); + connect( m_actionFont, TQT_SIGNAL(activated(const TQString &)), + m_textEdit, TQT_SLOT(setFamily(const TQString &)) ); + + + m_actionFontSize = new KFontSizeAction( i18n("Font &Size"), 0, + ac, "format_font_size" ); + connect( m_actionFontSize, TQT_SIGNAL(fontSizeChanged(int)), + m_textEdit, TQT_SLOT(setPointSize(int)) ); + + // + // Alignment + // + m_actionAlignLeft = new KToggleAction( i18n("Align &Left"), "text_left", 0, + ac, "format_align_left" ); + connect( m_actionAlignLeft, TQT_SIGNAL(toggled(bool)), + this, TQT_SLOT(setAlignLeft(bool)) ); + + m_actionAlignCenter = new KToggleAction( i18n("Align &Center"), "text_center", 0, + ac, "format_align_center" ); + connect( m_actionAlignCenter, TQT_SIGNAL(toggled(bool)), + this, TQT_SLOT(setAlignCenter(bool)) ); + + m_actionAlignRight = new KToggleAction( i18n("Align &Right"), "text_right", 0, + ac, "format_align_right" ); + connect( m_actionAlignRight, TQT_SIGNAL(toggled(bool)), + this, TQT_SLOT(setAlignRight(bool)) ); + + m_actionAlignJustify = new KToggleAction( i18n("&Justify"), "text_block", 0, + ac, "format_align_justify" ); + connect( m_actionAlignJustify, TQT_SIGNAL(toggled(bool)), + this, TQT_SLOT(setAlignJustify(bool)) ); + + m_actionAlignLeft->setExclusiveGroup( "tqalignment" ); + m_actionAlignCenter->setExclusiveGroup( "tqalignment" ); + m_actionAlignRight->setExclusiveGroup( "tqalignment" ); + m_actionAlignJustify->setExclusiveGroup( "tqalignment" ); + + // + // Tools + // + (void) KStdAction::spelling( this, TQT_SLOT(checkSpelling()), ac ); + + // + // Setup enable/disable + // + updateActions(); + + connect( m_textEdit, TQT_SIGNAL(currentFontChanged(const TQFont &)), + this, TQT_SLOT( updateFont() ) ); + connect( m_textEdit, TQT_SIGNAL(currentFontChanged(const TQFont &)), + this, TQT_SLOT(updateCharFmt()) ); + connect( m_textEdit, TQT_SIGNAL(cursorPositionChanged(int, int)), + this, TQT_SLOT(updateAligment()) ); +} + +void +DefaultEditor::updateActions() +{ + updateCharFmt(); + updateAligment(); + updateFont(); +} + +void +DefaultEditor::updateCharFmt() +{ + m_actionBold->setChecked( m_textEdit->bold() ); + m_actionItalic->setChecked( m_textEdit->italic() ); + m_actionUnderline->setChecked( m_textEdit->underline() ); +} + +void +DefaultEditor::updateAligment() +{ + int align = m_textEdit->tqalignment(); + + switch ( align ) { + case AlignRight: + m_actionAlignRight->setChecked( true ); + break; + case AlignCenter: + m_actionAlignCenter->setChecked( true ); + break; + case AlignLeft: + m_actionAlignLeft->setChecked( true ); + break; + case AlignJustify: + m_actionAlignJustify->setChecked( true ); + break; + default: + break; + } +} + +void +DefaultEditor::updateFont() +{ + if ( m_textEdit->pointSize() > 0 ) + m_actionFontSize->setFontSize( m_textEdit->pointSize() ); + m_actionFont->setFont( m_textEdit->family() ); +} + +void +DefaultEditor::formatColor() +{ + TQColor col; + + int s = KColorDialog::getColor( col, m_textEdit->color(), m_textEdit ); + if ( s != TQDialog::Accepted ) + return; + + m_textEdit->setColor( col ); +} + +void +DefaultEditor::setAlignLeft( bool yes ) +{ + if ( yes ) + m_textEdit->tqsetAlignment( AlignLeft ); +} + +void +DefaultEditor::setAlignRight( bool yes ) +{ + if ( yes ) + m_textEdit->tqsetAlignment( AlignRight ); +} + +void +DefaultEditor::setAlignCenter( bool yes ) +{ + if ( yes ) + m_textEdit->tqsetAlignment( AlignCenter ); +} + +void +DefaultEditor::setAlignJustify( bool yes ) +{ + if ( yes ) + m_textEdit->tqsetAlignment( AlignJustify ); +} + +// +// Content Actions +// + +bool +DefaultEditor::open() +{ + KURL url = KFileDialog::getOpenURL(); + if ( url.isEmpty() ) + return false; + + //fixme + //return openURL( url ); + return true; +} + +bool +DefaultEditor::saveAs() +{ + KURL url = KFileDialog::getSaveURL(); + if ( url.isEmpty() ) + return false; + + //FIXME + //return KParts::ReadWritePart::saveAs( url ); + return true; +} + +void +DefaultEditor::checkSpelling() +{ + TQString s; + if ( m_textEdit->hasSelectedText() ) + s = m_textEdit->selectedText(); + else + s = m_textEdit->text(); + + //KSpell::modalCheck( s ); +} + +bool +DefaultEditor::print() +{ + return true; +} + +#include "defaulteditor.moc" diff --git a/libtdepim/komposer/plugins/default/defaulteditor.desktop b/libtdepim/komposer/plugins/default/defaulteditor.desktop new file mode 100644 index 000000000..910f7d89c --- /dev/null +++ b/libtdepim/komposer/plugins/default/defaulteditor.desktop @@ -0,0 +1,109 @@ +[Desktop Entry] +Type=Service +Icon=editor +ServiceTypes=Komposer/Editor + +X-KDE-Library=libkomposer_defaulteditor +X-Komposer-Version=1 +X-Komposer-Weight=10 + +X-KDE-PluginInfo-Author=Zack Rusin +X-KDE-PluginInfo-Email=zack@kde.org +X-KDE-PluginInfo-Name=komposer_defaulteditor +X-KDE-PluginInfo-Version=0.0.1 +X-KDE-PluginInfo-Website=http://www.kde.org +X-KDE-PluginInfo-Category=Editors +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=LGPL +X-KDE-PluginInfo-EnabledByDefault=true +Name=Komposer Editor +Name[af]=Komposer Redigeerder +Name[bg]=Редактор за Komposer +Name[br]=Aozer Komposer +Name[ca]=Editor Komposer +Name[cs]=Komposer editor +Name[da]=Komposer-editor +Name[el]=ΕπεξεÏγαστής Komposer +Name[eo]=Komposer-redaktilo +Name[es]=Editor Komposer +Name[et]=Komposeri redaktor +Name[eu]=Komposer editorea +Name[fa]=ویرایشگر Komposer +Name[fi]=Komposer-muokkain +Name[fr]=Éditeur Komposer +Name[fy]=Komposer-bewurker +Name[ga]=Eagarthóir Komposer +Name[gl]=Editor Komposer +Name[hu]=Komposer szerkesztÅ‘ +Name[is]=Komposer ritill +Name[it]=Editor Komposer +Name[ja]=Komposer エディタ +Name[kk]=Komposer өңдегіші +Name[km]=កម្មវិធី​និពន្ធ Komposer +Name[lt]=Komposer redaktorius +Name[ms]=Editor Komposer +Name[nb]=Komposer-redigering +Name[ne]=कमà¥à¤ªà¥‹à¤œà¤° समà¥à¤ªà¤¾à¤¦à¤• +Name[nl]=Komposer-editor +Name[nn]=Komposer-redigering +Name[pl]=Edytor Komposer +Name[pt]=Editor Kompositor +Name[pt_BR]=Editor do Komposer +Name[ru]=Редактор Komposer +Name[sk]=Editor Komposer +Name[sl]=Urejevalnik Komposer +Name[sr]=Уређивач Komposer-а +Name[sr@Latn]=UreÄ‘ivaÄ Komposer-a +Name[sv]=Komposer editor +Name[ta]=கமà¯à®ªà¯‹à®šà®°à¯ தொகà¯à®ªà¯à®ªà®¾à®©à¯ +Name[tr]=Komposer Düzenleyicisi +Name[uk]=Редактор Komposer +Name[zh_CN]=Komposer 编辑器 +Name[zh_TW]=Komposer 編輯器 +Comment=Komposer default editor +Comment[af]=Komposer standaard redigeerder +Comment[bg]=Подразбиращ Ñе редактор за Komposer +Comment[ca]=Editor predeterminat de Komposer +Comment[cs]=Výchozí Komposer editor +Comment[da]=Komposer standardeditor +Comment[de]=Komposer Standardeditor +Comment[el]=ΠÏοεπιλεγμένος επεξεÏγαστής του Komposer +Comment[eo]=Komposer-redaktilo apriora +Comment[es]=Editor predefinido Komposer +Comment[et]=Komposeri vaikeredaktor +Comment[eu]=Komposer editore lehenetsia +Comment[fa]=ویرایشگر پیش‌Ùرض Komposer +Comment[fi]=Komposer oletusmuokkain +Comment[fr]=Éditeur Komposer par défaut +Comment[fy]=Komposer standertbewurker +Comment[ga]=Eagarthóir réamhshocraithe Komposer +Comment[gl]=Editor por defecto Komposer +Comment[he]=עורך ברירת מחדל של Kompoer +Comment[hu]=A Komposer alapértelmezett szerkesztÅ‘je +Comment[is]=Sjálfgefinn ritill Komposer +Comment[it]=Editor di default per Komposer +Comment[ja]=Komposer 標準エディタ +Comment[kk]=Komposer әдетті өңдегіші +Comment[km]=កម្មវិធី​និពន្ធ​លំនាំដើម​របស់ Komposer +Comment[ko]=Komposer 기본 편집기 +Comment[lt]=Komposer numatytasis redaktorius +Comment[ms]=Pengedit piawai Komposer +Comment[nb]=Komposer standard-redigerer +Comment[nds]=Komposer-Standardeditor +Comment[ne]=कमà¥à¤ªà¥‹à¤œà¤°à¤•à¥‹ पूरà¥à¤µà¤¨à¤¿à¤°à¥à¤§à¤¾à¤°à¤¿à¤¤ समà¥à¤ªà¤¾à¤¦à¤• +Comment[nl]=Komposer standaardeditor +Comment[nn]=Komposer standard-redigeringsprogram +Comment[pl]=DomyÅ›lny edytor Komposera +Comment[pt]=Editor predefinido Kompositor +Comment[pt_BR]=Editor padrão do Komposer +Comment[ru]=Редактор Komposer по умолчанию +Comment[sk]=Å tandardný editor Komposer +Comment[sl]=Privzeti urejevalnik Komposer +Comment[sr]=Подразумевани Komposer-ов уређивач +Comment[sr@Latn]=Podrazumevani Komposer-ov ureÄ‘ivaÄ +Comment[sv]=Komposer standardeditor +Comment[ta]=கமà¯à®ªà¯‹à®šà®°à¯ à®®à¯à®©à¯à®©à®¿à®°à¯à®ªà¯à®ªà¯ தொகà¯à®ªà¯à®ªà®¾à®©à¯ +Comment[tr]=Öntanımlı Komposer düzenleyicisi +Comment[uk]=Типовий редактор Komposer +Comment[zh_CN]=Komposer 默认编辑器 +Comment[zh_TW]=Komposer é è¨­ç·¨è¼¯å™¨ diff --git a/libtdepim/komposer/plugins/default/defaulteditor.h b/libtdepim/komposer/plugins/default/defaulteditor.h new file mode 100644 index 000000000..84cedcbc6 --- /dev/null +++ b/libtdepim/komposer/plugins/default/defaulteditor.h @@ -0,0 +1,118 @@ +/* + * defaulteditor.h + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef DEFAULTEDITOR_H +#define DEFAULTEDITOR_H + +#include "editor.h" + +class TQTextEdit; +class KFontAction; +class KFontSizeAction; +class KToggleAction; +class KActionCollection; + + +class DefaultEditor : public Komposer::Editor +{ + Q_OBJECT + TQ_OBJECT +public: + DefaultEditor( TQObject *parent, const char *name, const TQStringList &args ); + ~DefaultEditor(); + + virtual TQWidget *widget(); + virtual TQString text() const; +public slots: + virtual void setText( const TQString &txt ); + virtual void changeSignature( const TQString &txt ); + + /** + * Displays a file dialog and loads the selected file. + */ + bool open(); + + /** + * Displays a file dialog and saves to the selected file. + */ + bool saveAs(); + + /** + * Prints the current document + */ + bool print(); + + /** + * Displays a color dialog and sets the text color to the selected value. + */ + void formatColor(); + + void checkSpelling(); + + /** + * @internal + */ + void setAlignLeft( bool yes ); + + /** + * @internal + */ + void setAlignRight( bool yes ); + + /** + * @internal + */ + void setAlignCenter( bool yes ); + + /** + * @internal + */ + void setAlignJustify( bool yes ); + +protected slots: + /** + * Creates the part's actions in the part's action collection. + */ + void createActions( KActionCollection *ac ); + + void updateActions(); + + void updateFont(); + void updateCharFmt(); + void updateAligment(); + +private: + TQTextEdit *m_textEdit; + + KToggleAction *m_actionBold; + KToggleAction *m_actionItalic; + KToggleAction *m_actionUnderline; + + KFontAction *m_actionFont; + KFontSizeAction *m_actionFontSize; + + KToggleAction *m_actionAlignLeft; + KToggleAction *m_actionAlignRight; + KToggleAction *m_actionAlignCenter; + KToggleAction *m_actionAlignJustify; +}; + +#endif diff --git a/libtdepim/komposer/plugins/default/defaulteditorui.rc b/libtdepim/komposer/plugins/default/defaulteditorui.rc new file mode 100644 index 000000000..de8c2e6d2 --- /dev/null +++ b/libtdepim/komposer/plugins/default/defaulteditorui.rc @@ -0,0 +1,90 @@ + + + + &Edit + + + + + + + + + + + &View + + + + + F&ormat + + + + + + + &Alignment + + + + + + + + + + + + &Tools + + + + &Help + + +Editor Toolbar + + + + + + + + + + + +Format Toolbar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libtdepim/komposer/test/Makefile.am b/libtdepim/komposer/test/Makefile.am new file mode 100644 index 000000000..af51004e8 --- /dev/null +++ b/libtdepim/komposer/test/Makefile.am @@ -0,0 +1,7 @@ +AM_CPPFLAGS = -I$(top_srcdir) -I../core $(all_includes) +LDADD = $(LIB_KPARTS) ../core/libkomposer.la +AM_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor + +check_PROGRAMS = test + +test_SOURCES = test.cpp diff --git a/libtdepim/komposer/test/test.cpp b/libtdepim/komposer/test/test.cpp new file mode 100644 index 000000000..5d4544d2a --- /dev/null +++ b/libtdepim/komposer/test/test.cpp @@ -0,0 +1,56 @@ +/** + * test.cpp + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "core.h" + +#include +#include +#include +#include +#include + +#include + +static const char description[] = + I18N_NOOP( "KDE mail editing manager" ); + +static const char version[] = "0.0.1 (SVN)"; + +int main(int argc, char **argv) +{ + KAboutData about( "komposertest", I18N_NOOP( "KomposerTest" ), version, description, + KAboutData::License_GPL, "(C) 2001-2003 The Kontact developers", 0, "http://kontact.kde.org", "zack@kde.org" ); + about.addAuthor( "Zack Rusin", 0, "zack@kde.org" ); + + KCmdLineArgs::init( argc, argv, &about ); + KUniqueApplication app; + + // see if we are starting with session management + if ( app.isRestored() ) + RESTORE( Komposer::Core ) + else { + // no session.. just start up normally + Komposer::Core *mw = new Komposer::Core; + mw->show(); + } + + return app.exec(); +} diff --git a/libtdepim/kpartsdesignerplugin/CMakeLists.txt b/libtdepim/kpartsdesignerplugin/CMakeLists.txt new file mode 100644 index 000000000..55c75251c --- /dev/null +++ b/libtdepim/kpartsdesignerplugin/CMakeLists.txt @@ -0,0 +1,32 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +add_definitions( -DQT_PLUGIN ) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/libtdepim + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### kpartsdesignerplugin (module) ############# + +tde_add_kpart( kpartsdesignerplugin AUTOMOC + SOURCES kpartsdesignerplugin.cpp + LINK kparts-shared kio-shared + DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/designer +) diff --git a/libtdepim/kpartsdesignerplugin/Makefile.am b/libtdepim/kpartsdesignerplugin/Makefile.am new file mode 100644 index 000000000..ebbfbfba2 --- /dev/null +++ b/libtdepim/kpartsdesignerplugin/Makefile.am @@ -0,0 +1,8 @@ +AM_CXXFLAGS = -DQT_PLUGIN +METASOURCES = AUTO +INCLUDES = $(all_includes) + +kde_widget_LTLIBRARIES = kpartsdesignerplugin.la +kpartsdesignerplugin_la_LDFLAGS = $(KDE_PLUGIN) -module $(all_libraries) $(LIB_QT) -ltdecore -lkio +kpartsdesignerplugin_la_LIBADD = $(LIB_KPARTS) +kpartsdesignerplugin_la_SOURCES = kpartsdesignerplugin.cpp diff --git a/libtdepim/kpartsdesignerplugin/README b/libtdepim/kpartsdesignerplugin/README new file mode 100644 index 000000000..fb9f42837 --- /dev/null +++ b/libtdepim/kpartsdesignerplugin/README @@ -0,0 +1,2 @@ +When moving this to kdelibs: the KPartsGenericPart class should move to libkparts so +that it's possible to add an accessor for m_part there. diff --git a/libtdepim/kpartsdesignerplugin/kpartsdesignerplugin.cpp b/libtdepim/kpartsdesignerplugin/kpartsdesignerplugin.cpp new file mode 100644 index 000000000..c3eedc329 --- /dev/null +++ b/libtdepim/kpartsdesignerplugin/kpartsdesignerplugin.cpp @@ -0,0 +1,117 @@ +/* + Copyright (C) 2004, David Faure + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kpartsdesignerplugin.h" + +#include +#include +#include +#include +#include +#include + +KPartsGenericPart::KPartsGenericPart( TQWidget* parentWidget, const char* name ) + : TQWidget( parentWidget, name ), m_part( 0 ) +{ + TQVBoxLayout* tqlayout = new TQVBoxLayout( this ); + tqlayout->setAutoAdd( true ); +} + +void KPartsGenericPart::load() +{ + if ( m_mimetype.isEmpty() || m_url.isEmpty() ) + return; // not enough info yet + // Here it crashes in KSycoca::openDatabase when trying to load the stuff from designer itself + // Not sure why - but it's not really needed anyway. + if ( !kapp ) + return; + TQString mimetype = m_mimetype; + if ( mimetype == "auto" ) + mimetype == KMimeType::findByURL( m_url )->name(); + if ( m_part ) { + delete m_part; + } + // "this" is both the parent widget and the parent object + m_part = KParts::ComponentFactory::createPartInstanceFromQuery( mimetype, TQString(), TQT_TQWIDGET(this), 0, TQT_TQOBJECT(this), 0 ); + if ( m_part ) { + m_part->openURL( m_url ); + m_part->widget()->show(); + } +} + +//// + +static const char* mykey = "KPartsGenericPart"; + +TQStringList KPartsWidgetPlugin::keys() const { + return TQStringList() << mykey; +} + +TQWidget * KPartsWidgetPlugin::create( const TQString & key, TQWidget * parent, const char * name ) { + if ( key == mykey ) + return new KPartsGenericPart( parent, name ); + return 0; +} + +TQString KPartsWidgetPlugin::group( const TQString & key ) const { + if ( key == mykey ) + return "Display (KDE)"; + return TQString(); +} + +#if 0 +TQIconSet KPartsWidgetPlugin::iconSet( const TQString & key ) const { + return TQIconSet(); +} +#endif + +TQString KPartsWidgetPlugin::includeFile( const TQString & key ) const { + if ( key == mykey ) + return "partplugin.h"; + return TQString(); +} + +TQString KPartsWidgetPlugin::toolTip( const TQString & key ) const { + if ( key == mykey ) + return "Generic KParts viewer"; + return TQString(); +} + +TQString KPartsWidgetPlugin::whatsThis( const TQString & key ) const { + if ( key == mykey ) + return "A widget to embed any KParts viewer, given a url and optionally a mimetype"; + return TQString(); +} + +bool KPartsWidgetPlugin::isContainer( const TQString & /*key*/ ) const { + return false; +} + +/// Duplicated from kdelibs/tdecore/kdemacros.h.in for those with kdelibs < 3.4 +#ifndef KDE_TQ_EXPORT_PLUGIN +#define KDE_TQ_EXPORT_PLUGIN(PLUGIN) \ + TQ_EXTERN_C KDE_EXPORT const char* qt_ucm_query_verification_data(); \ + TQ_EXTERN_C KDE_EXPORT TQUnknownInterface* ucm_instantiate(); \ + TQ_EXPORT_PLUGIN(PLUGIN) +#endif + +KDE_TQ_EXPORT_PLUGIN( KPartsWidgetPlugin ) + +#include "kpartsdesignerplugin.moc" + diff --git a/libtdepim/kpartsdesignerplugin/kpartsdesignerplugin.h b/libtdepim/kpartsdesignerplugin/kpartsdesignerplugin.h new file mode 100644 index 000000000..fc49f2511 --- /dev/null +++ b/libtdepim/kpartsdesignerplugin/kpartsdesignerplugin.h @@ -0,0 +1,71 @@ +/* + Copyright (C) 2005, David Faure + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#ifndef DESIGNER_PARTPLUGIN_H +#define DESIGNER_PARTPLUGIN_H + +#include +#include +namespace KParts { class ReadOnlyPart; } + +/** + * Generic part loader, able to view any kind of file for which + * a KParts::ReadOnlyPart is available + */ +class KPartsGenericPart : public TQWidget { + Q_OBJECT + TQ_OBJECT + TQ_PROPERTY( TQString url READ url WRITE setURL ) + TQ_PROPERTY( TQString mimetype READ mimetype WRITE setMimetype ) +public: + KPartsGenericPart( TQWidget* parentWidget, const char* name ); + + TQString url() const { return m_url; } + void setURL( const TQString& url ) { m_url = url; load(); } + + // The mimetype, or "auto" if unknown + TQString mimetype() const { return m_mimetype; } + void setMimetype( const TQString& mimetype ) { m_mimetype = mimetype; load(); } + +private: + void load(); + +private: + TQString m_mimetype; + TQString m_url; + KParts::ReadOnlyPart* m_part; +}; + +/** + * TQt designer plugin for embedding a KParts using KPartsGenericPart + */ +class KPartsWidgetPlugin : public TQWidgetPlugin { +public: + TQStringList keys() const; + TQWidget * create( const TQString & key, TQWidget * parent, const char * name ); + TQString group( const TQString & key ) const; + //TQIconSet iconSet( const TQString & key ) const; + TQString includeFile( const TQString & key ) const; + TQString toolTip( const TQString & key ) const; + TQString whatsThis( const TQString & key ) const; + bool isContainer( const TQString & key ) const; +}; + +#endif diff --git a/libtdepim/kpimprefs.cpp b/libtdepim/kpimprefs.cpp new file mode 100644 index 000000000..478ed7047 --- /dev/null +++ b/libtdepim/kpimprefs.cpp @@ -0,0 +1,187 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "kpimprefs.h" + +KPimPrefs::KPimPrefs( const TQString &name ) + : KConfigSkeleton( name ) +{ +} + +KPimPrefs::~KPimPrefs() +{ +} + +void KPimPrefs::usrSetDefaults() +{ + setCategoryDefaults(); +} + +void KPimPrefs::usrReadConfig() +{ + kdDebug(5300) << "KPimPrefs::usrReadConfig()" << endl; + + config()->setGroup("General"); + mCustomCategories = config()->readListEntry( "Custom Categories" ); + if ( mCustomCategories.isEmpty() ) setCategoryDefaults(); + mCustomCategories.sort(); +} + +const TQString KPimPrefs::timezone() +{ + TQString zone = ""; + + // Read TimeZoneId from korganizerrc. + KConfig korgcfg( locate( "config", "korganizerrc" ) ); + korgcfg.setGroup( "Time & Date" ); + TQString tz( korgcfg.readEntry( "TimeZoneId" ) ); + if ( !tz.isEmpty() ) { + zone = tz; + kdDebug(5300) << "timezone from korganizerrc is " << zone << endl; + } + + // If timezone not found in KOrg, use the system's default timezone. + if ( zone.isEmpty() ) { + char zonefilebuf[ PATH_MAX ]; + + int len = readlink( "/etc/localtime", zonefilebuf, PATH_MAX ); + if ( len > 0 && len < PATH_MAX ) { + zone = TQString::fromLocal8Bit( zonefilebuf, len ); + zone = zone.mid( zone.find( "zoneinfo/" ) + 9 ); + kdDebug(5300) << "system timezone from /etc/localtime is " << zone + << endl; + } else { + tzset(); + zone = tzname[ 0 ]; + kdDebug(5300) << "system timezone from tzset() is " << zone << endl; + } + } + + return( zone ); +} + +TQDateTime KPimPrefs::utcToLocalTime( const TQDateTime &_dt, + const TQString &timeZoneId ) +{ + TQDateTime dt(_dt); +// kdDebug() << "--- UTC: " << dt.toString() << endl; + + int yearCorrection = 0; + // The timezone conversion only works for dates > 1970 + // For dates < 1970 we adjust the date to be in 1970, + // do the correction there and then re-adjust back. + // Actually, we use 1971 to prevent errors around + // January 1, 1970 + int year = dt.date().year(); + if (year < 1971) + { + yearCorrection = 1971 - year; + dt = dt.addYears(yearCorrection); +// kdDebug() << "--- Adjusted UTC: " << dt.toString() << endl; + } + + TQCString origTz = getenv("TZ"); + + setenv( "TZ", "UTC", 1 ); + time_t utcTime = dt.toTime_t(); + + setenv( "TZ", timeZoneId.local8Bit(), 1 ); + struct tm *local = localtime( &utcTime ); + + if ( origTz.isNull() ) { + unsetenv( "TZ" ); + } else { + setenv( "TZ", origTz, 1 ); + } + tzset(); + + TQDateTime result( TQDate( local->tm_year + 1900 - yearCorrection, + local->tm_mon + 1, local->tm_mday ), + TQTime( local->tm_hour, local->tm_min, local->tm_sec ) ); + +// kdDebug() << "--- LOCAL: " << result.toString() << endl; + return result; +} + +TQDateTime KPimPrefs::localTimeToUtc( const TQDateTime &_dt, + const TQString &timeZoneId ) +{ + TQDateTime dt(_dt); +// kdDebug() << "--- LOCAL: " << dt.toString() << endl; + + int yearCorrection = 0; + // The timezone conversion only works for dates > 1970 + // For dates < 1970 we adjust the date to be in 1970, + // do the correction there and then re-adjust back. + // Actually, we use 1971 to prevent errors around + // January 1, 1970 + + int year = dt.date().year(); + if (year < 1971) + { + yearCorrection = 1971 - year; + dt = dt.addYears(yearCorrection); +// kdDebug() << "--- Adjusted LOCAL: " << dt.toString() << endl; + } + + TQCString origTz = getenv("TZ"); + + setenv( "TZ", timeZoneId.local8Bit(), 1 ); + time_t localTime = dt.toTime_t(); + + setenv( "TZ", "UTC", 1 ); + struct tm *utc = gmtime( &localTime ); + + if ( origTz.isNull() ) { + unsetenv( "TZ" ); + } else { + setenv( "TZ", origTz, 1 ); + } + tzset(); + + TQDateTime result( TQDate( utc->tm_year + 1900 - yearCorrection, + utc->tm_mon + 1, utc->tm_mday ), + TQTime( utc->tm_hour, utc->tm_min, utc->tm_sec ) ); + +// kdDebug() << "--- UTC: " << result.toString() << endl; + + return result; +} + +void KPimPrefs::usrWriteConfig() +{ + config()->setGroup( "General" ); + config()->writeEntry( "Custom Categories", mCustomCategories ); +} diff --git a/libtdepim/kpimprefs.h b/libtdepim/kpimprefs.h new file mode 100644 index 000000000..1d88a8d8f --- /dev/null +++ b/libtdepim/kpimprefs.h @@ -0,0 +1,86 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KPIMPREFS_H +#define KPIMPREFS_H + +#include + +#include +#include + +class TQString; + +class KDE_EXPORT KPimPrefs : public KConfigSkeleton +{ + public: + KPimPrefs( const TQString &name = TQString() ); + + virtual ~KPimPrefs(); + + /** Set preferences to default values */ + void usrSetDefaults(); + + /** Read preferences from config file */ + void usrReadConfig(); + + /** Write preferences to config file */ + void usrWriteConfig(); + + /** + * Get user's timezone. + * + * This will first look for whatever timezone is stored in KOrganizer's + * configuration file. If no timezone is found there, it uses + * /etc/localtime. + * + * The value returned may be in various formats (for example, + * America/New_York or EST) so your program should be prepared to these + * formats. + * + * The Calendar class in libkcal says accepts all timezone codes that are + * listed in /usr/share/zoneinfo/zone.tab. + * + * @see Calendar + */ + static const TQString timezone(); + + /** + Convert time given in UTC to local time at timezone specified by given + timezone id. + */ + static TQDateTime utcToLocalTime( const TQDateTime &dt, + const TQString &timeZoneId ); + + /** + Convert time given in local time at timezone specified by given + timezone id to UTC. + */ + static TQDateTime localTimeToUtc( const TQDateTime &dt, + const TQString &timeZoneId ); + + public: + TQStringList mCustomCategories; + + protected: + virtual void setCategoryDefaults() {} +}; + +#endif diff --git a/libtdepim/kpimurlrequesterdlg.cpp b/libtdepim/kpimurlrequesterdlg.cpp new file mode 100644 index 000000000..553ca659f --- /dev/null +++ b/libtdepim/kpimurlrequesterdlg.cpp @@ -0,0 +1,41 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Wilco Greven + + library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#include +#include +#include +#include + +// KDE3.4 or KDE4.0: FIXME: Move to kdelibs! +KURL KPimURLRequesterDlg::getURL( const TQString& dir, const TQString &label, + TQWidget *parent, const TQString& caption ) +{ + KURLRequesterDlg dlg(dir, label, parent, "filedialog", true); + + dlg.setCaption(caption.isNull() ? i18n("Open") : caption); + + dlg.exec(); + + const KURL& url = dlg.selectedURL(); + if (url.isValid()) + KRecentDocument::add(url); + + return url; +} diff --git a/libtdepim/kpimurlrequesterdlg.h b/libtdepim/kpimurlrequesterdlg.h new file mode 100644 index 000000000..6a00cf4ef --- /dev/null +++ b/libtdepim/kpimurlrequesterdlg.h @@ -0,0 +1,47 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Wilco Greven + + library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KPIMURLREQUESTDLG_H_INCLUDED +#define KPIMURLREQUESTDLG_H_INCLUDED + +#include +#include +#include + +class TQWidget; + +class KDE_EXPORT KPimURLRequesterDlg +{ + public: + /** + * Creates a modal dialog with the given label text, executes it and + * returns the selected URL. + * + * @param url This specifies the initial path of the input line. + * @param text The text to be shown on the label. + * @param parent The widget the dialog will be centered on initially. + */ + static KURL getURL( const TQString &url = TQString(), + const TQString &text = TQString(), + TQWidget *parent = 0, + const TQString &caption = TQString() ); +}; + +#endif // KPIMURLREQUESTDLG_H_INCLUDED + diff --git a/libtdepim/kpixmapregionselectordialog.cpp b/libtdepim/kpixmapregionselectordialog.cpp new file mode 100644 index 000000000..b715e000b --- /dev/null +++ b/libtdepim/kpixmapregionselectordialog.cpp @@ -0,0 +1,131 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2004 Antonio Larrosa +#include +#include +#include +#include + +using namespace KPIM; + +KPixmapRegionSelectorDialog::KPixmapRegionSelectorDialog(TQWidget *parent, + const char *name, bool modal ) : KDialogBase(parent, name, modal, i18n("Select Region of Image"), Help|Ok|Cancel, Ok, true ) +{ + TQVBox *vbox=new TQVBox(this); + new TQLabel(i18n("Please click and drag on the image to select the region of interest:"), vbox); + m_pixmapSelectorWidget= new KPixmapRegionSelectorWidget(vbox); + + vbox->setSpacing( KDialog::spacingHint() ); + + setMainWidget(vbox); +} + +KPixmapRegionSelectorDialog::~KPixmapRegionSelectorDialog() +{ +} + +TQRect KPixmapRegionSelectorDialog::getSelectedRegion(const TQPixmap &pixmap, TQWidget *parent ) +{ + KPixmapRegionSelectorDialog dialog(parent); + + dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); + + TQDesktopWidget desktopWidget; + TQRect screen=desktopWidget.availableGeometry(); + dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( + (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); + + int result = dialog.exec(); + + TQRect rect; + + if ( result == TQDialog::Accepted ) + rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion(); + + return rect; +} + +TQRect KPixmapRegionSelectorDialog::getSelectedRegion(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent ) +{ + KPixmapRegionSelectorDialog dialog(parent); + + dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); + dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight); + + TQDesktopWidget desktopWidget; + TQRect screen=desktopWidget.availableGeometry(); + dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( + (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); + + int result = dialog.exec(); + + TQRect rect; + + if ( result == TQDialog::Accepted ) + rect = dialog.pixmapRegionSelectorWidget()->unzoomedSelectedRegion(); + + return rect; +} + +TQImage KPixmapRegionSelectorDialog::getSelectedImage(const TQPixmap &pixmap, TQWidget *parent ) +{ + KPixmapRegionSelectorDialog dialog(parent); + + dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); + + TQDesktopWidget desktopWidget; + TQRect screen=desktopWidget.availableGeometry(); + dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( + (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); + int result = dialog.exec(); + + TQImage image; + + if ( result == TQDialog::Accepted ) + image = dialog.pixmapRegionSelectorWidget()->selectedImage(); + + return image; +} + +TQImage KPixmapRegionSelectorDialog::getSelectedImage(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent ) +{ + KPixmapRegionSelectorDialog dialog(parent); + + dialog.pixmapRegionSelectorWidget()->setPixmap(pixmap); + dialog.pixmapRegionSelectorWidget()->setSelectionAspectRatio(aspectRatioWidth,aspectRatioHeight); + + TQDesktopWidget desktopWidget; + TQRect screen=desktopWidget.availableGeometry(); + dialog.pixmapRegionSelectorWidget()->setMaximumWidgetSize( + (int)(screen.width()*4.0/5), (int)(screen.height()*4.0/5)); + + int result = dialog.exec(); + + TQImage image; + + if ( result == TQDialog::Accepted ) + image = dialog.pixmapRegionSelectorWidget()->selectedImage(); + + return image; +} + diff --git a/libtdepim/kpixmapregionselectordialog.h b/libtdepim/kpixmapregionselectordialog.h new file mode 100644 index 000000000..ee864391a --- /dev/null +++ b/libtdepim/kpixmapregionselectordialog.h @@ -0,0 +1,112 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2004 Antonio Larrosa +#include +#include +#include + +namespace KPIM { + +/** + * A dialog that uses a KPixmapRegionSelectorWidget to allow the user + * to select a region of an image. If you want to use special features + * like forcing the selected area to have a fixed aspect ratio, you can use + * @see pixmapRegionSelectorWidget() to get the pointer to the + * pixmapRegionSelectorWidget object and set the desired options there. + * + * There are some convenience methods that allow to easily show a dialog + * for the user to select a region of an image, and just care about the selected + * image. + * + * @author Antonio Larrosa + * @since 3.4 + */ +class KDE_EXPORT KPixmapRegionSelectorDialog : public KDialogBase +{ +public: + /** + * The constructor of an empty KPixmapRegionSelectorDialog, you have to call + * later the setPixmap method of the KPixmapRegionSelectorWidget widget of + * the new object. + */ + KPixmapRegionSelectorDialog(TQWidget *parent=0L, const char *name=0L, + bool modal = false ); + /** + * The destructor of the dialog + */ + ~KPixmapRegionSelectorDialog(); + + /** + * @returns the KPixmapRegionSelectorWidget widget so that additional + * parameters can be set by using it. + */ + KPIM::KPixmapRegionSelectorWidget *pixmapRegionSelectorWidget() const + { return m_pixmapSelectorWidget; } + + /** + * Creates a modal dialog, lets the user to select a region of the @p pixmap + * and returns when the dialog is closed. + * + * @returns the selected rectangle, or an invalid rectangle if the user + * pressed the Cancel button. + */ + static TQRect getSelectedRegion(const TQPixmap &pixmap, TQWidget *parent = 0L ); + + /** + * Creates a modal dialog, lets the user to select a region of the @p pixmap + * with the same aspect ratio than @p aspectRatioWidth x @p aspectRatioHeight + * and returns when the dialog is closed. + * + * @returns the selected rectangle, or an invalid rectangle if the user + * pressed the Cancel button. + */ + static TQRect getSelectedRegion(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent = 0L ); + + /** + * Creates a modal dialog, lets the user to select a region of the @p pixmap + * and returns when the dialog is closed. + * + * @returns the selected image, or an invalid image if the user + * pressed the Cancel button. + */ + static TQImage getSelectedImage(const TQPixmap &pixmap, TQWidget *parent = 0L ); + + /** + * Creates a modal dialog, lets the user to select a region of the @p pixmap + * with the same aspect ratio than @p aspectRatioWidth x @p aspectRatioHeight + * and returns when the dialog is closed. + * + * @returns the selected image, or an invalid image if the user + * pressed the Cancel button. + */ + static TQImage getSelectedImage(const TQPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, TQWidget *parent = 0L ); + +protected: + KPIM::KPixmapRegionSelectorWidget *m_pixmapSelectorWidget; +}; + +} + +#endif diff --git a/libtdepim/kpixmapregionselectorwidget.cpp b/libtdepim/kpixmapregionselectorwidget.cpp new file mode 100644 index 000000000..d687ae8a1 --- /dev/null +++ b/libtdepim/kpixmapregionselectorwidget.cpp @@ -0,0 +1,454 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2004 Antonio Larrosa +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace KPIM; + +KPixmapRegionSelectorWidget::KPixmapRegionSelectorWidget( TQWidget *parent, + const char *name) : TQWidget( parent, name) +{ + TQHBoxLayout * hboxLayout=new TQHBoxLayout( this ); + + hboxLayout->addStretch(); + TQVBoxLayout * vboxLayout=new TQVBoxLayout( hboxLayout ); + + vboxLayout->addStretch(); + m_label = new TQLabel(this, "pixmapHolder"); + m_label->setBackgroundMode( TQt::NoBackground ); + m_label->installEventFilter( this ); + + vboxLayout->addWidget(m_label); + vboxLayout->addStretch(); + + hboxLayout->addStretch(); + + m_forcedAspectRatio=0; + + m_zoomFactor=1.0; +} + +KPixmapRegionSelectorWidget::~KPixmapRegionSelectorWidget() +{ +} + +void KPixmapRegionSelectorWidget::setPixmap( const TQPixmap &pixmap ) +{ + Q_ASSERT(!pixmap.isNull()); //This class isn't designed to deal with null pixmaps. + m_originalPixmap = pixmap; + m_unzoomedPixmap = pixmap; + m_label->setPixmap( pixmap ); + resetSelection(); +} + +void KPixmapRegionSelectorWidget::resetSelection() +{ + m_selectedRegion = m_originalPixmap.rect(); + updatePixmap(); +} + +TQRect KPixmapRegionSelectorWidget::selectedRegion() const +{ + return m_selectedRegion; +} + +void KPixmapRegionSelectorWidget::setSelectedRegion(const TQRect &rect) +{ + if (!rect.isValid()) resetSelection(); + else + { + m_selectedRegion=rect; + updatePixmap(); + + TQRect r=unzoomedSelectedRegion(); + } +} + +void KPixmapRegionSelectorWidget::updatePixmap() +{ + Q_ASSERT(!m_originalPixmap.isNull()); if(m_originalPixmap.isNull()) { m_label->setPixmap(m_originalPixmap); return; } + if (m_selectedRegion.width()>m_originalPixmap.width()) m_selectedRegion.setWidth( m_originalPixmap.width() ); + if (m_selectedRegion.height()>m_originalPixmap.height()) m_selectedRegion.setHeight( m_originalPixmap.height() ); + + TQPainter painter; + if (m_linedPixmap.isNull()) + { + m_linedPixmap = m_originalPixmap; + + painter.begin(&m_linedPixmap); + painter.setRasterOp( TQt::XorROP ); + painter.fillRect(0,0,m_linedPixmap.width(), m_linedPixmap.height(), + TQBrush( TQColor(255,255,255), TQt::BDiagPattern) ); + painter.end(); + + TQImage image=m_linedPixmap.convertToImage(); + image=KImageEffect::fade(image, 0.4, TQColor(0,0,0)); + m_linedPixmap.convertFromImage(image); + } + + TQPixmap pixmap = m_linedPixmap; + + painter.begin(&pixmap); + painter.drawPixmap( m_selectedRegion.topLeft(), + m_originalPixmap, m_selectedRegion ); + + painter.setPen( TQColor(255,255,255) ); + painter.setRasterOp( TQt::XorROP ); + + painter.drawRect( m_selectedRegion ); + + painter.end(); + + m_label->setPixmap(pixmap); +} + +KPopupMenu *KPixmapRegionSelectorWidget::createPopupMenu() +{ + KPopupMenu *popup=new KPopupMenu(this, "PixmapRegionSelectorPopup"); + popup->insertTitle(i18n("Image Operations")); + + KAction *action = new KAction(i18n("&Rotate Clockwise"), "rotate_cw", + 0, TQT_TQOBJECT(this), TQT_SLOT(rotateClockwise()), + TQT_TQOBJECT(popup), "rotateclockwise"); + action->plug(popup); + + action = new KAction(i18n("Rotate &Counterclockwise"), "rotate_ccw", + 0, TQT_TQOBJECT(this), TQT_SLOT(rotateCounterclockwise()), + TQT_TQOBJECT(popup), "rotatecounterclockwise"); + action->plug(popup); + +/* + I wonder if it would be appropiate to have here an "Open with..." option to + edit the image (antlarr) +*/ + return popup; +} + +void KPixmapRegionSelectorWidget::rotate(KImageEffect::RotateDirection direction) +{ + int w=m_originalPixmap.width(); + int h=m_originalPixmap.height(); + TQImage img=m_unzoomedPixmap.convertToImage(); + img= KImageEffect::rotate(img, direction); + m_unzoomedPixmap.convertFromImage(img); + + img=m_originalPixmap.convertToImage(); + img= KImageEffect::rotate(img, direction); + m_originalPixmap.convertFromImage(img); + + m_linedPixmap=TQPixmap(); + + if (m_forcedAspectRatio>0 && m_forcedAspectRatio!=1) + resetSelection(); + else + { + switch (direction) + { + case ( KImageEffect::Rotate90 ): + { + int x=h-m_selectedRegion.y()-m_selectedRegion.height(); + int y=m_selectedRegion.x(); + m_selectedRegion.setRect(x, y, m_selectedRegion.height(), m_selectedRegion.width() ); + updatePixmap(); + } break; + case ( KImageEffect::Rotate270 ): + { + int x=m_selectedRegion.y(); + int y=w-m_selectedRegion.x()-m_selectedRegion.width(); + m_selectedRegion.setRect(x, y, m_selectedRegion.height(), m_selectedRegion.width() ); + updatePixmap(); + } break; + default: resetSelection(); + } + } +} + +void KPixmapRegionSelectorWidget::rotateClockwise() +{ + rotate(KImageEffect::Rotate90); +} + +void KPixmapRegionSelectorWidget::rotateCounterclockwise() +{ + rotate(KImageEffect::Rotate270); +} + + + +bool KPixmapRegionSelectorWidget::eventFilter(TQObject *obj, TQEvent *ev) +{ + if ( ev->type() == TQEvent::MouseButtonPress ) + { + TQMouseEvent *mev= (TQMouseEvent *)(ev); + //kdDebug() << TQString("click at %1,%2").tqarg( mev->x() ).tqarg( mev->y() ) << endl; + + if ( mev->button() == Qt::RightButton ) + { + KPopupMenu *popup = createPopupMenu( ); + popup->exec( mev->globalPos() ); + delete popup; + return TRUE; + }; + + TQCursor cursor; + if ( m_selectedRegion.contains( mev->pos() ) + && m_selectedRegion!=m_originalPixmap.rect() ) + { + m_state=Moving; + cursor=TQCursor(TQt::SizeAllCursor); + } + else + { + m_state=Resizing; + cursor=TQCursor(TQt::CrossCursor); + } + TQApplication::setOverrideCursor(cursor); + + m_tempFirstClick=mev->pos(); + + return TRUE; + } + + if ( ev->type() == TQEvent::MouseMove ) + { + TQMouseEvent *mev= (TQMouseEvent *)(ev); + + //kdDebug() << TQString("move to %1,%2").tqarg( mev->x() ).tqarg( mev->y() ) << endl; + + if ( m_state == Resizing ) + { + setSelectedRegion ( + calcSelectionRectangle( m_tempFirstClick, mev->pos() ) ); + } + else if (m_state == Moving ) + { + int mevx = mev->x(); + int mevy = mev->y(); + bool mouseOutside=false; + if ( mevx < 0 ) + { + m_selectedRegion.moveBy(-m_selectedRegion.x(),0); + mouseOutside=true; + } + else if ( mevx > m_originalPixmap.width() ) + { + m_selectedRegion.moveBy(m_originalPixmap.width()-m_selectedRegion.width()-m_selectedRegion.x(),0); + mouseOutside=true; + } + if ( mevy < 0 ) + { + m_selectedRegion.moveBy(0,-m_selectedRegion.y()); + mouseOutside=true; + } + else if ( mevy > m_originalPixmap.height() ) + { + m_selectedRegion.moveBy(0,m_originalPixmap.height()-m_selectedRegion.height()-m_selectedRegion.y()); + mouseOutside=true; + } + if (mouseOutside) { updatePixmap(); return TRUE; }; + + m_selectedRegion.moveBy( mev->x()-m_tempFirstClick.x(), + mev->y()-m_tempFirstClick.y() ); + + // Check that the region has not fallen outside the image + if (m_selectedRegion.x() < 0) + m_selectedRegion.moveBy(-m_selectedRegion.x(),0); + else if (m_selectedRegion.right() > m_originalPixmap.width()) + m_selectedRegion.moveBy(-(m_selectedRegion.right()-m_originalPixmap.width()),0); + + if (m_selectedRegion.y() < 0) + m_selectedRegion.moveBy(0,-m_selectedRegion.y()); + else if (m_selectedRegion.bottom() > m_originalPixmap.height()) + m_selectedRegion.moveBy(0,-(m_selectedRegion.bottom()-m_originalPixmap.height())); + + m_tempFirstClick=mev->pos(); + updatePixmap(); + } + return TRUE; + } + + if ( ev->type() == TQEvent::MouseButtonRelease ) + { + TQMouseEvent *mev= (TQMouseEvent *)(ev); + + if ( m_state == Resizing && mev->pos() == m_tempFirstClick) + resetSelection(); + + m_state=None; + TQApplication::restoreOverrideCursor(); + + return TRUE; + } + + TQWidget::eventFilter(obj, ev); + return FALSE; +} + +TQRect KPixmapRegionSelectorWidget::calcSelectionRectangle( const TQPoint & startPoint, const TQPoint & _endPoint ) +{ + TQPoint endPoint = _endPoint; + if ( endPoint.x() < 0 ) endPoint.setX(0); + else if ( endPoint.x() > m_originalPixmap.width() ) endPoint.setX(m_originalPixmap.width()); + if ( endPoint.y() < 0 ) endPoint.setY(0); + else if ( endPoint.y() > m_originalPixmap.height() ) endPoint.setY(m_originalPixmap.height()); + int w=abs(startPoint.x()-endPoint.x()); + int h=abs(startPoint.y()-endPoint.y()); + + if (m_forcedAspectRatio>0) + { + double aspectRatio=w/double(h); + + if (aspectRatio>m_forcedAspectRatio) + h=(int)(w/m_forcedAspectRatio); + else + w=(int)(h*m_forcedAspectRatio); + } + + int x,y; + if ( startPoint.x() < endPoint.x() ) + x=startPoint.x(); + else + x=startPoint.x()-w; + if ( startPoint.y() < endPoint.y() ) + y=startPoint.y(); + else + y=startPoint.y()-h; + + if (x<0) + { + w+=x; + x=0; + h=(int)(w/m_forcedAspectRatio); + + if ( startPoint.y() > endPoint.y() ) + y=startPoint.y()-h; + } + else if (x+w>m_originalPixmap.width()) + { + w=m_originalPixmap.width()-x; + h=(int)(w/m_forcedAspectRatio); + + if ( startPoint.y() > endPoint.y() ) + y=startPoint.y()-h; + } + if (y<0) + { + h+=y; + y=0; + w=(int)(h*m_forcedAspectRatio); + + if ( startPoint.x() > endPoint.x() ) + x=startPoint.x()-w; + } + else if (y+h>m_originalPixmap.height()) + { + h=m_originalPixmap.height()-y; + w=(int)(h*m_forcedAspectRatio); + + if ( startPoint.x() > endPoint.x() ) + x=startPoint.x()-w; + } + + return TQRect(x,y,w,h); +} + +TQRect KPixmapRegionSelectorWidget::unzoomedSelectedRegion() const +{ + return TQRect((int)(m_selectedRegion.x()/m_zoomFactor), + (int)(m_selectedRegion.y()/m_zoomFactor), + (int)(m_selectedRegion.width()/m_zoomFactor), + (int)(m_selectedRegion.height()/m_zoomFactor)); +} + +TQImage KPixmapRegionSelectorWidget::selectedImage() const +{ + TQImage origImage=m_unzoomedPixmap.convertToImage(); + return origImage.copy(unzoomedSelectedRegion()); +} + +void KPixmapRegionSelectorWidget::setSelectionAspectRatio(int width, int height) +{ + m_forcedAspectRatio=width/double(height); +} + +void KPixmapRegionSelectorWidget::setFreeSelectionAspectRatio() +{ + m_forcedAspectRatio=0; +} + +void KPixmapRegionSelectorWidget::setMaximumWidgetSize(int width, int height) +{ + m_maxWidth=width; + m_maxHeight=height; + + m_originalPixmap=m_unzoomedPixmap; + if (m_selectedRegion == m_originalPixmap.rect()) m_selectedRegion=TQRect(); + +// kdDebug() << TQString(" original Pixmap :") << m_originalPixmap.rect() << endl; +// kdDebug() << TQString(" unzoomed Pixmap : %1 x %2 ").tqarg(m_unzoomedPixmap.width()).tqarg(m_unzoomedPixmap.height()) << endl; + + if ( !m_originalPixmap.isNull() && + ( m_originalPixmap.width() > m_maxWidth || + m_originalPixmap.height() > m_maxHeight ) ) + { + /* We have to resize the pixmap to get it complete on the screen */ + TQImage image=m_originalPixmap.convertToImage(); + m_originalPixmap.convertFromImage( image.smoothScale( width, height, TQ_ScaleMin ) ); + //m_originalPixmap.convertFromImage( KImageEffect::sample( image, width, height ) ); + double oldZoomFactor = m_zoomFactor; + m_zoomFactor=m_originalPixmap.width()/(double)m_unzoomedPixmap.width(); + + if (m_selectedRegion.isValid()) + { + m_selectedRegion= + TQRect((int)(m_selectedRegion.x()*m_zoomFactor/oldZoomFactor), + (int)(m_selectedRegion.y()*m_zoomFactor/oldZoomFactor), + (int)(m_selectedRegion.width()*m_zoomFactor/oldZoomFactor), + (int)(m_selectedRegion.height()*m_zoomFactor/oldZoomFactor) ); + } + } + + if (!m_selectedRegion.isValid()) m_selectedRegion = m_originalPixmap.rect(); + + m_linedPixmap=TQPixmap(); + updatePixmap(); + resize(m_label->width(), m_label->height()); +} + +#include "kpixmapregionselectorwidget.moc" diff --git a/libtdepim/kpixmapregionselectorwidget.h b/libtdepim/kpixmapregionselectorwidget.h new file mode 100644 index 000000000..7b75c98b2 --- /dev/null +++ b/libtdepim/kpixmapregionselectorwidget.h @@ -0,0 +1,176 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2004 Antonio Larrosa +#include +#include +#include +#include + +class KPopupMenu; + +namespace KPIM { + +/** + * KPixmapRegionSelectorWidget is a widget that shows a picture and provides the + * user with a friendly way to select a rectangular subregion of the pixmap. + * + * NOTE: There are two copies of this .h and the .cpp file, with subtle differences. + * One copy is in kdelibs/tdeui, and the other copy is in tdepim/libtdepim + * This is because tdepim has to remain backwards compatible. Any changes + * to either file should be made to the other. + * + * @author Antonio Larrosa + * @since 3.4 + */ +class KPixmapRegionSelectorWidget : public TQWidget +{ + Q_OBJECT + TQ_OBJECT + +public: + /** + * Constructor for a KPixmapRegionSelectorWidget. + */ + KPixmapRegionSelectorWidget( TQWidget *parent = 0L, const char *name=0L); + + /** + * Destructor for a KPixmapRegionSelectorWidget + */ + ~KPixmapRegionSelectorWidget(); + + /** + * Sets the pixmap which will be shown for the user to select a region from. + * @param pixmap The pixmap. Must be non-null. + */ + void setPixmap( const TQPixmap &pixmap ); + + /** + * @return the original whole pixmap that we're using in this widget as the + * pixmap the user is selecting a region from. + */ + TQPixmap pixmap() const { return m_unzoomedPixmap; } + + /** + * Sets the selected region to be @p rect (in zoomed pixmap coordinates) + */ + void setSelectedRegion(const TQRect &rect); + + /** + * Returns the selected region ( in zoomed pixmap coordinates ) + */ + TQRect selectedRegion() const; + + /** + * Returns the selected region ( in unzoomed, original pixmap coordinates ) + */ + TQRect unzoomedSelectedRegion() const; + + /** + * Resets the selection to use the whole image + */ + void resetSelection(); + + /** + * @returns a TQImage object with just the region the user selected from the + * image + */ + TQImage selectedImage() const; + + /** + * Sets the aspect ration that the selected subimage should have. The way to + * select it, is specifying an example valid @p width and @p height. + * @see setFreeSelectionAspectRatio() + */ + void setSelectionAspectRatio(int width, int height); + + /** + * Allows the user to do a selection which has any aspect ratio. This is + * the default. + * @see setSelectionAspectRatio() + */ + void setFreeSelectionAspectRatio(); + + /** + * Sets the maximum size for the widget. If the image is larger than this + * (either horizontally or vertically), it's scaled to adjust to the maximum + * size (preserving the aspect ratio) + */ + void setMaximumWidgetSize( int width, int height ); + + /** + * Rotates the image as specified by the @p direction parameter, also tries + * to rotate the selected region so that it doesn't change, as long as the + * forced aspect ratio setting is respected, in other case, the selected region + * is resetted. + */ + void rotate(KImageEffect::RotateDirection direction); + +public slots: + /** + * Rotates the current image 90º clockwise + */ + void rotateClockwise(); + /** + * Rotates the current image 90º counterclockwise + */ + void rotateCounterclockwise(); + +protected: + /** + * Creates a KPopupMenu with the menu that appears when clicking with the right button on the label + */ + virtual KPopupMenu *createPopupMenu(); + + +private: + bool eventFilter(TQObject *obj, TQEvent *ev); + + /** + * Recalculates the pixmap that is shown based on the current selected area, + * the original image, etc. + */ + void updatePixmap(); + + TQRect calcSelectionRectangle( const TQPoint &startPoint, const TQPoint & endPoint ); + + enum CursorState { None=0, Resizing, Moving }; + CursorState m_state; + + TQPixmap m_unzoomedPixmap; + TQPixmap m_originalPixmap; + TQPixmap m_linedPixmap; + TQRect m_selectedRegion; + TQLabel *m_label; + + TQPoint m_tempFirstClick; + double m_forcedAspectRatio; + + int m_maxWidth, m_maxHeight; + double m_zoomFactor; +}; + +} // for namespace + +#endif diff --git a/libtdepim/kprefsdialog.cpp b/libtdepim/kprefsdialog.cpp new file mode 100644 index 000000000..466691083 --- /dev/null +++ b/libtdepim/kprefsdialog.cpp @@ -0,0 +1,907 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2001,2003 Cornelius Schumacher + Copyright (C) 2003-2004 Reinhold Kainhofer + Copyright (C) 2005 Allen Winter + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "ktimeedit.h" +#include "kdateedit.h" + +#include "kprefsdialog.h" +#include "kprefsdialog.moc" + +namespace KPrefsWidFactory { + +KPrefsWid *create( KConfigSkeletonItem *item, TQWidget *parent ) +{ + KConfigSkeleton::ItemBool *boolItem = + dynamic_cast( item ); + if ( boolItem ) { + return new KPrefsWidBool( boolItem, parent ); + } + + KConfigSkeleton::ItemString *stringItem = + dynamic_cast( item ); + if ( stringItem ) { + return new KPrefsWidString( stringItem, parent ); + } + + KConfigSkeleton::ItemEnum *enumItem = + dynamic_cast( item ); + if ( enumItem ) { + TQValueList choices = enumItem->choices(); + if ( choices.isEmpty() ) { + kdError() << "KPrefsWidFactory::create(): Enum has no choices." << endl; + return 0; + } else { + KPrefsWidRadios *radios = new KPrefsWidRadios( enumItem, parent ); + TQValueList::ConstIterator it; + for( it = choices.begin(); it != choices.end(); ++it ) { + radios->addRadio( (*it).label ); + } + return radios; + } + } + + KConfigSkeleton::ItemInt *intItem = + dynamic_cast( item ); + if ( intItem ) { + return new KPrefsWidInt( intItem, parent ); + } + + return 0; +} + +} + + +TQValueList KPrefsWid::widgets() const +{ + return TQValueList(); +} + + +KPrefsWidBool::KPrefsWidBool( KConfigSkeleton::ItemBool *item, TQWidget *parent ) + : mItem( item ) +{ + mCheck = new TQCheckBox( item->label(), parent); + connect( mCheck, TQT_SIGNAL( clicked() ), TQT_SIGNAL( changed() ) ); + if ( !item->whatsThis().isNull() ) { + TQWhatsThis::add( mCheck, item->whatsThis() ); + } +} + +void KPrefsWidBool::readConfig() +{ + mCheck->setChecked( mItem->value() ); +} + +void KPrefsWidBool::writeConfig() +{ + mItem->setValue( mCheck->isChecked() ); +} + +TQCheckBox *KPrefsWidBool::checkBox() +{ + return mCheck; +} + +TQValueList KPrefsWidBool::widgets() const +{ + TQValueList widgets; + widgets.append( mCheck ); + return widgets; +} + + +KPrefsWidInt::KPrefsWidInt( KConfigSkeleton::ItemInt *item, + TQWidget *parent ) + : mItem( item ) +{ + mLabel = new TQLabel( mItem->label()+':', parent ); + mSpin = new TQSpinBox( parent ); + if ( !item->minValue().isNull() ) { + mSpin->setMinValue( item->minValue().toInt() ); + } + if ( !item->maxValue().isNull() ) { + mSpin->setMaxValue( item->maxValue().toInt() ); + } + connect( mSpin, TQT_SIGNAL( valueChanged( int ) ), TQT_SIGNAL( changed() ) ); + mLabel->setBuddy( mSpin ); + TQString whatsThis = mItem->whatsThis(); + if ( !whatsThis.isEmpty() ) { + TQWhatsThis::add( mLabel, whatsThis ); + TQWhatsThis::add( mSpin, whatsThis ); + } +} + +void KPrefsWidInt::readConfig() +{ + mSpin->setValue( mItem->value() ); +} + +void KPrefsWidInt::writeConfig() +{ + mItem->setValue( mSpin->value() ); +} + +TQLabel *KPrefsWidInt::label() +{ + return mLabel; +} + +TQSpinBox *KPrefsWidInt::spinBox() +{ + return mSpin; +} + +TQValueList KPrefsWidInt::widgets() const +{ + TQValueList widgets; + widgets.append( mLabel ); + widgets.append( mSpin ); + return widgets; +} + + +KPrefsWidColor::KPrefsWidColor( KConfigSkeleton::ItemColor *item, + TQWidget *parent ) + : mItem( item ) +{ + mButton = new KColorButton( parent ); + connect( mButton, TQT_SIGNAL( changed( const TQColor & ) ), TQT_SIGNAL( changed() ) ); + mLabel = new TQLabel( mButton, mItem->label()+':', parent ); + mLabel->setBuddy( mButton ); + TQString whatsThis = mItem->whatsThis(); + if (!whatsThis.isNull()) { + TQWhatsThis::add(mButton, whatsThis); + } +} + +KPrefsWidColor::~KPrefsWidColor() +{ +// kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl; +} + +void KPrefsWidColor::readConfig() +{ + mButton->setColor( mItem->value() ); +} + +void KPrefsWidColor::writeConfig() +{ + mItem->setValue( mButton->color() ); +} + +TQLabel *KPrefsWidColor::label() +{ + return mLabel; +} + +KColorButton *KPrefsWidColor::button() +{ + return mButton; +} + + +KPrefsWidFont::KPrefsWidFont( KConfigSkeleton::ItemFont *item, + TQWidget *parent, const TQString &sampleText ) + : mItem( item ) +{ + mLabel = new TQLabel( mItem->label()+':', parent ); + + mPreview = new TQLabel( sampleText, parent ); + mPreview->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + + mButton = new TQPushButton( i18n("Choose..."), parent ); + connect( mButton, TQT_SIGNAL( clicked() ), TQT_SLOT( selectFont() ) ); + TQString whatsThis = mItem->whatsThis(); + if (!whatsThis.isNull()) { + TQWhatsThis::add(mPreview, whatsThis); + TQWhatsThis::add(mButton, whatsThis); + } +} + +KPrefsWidFont::~KPrefsWidFont() +{ +} + +void KPrefsWidFont::readConfig() +{ + mPreview->setFont( mItem->value() ); +} + +void KPrefsWidFont::writeConfig() +{ + mItem->setValue( mPreview->font() ); +} + +TQLabel *KPrefsWidFont::label() +{ + return mLabel; +} + +TQFrame *KPrefsWidFont::preview() +{ + return mPreview; +} + +TQPushButton *KPrefsWidFont::button() +{ + return mButton; +} + +void KPrefsWidFont::selectFont() +{ + TQFont myFont(mPreview->font()); + int result = KFontDialog::getFont(myFont); + if (result == KFontDialog::Accepted) { + mPreview->setFont(myFont); + emit changed(); + } +} + + +KPrefsWidTime::KPrefsWidTime( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ) + : mItem( item ) +{ + mLabel = new TQLabel( mItem->label()+':', parent ); + mTimeEdit = new KTimeEdit( parent ); + mLabel->setBuddy( mTimeEdit ); + connect( mTimeEdit, TQT_SIGNAL( timeChanged( TQTime ) ), TQT_SIGNAL( changed() ) ); + TQString whatsThis = mItem->whatsThis(); + if ( !whatsThis.isNull() ) { + TQWhatsThis::add( mTimeEdit, whatsThis ); + } +} + +void KPrefsWidTime::readConfig() +{ + mTimeEdit->setTime( mItem->value().time() ); +} + +void KPrefsWidTime::writeConfig() +{ + // Don't overwrite the date value of the TQDateTime, so we can use a + // KPrefsWidTime and a KPrefsWidDate on the same config entry! + TQDateTime dt( mItem->value() ); + dt.setTime( mTimeEdit->getTime() ); + mItem->setValue( dt ); +} + +TQLabel *KPrefsWidTime::label() +{ + return mLabel; +} + +KTimeEdit *KPrefsWidTime::timeEdit() +{ + return mTimeEdit; +} + + +KPrefsWidDuration::KPrefsWidDuration( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ) + : mItem( item ) +{ + mLabel = new TQLabel( mItem->label()+':', parent ); + mTimeEdit = new TQTimeEdit( parent ); + mLabel->setBuddy( mTimeEdit ); + mTimeEdit->setAutoAdvance( true ); + mTimeEdit->setDisplay( TQTimeEdit::Hours | TQTimeEdit::Minutes ); + mTimeEdit->setRange( TQTime( 0, 1 ), TQTime( 24, 0 ) ); // [1min, 24hr] + connect( mTimeEdit, + TQT_SIGNAL( valueChanged( const TQTime & ) ), TQT_SIGNAL( changed() ) ); + TQString whatsThis = mItem->whatsThis(); + if ( !whatsThis.isNull() ) { + TQWhatsThis::add( mTimeEdit, whatsThis ); + } +} + +void KPrefsWidDuration::readConfig() +{ + mTimeEdit->setTime( mItem->value().time() ); +} + +void KPrefsWidDuration::writeConfig() +{ + TQDateTime dt( mItem->value() ); + dt.setTime( mTimeEdit->time() ); + mItem->setValue( dt ); +} + +TQLabel *KPrefsWidDuration::label() +{ + return mLabel; +} + +TQTimeEdit *KPrefsWidDuration::timeEdit() +{ + return mTimeEdit; +} + + +KPrefsWidDate::KPrefsWidDate( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ) + : mItem( item ) +{ + mLabel = new TQLabel( mItem->label()+':', parent ); + mDateEdit = new KDateEdit( parent ); + mLabel->setBuddy( mDateEdit ); + connect( mDateEdit, TQT_SIGNAL( dateChanged( const TQDate& ) ), TQT_SIGNAL( changed() ) ); + TQString whatsThis = mItem->whatsThis(); + if ( !whatsThis.isNull() ) { + TQWhatsThis::add( mDateEdit, whatsThis ); + } +} + +void KPrefsWidDate::readConfig() +{ + mDateEdit->setDate( mItem->value().date().isValid() ? mItem->value().date() : TQDate::tqcurrentDate() ); +} + +void KPrefsWidDate::writeConfig() +{ + TQDateTime dt( mItem->value() ); + dt.setDate( mDateEdit->date() ); + mItem->setValue( dt ); +} + +TQLabel *KPrefsWidDate::label() +{ + return mLabel; +} + +KDateEdit *KPrefsWidDate::dateEdit() +{ + return mDateEdit; +} + + +KPrefsWidRadios::KPrefsWidRadios( KConfigSkeleton::ItemEnum *item, + TQWidget *parent ) + : mItem( item ) +{ + mBox = new TQButtonGroup( 1, Qt::Horizontal, mItem->label(), parent ); + connect( mBox, TQT_SIGNAL( clicked( int ) ), TQT_SIGNAL( changed() ) ); +} + +KPrefsWidRadios::~KPrefsWidRadios() +{ +} + +void KPrefsWidRadios::addRadio(const TQString &text, const TQString &whatsThis) +{ + TQRadioButton *r = new TQRadioButton(text,mBox); + if (!whatsThis.isNull()) { + TQWhatsThis::add(r, whatsThis); + } +} + +TQButtonGroup *KPrefsWidRadios::groupBox() +{ + return mBox; +} + +void KPrefsWidRadios::readConfig() +{ + mBox->setButton( mItem->value() ); +} + +void KPrefsWidRadios::writeConfig() +{ + mItem->setValue( mBox->id( mBox->selected() ) ); +} + +TQValueList KPrefsWidRadios::widgets() const +{ + TQValueList w; + w.append( mBox ); + return w; +} + +KPrefsWidCombo::KPrefsWidCombo( KConfigSkeleton::ItemEnum *item, + TQWidget *parent ) + : mItem( item ) +{ + TQHBox *hbox = new TQHBox(parent); + new TQLabel( mItem->label(), hbox ); + mCombo = new TQComboBox( hbox ); + connect( mCombo, TQT_SIGNAL( activated( int ) ), TQT_SIGNAL( changed() ) ); +} + +KPrefsWidCombo::~KPrefsWidCombo() +{ +} + +void KPrefsWidCombo::readConfig() +{ + mCombo->setCurrentItem( mItem->value() ); +} + +void KPrefsWidCombo::writeConfig() +{ + mItem->setValue( mCombo->currentItem() ); +} + +TQValueList KPrefsWidCombo::widgets() const +{ + TQValueList w; + w.append( mCombo ); + return w; +} + +TQComboBox* KPrefsWidCombo::comboBox() +{ + return mCombo; +} + +KPrefsWidString::KPrefsWidString( KConfigSkeleton::ItemString *item, + TQWidget *parent, + TQLineEdit::EchoMode echomode ) + : mItem( item ) +{ + mLabel = new TQLabel( mItem->label()+':', parent ); + mEdit = new TQLineEdit( parent ); + mLabel->setBuddy( mEdit ); + connect( mEdit, TQT_SIGNAL( textChanged( const TQString & ) ), + TQT_SIGNAL( changed() ) ); + mEdit->setEchoMode( echomode ); + TQString whatsThis = mItem->whatsThis(); + if ( !whatsThis.isNull() ) { + TQWhatsThis::add( mEdit, whatsThis ); + } +} + +KPrefsWidString::~KPrefsWidString() +{ +} + +void KPrefsWidString::readConfig() +{ + mEdit->setText( mItem->value() ); +} + +void KPrefsWidString::writeConfig() +{ + mItem->setValue( mEdit->text() ); +} + +TQLabel *KPrefsWidString::label() +{ + return mLabel; +} + +TQLineEdit *KPrefsWidString::lineEdit() +{ + return mEdit; +} + +TQValueList KPrefsWidString::widgets() const +{ + TQValueList widgets; + widgets.append( mLabel ); + widgets.append( mEdit ); + return widgets; +} + + +KPrefsWidPath::KPrefsWidPath( KConfigSkeleton::ItemPath *item, TQWidget *parent, + const TQString &filter, uint mode ) + : mItem( item ) +{ + mLabel = new TQLabel( mItem->label()+':', parent ); + mURLRequester = new KURLRequester( parent ); + mLabel->setBuddy( mURLRequester ); + mURLRequester->setMode( mode ); + mURLRequester->setFilter( filter ); + connect( mURLRequester, TQT_SIGNAL( textChanged( const TQString & ) ), + TQT_SIGNAL( changed() ) ); + TQString whatsThis = mItem->whatsThis(); + if ( !whatsThis.isNull() ) { + TQWhatsThis::add( mURLRequester, whatsThis ); + } +} + +KPrefsWidPath::~KPrefsWidPath() +{ +} + +void KPrefsWidPath::readConfig() +{ + mURLRequester->setURL( mItem->value() ); +} + +void KPrefsWidPath::writeConfig() +{ + mItem->setValue( mURLRequester->url() ); +} + +TQLabel *KPrefsWidPath::label() +{ + return mLabel; +} + +KURLRequester *KPrefsWidPath::urlRequester() +{ + return mURLRequester; +} + +TQValueList KPrefsWidPath::widgets() const +{ + TQValueList widgets; + widgets.append( mLabel ); + widgets.append( mURLRequester ); + return widgets; +} + + +KPrefsWidManager::KPrefsWidManager( KConfigSkeleton *prefs ) + : mPrefs( prefs ) +{ +} + +KPrefsWidManager::~KPrefsWidManager() +{ +} + +void KPrefsWidManager::addWid( KPrefsWid *wid ) +{ + mPrefsWids.append( wid ); +} + +KPrefsWidBool *KPrefsWidManager::addWidBool( KConfigSkeleton::ItemBool *item, + TQWidget *parent ) +{ + KPrefsWidBool *w = new KPrefsWidBool( item, parent ); + addWid( w ); + return w; +} + +KPrefsWidTime *KPrefsWidManager::addWidTime( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ) +{ + KPrefsWidTime *w = new KPrefsWidTime( item, parent ); + addWid( w ); + return w; +} + +KPrefsWidDuration *KPrefsWidManager::addWidDuration( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ) +{ + KPrefsWidDuration *w = new KPrefsWidDuration( item, parent ); + addWid( w ); + return w; +} + +KPrefsWidDate *KPrefsWidManager::addWidDate( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ) +{ + KPrefsWidDate *w = new KPrefsWidDate( item, parent ); + addWid( w ); + return w; +} + +KPrefsWidColor *KPrefsWidManager::addWidColor( KConfigSkeleton::ItemColor *item, + TQWidget *parent ) +{ + KPrefsWidColor *w = new KPrefsWidColor( item, parent ); + addWid( w ); + return w; +} + +KPrefsWidRadios *KPrefsWidManager::addWidRadios( KConfigSkeleton::ItemEnum *item, + TQWidget *parent ) +{ + KPrefsWidRadios *w = new KPrefsWidRadios( item, parent ); + TQValueList choices; + choices = item->choices(); + TQValueList::ConstIterator it; + for( it = choices.begin(); it != choices.end(); ++it ) { + w->addRadio( (*it).label, (*it).whatsThis ); + } + addWid( w ); + return w; +} + +KPrefsWidCombo *KPrefsWidManager::addWidCombo( KConfigSkeleton::ItemEnum *item, + TQWidget* parent ) +{ + KPrefsWidCombo *w = new KPrefsWidCombo( item, parent ); + TQValueList choices; + choices = item->choices(); + TQValueList::ConstIterator it; + for( it = choices.begin(); it != choices.end(); ++it ) { + w->comboBox()->insertItem( (*it).label, -1 ); + } + addWid( w ); + return w; +} + +KPrefsWidString *KPrefsWidManager::addWidString( KConfigSkeleton::ItemString *item, + TQWidget *parent ) +{ + KPrefsWidString *w = new KPrefsWidString( item, parent, + TQLineEdit::Normal ); + addWid( w ); + return w; +} + +KPrefsWidPath *KPrefsWidManager::addWidPath( KConfigSkeleton::ItemPath *item, + TQWidget *parent, const TQString &filter, uint mode ) +{ + KPrefsWidPath *w = new KPrefsWidPath( item, parent, filter, mode ); + addWid( w ); + return w; +} + +KPrefsWidString *KPrefsWidManager::addWidPassword( KConfigSkeleton::ItemString *item, + TQWidget *parent ) +{ + KPrefsWidString *w = new KPrefsWidString( item, parent, TQLineEdit::Password ); + addWid( w ); + return w; +} + +KPrefsWidFont *KPrefsWidManager::addWidFont( KConfigSkeleton::ItemFont *item, + TQWidget *parent, + const TQString &sampleText ) +{ + KPrefsWidFont *w = new KPrefsWidFont( item, parent, sampleText ); + addWid( w ); + return w; +} + +KPrefsWidInt *KPrefsWidManager::addWidInt( KConfigSkeleton::ItemInt *item, + TQWidget *parent ) +{ + KPrefsWidInt *w = new KPrefsWidInt( item, parent ); + addWid( w ); + return w; +} + +void KPrefsWidManager::setWidDefaults() +{ + kdDebug() << "KPrefsWidManager::setWidDefaults()" << endl; + + bool tmp = mPrefs->useDefaults( true ); + + readWidConfig(); + + mPrefs->useDefaults( tmp ); +} + +void KPrefsWidManager::readWidConfig() +{ + kdDebug(5310) << "KPrefsWidManager::readWidConfig()" << endl; + + KPrefsWid *wid; + for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) { + wid->readConfig(); + } +} + +void KPrefsWidManager::writeWidConfig() +{ + kdDebug(5310) << "KPrefsWidManager::writeWidConfig()" << endl; + + KPrefsWid *wid; + for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) { + wid->writeConfig(); + } + + mPrefs->writeConfig(); +} + + +KPrefsDialog::KPrefsDialog( KConfigSkeleton *prefs, TQWidget *parent, char *name, + bool modal ) + : KDialogBase(IconList,i18n("Preferences"),Ok|Apply|Cancel|Default,Ok,parent, + name,modal,true), + KPrefsWidManager( prefs ) +{ +// TODO: This seems to cause a crash on exit. Investigate later. +// mPrefsWids.setAutoDelete(true); + +// connect(this,TQT_SIGNAL(defaultClicked()),TQT_SLOT(setDefaults())); + connect(this,TQT_SIGNAL(cancelClicked()),TQT_SLOT(reject())); +} + +KPrefsDialog::~KPrefsDialog() +{ +} + +void KPrefsDialog::autoCreate() +{ + KConfigSkeletonItem::List items = prefs()->items(); + + TQMap mGroupPages; + TQMap mGroupLayouts; + TQMap mCurrentRows; + + KConfigSkeletonItem::List::ConstIterator it; + for( it = items.begin(); it != items.end(); ++it ) { + TQString group = (*it)->group(); + TQString name = (*it)->name(); + + kdDebug() << "ITEMS: " << (*it)->name() << endl; + + TQWidget *page; + TQGridLayout *tqlayout; + int currentRow; + if ( !mGroupPages.contains( group ) ) { + page = addPage( group ); + tqlayout = new TQGridLayout( page ); + mGroupPages.insert( group, page ); + mGroupLayouts.insert( group, tqlayout ); + currentRow = 0; + mCurrentRows.insert( group, currentRow ); + } else { + page = mGroupPages[ group ]; + tqlayout = mGroupLayouts[ group ]; + currentRow = mCurrentRows[ group ]; + } + + KPrefsWid *wid = KPrefsWidFactory::create( *it, page ); + + if ( wid ) { + TQValueList widgets = wid->widgets(); + if ( widgets.count() == 1 ) { + tqlayout->addMultiCellWidget( widgets[ 0 ], + currentRow, currentRow, 0, 1 ); + } else if ( widgets.count() == 2 ) { + tqlayout->addWidget( widgets[ 0 ], currentRow, 0 ); + tqlayout->addWidget( widgets[ 1 ], currentRow, 1 ); + } else { + kdError() << "More widgets than expected: " << widgets.count() << endl; + } + + if ( (*it)->isImmutable() ) { + TQValueList::Iterator it2; + for( it2 = widgets.begin(); it2 != widgets.end(); ++it2 ) { + (*it2)->setEnabled( false ); + } + } + + addWid( wid ); + + mCurrentRows.replace( group, ++currentRow ); + } + } + + readConfig(); +} + +void KPrefsDialog::setDefaults() +{ + setWidDefaults(); +} + +void KPrefsDialog::readConfig() +{ + readWidConfig(); + + usrReadConfig(); +} + +void KPrefsDialog::writeConfig() +{ + writeWidConfig(); + + usrWriteConfig(); + + readConfig(); +} + + +void KPrefsDialog::slotApply() +{ + writeConfig(); + emit configChanged(); +} + +void KPrefsDialog::slotOk() +{ + slotApply(); + accept(); +} + +void KPrefsDialog::slotDefault() +{ + kdDebug() << "KPrefsDialog::slotDefault()" << endl; + + if (KMessageBox::warningContinueCancel(this, + i18n("You are about to set all preferences to default values. All " + "custom modifications will be lost."),i18n("Setting Default Preferences"), + i18n("Reset to Defaults")) + == KMessageBox::Continue) setDefaults(); +} + + +KPrefsModule::KPrefsModule( KConfigSkeleton *prefs, TQWidget *parent, + const char *name ) + : KCModule( parent, name ), + KPrefsWidManager( prefs ) +{ + emit changed( false ); +} + +void KPrefsModule::addWid( KPrefsWid *wid ) +{ + KPrefsWidManager::addWid( wid ); + + connect( wid, TQT_SIGNAL( changed() ), TQT_SLOT( slotWidChanged() ) ); +} + +void KPrefsModule::slotWidChanged() +{ + kdDebug(5310) << "KPrefsModule::slotWidChanged()" << endl; + + emit changed( true ); +} + +void KPrefsModule::load() +{ + kdDebug(5310) << "KPrefsModule::load()" << endl; + + readWidConfig(); + + usrReadConfig(); + + emit changed( false ); +} + +void KPrefsModule::save() +{ + kdDebug(5310) << "KPrefsModule::save()" << endl; + + writeWidConfig(); + + usrWriteConfig(); +} + +void KPrefsModule::defaults() +{ + setWidDefaults(); + + emit changed( true ); +} diff --git a/libtdepim/kprefsdialog.h b/libtdepim/kprefsdialog.h new file mode 100644 index 000000000..b1fffcdd7 --- /dev/null +++ b/libtdepim/kprefsdialog.h @@ -0,0 +1,798 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2001-2003 Cornelius Schumacher + Copyright (C) 2003-2004 Reinhold Kainhofer + Copyright (C) 2005 Allen Winter + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KPREFSDIALOG_H +#define KPREFSDIALOG_H + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +class KColorButton; +class TQCheckBox; +class TQComboBox; +class TQLabel; +class TQSpinBox; +class TQButtonGroup; +class TQTimeEdit; +class KTimeEdit; +class KDateEdit; +class KURLRequester; + +/** + @short Base class for GUI control elements used by @ref KPrefsDialog. + @author Cornelius Schumacher + @see KPrefsDialog + + This class provides the interface for the GUI control elements used by + KPrefsDialog. The control element consists of a set of widgets for handling + a certain type of configuration information. +*/ +class KDE_EXPORT KPrefsWid : public TQObject +{ + Q_OBJECT + TQ_OBJECT + public: + /** + This function is called to read value of the setting from the + stored configuration and display it in the widget. + */ + virtual void readConfig() = 0; + /** + This function is called to write the current setting of the widget to the + stored configuration. + */ + virtual void writeConfig() = 0; + + /** + Return a list of widgets used by this control element. + */ + virtual TQValueList widgets() const; + + signals: + /** + Emitted when widget value has changed. + */ + void changed(); +}; + +/** + @short Widgets for bool settings in @ref KPrefsDialog. + + This class provides a control element for configuring bool values. It is meant + to be used by KPrefsDialog. The user is responsible for the tqlayout management. +*/ +class KDE_EXPORT KPrefsWidBool : public KPrefsWid +{ + public: + /** + Create a bool value control element consisting of a TQCheckbox. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidBool( KConfigSkeleton::ItemBool *item, TQWidget *parent ); + + /** + Return the TQCheckbox used by this control element. + */ + TQCheckBox *checkBox(); + + void readConfig(); + void writeConfig(); + + TQValueList widgets() const; + + private: + KConfigSkeleton::ItemBool *mItem; + + TQCheckBox *mCheck; +}; + +/** + @short Widgets for int settings in @ref KPrefsDialog. + + This class provides a control element for configuring integer values. It is + meant to be used by KPrefsDialog. The user is responsible for the tqlayout + management. +*/ +class KDE_EXPORT KPrefsWidInt : public KPrefsWid +{ + public: + /** + Create a integer value control element consisting of a label and a + spinbox. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidInt( KConfigSkeleton::ItemInt *item, TQWidget *parent ); + + /** + Return TQLabel used by this control element. + */ + TQLabel *label(); + + /** + Return the TQSpinBox used by this control element. + */ + TQSpinBox *spinBox(); + + void readConfig(); + void writeConfig(); + + TQValueList widgets() const; + + private: + KConfigSkeleton::ItemInt *mItem; + + TQLabel *mLabel; + TQSpinBox *mSpin; +}; + +/** + @short Widgets for time settings in @ref KPrefsDialog. + + This class provides a control element for configuring time values. It is + meant to be used by KPrefsDialog. The user is responsible for the tqlayout + management. +*/ +class KDE_EXPORT KPrefsWidTime : public KPrefsWid +{ + public: + /** + Create a time value control element consisting of a label and a spinbox. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidTime( KConfigSkeleton::ItemDateTime *item, TQWidget *parent ); + + /** + Return TQLabel used by this widget. + */ + TQLabel *label(); + /** + Return TQSpinBox used by this widget. + */ + KTimeEdit *timeEdit(); + + void readConfig(); + void writeConfig(); + + private: + KConfigSkeleton::ItemDateTime *mItem; + + TQLabel *mLabel; + KTimeEdit *mTimeEdit; +}; + +/** + @short Widgets for duration settings in @ref KPrefsDialog. + + This class provides a control element for configuring duration values. It is + meant to be used by KPrefsDialog. The user is responsible for the tqlayout + management. +*/ +class KDE_EXPORT KPrefsWidDuration : public KPrefsWid +{ + public: + /** + Create a duration value control element consisting of a label and a + spinbox. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidDuration( KConfigSkeleton::ItemDateTime *item, TQWidget *parent ); + + /** + Return TQLabel used by this widget. + */ + TQLabel *label(); + /** + Return TQSpinBox used by this widget. + */ + TQTimeEdit *timeEdit(); + + void readConfig(); + void writeConfig(); + + private: + KConfigSkeleton::ItemDateTime *mItem; + + TQLabel *mLabel; + TQTimeEdit *mTimeEdit; +}; + +/** + @short Widgets for time settings in @ref KPrefsDialog. + + This class provides a control element for configuring date values. It is + meant to be used by KPrefsDialog. The user is responsible for the tqlayout + management. +*/ +class KDE_EXPORT KPrefsWidDate : public KPrefsWid +{ + public: + /** + Create a time value control element consisting of a label and a date box. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidDate( KConfigSkeleton::ItemDateTime *item, TQWidget *parent ); + + /** + Return TQLabel used by this widget. + */ + TQLabel *label(); + /** + Return TQSpinBox used by this widget. + */ + KDateEdit *dateEdit(); + + void readConfig(); + void writeConfig(); + + private: + KConfigSkeleton::ItemDateTime *mItem; + + TQLabel *mLabel; + KDateEdit *mDateEdit; +}; + +/** + @short Widgets for color settings in @ref KPrefsDialog. + + This class provides a control element for configuring color values. It is + meant to be used by KPrefsDialog. The user is responsible for the tqlayout + management. +*/ +class KDE_EXPORT KPrefsWidColor : public KPrefsWid +{ + Q_OBJECT + TQ_OBJECT + public: + /** + Create a color value control element consisting of a test field and a + button for opening a color dialog. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidColor( KConfigSkeleton::ItemColor *item, TQWidget *parent ); + /** + Destruct color setting widget. + */ + ~KPrefsWidColor(); + + /** + Return TQLabel for the button + */ + TQLabel *label(); + /** + Return button opening the color dialog. + */ + KColorButton *button(); + + void readConfig(); + void writeConfig(); + + private: + KConfigSkeleton::ItemColor *mItem; + + TQLabel *mLabel; + KColorButton *mButton; +}; + +/** + @short Widgets for font settings in @ref KPrefsDialog. + + This class provides a control element for configuring font values. It is meant + to be used by KPrefsDialog. The user is responsible for the tqlayout management. +*/ +class KDE_EXPORT KPrefsWidFont : public KPrefsWid +{ + Q_OBJECT + TQ_OBJECT + public: + /** + Create a font value control element consisting of a test field and a + button for opening a font dialog. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + @param sampleText Sample text for previewing the selected font. + */ + KPrefsWidFont( KConfigSkeleton::ItemFont *item, + TQWidget *parent, const TQString &sampleText ); + /** + Destruct font setting widget. + */ + ~KPrefsWidFont(); + + /** + Return TQLabel. + */ + TQLabel *label(); + /** + Return TQFrame used as preview field. + */ + TQFrame *preview(); + /** + Return button opening the font dialog. + */ + TQPushButton *button(); + + void readConfig(); + void writeConfig(); + + protected slots: + void selectFont(); + + private: + KConfigSkeleton::ItemFont *mItem; + + TQLabel *mLabel; + TQLabel *mPreview; + TQPushButton *mButton; +}; + +/** + @short Widgets for settings represented by a group of radio buttons in + @ref KPrefsDialog. + + This class provides a control element for configuring selections. It is meant + to be used by KPrefsDialog. The user is responsible for the tqlayout management. + + The setting is interpreted as an int value, corresponding to the position of + the radio button. The position of the button is defined by the sequence of + @ref addRadio() calls, starting with 0. +*/ +class KDE_EXPORT KPrefsWidRadios : public KPrefsWid +{ + public: + /** + Create a control element for selection of an option. It consists of a box + with several radio buttons. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidRadios( KConfigSkeleton::ItemEnum *item, TQWidget *parent ); + virtual ~KPrefsWidRadios(); + + /** + Add a radio button. + + @param text Text of the button. + @param whatsThis What's This help for the button. + */ + void addRadio( const TQString &text, + const TQString &whatsThis = TQString() ); + + /** + Return the box widget used by this widget. + */ + TQButtonGroup *groupBox(); + + void readConfig(); + void writeConfig(); + + TQValueList widgets() const; + + private: + KConfigSkeleton::ItemEnum *mItem; + + TQButtonGroup *mBox; +}; + +/** + @short Widgets for settings represented by a combo box in + @ref KPrefsDialog. + + This class provides a control element for configuring selections. It is meant + to be used by KPrefsDialog. The user is responsible for the tqlayout management. + + The setting is interpreted as an int value, corresponding to the index in + the combo box. +*/ +class KDE_EXPORT KPrefsWidCombo : public KPrefsWid +{ + public: + /** + Create a control element for selection of an option. It consists of a + combo box. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidCombo( KConfigSkeleton::ItemEnum *item, TQWidget *parent ); + virtual ~KPrefsWidCombo(); + + void readConfig(); + void writeConfig(); + + TQComboBox *comboBox(); + TQValueList widgets() const; + + private: + KConfigSkeleton::ItemEnum *mItem; + TQComboBox *mCombo; +}; + + + +/** + @short Widgets for string settings in @ref KPrefsDialog. + + This class provides a control element for configuring string values. It is + meant to be used by KPrefsDialog. The user is responsible for the tqlayout + management. +*/ +class KDE_EXPORT KPrefsWidString : public KPrefsWid +{ + public: + /** + Create a string value control element consisting of a test label and a + line edit. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + @param echomode Describes how a line edit should display its contents. + */ + KPrefsWidString( KConfigSkeleton::ItemString *item, TQWidget *parent, + TQLineEdit::EchoMode echomode=TQLineEdit::Normal ); + /** + Destructor. + */ + virtual ~KPrefsWidString(); + + /** + Return TQLabel used by this widget. + */ + TQLabel *label(); + /** + Return TQLineEdit used by this widget. + */ + TQLineEdit *lineEdit(); + + void readConfig(); + void writeConfig(); + + TQValueList widgets() const; + + private: + KConfigSkeleton::ItemString *mItem; + + TQLabel *mLabel; + TQLineEdit *mEdit; +}; + + +/** + @short Widgets for string settings in @ref KPrefsDialog. + + This class provides a control element for configuring string values. It is + meant to be used by KPrefsDialog. The user is responsible for the tqlayout + management. +*/ +class KDE_EXPORT KPrefsWidPath : public KPrefsWid +{ + public: + /** + Create a string value control element consisting of a test label and a + line edit. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + @param filter URLRequester filter + @param mode Describes how a line edit should display its contents. + */ + KPrefsWidPath( KConfigSkeleton::ItemPath *item, TQWidget *parent, + const TQString &filter = TQString(), uint mode = KFile::File ); + /** + Destructor. + */ + virtual ~KPrefsWidPath(); + + /** + Return TQLabel used by this widget. + */ + TQLabel *label(); + /** + Return TQLineEdit used by this widget. + */ + KURLRequester *urlRequester(); + + void readConfig(); + void writeConfig(); + + TQValueList widgets() const; + + private: + KConfigSkeleton::ItemPath *mItem; + + TQLabel *mLabel; + KURLRequester *mURLRequester; +}; + + +/** + @short Class for managing KPrefsWid objects. + + This class manages standard configuration widgets provided bz the KPrefsWid + subclasses. It handles creation, loading, saving and default values in a + transparent way. The user has to add the widgets by the corresponding addWid + functions and KPrefsWidManager handles the rest automatically. +*/ +class KDE_EXPORT KPrefsWidManager +{ + public: + /** + Create a KPrefsWidManager object for a KPrefs object. + + @param prefs KPrefs object used to access te configuration. + */ + KPrefsWidManager( KConfigSkeleton *prefs ); + /** + Destructor. + */ + virtual ~KPrefsWidManager(); + + KConfigSkeleton *prefs() const { return mPrefs; } + + /** + Register a custom KPrefsWid object. + */ + virtual void addWid( KPrefsWid * ); + + /** + Register a @ref KPrefsWidBool object. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidBool *addWidBool( KConfigSkeleton::ItemBool *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidInt object. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidInt *addWidInt( KConfigSkeleton::ItemInt *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidDate object. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidDate *addWidDate( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidTime object. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidTime *addWidTime( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidDuration object. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidDuration *addWidDuration( KConfigSkeleton::ItemDateTime *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidColor object. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidColor *addWidColor( KConfigSkeleton::ItemColor *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidRadios object. The choices represented by the + given item object are automatically added as radio buttons. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidRadios *addWidRadios( KConfigSkeleton::ItemEnum *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidCombo object. The choices represented by the + given item object are automatically added to the combo box. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidCombo *addWidCombo( KConfigSkeleton::ItemEnum *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidString object. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidString *addWidString( KConfigSkeleton::ItemString *item, + TQWidget *parent ); + + /** + Register a path @ref KPrefsWidPath object. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + @param filter URLRequester filter + @param mode URLRequester mode + */ + KPrefsWidPath *addWidPath ( KConfigSkeleton::ItemPath *item, TQWidget *parent, + const TQString &filter = TQString(), + uint mode = KFile::File ); + + /** + Register a password @ref KPrefsWidString object, with echomode set to TQLineEdit::Password. + + @param item The KConfigSkeletonItem representing the preferences entry. + @param parent Parent widget. + */ + KPrefsWidString *addWidPassword ( KConfigSkeleton::ItemString *item, + TQWidget *parent ); + + /** + Register a @ref KPrefsWidFont object. + + @param item The KConfigSkeletonItem representing the preferences + entry. + @param parent Parent widget. + @param sampleText Sample text for previewing the selected font. + */ + KPrefsWidFont *addWidFont( KConfigSkeleton::ItemFont *item, + TQWidget *parent, const TQString &sampleText ); + + /** Set all widgets to default values. */ + void setWidDefaults(); + + /** Read preferences from config file. */ + void readWidConfig(); + + /** Write preferences to config file. */ + void writeWidConfig(); + + private: + KConfigSkeleton *mPrefs; + + TQPtrList mPrefsWids; +}; + + +/** + @short Base class for a preferences dialog. + + This class provides the framework for a preferences dialog. You have to + subclass it and add the code to create the actual configuration widgets and + do the tqlayout management. + + KPrefsDialog provides functions to add subclasses of @ref KPrefsWid via + KPrefsWidManager. For these widgets the reading, writing and setting to + default values is handled automatically. Custom widgets have to be handled in + the functions @ref usrReadConfig() and @ref usrWriteConfig(). +*/ +class KDE_EXPORT KPrefsDialog : public KDialogBase, public KPrefsWidManager +{ + Q_OBJECT + TQ_OBJECT + public: + /** + Create a KPrefsDialog for a KPrefs object. + + @param prefs KPrefs object used to access te configuration. + @param parent Parent widget. + @param name Widget name. + @param modal true, if dialog has to be modal, false for non-modal. + */ + KPrefsDialog( KConfigSkeleton *prefs, TQWidget *parent = 0, char *name = 0, + bool modal = false ); + /** + Destructor. + */ + virtual ~KPrefsDialog(); + + void autoCreate(); + + public slots: + /** Set all widgets to default values. */ + void setDefaults(); + + /** Read preferences from config file. */ + void readConfig(); + + /** Write preferences to config file. */ + void writeConfig(); + + signals: + /** Emitted when the a changed configuration has been stored. */ + void configChanged(); + + protected slots: + /** Apply changes to preferences */ + void slotApply(); + + /** Accept changes to preferences and close dialog */ + void slotOk(); + + /** Set preferences to default values */ + void slotDefault(); + + protected: + /** Implement this to read custom configuration widgets. */ + virtual void usrReadConfig() {} + /** Implement this to write custom configuration widgets. */ + virtual void usrWriteConfig() {} +}; + + +class KDE_EXPORT KPrefsModule : public KCModule, public KPrefsWidManager +{ + Q_OBJECT + TQ_OBJECT + public: + KPrefsModule( KConfigSkeleton *, TQWidget *parent = 0, const char *name = 0 ); + + virtual void addWid( KPrefsWid * ); + + void load(); + void save(); + void defaults(); + + protected slots: + void slotWidChanged(); + + protected: + /** Implement this to read custom configuration widgets. */ + virtual void usrReadConfig() {} + /** Implement this to write custom configuration widgets. */ + virtual void usrWriteConfig() {} +}; + +#endif diff --git a/libtdepim/kregexp3.cpp b/libtdepim/kregexp3.cpp new file mode 100644 index 000000000..c4efa96f1 --- /dev/null +++ b/libtdepim/kregexp3.cpp @@ -0,0 +1,183 @@ +/* -*- c++ -*- + kregexp3.cpp + + This file is part of libkdenetwork. + Copyright (c) 2001 Marc Mutz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This library 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 library; 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 library with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 "kregexp3.h" + +// #define DEBUG_KREGEXP3 + +#ifdef DEBUG_KREGEXP3 +#include +#endif + +TQString KRegExp3::replace( const TQString & str, + const TQString & replacementStr, + int start, bool global ) +{ + int oldpos, pos; + + //-------- parsing the replacementStr into + //-------- literal parts and backreferences: + TQStringList literalStrs; + TQValueList backRefs; + + // Due to LTS: The regexp in unquoted form and with spaces: + // \\ (\d) | \$ (\d) | \$ \{ (\d+) \} + TQRegExp rx( "\\\\(\\d)|\\$(\\d)|\\$\\{(\\d+)\\}" ); + TQRegExp bbrx("\\\\"); + TQRegExp brx("\\"); + +#ifdef DEBUG_KREGEXP3 + kdDebug() << "Analyzing replacementStr: \"" + replacementStr + "\"" << endl; +#endif + + oldpos = 0; + pos = 0; + while ( true ) { + pos = rx.search( replacementStr, pos ); + +#ifdef DEBUG_KREGEXP3 + kdDebug() << TQString(" Found match at pos %1").tqarg(pos) << endl; +#endif + + if ( pos < 0 ) { + literalStrs << replacementStr.mid( oldpos ) + .replace( bbrx, "\\" ) + .replace( brx, "" ); +#ifdef DEBUG_KREGEXP3 + kdDebug() << " No more matches. Last literal is \"" + literalStrs.last() + "\"" << endl; +#endif + break; + } else { + literalStrs << replacementStr.mid( oldpos, pos-oldpos ) + .replace( bbrx, "\\" ) + .replace( brx, "" ); +#ifdef DEBUG_KREGEXP3 + kdDebug() << TQString(" Inserting \"") + literalStrs.last() + "\" as literal." << endl; + kdDebug() << " Searching for corresponding digit(s):" << endl; +#endif + for ( int i = 1 ; i < 4 ; i++ ) + if ( !rx.cap(i).isEmpty() ) { + backRefs << rx.cap(i).toInt(); +#ifdef DEBUG_KREGEXP3 + kdDebug() << TQString(" Found %1 at position %2 in the capturedTexts.") + .tqarg(backRefs.last()).tqarg(i) << endl; +#endif + break; + } + pos += rx.matchedLength(); +#ifdef DEBUG_KREGEXP3 + kdDebug() << TQString(" Setting new pos to %1.").tqarg(pos) << endl; +#endif + oldpos = pos; + } + } + +#ifdef DEBUG_KREGEXP3 + kdDebug() << "Finished the analysis of replacementStr!" << endl; +#endif + Q_ASSERT( literalStrs.count() == backRefs.count() + 1 ); + + //-------- actual construction of the + //-------- resulting TQString + TQString result = ""; + oldpos = 0; + pos = start; + + TQStringList::Iterator sIt; + TQValueList::Iterator iIt; + + if ( start < 0 ) + start += str.length(); + +#ifdef DEBUG_KREGEXP3 + kdDebug() << "Constructing the resultant string starts now:" << endl; +#endif + + while ( pos < (int)str.length() ) { + pos = search( str, pos ); + +#ifdef DEBUG_KREGEXP3 + kdDebug() << TQString(" Found match at pos %1").tqarg(pos) << endl; +#endif + + if ( pos < 0 ) { + result += str.mid( oldpos ); +#ifdef DEBUG_KREGEXP3 + kdDebug() << " No more matches. Adding trailing part from str:" << endl; + kdDebug() << " result == \"" + result + "\"" << endl; +#endif + break; + } else { + result += str.mid( oldpos, pos-oldpos ); +#ifdef DEBUG_KREGEXP3 + kdDebug() << " Adding unchanged part from str:" << endl; + kdDebug() << " result == \"" + result + "\"" << endl; +#endif + for ( sIt = literalStrs.begin(), iIt = backRefs.begin() ; + iIt != backRefs.end() ; ++sIt, ++iIt ) { + result += (*sIt); +#ifdef DEBUG_KREGEXP3 + kdDebug() << " Adding literal replacement part:" << endl; + kdDebug() << " result == \"" + result + "\"" << endl; +#endif + result += cap( (*iIt) ); +#ifdef DEBUG_KREGEXP3 + kdDebug() << " Adding captured string:" << endl; + kdDebug() << " result == \"" + result + "\"" << endl; +#endif + } + result += (*sIt); +#ifdef DEBUG_KREGEXP3 + kdDebug() << " Adding literal replacement part:" << endl; + kdDebug() << " result == \"" + result + "\"" << endl; +#endif + } + if (matchedLength() == 0 && pos == 0) { + // if we matched the begin of the string, then better avoid endless + // recursion + result += str.mid( oldpos ); + break; + } + pos += matchedLength(); +#ifdef DEBUG_KREGEXP3 + kdDebug() << TQString(" Setting new pos to %1.").tqarg(pos) << endl; +#endif + oldpos = pos; + + if ( !global ) { + // only replace the first occurrence, so stop here: + result += str.mid( oldpos ); + break; + } + } + + return result; +} diff --git a/libtdepim/kregexp3.h b/libtdepim/kregexp3.h new file mode 100644 index 000000000..e5013366c --- /dev/null +++ b/libtdepim/kregexp3.h @@ -0,0 +1,111 @@ +/* -*- c++ -*- + kregexp3.h + + This file is part of libkdenetwork. + Copyright (c) 2001 Marc Mutz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This library 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 library; 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 library with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 + +/** @short A TQRegExp (TQt3.x) with a replace() method. + + This class is simply there to provide a namespace for some nice + enhancements of the mighty TQRegExp (TQt3 version) regular + expression engine, namely the method replace(), which can be + used to do search-and-replace like one is used to from perl or sed. + + It "simply" adds the ability to define a replacement string which + contains references to the captured substrings. The following + constructs are understood, which can be freely mixed in the + replacement string: + + @section Sed syntax + + Back references in the replacement string are made using \n + (backslash-digit), where @p n is a single digit. With this mode of + operation, only the first nine captured substrings can be + referenced. + + NOTE: Remember that C++ interprets the backslash in string + constants, so you have to write a backslash as "\\". + + @section Perl syntax + + Back references in the replacement string are made using $n + (dollarsign-digit), where @p n is a single digit. With this mode + of operation, only the first nine captured substrings can be + referenced. + + Additionally, Perl supports the syntax ${nn} + (dollarSign-leftCurlyBrace-digits-rightCurlyBrace), where @p nn + can be a multi-digit number. + + In all modes, counting of captured substrings starts with 1 (one)! + To reference the entire matched string, use $0, ${0} or \\0. + + @author Marc Mutz + @see TQRegExp +*/ + +class KDE_EXPORT KRegExp3 : public TQRegExp +{ +public: + KRegExp3() + : TQRegExp() {} + KRegExp3( const TQString & pattern, + bool caseSensitive = TRUE, + bool wildcard = FALSE ) + : TQRegExp( pattern, caseSensitive, wildcard ) {} + KRegExp3( const TQRegExp & rx ) + : TQRegExp( rx ) {} + KRegExp3( const KRegExp3 & rx ) + : TQRegExp( (TQRegExp)rx ) {} + + /** Replaces each matching subpattern in @p str with + @p replacementStr, inserting captured substrings for + \\n, $n and ${nn} as described in the class documentation. + @param str The source string. + @param replacementStr The string which replaces matched + substrings of @p str. + @param start Start position for the search. + If @p start is negative, starts @p -(start) positions + from the end of @p str. + @param global If @p TRUE, requests to replace all occurrences + of the regexp with @p replacementStr; if @p FALSE, + only the first occurrence will be replaced. + Equivalent to the /g switch to perl's s/// operator. + @return The modified string. + */ + TQString replace( const TQString & str, + const TQString & replacementStr, + int start=0, bool global=TRUE ); +}; diff --git a/libtdepim/kresourceprefs.cpp b/libtdepim/kresourceprefs.cpp new file mode 100644 index 000000000..c343f806d --- /dev/null +++ b/libtdepim/kresourceprefs.cpp @@ -0,0 +1,38 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +#include "kresourceprefs.h" + +KResourcePrefs::KResourcePrefs( const TQString &name ) + : KConfigSkeleton( name ) +{ +} + +void KResourcePrefs::addGroupPrefix( const TQString &prefix ) +{ + KConfigSkeletonItem::List itemList = items(); + KConfigSkeletonItem::List::Iterator it; + + for ( it = itemList.begin(); it != itemList.end(); ++it ) + (*it)->setGroup( prefix + ":" + (*it)->group() ); +} diff --git a/libtdepim/kresourceprefs.h b/libtdepim/kresourceprefs.h new file mode 100644 index 000000000..6d96deadb --- /dev/null +++ b/libtdepim/kresourceprefs.h @@ -0,0 +1,49 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KRESOURCEPREFS_H +#define KRESOURCEPREFS_H + +#include +#include + +class TQString; + +/** + This is a base class for all KPrefs objects, where multiple instances want + to work on the same config file. + By calling addGroupPrefix( "foobar" ), 'foobar' as a prefix is added to the + group names in the configuration file. + The prefix should be an unique identifier to avoid name clashes and the method + has to be called before readConfig(), otherwise the wrong entries are read. + */ +class KDE_EXPORT KResourcePrefs : public KConfigSkeleton +{ + public: + KResourcePrefs( const TQString &name = TQString() ); + + /** + Adds a prefix to all groups of this prefs object. + */ + void addGroupPrefix( const TQString &prefix ); +}; + +#endif diff --git a/libtdepim/krsqueezedtextlabel.cpp b/libtdepim/krsqueezedtextlabel.cpp new file mode 100644 index 000000000..ef9746ee0 --- /dev/null +++ b/libtdepim/krsqueezedtextlabel.cpp @@ -0,0 +1,86 @@ +/* This file has been copied from the KDE libraries and slightly modified. + This can be removed as soon as kdelibs provides the same functionality. + + Copyright (C) 2000 Ronny Standtke + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "krsqueezedtextlabel.h" +#include "kstringhandler.h" +#include + +KRSqueezedTextLabel::KRSqueezedTextLabel( const TQString &text , TQWidget *parent, const char *name ) + : TQLabel ( parent, name ) { + tqsetSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed )); + fullText = text; + squeezeTextToLabel(); +} + +KRSqueezedTextLabel::KRSqueezedTextLabel( TQWidget *parent, const char *name ) + : TQLabel ( parent, name ) { + tqsetSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed )); +} + +void KRSqueezedTextLabel::resizeEvent( TQResizeEvent * ) { + squeezeTextToLabel(); +} + +TQSize KRSqueezedTextLabel::tqminimumSizeHint() const +{ + TQSize sh = TQLabel::tqminimumSizeHint(); + sh.setWidth(-1); + return sh; +} + +TQSize KRSqueezedTextLabel::tqsizeHint() const +{ + return TQSize(contentsRect().width(), TQLabel::tqsizeHint().height()); +} + +void KRSqueezedTextLabel::setText( const TQString &text ) { + fullText = text; + squeezeTextToLabel(); +} + +void KRSqueezedTextLabel::squeezeTextToLabel() { + TQFontMetrics fm(fontMetrics()); + int labelWidth = size().width(); + int textWidth = fm.width(fullText); + if (textWidth > labelWidth) { + TQString squeezedText = KStringHandler::rPixelSqueeze(fullText, fm, labelWidth); + TQLabel::setText(squeezedText); + + TQToolTip::remove( this ); + TQToolTip::add( this, fullText ); + + } else { + TQLabel::setText(fullText); + + TQToolTip::remove( this ); + TQToolTip::hide(); + + } +} + +void KRSqueezedTextLabel::tqsetAlignment( int tqalignment ) +{ + // save fullText and restore it + TQString tmpFull(fullText); + TQLabel::tqsetAlignment(tqalignment); + fullText = tmpFull; +} + +#include "krsqueezedtextlabel.moc" diff --git a/libtdepim/krsqueezedtextlabel.h b/libtdepim/krsqueezedtextlabel.h new file mode 100644 index 000000000..36bd209b6 --- /dev/null +++ b/libtdepim/krsqueezedtextlabel.h @@ -0,0 +1,75 @@ +/* This file has been copied from the KDE libraries and slightly modified. + This can be removed as soon as kdelibs provides the same functionality. + + Copyright (C) 2000 Ronny Standtke + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KRSTQUEEZEDTEXTLABEL_H +#define KRSTQUEEZEDTEXTLABEL_H + +#include +#include + +/** + * @short A replacement for TQLabel that squeezes its text + * + * A label class that squeezes its text into the label + * + * If the text is too long to fit into the label it is divided into + * remaining left and right parts which are separated by three dots. + * + * @author Ronny Standtke + */ + +/* + * TQLabel + */ +class KDE_EXPORT KRSqueezedTextLabel : public TQLabel { + Q_OBJECT + TQ_OBJECT + +public: + /** + * Default constructor. + */ + KRSqueezedTextLabel( TQWidget *parent, const char *name = 0 ); + KRSqueezedTextLabel( const TQString &text, TQWidget *parent, const char *name = 0 ); + + virtual TQSize tqminimumSizeHint() const; + virtual TQSize tqsizeHint() const; + /** + * Overridden for internal reasons; the API remains unaffected. + */ + virtual void tqsetAlignment( int ); + +public slots: + void setText( const TQString & ); + +protected: + /** + * used when widget is resized + */ + void resizeEvent( TQResizeEvent * ); + /** + * does the dirty work + */ + void squeezeTextToLabel(); + TQString fullText; + +}; + +#endif // KRSTQUEEZEDTEXTLABEL_H diff --git a/libtdepim/kscoring.cpp b/libtdepim/kscoring.cpp new file mode 100644 index 000000000..cf02d88f4 --- /dev/null +++ b/libtdepim/kscoring.cpp @@ -0,0 +1,1234 @@ +/* + kscoring.cpp + + Copyright (c) 2001 Mathias Waack + Copyright (C) 2005 by Volker Krause + + Author: Mathias Waack + + 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. + 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, US +*/ +#ifdef KDE_USE_FINAL +#undef TQT_NO_ASCII_CAST +#endif + +#undef TQT_NO_COMPAT + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kscoring.h" +#include "kscoringeditor.h" + + +//---------------------------------------------------------------------------- +// a small function to encode attribute values, code stolen from TQDom +static TQString toXml(const TQString& str) +{ + TQString tmp(str); + uint len = tmp.length(); + uint i = 0; + while ( i < len ) { + if (tmp[(int)i] == '<') { + tmp.replace(i, 1, "<"); + len += 3; + i += 4; + } else if (tmp[(int)i] == '"') { + tmp.replace(i, 1, """); + len += 5; + i += 6; + } else if (tmp[(int)i] == '&') { + tmp.replace(i, 1, "&"); + len += 4; + i += 5; + } else if (tmp[(int)i] == '>') { + tmp.replace(i, 1, ">"); + len += 3; + i += 4; + } else { + ++i; + } + } + + return tmp; +} + + +// small dialog to display the messages from NotifyAction +NotifyDialog* NotifyDialog::me = 0; +NotifyDialog::NotesMap NotifyDialog::dict; + +NotifyDialog::NotifyDialog(TQWidget* p) + : KDialogBase(p,"notify action dialog",true,"Notify Message",Close,Close,true) +{ + TQFrame *f = makeMainWidget(); + TQVBoxLayout *topL = new TQVBoxLayout(f); + note = new TQLabel(f); + note->setTextFormat(RichText); + topL->addWidget(note); + TQCheckBox *check = new TQCheckBox(i18n("Do not show this message again"),f); + check->setChecked(true); + topL->addWidget(check); + connect(check,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotShowAgainToggled(bool))); +} + +void NotifyDialog::slotShowAgainToggled(bool flag) +{ + dict.replace(msg,!flag); + kdDebug(5100) << "note \"" << note << "\" will popup again: " << flag << endl; +} + +void NotifyDialog::display(ScorableArticle& a, const TQString& s) +{ + kdDebug(5100) << "displaying message" << endl; + if (!me) me = new NotifyDialog(); + me->msg = s; + + NotesMap::Iterator i = dict.find(s); + if (i == dict.end() || i.data()) { + TQString msg = i18n("Article\n%1
%2
caused the following" + " note to appear:
%3"). + arg(a.from()). + arg(a.subject()). + arg(s); + me->note->setText(msg); + if ( i == dict.end() ) i = dict.replace(s,false); + me->adjustSize(); + me->exec(); + } +} + + +//---------------------------------------------------------------------------- +ScorableArticle::~ScorableArticle() +{ +} + +void ScorableArticle::displayMessage(const TQString& note) +{ + NotifyDialog::display(*this,note); +} + +//---------------------------------------------------------------------------- +ScorableGroup::~ScorableGroup() +{ +} + +// the base class for all actions +ActionBase::ActionBase() +{ + kdDebug(5100) << "new Action " << this << endl; +} + +ActionBase::~ActionBase() +{ + kdDebug(5100) << "delete Action " << this << endl; +} + + +TQStringList ActionBase::userNames() +{ + TQStringList l; + l << userName(SETSCORE); + l << userName(NOTIFY); + l << userName(COLOR); + l << userName(MARKASREAD); + return l; +} + +ActionBase* ActionBase::factory(int type, const TQString &value) +{ + switch (type) { + case SETSCORE: return new ActionSetScore(value); + case NOTIFY: return new ActionNotify(value); + case COLOR: return new ActionColor(value); + case MARKASREAD: return new ActionMarkAsRead(); + default: + kdWarning(5100) << "unknown type " << type << " in ActionBase::factory()" << endl; + return 0; + } +} + +TQString ActionBase::userName(int type) +{ + switch (type) { + case SETSCORE: return i18n("Adjust Score"); + case NOTIFY: return i18n("Display Message"); + case COLOR: return i18n("Colorize Header"); + case MARKASREAD: return i18n("Mark As Read"); + default: + kdWarning(5100) << "unknown type " << type << " in ActionBase::userName()" << endl; + return 0; + } +} + +int ActionBase::getTypeForName(const TQString& name) +{ + if (name == "SETSCORE") return SETSCORE; + else if (name == "NOTIFY") return NOTIFY; + else if (name == "COLOR") return COLOR; + else if (name == "MARKASREAD") return MARKASREAD; + else { + kdWarning(5100) << "unknown type string " << name + << " in ActionBase::getTypeForName()" << endl; + return -1; + } +} + +int ActionBase::getTypeForUserName(const TQString& name) +{ + if (name == userName(SETSCORE)) return SETSCORE; + else if (name == userName(NOTIFY)) return NOTIFY; + else if (name == userName(COLOR)) return COLOR; + else if ( name == userName(MARKASREAD) ) return MARKASREAD; + else { + kdWarning(5100) << "unknown type string " << name + << " in ActionBase::getTypeForUserName()" << endl; + return -1; + } +} + +// the set score action +ActionSetScore::ActionSetScore(short v) + : val(v) +{ +} + +ActionSetScore::ActionSetScore(const TQString& s) +{ + val = s.toShort(); +} + +ActionSetScore::ActionSetScore(const ActionSetScore& as) + : ActionBase(), + val(as.val) +{ +} + +ActionSetScore::~ActionSetScore() +{ +} + +TQString ActionSetScore::toString() const +{ + TQString a; + a += ""; + return a; +} + +void ActionSetScore::apply(ScorableArticle& a) const +{ + a.addScore(val); +} + +ActionSetScore* ActionSetScore::clone() const +{ + return new ActionSetScore(*this); +} + +// the color action +ActionColor::ActionColor(const TQColor& c) + : ActionBase(), color(c) +{ +} + +ActionColor::ActionColor(const TQString& s) + : ActionBase() +{ + setValue(s); +} + +ActionColor::ActionColor(const ActionColor& a) + : ActionBase(), color(a.color) +{ +} + +ActionColor::~ActionColor() +{} + +TQString ActionColor::toString() const +{ + TQString a; + a += ""; + return a; +} + +void ActionColor::apply(ScorableArticle& a) const +{ + a.changeColor(color); +} + +ActionColor* ActionColor::clone() const +{ + return new ActionColor(*this); +} + + +// the notify action +ActionNotify::ActionNotify(const TQString& s) +{ + note = s; +} + +ActionNotify::ActionNotify(const ActionNotify& an) + : ActionBase() +{ + note = an.note; +} + +TQString ActionNotify::toString() const +{ + return ""; +} + +void ActionNotify::apply(ScorableArticle& a) const +{ + a.displayMessage(note); +} + +ActionNotify* ActionNotify::clone() const +{ + return new ActionNotify(*this); +} + + +// mark as read action +ActionMarkAsRead::ActionMarkAsRead() : + ActionBase() +{ +} + +ActionMarkAsRead::ActionMarkAsRead( const ActionMarkAsRead &action ) : + ActionBase() +{ + Q_UNUSED( action ); +} + +TQString ActionMarkAsRead::toString() const +{ + return ""; +} + +void ActionMarkAsRead::apply( ScorableArticle &article ) const +{ + article.markAsRead(); +} + +ActionMarkAsRead* ActionMarkAsRead::clone() const +{ + return new ActionMarkAsRead(*this); +} + +//---------------------------------------------------------------------------- +NotifyCollection::NotifyCollection() +{ + notifyList.setAutoDelete(true); +} + +NotifyCollection::~NotifyCollection() +{ +} + +void NotifyCollection::addNote(const ScorableArticle& a, const TQString& note) +{ + article_list *l = notifyList.find(note); + if (!l) { + notifyList.insert(note,new article_list); + l = notifyList.find(note); + } + article_info i; + i.from = a.from(); + i.subject = a.subject(); + l->append(i); +} + +TQString NotifyCollection::collection() const +{ + TQString notifyCollection = i18n("

List of collected notes

"); + notifyCollection += "

    "; + // first look thru the notes and create one string + TQDictIterator it(notifyList); + for(;it.current();++it) { + const TQString& note = it.currentKey(); + notifyCollection += "
  • " + note + "
      "; + article_list* alist = it.current(); + article_list::Iterator ait; + for(ait = alist->begin(); ait != alist->end(); ++ait) { + notifyCollection += "
    • From: " + (*ait).from + "
      "; + notifyCollection += "Subject: " + (*ait).subject; + } + notifyCollection += "
    "; + } + notifyCollection += "
"; + + return notifyCollection; +} + +void NotifyCollection::displayCollection(TQWidget *p) const +{ + //KMessageBox::information(p,collection(),i18n("Collected Notes")); + KDialogBase *dlg = new KDialogBase( p, 0, false, i18n("Collected Notes"), + KDialogBase::Close, KDialogBase::Close ); + TQTextView *text = new TQTextView(dlg); + text->setText(collection()); + dlg->setMainWidget(text); + dlg->setMinimumWidth(300); + dlg->setMinimumHeight(300); + dlg->show(); +} + +//---------------------------------------------------------------------------- +KScoringExpression::KScoringExpression(const TQString& h, const TQString& t, const TQString& n, const TQString& ng) + : header(h), expr_str(n) +{ + if (t == "MATCH" ) { + cond = MATCH; + expr.setPattern(expr_str); + expr.setCaseSensitive(false); + } + else if ( t == "MATCHCS" ) { + cond = MATCHCS; + expr.setPattern( expr_str ); + expr.setCaseSensitive( true ); + } + else if (t == "CONTAINS" ) cond = CONTAINS; + else if (t == "ETQUALS" ) cond = ETQUALS; + else if (t == "GREATER") { + cond = GREATER; + expr_int = expr_str.toInt(); + } + else if (t == "SMALLER") { + cond = SMALLER; + expr_int = expr_str.toInt(); + } + else { + kdDebug(5100) << "unknown match type in new expression" << endl; + } + + neg = ng.toInt(); + c_header = header.latin1(); + + kdDebug(5100) << "new expr: " << c_header << " " << t << " " + << expr_str << " " << neg << endl; +} + +// static +int KScoringExpression::getConditionForName(const TQString& s) +{ + if (s == getNameForCondition(CONTAINS)) return CONTAINS; + else if (s == getNameForCondition(MATCH)) return MATCH; + else if (s == getNameForCondition(MATCHCS)) return MATCHCS; + else if (s == getNameForCondition(ETQUALS)) return ETQUALS; + else if (s == getNameForCondition(SMALLER)) return SMALLER; + else if (s == getNameForCondition(GREATER)) return GREATER; + else { + kdWarning(5100) << "unknown condition name " << s + << " in KScoringExpression::getConditionForName()" << endl; + return -1; + } +} + +// static +TQString KScoringExpression::getNameForCondition(int cond) +{ + switch (cond) { + case CONTAINS: return i18n("Contains Substring"); + case MATCH: return i18n("Matches Regular Expression"); + case MATCHCS: return i18n("Matches Regular Expression (Case Sensitive)"); + case ETQUALS: return i18n("Is Exactly the Same As"); + case SMALLER: return i18n("Less Than"); + case GREATER: return i18n("Greater Than"); + default: + kdWarning(5100) << "unknown condition " << cond + << " in KScoringExpression::getNameForCondition()" << endl; + return ""; + } +} + +// static +TQStringList KScoringExpression::conditionNames() +{ + TQStringList l; + l << getNameForCondition(CONTAINS); + l << getNameForCondition(MATCH); + l << getNameForCondition(MATCHCS); + l << getNameForCondition(ETQUALS); + l << getNameForCondition(SMALLER); + l << getNameForCondition(GREATER); + return l; +} + +// static +TQStringList KScoringExpression::headerNames() +{ + TQStringList l; + l.append("From"); + l.append("Message-ID"); + l.append("Subject"); + l.append("Date"); + l.append("References"); + l.append("NNTP-Posting-Host"); + l.append("Bytes"); + l.append("Lines"); + l.append("Xref"); + return l; +} + +KScoringExpression::~KScoringExpression() +{ +} + +bool KScoringExpression::match(ScorableArticle& a) const +{ + //kdDebug(5100) << "matching against header " << c_header << endl; + bool res = true; + TQString head; + + if (header == "From") + head = a.from(); + else if (header == "Subject") + head = a.subject(); + else + head = a.getHeaderByType(c_header); + + if (!head.isEmpty()) { + switch (cond) { + case ETQUALS: + res = (head.lower() == expr_str.lower()); + break; + case CONTAINS: + res = (head.lower().find(expr_str.lower()) >= 0); + break; + case MATCH: + case MATCHCS: + res = (expr.search(head)!=-1); + break; + case GREATER: + res = (head.toInt() > expr_int); + break; + case SMALLER: + res = (head.toInt() < expr_int); + break; + default: + kdDebug(5100) << "unknown match" << endl; + res = false; + } + } + else res = false; +// kdDebug(5100) << "matching returns " << res << endl; + return (neg)?!res:res; +} + +void KScoringExpression::write(TQTextStream& st) const +{ + st << toString(); +} + +TQString KScoringExpression::toString() const +{ +// kdDebug(5100) << "KScoringExpression::toString() starts" << endl; +// kdDebug(5100) << "header is " << header << endl; +// kdDebug(5100) << "expr is " << expr_str << endl; +// kdDebug(5100) << "neg is " << neg << endl; +// kdDebug(5100) << "type is " << getType() << endl; + TQString e; + e += ""; +// kdDebug(5100) << "KScoringExpression::toString() finished" << endl; + return e; +} + +TQString KScoringExpression::getTypeString() const +{ + return KScoringExpression::getTypeString(cond); +} + +TQString KScoringExpression::getTypeString(int cond) +{ + switch (cond) { + case CONTAINS: return "CONTAINS"; + case MATCH: return "MATCH"; + case MATCHCS: return "MATCHCS"; + case ETQUALS: return "ETQUALS"; + case SMALLER: return "SMALLER"; + case GREATER: return "GREATER"; + default: + kdWarning(5100) << "unknown cond " << cond << " in KScoringExpression::getTypeString()" << endl; + return ""; + } +} + +int KScoringExpression::getType() const +{ + return cond; +} + +//---------------------------------------------------------------------------- +KScoringRule::KScoringRule(const TQString& n ) + : name(n), link(AND) +{ + expressions.setAutoDelete(true); + actions.setAutoDelete(true); +} + +KScoringRule::KScoringRule(const KScoringRule& r) +{ + kdDebug(5100) << "copying rule " << r.getName() << endl; + name = r.getName(); + expressions.setAutoDelete(true); + actions.setAutoDelete(true); + // copy expressions + expressions.clear(); + const ScoreExprList& rexpr = r.expressions; + TQPtrListIterator it(rexpr); + for ( ; it.current(); ++it ) { + KScoringExpression *t = new KScoringExpression(**it); + expressions.append(t); + } + // copy actions + actions.clear(); + const ActionList& ract = r.actions; + TQPtrListIterator ait(ract); + for ( ; ait.current(); ++ait ) { + ActionBase *t = *ait; + actions.append(t->clone()); + } + // copy groups, servers, linkmode and expires + groups = r.groups; + expires = r.expires; + link = r.link; +} + +KScoringRule::~KScoringRule() +{ + cleanExpressions(); + cleanActions(); +} + +void KScoringRule::cleanExpressions() +{ + // the expressions is setAutoDelete(true) + expressions.clear(); +} + +void KScoringRule::cleanActions() +{ + // the actions is setAutoDelete(true) + actions.clear(); +} + +void KScoringRule::addExpression( KScoringExpression* expr) +{ + kdDebug(5100) << "KScoringRule::addExpression" << endl; + expressions.append(expr); +} + +void KScoringRule::addAction(int type, const TQString& val) +{ + ActionBase *action = ActionBase::factory(type,val); + addAction(action); +} + +void KScoringRule::addAction(ActionBase* a) +{ + kdDebug(5100) << "KScoringRule::addAction() " << a->toString() << endl; + actions.append(a); +} + +void KScoringRule::setLinkMode(const TQString& l) +{ + if (l == "OR") link = OR; + else link = AND; +} + +void KScoringRule::setExpire(const TQString& e) +{ + if (e != "never") { + TQStringList l = TQStringList::split("-",e); + Q_ASSERT( l.count() == 3 ); + expires.setYMD( (*(l.at(0))).toInt(), + (*(l.at(1))).toInt(), + (*(l.at(2))).toInt()); + } + kdDebug(5100) << "Rule " << getName() << " expires at " << getExpireDateString() << endl; +} + +bool KScoringRule::matchGroup(const TQString& group) const +{ + for(GroupList::ConstIterator i=groups.begin(); i!=groups.end();++i) { + TQRegExp e(*i); + if (e.search(group, 0) != -1 && + (uint)e.matchedLength() == group.length()) + return true; + } + return false; +} + +void KScoringRule::applyAction(ScorableArticle& a) const +{ + TQPtrListIterator it(actions); + for(; it.current(); ++it) { + it.current()->apply(a); + } +} + +void KScoringRule::applyRule(ScorableArticle& a) const +{ + // kdDebug(5100) << "checking rule " << name << endl; + // kdDebug(5100) << " for article from " + // << a->from()->asUnicodeString() + // << endl; + bool oper_and = (link == AND); + bool res = true; + TQPtrListIterator it(expressions); + //kdDebug(5100) << "checking " << expressions.count() << " expressions" << endl; + for (; it.current(); ++it) { + Q_ASSERT( it.current() ); + res = it.current()->match(a); + if (!res && oper_and) return; + else if (res && !oper_and) break; + } + if (res) applyAction(a); +} + +void KScoringRule::applyRule(ScorableArticle& a /*, const TQString& s*/, const TQString& g) const +{ + // check if one of the groups match + for (TQStringList::ConstIterator i = groups.begin(); i != groups.end(); ++i) { + if (TQRegExp(*i).search(g) != -1) { + applyRule(a); + return; + } + } +} + +void KScoringRule::write(TQTextStream& s) const +{ + s << toString(); +} + +TQString KScoringRule::toString() const +{ + //kdDebug(5100) << "KScoringRule::toString() starts" << endl; + TQString r; + r += ""; + //kdDebug(5100) << "building grouplist..." << endl; + for(GroupList::ConstIterator i=groups.begin();i!=groups.end();++i) { + r += ""; + } + //kdDebug(5100) << "building expressionlist..." << endl; + TQPtrListIterator eit(expressions); + for (; eit.current(); ++eit) { + r += eit.current()->toString(); + } + //kdDebug(5100) << "building actionlist..." << endl; + TQPtrListIterator ait(actions); + for (; ait.current(); ++ait) { + r += ait.current()->toString(); + } + r += ""; + //kdDebug(5100) << "KScoringRule::toString() finished" << endl; + return r; +} + +TQString KScoringRule::getLinkModeName() const +{ + switch (link) { + case AND: return "AND"; + case OR: return "OR"; + default: return "AND"; + } +} + +TQString KScoringRule::getExpireDateString() const +{ + if (expires.isNull()) return "never"; + else { + return TQString::number(expires.year()) + TQString("-") + + TQString::number(expires.month()) + TQString("-") + + TQString::number(expires.day()); + } +} + +bool KScoringRule::isExpired() const +{ + return (expires.isValid() && (expires < TQDate::tqcurrentDate())); +} + + + +//---------------------------------------------------------------------------- +KScoringManager::KScoringManager(const TQString& appName) + : cacheValid(false)//, _s(0) +{ + allRules.setAutoDelete(true); + // determine filename of the scorefile + if(appName.isEmpty()) + mFilename = KGlobal::dirs()->saveLocation("appdata") + "/scorefile"; + else + mFilename = KGlobal::dirs()->saveLocation("data") + "/" + appName + "/scorefile"; + // open the score file + load(); +} + + +KScoringManager::~KScoringManager() +{ +} + +void KScoringManager::load() +{ + TQDomDocument sdoc("Scorefile"); + TQFile f( mFilename ); + if ( !f.open( IO_ReadOnly ) ) + return; + if ( !sdoc.setContent( &f ) ) { + f.close(); + kdDebug(5100) << "loading the scorefile failed" << endl; + return; + } + f.close(); + kdDebug(5100) << "loaded the scorefile, creating internal representation" << endl; + allRules.clear(); + createInternalFromXML(sdoc); + expireRules(); + kdDebug(5100) << "ready, got " << allRules.count() << " rules" << endl; +} + +void KScoringManager::save() +{ + kdDebug(5100) << "KScoringManager::save() starts" << endl; + TQFile f( mFilename ); + if ( !f.open( IO_WriteOnly ) ) + return; + TQTextStream stream(&f); + stream.setEncoding(TQTextStream::Unicode); + kdDebug(5100) << "KScoringManager::save() creating xml" << endl; + createXMLfromInternal().save(stream,2); + kdDebug(5100) << "KScoringManager::save() finished" << endl; +} + +TQDomDocument KScoringManager::createXMLfromInternal() +{ + // I was'nt able to create a TQDomDocument in memory:( + // so I write the content into a string, which is really stupid + TQDomDocument sdoc("Scorefile"); + TQString ss; // scorestring + ss += ""; + ss += toString(); + ss += "\n"; + kdDebug(5100) << "KScoringManager::createXMLfromInternal():" << endl << ss << endl; + sdoc.setContent(ss); + return sdoc; +} + +TQString KScoringManager::toString() const +{ + TQString s; + s += "\n"; + TQPtrListIterator it(allRules); + for( ; it.current(); ++it) { + s += it.current()->toString(); + } + return s; +} + +void KScoringManager::expireRules() +{ + for ( KScoringRule *cR = allRules.first(); cR; cR=allRules.next()) { + if (cR->isExpired()) { + kdDebug(5100) << "Rule " << cR->getName() << " is expired, deleting it" << endl; + allRules.remove(); + } + } +} + +void KScoringManager::createInternalFromXML(TQDomNode n) +{ + static KScoringRule *cR = 0; // the currentRule + // the XML file was parsed and now we simply traverse the resulting tree + if ( !n.isNull() ) { + kdDebug(5100) << "inspecting node of type " << n.nodeType() + << " named " << n.toElement().tagName() << endl; + + switch (n.nodeType()) { + case TQDomNode::DocumentNode: { + // the document itself + break; + } + case TQDomNode::ElementNode: { + // Server, Newsgroup, Rule, Expression, Action + TQDomElement e = n.toElement(); + //kdDebug(5100) << "The name of the element is " + //<< e.tagName().latin1() << endl; + TQString s = e.tagName(); + if (s == "Rule") { + cR = new KScoringRule(e.attribute("name")); + cR->setLinkMode(e.attribute("linkmode")); + cR->setExpire(e.attribute("expires")); + addRuleInternal(cR); + } + else if (s == "Group") { + Q_CHECK_PTR(cR); + cR->addGroup( e.attribute("name") ); + } + else if (s == "Expression") { + cR->addExpression(new KScoringExpression(e.attribute("header"), + e.attribute("type"), + e.attribute("expr"), + e.attribute("neg"))); + } + else if (s == "Action") { + Q_CHECK_PTR(cR); + cR->addAction(ActionBase::getTypeForName(e.attribute("type")), + e.attribute("value")); + } + break; + } + default: // kdDebug(5100) << "unknown DomNode::type" << endl; + ; + } + TQDomNodeList nodelist = n.childNodes(); + unsigned cnt = nodelist.count(); + //kdDebug(5100) << "recursive checking " << cnt << " nodes" << endl; + for (unsigned i=0;iaddGroup( group ); + rule->addExpression( + new KScoringExpression("From","CONTAINS", + a.from(),"0")); + if (score) rule->addAction(new ActionSetScore(score)); + rule->setExpireDate(TQDate::tqcurrentDate().addDays(30)); + addRule(rule); + KScoringEditor *edit = KScoringEditor::createEditor(this); + edit->setRule(rule); + edit->show(); + setCacheValid(false); + return rule; +} + +KScoringRule* KScoringManager::addRule(KScoringRule* expr) +{ + int i = allRules.findRef(expr); + if (i == -1) { + // only add a rule we don't know + addRuleInternal(expr); + } + else { + emit changedRules(); + } + return expr; +} + +KScoringRule* KScoringManager::addRule() +{ + KScoringRule *rule = new KScoringRule(findUniqueName()); + addRule(rule); + return rule; +} + +void KScoringManager::addRuleInternal(KScoringRule *e) +{ + allRules.append(e); + setCacheValid(false); + emit changedRules(); + kdDebug(5100) << "KScoringManager::addRuleInternal " << e->getName() << endl; +} + +void KScoringManager::cancelNewRule(KScoringRule *r) +{ + // if e was'nt previously added to the list of rules, we delete it + int i = allRules.findRef(r); + if (i == -1) { + kdDebug(5100) << "deleting rule " << r->getName() << endl; + deleteRule(r); + } + else { + kdDebug(5100) << "rule " << r->getName() << " not deleted" << endl; + } +} + +void KScoringManager::setRuleName(KScoringRule *r, const TQString& s) +{ + bool cont = true; + TQString text = s; + TQString oldName = r->getName(); + while (cont) { + cont = false; + TQPtrListIterator it(allRules); + for (; it.current(); ++it) { + if ( it.current() != r && it.current()->getName() == text ) { + kdDebug(5100) << "rule name " << text << " is not unique" << endl; + text = KInputDialog::getText(i18n("Choose Another Rule Name"), + i18n("The rule name is already assigned, please choose another name:"), + text); + cont = true; + break; + } + } + } + if (text != oldName) { + r->setName(text); + emit changedRuleName(oldName,text); + } +} + +void KScoringManager::deleteRule(KScoringRule *r) +{ + int i = allRules.findRef(r); + if (i != -1) { + allRules.remove(); + emit changedRules(); + } +} + +void KScoringManager::editRule(KScoringRule *e, TQWidget *w) +{ + KScoringEditor *edit = KScoringEditor::createEditor(this, w); + edit->setRule(e); + edit->show(); + delete edit; +} + +void KScoringManager::moveRuleAbove( KScoringRule *above, KScoringRule *below ) +{ + int aindex = allRules.findRef( above ); + int bindex = allRules.findRef( below ); + if ( aindex <= 0 || bindex < 0 ) + return; + if ( aindex < bindex ) + --bindex; + allRules.take( aindex ); + allRules.insert( bindex, above ); +} + +void KScoringManager::moveRuleBelow( KScoringRule *below, KScoringRule *above ) +{ + int bindex = allRules.findRef( below ); + int aindex = allRules.findRef( above ); + if ( bindex < 0 || bindex >= (int)allRules.count() - 1 || aindex < 0 ) + return; + if ( bindex < aindex ) + --aindex; + allRules.take( bindex ); + allRules.insert( aindex + 1, below ); +} + +void KScoringManager::editorReady() +{ + kdDebug(5100) << "emitting signal finishedEditing" << endl; + save(); + emit finishedEditing(); +} + +KScoringRule* KScoringManager::copyRule(KScoringRule *r) +{ + KScoringRule *rule = new KScoringRule(*r); + rule->setName(findUniqueName()); + addRuleInternal(rule); + return rule; +} + +void KScoringManager::applyRules(ScorableGroup* ) +{ + kdWarning(5100) << "KScoringManager::applyRules(ScorableGroup* ) isn't implemented" << endl; +} + +void KScoringManager::applyRules(ScorableArticle& article, const TQString& group) +{ + setGroup(group); + applyRules(article); +} + +void KScoringManager::applyRules(ScorableArticle& a) +{ + TQPtrListIterator it(isCacheValid()? ruleList : allRules); + for( ; it.current(); ++it) { + it.current()->applyRule(a); + } +} + +void KScoringManager::initCache(const TQString& g) +{ + group = g; + ruleList.clear(); + TQPtrListIterator it(allRules); + for (; it.current(); ++it) { + if ( it.current()->matchGroup(group) ) { + ruleList.append(it.current()); + } + } + kdDebug(5100) << "created cache for group " << group + << " with " << ruleList.count() << " rules" << endl; + setCacheValid(true); +} + +void KScoringManager::setGroup(const TQString& g) +{ + if (group != g) initCache(g); +} + +bool KScoringManager::hasRulesForCurrentGroup() +{ + return ruleList.count() != 0; +} + + +TQStringList KScoringManager::getRuleNames() +{ + TQStringList l; + TQPtrListIterator it(allRules); + for( ; it.current(); ++it) { + l << it.current()->getName(); + } + return l; +} + +KScoringRule* KScoringManager::findRule(const TQString& ruleName) +{ + TQPtrListIterator it(allRules); + for (; it.current(); ++it) { + if ( it.current()->getName() == ruleName ) { + return it; + } + } + return 0; +} + +bool KScoringManager::setCacheValid(bool v) +{ + bool res = cacheValid; + cacheValid = v; + return res; +} + +TQString KScoringManager::findUniqueName() const +{ + int nr = 0; + TQString ret; + bool duplicated=false; + + while (nr < 99999999) { + nr++; + ret = i18n("rule %1").tqarg(nr); + + duplicated=false; + TQPtrListIterator it(allRules); + for( ; it.current(); ++it) { + if (it.current()->getName() == ret) { + duplicated = true; + break; + } + } + + if (!duplicated) + return ret; + } + + return ret; +} + +bool KScoringManager::hasFeature(int p) +{ + switch (p) { + case ActionBase::SETSCORE: return canScores(); + case ActionBase::NOTIFY: return canNotes(); + case ActionBase::COLOR: return canColors(); + case ActionBase::MARKASREAD: return canMarkAsRead(); + default: return false; + } +} + +TQStringList KScoringManager::getDefaultHeaders() const +{ + TQStringList l; + l.append("Subject"); + l.append("From"); + l.append("Date"); + l.append("Message-ID"); + return l; +} + +void KScoringManager::pushRuleList() +{ + stack.push(allRules); +} + +void KScoringManager::popRuleList() +{ + stack.pop(allRules); +} + +void KScoringManager::removeTOS() +{ + stack.drop(); +} + +RuleStack::RuleStack() +{ +} + +RuleStack::~RuleStack() +{} + +void RuleStack::push(TQPtrList& l) +{ + kdDebug(5100) << "RuleStack::push pushing list with " << l.count() << " rules" << endl; + KScoringManager::ScoringRuleList *l1 = new KScoringManager::ScoringRuleList; + for ( KScoringRule *r=l.first(); r != 0; r=l.next() ) { + l1->append(new KScoringRule(*r)); + } + stack.push(l1); + kdDebug(5100) << "now there are " << stack.count() << " lists on the stack" << endl; +} + +void RuleStack::pop(TQPtrList& l) +{ + top(l); + drop(); + kdDebug(5100) << "RuleStack::pop pops list with " << l.count() << " rules" << endl; + kdDebug(5100) << "now there are " << stack.count() << " lists on the stack" << endl; +} + +void RuleStack::top(TQPtrList& l) +{ + l.clear(); + KScoringManager::ScoringRuleList *l1 = stack.top(); + l = *l1; +} + +void RuleStack::drop() +{ + kdDebug(5100) << "drop: now there are " << stack.count() << " lists on the stack" << endl; + stack.remove(); +} + + +#include "kscoring.moc" diff --git a/libtdepim/kscoring.h b/libtdepim/kscoring.h new file mode 100644 index 000000000..7225eb93f --- /dev/null +++ b/libtdepim/kscoring.h @@ -0,0 +1,429 @@ +/* + kscoring.h + + Copyright (c) 2001 Mathias Waack + Copyright (C) 2005 by Volker Krause + + Author: Mathias Waack + + 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. + 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, US +*/ + +#ifndef KSCORING_H +#define KSCORING_H + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +class TQDomNode; +class TQDomDocument; +class TQDomElement; +class TQTextStream; +class TQLabel; + + +/** + The following classes ScorableArticle, ScorableGroup define + the interface for the scoring. Any application using this mechanism should + create its own subclasses of this classes. The scoring itself will be handled + by the ScoringManager class. + */ + +//---------------------------------------------------------------------------- +class KDE_EXPORT ScorableGroup +{ +public: + virtual ~ScorableGroup(); +}; + +class KDE_EXPORT ScorableArticle +{ +public: + virtual ~ScorableArticle(); + + virtual void addScore(short) {} + virtual void displayMessage(const TQString&); + virtual void changeColor(const TQColor&) {} + virtual void markAsRead() {} + virtual TQString from() const = 0; + virtual TQString subject() const = 0; + virtual TQString getHeaderByType(const TQString&) const = 0; + //virtual ScorableGroup group() const =0; +}; + + +//---------------------------------------------------------------------------- +/** + Base class for other Action classes. + */ +class KDE_EXPORT ActionBase { + public: + ActionBase(); + virtual ~ActionBase(); + virtual TQString toString() const =0; + virtual void apply(ScorableArticle&) const =0; + virtual ActionBase* clone() const =0; + virtual int getType() const =0; + virtual TQString getValueString() const { return TQString(); } + virtual void setValue(const TQString&) {} + static ActionBase* factory(int type, const TQString &value); + static TQStringList userNames(); + static TQString userName(int type); + static int getTypeForName(const TQString& name); + static int getTypeForUserName(const TQString& name); + TQString userName() { return userName(getType()); } + enum ActionTypes { SETSCORE, NOTIFY, COLOR, MARKASREAD }; +}; + +class KDE_EXPORT ActionColor : public ActionBase { +public: + ActionColor(const TQColor&); + ActionColor(const TQString&); + ActionColor(const ActionColor&); + virtual ~ActionColor(); + virtual TQString toString() const; + virtual int getType() const { return COLOR; } + virtual TQString getValueString() const { return color.name(); } + virtual void setValue(const TQString& s) { color.setNamedColor(s); } + void setValue(const TQColor& c) { color = c; } + TQColor value() const { return color; } + virtual void apply(ScorableArticle&) const; + virtual ActionColor* clone() const; +private: + TQColor color; +}; + +class KDE_EXPORT ActionSetScore : public ActionBase { + public: + ActionSetScore(short); + ActionSetScore(const ActionSetScore&); + ActionSetScore(const TQString&); + virtual ~ActionSetScore(); + virtual TQString toString() const; + virtual int getType() const { return SETSCORE; } + virtual TQString getValueString() const { return TQString::number(val); } + virtual void setValue(const TQString& s) { val = s.toShort(); } + void setValue(short v) { val = v; } + short value() const { return val; } + virtual void apply(ScorableArticle&) const; + virtual ActionSetScore* clone() const; + private: + short val; +}; + +class KDE_EXPORT ActionNotify : public ActionBase { + public: + ActionNotify(const TQString&); + ActionNotify(const ActionNotify&); + virtual ~ActionNotify() {} + virtual TQString toString() const; + virtual int getType() const { return NOTIFY; } + virtual TQString getValueString() const { return note; } + virtual void setValue(const TQString& s) { note = s; } + virtual void apply(ScorableArticle&) const; + virtual ActionNotify* clone() const; + private: + TQString note; +}; + +class KDE_EXPORT ActionMarkAsRead : public ActionBase { + public: + ActionMarkAsRead(); + ActionMarkAsRead( const ActionMarkAsRead& ); + virtual ~ActionMarkAsRead() {} + virtual TQString toString() const; + virtual int getType() const { return MARKASREAD; } + virtual void apply( ScorableArticle &article ) const; + virtual ActionMarkAsRead* clone() const; +}; + +class KDE_EXPORT NotifyCollection +{ +public: + NotifyCollection(); + ~NotifyCollection(); + void addNote(const ScorableArticle&, const TQString&); + TQString collection() const; + void displayCollection(TQWidget *p=0) const; +private: + struct article_info { + TQString from; + TQString subject; + }; + typedef TQValueList article_list; + typedef TQDict note_list; + note_list notifyList; +}; + + +//---------------------------------------------------------------------------- +class KDE_EXPORT KScoringExpression +{ + friend class KScoringRule; + public: + enum Condition { CONTAINS, MATCH, ETQUALS, SMALLER, GREATER, MATCHCS }; + + KScoringExpression(const TQString&,const TQString&,const TQString&, const TQString&); + ~KScoringExpression(); + + bool match(ScorableArticle& a) const ; + TQString getTypeString() const; + static TQString getTypeString(int); + int getType() const; + TQString toString() const; + void write(TQTextStream& ) const; + + bool isNeg() const { return neg; } + Condition getCondition() const { return cond; } + TQString getExpression() const { return expr_str; } + TQString getHeader() const { return header; } + static TQStringList conditionNames(); + static TQStringList headerNames(); + static int getConditionForName(const TQString&); + static TQString getNameForCondition(int); + private: + bool neg; + TQString header; + const char* c_header; + Condition cond; + TQRegExp expr; + TQString expr_str; + int expr_int; +}; + +//---------------------------------------------------------------------------- +class KDE_EXPORT KScoringRule +{ + friend class KScoringManager; + public: + KScoringRule(const TQString& name); + KScoringRule(const KScoringRule& r); + ~KScoringRule(); + + typedef TQPtrList ScoreExprList; + typedef TQPtrList ActionList; + typedef TQStringList GroupList; + enum LinkMode { AND, OR }; + + TQString getName() const { return name; } + TQStringList getGroups() const { return groups; } + void setGroups(const TQStringList &l) { groups = l; } + LinkMode getLinkMode() const { return link; } + TQString getLinkModeName() const; + TQString getExpireDateString() const; + TQDate getExpireDate() const { return expires; } + void setExpireDate(const TQDate &d) { expires = d; } + bool isExpired() const; + ScoreExprList getExpressions() const { return expressions; } + ActionList getActions() const { return actions; } + void cleanExpressions(); + void cleanActions(); + + bool matchGroup(const TQString& group) const ; + void applyRule(ScorableArticle& a) const; + void applyRule(ScorableArticle& a, const TQString& group) const; + void applyAction(ScorableArticle& a) const; + + void setLinkMode(const TQString& link); + void setLinkMode(LinkMode m) { link = m; } + void setExpire(const TQString& exp); + void addExpression( KScoringExpression* ); + void addGroup( const TQString& group) { groups.append(group); } + //void addServer(const TQString& server) { servers.append(server); } + void addAction(int, const TQString& ); + void addAction(ActionBase*); + + void updateXML(TQDomElement& e, TQDomDocument& d); + TQString toString() const; + + // writes the rule in XML format into the textstream + void write(TQTextStream& ) const; +protected: + //! assert that the name is unique + void setName(const TQString &n) { name = n; } +private: + TQString name; + GroupList groups; + //ServerList servers; + LinkMode link; + ScoreExprList expressions; + ActionList actions; + TQDate expires; +}; + +/** this helper class implements a stack for lists of lists of rules. + With the help of this class its very easy for the KScoringManager + to temporary drop lists of rules and restore them afterwards +*/ +class KDE_EXPORT RuleStack +{ +public: + RuleStack(); + ~RuleStack(); + //! puts the list on the stack, doesn't change the list + void push(TQPtrList&); + //! clears the argument list and copy the content of the TOS into it + //! after that the TOS gets dropped + void pop(TQPtrList&); + //! like pop but without dropping the TOS + void top(TQPtrList&); + //! drops the TOS + void drop(); +private: + TQPtrStack< TQPtrList > stack; +}; + +//---------------------------------------------------------------------------- +// Manages the score rules. +class KDE_EXPORT KScoringManager : public TQObject +{ + Q_OBJECT + TQ_OBJECT + + public: + //* this is the container for all rules + typedef TQPtrList ScoringRuleList; + + KScoringManager(const TQString& appName = TQString()); + virtual ~KScoringManager(); + + //* returns a list of all available groups, must be overridden + virtual TQStringList getGroups() const =0; + + //! returns a list of common (or available) headers + //! defaults to returning { Subject, From, Message-ID, Date } + virtual TQStringList getDefaultHeaders() const; + + //* setting current server and group and calling applyRules(ScorableArticle&) + void applyRules(ScorableArticle& article, const TQString& group/*, const TQString& server*/); + //* assuming a properly set group + void applyRules(ScorableArticle&); + //* same as above + void applyRules(ScorableGroup* group); + + //* pushes the current rule list onto a stack + void pushRuleList(); + //* restores the current rule list from list stored on a stack + //* by a previous call to pushRuleList (this implicitly deletes the + //* current rule list) + void popRuleList(); + //* removes the TOS from the stack of rule lists + void removeTOS(); + + KScoringRule* addRule(KScoringRule *); + KScoringRule* addRule(const ScorableArticle&, TQString group, short =0); + KScoringRule* addRule(); + void cancelNewRule(KScoringRule *); + void deleteRule(KScoringRule *); + void editRule(KScoringRule *e, TQWidget *w=0); + KScoringRule* copyRule(KScoringRule *); + void moveRuleAbove( KScoringRule *above, KScoringRule *below ); + void moveRuleBelow( KScoringRule *below, KScoringRule *above ); + void setGroup(const TQString& g); + // has to be called after setGroup() or initCache() + bool hasRulesForCurrentGroup(); + TQString findUniqueName() const; + + /** called from an editor whenever it finishes editing the rule base, + causes the finishedEditing signal to be emitted */ + void editorReady(); + + ScoringRuleList getAllRules() const { return allRules; } + KScoringRule *findRule(const TQString&); + TQStringList getRuleNames(); + void setRuleName(KScoringRule *, const TQString&); + int getRuleCount() const { return allRules.count(); } + TQString toString() const; + + bool setCacheValid(bool v); + bool isCacheValid() { return cacheValid; } + void initCache(const TQString& group/*, const TQString& server*/); + + void load(); + void save(); + + //--------------- Properties + virtual bool canScores() const { return true; } + virtual bool canNotes() const { return true; } + virtual bool canColors() const { return false; } + virtual bool canMarkAsRead() const { return false; } + virtual bool hasFeature(int); + + signals: + void changedRules(); + void changedRuleName(const TQString& oldName, const TQString& newName); + void finishedEditing(); + + private: + void addRuleInternal(KScoringRule *e); + void expireRules(); + + TQDomDocument createXMLfromInternal(); + void createInternalFromXML(TQDomNode); + + // list of all Rules + ScoringRuleList allRules; + + // the stack for temporary storing rule lists + RuleStack stack; + + // for the cache + bool cacheValid; + // current rule set, ie the cache + ScoringRuleList ruleList; + //TQString server; + TQString group; + + //ScorableServer* _s; + + // filename of the scorefile + TQString mFilename; +}; + + +//---------------------------------------------------------------------------- +class KDE_EXPORT NotifyDialog : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT +public: + static void display(ScorableArticle&,const TQString&); +protected slots: + void slotShowAgainToggled(bool); +private: + NotifyDialog(TQWidget* p =0); + static NotifyDialog *me; + + TQLabel *note; + TQString msg; + typedef TQMap NotesMap; + static NotesMap dict; +}; + + +#endif diff --git a/libtdepim/kscoringeditor.cpp b/libtdepim/kscoringeditor.cpp new file mode 100644 index 000000000..6e520e983 --- /dev/null +++ b/libtdepim/kscoringeditor.cpp @@ -0,0 +1,1029 @@ +/* + kscoringeditor.cpp + + Copyright (c) 2001 Mathias Waack + Copyright (C) 2005 by Volker Krause + + Author: Mathias Waack + + 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. + 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, US +*/ + +#undef TQT_NO_COMPAT + +#include "kscoring.h" +#include "kscoringeditor.h" + +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// works for both ListBox and ComboBox +template static int setCurrentItem(T *box, const TQString& s) +{ + int cnt = box->count(); + for (int i=0;itext(i) == s) { + box->setCurrentItem(i); + return i; + } + } + return -1; +} + + +//============================================================================ +// +// class SingleConditionWidget (editor for one condition, used in ConditionEditWidget) +// +//============================================================================ +SingleConditionWidget::SingleConditionWidget(KScoringManager *m,TQWidget *p, const char *n) + : TQFrame(p,n), manager(m) +{ + TQBoxLayout *topL = new TQVBoxLayout(this,5); + TQBoxLayout *firstRow = new TQHBoxLayout(topL); + neg = new TQCheckBox(i18n("Not"),this); + TQToolTip::add(neg,i18n("Negate this condition")); + firstRow->addWidget(neg); + headers = new KComboBox(this); + headers->insertStringList(manager->getDefaultHeaders()); + headers->setEditable( true ); + TQToolTip::add(headers,i18n("Select the header to match this condition against")); + firstRow->addWidget(headers,1); + matches = new KComboBox(this); + matches->insertStringList(KScoringExpression::conditionNames()); + TQToolTip::add(matches,i18n("Select the type of match")); + firstRow->addWidget(matches,1); + connect( matches, TQT_SIGNAL( activated( int ) ), TQT_SLOT( toggleRegExpButton( int ) ) ); + TQHBoxLayout *secondRow = new TQHBoxLayout( topL ); + secondRow->setSpacing( 1 ); + expr = new KLineEdit( this ); + TQToolTip::add(expr,i18n("The condition for the match")); + // reserve space for at least 20 characters + expr->setMinimumWidth(fontMetrics().maxWidth()*20); + secondRow->addWidget( expr ); + regExpButton = new TQPushButton( i18n("Edit..."), this ); + secondRow->addWidget( regExpButton ); + connect( regExpButton, TQT_SIGNAL( clicked() ), TQT_SLOT( showRegExpDialog() ) ); + + // occupy at much width as possible + tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Fixed)); + setFrameStyle(Box | Sunken); + setLineWidth(1); +} + +SingleConditionWidget::~SingleConditionWidget() +{} + +void SingleConditionWidget::setCondition(KScoringExpression *e) +{ + neg->setChecked(e->isNeg()); + headers->setCurrentText( e->getHeader() ); + setCurrentItem(matches,KScoringExpression::getNameForCondition(e->getCondition())); + toggleRegExpButton( matches->currentItem() ); + expr->setText(e->getExpression()); +} + +KScoringExpression* SingleConditionWidget::createCondition() const +{ + TQString head = headers->currentText(); + TQString match = matches->currentText(); + int condType = KScoringExpression::getConditionForName(match); + match = KScoringExpression::getTypeString(condType); + TQString cond = expr->text(); + TQString negs = (neg->isChecked())?"1":"0"; + return new KScoringExpression(head,match,cond,negs); +} + +void SingleConditionWidget::clear() +{ + neg->setChecked(false); + expr->clear(); +} + +void SingleConditionWidget::toggleRegExpButton( int selected ) +{ + bool isRegExp = (KScoringExpression::MATCH == selected || + KScoringExpression::MATCHCS == selected) && + !KTrader::self()->query("KRegExpEditor/KRegExpEditor").isEmpty(); + regExpButton->setEnabled( isRegExp ); +} + +void SingleConditionWidget::showRegExpDialog() +{ + TQDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery( "KRegExpEditor/KRegExpEditor" ); + if ( editorDialog ) { + KRegExpEditorInterface *editor = static_cast( editorDialog->qt_cast( "KRegExpEditorInterface" ) ); + Q_ASSERT( editor ); // This should not fail! + editor->setRegExp( expr->text() ); + editorDialog->exec(); + expr->setText( editor->regExp() ); + } +} + +//============================================================================ +// +// class ConditionEditWidget (the widget to edit the conditions of a rule) +// +//============================================================================ +ConditionEditWidget::ConditionEditWidget(KScoringManager *m, TQWidget *p, const char *n) + : KWidgetLister(1,8,p,n), manager(m) +{ + // create one initial widget + addWidgetAtEnd(); +} + +ConditionEditWidget::~ConditionEditWidget() +{} + +TQWidget* ConditionEditWidget::createWidget(TQWidget *parent) +{ + return new SingleConditionWidget(manager,parent); +} + +void ConditionEditWidget::clearWidget(TQWidget *w) +{ + Q_ASSERT( w->isA("SingleConditionWidget") ); + SingleConditionWidget *sw = dynamic_cast(w); + if (sw) + sw->clear(); +} + +void ConditionEditWidget::slotEditRule(KScoringRule *rule) +{ + KScoringRule::ScoreExprList l; + if (rule) l = rule->getExpressions(); + if (!rule || l.count() == 0) { + slotClear(); + } else { + setNumberOfShownWidgetsTo(l.count()); + KScoringExpression *e = l.first(); + SingleConditionWidget *scw = static_cast(mWidgetList.first()); + while (e && scw) { + scw->setCondition(e); + e = l.next(); + scw = static_cast(mWidgetList.next()); + } + } +} + +void ConditionEditWidget::updateRule(KScoringRule *rule) +{ + rule->cleanExpressions(); + for(TQWidget *w = mWidgetList.first(); w; w = mWidgetList.next()) { + if (! w->isA("SingleConditionWidget")) { + kdWarning(5100) << "there is a widget in ConditionEditWidget " + << "which isn't a SingleConditionWidget" << endl; + } else { + SingleConditionWidget *saw = dynamic_cast(w); + if (saw) + rule->addExpression(saw->createCondition()); + } + } +} + +//============================================================================ +// +// class SingleActionWidget (editor for one action, used in ActionEditWidget) +// +//============================================================================ +SingleActionWidget::SingleActionWidget(KScoringManager *m,TQWidget *p, const char *n) + : TQWidget(p,n), notifyEditor(0), scoreEditor(0), colorEditor(0),manager(m) +{ + TQHBoxLayout *topL = new TQHBoxLayout(this,0,5); + types = new KComboBox(this); + types->setEditable(false); + topL->addWidget(types); + stack = new TQWidgetStack(this); + topL->addWidget(stack); + + dummyLabel = new TQLabel(i18n("Select an action."), stack); + stack->addWidget(dummyLabel, 0); + + // init widget stack and the types combo box + int index = 1; + types->insertItem(TQString()); + TQStringList l = ActionBase::userNames(); + for ( TQStringList::Iterator it = l.begin(); it != l.end(); ++it ) { + TQString name = *it; + int feature = ActionBase::getTypeForUserName(name); + if (manager->hasFeature(feature)) { + types->insertItem(name); + TQWidget *w=0; + switch (feature) { + case ActionBase::SETSCORE: + w = scoreEditor = new KIntSpinBox(-99999,99999,1,0,10, stack); + break; + case ActionBase::NOTIFY: + w = notifyEditor = new KLineEdit(stack); + break; + case ActionBase::COLOR: + w = colorEditor = new KColorCombo(stack); + break; + case ActionBase::MARKASREAD: + w = new TQLabel( stack ); // empty dummy + break; + } + if ( w ) + stack->addWidget(w,index++); + } + } + + connect(types,TQT_SIGNAL(activated(int)),stack,TQT_SLOT(raiseWidget(int))); + + // raise the dummy label + types->setCurrentItem(0); + stack->raiseWidget(dummyLabel); +} + +SingleActionWidget::~SingleActionWidget() +{ +} + +void SingleActionWidget::setAction(ActionBase *act) +{ + kdDebug(5100) << "SingleActionWidget::setAction()" << endl; + setCurrentItem(types,ActionBase::userName(act->getType())); + int index = types->currentItem(); + stack->raiseWidget(index); + switch (act->getType()) { + case ActionBase::SETSCORE: + scoreEditor->setValue(act->getValueString().toInt()); + break; + case ActionBase::NOTIFY: + notifyEditor->setText(act->getValueString()); + break; + case ActionBase::COLOR: + colorEditor->setColor(TQColor(act->getValueString())); + break; + case ActionBase::MARKASREAD: + // nothing + break; + default: + kdWarning(5100) << "unknown action type in SingleActionWidget::setAction()" << endl; + } +} + +ActionBase* SingleActionWidget::createAction() const +{ + // no action selected... + if (types->currentText().isEmpty()) + return 0; + + int type = ActionBase::getTypeForUserName(types->currentText()); + switch (type) { + case ActionBase::SETSCORE: + return new ActionSetScore(scoreEditor->value()); + case ActionBase::NOTIFY: + return new ActionNotify(notifyEditor->text()); + case ActionBase::COLOR: + return new ActionColor(TQString(colorEditor->color().name())); + case ActionBase::MARKASREAD: + return new ActionMarkAsRead(); + default: + kdWarning(5100) << "unknown action type in SingleActionWidget::getValue()" << endl; + return 0; + } +} + +void SingleActionWidget::clear() +{ + if (scoreEditor) scoreEditor->setValue(0); + if (notifyEditor) notifyEditor->clear(); + if (colorEditor) colorEditor->setCurrentItem(0); + types->setCurrentItem(0); + stack->raiseWidget(dummyLabel); +} + +//============================================================================ +// +// class ActionEditWidget (the widget to edit the actions of a rule) +// +//============================================================================ +ActionEditWidget::ActionEditWidget(KScoringManager *m,TQWidget *p, const char *n) + : KWidgetLister(1,8,p,n), manager(m) +{ + // create one initial widget + addWidgetAtEnd(); +} + +ActionEditWidget::~ActionEditWidget() +{} + +TQWidget* ActionEditWidget::createWidget( TQWidget *parent ) +{ + return new SingleActionWidget(manager,parent); +} + +void ActionEditWidget::slotEditRule(KScoringRule *rule) +{ + KScoringRule::ActionList l; + if (rule) l = rule->getActions(); + if (!rule || l.count() == 0) { + slotClear(); + } else { + setNumberOfShownWidgetsTo(l.count()); + ActionBase *act = l.first(); + SingleActionWidget *saw = static_cast(mWidgetList.first()); + while (act && saw) { + saw->setAction(act); + act = l.next(); + saw = static_cast(mWidgetList.next()); + } + } +} + +void ActionEditWidget::updateRule(KScoringRule *rule) +{ + rule->cleanActions(); + for(TQWidget *w = mWidgetList.first(); w; w = mWidgetList.next()) { + if (! w->isA("SingleActionWidget")) { + kdWarning(5100) << "there is a widget in ActionEditWidget " + << "which isn't a SingleActionWidget" << endl; + } else { + SingleActionWidget *saw = dynamic_cast(w); + if (saw) + { + ActionBase *act = saw->createAction(); + if (act) + rule->addAction(act); + } + } + } +} + +void ActionEditWidget::clearWidget(TQWidget *w) +{ + Q_ASSERT( w->isA("SingleActionWidget") ); + SingleActionWidget *sw = dynamic_cast(w); + if (sw) + sw->clear(); +} + +//============================================================================ +// +// class RuleEditWidget (the widget to edit one rule) +// +//============================================================================ +RuleEditWidget::RuleEditWidget(KScoringManager *m,TQWidget *p, const char *n) + : TQWidget(p,n), dirty(false), manager(m), oldRuleName(TQString()) +{ + kdDebug(5100) << "RuleEditWidget::RuleEditWidget()" << endl; + if ( !n ) setName( "RuleEditWidget" ); + TQVBoxLayout *topLayout = new TQVBoxLayout( this, 5, KDialog::spacingHint() ); + + //------------- Name, Servers, Groups --------------------- + TQGroupBox *groupB = new TQGroupBox(i18n("Properties"),this); + topLayout->addWidget(groupB); + TQGridLayout* groupL = new TQGridLayout(groupB, 6,2, 8,5); + groupL->addRowSpacing(0, fontMetrics().lineSpacing()-4); + + // name + ruleNameEdit = new KLineEdit( groupB, "ruleNameEdit" ); + groupL->addWidget( ruleNameEdit, 1, 1 ); + TQLabel *ruleNameLabel = new TQLabel(ruleNameEdit, i18n("&Name:"), groupB, "ruleNameLabel"); + groupL->addWidget( ruleNameLabel, 1, 0 ); + + // groups + groupsEdit = new KLineEdit( groupB, "groupsEdit" ); + groupL->addWidget( groupsEdit, 2, 1 ); + TQLabel *groupsLabel = new TQLabel(groupsEdit, i18n("&Groups:"), groupB, "groupsLabel"); + groupL->addWidget( groupsLabel, 2, 0 ); + + TQPushButton *groupsBtn = new TQPushButton(i18n("A&dd Group"), groupB); + connect(groupsBtn,TQT_SIGNAL(clicked()),TQT_SLOT(slotAddGroup())); + groupL->addWidget( groupsBtn, 3, 0 ); + + groupsBox = new KComboBox( false, groupB, "groupsBox" ); + groupsBox->setDuplicatesEnabled(false); + groupsBox->insertStringList(manager->getGroups()); + groupsBox->tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed)); + groupL->addWidget( groupsBox, 3, 1 ); + + // expires + expireCheck = new TQCheckBox(i18n("&Expire rule automatically"), groupB); + groupL->addMultiCellWidget( expireCheck, 4,4, 0,1 ); + expireEdit = new KIntSpinBox(1,99999,1,30,10, groupB, "expireWidget"); + //Init suffix + slotExpireEditChanged(30); + connect(expireEdit, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotExpireEditChanged(int))); + groupL->addWidget( expireEdit, 5, 1 ); + expireLabel = new TQLabel(expireEdit, i18n("&Rule is valid for:"), groupB, "expireLabel"); + groupL->addWidget( expireLabel, 5, 0 ); + expireLabel->setEnabled(false); + expireEdit->setEnabled(false); + + connect(expireCheck, TQT_SIGNAL(toggled(bool)), expireLabel, TQT_SLOT(setEnabled(bool))); + connect(expireCheck, TQT_SIGNAL(toggled(bool)), expireEdit, TQT_SLOT(setEnabled(bool))); + + //------------- Conditions --------------------- + TQGroupBox *groupConds = new TQGroupBox(i18n("Conditions"), this); + topLayout->addWidget(groupConds); + TQGridLayout *condL = new TQGridLayout(groupConds, 3,2, 8,5); + + condL->addRowSpacing(0, fontMetrics().lineSpacing()-4); + + TQButtonGroup *buttonGroup = new TQButtonGroup(groupConds); + buttonGroup->hide(); + linkModeAnd = new TQRadioButton(i18n("Match a&ll conditions"), groupConds); + buttonGroup->insert(linkModeAnd); + condL->addWidget(linkModeAnd, 1,0); + linkModeOr = new TQRadioButton(i18n("Matc&h any condition"), groupConds); + buttonGroup->insert(linkModeOr); + condL->addWidget(linkModeOr, 1,1); + linkModeAnd->setChecked(true); + + condEditor = new ConditionEditWidget(manager,groupConds); + condL->addMultiCellWidget(condEditor, 2,2, 0,1); + connect(condEditor,TQT_SIGNAL(widgetRemoved()),this,TQT_SLOT(slotShrink())); + + //------------- Actions --------------------- + TQGroupBox *groupActions = new TQGroupBox(i18n("Actions"), this); + topLayout->addWidget(groupActions); + TQBoxLayout *actionL = new TQVBoxLayout(groupActions,8,5); + actionL->addSpacing(fontMetrics().lineSpacing()-4); + actionEditor = new ActionEditWidget(manager,groupActions); + actionL->addWidget(actionEditor); + connect(actionEditor,TQT_SIGNAL(widgetRemoved()),this,TQT_SLOT(slotShrink())); + + topLayout->addStretch(1); + + kdDebug(5100) << "constructed RuleEditWidget" << endl; +} + +RuleEditWidget::~RuleEditWidget() +{ +} + +void RuleEditWidget::slotEditRule(const TQString& ruleName) +{ + kdDebug(5100) << "RuleEditWidget::slotEditRule(" << ruleName << ")" << endl; +// // first update the old rule if there is one +// kdDebug(5100) << "let see if we have a rule with name " << oldRuleName << endl; +// KScoringRule *rule; +// if (!oldRuleName.isNull() && oldRuleName != ruleName) { +// rule = manager->findRule(oldRuleName); +// if (rule) { +// kdDebug(5100) << "updating rule " << rule->getName() << endl; +// updateRule(rule); +// } +// } + + KScoringRule* rule = manager->findRule(ruleName); + if (!rule) { + kdDebug(5100) << "no rule for ruleName " << ruleName << endl; + clearContents(); + return; + } + oldRuleName = rule->getName(); + ruleNameEdit->setText(rule->getName()); + groupsEdit->setText(rule->getGroups().join(";")); + + bool b = rule->getExpireDate().isValid(); + expireCheck->setChecked(b); + expireEdit->setEnabled(b); + expireLabel->setEnabled(b); + if (b) + expireEdit->setValue(TQDate::tqcurrentDate().daysTo(rule->getExpireDate())); + else + expireEdit->setValue(30); + if (rule->getLinkMode() == KScoringRule::AND) { + linkModeAnd->setChecked(true); + } + else { + linkModeOr->setChecked(true); + } + + condEditor->slotEditRule(rule); + actionEditor->slotEditRule(rule); + + kdDebug(5100) << "RuleEditWidget::slotEditRule() ready" << endl; +} + +void RuleEditWidget::clearContents() +{ + ruleNameEdit->setText(""); + groupsEdit->setText(""); + expireCheck->setChecked(false); + expireEdit->setValue(30); + expireEdit->setEnabled(false); + condEditor->slotEditRule(0); + actionEditor->slotEditRule(0); + oldRuleName = TQString(); +} + +void RuleEditWidget::updateRule(KScoringRule *rule) +{ + oldRuleName = TQString(); + TQString groups = groupsEdit->text(); + if (groups.isEmpty()) + rule->setGroups(TQStringList(".*")); + else + rule->setGroups(TQStringList::split(";",groups)); + bool b = expireCheck->isChecked(); + if (b) + rule->setExpireDate(TQDate::tqcurrentDate().addDays(expireEdit->value())); + else + rule->setExpireDate(TQDate()); + actionEditor->updateRule(rule); + rule->setLinkMode(linkModeAnd->isChecked()?KScoringRule::AND:KScoringRule::OR); + condEditor->updateRule(rule); + if (rule->getName() != ruleNameEdit->text()) + manager->setRuleName(rule,ruleNameEdit->text()); +} + +void RuleEditWidget::updateRule() +{ + KScoringRule *rule = manager->findRule(oldRuleName); + if (rule) updateRule(rule); +} + +void RuleEditWidget::slotAddGroup() +{ + TQString grp = groupsBox->currentText(); + if ( grp.isEmpty() ) + return; + TQString txt = groupsEdit->text().stripWhiteSpace(); + if ( txt == ".*" || txt.isEmpty() ) groupsEdit->setText(grp); + else groupsEdit->setText(txt + ";" + grp); +} + +void RuleEditWidget::setDirty() +{ + kdDebug(5100) << "RuleEditWidget::setDirty()" << endl; + if (dirty) return; + dirty = true; +} + +void RuleEditWidget::slotShrink() +{ + emit(shrink()); +} + +void RuleEditWidget::slotExpireEditChanged(int value) +{ + expireEdit->setSuffix(i18n(" day", " days", value)); +} + +//============================================================================ +// +// class RuleListWidget (the widget for managing a list of rules) +// +//============================================================================ +RuleListWidget::RuleListWidget(KScoringManager *m, bool standalone, TQWidget *p, const char *n) + : TQWidget(p,n), alone(standalone), manager(m) +{ + kdDebug(5100) << "RuleListWidget::RuleListWidget()" << endl; + if (!n) setName("RuleListWidget"); + TQVBoxLayout *topL = new TQVBoxLayout(this,standalone? 0:5,KDialog::spacingHint()); + ruleList = new KListBox(this); + if (standalone) { + connect(ruleList,TQT_SIGNAL(doubleClicked(TQListBoxItem*)), + this,TQT_SLOT(slotEditRule(TQListBoxItem*))); + connect(ruleList,TQT_SIGNAL(returnPressed(TQListBoxItem*)), + this,TQT_SLOT(slotEditRule(TQListBoxItem*))); + } + connect(ruleList, TQT_SIGNAL(currentChanged(TQListBoxItem*)), + this, TQT_SLOT(slotRuleSelected(TQListBoxItem*))); + topL->addWidget(ruleList); + + TQHBoxLayout *btnL = new TQHBoxLayout( topL, KDialog::spacingHint() ); + mRuleUp = new TQPushButton( this ); + mRuleUp->setPixmap( BarIcon( "up", KIcon::SizeSmall ) ); + TQToolTip::add( mRuleUp, i18n("Move rule up") ); + btnL->addWidget( mRuleUp ); + connect( mRuleUp, TQT_SIGNAL( clicked() ), TQT_SLOT( slotRuleUp() ) ); + mRuleDown = new TQPushButton( this ); + mRuleDown->setPixmap( BarIcon( "down", KIcon::SizeSmall ) ); + TQToolTip::add( mRuleDown, i18n("Move rule down") ); + btnL->addWidget( mRuleDown ); + connect( mRuleDown, TQT_SIGNAL( clicked() ), TQT_SLOT( slotRuleDown() ) ); + + btnL = new TQHBoxLayout( topL, KDialog::spacingHint() ); + editRule=0L; + newRule = new TQPushButton(this); + newRule->setPixmap( BarIcon( "filenew", KIcon::SizeSmall ) ); + TQToolTip::add(newRule,i18n("New rule")), + btnL->addWidget(newRule); + connect(newRule, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotNewRule())); + // if we're standalone, we need an additional edit button + if (standalone) { + editRule = new TQPushButton(this); + editRule->setIconSet( BarIconSet("edit", KIcon::SizeSmall) ); + TQToolTip::add(editRule,i18n("Edit rule")); + btnL->addWidget(editRule); + connect(editRule,TQT_SIGNAL(clicked()),this,TQT_SLOT(slotEditRule())); + } + delRule = new TQPushButton(this); + delRule->setIconSet( BarIconSet( "editdelete", KIcon::SizeSmall ) ); + TQToolTip::add(delRule,i18n("Remove rule")); + btnL->addWidget(delRule); + connect(delRule, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotDelRule())); + copyRule = new TQPushButton(this); + copyRule->setIconSet(BarIconSet("editcopy", KIcon::SizeSmall)); + TQToolTip::add(copyRule,i18n("Copy rule")); + btnL->addWidget(copyRule); + connect(copyRule, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotCopyRule())); + + // the group filter + TQBoxLayout *filterL = new TQVBoxLayout(topL,KDialog::spacingHint()); + KComboBox *filterBox = new KComboBox(this); + TQStringList l = m->getGroups(); + filterBox->insertItem(i18n("")); + filterBox->insertStringList(l); + filterBox->tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed)); + connect(filterBox,TQT_SIGNAL(activated(const TQString&)), + this,TQT_SLOT(slotGroupFilter(const TQString&))); + slotGroupFilter(i18n("")); + TQLabel *lab = new TQLabel(filterBox,i18n("Sho&w only rules for group:"),this); + filterL->addWidget(lab); + filterL->addWidget(filterBox); + + connect(manager,TQT_SIGNAL(changedRules()), + this,TQT_SLOT(updateRuleList())); + connect(manager,TQT_SIGNAL(changedRuleName(const TQString&,const TQString&)), + this,TQT_SLOT(slotRuleNameChanged(const TQString&,const TQString&))); + + updateRuleList(); + updateButton(); +} + +RuleListWidget::~RuleListWidget() +{ +} + +void RuleListWidget::updateButton() +{ + bool state = ruleList->count() > 0; + if(editRule) + editRule->setEnabled(state); + delRule->setEnabled(state); + copyRule->setEnabled(state); + + TQListBoxItem *item = ruleList->item( ruleList->currentItem() ); + if ( item ) { + mRuleUp->setEnabled( item->prev() != 0 ); + mRuleDown->setEnabled( item->next() != 0 ); + } +} + +void RuleListWidget::updateRuleList() +{ + emit leavingRule(); + kdDebug(5100) << "RuleListWidget::updateRuleList()" << endl; + TQString curr = ruleList->currentText(); + ruleList->clear(); + if (group == i18n("")) { + TQStringList l = manager->getRuleNames(); + ruleList->insertStringList(l); + } else { + KScoringManager::ScoringRuleList l = manager->getAllRules(); + for (KScoringRule* rule = l.first(); rule; rule = l.next() ) { + if (rule->matchGroup(group)) ruleList->insertItem(rule->getName()); + } + } + int index = setCurrentItem(ruleList,curr); + if (index <0) { + ruleList->setCurrentItem(0); + slotRuleSelected(ruleList->currentText()); + } + else { + slotRuleSelected(curr); + } +} + +void RuleListWidget::updateRuleList(const KScoringRule *rule) +{ + kdDebug(5100) << "RuleListWidget::updateRuleList(" << rule->getName() << ")" << endl; + TQString name = rule->getName(); + updateRuleList(); + slotRuleSelected(name); +} + +void RuleListWidget::slotRuleNameChanged(const TQString& oldName, const TQString& newName) +{ + int ind = ruleList->currentItem(); + for (uint i=0;icount();++i) + if (ruleList->text(i) == oldName) { + ruleList->changeItem(newName,i); + ruleList->setCurrentItem(ind); + return; + } +} + +void RuleListWidget::slotEditRule(const TQString& s) +{ + emit ruleEdited(s); +} + +void RuleListWidget::slotEditRule() +{ + if (ruleList->currentItem() >= 0) { + emit ruleEdited(ruleList->currentText()); + } + else if (ruleList->count() == 0) + emit ruleEdited(TQString()); +} + +void RuleListWidget::slotEditRule(TQListBoxItem* item) +{ + slotEditRule(item->text()); +} + +void RuleListWidget::slotGroupFilter(const TQString& s) +{ + group = s; + updateRuleList(); +} + +void RuleListWidget::slotRuleSelected(const TQString& ruleName) +{ + emit leavingRule(); + kdDebug(5100) << "RuleListWidget::slotRuleSelected(" << ruleName << ")" << endl; + if (ruleName != ruleList->currentText()) { + setCurrentItem(ruleList,ruleName); + } + updateButton(); + emit ruleSelected(ruleName); +} + +void RuleListWidget::slotRuleSelected(TQListBoxItem *item) +{ + if (!item) return; + TQString ruleName = item->text(); + slotRuleSelected(ruleName); +} + +void RuleListWidget::slotRuleSelected(int index) +{ + uint idx = index; + if (idx >= ruleList->count()) return; + TQString ruleName = ruleList->text(index); + slotRuleSelected(ruleName); +} + +void RuleListWidget::slotNewRule() +{ + emit leavingRule(); + KScoringRule *rule = manager->addRule(); + updateRuleList(rule); + if (alone) slotEditRule(rule->getName()); + updateButton(); +} + +void RuleListWidget::slotDelRule() +{ + KScoringRule *rule = manager->findRule(ruleList->currentText()); + if (rule) + manager->deleteRule(rule); + // goto the next rule + if (!alone) slotEditRule(); + updateButton(); +} + +void RuleListWidget::slotCopyRule() +{ + emit leavingRule(); + TQString ruleName = ruleList->currentText(); + KScoringRule *rule = manager->findRule(ruleName); + if (rule) { + KScoringRule *nrule = manager->copyRule(rule); + updateRuleList(nrule); + slotEditRule(nrule->getName()); + } + updateButton(); +} + +void RuleListWidget::slotRuleUp() +{ + KScoringRule *rule = 0, *below = 0; + TQListBoxItem *item = ruleList->item( ruleList->currentItem() ); + if ( item ) { + rule = manager->findRule( item->text() ); + item = item->prev(); + if ( item ) + below = manager->findRule( item->text() ); + } + if ( rule && below ) + manager->moveRuleAbove( rule, below ); + updateRuleList(); + updateButton(); +} + +void RuleListWidget::slotRuleDown() +{ + KScoringRule *rule = 0, *above = 0; + TQListBoxItem *item = ruleList->item( ruleList->currentItem() ); + if ( item ) { + rule = manager->findRule( item->text() ); + item = item->next(); + if ( item ) + above = manager->findRule( item->text() ); + } + if ( rule && above ) + manager->moveRuleBelow( rule, above ); + updateRuleList(); + updateButton(); +} + +//============================================================================ +// +// class KScoringEditor (the score edit dialog) +// +//============================================================================ +KScoringEditor* KScoringEditor::scoreEditor = 0; + +KScoringEditor::KScoringEditor(KScoringManager* m, + TQWidget *parent, const char *name) + : KDialogBase(parent,name,false,i18n("Rule Editor"),Ok|Apply|Cancel,Ok,true), manager(m) +{ + manager->pushRuleList(); + if (!scoreEditor) scoreEditor = this; + kdDebug(5100) << "KScoringEditor::KScoringEditor()" << endl; + if (!name) setName("KScoringEditor"); + // the left side gives an overview about all rules, the right side + // shows a detailed view of an selected rule + TQWidget *w = new TQWidget(this); + setMainWidget(w); + TQHBoxLayout *hbl = new TQHBoxLayout(w,0,spacingHint()); + ruleLister = new RuleListWidget(manager,false,w); + hbl->addWidget(ruleLister); + ruleEditor = new RuleEditWidget(manager,w); + hbl->addWidget(ruleEditor); + connect(ruleLister,TQT_SIGNAL(ruleSelected(const TQString&)), + ruleEditor, TQT_SLOT(slotEditRule(const TQString&))); + connect(ruleLister, TQT_SIGNAL(leavingRule()), + ruleEditor, TQT_SLOT(updateRule())); + connect(ruleEditor, TQT_SIGNAL(shrink()), TQT_SLOT(slotShrink())); + connect(this,TQT_SIGNAL(finished()),TQT_SLOT(slotFinished())); + ruleLister->slotRuleSelected(0); + resize(550, tqsizeHint().height()); +} + +void KScoringEditor::setDirty() +{ + TQPushButton *applyBtn = actionButton(Apply); + applyBtn->setEnabled(true); +} + +KScoringEditor::~KScoringEditor() +{ + scoreEditor = 0; +} + +KScoringEditor* KScoringEditor::createEditor(KScoringManager* m, + TQWidget *parent, const char *name) +{ + if (scoreEditor) return scoreEditor; + else return new KScoringEditor(m,parent,name); +} + +void KScoringEditor::setRule(KScoringRule* r) +{ + kdDebug(5100) << "KScoringEditor::setRule(" << r->getName() << ")" << endl; + TQString ruleName = r->getName(); + ruleLister->slotRuleSelected(ruleName); +} + +void KScoringEditor::slotShrink() +{ + TQTimer::singleShot(5, this, TQT_SLOT(slotDoShrink())); +} + +void KScoringEditor::slotDoShrink() +{ + updateGeometry(); + TQApplication::sendPostedEvents(); + resize(width(),tqsizeHint().height()); +} + +void KScoringEditor::slotApply() +{ + TQString ruleName = ruleLister->currentRule(); + KScoringRule *rule = manager->findRule(ruleName); + if (rule) { + ruleEditor->updateRule(rule); + ruleLister->updateRuleList(rule); + } + manager->removeTOS(); + manager->pushRuleList(); +} + +void KScoringEditor::slotOk() +{ + slotApply(); + manager->removeTOS(); + KDialogBase::slotOk(); + manager->editorReady(); +} + +void KScoringEditor::slotCancel() +{ + manager->popRuleList(); + KDialogBase::slotCancel(); +} + +void KScoringEditor::slotFinished() +{ + delayedDestruct(); +} + +//============================================================================ +// +// class KScoringEditorWidgetDialog (a dialog for the KScoringEditorWidget) +// +//============================================================================ +KScoringEditorWidgetDialog::KScoringEditorWidgetDialog(KScoringManager *m, const TQString& r, TQWidget *p, const char *n) + : KDialogBase(p,n,true,i18n("Edit Rule"), + KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Close, + KDialogBase::Ok,true), + manager(m), ruleName(r) +{ + TQFrame *f = makeMainWidget(); + TQBoxLayout *topL = new TQVBoxLayout(f); + ruleEditor = new RuleEditWidget(manager,f); + connect(ruleEditor, TQT_SIGNAL(shrink()), TQT_SLOT(slotShrink())); + topL->addWidget(ruleEditor); + ruleEditor->slotEditRule(ruleName); + resize(0,0); +} + +void KScoringEditorWidgetDialog::slotApply() +{ + KScoringRule *rule = manager->findRule(ruleName); + if (rule) { + ruleEditor->updateRule(rule); + ruleName = rule->getName(); + } +} + +void KScoringEditorWidgetDialog::slotOk() +{ + slotApply(); + KDialogBase::slotOk(); +} + +void KScoringEditorWidgetDialog::slotShrink() +{ + TQTimer::singleShot(5, this, TQT_SLOT(slotDoShrink())); +} + +void KScoringEditorWidgetDialog::slotDoShrink() +{ + updateGeometry(); + TQApplication::sendPostedEvents(); + resize(width(),tqsizeHint().height()); +} + +//============================================================================ +// +// class KScoringEditorWidget (a reusable widget for config dialog...) +// +//============================================================================ +KScoringEditorWidget::KScoringEditorWidget(KScoringManager *m,TQWidget *p, const char *n) + : TQWidget(p,n), manager(m) +{ + TQBoxLayout *topL = new TQVBoxLayout(this); + ruleLister = new RuleListWidget(manager,true,this); + topL->addWidget(ruleLister); + connect(ruleLister,TQT_SIGNAL(ruleEdited(const TQString&)), + this,TQT_SLOT(slotRuleEdited(const TQString &))); +} + +KScoringEditorWidget::~KScoringEditorWidget() +{ + manager->editorReady(); +} + +void KScoringEditorWidget::slotRuleEdited(const TQString& ruleName) +{ + KScoringEditorWidgetDialog dlg(manager,ruleName,this); + dlg.exec(); + ruleLister->updateRuleList(); +} + +#include "kscoringeditor.moc" diff --git a/libtdepim/kscoringeditor.h b/libtdepim/kscoringeditor.h new file mode 100644 index 000000000..ba0ee190e --- /dev/null +++ b/libtdepim/kscoringeditor.h @@ -0,0 +1,317 @@ +/* + kscoringeditor.h + + Copyright (c) 2001 Mathias Waack + Copyright (C) 2005 by Volker Krause + + Author: Mathias Waack + + 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. + 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, US +*/ + +#ifndef SCOREEDITWIDGET_H +#define SCOREEDITWIDGET_H + +#include +#include +#include +#include + +#include "kwidgetlister.h" + +#include + +class KComboBox; +class KLineEdit; +class KIntSpinBox; +class KListBox; +class TQFrame; +class TQLabel; +class TQListBoxItem; +class TQPushButton; +class TQCheckBox; +class TQRadioButton; + +class KScoringRule; +class KScoringExpression; +class KScoringManager; +class ActionBase; +class KScoringEditor; +class ScoreEditWidget; +class KColorCombo; + +/** this widget implements an editor for one condition. + It is used in ExpressionEditWidget +*/ +class KDE_EXPORT SingleConditionWidget : public TQFrame +{ + Q_OBJECT + TQ_OBJECT + friend class ConditionEditWidget; +public: + SingleConditionWidget(KScoringManager *,TQWidget *p =0, const char *n =0); + ~SingleConditionWidget(); + void setCondition(KScoringExpression*); + KScoringExpression *createCondition() const; + void clear(); + +protected slots: + void toggleRegExpButton( int ); + void showRegExpDialog(); + +private: + /** marks a condition as negated */ + TQCheckBox *neg; + /** list of possible headers */ + KComboBox *headers; + /** list of match types */ + KComboBox *matches; + /** the expression which will be matched */ + KLineEdit *expr; + /** the button to open the regexp-editor */ + TQPushButton *regExpButton; + + KScoringManager *manager; +}; + +/** this widget implements the conditions editor + */ +class ConditionEditWidget: public KWidgetLister +{ + Q_OBJECT + TQ_OBJECT +public: + ConditionEditWidget(KScoringManager *,TQWidget *p =0, const char *n =0); + ~ConditionEditWidget(); + TQWidget* createWidget(TQWidget*); + void updateRule(KScoringRule*); + void clearWidget(TQWidget*); +public slots: + void slotEditRule(KScoringRule*); +private: + KScoringManager *manager; +}; + +/** this widget implements an editor for one action. + It is used in ActionEditWidget +*/ +class SingleActionWidget : public TQWidget +{ + Q_OBJECT + TQ_OBJECT + friend class ActionEditWidget; +public: + SingleActionWidget(KScoringManager *m,TQWidget *p =0, const char *n =0); + ~SingleActionWidget(); + void setAction(ActionBase*); + ActionBase *createAction() const; + void clear(); +private: + /** the list of available action */ + KComboBox *types; + /** the stack of the edit widgets for each action type */ + TQWidgetStack *stack; + /** the notify action editor */ + KLineEdit *notifyEditor; + /** the score acton editor */ + KIntSpinBox *scoreEditor; + /** the color action editor */ + KColorCombo *colorEditor; + /** the dummy label */ + TQLabel *dummyLabel; + + KScoringManager *manager; +}; + +/** this widget implements the action editor + */ +class KDE_EXPORT ActionEditWidget : public KWidgetLister +{ + Q_OBJECT + TQ_OBJECT +public: + ActionEditWidget(KScoringManager *m,TQWidget *p =0, const char *n =0); + ~ActionEditWidget(); + TQWidget* createWidget(TQWidget *parent); + void updateRule(KScoringRule*); + void clearWidget(TQWidget *); +public slots: + void slotEditRule(KScoringRule *); +private: + KScoringManager *manager; +}; + +/** This widget implements the rule editor + */ +class RuleEditWidget : public TQWidget +{ + Q_OBJECT + TQ_OBJECT +public: + RuleEditWidget(KScoringManager *m,TQWidget *p =0, const char *n =0); + ~RuleEditWidget(); +public slots: + void setDirty(); + void slotEditRule(const TQString&); + void updateRule(KScoringRule*); + void updateRule(); +signals: + void shrink(); +protected slots: + void slotAddGroup(); + void slotShrink(); +private slots: + void slotExpireEditChanged(int value); +private: + void clearContents(); + + bool dirty; + /** the name of the rule */ + KLineEdit *ruleNameEdit; + /** the list of groups this rule applies to */ + KLineEdit *groupsEdit; + /** list of all available groups */ + KComboBox *groupsBox; + /** the expire enable */ + TQCheckBox *expireCheck; + /** the label to the expireCheck */ + TQLabel *expireLabel; + /** the expire delay */ + KIntSpinBox *expireEdit; + /** the link modes of the conditions */ + TQRadioButton *linkModeOr, *linkModeAnd; + /** the actions editor */ + ActionEditWidget *actionEditor; + /** the conditions editor */ + ConditionEditWidget *condEditor; + + KScoringManager *manager; + + // the old name of the current rule + TQString oldRuleName; +}; + +/** This widget shows a list of rules with buttons for + copy, delete aso. +*/ +class KDE_EXPORT RuleListWidget : public TQWidget +{ + Q_OBJECT + TQ_OBJECT +public: + RuleListWidget(KScoringManager *m, bool =false, TQWidget *p =0, const char *n =0); + ~RuleListWidget(); + TQString currentRule() const { return ruleList->currentText(); } +protected: + void updateButton(); + +signals: + void ruleSelected(const TQString&); + void ruleEdited(const TQString&); + void leavingRule(); +public slots: + void slotRuleSelected(const TQString&); + void slotRuleSelected(TQListBoxItem *); + void slotRuleSelected(int); + void updateRuleList(); + void updateRuleList(const KScoringRule*); + void slotRuleNameChanged(const TQString&,const TQString&); +protected slots: + void slotGroupFilter(const TQString&); + void slotEditRule(TQListBoxItem*); + void slotEditRule(const TQString&); + void slotEditRule(); + void slotDelRule(); + void slotNewRule(); + void slotCopyRule(); + void slotRuleUp(); + void slotRuleDown(); + +private: + /** the list of rules */ + KListBox *ruleList; + /** the current group */ + TQString group; + /** marks if we're alone or together with the edit widget */ + bool alone; + + KScoringManager *manager; + + TQPushButton *editRule; + TQPushButton *newRule; + TQPushButton *delRule; + TQPushButton *copyRule; + TQPushButton *mRuleUp; + TQPushButton *mRuleDown; +}; + +class KDE_EXPORT KScoringEditor : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT +public: + ~KScoringEditor(); + void setRule(KScoringRule*); + static KScoringEditor *createEditor(KScoringManager* m, TQWidget *parent=0, const char *name=0); + static KScoringEditor *editor() { return scoreEditor; } + void setDirty(); +protected: + KScoringEditor(KScoringManager* m, TQWidget *parent=0, const char *name=0); +private: + /** the editor for the current rule */ + RuleEditWidget* ruleEditor; + /** the list of known rules */ + RuleListWidget *ruleLister; +protected slots: + void slotShrink(); + void slotDoShrink(); + void slotApply(); + void slotOk(); + void slotCancel(); + void slotFinished(); +private: + KScoringManager *manager; + ScoreEditWidget *edit; + /** make sure that there is only one instance of ourselve */ + static KScoringEditor *scoreEditor; +}; + +class KScoringEditorWidgetDialog : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT +public: + KScoringEditorWidgetDialog(KScoringManager *m, const TQString& rName, TQWidget *parent=0, const char *name=0); +protected slots: + void slotApply(); + void slotOk(); + void slotShrink(); + void slotDoShrink(); +private: + RuleEditWidget *ruleEditor; + KScoringManager *manager; + TQString ruleName; +}; + +class KDE_EXPORT KScoringEditorWidget : public TQWidget +{ + Q_OBJECT + TQ_OBJECT +public: + KScoringEditorWidget(KScoringManager *m,TQWidget *p =0, const char *n =0); + ~KScoringEditorWidget(); +protected slots: + void slotRuleEdited(const TQString&); +private: + RuleListWidget *ruleLister; + KScoringManager *manager; +}; + + +#endif // SCOREEDITWIDGET_H diff --git a/libtdepim/ksubscription.cpp b/libtdepim/ksubscription.cpp new file mode 100644 index 000000000..b611e1260 --- /dev/null +++ b/libtdepim/ksubscription.cpp @@ -0,0 +1,793 @@ +/* + ksubscription.cpp + + 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. + 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, US +*/ + +#include "ksubscription.h" +#include "kaccount.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +//============================================================================= + +KGroupInfo::KGroupInfo(const TQString &name, const TQString &description, + bool newGroup, bool subscribed, + tqStatus status, TQString path) + : name(name), description(description), + newGroup(newGroup), subscribed(subscribed), + status(status), path(path) +{ +} + +//----------------------------------------------------------------------------- +bool KGroupInfo::operator== (const KGroupInfo &gi2) +{ + return (name == gi2.name); +} + +//----------------------------------------------------------------------------- +bool KGroupInfo::operator< (const KGroupInfo &gi2) +{ + return (name < gi2.name); +} + +//============================================================================= + +GroupItem::GroupItem( TQListView *v, const KGroupInfo &gi, KSubscription* browser, + bool isCheckItem ) + : TQCheckListItem( v, gi.name, isCheckItem ? CheckBox : CheckBoxController ), + mInfo( gi ), mBrowser( browser ), mIsCheckItem( isCheckItem ), + mIgnoreStateChange( false ) +{ + if (listView()->columns() > 1) + setDescription(); +} + +//----------------------------------------------------------------------------- +GroupItem::GroupItem( TQListViewItem *i, const KGroupInfo &gi, KSubscription* browser, + bool isCheckItem ) + : TQCheckListItem( i, gi.name, isCheckItem ? CheckBox : CheckBoxController ), + mInfo( gi ), mBrowser( browser ), mIsCheckItem( isCheckItem ), + mIgnoreStateChange( false ) +{ + if (listView()->columns() > 1) + setDescription(); +} + +//----------------------------------------------------------------------------- +void GroupItem::setInfo( KGroupInfo info ) +{ + mInfo = info; + setText(0, mInfo.name); + if (listView()->columns() > 1) + setDescription(); +} + +//----------------------------------------------------------------------------- +void GroupItem::setDescription() +{ + setText(1, mInfo.description); +} + +//----------------------------------------------------------------------------- +void GroupItem::setOn( bool on ) +{ + if (mBrowser->isLoading()) + { + // set this only if we're loading/creating items + // otherwise changes are only permanent when the dialog is saved + mInfo.subscribed = on; + } + if (isCheckItem()) + TQCheckListItem::setOn(on); +} + +//------------------------------------------------------------------------------ +void GroupItem::stateChange( bool on ) +{ + // delegate to parent + if ( !mIgnoreStateChange ) + mBrowser->changeItemState(this, on); +} + +//------------------------------------------------------------------------------ +void GroupItem::setVisible( bool b ) +{ + if (b) + { + TQListViewItem::setVisible(b); + setEnabled(true); + } + else + { + if (isCheckItem()) + { + bool setInvisible = true; + for (TQListViewItem * lvchild = firstChild(); lvchild != 0; + lvchild = lvchild->nextSibling()) + { + if (lvchild->isVisible()) // item has a visible child + setInvisible = false; + } + if (setInvisible) + TQListViewItem::setVisible(b); + else + { + // leave it visible so that tqchildren remain visible + setOpen(true); + setEnabled(false); + } + } + else + { + // non-checkable item + TQPtrList moveItems; + + for (TQListViewItem * lvchild = firstChild(); lvchild != 0; + lvchild = lvchild->nextSibling()) + { + if (static_cast(lvchild)->isCheckItem()) + { + // remember the items + moveItems.append(lvchild); + } + } + TQPtrListIterator it( moveItems ); + for ( ; it.current(); ++it) + { + // move the checkitem to top + TQListViewItem* parent = it.current()->parent(); + if (parent) parent->takeItem(it.current()); + listView()->insertItem(it.current()); + } + TQListViewItem::setVisible(false); + } + } +} + +//----------------------------------------------------------------------------- +void GroupItem::paintCell( TQPainter * p, const TQColorGroup & cg, + int column, int width, int align ) +{ + if (mIsCheckItem) + return TQCheckListItem::paintCell( p, cg, column, width, align ); + else + return TQListViewItem::paintCell( p, cg, column, width, align ); +} + +//----------------------------------------------------------------------------- +void GroupItem::paintFocus( TQPainter * p, const TQColorGroup & cg, + const TQRect & r ) +{ + if (mIsCheckItem) + TQCheckListItem::paintFocus(p, cg, r); + else + TQListViewItem::paintFocus(p, cg, r); +} + +//----------------------------------------------------------------------------- +int GroupItem::width( const TQFontMetrics& fm, const TQListView* lv, int column) const +{ + if (mIsCheckItem) + return TQCheckListItem::width(fm, lv, column); + else + return TQListViewItem::width(fm, lv, column); +} + +//----------------------------------------------------------------------------- +void GroupItem::setup() +{ + if (mIsCheckItem) + TQCheckListItem::setup(); + else + TQListViewItem::setup(); +} + + +//============================================================================= + +KSubscription::KSubscription( TQWidget *parent, const TQString &caption, + KAccount * acct, int buttons, const TQString &user1, bool descriptionColumn ) + : KDialogBase( parent, 0, true, caption, buttons | Help | Ok | Cancel, Ok, + true, i18n("Reload &List"), user1 ), + mAcct( acct ) +{ + mLoading = true; + setWFlags( getWFlags() | WDestructiveClose ); + + // create Widgets + page = new TQWidget(this); + setMainWidget(page); + + TQLabel *comment = new TQLabel("

"+ + i18n("Manage which mail folders you want to see in your folder view") + "

", page); + + TQToolButton *clearButton = new TQToolButton( page ); + clearButton->setIconSet( KGlobal::iconLoader()->loadIconSet( + KApplication::reverseLayout() ? "clear_left":"locationbar_erase", KIcon::Small, 0 ) ); + filterEdit = new KLineEdit(page); + TQLabel *l = new TQLabel(filterEdit,i18n("S&earch:"), page); + connect( clearButton, TQT_SIGNAL( clicked() ), filterEdit, TQT_SLOT( clear() ) ); + + // checkboxes + noTreeCB = new TQCheckBox(i18n("Disable &tree view"), page); + noTreeCB->setChecked(false); + subCB = new TQCheckBox(i18n("&Subscribed only"), page); + subCB->setChecked(false); + newCB = new TQCheckBox(i18n("&New only"), page); + newCB->setChecked(false); + + + KSeparator *sep = new KSeparator(KSeparator::HLine, page); + + // init the labels + TQFont fnt = font(); + fnt.setBold(true); + leftLabel = new TQLabel(i18n("Loading..."), page); + rightLabel = new TQLabel(i18n("Current changes:"), page); + leftLabel->setFont(fnt); + rightLabel->setFont(fnt); + + // icons + pmRight = BarIconSet("forward"); + pmLeft = BarIconSet("back"); + + arrowBtn1 = new TQPushButton(page); + arrowBtn1->setEnabled(false); + arrowBtn2 = new TQPushButton(page); + arrowBtn2->setEnabled(false); + arrowBtn1->setIconSet(pmRight); + arrowBtn2->setIconSet(pmRight); + arrowBtn1->setFixedSize(35,30); + arrowBtn2->setFixedSize(35,30); + + // the main listview + groupView = new TQListView(page); + groupView->setRootIsDecorated(true); + groupView->addColumn(i18n("Name")); + groupView->setAllColumnsShowFocus(true); + if (descriptionColumn) + mDescrColumn = groupView->addColumn(i18n("Description")); + else + groupView->header()->setStretchEnabled(true, 0); + + // tqlayout + TQGridLayout *topL = new TQGridLayout(page,4,1,0, KDialog::spacingHint()); + TQHBoxLayout *filterL = new TQHBoxLayout(KDialog::spacingHint()); + TQVBoxLayout *arrL = new TQVBoxLayout(KDialog::spacingHint()); + listL = new TQGridLayout(2, 3, KDialog::spacingHint()); + + topL->addWidget(comment, 0,0); + topL->addLayout(filterL, 1,0); + topL->addWidget(sep,2,0); + topL->addLayout(listL, 3,0); + + filterL->addWidget(clearButton); + filterL->addWidget(l); + filterL->addWidget(filterEdit, 1); + filterL->addWidget(noTreeCB); + filterL->addWidget(subCB); + filterL->addWidget(newCB); + + listL->addWidget(leftLabel, 0,0); + listL->addWidget(rightLabel, 0,2); + listL->addWidget(groupView, 1,0); + listL->addLayout(arrL, 1,1); + listL->setRowStretch(1,1); + listL->setColStretch(0,5); + listL->setColStretch(2,2); + + arrL->addWidget(arrowBtn1, AlignCenter); + arrL->addWidget(arrowBtn2, AlignCenter); + + // listviews + subView = new TQListView(page); + subView->addColumn(i18n("Subscribe To")); + subView->header()->setStretchEnabled(true, 0); + unsubView = new TQListView(page); + unsubView->addColumn(i18n("Unsubscribe From")); + unsubView->header()->setStretchEnabled(true, 0); + + TQVBoxLayout *protL = new TQVBoxLayout(3); + listL->addLayout(protL, 1,2); + protL->addWidget(subView); + protL->addWidget(unsubView); + + // disable some widgets as long we're loading + enableButton(User1, false); + enableButton(User2, false); + newCB->setEnabled(false); + noTreeCB->setEnabled(false); + subCB->setEnabled(false); + + filterEdit->setFocus(); + + // items clicked + connect(groupView, TQT_SIGNAL(clicked(TQListViewItem *)), + this, TQT_SLOT(slotChangeButtonState(TQListViewItem*))); + connect(subView, TQT_SIGNAL(clicked(TQListViewItem *)), + this, TQT_SLOT(slotChangeButtonState(TQListViewItem*))); + connect(unsubView, TQT_SIGNAL(clicked(TQListViewItem *)), + this, TQT_SLOT(slotChangeButtonState(TQListViewItem*))); + + // connect buttons + connect(arrowBtn1, TQT_SIGNAL(clicked()), TQT_SLOT(slotButton1())); + connect(arrowBtn2, TQT_SIGNAL(clicked()), TQT_SLOT(slotButton2())); + connect(this, TQT_SIGNAL(user1Clicked()), TQT_SLOT(slotLoadFolders())); + + // connect checkboxes + connect(subCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled())); + connect(newCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled())); + connect(noTreeCB, TQT_SIGNAL(clicked()), TQT_SLOT(slotCBToggled())); + + // connect textfield + connect(filterEdit, TQT_SIGNAL(textChanged(const TQString&)), + TQT_SLOT(slotFilterTextChanged(const TQString&))); + + // update status + connect(this, TQT_SIGNAL(listChanged()), TQT_SLOT(slotUpdateStatusLabel())); +} + +//----------------------------------------------------------------------------- +KSubscription::~KSubscription() +{ +} + +//----------------------------------------------------------------------------- +void KSubscription::setStartItem( const KGroupInfo &info ) +{ + TQListViewItemIterator it(groupView); + + for ( ; it.current(); ++it) + { + if (static_cast(it.current())->info() == info) + { + it.current()->setSelected(true); + it.current()->setOpen(true); + } + } +} + +//----------------------------------------------------------------------------- +void KSubscription::removeListItem( TQListView *view, const KGroupInfo &gi ) +{ + if(!view) return; + TQListViewItemIterator it(view); + + for ( ; it.current(); ++it) + { + if (static_cast(it.current())->info() == gi) + { + delete it.current(); + break; + } + } + if (view == groupView) + emit listChanged(); +} + +//----------------------------------------------------------------------------- +TQListViewItem* KSubscription::getListItem( TQListView *view, const KGroupInfo &gi ) +{ + if(!view) return 0; + TQListViewItemIterator it(view); + + for ( ; it.current(); ++it) + { + if (static_cast(it.current())->info() == gi) + return (it.current()); + } + return 0; +} + +//----------------------------------------------------------------------------- +bool KSubscription::itemInListView( TQListView *view, const KGroupInfo &gi ) +{ + if(!view) return false; + TQListViewItemIterator it(view); + + for ( ; it.current(); ++it) + if (static_cast(it.current())->info() == gi) + return true; + + return false; +} + +//------------------------------------------------------------------------------ +void KSubscription::setDirectionButton1( Direction dir ) +{ + mDirButton1 = dir; + if (dir == Left) + arrowBtn1->setIconSet(pmLeft); + else + arrowBtn1->setIconSet(pmRight); +} + +//------------------------------------------------------------------------------ +void KSubscription::setDirectionButton2( Direction dir ) +{ + mDirButton2 = dir; + if (dir == Left) + arrowBtn2->setIconSet(pmLeft); + else + arrowBtn2->setIconSet(pmRight); +} + +//------------------------------------------------------------------------------ +void KSubscription::changeItemState( GroupItem* item, bool on ) +{ + // is this a checkable item + if (!item->isCheckItem()) return; + + // if we're currently loading the items ignore changes + if (mLoading) return; + if (on) + { + if (!itemInListView(unsubView, item->info())) + { + TQListViewItem *p = item->parent(); + while (p) + { + // make sure all parents are subscribed + GroupItem* pi = static_cast(p); + if (pi->isCheckItem() && !pi->isOn()) + { + pi->setIgnoreStateChange(true); + pi->setOn(true); + pi->setIgnoreStateChange(false); + new GroupItem(subView, pi->info(), this); + } + p = p->parent(); + } + new GroupItem(subView, item->info(), this); + } + // eventually remove it from the other listview + removeListItem(unsubView, item->info()); + } + else { + if (!itemInListView(subView, item->info())) + { + new GroupItem(unsubView, item->info(), this); + } + // eventually remove it from the other listview + removeListItem(subView, item->info()); + } + // update the buttons + slotChangeButtonState(item); +} + +//------------------------------------------------------------------------------ +void KSubscription::filterChanged( TQListViewItem* item, const TQString & text ) +{ + if ( !item && groupView ) + item = groupView->firstChild(); + if ( !item ) + return; + + do + { + if ( item->firstChild() ) // recursive descend + filterChanged(item->firstChild(), text); + + GroupItem* gr = static_cast(item); + if (subCB->isChecked() || newCB->isChecked() || !text.isEmpty() || + noTreeCB->isChecked()) + { + // set it invisible + if ( subCB->isChecked() && + (!gr->isCheckItem() || + (gr->isCheckItem() && !gr->info().subscribed)) ) + { + // only subscribed + gr->setVisible(false); + continue; + } + if ( newCB->isChecked() && + (!gr->isCheckItem() || + (gr->isCheckItem() && !gr->info().newGroup)) ) + { + // only new + gr->setVisible(false); + continue; + } + if ( !text.isEmpty() && + gr->text(0).find(text, 0, false) == -1) + { + // searchfield + gr->setVisible(false); + continue; + } + if ( noTreeCB->isChecked() && + !gr->isCheckItem() ) + { + // disable treeview + gr->setVisible(false); + continue; + } + + gr->setVisible(true); + + } else { + gr->setVisible(true); + } + + } while ((item = item->nextSibling())); + +} + +//------------------------------------------------------------------------------ +uint KSubscription::activeItemCount() +{ + TQListViewItemIterator it(groupView); + + uint count = 0; + for ( ; it.current(); ++it) + { + if (static_cast(it.current())->isCheckItem() && + it.current()->isVisible() && it.current()->isEnabled()) + count++; + } + + return count; +} + +//------------------------------------------------------------------------------ +void KSubscription::restoreOriginalParent() +{ + TQPtrList move; + TQListViewItemIterator it(groupView); + for ( ; it.current(); ++it) + { + TQListViewItem* origParent = static_cast(it.current())-> + originalParent(); + if (origParent && origParent != it.current()->parent()) + { + // remember this to avoid messing up the iterator + move.append(it.current()); + } + } + TQPtrListIterator it2( move ); + for ( ; it2.current(); ++it2) + { + // restore the original parent + TQListViewItem* origParent = static_cast(it2.current())-> + originalParent(); + groupView->takeItem(it2.current()); + origParent->insertItem(it2.current()); + } +} + +//----------------------------------------------------------------------------- +void KSubscription::saveOpenStates() +{ + TQListViewItemIterator it(groupView); + + for ( ; it.current(); ++it) + { + static_cast(it.current())->setLastOpenState( + it.current()->isOpen() ); + } +} + +//----------------------------------------------------------------------------- +void KSubscription::restoreOpenStates() +{ + TQListViewItemIterator it(groupView); + + for ( ; it.current(); ++it) + { + it.current()->setOpen( + static_cast(it.current())->lastOpenState() ); + } +} + +//----------------------------------------------------------------------------- +void KSubscription::slotLoadingComplete() +{ + mLoading = false; + + enableButton(User1, true); + enableButton(User2, true); + newCB->setEnabled(true); + noTreeCB->setEnabled(true); + subCB->setEnabled(true); + + // remember the correct parent + TQListViewItemIterator it(groupView); + for ( ; it.current(); ++it) + { + static_cast(it.current())-> + setOriginalParent( it.current()->parent() ); + } + + emit listChanged(); +} + +//------------------------------------------------------------------------------ +void KSubscription::slotChangeButtonState( TQListViewItem *item ) +{ + if (!item || + (item->listView() == groupView && + !static_cast(item)->isCheckItem())) + { + // disable and return + arrowBtn1->setEnabled(false); + arrowBtn2->setEnabled(false); + return; + } + // set the direction of the buttons and enable/disable them + TQListView* currentView = item->listView(); + if (currentView == groupView) + { + setDirectionButton1(Right); + setDirectionButton2(Right); + if (static_cast(item)->isOn()) + { + // already subscribed + arrowBtn1->setEnabled(false); + arrowBtn2->setEnabled(true); + } else { + // unsubscribed + arrowBtn1->setEnabled(true); + arrowBtn2->setEnabled(false); + } + } else if (currentView == subView) + { + // undo possible + setDirectionButton1(Left); + + arrowBtn1->setEnabled(true); + arrowBtn2->setEnabled(false); + } else if (currentView == unsubView) + { + // undo possible + setDirectionButton2(Left); + + arrowBtn1->setEnabled(false); + arrowBtn2->setEnabled(true); + } +} + +//------------------------------------------------------------------------------ +void KSubscription::slotButton1() +{ + if (mDirButton1 == Right) + { + if (groupView->currentItem() && + static_cast(groupView->currentItem())->isCheckItem()) + { + // activate + GroupItem* item = static_cast(groupView->currentItem()); + item->setOn(true); + } + } + else { + if (subView->currentItem()) + { + GroupItem* item = static_cast(subView->currentItem()); + // get the corresponding item from the groupView + TQListViewItem* listitem = getListItem(groupView, item->info()); + if (listitem) + { + // deactivate + GroupItem* chk = static_cast(listitem); + chk->setOn(false); + } + } + } +} + +//------------------------------------------------------------------------------ +void KSubscription::slotButton2() +{ + if (mDirButton2 == Right) + { + if (groupView->currentItem() && + static_cast(groupView->currentItem())->isCheckItem()) + { + // deactivate + GroupItem* item = static_cast(groupView->currentItem()); + item->setOn(false); + } + } + else { + if (unsubView->currentItem()) + { + GroupItem* item = static_cast(unsubView->currentItem()); + // get the corresponding item from the groupView + TQListViewItem* listitem = getListItem(groupView, item->info()); + if (listitem) + { + // activate + GroupItem* chk = static_cast(listitem); + chk->setOn(true); + } + } + } +} + +//------------------------------------------------------------------------------ +void KSubscription::slotCBToggled() +{ + if (!noTreeCB->isChecked() && !newCB->isChecked() && !subCB->isChecked()) + { + restoreOriginalParent(); + } + // set items {in}visible + filterChanged(groupView->firstChild()); + emit listChanged(); +} + +//------------------------------------------------------------------------------ +void KSubscription::slotFilterTextChanged( const TQString & text ) +{ + // remember is the items are open + if (mLastText.isEmpty()) + saveOpenStates(); + + if (!mLastText.isEmpty() && text.length() < mLastText.length()) + { + // reset + restoreOriginalParent(); + TQListViewItemIterator it(groupView); + for ( ; it.current(); ++it) + { + it.current()->setVisible(true); + it.current()->setEnabled(true); + } + } + // set items {in}visible + filterChanged(groupView->firstChild(), text); + // restore the open-states + if (text.isEmpty()) + restoreOpenStates(); + + emit listChanged(); + mLastText = text; +} + +//------------------------------------------------------------------------------ +void KSubscription::slotUpdateStatusLabel() +{ + TQString text; + if (mLoading) + text = i18n("Loading... (1 matching)", "Loading... (%n matching)", + activeItemCount()); + else + text = i18n("%1: (1 matching)", "%1: (%n matching)", activeItemCount()) + .tqarg(account()->name()); + + leftLabel->setText(text); +} + +//------------------------------------------------------------------------------ +void KSubscription::slotLoadFolders() +{ + enableButton(User1, false); + mLoading = true; + subView->clear(); + unsubView->clear(); + groupView->clear(); +} + +#include "ksubscription.moc" diff --git a/libtdepim/ksubscription.h b/libtdepim/ksubscription.h new file mode 100644 index 000000000..c819701d1 --- /dev/null +++ b/libtdepim/ksubscription.h @@ -0,0 +1,382 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2002 Carsten Burghardt + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/** @file +* This file defines a generic subscription widget and some support classes. +*/ + +#ifndef __KSUBSCRIPTION +#define __KSUBSCRIPTION + +#include +#include + +#include +#include +#include "kfoldertree.h" + +class KSubscription; + +class KLineEdit; +class TQLayout; +class TQLabel; +class TQGridLayout; +class KAccount; + +//========================================================================== + +class KDE_EXPORT KGroupInfo +{ + public: + enum tqStatus { + unknown, + readOnly, + postingAllowed, + moderated + }; + + KGroupInfo( const TQString &name, const TQString &description = TQString(), + bool newGroup = false, bool subscribed = false, + tqStatus status = unknown, TQString path = TQString() ); + + TQString name, description; + bool newGroup, subscribed; + tqStatus status; + TQString path; + + bool operator== (const KGroupInfo &gi2); + bool operator< (const KGroupInfo &gi2); + +}; + +//========================================================================== + +/** A class representing a single group item (what's that?) */ +class KDE_EXPORT GroupItem : public TQCheckListItem +{ + public: + GroupItem( TQListView *v, const KGroupInfo &gi, KSubscription* browser, + bool isCheckItem = false ); + GroupItem( TQListViewItem *i, const KGroupInfo &gi, KSubscription* browser, + bool isCheckItem = false ); + + /** + * Get/Set the KGroupInfo + */ + KGroupInfo info() { return mInfo; } + void setInfo( KGroupInfo info ); + + /** + * Get/Set the original parent + */ + TQListViewItem* originalParent() { return mOriginalParent; } + void setOriginalParent( TQListViewItem* parent ) { mOriginalParent = parent; } + + /** + * Get/Set the last open state + */ + bool lastOpenState() { return mLastOpenState; } + void setLastOpenState( bool last ) { mLastOpenState = last; } + + /** + * Sets the description from the KGroupInfo + * Reimplement this for special cases + */ + virtual void setDescription(); + + /** + * Get if this is a checkable item + */ + bool isCheckItem() const { return mIsCheckItem; } + + /** + * Get/Set if state changes should be ignored + */ + bool ignoreStateChange() { return mIgnoreStateChange; } + void setIgnoreStateChange( bool ignore ) { mIgnoreStateChange = ignore; } + + /** + * Reimplemented + * Sets the subscribed property (only while items are loaded) + */ + virtual void setOn( bool on ); + + /** + * Reimlemented + * Calls KSubscription::changeItemState if mIgnoreStateChange == false + */ + virtual void stateChange( bool on ); + + /** + * Reimplemented + * Sets items invisible or disabled or even moves them + */ + void setVisible( bool b ); + + /** + * Reimplemented + * Calls TQListViewItem or TQCheckListItem + */ + virtual void paintCell( TQPainter * p, const TQColorGroup & cg, + int column, int width, int align ); + + /** + * Reimplemented + * Calls TQListViewItem or TQCheckListItem + */ + virtual void paintFocus( TQPainter *, const TQColorGroup & cg, + const TQRect & r ); + + /** + * Reimplemented + * Calls TQListViewItem or TQCheckListItem + */ + virtual int width( const TQFontMetrics&, const TQListView*, int column) const; + + /** + * Reimplemented + * Calls TQListViewItem or TQCheckListItem + */ + virtual void setup(); + + /** Reimplemented */ + virtual int rtti () const { return 15689; } + + protected: + KGroupInfo mInfo; + KSubscription* mBrowser; + TQListViewItem* mOriginalParent; + // remember last open state + bool mLastOpenState; + // is this a checkable item + bool mIsCheckItem; + // ignore state changes + bool mIgnoreStateChange; +}; + +//========================================================================== + +/** + * This class provides a generic subscription widget + * The dialog itself has a main listview that holds all items and two listviews that + * show all changes. The user can change the state of the items via checkable items. + * When you construct a new instance you need to provide an account and a caption + * After inserting your items (checkable or not) you need to call slotLoadingComplete() + * You should at least connect slots to the signals okClicked() (to save your changes) + * and user1Clicked() (to reload the list) + * You can hide unwanted checkboxes via the respective hide methods + * + */ + +class KDE_EXPORT KSubscription : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT + + public: + /** + * The direction of the buttons + */ + enum Direction { + Left, + Right + }; + + KSubscription( TQWidget *parent, const TQString &caption, KAccount* acct, + int buttons = 0, const TQString &user1 = TQString(), + bool descriptionColumn = true ); + + ~KSubscription(); + + /** + * Get/Set the account + */ + KAccount* account() { return mAcct; } + void setAccount( KAccount * acct ) { mAcct = acct; } + + /** + * Access to the treewidget that holds the GroupItems + */ + TQListView* folderTree() { return groupView; } + + /** + * Access to the searchfield + */ + KLineEdit* searchField() { return filterEdit; } + + /** + * The item that should be selected on startup + */ + void setStartItem( const KGroupInfo &info ); + + /** + * Removes the item from the listview + */ + void removeListItem( TQListView *view, const KGroupInfo &gi ); + + /** + * Gets the item from the listview + * Returns 0 if the item can't be found + */ + TQListViewItem* getListItem( TQListView *view, const KGroupInfo &gi ); + + /** + * Is the item in the given listview + */ + bool itemInListView( TQListView *view, const KGroupInfo &gi ); + + /** + * Makes all changes after an item is toggled + * called by the item's stateChange-method + */ + void changeItemState( GroupItem* item, bool on ); + + /** + * Get/Set the direction of button1 + */ + Direction directionButton1() { return mDirButton1; } + void setDirectionButton1( Direction dir ); + + /** + * Get/Set the direction of button2 + */ + Direction directionButton2() { return mDirButton2; } + void setDirectionButton2( Direction dir ); + + /** + * Returns true if items are being constructed + * Call 'slotLoadingComplete' to switch this + */ + bool isLoading() { return mLoading; } + + /** + * Hide 'Disable tree view' checkbox + */ + void hideTreeCheckbox() { noTreeCB->hide(); } + + /** + * Hide 'New Only' checkbox + */ + void hideNewOnlyCheckbox() { newCB->hide(); } + + /** + * Update the item-states (visible, enabled) when a filter + * criteria changed + */ + void filterChanged( TQListViewItem* item = 0, + const TQString & text = TQString() ); + + /** + * The amount of items that are visible and enabled + */ + uint activeItemCount(); + + /** + * Moves all items from toplevel back to their original position + */ + void restoreOriginalParent(); + + /** + * Saves the open states + */ + void saveOpenStates(); + + /** + * Restores the saved open state + */ + void restoreOpenStates(); + + + public slots: + /** + * Call this slot when you have created all items + */ + void slotLoadingComplete(); + + /** + * Changes the current state of the buttons + */ + void slotChangeButtonState( TQListViewItem* ); + + /** + * Buttons are clicked + */ + void slotButton1(); + void slotButton2(); + + /** + * Updates the status-label + */ + void slotUpdateStatusLabel(); + + /** + * The reload-button is pressed + */ + void slotLoadFolders(); + + protected slots: + /** + * Slot for the checkboxes + */ + void slotCBToggled(); + + /** + * Filter text changed + */ + void slotFilterTextChanged( const TQString & text ); + + signals: + /** + * Emitted when the amount of items in the + * groupView changes (e.g. on filtering) + */ + void listChanged(); + + + protected: + // current account + KAccount* mAcct; + + // widgets + TQWidget *page; + TQListView *groupView; + TQListView *subView, *unsubView; + KLineEdit *filterEdit; + TQCheckBox *noTreeCB, *subCB, *newCB; + TQPushButton *arrowBtn1, *arrowBtn2; + TQIconSet pmRight, pmLeft; + TQGridLayout *listL; + TQLabel *leftLabel, *rightLabel; + + // false if all items are loaded + bool mLoading; + + // directions + Direction mDirButton1; + Direction mDirButton2; + + // remember last searchtext + TQString mLastText; + + // remember description column + int mDescrColumn; +}; + +#endif diff --git a/libtdepim/ktimeedit.cpp b/libtdepim/ktimeedit.cpp new file mode 100644 index 000000000..c968f235c --- /dev/null +++ b/libtdepim/ktimeedit.cpp @@ -0,0 +1,292 @@ +/* + This file is part of libtdepim. + + Copyright (c) 1999 Preston Brown + Copyright (c) 1999 Ian Dawes + Copyright (C) 2003-2004 Reinhold Kainhofer + + 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. + + As a special exception, permission is given to link this program + with any edition of TQt, and distribute the resulting executable, + without including the source code for TQt in the source distribution. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "ktimeedit.h" +#include +#include "ktimeedit.moc" + +// Validator for a time value with only hours and minutes (no seconds) +// Mostly locale aware. Author: David Faure +class KOTimeValidator : public TQValidator +{ +public: + KOTimeValidator(TQWidget* parent, const char* name=0) : TQValidator(TQT_TQOBJECT(parent), name) {} + + virtual State validate(TQString& str, int& /*cursorPos*/) const + { + int length = str.length(); + // empty string is intermediate so one can clear the edit line and start from scratch + if ( length <= 0 ) + return Intermediate; + + bool ok = false; + /*TQTime time =*/ KGlobal::locale()->readTime(str, KLocale::WithoutSeconds, &ok); + if ( ok ) + return Acceptable; +// kdDebug(5300)<<"Time "<= 0 && m < 60 ) + return Intermediate; + } else if ( str[str.length()-1] == sep ) + { + TQString hours = str.left(length-1); + int h = hours.toInt(&ok); + if ( ok && h >= 0 && h < 24 ) + return Intermediate; + } +// return Invalid; + return Intermediate; + } + virtual void fixup ( TQString & input ) const { + bool ok = false; + KGlobal::locale()->readTime( input, KLocale::WithoutSeconds, &ok ); + if ( !ok ) { + // Also try to accept times in "military format", i.e. no delimiter, like 1200 + int tm = input.toInt( &ok ); + if ( ( 0 <= tm ) && ( tm < 2400 ) && ( tm%100 < 60 ) && ok ) { + input = KGlobal::locale()->formatTime( TQTime( tm / 100, tm % 100, 0 ) ); + } + } + } +}; + +// KTimeWidget/TQTimeEdit provide nicer editing, but don't provide a combobox. +// Difficult to get all in one... +// But TQt-3.2 will offer TQLineEdit::setMask, so a "99:99" mask would help. +KTimeEdit::KTimeEdit( TQWidget *parent, TQTime qt, const char *name ) + : TQComboBox( true, parent, name ) +{ + setInsertionPolicy( NoInsertion ); + setValidator( new KOTimeValidator( this ) ); + + mTime = qt; + +// mNoTimeString = i18n("No Time"); +// insertItem( mNoTimeString ); + + // Fill combo box with selection of times in localized format. + TQTime timeEntry(0,0,0); + do { + insertItem(KGlobal::locale()->formatTime(timeEntry)); + timeEntry = timeEntry.addSecs(60*15); + } while (!timeEntry.isNull()); + // Add end of day. + insertItem( KGlobal::locale()->formatTime( TQTime( 23, 59, 59 ) ) ); + + updateText(); + setFocusPolicy(TQ_StrongFocus); + + connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(active(int))); + connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(hilit(int))); + connect(this, TQT_SIGNAL(textChanged(const TQString&)),this,TQT_SLOT(changedText())); +} + +KTimeEdit::~KTimeEdit() +{ +} + +bool KTimeEdit::hasTime() const +{ + // Can't happen + if ( currentText().isEmpty() ) return false; + //if ( currentText() == mNoTimeString ) return false; + + return true; // always +} + +TQTime KTimeEdit::getTime() const +{ + //kdDebug(5300) << "KTimeEdit::getTime(), currentText() = " << currentText() << endl; + // TODO use KLocale::WithoutSeconds in HEAD + bool ok = false; + TQTime time = KGlobal::locale()->readTime( currentText(), KLocale::WithoutSeconds, &ok ); + if ( !ok ) { + // Also try to accept times in "military format", i.e. no delimiter, like 1200 + int tm = currentText().toInt( &ok ); + if ( ( 0 <= tm ) && ( tm < 2400 ) && ( tm%100 < 60 ) && ok ) { + time.setHMS( tm / 100, tm % 100, 0 ); + } else { + ok = false; + } + } + // kdDebug(5300) << "KTimeEdit::getTime(): " << time.toString() << endl; + return time; +} + +TQSizePolicy KTimeEdit::sizePolicy() const +{ + // Set size policy to Fixed, because edit cannot contain more text than the + // string representing the time. It doesn't make sense to provide more space. + TQSizePolicy sizePolicy(TQSizePolicy::Fixed,TQSizePolicy::Fixed); + + return sizePolicy; +} + +void KTimeEdit::setTime(TQTime newTime) +{ + if ( mTime != newTime ) + { + kdDebug(5300) << "KTimeEdit::setTime(): " << TQString(newTime.toString()) << endl; + + mTime = newTime; + updateText(); + } +} + +void KTimeEdit::active(int i) +{ + // The last entry, 23:59, is a special case + if( i == count() - 1 ) + mTime = TQTime( 23, 59, 0 ); + else + mTime = TQTime(0,0,0).addSecs(i*15*60); + emit timeChanged(mTime); +} + +void KTimeEdit::hilit(int ) +{ + // we don't currently need to do anything here. +} + +void KTimeEdit::addTime(TQTime qt) +{ + // Calculate the new time. + mTime = qt.addSecs(mTime.minute()*60+mTime.hour()*3600); + updateText(); + emit timeChanged(mTime); +} + +void KTimeEdit::subTime(TQTime qt) +{ + int h, m; + + // Note that we cannot use the same method for determining the new + // time as we did in addTime, because TQTime does not handle adding + // negative seconds well at all. + h = mTime.hour()-qt.hour(); + m = mTime.minute()-qt.minute(); + + if(m < 0) { + m += 60; + h -= 1; + } + + if(h < 0) { + h += 24; + } + + // store the newly calculated time. + mTime.setHMS(h, m, 0); + updateText(); + emit timeChanged(mTime); +} + +void KTimeEdit::keyPressEvent(TQKeyEvent *qke) +{ + switch(qke->key()) { + case Key_Down: + addTime(TQTime(0,1,0)); + break; + case Key_Up: + subTime(TQTime(0,1,0)); + break; + case Key_Prior: + subTime(TQTime(1,0,0)); + break; + case Key_Next: + addTime(TQTime(1,0,0)); + break; + default: + TQComboBox::keyPressEvent(qke); + break; + } // switch +} + +void KTimeEdit::updateText() +{ +// kdDebug(5300) << "KTimeEdit::updateText() " << endl; + TQString s = KGlobal::locale()->formatTime(mTime); + // Set the text but without emitting signals, nor losing the cursor position + TQLineEdit *line = lineEdit(); + line->blockSignals(true); + int pos = line->cursorPosition(); + + // select item with nearest time, must be done while line edit is blocked + // as setCurrentItem() calls setText() with triggers KTimeEdit::changedText() + setCurrentItem((mTime.hour()*4)+((mTime.minute()+7)/15)); + + line->setText(s); + line->setCursorPosition(pos); + line->blockSignals(false); + +// kdDebug(5300) << "KTimeEdit::updateText(): " << s << endl; +} + +bool KTimeEdit::inputIsValid() const +{ + int cursorPos = lineEdit()->cursorPosition(); + TQString str = currentText(); + return validator()->validate( str, cursorPos ) == TQValidator::Acceptable; +} + +void KTimeEdit::changedText() +{ + //kdDebug(5300) << "KTimeEdit::changedText()" << endl; + if ( inputIsValid() ) + { + mTime = getTime(); + emit timeChanged(mTime); + } +} diff --git a/libtdepim/ktimeedit.h b/libtdepim/ktimeedit.h new file mode 100644 index 000000000..11190842a --- /dev/null +++ b/libtdepim/ktimeedit.h @@ -0,0 +1,96 @@ +/* + This file is part of libtdepim. + + Copyright (c) 1999 Preston Brown + Copyright (c) 1999 Ian Dawes + + 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. + + As a special exception, permission is given to link this program + with any edition of TQt, and distribute the resulting executable, + without including the source code for TQt in the source distribution. +*/ +#ifndef _KTIMEEDIT_H +#define _KTIMEEDIT_H + +#include +#include +#include +#include +#include + +#include +#include + +/** + This is a class that provides an easy, user friendly way to edit times. + up/down/ increase or decrease time, respectively. + + @short Provides a way to edit times in a user-friendly manner. + @author Preston Brown, Ian Dawes +*/ +class KDE_EXPORT KTimeEdit : public TQComboBox +{ + Q_OBJECT + TQ_OBJECT + public: + /** constructs a new time edit. */ + KTimeEdit(TQWidget *parent=0, TQTime qt=TQTime(12,0), const char *name=0); + + virtual ~KTimeEdit(); + + /** + Returns, if a time is selected. Can not return false anymore.... + */ + bool hasTime() const; + + /** returns the time that is currently set in the timeLineEdit. */ + TQTime getTime() const; + + /** returns the preferred size policy of the KTimeEdit */ + TQSizePolicy sizePolicy() const; + + /** return true if input is a valid time and false if not */ + bool inputIsValid() const; + + signals: + /** + Emitted every time the time displayed changes. "newt" is the new + time. + */ + void timeChanged(TQTime newt); + + public slots: + /** used to set the time which is displayed to a specific value. */ + void setTime(TQTime qt); + + protected slots: + void active(int); + void hilit(int); + void changedText(); + + protected: + virtual void keyPressEvent(TQKeyEvent *qke); + void addTime(TQTime qt); + void subTime(TQTime qt); + // Update the lineedit text from mTime + void updateText(); + +private: + TQTime mTime; // the widget's displayed time. + //TQString mNoTimeString; +}; + +#endif diff --git a/libtdepim/kvcarddrag.cpp b/libtdepim/kvcarddrag.cpp new file mode 100644 index 000000000..054a424e9 --- /dev/null +++ b/libtdepim/kvcarddrag.cpp @@ -0,0 +1,101 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kvcarddrag.h" + +#include + +static const char vcard_mime_string[] = "text/x-vcard"; + +#if defined(KABC_VCARD_ENCODING_FIX) +KVCardDrag::KVCardDrag( const TQByteArray &content, TQWidget *dragsource, const char *name ) +#else +KVCardDrag::KVCardDrag( const TQString &content, TQWidget *dragsource, const char *name ) +#endif + : TQStoredDrag( vcard_mime_string, dragsource, name ) +{ + setVCard( content ); +} + +KVCardDrag::KVCardDrag( TQWidget *dragsource, const char *name ) + : TQStoredDrag( vcard_mime_string, dragsource, name ) +{ +#if defined(KABC_VCARD_ENCODING_FIX) + setVCard( TQByteArray() ); +#else + setVCard( TQString() ); +#endif +} + +#if defined(KABC_VCARD_ENCODING_FIX) +void KVCardDrag::setVCard( const TQByteArray &content ) +{ + setEncodedData( content ); +} +#else +void KVCardDrag::setVCard( const TQString &content ) +{ + setEncodedData( content.utf8() ); +} +#endif + +bool KVCardDrag::canDecode( TQMimeSource *e ) +{ + return e->provides( vcard_mime_string ); +} + +#if defined(KABC_VCARD_ENCODING_FIX) +bool KVCardDrag::decode( TQMimeSource *e, TQByteArray &content ) +{ + if ( !canDecode( e ) ) { + return false; + } + content = e->tqencodedData( vcard_mime_string ); + return true; +} +#else +bool KVCardDrag::decode( TQMimeSource *e, TQString &content ) +{ + if ( !canDecode( e ) ) { + return false; + } + content = TQString::fromUtf8( e->tqencodedData( vcard_mime_string ) ); + return true; +} +#endif + +bool KVCardDrag::decode( TQMimeSource *e, KABC::Addressee::List& addressees ) +{ + if ( !canDecode( e ) ) { + return false; + } +#if defined(KABC_VCARD_ENCODING_FIX) + addressees = KABC::VCardConverter().parseVCardsRaw( e->tqencodedData( vcard_mime_string ).data() ); +#else + addressees = KABC::VCardConverter().parseVCards( e->tqencodedData( vcard_mime_string ) ); +#endif + return true; +} + +void KVCardDrag::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "kvcarddrag.moc" diff --git a/libtdepim/kvcarddrag.h b/libtdepim/kvcarddrag.h new file mode 100644 index 000000000..31885f6ad --- /dev/null +++ b/libtdepim/kvcarddrag.h @@ -0,0 +1,95 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KVCARDDRAG_H +#define KVCARDDRAG_H + +#include +#include + +#include +#include // for KABC_VCARD_ENCODING_FIX define +#include + +class KVCardDragPrivate; + +/** + * A drag-and-drop object for vcards. The according MIME type + * is set to text/x-vcard. + * + * See the TQt drag'n'drop documentation. + */ +class KDE_EXPORT KVCardDrag : public TQStoredDrag +{ + Q_OBJECT + TQ_OBJECT + + public: + /** + * Constructs an empty vcard drag. + */ + KVCardDrag( TQWidget *dragsource = 0, const char *name = 0 ); + + /** + * Constructs a vcard drag with the @p addressee. + */ +#if defined(KABC_VCARD_ENCODING_FIX) + KVCardDrag( const TQByteArray &content, TQWidget *dragsource = 0, const char *name = 0 ); +#else + KVCardDrag( const TQString &content, TQWidget *dragsource = 0, const char *name = 0 ); +#endif + virtual ~KVCardDrag() {} + + /** + * Sets the vcard of the drag to @p content. + */ +#if defined(KABC_VCARD_ENCODING_FIX) + void setVCard( const TQByteArray &content ); +#else + void setVCard( const TQString &content ); +#endif + /** + * Returns true if the MIME source @p e contains a vcard object. + */ + static bool canDecode( TQMimeSource *e ); + + /** + * Decodes the MIME source @p e and puts the resulting vcard into @p content. + */ +#if defined(KABC_VCARD_ENCODING_FIX) + static bool decode( TQMimeSource *e, TQByteArray &content ); +#else + static bool decode( TQMimeSource *e, TQString &content ); +#endif + + /** + * Decodes the MIME source @p e and puts the resulting vcard into @p addresseess. + */ + static bool decode( TQMimeSource *e, KABC::Addressee::List& addressees ); + + protected: + virtual void virtual_hook( int id, void* data ); + + private: + KVCardDragPrivate *d; +}; + +#endif // KVCARDDRAG_H diff --git a/libtdepim/kwidgetlister.cpp b/libtdepim/kwidgetlister.cpp new file mode 100644 index 000000000..b2b839f43 --- /dev/null +++ b/libtdepim/kwidgetlister.cpp @@ -0,0 +1,178 @@ +/* -*- c++ -*- + kwidgetlister.cpp + + This file is part of libkdenetwork. + Copyright (c) 2001 Marc Mutz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This library 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 library; 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 library with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 "kwidgetlister.h" + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +KWidgetLister::KWidgetLister( int minWidgets, int maxWidgets, TQWidget *parent, const char* name ) + : TQWidget( parent, name ) +{ + mWidgetList.setAutoDelete(TRUE); + + mMinWidgets = TQMAX( minWidgets, 1 ); + mMaxWidgets = TQMAX( maxWidgets, mMinWidgets + 1 ); + + //--------- the button box + mLayout = new TQVBoxLayout(this, 0, 4); + mButtonBox = new TQHBox(this); + mButtonBox->setSpacing( KDialog::spacingHint() ); + mLayout->addWidget( mButtonBox ); + + mBtnMore = new KPushButton( KGuiItem( i18n( "more widgets", "More" ), "button_more" ), mButtonBox ); + mButtonBox->setStretchFactor( mBtnMore, 0 ); + + mBtnFewer = new KPushButton( KGuiItem( i18n( "fewer widgets", "Fewer" ), "button_fewer" ), mButtonBox ); + mButtonBox->setStretchFactor( mBtnFewer, 0 ); + + TQWidget *spacer = new TQWidget( mButtonBox ); + mButtonBox->setStretchFactor( spacer, 1 ); + + // FIXME: We need a KStdGuiItem::clear here and in other locations to be automagically RTL aware - Martijn + mBtnClear = new KPushButton( KGuiItem( i18n( "clear widgets", "Clear" ), "locationbar_erase" ), mButtonBox ); + mButtonBox->setStretchFactor( mBtnClear, 0 ); + + //---------- connect everything + connect( mBtnMore, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotMore()) ); + connect( mBtnFewer, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotFewer()) ); + connect( mBtnClear, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotClear()) ); + + enableControls(); +} + +KWidgetLister::~KWidgetLister() +{ +} + +void KWidgetLister::slotMore() +{ + // the class should make certain that slotMore can't + // be called when mMaxWidgets are on screen. + assert( (int)mWidgetList.count() < mMaxWidgets ); + + addWidgetAtEnd(); + // adjustSize(); + enableControls(); +} + +void KWidgetLister::slotFewer() +{ + // the class should make certain that slotFewer can't + // be called when mMinWidgets are on screen. + assert( (int)mWidgetList.count() > mMinWidgets ); + + removeLastWidget(); + // adjustSize(); + enableControls(); +} + +void KWidgetLister::slotClear() +{ + setNumberOfShownWidgetsTo( mMinWidgets ); + + // clear remaining widgets + TQPtrListIterator it( mWidgetList ); + for ( it.toFirst() ; it.current() ; ++it ) + clearWidget( (*it) ); + + // adjustSize(); + enableControls(); + emit clearWidgets(); +} + +void KWidgetLister::addWidgetAtEnd(TQWidget *w) +{ + if (!w) w = this->createWidget(this); + + mLayout->insertWidget( mLayout->findWidget( mButtonBox ), w ); + mWidgetList.append( w ); + w->show(); + enableControls(); + emit widgetAdded(); + emit widgetAdded(w); +} + +void KWidgetLister::removeLastWidget() +{ + // The tqlayout will take care that the + // widget is removed from screen, too. + mWidgetList.removeLast(); + enableControls(); + emit widgetRemoved(); +} + +void KWidgetLister::clearWidget( TQWidget* /*aWidget*/ ) +{ +} + +TQWidget* KWidgetLister::createWidget( TQWidget* parent ) +{ + return new TQWidget( parent ); +} + +void KWidgetLister::setNumberOfShownWidgetsTo( int aNum ) +{ + int superfluousWidgets = TQMAX( (int)mWidgetList.count() - aNum, 0 ); + int missingWidgets = TQMAX( aNum - (int)mWidgetList.count(), 0 ); + + // remove superfluous widgets + for ( ; superfluousWidgets ; superfluousWidgets-- ) + removeLastWidget(); + + // add missing widgets + for ( ; missingWidgets ; missingWidgets-- ) + addWidgetAtEnd(); +} + +void KWidgetLister::enableControls() +{ + int count = mWidgetList.count(); + bool isMaxWidgets = ( count >= mMaxWidgets ); + bool isMinWidgets = ( count <= mMinWidgets ); + + mBtnMore->setEnabled( !isMaxWidgets ); + mBtnFewer->setEnabled( !isMinWidgets ); +} + +#include "kwidgetlister.moc" diff --git a/libtdepim/kwidgetlister.h b/libtdepim/kwidgetlister.h new file mode 100644 index 000000000..db993297f --- /dev/null +++ b/libtdepim/kwidgetlister.h @@ -0,0 +1,154 @@ +/* -*- c++ -*- + kwidgetlister.h + + This file is part of libkdenetwork. + Copyright (c) 2001 Marc Mutz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This library 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 library; 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 library with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 _KWIDGETLISTER_H_ +#define _KWIDGETLISTER_H_ + +#include +#include +#include + +class TQPushButton; +class TQVBoxLayout; +class TQHBox; + +/** + @short Widget that manages a list of other widgets (incl. 'more', 'fewer' and 'clear' buttons). + + Simple widget that nonetheless does a lot of the dirty work for + the filter edit widgets (KMSearchPatternEdit and + KMFilterActionEdit). It provides a growable and shrinkable area + where widget may be displayed in rows. Widgets can be added by + hitting the provided 'More' button, removed by the 'Fewer' button + and cleared (e.g. reset, if an derived class implements that and + removed for all but @ref mMinWidgets). + + To use this widget, derive from it with the template changed to + the type of widgets this class should list. Then reimplement @ref + addWidgetAtEnd, @ref removeLastWidget, calling the original + implementation as necessary. Instantiate an object of the class and + put it in your dialog. + + @author Marc Mutz + @see KMSearchPatternEdit::WidgetLister KMFilterActionEdit::WidgetLister + +*/ + +class KDE_EXPORT KWidgetLister : public TQWidget +{ + Q_OBJECT + TQ_OBJECT +public: + KWidgetLister( int minWidgets=1, int maxWidgets=8, TQWidget* parent=0, const char* name=0 ); + virtual ~KWidgetLister(); + +protected slots: + /** Called whenever the user clicks on the 'more' button. + Reimplementations should call this method, because this + implementation does all the dirty work with adding the widgets + to the tqlayout (through @ref addWidgetAtEnd) and enabling/disabling + the control buttons. */ + virtual void slotMore(); + /** Called whenever the user clicks on the 'fewer' button. + Reimplementations should call this method, because this + implementation does all the dirty work with removing the widgets + from the tqlayout (through @ref removeLastWidget) and + enabling/disabling the control buttons. */ + virtual void slotFewer(); + /** Called whenever the user clicks on the 'clear' button. + Reimplementations should call this method, because this + implementation does all the dirty work with removing all but + @ref mMinWidgets widgets from the tqlayout and enabling/disabling + the control buttons. */ + virtual void slotClear(); + + + +protected: + /** Adds a single widget. Doesn't care if there are already @ref + mMaxWidgets on screen and whether it should enable/disable any + controls. It simply does what it is asked to do. You want to + reimplement this method if you want to initialize the the widget + when showing it on screen. Make sure you call this + implementaion, though, since you cannot put the widget on screen + from derived classes (@p mLayout is private). + Make sure the parent of the TQWidget to add is this KWidgetLister. */ + virtual void addWidgetAtEnd(TQWidget *w =0); + /** Removes a single (always the last) widget. Doesn't care if there + are still only @ref mMinWidgets left on screen and whether it + should enable/disable any controls. It simply does what it is + asked to do. You want to reimplement this method if you want to + save the the widget's state before removing it from screen. Make + sure you call this implementaion, though, since you should not + remove the widget from screen from derived classes. */ + virtual void removeLastWidget(); + /** Called to clear a given widget. The default implementation does + nothing. */ + virtual void clearWidget( TQWidget* ); + /** Because QT 2.x does not support signals/slots in template + classes, we are forced to emulate this by forcing the + implementers of subclasses of KWidgetLister to reimplement this + function which replaces the "@p new @p T" call. */ + virtual TQWidget* createWidget( TQWidget *parent ); + /** Sets the number of widgets on scrren to exactly @p aNum. Doesn't + check if @p aNum is inside the range @p + [mMinWidgets,mMaxWidgets]. */ + virtual void setNumberOfShownWidgetsTo( int aNum ); + /** The list of widgets. Note that this list is set to auto-delete, + meaning that widgets that are removed from the screen by either + @ref slotFewer or @ref slotClear will be destroyed! */ + TQPtrList mWidgetList; + /** The minimum number of widgets that are to stay on screen. */ + int mMinWidgets; + /** The maximum number of widgets that are to be shown on screen. */ + int mMaxWidgets; + +signals: + /** This signal is emitted whenever a widget was added */ + void widgetAdded(); + /** This signal is emitted whenever a widget was added */ + void widgetAdded(TQWidget *); + /** This signal is emitted whenever a widget was removed */ + void widgetRemoved(); + /** This signal is emitted whenever the clear button is clicked */ + void clearWidgets(); + +private: + void enableControls(); + + TQPushButton *mBtnMore, *mBtnFewer, *mBtnClear; + TQVBoxLayout *mLayout; + TQHBox *mButtonBox; +}; + + + +#endif /* _KWIDGETLISTER_H_ */ diff --git a/libtdepim/kxface.cpp b/libtdepim/kxface.cpp new file mode 100644 index 000000000..210fefb5f --- /dev/null +++ b/libtdepim/kxface.cpp @@ -0,0 +1,729 @@ +/* + This file is part of libtdepim. + + Original compface: + Copyright (c) James Ashton - Sydney University - June 1990. + + Additions for KDE: + Copyright (c) 2004 Jakob Schröter + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kxface.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#define GEN(g) F[h] ^= G.g[k]; break + +#define BITSPERDIG 4 +#define DIGITS (PIXELS / BITSPERDIG) +#define DIGSPERWORD 4 +#define WORDSPERLINE (WIDTH / DIGSPERWORD / BITSPERDIG) + +/* compressed output uses the full range of printable characters. + * in ascii these are in a contiguous block so we just need to know + * the first and last. The total number of printables is needed too */ +#define FIRSTPRINT '!' +#define LASTPRINT '~' +#define NUMPRINTS (LASTPRINT - FIRSTPRINT + 1) + +/* output line length for compressed data */ +#define MAXLINELEN 78 + +/* Portable, very large unsigned integer arithmetic is needed. + * Implementation uses arrays of WORDs. COMPs must have at least + * twice as many bits as WORDs to handle intermediate results */ +#define COMP unsigned long +#define WORDCARRY (1 << BITSPERWORD) +#define WORDMASK (WORDCARRY - 1) + +#define ERR_OK 0 /* successful completion */ +#define ERR_EXCESS 1 /* completed OK but some input was ignored */ +#define ERR_INSUFF -1 /* insufficient input. Bad face format? */ +#define ERR_INTERNAL -2 /* Arithmetic overflow or buffer overflow */ + +#define BLACK 0 +#define GREY 1 +#define WHITE 2 + +#define MAX_XFACE_LENGTH 2048 + +using namespace KPIM; + +KXFace::KXFace() +{ + NumProbs = 0; +} + +KXFace::~KXFace() +{ +} + +TQString KXFace::fromImage( const TQImage &image ) +{ + if( image.isNull() ) + return TQString(); + + TQImage scaledImg = image.smoothScale( 48, 48 ); + TQByteArray ba; + TQBuffer buffer( ba ); + buffer.open( IO_WriteOnly ); + scaledImg.save( &buffer, "XBM" ); + TQString xbm( ba ); + xbm.remove( 0, xbm.find( "{" ) + 1 ); + xbm.truncate( xbm.find( "}" ) ); + xbm.remove( " " ); + xbm.remove( "," ); + xbm.remove( "0x" ); + xbm.remove( "\n" ); + xbm.truncate( 576 ); + TQCString tmp = TQCString( xbm.latin1() ); + uint len = tmp.length(); + for( uint i=0; i MAX_XFACE_LENGTH ) + return TQImage(); + + char *fbuf = (char *)malloc( MAX_XFACE_LENGTH ); + memset( fbuf, '\0', MAX_XFACE_LENGTH ); + strncpy( fbuf, xface.latin1(), xface.length() ); + TQCString img; + if ( !( status = setjmp( comp_env ) ) ) + { + UnCompAll( fbuf );/* compress otherwise */ + UnGenFace(); + img = WriteFace(); + } + free( fbuf ); + TQImage p; + p.loadFromData( img, "XBM" ); + + return p; +} + +//============================================================================ +// more or less original compface 1.4 source + +void KXFace::RevPush(const Prob *p) +{ + if (NumProbs >= PIXELS * 2 - 1) + longjmp(comp_env, ERR_INTERNAL); + ProbBuf[NumProbs++] = (Prob *) p; +} + +void KXFace::BigPush(Prob *p) +{ + static unsigned char tmp; + + BigDiv(p->p_range, &tmp); + BigMul(0); + BigAdd(tmp + p->p_offset); +} + +int KXFace::BigPop(register const Prob *p) +{ + static unsigned char tmp; + register int i; + + BigDiv(0, &tmp); + i = 0; + while ((tmp < p->p_offset) || (tmp >= p->p_range + p->p_offset)) + { + p++; + i++; + } + BigMul(p->p_range); + BigAdd(tmp - p->p_offset); + return i; +} + + +/* Divide B by a storing the result in B and the remainder in the word + * pointer to by r + */ +void KXFace::BigDiv(register unsigned char a, register unsigned char *r) +{ + register int i; + register unsigned char *w; + register COMP c, d; + + a &= WORDMASK; + if ((a == 1) || (B.b_words == 0)) + { + *r = 0; + return; + } + if (a == 0) /* treat this as a == WORDCARRY */ + { /* and just shift everything right a WORD (unsigned char)*/ + i = --B.b_words; + w = B.b_word; + *r = *w; + while (i--) + { + *w = *(w + 1); + w++; + } + *w = 0; + return; + } + w = B.b_word + (i = B.b_words); + c = 0; + while (i--) + { + c <<= BITSPERWORD; + c += (COMP)*--w; + d = c / (COMP)a; + c = c % (COMP)a; + *w = (unsigned char)(d & WORDMASK); + } + *r = c; + if (B.b_word[B.b_words - 1] == 0) + B.b_words--; +} + +/* Multiply a by B storing the result in B + */ +void KXFace::BigMul(register unsigned char a) +{ + register int i; + register unsigned char *w; + register COMP c; + + a &= WORDMASK; + if ((a == 1) || (B.b_words == 0)) + return; + if (a == 0) /* treat this as a == WORDCARRY */ + { /* and just shift everything left a WORD (unsigned char) */ + if ((i = B.b_words++) >= MAXWORDS - 1) + longjmp(comp_env, ERR_INTERNAL); + w = B.b_word + i; + while (i--) + { + *w = *(w - 1); + w--; + } + *w = 0; + return; + } + i = B.b_words; + w = B.b_word; + c = 0; + while (i--) + { + c += (COMP)*w * (COMP)a; + *(w++) = (unsigned char)(c & WORDMASK); + c >>= BITSPERWORD; + } + if (c) + { + if (B.b_words++ >= MAXWORDS) + longjmp(comp_env, ERR_INTERNAL); + *w = (COMP)(c & WORDMASK); + } +} + +/* Add to a to B storing the result in B + */ +void KXFace::BigAdd(unsigned char a) +{ + register int i; + register unsigned char *w; + register COMP c; + + a &= WORDMASK; + if (a == 0) + return; + i = 0; + w = B.b_word; + c = a; + while ((i < B.b_words) && c) + { + c += (COMP)*w; + *w++ = (unsigned char)(c & WORDMASK); + c >>= BITSPERWORD; + i++; + } + if ((i == B.b_words) && c) + { + if (B.b_words++ >= MAXWORDS) + longjmp(comp_env, ERR_INTERNAL); + *w = (COMP)(c & WORDMASK); + } +} + +void KXFace::BigClear() +{ + B.b_words = 0; +} + +TQCString KXFace::WriteFace() +{ + register char *s; + register int i, j, bits, digits, words; + int digsperword = DIGSPERWORD; + int wordsperline = WORDSPERLINE; + TQCString t( "#define noname_width 48\n#define noname_height 48\nstatic char noname_bits[] = {\n " ); + j = t.length() - 1; + + s = F; + bits = digits = words = i = 0; + t.resize( MAX_XFACE_LENGTH ); + digsperword = 2; + wordsperline = 15; + while ( s < F + PIXELS ) + { + if ( ( bits == 0 ) && ( digits == 0 ) ) + { + t[j++] = '0'; + t[j++] = 'x'; + } + if ( *(s++) ) + i = ( i >> 1 ) | 0x8; + else + i >>= 1; + if ( ++bits == BITSPERDIG ) + { + j++; + t[j-( ( digits & 1 ) * 2 )] = *(i + HexDigits); + bits = i = 0; + if ( ++digits == digsperword ) + { + if ( s >= F + PIXELS ) + break; + t[j++] = ','; + digits = 0; + if ( ++words == wordsperline ) + { + t[j++] = '\n'; + t[j++] = ' '; + words = 0; + } + } + } + } + t.resize( j + 1 ); + t += "};\n"; + return t; +} + +void KXFace::UnCompAll(char *fbuf) +{ + register char *p; + + BigClear(); + BigRead(fbuf); + p = F; + while (p < F + PIXELS) + *(p++) = 0; + UnCompress(F, 16, 16, 0); + UnCompress(F + 16, 16, 16, 0); + UnCompress(F + 32, 16, 16, 0); + UnCompress(F + WIDTH * 16, 16, 16, 0); + UnCompress(F + WIDTH * 16 + 16, 16, 16, 0); + UnCompress(F + WIDTH * 16 + 32, 16, 16, 0); + UnCompress(F + WIDTH * 32, 16, 16, 0); + UnCompress(F + WIDTH * 32 + 16, 16, 16, 0); + UnCompress(F + WIDTH * 32 + 32, 16, 16, 0); +} + +void KXFace::UnCompress(char *f, int wid, int hei, int lev) +{ + switch (BigPop(&levels[lev][0])) + { + case WHITE : + return; + case BLACK : + PopGreys(f, wid, hei); + return; + default : + wid /= 2; + hei /= 2; + lev++; + UnCompress(f, wid, hei, lev); + UnCompress(f + wid, wid, hei, lev); + UnCompress(f + hei * WIDTH, wid, hei, lev); + UnCompress(f + wid + hei * WIDTH, wid, hei, lev); + return; + } +} + +void KXFace::BigWrite(register char *fbuf) +{ + static unsigned char tmp; + static char buf[DIGITS]; + register char *s; + register int i; + + s = buf; + while (B.b_words > 0) + { + BigDiv(NUMPRINTS, &tmp); + *(s++) = tmp + FIRSTPRINT; + } + i = 7; // leave room for the field name on the first line + *(fbuf++) = ' '; + while (s-- > buf) + { + if (i == 0) + *(fbuf++) = ' '; + *(fbuf++) = *s; + if (++i >= MAXLINELEN) + { + *(fbuf++) = '\n'; + i = 0; + } + } + if (i > 0) + *(fbuf++) = '\n'; + *(fbuf++) = '\0'; +} + +void KXFace::BigRead(register char *fbuf) +{ + register int c; + + while (*fbuf != '\0') + { + c = *(fbuf++); + if ((c < FIRSTPRINT) || (c > LASTPRINT)) + continue; + BigMul(NUMPRINTS); + BigAdd((unsigned char)(c - FIRSTPRINT)); + } +} + +void KXFace::ReadFace(char *fbuf) +{ + register int c, i; + register char *s, *t; + + t = s = fbuf; + for(i = strlen(s); i > 0; i--) + { + c = (int)*(s++); + if ((c >= '0') && (c <= '9')) + { + if (t >= fbuf + DIGITS) + { + status = ERR_EXCESS; + break; + } + *(t++) = c - '0'; + } + else if ((c >= 'A') && (c <= 'F')) + { + if (t >= fbuf + DIGITS) + { + status = ERR_EXCESS; + break; + } + *(t++) = c - 'A' + 10; + } + else if ((c >= 'a') && (c <= 'f')) + { + if (t >= fbuf + DIGITS) + { + status = ERR_EXCESS; + break; + } + *(t++) = c - 'a' + 10; + } + else if (((c == 'x') || (c == 'X')) && (t > fbuf) && (*(t-1) == 0)) + t--; + } + if (t < fbuf + DIGITS) + longjmp(comp_env, ERR_INSUFF); + s = fbuf; + t = F; + c = 1 << (BITSPERDIG - 1); + while (t < F + PIXELS) + { + *(t++) = (*s & c) ? 1 : 0; + if ((c >>= 1) == 0) + { + s++; + c = 1 << (BITSPERDIG - 1); + } + } +} + +void KXFace::GenFace() +{ + static char newp[PIXELS]; + register char *f1; + register char *f2; + register int i; + + f1 = newp; + f2 = F; + i = PIXELS; + while (i-- > 0) + *(f1++) = *(f2++); + Gen(newp); +} + +void KXFace::UnGenFace() +{ + Gen(F); +} + +// static +void KXFace::Gen(register char *f) +{ + register int m, l, k, j, i, h; + + for (j = 0; j < HEIGHT; j++) + { + for (i = 0; i < WIDTH; i++) + { + h = i + j * WIDTH; + k = 0; + for (l = i - 2; l <= i + 2; l++) + for (m = j - 2; m <= j; m++) + { + if ((l >= i) && (m == j)) + continue; + if ((l > 0) && (l <= WIDTH) && (m > 0)) + k = *(f + l + m * WIDTH) ? k * 2 + 1 : k * 2; + } + switch (i) + { + case 1 : + switch (j) + { + case 1 : GEN(g_22); + case 2 : GEN(g_21); + default : GEN(g_20); + } + break; + case 2 : + switch (j) + { + case 1 : GEN(g_12); + case 2 : GEN(g_11); + default : GEN(g_10); + } + break; + case WIDTH - 1 : + switch (j) + { + case 1 : GEN(g_42); + case 2 : GEN(g_41); + default : GEN(g_40); + } + break; + /* i runs from 0 to WIDTH-1, so case can never occur. I leave the code in + because it appears exactly like this in the original compface code. + case WIDTH : + switch (j) + { + case 1 : GEN(g_32); + case 2 : GEN(g_31); + default : GEN(g_30); + } + break; + */ + default : + switch (j) + { + case 1 : GEN(g_02); + case 2 : GEN(g_01); + default : GEN(g_00); + } + break; + } + } + } +} + +void KXFace::PopGreys(char *f, int wid, int hei) +{ + if (wid > 3) + { + wid /= 2; + hei /= 2; + PopGreys(f, wid, hei); + PopGreys(f + wid, wid, hei); + PopGreys(f + WIDTH * hei, wid, hei); + PopGreys(f + WIDTH * hei + wid, wid, hei); + } + else + { + wid = BigPop(freqs); + if (wid & 1) + *f = 1; + if (wid & 2) + *(f + 1) = 1; + if (wid & 4) + *(f + WIDTH) = 1; + if (wid & 8) + *(f + WIDTH + 1) = 1; + } +} + +void KXFace::CompAll(char *fbuf) +{ + Compress(F, 16, 16, 0); + Compress(F + 16, 16, 16, 0); + Compress(F + 32, 16, 16, 0); + Compress(F + WIDTH * 16, 16, 16, 0); + Compress(F + WIDTH * 16 + 16, 16, 16, 0); + Compress(F + WIDTH * 16 + 32, 16, 16, 0); + Compress(F + WIDTH * 32, 16, 16, 0); + Compress(F + WIDTH * 32 + 16, 16, 16, 0); + Compress(F + WIDTH * 32 + 32, 16, 16, 0); + BigClear(); + while (NumProbs > 0) + BigPush(ProbBuf[--NumProbs]); + BigWrite(fbuf); +} + +void KXFace::Compress(register char *f, register int wid, register int hei, register int lev) +{ + if (AllWhite(f, wid, hei)) + { + RevPush(&levels[lev][WHITE]); + return; + } + if (AllBlack(f, wid, hei)) + { + RevPush(&levels[lev][BLACK]); + PushGreys(f, wid, hei); + return; + } + RevPush(&levels[lev][GREY]); + wid /= 2; + hei /= 2; + lev++; + Compress(f, wid, hei, lev); + Compress(f + wid, wid, hei, lev); + Compress(f + hei * WIDTH, wid, hei, lev); + Compress(f + wid + hei * WIDTH, wid, hei, lev); +} + +int KXFace::AllWhite(char *f, int wid, int hei) +{ + return ((*f == 0) && Same(f, wid, hei)); +} + +int KXFace::AllBlack(char *f, int wid, int hei) +{ + if (wid > 3) + { + wid /= 2; + hei /= 2; + return (AllBlack(f, wid, hei) && AllBlack(f + wid, wid, hei) && + AllBlack(f + WIDTH * hei, wid, hei) && + AllBlack(f + WIDTH * hei + wid, wid, hei)); + } + else + return (*f || *(f + 1) || *(f + WIDTH) || *(f + WIDTH + 1)); +} + +int KXFace::Same(register char *f, register int wid, register int hei) +{ + register char val, *row; + register int x; + + val = *f; + while (hei--) + { + row = f; + x = wid; + while (x--) + if (*(row++) != val) + return(0); + f += WIDTH; + } + return 1; +} + +void KXFace::PushGreys(char *f, int wid, int hei) +{ + if (wid > 3) + { + wid /= 2; + hei /= 2; + PushGreys(f, wid, hei); + PushGreys(f + wid, wid, hei); + PushGreys(f + WIDTH * hei, wid, hei); + PushGreys(f + WIDTH * hei + wid, wid, hei); + } + else + RevPush(freqs + *f + 2 * *(f + 1) + 4 * *(f + WIDTH) + + 8 * *(f + WIDTH + 1)); +} + + +#include "kxface.moc" diff --git a/libtdepim/kxface.h b/libtdepim/kxface.h new file mode 100644 index 000000000..770232306 --- /dev/null +++ b/libtdepim/kxface.h @@ -0,0 +1,594 @@ +/* + This file is part of libtdepim. + + Original compface: + Copyright (c) James Ashton - Sydney University - June 1990. + + Additions for KDE: + Copyright (c) 2004 Jakob Schröter + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KXFACE_H +#define __KXFACE_H + + +#include +#include + +#include + +// #define WIDTH 48 +// #define HEIGHT WIDTH + +/* total number of pixels and digits */ +// #define PIXELS (WIDTH * HEIGHT) +// #define WORD unsigned char +// #define MAXWORDS ((PIXELS * 2 + BITSPERWORD - 1) / BITSPERWORD) +// #define BITSPERWORD 8 + + +typedef struct guesses +{ + char g_00[1<<12]; + char g_01[1<<7]; + char g_02[1<<2]; + char g_10[1<<9]; + char g_20[1<<6]; + char g_30[1<<8]; + char g_40[1<<10]; + char g_11[1<<5]; + char g_21[1<<3]; + char g_31[1<<5]; + char g_41[1<<6]; + char g_12[1<<1]; + char g_22[1<<0]; + char g_32[1<<2]; + char g_42[1<<2]; +} Guesses; + +static const Guesses G = +{ + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, + 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, + 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, + 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, + 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, + 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, + 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, + 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, + 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, + 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, + 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, + 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, + 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, + 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, + 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, + 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, + 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, + 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, + 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + }, + { + 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, + 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, + 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + }, + { + 0, 1, 0, 1, + }, + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, + 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, + 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, + 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, + 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + }, + { + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, + }, + { + 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, + 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, + }, + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, + 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, + 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + }, + { + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, + 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + }, + { + 0, 0, 0, 1, 0, 1, 1, 1, + }, + { + 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, + 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + }, + { + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + }, + { + 0, 1, + }, + { + 0, + }, + { + 0, 0, 0, 1, + }, + { + 0, 0, 0, 1, + } +}; + +typedef struct prob +{ + int p_range; + int p_offset; +} Prob; + + + +static const Prob levels[4][3] = { + {{1, 255}, {251, 0}, {4, 251}}, /* Top of tree almost always grey */ + {{1, 255}, {200, 0}, {55, 200}}, + {{33, 223}, {159, 0}, {64, 159}}, + {{131, 0}, {0, 0}, {125, 131}} /* Grey disallowed at bottom */ +}; + +static const Prob freqs[16] = { + {0, 0}, {38, 0}, {38, 38}, {13, 152}, + {38, 76}, {13, 165}, {13, 178}, {6, 230}, + {38, 114}, {13, 191}, {13, 204}, {6, 236}, + {13, 217}, {6, 242}, {5, 248}, {3, 253} +}; + +static const char HexDigits[] = "0123456789ABCDEF"; + + +class TQImage; +class TQString; + +namespace KPIM { + + class KDE_EXPORT KXFace : public TQObject + { + Q_OBJECT + TQ_OBJECT + + public: + KXFace(); + virtual ~KXFace(); + + /** + * generates the xface string from @p image + */ + TQString fromImage(const TQImage &image); + + /** + * creates a pixmap from @p xface + */ + TQImage toImage(const TQString &xface); + + + private: + static const int WIDTH = 48; + static const int HEIGHT = WIDTH; + static const int PIXELS = (WIDTH * HEIGHT); + static const int BITSPERWORD = 8; + static const int MAXWORDS = ((PIXELS * 2 + BITSPERWORD - 1) / BITSPERWORD); + + int NumProbs; + int status; + int compface_xbitmap; + + char F[PIXELS]; + Prob *ProbBuf[PIXELS * 2]; + + jmp_buf comp_env; + + typedef struct bigint + { + int b_words; + unsigned char b_word[MAXWORDS]; + } BigInt; + + BigInt B; + + void RevPush(const Prob *p); + void BigPush(Prob *p); + int BigPop(register const Prob *p); + void BigDiv(register unsigned char a, register unsigned char *r); + void BigMul(register unsigned char a); + void BigAdd(unsigned char a); + void BigClear(); + + TQCString WriteFace(); + void UnCompAll(char *fbuf); + void UnCompress(register char *f, register int wid, register int hei, register int lev); + void BigWrite(register char *fbuf); + void BigRead(register char *fbuf); + void ReadFace(char *fbuf); + void GenFace(); + void UnGenFace(); + void Gen(register char *f); + void PopGreys(char *f, int wid, int hei); + void CompAll(char *fbuf); + void Compress(register char *f, register int wid, register int hei, register int lev); + int AllWhite(char *f, int wid, int hei); + int AllBlack(char *f, int wid, int hei); + int Same(register char *f, register int wid, register int hei); + void PushGreys(char *f, int wid, int hei); + + + }; +} // namespace KPIM +#endif // __KXFACE_H diff --git a/libtdepim/ldapclient.cpp b/libtdepim/ldapclient.cpp new file mode 100644 index 000000000..f8497f084 --- /dev/null +++ b/libtdepim/ldapclient.cpp @@ -0,0 +1,613 @@ +/* kldapclient.cpp - LDAP access + * Copyright (C) 2002 Klarälvdalens Datakonsult AB + * + * Author: Steffen Hansen + * + * Ported to KABC by Daniel Molkentin + * + * This file 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 file 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 "ldapclient.h" + +using namespace KPIM; + +KConfig *KPIM::LdapSearch::s_config = 0L; +static KStaticDeleter configDeleter; + +TQString LdapObject::toString() const +{ + TQString result = TQString::tqfromLatin1( "\ndn: %1\n" ).tqarg( dn ); + for ( LdapAttrMap::ConstIterator it = attrs.begin(); it != attrs.end(); ++it ) { + TQString attr = it.key(); + for ( LdapAttrValue::ConstIterator it2 = (*it).begin(); it2 != (*it).end(); ++it2 ) { + result += TQString::fromUtf8( KABC::LDIF::assembleLine( attr, *it2, 76 ) ) + "\n"; + } + } + + return result; +} + +void LdapObject::clear() +{ + dn = TQString(); + objectClass = TQString(); + attrs.clear(); +} + +void LdapObject::assign( const LdapObject& that ) +{ + if ( &that != this ) { + dn = that.dn; + attrs = that.attrs; + client = that.client; + } +} + +LdapClient::LdapClient( int clientNumber, TQObject* parent, const char* name ) + : TQObject( parent, name ), mJob( 0 ), mActive( false ), mReportObjectClass( false ) +{ +// d = new LdapClientPrivate; + mClientNumber = clientNumber; + mCompletionWeight = 50 - mClientNumber; +} + +LdapClient::~LdapClient() +{ + cancelQuery(); +// delete d; d = 0; +} + +void LdapClient::setAttrs( const TQStringList& attrs ) +{ + mAttrs = attrs; + for ( TQStringList::Iterator it = mAttrs.begin(); it != mAttrs.end(); ++it ) + if( (*it).lower() == "objectclass" ){ + mReportObjectClass = true; + return; + } + mAttrs << "objectClass"; // via objectClass we detect distribution lists + mReportObjectClass = false; +} + +void LdapClient::startQuery( const TQString& filter ) +{ + cancelQuery(); + KABC::LDAPUrl url; + + url.setProtocol( ( mServer.security() == LdapServer::SSL ) ? "ldaps" : "ldap" ); + if ( mServer.auth() != LdapServer::Anonymous ) { + url.setUser( mServer.user() ); + url.setPass( mServer.pwdBindDN() ); + } + url.setHost( mServer.host() ); + url.setPort( mServer.port() ); + url.setExtension( "x-ver", TQString::number( mServer.version() ) ); + url.setDn( mServer.baseDN() ); + url.setDn( mServer.baseDN() ); + if ( mServer.security() == LdapServer::TLS ) url.setExtension( "x-tls","" ); + if ( mServer.auth() == LdapServer::SASL ) { + url.setExtension( "x-sasl","" ); + if ( !mServer.bindDN().isEmpty() ) url.setExtension( "x-bindname", mServer.bindDN() ); + if ( !mServer.mech().isEmpty() ) url.setExtension( "x-mech", mServer.mech() ); + } + if ( mServer.timeLimit() != 0 ) url.setExtension( "x-timelimit", + TQString::number( mServer.timeLimit() ) ); + if ( mServer.sizeLimit() != 0 ) url.setExtension( "x-sizelimit", + TQString::number( mServer.sizeLimit() ) ); + + url.setAttributes( mAttrs ); + url.setScope( mScope == "one" ? KABC::LDAPUrl::One : KABC::LDAPUrl::Sub ); + url.setFilter( "("+filter+")" ); + + kdDebug(5300) << "LdapClient: Doing query: " << url.prettyURL() << endl; + + startParseLDIF(); + mActive = true; + mJob = KIO::get( url, false, false ); + connect( mJob, TQT_SIGNAL( data( KIO::Job*, const TQByteArray& ) ), + this, TQT_SLOT( slotData( KIO::Job*, const TQByteArray& ) ) ); + connect( mJob, TQT_SIGNAL( infoMessage( KIO::Job*, const TQString& ) ), + this, TQT_SLOT( slotInfoMessage( KIO::Job*, const TQString& ) ) ); + connect( mJob, TQT_SIGNAL( result( KIO::Job* ) ), + this, TQT_SLOT( slotDone() ) ); +} + +void LdapClient::cancelQuery() +{ + if ( mJob ) { + mJob->kill(); + mJob = 0; + } + + mActive = false; +} + +void LdapClient::slotData( KIO::Job*, const TQByteArray& data ) +{ + parseLDIF( data ); +} + +void LdapClient::slotInfoMessage( KIO::Job*, const TQString & ) +{ + //qDebug("Job said \"%s\"", info.latin1()); +} + +void LdapClient::slotDone() +{ + endParseLDIF(); + mActive = false; +#if 0 + for ( TQValueList::Iterator it = mObjects.begin(); it != mObjects.end(); ++it ) { + qDebug( (*it).toString().latin1() ); + } +#endif + int err = mJob->error(); + if ( err && err != KIO::ERR_USER_CANCELED ) { + emit error( mJob->errorString() ); + } + emit done(); +} + +void LdapClient::startParseLDIF() +{ + mCurrentObject.clear(); + mLdif.startParsing(); +} + +void LdapClient::endParseLDIF() +{ +} + +void LdapClient::finishCurrentObject() +{ + mCurrentObject.dn = mLdif.dn(); + const TQString sClass( mCurrentObject.objectClass.lower() ); + if( sClass == "groupofnames" || sClass == "kolabgroupofnames" ){ + LdapAttrMap::ConstIterator it = mCurrentObject.attrs.find("mail"); + if( it == mCurrentObject.attrs.end() ){ + // No explicit mail address found so far? + // Fine, then we use the address stored in the DN. + TQString sMail; + TQStringList lMail = TQStringList::split(",dc=", mCurrentObject.dn); + const int n = lMail.count(); + if( n ){ + if( lMail.first().lower().startsWith("cn=") ){ + sMail = lMail.first().simplifyWhiteSpace().mid(3); + if( 1 < n ) + sMail.append('@'); + for( int i=1; ireadEntry( prefix + TQString( "Host%1" ).tqarg( j ), "" ).stripWhiteSpace(); + if ( !host.isEmpty() ) + server.setHost( host ); + + int port = config->readNumEntry( prefix + TQString( "Port%1" ).tqarg( j ), 389 ); + server.setPort( port ); + + TQString base = config->readEntry( prefix + TQString( "Base%1" ).tqarg( j ), "" ).stripWhiteSpace(); + if ( !base.isEmpty() ) + server.setBaseDN( base ); + + TQString user = config->readEntry( prefix + TQString( "User%1" ).tqarg( j ) ).stripWhiteSpace(); + if ( !user.isEmpty() ) + server.setUser( user ); + + TQString bindDN = config->readEntry( prefix + TQString( "Bind%1" ).tqarg( j ) ).stripWhiteSpace(); + if ( !bindDN.isEmpty() ) + server.setBindDN( bindDN ); + + TQString pwdBindDN = config->readEntry( prefix + TQString( "PwdBind%1" ).tqarg( j ) ); + if ( !pwdBindDN.isEmpty() ) + server.setPwdBindDN( pwdBindDN ); + + server.setTimeLimit( config->readNumEntry( prefix + TQString( "TimeLimit%1" ).tqarg( j ) ) ); + server.setSizeLimit( config->readNumEntry( prefix + TQString( "SizeLimit%1" ).tqarg( j ) ) ); + server.setVersion( config->readNumEntry( prefix + TQString( "Version%1" ).tqarg( j ), 3 ) ); + server.setSecurity( config->readNumEntry( prefix + TQString( "Security%1" ).tqarg( j ) ) ); + server.setAuth( config->readNumEntry( prefix + TQString( "Auth%1" ).tqarg( j ) ) ); + server.setMech( config->readEntry( prefix + TQString( "Mech%1" ).tqarg( j ) ) ); +} + +void LdapSearch::writeConfig( const LdapServer &server, KConfig *config, int j, bool active ) +{ + TQString prefix; + if ( active ) prefix = "Selected"; + config->writeEntry( prefix + TQString( "Host%1" ).tqarg( j ), server.host() ); + config->writeEntry( prefix + TQString( "Port%1" ).tqarg( j ), server.port() ); + config->writeEntry( prefix + TQString( "Base%1" ).tqarg( j ), server.baseDN() ); + config->writeEntry( prefix + TQString( "User%1" ).tqarg( j ), server.user() ); + config->writeEntry( prefix + TQString( "Bind%1" ).tqarg( j ), server.bindDN() ); + config->writeEntry( prefix + TQString( "PwdBind%1" ).tqarg( j ), server.pwdBindDN() ); + config->writeEntry( prefix + TQString( "TimeLimit%1" ).tqarg( j ), server.timeLimit() ); + config->writeEntry( prefix + TQString( "SizeLimit%1" ).tqarg( j ), server.sizeLimit() ); + config->writeEntry( prefix + TQString( "Version%1" ).tqarg( j ), server.version() ); + config->writeEntry( prefix + TQString( "Security%1" ).tqarg( j ), server.security() ); + config->writeEntry( prefix + TQString( "Auth%1" ).tqarg( j ), server.auth() ); + config->writeEntry( prefix + TQString( "Mech%1" ).tqarg( j ), server.mech() ); +} + +KConfig* LdapSearch::config() +{ + if ( !s_config ) + configDeleter.setObject( s_config, new KConfig( "kabldaprc", false, false ) ); // Open read-write, no kdeglobals + + return s_config; +} + + +LdapSearch::LdapSearch() + : mActiveClients( 0 ), mNoLDAPLookup( false ) +{ + if ( !KProtocolInfo::isKnownProtocol( KURL("ldap://localhost") ) ) { + mNoLDAPLookup = true; + return; + } + + readConfig(); + connect(KDirWatch::self(), TQT_SIGNAL(dirty (const TQString&)),this, + TQT_SLOT(slotFileChanged(const TQString&))); +} + +void LdapSearch::readWeighForClient( LdapClient *client, KConfig *config, int clientNumber ) +{ + const int completionWeight = config->readNumEntry( TQString( "SelectedCompletionWeight%1" ).tqarg( clientNumber ), -1 ); + if ( completionWeight != -1 ) + client->setCompletionWeight( completionWeight ); +} + +void LdapSearch::updateCompletionWeights() +{ + KConfig *config = KPIM::LdapSearch::config(); + config->setGroup( "LDAP" ); + for ( uint i = 0; i < mClients.size(); i++ ) { + readWeighForClient( mClients[i], config, i ); + } +} + +void LdapSearch::readConfig() +{ + cancelSearch(); + TQValueList< LdapClient* >::Iterator it; + for ( it = mClients.begin(); it != mClients.end(); ++it ) + delete *it; + mClients.clear(); + + // stolen from KAddressBook + KConfig *config = KPIM::LdapSearch::config(); + config->setGroup( "LDAP" ); + int numHosts = config->readUnsignedNumEntry( "NumSelectedHosts"); + if ( !numHosts ) { + mNoLDAPLookup = true; + } else { + for ( int j = 0; j < numHosts; j++ ) { + LdapClient* ldapClient = new LdapClient( j, this ); + LdapServer server; + readConfig( server, config, j, true ); + if ( !server.host().isEmpty() ) mNoLDAPLookup = false; + ldapClient->setServer( server ); + + readWeighForClient( ldapClient, config, j ); + + TQStringList attrs; + // note: we need "objectClass" to detect distribution lists + attrs << "cn" << "mail" << "givenname" << "sn" << "objectClass"; + ldapClient->setAttrs( attrs ); + + connect( ldapClient, TQT_SIGNAL( result( const KPIM::LdapObject& ) ), + this, TQT_SLOT( slotLDAPResult( const KPIM::LdapObject& ) ) ); + connect( ldapClient, TQT_SIGNAL( done() ), + this, TQT_SLOT( slotLDAPDone() ) ); + connect( ldapClient, TQT_SIGNAL( error( const TQString& ) ), + this, TQT_SLOT( slotLDAPError( const TQString& ) ) ); + + mClients.append( ldapClient ); + } + + connect( &mDataTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotDataTimer() ) ); + } + mConfigFile = locateLocal( "config", "kabldaprc" ); + KDirWatch::self()->addFile( mConfigFile ); +} + +void LdapSearch::slotFileChanged( const TQString& file ) +{ + if ( file == mConfigFile ) + readConfig(); +} + +void LdapSearch::startSearch( const TQString& txt ) +{ + if ( mNoLDAPLookup ) + return; + + cancelSearch(); + + int pos = txt.find( '\"' ); + if( pos >= 0 ) + { + ++pos; + int pos2 = txt.find( '\"', pos ); + if( pos2 >= 0 ) + mSearchText = txt.mid( pos , pos2 - pos ); + else + mSearchText = txt.mid( pos ); + } else + mSearchText = txt; + + /* The reasoning behind this filter is: + * If it's a person, or a distlist, show it, even if it doesn't have an email address. + * If it's not a person, or a distlist, only show it if it has an email attribute. + * This allows both resource accounts with an email address which are not a person and + * person entries without an email address to show up, while still not showing things + * like structural entries in the ldap tree. */ + TQString filter = TQString( "&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))(|(cn=%1*)(mail=%2*)(mail=*@%3*)(givenName=%4*)(sn=%5*))" ) + .tqarg( mSearchText ).tqarg( mSearchText ).tqarg( mSearchText ).tqarg( mSearchText ).tqarg( mSearchText ); + + TQValueList< LdapClient* >::Iterator it; + for ( it = mClients.begin(); it != mClients.end(); ++it ) { + (*it)->startQuery( filter ); + kdDebug(5300) << "LdapSearch::startSearch() " << filter << endl; + ++mActiveClients; + } +} + +void LdapSearch::cancelSearch() +{ + TQValueList< LdapClient* >::Iterator it; + for ( it = mClients.begin(); it != mClients.end(); ++it ) + (*it)->cancelQuery(); + + mActiveClients = 0; + mResults.clear(); +} + +void LdapSearch::slotLDAPResult( const KPIM::LdapObject& obj ) +{ + mResults.append( obj ); + if ( !mDataTimer.isActive() ) + mDataTimer.start( 500, true ); +} + +void LdapSearch::slotLDAPError( const TQString& ) +{ + slotLDAPDone(); +} + +void LdapSearch::slotLDAPDone() +{ + if ( --mActiveClients > 0 ) + return; + + finish(); +} + +void LdapSearch::slotDataTimer() +{ + TQStringList lst; + LdapResultList reslist; + makeSearchData( lst, reslist ); + if ( !lst.isEmpty() ) + emit searchData( lst ); + if ( !reslist.isEmpty() ) + emit searchData( reslist ); +} + +void LdapSearch::finish() +{ + mDataTimer.stop(); + + slotDataTimer(); // emit final bunch of data + emit searchDone(); +} + +void LdapSearch::makeSearchData( TQStringList& ret, LdapResultList& resList ) +{ + TQString search_text_upper = mSearchText.upper(); + + TQValueList< KPIM::LdapObject >::ConstIterator it1; + for ( it1 = mResults.begin(); it1 != mResults.end(); ++it1 ) { + TQString name, mail, givenname, sn; + TQStringList mails; + bool isDistributionList = false; + bool wasCN = false; + bool wasDC = false; + + //kdDebug(5300) << "\n\nLdapSearch::makeSearchData()\n\n" << endl; + + LdapAttrMap::ConstIterator it2; + for ( it2 = (*it1).attrs.begin(); it2 != (*it1).attrs.end(); ++it2 ) { + TQByteArray val = (*it2).first(); + int len = val.size(); + if( len > 0 && '\0' == val[len-1] ) + --len; + const TQString tmp = TQString::fromUtf8( val, len ); + //kdDebug(5300) << " key: \"" << it2.key() << "\" value: \"" << tmp << "\"" << endl; + if ( it2.key() == "cn" ) { + name = tmp; + if( mail.isEmpty() ) + mail = tmp; + else{ + if( wasCN ) + mail.prepend( "." ); + else + mail.prepend( "@" ); + mail.prepend( tmp ); + } + wasCN = true; + } else if ( it2.key() == "dc" ) { + if( mail.isEmpty() ) + mail = tmp; + else{ + if( wasDC ) + mail.append( "." ); + else + mail.append( "@" ); + mail.append( tmp ); + } + wasDC = true; + } else if( it2.key() == "mail" ) { + mail = tmp; + LdapAttrValue::ConstIterator it3 = it2.data().begin(); + for ( ; it3 != it2.data().end(); ++it3 ) { + mails.append( TQString::fromUtf8( (*it3).data(), (*it3).size() ) ); + } + } else if( it2.key() == "givenName" ) + givenname = tmp; + else if( it2.key() == "sn" ) + sn = tmp; + else if( it2.key() == "objectClass" && + (tmp == "groupOfNames" || tmp == "kolabGroupOfNames") ) { + isDistributionList = true; + } + } + + if( mails.isEmpty()) { + if ( !mail.isEmpty() ) mails.append( mail ); + if( isDistributionList ) { + //kdDebug(5300) << "\n\nLdapSearch::makeSearchData() found a list: " << name << "\n\n" << endl; + ret.append( name ); + // following lines commented out for bugfixing kolab issue #177: + // + // Unlike we thought previously we may NOT append the server name here. + // + // The right server is found by the SMTP server instead: Kolab users + // must use the correct SMTP server, by definition. + // + //mail = (*it1).client->base().simplifyWhiteSpace(); + //mail.replace( ",dc=", ".", false ); + //if( mail.startsWith("dc=", false) ) + // mail.remove(0, 3); + //mail.prepend( '@' ); + //mail.prepend( name ); + //mail = name; + } else { + //kdDebug(5300) << "LdapSearch::makeSearchData() found BAD ENTRY: \"" << name << "\"" << endl; + continue; // nothing, bad entry + } + } else if ( name.isEmpty() ) { + //kdDebug(5300) << "LdapSearch::makeSearchData() mail: \"" << mail << "\"" << endl; + ret.append( mail ); + } else { + //kdDebug(5300) << "LdapSearch::makeSearchData() name: \"" << name << "\" mail: \"" << mail << "\"" << endl; + ret.append( TQString( "%1 <%2>" ).tqarg( name ).tqarg( mail ) ); + } + + LdapResult sr; + sr.clientNumber = (*it1).client->clientNumber(); + sr.completionWeight = (*it1).client->completionWeight(); + sr.name = name; + sr.email = mails; + resList.append( sr ); + } + + mResults.clear(); +} + +bool LdapSearch::isAvailable() const +{ + return !mNoLDAPLookup; +} + + +#include "ldapclient.moc" diff --git a/libtdepim/ldapclient.h b/libtdepim/ldapclient.h new file mode 100644 index 000000000..a2a85f1e3 --- /dev/null +++ b/libtdepim/ldapclient.h @@ -0,0 +1,300 @@ +/* kldapclient.h - LDAP access + * Copyright (C) 2002 Klar�vdalens Datakonsult AB + * + * Author: Steffen Hansen + * + * This file 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 file 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 KPIM_LDAPCLIENT_H +#define KPIM_LDAPCLIENT_H + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +namespace KPIM { + +class LdapClient; +typedef TQValueList LdapAttrValue; +typedef TQMap LdapAttrMap; + +class LdapServer +{ + public: + LdapServer() + : mPort( 389 ), + mTimeLimit(0), + mSizeLimit(0), + mVersion(2), + mSecurity(Sec_None), + mAuth( LdapServer::Anonymous ) + {} + + enum Security{ Sec_None, TLS, SSL }; + enum Auth{ Anonymous, Simple, SASL }; + TQString host() const { return mHost; } + int port() const { return mPort; } + const TQString &baseDN() const { return mBaseDN; } + const TQString &user() const { return mUser; } + const TQString &bindDN() const { return mBindDN; } + const TQString &pwdBindDN() const { return mPwdBindDN; } + int timeLimit() const { return mTimeLimit; } + int sizeLimit() const { return mSizeLimit; } + int version() const { return mVersion; } + int security() const { return mSecurity; } + int auth() const { return mAuth; } + const TQString &mech() const { return mMech; } + + void setHost( const TQString &host ) { mHost = host; } + void setPort( int port ) { mPort = port; } + void setBaseDN( const TQString &baseDN ) { mBaseDN = baseDN; } + void setUser( const TQString &user ) { mUser = user; } + void setBindDN( const TQString &bindDN ) { mBindDN = bindDN; } + void setPwdBindDN( const TQString &pwdBindDN ) { mPwdBindDN = pwdBindDN; } + void setTimeLimit( int timelimit ) { mTimeLimit = timelimit; } + void setSizeLimit( int sizelimit ) { mSizeLimit = sizelimit; } + void setVersion( int version ) { mVersion = version; } + void setSecurity( int security ) { mSecurity = security; } //0-No, 1-TLS, 2-SSL - KDE4: add an enum to Lda + void setAuth( int auth ) { mAuth = auth; } //0-Anonymous, 1-simple, 2-SASL - KDE4: add an enum to LdapCon + void setMech( const TQString &mech ) { mMech = mech; } + + private: + TQString mHost; + int mPort; + TQString mBaseDN; + TQString mUser; + TQString mBindDN; + TQString mPwdBindDN; + TQString mMech; + int mTimeLimit, mSizeLimit, mVersion, mSecurity, mAuth; +}; + + +/** + * This class is internal. Binary compatibiliy might be broken any time + * without notification. Do not use it. + * + * We mean it! + * + */ +class LdapObject +{ + public: + LdapObject() + : dn( TQString() ), client( 0 ) {} + explicit LdapObject( const TQString& _dn, LdapClient* _cl ) : dn( _dn ), client( _cl ) {} + LdapObject( const LdapObject& that ) { assign( that ); } + + LdapObject& operator=( const LdapObject& that ) + { + assign( that ); + return *this; + } + + TQString toString() const; + + void clear(); + + TQString dn; + TQString objectClass; + LdapAttrMap attrs; + LdapClient* client; + + protected: + void assign( const LdapObject& that ); + + private: + //class LdapObjectPrivate* d; +}; + +/** + * This class is internal. Binary compatibility might be broken any time + * without notification. Do not use it. + * + * We mean it! + * + */ +class KDE_EXPORT LdapClient : public TQObject +{ + Q_OBJECT + TQ_OBJECT + + public: + LdapClient( int clientNumber, TQObject* parent = 0, const char* name = 0 ); + virtual ~LdapClient(); + + /*! returns true if there is a query running */ + bool isActive() const { return mActive; } + + int clientNumber() const; + int completionWeight() const; + void setCompletionWeight( int ); + + const LdapServer& server() { return mServer; } + void setServer( const LdapServer &server ) { mServer = server; } + /*! Return the attributes that should be + * returned, or an empty list if + * all attributes are wanted + */ + TQStringList attrs() const { return mAttrs; } + + signals: + /*! Emitted when the query is done */ + void done(); + + /*! Emitted in case of error */ + void error( const TQString& ); + + /*! Emitted once for each object returned + * from the query + */ + void result( const KPIM::LdapObject& ); + + public slots: // why are those slots? + /*! Set the attributes that should be + * returned, or an empty list if + * all attributes are wanted + */ + void setAttrs( const TQStringList& attrs ); + + void setScope( const TQString scope ) { mScope = scope; } + + /*! + * Start the query with filter filter + */ + void startQuery( const TQString& filter ); + + /*! + * Abort a running query + */ + void cancelQuery(); + + protected slots: + void slotData( KIO::Job*, const TQByteArray &data ); + void slotInfoMessage( KIO::Job*, const TQString &info ); + void slotDone(); + + protected: + void startParseLDIF(); + void parseLDIF( const TQByteArray& data ); + void endParseLDIF(); + void finishCurrentObject(); + + LdapServer mServer; + TQString mScope; + TQStringList mAttrs; + + TQGuardedPtr mJob; + bool mActive; + bool mReportObjectClass; + + LdapObject mCurrentObject; + + private: + KABC::LDIF mLdif; + int mClientNumber; + int mCompletionWeight; + +// class LdapClientPrivate; +// LdapClientPrivate* d; +}; + +/** + * Structure describing one result returned by a LDAP query + */ +struct LdapResult { + TQString name; ///< full name + TQStringList email; ///< emails + int clientNumber; ///< for sorting in a ldap-only lookup + int completionWeight; ///< for sorting in a completion list +}; +typedef TQValueList LdapResultList; + + +/** + * This class is internal. Binary compatibiliy might be broken any time + * without notification. Do not use it. + * + * We mean it! + * + */ +class KDE_EXPORT LdapSearch : public TQObject +{ + Q_OBJECT + TQ_OBJECT + + public: + LdapSearch(); + + static KConfig *config(); + static void readConfig( LdapServer &server, KConfig *config, int num, bool active ); + static void writeConfig( const LdapServer &server, KConfig *config, int j, bool active ); + + void startSearch( const TQString& txt ); + void cancelSearch(); + bool isAvailable() const; + void updateCompletionWeights(); + + TQValueList< LdapClient* > clients() const { return mClients; } + + signals: + /// Results, assembled as "Full Name " + /// (This signal can be emitted many times) + void searchData( const TQStringList& ); + /// Another form for the results, with separate fields + /// (This signal can be emitted many times) + void searchData( const KPIM::LdapResultList& ); + void searchDone(); + + private slots: + void slotLDAPResult( const KPIM::LdapObject& ); + void slotLDAPError( const TQString& ); + void slotLDAPDone(); + void slotDataTimer(); + void slotFileChanged( const TQString& ); + + private: + void readWeighForClient( LdapClient *client, KConfig *config, int clientNumber ); + void readConfig(); + void finish(); + void makeSearchData( TQStringList& ret, LdapResultList& resList ); + TQValueList< LdapClient* > mClients; + TQString mSearchText; + TQTimer mDataTimer; + int mActiveClients; + bool mNoLDAPLookup; + TQValueList< LdapObject > mResults; + TQString mConfigFile; + + private: + static KConfig *s_config; + class LdapSearchPrivate* d; +}; + +} +#endif // KPIM_LDAPCLIENT_H diff --git a/libtdepim/ldapsearchdialog.cpp b/libtdepim/ldapsearchdialog.cpp new file mode 100644 index 000000000..ed1aa2933 --- /dev/null +++ b/libtdepim/ldapsearchdialog.cpp @@ -0,0 +1,480 @@ +/* ldapsearchdialogimpl.cpp - LDAP access + * Copyright (C) 2002 Klar�vdalens Datakonsult AB + * + * Author: Steffen Hansen + * + * This file 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 file 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 "ldapsearchdialog.h" +#include "ldapclient.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace KPIM; + +static TQString asUtf8( const TQByteArray &val ) +{ + if ( val.isEmpty() ) + return TQString(); + + const char *data = val.data(); + + //TQString::fromUtf8() bug workaround + if ( data[ val.size() - 1 ] == '\0' ) + return TQString::fromUtf8( data, val.size() - 1 ); + else + return TQString::fromUtf8( data, val.size() ); +} + +static TQString join( const KPIM::LdapAttrValue& lst, const TQString& sep ) +{ + TQString res; + bool alredy = false; + for ( KPIM::LdapAttrValue::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { + if ( alredy ) + res += sep; + alredy = TRUE; + res += asUtf8( *it ); + } + return res; +} + +static TQMap& adrbookattr2ldap() +{ + static TQMap keys; + + if ( keys.isEmpty() ) { + keys[ i18n( "Title" ) ] = "title"; + keys[ i18n( "Full Name" ) ] = "cn"; + keys[ i18n( "Email" ) ] = "mail"; + keys[ i18n( "Home Number" ) ] = "homePhone"; + keys[ i18n( "Work Number" ) ] = "telephoneNumber"; + keys[ i18n( "Mobile Number" ) ] = "mobile"; + keys[ i18n( "Fax Number" ) ] = "facsimileTelephoneNumber"; + keys[ i18n( "Pager" ) ] = "pager"; + keys[ i18n( "Street") ] = "street"; + keys[ i18n( "State" ) ] = "st"; + keys[ i18n( "Country" ) ] = "co"; + keys[ i18n( "City" ) ] = "l"; + keys[ i18n( "Organization" ) ] = "o"; + keys[ i18n( "Company" ) ] = "Company"; + keys[ i18n( "Department" ) ] = "department"; + keys[ i18n( "Zip Code" ) ] = "postalCode"; + keys[ i18n( "Postal Address" ) ] = "postalAddress"; + keys[ i18n( "Description" ) ] = "description"; + keys[ i18n( "User ID" ) ] = "uid"; + } + return keys; +} + +namespace KPIM { + +class ContactListItem : public TQListViewItem +{ + public: + ContactListItem( TQListView* parent, const KPIM::LdapAttrMap& attrs ) + : TQListViewItem( parent ), mAttrs( attrs ) + { + const KPIM::LdapAttrValue &mailAttrs = attrs[ "mail" ]; + if ( mailAttrs.isEmpty() ) { + setSelectable( false ); + setEnabled( false ); + } + } + + KPIM::LdapAttrMap mAttrs; + + virtual TQString text( int col ) const + { + // Look up a suitable attribute for column col + const TQString colName = listView()->columnText( col ); + const TQString ldapAttrName = adrbookattr2ldap()[ colName ]; + return join( mAttrs[ ldapAttrName ], ", " ); + } +}; + +} + +LDAPSearchDialog::LDAPSearchDialog( TQWidget* parent, const char* name ) + : KDialogBase( Plain, i18n( "Search for Addresses in Directory" ), Help | User1 | + User2 | User3 | Cancel, Default, parent, name, false, true ) +{ + setButtonCancel( KStdGuiItem::close() ); + TQFrame *page = plainPage(); + TQVBoxLayout *topLayout = new TQVBoxLayout( page, marginHint(), spacingHint() ); + + TQGroupBox *groupBox = new TQGroupBox( i18n( "Search for Addresses in Directory" ), + page ); + groupBox->setFrameShape( TQGroupBox::Box ); + groupBox->setFrameShadow( TQGroupBox::Sunken ); + groupBox->setColumnLayout( 0, Qt::Vertical ); + TQGridLayout *boxLayout = new TQGridLayout( groupBox->tqlayout(), 2, + 5, spacingHint() ); + boxLayout->setColStretch( 1, 1 ); + + TQLabel *label = new TQLabel( i18n( "Search for:" ), groupBox ); + boxLayout->addWidget( label, 0, 0 ); + + mSearchEdit = new KLineEdit( groupBox ); + boxLayout->addWidget( mSearchEdit, 0, 1 ); + label->setBuddy( mSearchEdit ); + + label = new TQLabel( i18n( "in" ), groupBox ); + boxLayout->addWidget( label, 0, 2 ); + + mFilterCombo = new KComboBox( groupBox ); + mFilterCombo->insertItem( i18n( "Name" ) ); + mFilterCombo->insertItem( i18n( "Email" ) ); + mFilterCombo->insertItem( i18n( "Home Number" ) ); + mFilterCombo->insertItem( i18n( "Work Number" ) ); + boxLayout->addWidget( mFilterCombo, 0, 3 ); + + TQSize buttonSize; + mSearchButton = new TQPushButton( i18n( "Stop" ), groupBox ); + buttonSize = mSearchButton->tqsizeHint(); + mSearchButton->setText( i18n( "Search" ) ); + if ( buttonSize.width() < mSearchButton->tqsizeHint().width() ) + buttonSize = mSearchButton->tqsizeHint(); + mSearchButton->setFixedWidth( buttonSize.width() ); + + mSearchButton->setDefault( true ); + boxLayout->addWidget( mSearchButton, 0, 4 ); + + mRecursiveCheckbox = new TQCheckBox( i18n( "Recursive search" ), groupBox ); + mRecursiveCheckbox->setChecked( true ); + boxLayout->addMultiCellWidget( mRecursiveCheckbox, 1, 1, 0, 4 ); + + mSearchType = new KComboBox( groupBox ); + mSearchType->insertItem( i18n( "Contains" ) ); + mSearchType->insertItem( i18n( "Starts With" ) ); + boxLayout->addMultiCellWidget( mSearchType, 1, 1, 3, 4 ); + + topLayout->addWidget( groupBox ); + + mResultListView = new TQListView( page ); + mResultListView->setSelectionMode( TQListView::Multi ); + mResultListView->setAllColumnsShowFocus( true ); + mResultListView->setShowSortIndicator( true ); + topLayout->addWidget( mResultListView ); + + resize( TQSize( 600, 400).expandedTo( tqminimumSizeHint() ) ); + + setButtonText( User1, i18n( "Unselect All" ) ); + setButtonText( User2, i18n( "Select All" ) ); + setButtonText( User3, i18n( "Add Selected" ) ); + + mNumHosts = 0; + mIsOK = false; + + connect( mRecursiveCheckbox, TQT_SIGNAL( toggled( bool ) ), + this, TQT_SLOT( slotSetScope( bool ) ) ); + connect( mSearchButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotStartSearch() ) ); + + setTabOrder(mSearchEdit, mFilterCombo); + setTabOrder(mFilterCombo, mSearchButton); + mSearchEdit->setFocus(); + + restoreSettings(); +} + +LDAPSearchDialog::~LDAPSearchDialog() +{ + saveSettings(); +} + +void LDAPSearchDialog::restoreSettings() +{ + // Create one KPIM::LdapClient per selected server and configure it. + + // First clean the list to make sure it is empty at + // the beginning of the process + mLdapClientList.setAutoDelete( true ); + mLdapClientList.clear(); + + KConfig kabConfig( "kaddressbookrc" ); + kabConfig.setGroup( "LDAPSearch" ); + mSearchType->setCurrentItem( kabConfig.readNumEntry( "SearchType", 0 ) ); + + // then read the config file and register all selected + // server in the list + KConfig* config = KABC::AddressLineEdit::config(); // singleton kabldaprc config object + KConfigGroupSaver saver( config, "LDAP" ); + mNumHosts = config->readUnsignedNumEntry( "NumSelectedHosts" ); + if ( !mNumHosts ) { + KMessageBox::error( this, i18n( "You must select a LDAP server before searching.\nYou can do this from the menu Settings/Configure KAddressBook." ) ); + mIsOK = false; + } else { + mIsOK = true; + for ( int j = 0; j < mNumHosts; ++j ) { + KPIM::LdapServer ldapServer; + + TQString host = config->readEntry( TQString( "SelectedHost%1" ).tqarg( j ), "" ); + if ( !host.isEmpty() ) + ldapServer.setHost( host ); + + int port = config->readUnsignedNumEntry( TQString( "SelectedPort%1" ).tqarg( j ) ); + if ( port ) + ldapServer.setPort( port ); + + TQString base = config->readEntry( TQString( "SelectedBase%1" ).tqarg( j ), "" ); + if ( !base.isEmpty() ) + ldapServer.setBaseDN( base ); + + TQString bindDN = config->readEntry( TQString( "SelectedBind%1" ).tqarg( j ), "" ); + if ( !bindDN.isEmpty() ) + ldapServer.setBindDN( bindDN ); + + TQString pwdBindDN = config->readEntry( TQString( "SelectedPwdBind%1" ).tqarg( j ), "" ); + if ( !pwdBindDN.isEmpty() ) + ldapServer.setPwdBindDN( pwdBindDN ); + + KPIM::LdapClient* ldapClient = new KPIM::LdapClient( 0, TQT_TQOBJECT(this), "ldapclient" ); + ldapClient->setServer( ldapServer ); + + TQStringList attrs; + + for ( TQMap::Iterator it = adrbookattr2ldap().begin(); it != adrbookattr2ldap().end(); ++it ) + attrs << *it; + + ldapClient->setAttrs( attrs ); + + connect( ldapClient, TQT_SIGNAL( result( const KPIM::LdapObject& ) ), + this, TQT_SLOT( slotAddResult( const KPIM::LdapObject& ) ) ); + connect( ldapClient, TQT_SIGNAL( done() ), + this, TQT_SLOT( slotSearchDone() ) ); + connect( ldapClient, TQT_SIGNAL( error( const TQString& ) ), + this, TQT_SLOT( slotError( const TQString& ) ) ); + + mLdapClientList.append( ldapClient ); + } + +/** CHECKIT*/ + while ( mResultListView->header()->count() > 0 ) { + mResultListView->removeColumn(0); + } + + mResultListView->addColumn( i18n( "Full Name" ) ); + mResultListView->addColumn( i18n( "Email" ) ); + mResultListView->addColumn( i18n( "Home Number" ) ); + mResultListView->addColumn( i18n( "Work Number" ) ); + mResultListView->addColumn( i18n( "Mobile Number" ) ); + mResultListView->addColumn( i18n( "Fax Number" ) ); + mResultListView->addColumn( i18n( "Company" ) ); + mResultListView->addColumn( i18n( "Organization" ) ); + mResultListView->addColumn( i18n( "Street" ) ); + mResultListView->addColumn( i18n( "State" ) ); + mResultListView->addColumn( i18n( "Country" ) ); + mResultListView->addColumn( i18n( "Zip Code" ) ); + mResultListView->addColumn( i18n( "Postal Address" ) ); + mResultListView->addColumn( i18n( "City" ) ); + mResultListView->addColumn( i18n( "Department" ) ); + mResultListView->addColumn( i18n( "Description" ) ); + mResultListView->addColumn( i18n( "User ID" ) ); + mResultListView->addColumn( i18n( "Title" ) ); + + mResultListView->clear(); + } +} + +void LDAPSearchDialog::saveSettings() +{ + KConfig config( "kaddressbookrc" ); + config.setGroup( "LDAPSearch" ); + config.writeEntry( "SearchType", mSearchType->currentItem() ); + config.sync(); +} + +void LDAPSearchDialog::cancelQuery() +{ + for ( KPIM::LdapClient* client = mLdapClientList.first(); client; client = mLdapClientList.next() ) { + client->cancelQuery(); + } +} + +void LDAPSearchDialog::slotAddResult( const KPIM::LdapObject& obj ) +{ + new ContactListItem( mResultListView, obj.attrs ); +} + +void LDAPSearchDialog::slotSetScope( bool rec ) +{ + for ( KPIM::LdapClient* client = mLdapClientList.first(); client; client = mLdapClientList.next() ) { + if ( rec ) + client->setScope( "sub" ); + else + client->setScope( "one" ); + } +} + +TQString LDAPSearchDialog::makeFilter( const TQString& query, const TQString& attr, + bool startsWith ) +{ + /* The reasoning behind this filter is: + * If it's a person, or a distlist, show it, even if it doesn't have an email address. + * If it's not a person, or a distlist, only show it if it has an email attribute. + * This allows both resource accounts with an email address which are not a person and + * person entries without an email address to show up, while still not showing things + * like structural entries in the ldap tree. */ + TQString result( "&(|(objectclass=person)(objectclass=groupofnames)(mail=*))(" ); + if( query.isEmpty() ) + // Return a filter that matches everything + return result + "|(cn=*)(sn=*)" + ")"; + + if ( attr == i18n( "Name" ) ) { + result += startsWith ? "|(cn=%1*)(sn=%2*)" : "|(cn=*%1*)(sn=*%2*)"; + result = result.tqarg( query ).tqarg( query ); + } else { + result += (startsWith ? "%1=%2*" : "%1=*%2*"); + if ( attr == i18n( "Email" ) ) { + result = result.tqarg( "mail" ).tqarg( query ); + } else if ( attr == i18n( "Home Number" ) ) { + result = result.tqarg( "homePhone" ).tqarg( query ); + } else if ( attr == i18n( "Work Number" ) ) { + result = result.tqarg( "telephoneNumber" ).tqarg( query ); + } else { + // Error? + result = TQString(); + return result; + } + } + result += ")"; + return result; +} + +void LDAPSearchDialog::slotStartSearch() +{ + cancelQuery(); + + TQApplication::setOverrideCursor( TQt::waitCursor ); + mSearchButton->setText( i18n( "Stop" ) ); + + disconnect( mSearchButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotStartSearch() ) ); + connect( mSearchButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotStopSearch() ) ); + + bool startsWith = (mSearchType->currentItem() == 1); + + TQString filter = makeFilter( mSearchEdit->text().stripWhiteSpace(), mFilterCombo->currentText(), startsWith ); + + // loop in the list and run the KPIM::LdapClients + mResultListView->clear(); + for( KPIM::LdapClient* client = mLdapClientList.first(); client; client = mLdapClientList.next() ) { + client->startQuery( filter ); + } + + saveSettings(); +} + +void LDAPSearchDialog::slotStopSearch() +{ + cancelQuery(); + slotSearchDone(); +} + +void LDAPSearchDialog::slotSearchDone() +{ + // If there are no more active clients, we are done. + for ( KPIM::LdapClient* client = mLdapClientList.first(); client; client = mLdapClientList.next() ) { + if ( client->isActive() ) + return; + } + + disconnect( mSearchButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotStopSearch() ) ); + connect( mSearchButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotStartSearch() ) ); + + mSearchButton->setText( i18n( "Search" ) ); + TQApplication::restoreOverrideCursor(); +} + +void LDAPSearchDialog::slotError( const TQString& error ) +{ + TQApplication::restoreOverrideCursor(); + KMessageBox::error( this, error ); +} + +void LDAPSearchDialog::closeEvent( TQCloseEvent* e ) +{ + slotStopSearch(); + e->accept(); +} + +/*! + * Returns a ", " separated list of email addresses that were + * checked by the user + */ +TQString LDAPSearchDialog::selectedEMails() const +{ + TQStringList result; + ContactListItem* cli = static_cast( mResultListView->firstChild() ); + while ( cli ) { + if ( cli->isSelected() ) { + TQString email = asUtf8( cli->mAttrs[ "mail" ].first() ).stripWhiteSpace(); + if ( !email.isEmpty() ) { + TQString name = asUtf8( cli->mAttrs[ "cn" ].first() ).stripWhiteSpace(); + if ( name.isEmpty() ) { + result << email; + } else { + result << KPIM::quoteNameIfNecessary( name ) + " <" + email + ">"; + } + } + } + cli = static_cast( cli->nextSibling() ); + } + + return result.join( ", " ); +} + +void LDAPSearchDialog::slotHelp() +{ + kapp->invokeHelp( "ldap-queries" ); +} + +void LDAPSearchDialog::slotUser1() +{ + mResultListView->selectAll( false ); +} + +void LDAPSearchDialog::slotUser2() +{ + mResultListView->selectAll( true ); +} + +void LDAPSearchDialog::slotUser3() +{ + emit addresseesAdded(); +} + +#include "ldapsearchdialog.moc" diff --git a/libtdepim/ldapsearchdialog.h b/libtdepim/ldapsearchdialog.h new file mode 100644 index 000000000..45e174efe --- /dev/null +++ b/libtdepim/ldapsearchdialog.h @@ -0,0 +1,93 @@ +/* ldapsearchdialogimpl.h - LDAP access + * Copyright (C) 2002 Klar�vdalens Datakonsult AB + * + * Author: Steffen Hansen + * + * This file 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 file 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 LDAPSEARCHDIALOG_H +#define LDAPSEARCHDIALOG_H + +#include + +#include +#include +#include + +class KComboBox; + +class TQCheckBox; +class TQListView; +class TQPushButton; + +namespace KPIM { + +class LDAPSearchDialog : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT + + public: + LDAPSearchDialog( TQWidget* parent, const char* name = 0 ); + ~LDAPSearchDialog(); + + bool isOK() const { return mIsOK; } + + void restoreSettings(); + + void setSearchText( const TQString &text ) { mSearchEdit->setText( text ); } + TQString selectedEMails() const; + signals: + void addresseesAdded(); + + protected slots: + void slotAddResult( const KPIM::LdapObject& obj ); + void slotSetScope( bool rec ); + void slotStartSearch(); + void slotStopSearch(); + void slotSearchDone(); + void slotError( const TQString& ); + virtual void slotHelp(); + virtual void slotUser1(); + virtual void slotUser2(); + virtual void slotUser3(); + + protected: + + virtual void closeEvent( TQCloseEvent* ); + + private: + void saveSettings(); + + TQString makeFilter( const TQString& query, const TQString& attr, bool startsWith ); + + void cancelQuery(); + + int mNumHosts; + TQPtrList mLdapClientList; + bool mIsOK; + KComboBox* mFilterCombo; + KComboBox* mSearchType; + KLineEdit* mSearchEdit; + + TQCheckBox* mRecursiveCheckbox; + TQListView* mResultListView; + TQPushButton* mSearchButton; +}; + + +} +#endif diff --git a/libtdepim/linklocator.cpp b/libtdepim/linklocator.cpp new file mode 100644 index 000000000..399c5d3b3 --- /dev/null +++ b/libtdepim/linklocator.cpp @@ -0,0 +1,466 @@ +/** + * linklocator.cpp + * + * Copyright (c) 2002 Dave Corrie + * + * This file is part of KMail. + * + * KMail 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 "linklocator.h" +#include "pimemoticons.h" +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +TQMap *LinkLocator::s_smileyEmoticonNameMap = 0; +TQMap *LinkLocator::s_smileyEmoticonHTMLCache = 0; + +static KStaticDeleter< TQMap > smileyMapDeleter; +static KStaticDeleter< TQMap > smileyCacheDeleter; + +LinkLocator::LinkLocator(const TQString& text, int pos) + : mText(text), mPos(pos), mMaxUrlLen(4096), mMaxAddressLen(255) +{ + // If you change either of the above values for maxUrlLen or + // maxAddressLen, then please also update the documentation for + // setMaxUrlLen()/setMaxAddressLen() in the header file AND the + // default values used for the maxUrlLen/maxAddressLen parameters + // of convertToHtml(). + + if ( !s_smileyEmoticonNameMap ) { + smileyMapDeleter.setObject( s_smileyEmoticonNameMap, + new TQMap() ); + for ( int i = 0; i < EmotIcons::EnumSindex::COUNT; ++i ) { + TQString imageName( EmotIcons::EnumSindex::enumToString[i] ); + imageName.truncate( imageName.length() - 2 ); //remove the _0 bit + s_smileyEmoticonNameMap->insert( EmotIcons::smiley(i), imageName ); + } + } + + if ( !s_smileyEmoticonHTMLCache ) + smileyCacheDeleter.setObject( s_smileyEmoticonHTMLCache, + new TQMap() ); +} + +void LinkLocator::setMaxUrlLen(int length) +{ + mMaxUrlLen = length; +} + +int LinkLocator::maxUrlLen() const +{ + return mMaxUrlLen; +} + +void LinkLocator::setMaxAddressLen(int length) +{ + mMaxAddressLen = length; +} + +int LinkLocator::maxAddressLen() const +{ + return mMaxAddressLen; +} + +TQString LinkLocator::getUrl() +{ + TQString url; + if(atUrl()) + { + // handle cases like this: http://foobar.org/ + int start = mPos; + while(mPos < (int)mText.length() && mText[mPos] > ' ' && mText[mPos] != '"' && + TQString("<>()[]").find(mText[mPos]) == -1) + { + ++mPos; + } + /* some URLs really end with: # / & - _ */ + const TQString allowedSpecialChars = TQString("#/&-_"); + while(mPos > start && mText[mPos-1].isPunct() && + allowedSpecialChars.find(mText[mPos-1]) == -1 ) + { + --mPos; + } + + url = mText.mid(start, mPos - start); + if(isEmptyUrl(url) || mPos - start > maxUrlLen()) + { + mPos = start; + url = ""; + } + else + { + --mPos; + } + } + return url; +} + +// keep this in sync with KMMainWin::slotUrlClicked() +bool LinkLocator::atUrl() const +{ + // the following characters are allowed in a dot-atom (RFC 2822): + // a-z A-Z 0-9 . ! # $ % & ' * + - / = ? ^ _ ` { | } ~ + const TQString allowedSpecialChars = TQString(".!#$%&'*+-/=?^_`{|}~"); + + // the character directly before the URL must not be a letter, a number or + // any other character allowed in a dot-atom (RFC 2822). + if( ( mPos > 0 ) && ( mText[mPos-1].isLetterOrNumber() || + ( allowedSpecialChars.find( mText[mPos-1] ) != -1 ) ) ) + return false; + + TQChar ch = mText[mPos]; + return (ch=='h' && ( mText.mid(mPos, 7) == "http://" || + mText.mid(mPos, 8) == "https://") ) || + (ch=='v' && mText.mid(mPos, 6) == "vnc://") || + (ch=='f' && ( mText.mid(mPos, 7) == "fish://" || + mText.mid(mPos, 6) == "ftp://" || + mText.mid(mPos, 7) == "ftps://") ) || + (ch=='s' && ( mText.mid(mPos, 7) == "sftp://" || + mText.mid(mPos, 6) == "smb://") ) || + (ch=='m' && mText.mid(mPos, 7) == "mailto:") || + (ch=='w' && mText.mid(mPos, 4) == "www.") || + (ch=='f' && mText.mid(mPos, 4) == "ftp.") || + (ch=='n' && mText.mid(mPos, 5) == "news:"); + // note: no "file:" for security reasons +} + +bool LinkLocator::isEmptyUrl(const TQString& url) +{ + return url.isEmpty() || + url == "http://" || + url == "https://" || + url == "fish://" || + url == "ftp://" || + url == "ftps://" || + url == "sftp://" || + url == "smb://" || + url == "vnc://" || + url == "mailto" || + url == "www" || + url == "ftp" || + url == "news" || + url == "news://"; +} + +TQString LinkLocator::getEmailAddress() +{ + TQString address; + + if ( mText[mPos] == '@' ) { + // the following characters are allowed in a dot-atom (RFC 2822): + // a-z A-Z 0-9 . ! # $ % & ' * + - / = ? ^ _ ` { | } ~ + const TQString allowedSpecialChars = TQString(".!#$%&'*+-/=?^_`{|}~"); + + // determine the local part of the email address + int start = mPos - 1; + while ( start >= 0 && mText[start].tqunicode() < 128 && + ( mText[start].isLetterOrNumber() || + mText[start] == '@' || // allow @ to find invalid email addresses + allowedSpecialChars.find( mText[start] ) != -1 ) ) { + if ( mText[start] == '@' ) + return TQString(); // local part contains '@' -> no email address + --start; + } + ++start; + // we assume that an email address starts with a letter or a digit + while ( ( start < mPos ) && !mText[start].isLetterOrNumber() ) + ++start; + if ( start == mPos ) + return TQString(); // local part is empty -> no email address + + // determine the domain part of the email address + int dotPos = INT_MAX; + int end = mPos + 1; + while ( end < (int)mText.length() && + ( mText[end].isLetterOrNumber() || + mText[end] == '@' || // allow @ to find invalid email addresses + mText[end] == '.' || + mText[end] == '-' ) ) { + if ( mText[end] == '@' ) + return TQString(); // domain part contains '@' -> no email address + if ( mText[end] == '.' ) + dotPos = TQMIN( dotPos, end ); // remember index of first dot in domain + ++end; + } + // we assume that an email address ends with a letter or a digit + while ( ( end > mPos ) && !mText[end - 1].isLetterOrNumber() ) + --end; + if ( end == mPos ) + return TQString(); // domain part is empty -> no email address + if ( dotPos >= end ) + return TQString(); // domain part doesn't contain a dot + + if ( end - start > maxAddressLen() ) + return TQString(); // too long -> most likely no email address + address = mText.mid( start, end - start ); + + mPos = end - 1; + } + return address; +} + +TQString LinkLocator::convertToHtml(const TQString& plainText, int flags, + int maxUrlLen, int maxAddressLen) +{ + LinkLocator locator(plainText); + locator.setMaxUrlLen(maxUrlLen); + locator.setMaxAddressLen(maxAddressLen); + + TQString str; + TQString result((TQChar*)0, (int)locator.mText.length() * 2); + TQChar ch; + int x; + bool startOfLine = true; + TQString emoticon; + + for (locator.mPos = 0, x = 0; locator.mPos < (int)locator.mText.length(); locator.mPos++, x++) + { + ch = locator.mText[locator.mPos]; + if ( flags & PreserveSpaces ) + { + if (ch==' ') + { + if (startOfLine) { + result += " "; + locator.mPos++, x++; + startOfLine = false; + } + while (locator.mText[locator.mPos] == ' ') + { + result += " "; + locator.mPos++, x++; + if (locator.mText[locator.mPos] == ' ') { + result += " "; + locator.mPos++, x++; + } + } + locator.mPos--, x--; + continue; + } + else if (ch=='\t') + { + do + { + result += " "; + x++; + } + while((x&7) != 0); + x--; + startOfLine = false; + continue; + } + } + if (ch=='\n') + { + result += "
"; + startOfLine = true; + x = -1; + continue; + } + + startOfLine = false; + if (ch=='&') + result += "&"; + else if (ch=='"') + result += """; + else if (ch=='<') + result += "<"; + else if (ch=='>') + result += ">"; + else + { + const int start = locator.mPos; + if ( !(flags & IgnoreUrls) ) { + str = locator.getUrl(); + if (!str.isEmpty()) + { + TQString hyperlink; + if(str.left(4) == "www.") + hyperlink = "http://" + str; + else if(str.left(4) == "ftp.") + hyperlink = "ftp://" + str; + else + hyperlink = str; + + str = str.replace('&', "&"); + result += "" + str + ""; + x += locator.mPos - start; + continue; + } + str = locator.getEmailAddress(); + if(!str.isEmpty()) + { + // len is the length of the local part + int len = str.find('@'); + TQString localPart = str.left(len); + + // remove the local part from the result (as '&'s have been expanded to + // & we have to take care of the 4 additional characters per '&') + result.truncate(result.length() - len - (localPart.contains('&')*4)); + x -= len; + + result += "" + str + ""; + x += str.length() - 1; + continue; + } + } + if ( flags & ReplaceSmileys ) { + str = locator.getEmoticon(); + if ( ! str.isEmpty() ) { + result += str; + x += locator.mPos - start; + continue; + } + } + if ( flags & HighlightText ) { + str = locator.highlightedText(); + if ( !str.isEmpty() ) { + result += str; + x += locator.mPos - start; + continue; + } + } + result += ch; + } + } + + return result; +} + +TQString LinkLocator::pngToDataUrl( const TQString & iconPath ) +{ + if ( iconPath.isEmpty() ) + return TQString(); + + TQFile pngFile( iconPath ); + if ( !pngFile.open( IO_ReadOnly | IO_Raw ) ) + return TQString(); + + TQByteArray ba = pngFile.readAll(); + pngFile.close(); + return TQString::tqfromLatin1("data:image/png;base64,%1") + .tqarg( KCodecs::base64Encode( ba ).data() ); +} + + +TQString LinkLocator::getEmoticon() +{ + // smileys have to be prepended by whitespace + if ( ( mPos > 0 ) && !mText[mPos-1].isSpace() ) + return TQString(); + + // since smileys start with ':', ';', '(' or '8' short circuit method + const TQChar ch = mText[mPos]; + if ( ch !=':' && ch != ';' && ch != '(' && ch != '8' ) + return TQString(); + + // find the end of the smiley (a smiley is at most 4 chars long and ends at + // lineend or whitespace) + const int MinSmileyLen = 2; + const int MaxSmileyLen = 4; + int smileyLen = 1; + while ( ( smileyLen <= MaxSmileyLen ) && + ( mPos+smileyLen < (int)mText.length() ) && + !mText[mPos+smileyLen].isSpace() ) + smileyLen++; + if ( smileyLen < MinSmileyLen || smileyLen > MaxSmileyLen ) + return TQString(); + + const TQString smiley = mText.mid( mPos, smileyLen ); + if ( !s_smileyEmoticonNameMap->contains( smiley ) ) + return TQString(); // that's not a (known) smiley + + TQString htmlRep; + if ( s_smileyEmoticonHTMLCache->contains( smiley ) ) { + htmlRep = (*s_smileyEmoticonHTMLCache)[smiley]; + } + else { + const TQString imageName = (*s_smileyEmoticonNameMap)[smiley]; + +#if KDE_IS_VERSION( 3, 3, 91 ) + const TQString iconPath = locate( "emoticons", + EmotIcons::theme() + + TQString::tqfromLatin1( "/" ) + + imageName + TQString::tqfromLatin1(".png") ); +#else + const TQString iconPath = locate( "data", + TQString::tqfromLatin1( "kopete/pics/emoticons/" )+ + EmotIcons::theme() + + TQString::tqfromLatin1( "/" ) + + imageName + TQString::tqfromLatin1(".png") ); +#endif + + const TQString dataUrl = pngToDataUrl( iconPath ); + if ( dataUrl.isEmpty() ) { + htmlRep = TQString(); + } + else { + // create an image tag (the text in attribute alt is used + // for copy & paste) representing the smiley + htmlRep = TQString("") + .tqarg( dataUrl, + TQStyleSheet::escape( smiley ), + TQStyleSheet::escape( smiley ) ); + } + s_smileyEmoticonHTMLCache->insert( smiley, htmlRep ); + } + + if ( !htmlRep.isEmpty() ) + mPos += smileyLen - 1; + + return htmlRep; +} + +TQString LinkLocator::highlightedText() +{ + // formating symbols must be prepended with a whitespace + if ( ( mPos > 0 ) && !mText[mPos-1].isSpace() ) + return TQString(); + + const TQChar ch = mText[mPos]; + if ( ch != '/' && ch != '*' && ch != '_' ) + return TQString(); + + TQRegExp re = TQRegExp( TQString("\\%1([0-9A-Za-z]+)\\%2").tqarg( ch ).tqarg( ch ) ); + if ( re.search( mText, mPos ) == mPos ) { + uint length = re.matchedLength(); + // there must be a whitespace after the closing formating symbol + if ( mPos + length < mText.length() && !mText[mPos + length].isSpace() ) + return TQString(); + mPos += length - 1; + switch ( ch.latin1() ) { + case '*': + return "" + re.cap( 1 ) + ""; + case '_': + return "" + re.cap( 1 ) + ""; + case '/': + return "" + re.cap( 1 ) + ""; + } + } + return TQString(); +} + diff --git a/libtdepim/linklocator.h b/libtdepim/linklocator.h new file mode 100644 index 000000000..4597d836b --- /dev/null +++ b/libtdepim/linklocator.h @@ -0,0 +1,190 @@ +/* + * linklocator.h + * + * Copyright (c) 2002 Dave Corrie + * + * This file is part of KMail. + * + * KMail 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 LINKLOCATOR_H_INCLUDED +#define LINKLOCATOR_H_INCLUDED + +#include +#include + +#include + +/** + * LinkLocator assists in identifying sections of text that can + * usefully be converted in hyperlinks in html. It is intended + * to be used in two ways: either by calling @ref convertToHtml() + * to convert a plaintext string into html, or to be derived from + * where more control is needed. + * + * @short Identifies URLs and email addresses embedded in plaintext. + * @author Dave Corrie + */ +class KDE_EXPORT LinkLocator +{ +public: + /** + * Constructs a LinkLocator that will search a plaintext string + * from a given starting point. + * + * @param text The string in which to search. + * @param pos An index into 'text' from where the search + * should begin. + */ + LinkLocator(const TQString& text, int pos = 0); + + /** + * Sets the maximum length of URLs that will be matched by + * @ref getUrl(). By default, this is set to 4096 + * characters. The reason for this limit is that there may + * be possible security implications in handling URLs of + * unlimited length. + * + * @param length The new maximum length of URLs that will be + * matched by @ref getUrl(). + */ + void setMaxUrlLen(int length); + + /** + * @return The current limit on the maximum length of a URL. + * + * @see setMaxUrlLen(). + */ + int maxUrlLen() const; + + /** + * Sets the maximum length of email addresses that will be + * matched by @ref getEmailAddress(). By default, this is + * set to 255 characters. The reason for this limit is that + * there may be possible security implications in handling + * addresses of unlimited length. + * + * @param length The new maximum length of email addresses + * that will be matched by @ref getEmailAddress(). + */ + void setMaxAddressLen(int length); + + /** + * @return The current limit on the maximum length of an email + * address. + * + * @see setMaxAddressLen(). + */ + int maxAddressLen() const; + + /** + * Attempts to grab a URL starting at the current scan position. + * If there is no URL at the current scan position, then an empty + * string is returned. If a URL is found, the current scan position + * is set to the index of the last character in the URL. + * + * @return The URL at the current scan position, or an empty string. + */ + TQString getUrl(); + + /** + * Attempts to grab an email address. If there is an @ symbol at the + * current scan position, then the text will be searched both backwards + * and forwards to find the email address. If there is no @ symbol at + * the current scan position, an empty string is returned. If an address + * is found, then the current scan position is set to the index of the + * last character in the address. + * + * @return The email address at the current scan position, or an empty + * string. + */ + TQString getEmailAddress(); + + /** + * Converts plaintext into html. The following characters are converted to HTML + * entities: & " < >. Newlines are also preserved. + * + * @param plainText The text to be converted into HTML. + * @param flags The flags to consider when processing plainText. + * Currently supported flags are: + * - PreserveSpaces, preserves the appearance of + * sequences of space and tab + * characters in the resulting HTML. + * - ReplaceSmileys, replace text smileys with + * emoticon images. + * - IgnoreUrls, doesn't parse any URLs. + * - HighlightText, interprets text highlighting markup + * like *bold*, _underlined_ and + * /italic/. + * @param maxUrlLen The maximum length of permitted URLs. (See + * @ref maxUrlLen().) + * @param maxAddressLen The maximum length of permitted email addresses. + * (See @ref maxAddressLen().) + * @return An HTML version of the text supplied in the 'plainText' parameter, + * suitable for inclusion in the BODY of an HTML document. + */ + static TQString convertToHtml(const TQString& plainText, int flags = 0, + int maxUrlLen = 4096, int maxAddressLen = 255); + + static const int PreserveSpaces = 0x01; + static const int ReplaceSmileys = 0x02; + static const int IgnoreUrls = 0x04; + static const int HighlightText = 0x08; + + /** Embed the given PNG image into a data URL. + * @param iconPath path to the PNG image + * @return A data URL, TQString() if the image could not be read. + */ + static TQString pngToDataUrl( const TQString & iconPath ); + +protected: + /** + * The plaintext string being scanned for URLs and email addresses. + */ + TQString mText; + /** + * The current scan position. + */ + int mPos; + +private: + bool atUrl() const; + bool isEmptyUrl(const TQString& url); + + /** + * Replaces smiley text with an tag containing the relevant image. + * For an emoticon text to be recognised it has to match + * "(^|\s+)text(\s+|$)" + * @return An HTML String with for an emoticon + */ + TQString getEmoticon(); + /** + * Highlight text according to *bold*, /italic/ and _underlined_ markup. + * @return A HTML string. + */ + TQString highlightedText(); + + int mMaxUrlLen; + int mMaxAddressLen; + + // maps the smiley text to the corresponding emoticon name + static TQMap *s_smileyEmoticonNameMap; + // cache for the HTML representation of a smiley + static TQMap *s_smileyEmoticonHTMLCache; +}; + +#endif // LINKLOCATOR_H_INCLUDED + diff --git a/libtdepim/maillistdrag.cpp b/libtdepim/maillistdrag.cpp new file mode 100644 index 000000000..a9e2e9fa0 --- /dev/null +++ b/libtdepim/maillistdrag.cpp @@ -0,0 +1,259 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Don Sanders + Copyright (c) 2005 George Staikos + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "maillistdrag.h" +#include +#include +#include +#include +#include +#include + +using namespace KPIM; + +MailSummary::MailSummary( TQ_UINT32 serialNumber, TQString messageId, + TQString subject, TQString from, TQString to, + time_t date ) + : mSerialNumber( serialNumber ), mMessageId( messageId ), + mSubject( subject ), mFrom( from ), mTo( to ), mDate( date ) +{} + +TQ_UINT32 MailSummary::serialNumber() const +{ + return mSerialNumber; +} + +TQString MailSummary::messageId() +{ + return mMessageId; +} + +TQString MailSummary::subject() +{ + return mSubject; +} + +TQString MailSummary::from() +{ + return mFrom; +} + +TQString MailSummary::to() +{ + return mTo; +} + +time_t MailSummary::date() +{ + return mDate; +} + +void MailSummary::set( TQ_UINT32 serialNumber, TQString messageId, + TQString subject, TQString from, TQString to, time_t date ) +{ + mSerialNumber = serialNumber; + mMessageId = messageId; + mSubject = subject; + mFrom = from; + mTo = to; + mDate = date; +} + +MailListDrag::MailListDrag( MailList mailList, TQWidget * parent, MailTextSource *src ) + : TQStoredDrag( MailListDrag::format(), parent ), _src(src) +{ + setMailList( mailList ); +} + +MailListDrag::~MailListDrag() +{ + delete _src; + _src = 0; +} + +const char* MailListDrag::format() +{ + return "x-kmail-drag/message-list"; +} + +bool MailListDrag::canDecode( TQMimeSource *e ) +{ + return e->provides( MailListDrag::format() ); +} + +// Have to define before use +TQDataStream& operator<< ( TQDataStream &s, MailSummary &d ) +{ + s << d.serialNumber(); + s << d.messageId(); + s << d.subject(); + s << d.from(); + s << d.to(); + s << d.date(); + return s; +} + +TQDataStream& operator>> ( TQDataStream &s, MailSummary &d ) +{ + TQ_UINT32 serialNumber; + TQString messageId, subject, from, to; + time_t date; + s >> serialNumber; + s >> messageId; + s >> subject; + s >> from; + s >> to; + s >> date; + d.set( serialNumber, messageId, subject, from, to, date ); + return s; +} + +TQDataStream& operator<< ( TQDataStream &s, MailList &mailList ) +{ + MailList::iterator it; + for (it = mailList.begin(); it != mailList.end(); ++it) { + MailSummary mailDrag = *it; + s << mailDrag; + } + return s; +} + +TQDataStream& operator>> ( TQDataStream &s, MailList &mailList ) +{ + mailList.clear(); + MailSummary mailDrag; + while (!s.atEnd()) { + s >> mailDrag; + mailList.append( mailDrag ); + } + return s; +} + +bool MailListDrag::decode( TQDropEvent* e, MailList& mailList ) +{ + TQByteArray payload = e->tqencodedData( MailListDrag::format() ); + TQDataStream buffer( payload, IO_ReadOnly ); + if ( payload.size() ) { + e->accept(); + buffer >> mailList; + return TRUE; + } + return FALSE; +} + +bool MailListDrag::decode( TQByteArray& payload, MailList& mailList ) +{ + TQDataStream stream( payload, IO_ReadOnly ); + if ( payload.size() ) { + stream >> mailList; + return TRUE; + } + return FALSE; +} + +bool MailListDrag::decode( TQDropEvent* e, TQByteArray &a ) +{ + MailList mailList; + if (decode( e, mailList )) { + MailList::iterator it; + TQBuffer buffer( a ); + buffer.open( IO_WriteOnly ); + TQDataStream stream( &buffer ); + for (it = mailList.begin(); it != mailList.end(); ++it) { + MailSummary mailDrag = *it; + stream << mailDrag.serialNumber(); + } + buffer.close(); + return TRUE; + } + return FALSE; +} + +void MailListDrag::setMailList( MailList mailList ) +{ + TQByteArray array; + TQBuffer buffer( array ); + buffer.open( IO_WriteOnly); + TQDataStream stream( array, IO_WriteOnly ); + stream << mailList; + buffer.close(); + setEncodedData( array ); +} + +const char *MailListDrag::format(int i) const +{ + if (_src) { + if (i == 0) { + return "message/rfc822"; + } else { + return TQStoredDrag::format(i - 1); + } + } + + return TQStoredDrag::format(i); +} + +bool MailListDrag::provides(const char *mimeType) const +{ + if (_src && TQCString(mimeType) == "message/rfc822") { + return true; + } + + return TQStoredDrag::provides(mimeType); +} + +TQByteArray MailListDrag::tqencodedData(const char *mimeType) const +{ + if (TQCString(mimeType) != "message/rfc822") { + return TQStoredDrag::tqencodedData(mimeType); + } + + TQByteArray rc; + if (_src) { + MailList ml; + TQByteArray enc = TQStoredDrag::tqencodedData(format()); + decode(enc, ml); + + KProgressDialog *dlg = new KProgressDialog(0, 0, TQString(), i18n("Retrieving and storing messages..."), true); + dlg->setAllowCancel(true); + dlg->progressBar()->setTotalSteps(ml.count()); + int i = 0; + dlg->progressBar()->setValue(i); + dlg->show(); + + TQTextStream *ts = new TQTextStream(rc, IO_WriteOnly); + for (MailList::ConstIterator it = ml.begin(); it != ml.end(); ++it) { + MailSummary mailDrag = *it; + *ts << _src->text(mailDrag.serialNumber()); + if (dlg->wasCancelled()) { + break; + } + dlg->progressBar()->setValue(++i); + kapp->eventLoop()->processEvents(TQEventLoop::ExcludeSocketNotifiers); + } + + delete dlg; + delete ts; + } + return rc; +} + diff --git a/libtdepim/maillistdrag.h b/libtdepim/maillistdrag.h new file mode 100644 index 000000000..f13e59ebf --- /dev/null +++ b/libtdepim/maillistdrag.h @@ -0,0 +1,135 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Don Sanders + Copyright (c) 2005 George Staikos + +/** + * KDEPIM classes for drag and drop of mails + * + * // Code example for drag and drop enabled widget + * + * void SomeWidget::contentsDropEvent(TQDropEvent *e) + * { + * if (e->provides(MailListDrag::format())) { + * MailList mailList; + * MailListDrag::decode( e, mailList ); + * ... + **/ + +namespace KPIM { + +class KDE_EXPORT MailSummary +{ +public: + MailSummary( TQ_UINT32 serialNumber, TQString messageId, TQString subject, + TQString from, TQString to, time_t date ); + MailSummary() {} + ~MailSummary() {} + + /*** Set fields for this mail summary ***/ + void set( TQ_UINT32, TQString, TQString, TQString, TQString, time_t ); + + /*** KMail unique identification number ***/ + TQ_UINT32 serialNumber() const; + + /*** MD5 checksum of message identification string ***/ + TQString messageId(); + + /*** Subject of the message including prefixes ***/ + TQString subject(); + + /*** Simplified from address ***/ + TQString from(); + + /** Simplified to address ***/ + TQString to(); + + /*** Date the message was sent ***/ + time_t date(); + +private: + TQ_UINT32 mSerialNumber; + TQString mMessageId, mSubject, mFrom, mTo; + time_t mDate; +}; + +// List of mail summaries +typedef TQValueList MailList; + +// Object for the drag object to call-back for message fulltext +class KDE_EXPORT MailTextSource { +public: + MailTextSource() {} + virtual ~MailTextSource() {} + + virtual TQCString text(TQ_UINT32 serialNumber) const = 0; +}; + +// Drag and drop object for mails +class KDE_EXPORT MailListDrag : public TQStoredDrag +{ +public: + // Takes ownership of "src" and deletes it when done + MailListDrag( MailList, TQWidget * parent = 0, MailTextSource *src = 0 ); + ~MailListDrag(); + + const char *format(int i) const; + + bool provides(const char *mimeType) const; + + TQByteArray tqencodedData(const char *) const; + + /* Reset the list of mail summaries */ + void setMailList( MailList ); + + /* The format for this drag - "x-kmail-drag/message-list" */ + static const char* format(); + + /* Returns TRUE if the information in e can be decoded into a TQString; + otherwsie returns FALSE */ + static bool canDecode( TQMimeSource* e ); + + /* Attempts to decode the dropped information; + Returns TRUE if successful; otherwise return false */ + static bool decode( TQDropEvent* e, MailList& s ); + + /* Attempts to decode the serialNumbers of the dropped information; + Returns TRUE if successful; otherwise return false */ + static bool decode( TQDropEvent* e, TQByteArray& a ); + + /* Attempts to decode the encoded MailList; + Returns TRUE if successful; otherwise return false */ + static bool decode( TQByteArray& a, MailList& s ); + +private: + MailTextSource *_src; +}; + +} +#endif /*maillistdrag_h*/ diff --git a/libtdepim/overlaywidget.cpp b/libtdepim/overlaywidget.cpp new file mode 100644 index 000000000..ac05d84fd --- /dev/null +++ b/libtdepim/overlaywidget.cpp @@ -0,0 +1,92 @@ +/** -*- c++ -*- + * overlaywidget.h + * + * Copyright (c) 2004 David Faure + * + * 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; version 2 of the License + * + * 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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 "overlaywidget.h" +using namespace KPIM; + +OverlayWidget::OverlayWidget( TQWidget* alignWidget, TQWidget* parent, const char* name ) + : TQHBox( parent, name ), mAlignWidget( 0 ) +{ + setAlignWidget( alignWidget ); +} + +OverlayWidget::~OverlayWidget() +{ +} + +void OverlayWidget::reposition() +{ + if ( !mAlignWidget ) + return; + // p is in the alignWidget's coordinates + TQPoint p; + // We are always above the alignWidget, right-aligned with it. + p.setX( mAlignWidget->width() - width() ); + p.setY( -height() ); + // Position in the toplevelwidget's coordinates + TQPoint pTopLevel = mAlignWidget->mapTo( tqtopLevelWidget(), p ); + // Position in the widget's parentWidget coordinates + TQPoint pParent = parentWidget()->mapFrom( tqtopLevelWidget(), pTopLevel ); + // Move 'this' to that position. + move( pParent ); +} + +void OverlayWidget::setAlignWidget( TQWidget * w ) +{ + if (w == mAlignWidget) + return; + + if (mAlignWidget) + mAlignWidget->removeEventFilter(this); + + mAlignWidget = w; + + if (mAlignWidget) + mAlignWidget->installEventFilter(this); + + reposition(); +} + +bool OverlayWidget::eventFilter( TQObject* o, TQEvent* e) +{ + if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(mAlignWidget) && + ( e->type() == TQEvent::Move || e->type() == TQEvent::Resize ) ) { + reposition(); + } + return TQFrame::eventFilter(o,e); +} + +void OverlayWidget::resizeEvent( TQResizeEvent* ev ) +{ + reposition(); + TQFrame::resizeEvent( ev ); +} + +#include "overlaywidget.moc" diff --git a/libtdepim/overlaywidget.h b/libtdepim/overlaywidget.h new file mode 100644 index 000000000..9e611fb92 --- /dev/null +++ b/libtdepim/overlaywidget.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- + * overlaywidget.h + * + * Copyright (c) 2004 David Faure + * + * 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; version 2 of the License + * + * 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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 OVERLAYWIDGET_H +#define OVERLAYWIDGET_H + +#include + +namespace KPIM { + +/** + * This is a widget that can align itself with another one, without using a tqlayout, + * so that it can actually be on top of other widgets. + * Currently the only supported type of tqalignment is "right aligned, on top of the other widget". + * + * OverlayWidget inherits TQHBox for convenience purposes (tqlayout, and frame) + */ +class OverlayWidget : public TQHBox +{ + Q_OBJECT + TQ_OBJECT + +public: + OverlayWidget( TQWidget* alignWidget, TQWidget* parent, const char* name = 0 ); + ~OverlayWidget(); + + TQWidget * alignWidget() { return mAlignWidget; } + void setAlignWidget( TQWidget * alignWidget ); + +protected: + void resizeEvent( TQResizeEvent* ev ); + bool eventFilter( TQObject* o, TQEvent* e); + +private: + void reposition(); + +private: + TQWidget * mAlignWidget; +}; + +} // namespace + +#endif /* OVERLAYWIDGET_H */ + diff --git a/libtdepim/pics/CMakeLists.txt b/libtdepim/pics/CMakeLists.txt new file mode 100644 index 000000000..7cbe71d0a --- /dev/null +++ b/libtdepim/pics/CMakeLists.txt @@ -0,0 +1,15 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +install( FILES + addresseelineedit.png clicklineedit.png + kdateedit.png ktimeedit.png + DESTINATION ${DATA_INSTALL_DIR}/tdepimwidgets/pics ) diff --git a/libtdepim/pics/Makefile.am b/libtdepim/pics/Makefile.am new file mode 100644 index 000000000..c4c611966 --- /dev/null +++ b/libtdepim/pics/Makefile.am @@ -0,0 +1,6 @@ +tdepimwidgetsdata_DATA = addresseelineedit.png \ + clicklineedit.png kdateedit.png ktimeedit.png + +tdepimwidgetsdatadir = $(kde_datadir)/tdepimwidgets/pics + +EXTRA_DIST = $(tdepimwidgetsdata_DATA) diff --git a/libtdepim/pics/addresseelineedit.png b/libtdepim/pics/addresseelineedit.png new file mode 100644 index 000000000..81d313913 Binary files /dev/null and b/libtdepim/pics/addresseelineedit.png differ diff --git a/libtdepim/pics/clicklineedit.png b/libtdepim/pics/clicklineedit.png new file mode 100644 index 000000000..ec40fb2f3 Binary files /dev/null and b/libtdepim/pics/clicklineedit.png differ diff --git a/libtdepim/pics/kdateedit.png b/libtdepim/pics/kdateedit.png new file mode 100644 index 000000000..e2fa34682 Binary files /dev/null and b/libtdepim/pics/kdateedit.png differ diff --git a/libtdepim/pics/ktimeedit.png b/libtdepim/pics/ktimeedit.png new file mode 100644 index 000000000..1b0d79afe Binary files /dev/null and b/libtdepim/pics/ktimeedit.png differ diff --git a/libtdepim/pimemoticons.kcfg b/libtdepim/pimemoticons.kcfg new file mode 100644 index 000000000..f06a7743a --- /dev/null +++ b/libtdepim/pimemoticons.kcfg @@ -0,0 +1,178 @@ + + + + + + + Default + + This allows you to change the emoticon theme that should be used. + + + + + angry_0 + angry_1 + + + bat_0 + bat_1 + + + cake_0 + + + cat_0 + + + + + confused_0 + confused_1 + confused_2 + confused_3 + cry_0 + cry_1 + cry_2 + cry_3 + + + dog_0 + embarassed_0 + embarassed_1 + + + film_0 + + + kiss_2 + kiss_3 + kiss_4 + kiss_5 + + + + + + omg_0 + omg_1 + omg_2 + omg_3 + + + + + + + sad_0 + sad_1 + + shade_1 + + smile_0 + smile_1 + smile_2 + star_0 + teeth_0 + teeth_1 + teeth_2 + teeth_3 + + + + + tongue_0 + tongue_1 + tongue_2 + tongue_3 + + + + + wink_0 + wink_1 + + + :-@ + :@ + + + :-[ + :[ + + + (^) + + + (@) + + + + + :-S + :S + :-s + :s + :'( + :'-( + ;-( + ;( + + + (&) + :-$ + :$ + + + (~) + + + :-X + :X + :-x + :x + + + + + + :-O + :O + :-o + :o + + + + + + + :-( + :( + + 8-) + + :-) + :) + :o) + (*) + :-D + :D + :-d + :d + + + + + :-P + :P + :-p + :p + + + + + ;-) + ;) + + + diff --git a/libtdepim/pimemoticons.kcfgc b/libtdepim/pimemoticons.kcfgc new file mode 100644 index 000000000..9121a7302 --- /dev/null +++ b/libtdepim/pimemoticons.kcfgc @@ -0,0 +1,5 @@ +File=pimemoticons.kcfg +ClassName=EmotIcons +Singleton=true +#ItemAccessors=true + diff --git a/libtdepim/pluginloader.h b/libtdepim/pluginloader.h new file mode 100644 index 000000000..6d38bbd18 --- /dev/null +++ b/libtdepim/pluginloader.h @@ -0,0 +1,135 @@ +/* -*- c++ -*- + This file is part of libtdepim. + + Copyright (c) 2002,2004 Marc Mutz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KPIM_SHARED_PLUGINLOADER_H__ +#define __KPIM_SHARED_PLUGINLOADER_H__ + +#include + +namespace KPIM { + + /** + * @short A generic plugin loader for when KPart::Plugin is overkill + * @author Marc Mutz based on KABC's FormatFactory + * + * This is a generic plugin loader / factory for small plugins that + * don't want to be TQObjects. + * + * @section Usage + * + * A PluginLoader takes two template arguments, T and + * T_config: + * + *
+ *
T
The type of object to return
+ *
T_config::mainfunc
The suffix of the factory function to call + * in the library to obtain a new object of type T. + * The string passed to KLibrary::symbol() is + * libName_mainfunc.
+ *
T_config::path
The search pattern for .desktop files + * containing the plugin descriptions. This is the string passed as + * the @p filter argument to + * KStandardDirs::findAllResources.
+ *
+ * + * The last two parameters being strings, they are passed via an + * encapsulating class, of which mainfunc and + * path are public static members: + * + *
+   * struct MyObjectPluginLoaderConfig {
+   *   static const char * const mainfunc;
+   *   static const char * const path;
+   * };
+   * const char * const MyObjectPluginLoaderConfig::mainfunc = "myapp_create_myobject";
+   * const char * const MyObjectPluginLoaderConfig::path = "myapp/plugins/ *.desktop";
+   * 
+ * + * You would then use a typedef to create a less unwieldy + * name for your plugin loader: + * + *
+   * typedef KPIM::PluginLoader< MyObject, MyObjectPluginLoaderConfig > MyObjectPluginLoader;
+   * 
+ * + * All of this is what the + * KPIM_DEFINE_PLUGIN_LOADER(pluginloadername,type,mainfunc,path) macro + * achieves. + * + **/ + template< typename T, typename T_config > + class KDE_EXPORT PluginLoader : public PluginLoaderBase { + protected: + PluginLoader() : PluginLoaderBase() {} + + private: + static PluginLoader * mSelf; + + public: + virtual ~PluginLoader() { mSelf = 0; } + + /** Returns the single instance of this loader. */ + static PluginLoader * instance() { + if ( !mSelf ) { + mSelf = new PluginLoader(); + mSelf->scan(); + } + return mSelf; + } + + /** Rescans the plugin directory to find any newly installed + plugins. + **/ + virtual void scan() { + doScan( T_config::path ); + } + + /** Returns a pointer to a plugin object (of type @p T) or a null + pointer if the type wasn't found. You can extend this method + for when you want to handle builtin types */ + virtual T * createForName( const TQString & type ) const { + void * main_func = mainFunc( type, T_config::mainfunc ); + if ( !main_func ) return 0; + + // cast to a pointer to a function returning T*, call it and + // return the result; don't you love C? ;-) + return ((T* (*)())( main_func ))(); + } + }; + + template< typename T, typename T_config > + PluginLoader * PluginLoader::mSelf = 0; + +} + +#define KPIM_DEFINE_PLUGIN_LOADER( pl, t, mf, p ) \ + namespace { /* don't pollute namespaces */ \ + struct KDE_EXPORT pl##Config { \ + static const char * const mainfunc; \ + static const char * const path; \ + }; \ + const char * const pl##Config::mainfunc = mf; \ + const char * const pl##Config::path = p; \ + } \ + typedef KPIM::PluginLoader< t, pl##Config > pl; \ + + +#endif // __KPIM_SHARED_PLUGINLOADER_H__ diff --git a/libtdepim/pluginloaderbase.cpp b/libtdepim/pluginloaderbase.cpp new file mode 100644 index 000000000..60a925efa --- /dev/null +++ b/libtdepim/pluginloaderbase.cpp @@ -0,0 +1,159 @@ +/* -*- c++ -*- + This file is part of libtdepim. + + Copyright (c) 2002,2004 Marc Mutz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 + +static kdbgstream warning() { + return kdWarning( 5300 ) << "PluginLoaderBase: "; +} +#ifndef NDEBUG +static kdbgstream debug( bool cond ) +#else +static kndbgstream debug( bool cond ) +#endif +{ + return kdDebug( cond, 5300 ) << "PluginLoaderBase: "; +} + +namespace KPIM { + + PluginLoaderBase::PluginLoaderBase() : d(0) {} + PluginLoaderBase::~PluginLoaderBase() {} + + + TQStringList PluginLoaderBase::types() const { + TQStringList result; + for ( TQMap< TQString, PluginMetaData >::const_iterator it = mPluginMap.begin(); + it != mPluginMap.end() ; ++it ) + result.push_back( it.key() ); + return result; + } + + const PluginMetaData * PluginLoaderBase::infoForName( const TQString & type ) const { + return mPluginMap.contains( type ) ? &(mPluginMap[type]) : 0 ; + } + + + void PluginLoaderBase::doScan( const char * path ) { + mPluginMap.clear(); + + const TQStringList list = + KGlobal::dirs()->findAllResources( "data", path, true, true ); + for ( TQStringList::const_iterator it = list.begin() ; + it != list.end() ; ++it ) { + KSimpleConfig config( *it, true ); + if ( config.hasGroup( "Misc" ) && config.hasGroup( "Plugin" ) ) { + config.setGroup( "Plugin" ); + + const TQString type = config.readEntry( "Type" ).lower(); + if ( type.isEmpty() ) { + warning() << "missing or empty [Plugin]Type value in \"" + << *it << "\" - skipping" << endl; + continue; + } + + const TQString library = config.readEntry( "X-KDE-Library" ); + if ( library.isEmpty() ) { + warning() << "missing or empty [Plugin]X-KDE-Library value in \"" + << *it << "\" - skipping" << endl; + continue; + } + + config.setGroup( "Misc" ); + + TQString name = config.readEntry( "Name" ); + if ( name.isEmpty() ) { + warning() << "missing or empty [Misc]Name value in \"" + << *it << "\" - inserting default name" << endl; + name = i18n("Unnamed plugin"); + } + + TQString comment = config.readEntry( "Comment" ); + if ( comment.isEmpty() ) { + warning() << "missing or empty [Misc]Comment value in \"" + << *it << "\" - inserting default name" << endl; + comment = i18n("No description available"); + } + + mPluginMap.insert( type, PluginMetaData( library, name, comment ) ); + } else { + warning() << "Desktop file \"" << *it + << "\" doesn't seem to describe a plugin " + << "(misses Misc and/or Plugin group)" << endl; + } + } + } + + void * PluginLoaderBase::mainFunc( const TQString & type, + const char * mf_name ) const { + if ( type.isEmpty() || !mPluginMap.contains( type ) ) + return 0; + + const TQString libName = mPluginMap[ type ].library; + if ( libName.isEmpty() ) + return 0; + + const KLibrary * lib = openLibrary( libName ); + if ( !lib ) + return 0; + + mPluginMap[ type ].loaded = true; + + const TQString factory_name = libName + '_' + mf_name; + if ( !lib->hasSymbol( factory_name.latin1() ) ) { + warning() << "No symbol named \"" << factory_name.latin1() << "\" (" + << factory_name << ") was found in library \"" << libName + << "\"" << endl; + return 0; + } + + return lib->symbol( factory_name.latin1() ); + } + + const KLibrary * PluginLoaderBase::openLibrary( const TQString & libName ) const { + + const TQString path = KLibLoader::findLibrary( TQFile::encodeName( libName ) ); + + if ( path.isEmpty() ) { + warning() << "No plugin library named \"" << libName + << "\" was found!" << endl; + return 0; + } + + const KLibrary * library = KLibLoader::self()->library( TQFile::encodeName( path ) ); + + debug( !library ) << "Could not load library '" << libName << "'" << endl; + + return library; + } + + +} // namespace KMime diff --git a/libtdepim/pluginloaderbase.h b/libtdepim/pluginloaderbase.h new file mode 100644 index 000000000..766372787 --- /dev/null +++ b/libtdepim/pluginloaderbase.h @@ -0,0 +1,86 @@ +/* -*- c++ -*- + This file is part of libtdepim. + + Copyright (c) 2002,2004 Marc Mutz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __LIBKDEPIM_PLUGINLOADERBASE_H__ +#define __LIBKDEPIM_PLUGINLOADERBASE_H__ + +#include +#include + +#include + +class KLibrary; +class TQStringList; + +namespace KPIM { + + class KDE_EXPORT PluginMetaData { + public: + PluginMetaData() {} + PluginMetaData( const TQString & lib, const TQString & name, + const TQString & comment ) + : library( lib ), nameLabel( name ), + descriptionLabel( comment ), loaded( false ) {} + TQString library; + TQString nameLabel; + TQString descriptionLabel; + mutable bool loaded; + }; + + class KDE_EXPORT PluginLoaderBase { + protected: + PluginLoaderBase(); + virtual ~PluginLoaderBase(); + + public: + /** Returns a list of all available plugin objects (of kind @p T) */ + TQStringList types() const; + + /** Returns the @ref PluginMetaData structure for a given type */ + const PluginMetaData * infoForName( const TQString & type ) const; + + /** Overload this method in subclasses to call @ref doScan with + the right @p path argument */ + virtual void scan() = 0; + + protected: + /** Rescans the plugin directory to find any newly installed + plugins. Extend this method in subclasses to add any + builtins. Subclasses must call this explicitely. It's not + called for them in the constructor. + **/ + void doScan( const char * path ); + + /** Returns a pointer to symbol @p main_func in the library that + implements the plugin of type @p type */ + void * mainFunc( const TQString & type, const char * main_func ) const; + + private: + const KLibrary * openLibrary( const TQString & libName ) const; + TQMap< TQString, PluginMetaData > mPluginMap; + + class Private; + Private * d; + }; + +} // namespace KMime + +#endif // __LIBKDEPIM_PLUGINLOADERBASE_H__ diff --git a/libtdepim/progressdialog.cpp b/libtdepim/progressdialog.cpp new file mode 100644 index 000000000..bd5b594c6 --- /dev/null +++ b/libtdepim/progressdialog.cpp @@ -0,0 +1,437 @@ +/** -*- c++ -*- + * progressdialog.cpp + * + * Copyright (c) 2004 Till Adam , + * David Faure + * + * 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; version 2 of the License + * + * 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "progressdialog.h" +#include "progressmanager.h" +#include "ssllabel.h" +#include + +namespace KPIM { + +class TransactionItem; + +TransactionItemView::TransactionItemView( TQWidget * parent, + const char * name, + WFlags f ) + : TQScrollView( parent, name, f ) { + setFrameStyle( NoFrame ); + mBigBox = new TQVBox( viewport() ); + mBigBox->setSpacing( 5 ); + addChild( mBigBox ); + setResizePolicy( TQScrollView::AutoOneFit ); // Fit so that the box expands horizontally +} + +TransactionItem* TransactionItemView::addTransactionItem( ProgressItem* item, bool first ) +{ + TransactionItem *ti = new TransactionItem( mBigBox, item, first ); + ti->hide(); + TQTimer::singleShot( 1000, ti, TQT_SLOT( show() ) ); + return ti; +} + +void TransactionItemView::resizeContents( int w, int h ) +{ + // (handling of TQEvent::LayoutHint in TQScrollView calls this method) + //kdDebug(5300) << k_funcinfo << w << "," << h << endl; + TQScrollView::resizeContents( w, h ); + // Tell the tqlayout in the parent (progressdialog) that our size changed + updateGeometry(); + // Resize the parent (progressdialog) - this works but resize horizontally too often + //parentWidget()->adjustSize(); + + TQApplication::sendPostedEvents( 0, TQEvent::ChildInserted ); + TQApplication::sendPostedEvents( 0, TQEvent::LayoutHint ); + TQSize sz = parentWidget()->tqsizeHint(); + int currentWidth = parentWidget()->width(); + // Don't resize to sz.width() every time when it only reduces a little bit + if ( currentWidth < sz.width() || currentWidth > sz.width() + 100 ) + currentWidth = sz.width(); + parentWidget()->resize( currentWidth, sz.height() ); +} + +TQSize TransactionItemView::tqsizeHint() const +{ + return tqminimumSizeHint(); +} + +TQSize TransactionItemView::tqminimumSizeHint() const +{ + int f = 2 * frameWidth(); + // Make room for a vertical scrollbar in all cases, to avoid a horizontal one + int vsbExt = verticalScrollBar()->tqsizeHint().width(); + int minw = tqtopLevelWidget()->width() / 3; + int maxh = tqtopLevelWidget()->height() / 2; + TQSize sz( mBigBox->tqminimumSizeHint() ); + sz.setWidth( TQMAX( sz.width(), minw ) + f + vsbExt ); + sz.setHeight( TQMIN( sz.height(), maxh ) + f ); + return sz; +} + + +void TransactionItemView::slotLayoutFirstItem() +{ + /* + The below relies on some details in TQt's behaviour regarding deleting + objects. This slot is called from the destroyed signal of an item just + going away. That item is at that point still in the list of chilren, but + since the vtable is already gone, it will have type TQObject. The first + one with both the right name and the right class therefor is what will + be the first item very shortly. That's the one we want to remove the + hline for. + */ + TQObject *o = mBigBox->child( "TransactionItem", "KPIM::TransactionItem" ); + TransactionItem *ti = dynamic_cast( o ); + if ( ti ) { + ti->hideHLine(); + } +} + + +// ---------------------------------------------------------------------------- + +TransactionItem::TransactionItem( TQWidget* parent, + ProgressItem *item, bool first ) + : TQVBox( parent, "TransactionItem" ), mCancelButton( 0 ), mItem( item ) + +{ + setSpacing( 2 ); + setMargin( 2 ); + tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) ); + + mFrame = new TQFrame( this ); + mFrame->setFrameShape( TQFrame::HLine ); + mFrame->setFrameShadow( TQFrame::Raised ); + mFrame->show(); + setStretchFactor( mFrame, 3 ); + + TQHBox *h = new TQHBox( this ); + h->setSpacing( 5 ); + + mItemLabel = new TQLabel( item->label(), h ); + // always interpret the label text as RichText, but disable word wrapping + mItemLabel->setTextFormat( TQt::RichText ); + mItemLabel->tqsetAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::SingleLine ); + h->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) ); + + mProgress = new TQProgressBar( 100, h ); + mProgress->setProgress( item->progress() ); + + if ( item->canBeCanceled() ) { + mCancelButton = new TQPushButton( SmallIcon( "cancel" ), TQString(), h ); + TQToolTip::add( mCancelButton, i18n("Cancel this operation.") ); + connect ( mCancelButton, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotItemCanceled() )); + } + + h = new TQHBox( this ); + h->setSpacing( 5 ); + h->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) ); + mSSLLabel = new SSLLabel( h ); + mSSLLabel->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) ); + mItemtqStatus = new TQLabel( item->status(), h ); + // always interpret the status text as RichText, but disable word wrapping + mItemtqStatus->setTextFormat( TQt::RichText ); + mItemtqStatus->tqsetAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::SingleLine ); + // richtext leads to tqsizeHint acting as if wrapping was enabled though, + // so make sure we only ever have the height of one line. + mItemtqStatus->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Ignored ) ); + mItemtqStatus->setFixedHeight( mItemLabel->tqsizeHint().height() ); + setCrypto( item->usesCrypto() ); + if( first ) hideHLine(); +} + +TransactionItem::~TransactionItem() +{ +} + +void TransactionItem::hideHLine() +{ + mFrame->hide(); +} + +void TransactionItem::setProgress( int progress ) +{ + mProgress->setProgress( progress ); +} + +void TransactionItem::setLabel( const TQString& label ) +{ + mItemLabel->setText( label ); +} + +void TransactionItem::setqStatus( const TQString& status ) +{ + mItemtqStatus->setText( status ); +} + +void TransactionItem::setCrypto( bool on ) +{ + if (on) + mSSLLabel->setEncrypted( true ); + else + mSSLLabel->setEncrypted( false ); + + mSSLLabel->setState( mSSLLabel->lastState() ); +} + +void TransactionItem::setTotalSteps( int totalSteps ) +{ + mProgress->setTotalSteps( totalSteps ); +} + +void TransactionItem::slotItemCanceled() +{ + if ( mItem ) + mItem->cancel(); +} + + +void TransactionItem::addSubTransaction( ProgressItem* /*item*/ ) +{ + +} + + +// --------------------------------------------------------------------------- + +ProgressDialog::ProgressDialog( TQWidget* alignWidget, TQWidget* parent, const char* name ) + : OverlayWidget( alignWidget, parent, name ), mWasLastShown( false ) +{ + setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); // TQFrame + setSpacing( 0 ); // TQHBox + setMargin( 1 ); + + mScrollView = new TransactionItemView( this, "ProgressScrollView" ); + + // No more close button for now, since there is no more autoshow + /* + TQVBox* rightBox = new TQVBox( this ); + TQToolButton* pbClose = new TQToolButton( rightBox ); + pbClose->setAutoRaise(true); + pbClose->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) ); + pbClose->setFixedSize( 16, 16 ); + pbClose->setIconSet( KGlobal::iconLoader()->loadIconSet( "fileclose", KIcon::Small, 14 ) ); + TQToolTip::add( pbClose, i18n( "Hide detailed progress window" ) ); + connect(pbClose, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotClose())); + TQWidget* spacer = new TQWidget( rightBox ); // don't let the close button take up all the height + rightBox->setStretchFactor( spacer, 100 ); + */ + + /* + * Get the singleton ProgressManager item which will inform us of + * appearing and vanishing items. + */ + ProgressManager *pm = ProgressManager::instance(); + connect ( pm, TQT_SIGNAL( progressItemAdded( KPIM::ProgressItem* ) ), + this, TQT_SLOT( slotTransactionAdded( KPIM::ProgressItem* ) ) ); + connect ( pm, TQT_SIGNAL( progressItemCompleted( KPIM::ProgressItem* ) ), + this, TQT_SLOT( slotTransactionCompleted( KPIM::ProgressItem* ) ) ); + connect ( pm, TQT_SIGNAL( progressItemProgress( KPIM::ProgressItem*, unsigned int ) ), + this, TQT_SLOT( slotTransactionProgress( KPIM::ProgressItem*, unsigned int ) ) ); + connect ( pm, TQT_SIGNAL( progressItemtqStatus( KPIM::ProgressItem*, const TQString& ) ), + this, TQT_SLOT( slotTransactiontqStatus( KPIM::ProgressItem*, const TQString& ) ) ); + connect ( pm, TQT_SIGNAL( progressItemLabel( KPIM::ProgressItem*, const TQString& ) ), + this, TQT_SLOT( slotTransactionLabel( KPIM::ProgressItem*, const TQString& ) ) ); + connect ( pm, TQT_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*, bool) ), + this, TQT_SLOT( slotTransactionUsesCrypto( KPIM::ProgressItem*, bool ) ) ); + connect ( pm, TQT_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*, bool) ), + this, TQT_SLOT( slotTransactionUsesBusyIndicator( KPIM::ProgressItem*, bool ) ) ); + connect ( pm, TQT_SIGNAL( showProgressDialog() ), + this, TQT_SLOT( slotShow() ) ); +} + +void ProgressDialog::closeEvent( TQCloseEvent* e ) +{ + e->accept(); + hide(); +} + + +/* + * Destructor + */ +ProgressDialog::~ProgressDialog() +{ + // no need to delete child widgets. +} + +void ProgressDialog::slotTransactionAdded( ProgressItem *item ) +{ + TransactionItem *parent = 0; + if ( item->parent() ) { + if ( mTransactionsToListviewItems.contains( item->parent() ) ) { + parent = mTransactionsToListviewItems[ item->parent() ]; + parent->addSubTransaction( item ); + } + } else { + const bool first = mTransactionsToListviewItems.empty(); + TransactionItem *ti = mScrollView->addTransactionItem( item, first ); + if ( ti ) + mTransactionsToListviewItems.replace( item, ti ); + if ( first && mWasLastShown ) + TQTimer::singleShot( 1000, this, TQT_SLOT( slotShow() ) ); + + } +} + +void ProgressDialog::slotTransactionCompleted( ProgressItem *item ) +{ + if ( mTransactionsToListviewItems.contains( item ) ) { + TransactionItem *ti = mTransactionsToListviewItems[ item ]; + mTransactionsToListviewItems.remove( item ); + ti->setItemComplete(); + TQTimer::singleShot( 3000, ti, TQT_SLOT( deleteLater() ) ); + // see the slot for comments as to why that works + connect ( ti, TQT_SIGNAL( destroyed() ), + mScrollView, TQT_SLOT( slotLayoutFirstItem() ) ); + } + // This was the last item, hide. + if ( mTransactionsToListviewItems.empty() ) + TQTimer::singleShot( 3000, this, TQT_SLOT( slotHide() ) ); +} + +void ProgressDialog::slotTransactionCanceled( ProgressItem* ) +{ +} + +void ProgressDialog::slotTransactionProgress( ProgressItem *item, + unsigned int progress ) +{ + if ( mTransactionsToListviewItems.contains( item ) ) { + TransactionItem *ti = mTransactionsToListviewItems[ item ]; + ti->setProgress( progress ); + } +} + +void ProgressDialog::slotTransactiontqStatus( ProgressItem *item, + const TQString& status ) +{ + if ( mTransactionsToListviewItems.contains( item ) ) { + TransactionItem *ti = mTransactionsToListviewItems[ item ]; + ti->setqStatus( status ); + } +} + +void ProgressDialog::slotTransactionLabel( ProgressItem *item, + const TQString& label ) +{ + if ( mTransactionsToListviewItems.contains( item ) ) { + TransactionItem *ti = mTransactionsToListviewItems[ item ]; + ti->setLabel( label ); + } +} + + +void ProgressDialog::slotTransactionUsesCrypto( ProgressItem *item, + bool value ) +{ + if ( mTransactionsToListviewItems.contains( item ) ) { + TransactionItem *ti = mTransactionsToListviewItems[ item ]; + ti->setCrypto( value ); + } +} + +void ProgressDialog::slotTransactionUsesBusyIndicator( KPIM::ProgressItem *item, bool value ) +{ + if ( mTransactionsToListviewItems.contains( item ) ) { + TransactionItem *ti = mTransactionsToListviewItems[ item ]; + if ( value ) + ti->setTotalSteps( 0 ); + else + ti->setTotalSteps( 100 ); + } +} + +void ProgressDialog::slotShow() +{ + setVisible( true ); +} + +void ProgressDialog::slotHide() +{ + // check if a new item showed up since we started the timer. If not, hide + if ( mTransactionsToListviewItems.isEmpty() ) { + setVisible( false ); + } +} + +void ProgressDialog::slotClose() +{ + mWasLastShown = false; + setVisible( false ); +} + +void ProgressDialog::setVisible( bool b ) +{ + if ( b ) + show(); + else + hide(); + emit visibilityChanged( b ); +} + +void ProgressDialog::slotToggleVisibility() +{ + /* Since we are only hiding with a timeout, there is a short period of + * time where the last item is still visible, but clicking on it in + * the statusbarwidget should not display the dialog, because there + * are no items to be shown anymore. Guard against that. + */ + mWasLastShown = !isShown(); + if ( isShown() || !mTransactionsToListviewItems.isEmpty() ) + setVisible( !isShown() ); +} + +} + +#include "progressdialog.moc" diff --git a/libtdepim/progressdialog.h b/libtdepim/progressdialog.h new file mode 100644 index 000000000..b2511624e --- /dev/null +++ b/libtdepim/progressdialog.h @@ -0,0 +1,160 @@ +/* -*- c++ -*- + * progressdialog.h + * + * Copyright (c) 2004 Till Adam + * based on imapprogressdialog.cpp ,which is + * Copyright (c) 2002-2003 Klar�vdalens Datakonsult AB + * + * 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; version 2 of the License + * + * 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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 __KPIM_PROGRESSDIALOG_H__ +#define __KPIM_PROGRESSDIALOG_H__ + +#include +#include +#include +#include +#include "overlaywidget.h" +#include + +class TQProgressBar; +class TQScrollView; +class TQFrame; + +namespace KPIM { +class ProgressItem; +class TransactionItemListView; +class TransactionItem; +class SSLLabel; + +class TransactionItemView : public TQScrollView { + Q_OBJECT + TQ_OBJECT +public: + TransactionItemView( TQWidget * parent = 0, + const char * name = 0, + WFlags f = 0 ); + + virtual ~TransactionItemView() + {} + TransactionItem* addTransactionItem( ProgressItem *item, bool first ); + + + TQSize tqsizeHint() const; + TQSize tqminimumSizeHint() const; +public slots: + void slotLayoutFirstItem(); + +protected: + virtual void resizeContents ( int w, int h ); + +private: + TQVBox * mBigBox; +}; + +class TransactionItem : public TQVBox { + + Q_OBJECT + TQ_OBJECT + +public: + TransactionItem( TQWidget * parent, + ProgressItem* item, bool first ); + + ~TransactionItem(); + + void hideHLine(); + + void setProgress( int progress ); + void setLabel( const TQString& ); + void setqStatus( const TQString& ); + void setCrypto( bool ); + void setTotalSteps( int totalSteps ); + + ProgressItem* item() const { return mItem; } + + void addSubTransaction( ProgressItem *item); + + // The progressitem is deleted immediately, we take 5s to go out, + // so better not use mItem during this time. + void setItemComplete() { mItem = 0; } + +public slots: + void slotItemCanceled(); + +protected: + TQProgressBar* mProgress; + TQPushButton* mCancelButton; + TQLabel* mItemLabel; + TQLabel* mItemtqStatus; + TQFrame* mFrame; + SSLLabel* mSSLLabel; + ProgressItem* mItem; +}; + +class KDE_EXPORT ProgressDialog : public OverlayWidget +{ + Q_OBJECT + TQ_OBJECT + +public: + ProgressDialog( TQWidget* alignWidget, TQWidget* parent, const char* name = 0 ); + ~ProgressDialog(); + void setVisible( bool b ); + +public slots: + void slotToggleVisibility(); + +protected slots: +void slotTransactionAdded( KPIM::ProgressItem *item ); + void slotTransactionCompleted( KPIM::ProgressItem *item ); + void slotTransactionCanceled( KPIM::ProgressItem *item ); + void slotTransactionProgress( KPIM::ProgressItem *item, unsigned int progress ); + void slotTransactiontqStatus( KPIM::ProgressItem *item, const TQString& ); + void slotTransactionLabel( KPIM::ProgressItem *item, const TQString& ); + void slotTransactionUsesCrypto( KPIM::ProgressItem *item, bool ); + void slotTransactionUsesBusyIndicator( KPIM::ProgressItem*, bool ); + + void slotClose(); + void slotShow(); + void slotHide(); + +signals: + void visibilityChanged( bool ); + +protected: + virtual void closeEvent( TQCloseEvent* ); + + TransactionItemView* mScrollView; + TransactionItem* mPreviousItem; + TQMap< const ProgressItem*, TransactionItem* > mTransactionsToListviewItems; + bool mWasLastShown; +}; + + +} // namespace KPIM + +#endif // __KPIM_PROGRESSDIALOG_H__ diff --git a/libtdepim/progressmanager.cpp b/libtdepim/progressmanager.cpp new file mode 100644 index 000000000..a00970c5e --- /dev/null +++ b/libtdepim/progressmanager.cpp @@ -0,0 +1,248 @@ +/* + progressmanager.cpp + + This file is part of KDEPIM. + + Author: Till Adam (C) 2004 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include +#include + +#include "progressmanager.h" + +namespace KPIM { + +KPIM::ProgressManager * KPIM::ProgressManager::mInstance = 0; +unsigned int KPIM::ProgressManager::uID = 42; + +ProgressItem::ProgressItem( + ProgressItem* parent, const TQString& id, + const TQString& label, const TQString& status, bool canBeCanceled, + bool usesCrypto ) + :mId( id ), mLabel( label ), mtqStatus( status ), mParent( parent ), + mCanBeCanceled( canBeCanceled ), mProgress( 0 ), mTotal( 0 ), + mCompleted( 0 ), mWaitingForKids( false ), mCanceled( false ), + mUsesCrypto( usesCrypto ), mUsesBusyIndicator( false ) + {} + +ProgressItem::~ProgressItem() +{ +} + +void ProgressItem::setComplete() +{ +// kdDebug(5300) << "ProgressItem::setComplete - " << label() << endl; + + if ( mChildren.isEmpty() ) { + if ( !mCanceled ) + setProgress( 100 ); + emit progressItemCompleted( this ); + if ( parent() ) + parent()->removeChild( this ); + deleteLater(); + } else { + mWaitingForKids = true; + } +} + +void ProgressItem::addChild( ProgressItem *kiddo ) +{ + mChildren.replace( kiddo, true ); +} + +void ProgressItem::removeChild( ProgressItem *kiddo ) +{ + mChildren.remove( kiddo ); + // in case we were waiting for the last kid to go away, now is the time + if ( mChildren.count() == 0 && mWaitingForKids ) { + emit progressItemCompleted( this ); + deleteLater(); + } +} + +void ProgressItem::cancel() +{ + if ( mCanceled || !mCanBeCanceled ) return; + kdDebug(5300) << "ProgressItem::cancel() - " << label() << endl; + mCanceled = true; + // Cancel all tqchildren. + TQValueList kids = mChildren.keys(); + TQValueList::Iterator it( kids.begin() ); + TQValueList::Iterator end( kids.end() ); + for ( ; it != end; it++ ) { + ProgressItem *kid = *it; + if ( kid->canBeCanceled() ) + kid->cancel(); + } + setqStatus( i18n( "Aborting..." ) ); + emit progressItemCanceled( this ); +} + + +void ProgressItem::setProgress( unsigned int v ) +{ + mProgress = v; + // kdDebug(5300) << "ProgressItem::setProgress(): " << label() << " : " << v << endl; + emit progressItemProgress( this, mProgress ); +} + +void ProgressItem::setLabel( const TQString& v ) +{ + mLabel = v; + emit progressItemLabel( this, mLabel ); +} + +void ProgressItem::setqStatus( const TQString& v ) +{ + mtqStatus = v; + emit progressItemtqStatus( this, mtqStatus ); +} + +void ProgressItem::setUsesCrypto( bool v ) +{ + mUsesCrypto = v; + emit progressItemUsesCrypto( this, v ); +} + +void ProgressItem::setUsesBusyIndicator( bool useBusyIndicator ) +{ + mUsesBusyIndicator = useBusyIndicator; + emit progressItemUsesBusyIndicator( this, useBusyIndicator ); +} + +// ====================================== + +ProgressManager::ProgressManager() :TQObject() { + mInstance = this; +} + +ProgressManager::~ProgressManager() { mInstance = 0; } +static KStaticDeleter progressManagerDeleter; + +ProgressManager* ProgressManager::instance() +{ + if ( !mInstance ) { + progressManagerDeleter.setObject( mInstance, new ProgressManager() ); + } + return mInstance; +} + +ProgressItem* ProgressManager::createProgressItemImpl( + ProgressItem* parent, const TQString& id, + const TQString &label, const TQString &status, + bool cancellable, bool usesCrypto ) +{ + ProgressItem *t = 0; + if ( !mTransactions[ id ] ) { + t = new ProgressItem ( parent, id, label, status, cancellable, usesCrypto ); + mTransactions.insert( id, t ); + if ( parent ) { + ProgressItem *p = mTransactions[ parent->id() ]; + if ( p ) { + p->addChild( t ); + } + } + // connect all signals + connect ( t, TQT_SIGNAL( progressItemCompleted(KPIM::ProgressItem*) ), + this, TQT_SLOT( slotTransactionCompleted(KPIM::ProgressItem*) ) ); + connect ( t, TQT_SIGNAL( progressItemProgress(KPIM::ProgressItem*, unsigned int) ), + this, TQT_SIGNAL( progressItemProgress(KPIM::ProgressItem*, unsigned int) ) ); + connect ( t, TQT_SIGNAL( progressItemAdded(KPIM::ProgressItem*) ), + this, TQT_SIGNAL( progressItemAdded(KPIM::ProgressItem*) ) ); + connect ( t, TQT_SIGNAL( progressItemCanceled(KPIM::ProgressItem*) ), + this, TQT_SIGNAL( progressItemCanceled(KPIM::ProgressItem*) ) ); + connect ( t, TQT_SIGNAL( progressItemtqStatus(KPIM::ProgressItem*, const TQString&) ), + this, TQT_SIGNAL( progressItemtqStatus(KPIM::ProgressItem*, const TQString&) ) ); + connect ( t, TQT_SIGNAL( progressItemLabel(KPIM::ProgressItem*, const TQString&) ), + this, TQT_SIGNAL( progressItemLabel(KPIM::ProgressItem*, const TQString&) ) ); + connect ( t, TQT_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*, bool) ), + this, TQT_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*, bool) ) ); + connect ( t, TQT_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*, bool) ), + this, TQT_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*, bool) ) ); + + emit progressItemAdded( t ); + } else { + // Hm, is this what makes the most sense? + t = mTransactions[id]; + } + return t; +} + +ProgressItem* ProgressManager::createProgressItemImpl( + const TQString& parent, const TQString &id, + const TQString &label, const TQString& status, + bool canBeCanceled, bool usesCrypto ) +{ + ProgressItem * p = mTransactions[parent]; + return createProgressItemImpl( p, id, label, status, canBeCanceled, usesCrypto ); +} + +void ProgressManager::emitShowProgressDialogImpl() +{ + emit showProgressDialog(); +} + + +// slots + +void ProgressManager::slotTransactionCompleted( ProgressItem *item ) +{ + mTransactions.remove( item->id() ); + emit progressItemCompleted( item ); +} + +void ProgressManager::slotStandardCancelHandler( ProgressItem *item ) +{ + item->setComplete(); +} + +ProgressItem* ProgressManager::singleItem() const +{ + ProgressItem *item = 0; + TQDictIterator< ProgressItem > it( mTransactions ); + for ( ; it.current(); ++it ) { + + // No single item for progress possible, as one of them is a busy indicator one. + if ( (*it)->usesBusyIndicator() ) + return 0; + + if ( !(*it)->parent() ) { // if it's a top level one, only those count + if ( item ) + return 0; // we found more than one + else + item = (*it); + } + } + return item; +} + +void ProgressManager::slotAbortAll() +{ + TQDictIterator< ProgressItem > it( mTransactions ); + for ( ; it.current(); ++it ) { + it.current()->cancel(); + } +} + +} // namespace + +#include "progressmanager.moc" diff --git a/libtdepim/progressmanager.h b/libtdepim/progressmanager.h new file mode 100644 index 000000000..a447d49fb --- /dev/null +++ b/libtdepim/progressmanager.h @@ -0,0 +1,438 @@ +/* + progressmanager.h + + This file is part of KDEPIM. + + Author: Till Adam (C) 2004 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KPIM_PROGRESSMANAGER_H__ +#define __KPIM_PROGRESSMANAGER_H__ + +#include +#include +#include + +#include + +namespace KPIM { + +class ProgressItem; +class ProgressManager; +typedef TQMap ProgressItemMap; + +class KDE_EXPORT ProgressItem : public TQObject +{ + Q_OBJECT + TQ_OBJECT + friend class ProgressManager; + friend class TQDict< ProgressItem >; // so it can be deleted from dicts + + public: + + /** + * @return The id string which uniquely identifies the operation + * represented by this item. + */ + const TQString& id() const { return mId; } + + /** + * @return The parent item of this one, if there is one. + */ + ProgressItem *parent() const { return mParent; } + + /** + * @return The user visible string to be used to represent this item. + */ + const TQString& label() const { return mLabel; } + + /** + * @param v Set the user visible string identifying this item. @p v will + be interpreted as rich text, so it might have to be escaped. + */ + void setLabel( const TQString& v ); + + /** + * @return The string to be used for showing this item's current status. + */ + const TQString& status() const { return mtqStatus; } + /** + * Set the string to be used for showing this item's current status. + * @p v will be interpreted as rich text, so it might have to be escaped. + * @param v The status string. + */ + void setqStatus( const TQString& v ); + + /** + * @return Whether this item can be cancelled. + */ + bool canBeCanceled() const { return mCanBeCanceled; } + + /** + * @return Whether this item uses secure communication + * (Account uses ssl, for example.). + */ + bool usesCrypto() const { return mUsesCrypto; } + + /** + * Set whether this item uses crypted communication, so listeners + * can display a nice crypto icon. + * @param v The value. + */ + void setUsesCrypto( bool v ); + + /** + * @return whether this item uses a busy indicator instead of real progress display + */ + bool usesBusyIndicator() const { return mUsesBusyIndicator; } + + /** + * Sets whether this item uses a busy indicator instead of real progress for its progress bar. + * If it uses a busy indicator, you are still responsible for calling setProgress() from time to + * time to update the busy indicator. + */ + void setUsesBusyIndicator( bool useBusyIndicator ); + + /** + * @return The current progress value of this item in percent. + */ + unsigned int progress() const { return mProgress; } + + /** + * Set the progress (percentage of completion) value of this item. + * @param v The percentage value. + */ + void setProgress( unsigned int v ); + + /** + * Tell the item it has finished. This will emit progressItemCompleted() + * result in the destruction of the item after all slots connected to this + * signal have executed. This is the only way to get rid of an item and + * needs to be called even if the item is cancelled. Don't use the item + * after this has been called on it. + */ + void setComplete(); + + /** + * Reset the progress value of this item to 0 and the status string to + * the empty string. + */ + void reset() { setProgress( 0 ); setqStatus( TQString() ); mCompleted = 0; } + + void cancel(); + + // Often needed values for calculating progress. + void setTotalItems( unsigned int v ) { mTotal = v; } + unsigned int totalItems() const { return mTotal; } + void setCompletedItems( unsigned int v ) { mCompleted = v; } + void incCompletedItems( unsigned int v = 1 ) { mCompleted += v; } + unsigned int completedItems() const { return mCompleted; } + + /** + * Recalculate progress according to total/completed items and update. + */ + void updateProgress() { setProgress( mTotal? mCompleted*100/mTotal: 0 ); } + + void addChild( ProgressItem *kiddo ); + void removeChild( ProgressItem *kiddo ); + + bool canceled() const { return mCanceled; } + +signals: + /** + * Emitted when a new ProgressItem is added. + * @param The ProgressItem that was added. + */ + void progressItemAdded( KPIM::ProgressItem* ); + /** + * Emitted when the progress value of an item changes. + * @param The item which got a new value. + * @param The value, for convenience. + */ + void progressItemProgress( KPIM::ProgressItem*, unsigned int ); + /** + * Emitted when a progress item was completed. The item will be + * deleted afterwards, so slots connected to this are the last + * chance to work with this item. + * @param The completed item. + */ + void progressItemCompleted( KPIM::ProgressItem* ); + /** + * Emitted when an item was cancelled. It will _not_ go away immediately, + * only when the owner sets it complete, which will usually happen. Can be + * used to visually indicate the cancelled status of an item. Should be used + * by the owner of the item to make sure it is set completed even if it is + * cancelled. There is a ProgressManager::slotStandardCancelHandler which + * simply sets the item completed and can be used if no other work needs to + * be done on cancel. + * @param The canceled item; + */ + void progressItemCanceled( KPIM::ProgressItem* ); + /** + * Emitted when the status message of an item changed. Should be used by + * progress dialogs to update the status message for an item. + * @param The updated item. + * @param The new message. + */ + void progressItemtqStatus( KPIM::ProgressItem*, const TQString& ); + /** + * Emitted when the label of an item changed. Should be used by + * progress dialogs to update the label of an item. + * @param The updated item. + * @param The new label. + */ + void progressItemLabel( KPIM::ProgressItem*, const TQString& ); + /** + * Emitted when the crypto status of an item changed. Should be used by + * progress dialogs to update the crypto indicator of an item. + * @param The updated item. + * @param The new state. + */ + void progressItemUsesCrypto( KPIM::ProgressItem*, bool ); + + /** + * Emitted when the busy indicator state of an item changes. Should be used + * by progress dialogs so that they can adjust the display of the progress bar + * to the new mode. + * @param item The updated item + * @param value True if the item uses a busy indicator now, false otherwise + */ + void progressItemUsesBusyIndicator( KPIM::ProgressItem *item, bool value ); + + + protected: + /* Only to be used by our good friend the ProgressManager */ + ProgressItem( ProgressItem* parent, + const TQString& id, + const TQString& label, + const TQString& status, + bool isCancellable, + bool usesCrypto ); + virtual ~ProgressItem(); + + + private: + TQString mId; + TQString mLabel; + TQString mtqStatus; + ProgressItem* mParent; + bool mCanBeCanceled; + unsigned int mProgress; + ProgressItemMap mChildren; + unsigned int mTotal; + unsigned int mCompleted; + bool mWaitingForKids; + bool mCanceled; + bool mUsesCrypto; + bool mUsesBusyIndicator; +}; + +/** + * The ProgressManager singleton keeps track of all ongoing transactions + * and notifies observers (progress dialogs) when their progress percent value + * changes, when they are completed (by their owner), and when they are canceled. + * Each ProgressItem emits those signals individually and the singleton + * broadcasts them. Use the ::createProgressItem() statics to acquire an item + * and then call ->setProgress( int percent ) on it everytime you want to update + * the item and ->setComplete() when the operation is done. This will delete the + * item. Connect to the item's progressItemCanceled() signal to be notified when + * the user cancels the transaction using one of the observing progress dialogs + * or by calling item->cancel() in some other way. The owner is responsible for + * calling setComplete() on the item, even if it is canceled. Use the + * standardCancelHandler() slot if that is all you want to do on cancel. + * + * Note that if you request an item with a certain id and there is already + * one with that id, there will not be a new one created but the existing + * one will be returned. This is convenient for accessing items that are + * needed regularly without the to store a pointer to them or to add child + * items to parents by id. + */ + +class KDE_EXPORT ProgressManager : public TQObject +{ + + Q_OBJECT + TQ_OBJECT + + public: + virtual ~ProgressManager(); + + /** + * @return The singleton instance of this class. + */ + static ProgressManager * instance(); + + /** + * Use this to aquire a unique id number which can be used to discern + * an operation from all others going on at the same time. Use that + * number as the id string for your progressItem to ensure it is unique. + * @return + */ + static TQString getUniqueID() { return TQString::number( ++uID ); } + + /** + * Creates a ProgressItem with a unique id and the given label. + * This is the simplest way to aquire a progress item. It will not + * have a parent and will be set to be cancellable and not using crypto. + * + * @param label The text to be displayed by progress handlers. It will be + * interpreted as rich text, so it might have to be escaped. + */ + static ProgressItem * createProgressItem( const TQString &label ) { + return instance()->createProgressItemImpl( 0, getUniqueID(), label, + TQString(), true, false ); + } + + /** + * Creates a new progressItem with the given parent, id, label and initial + * status. + * + * @param parent Specify an already existing item as the parent of this one. + * @param id Used to identify this operation for cancel and progress info. + * @param label The text to be displayed by progress handlers. It will be + * interpreted as rich text, so it might have to be escaped. + * @param status Additional text to be displayed for the item. It will be + * interpreted as rich text, so it might have to be escaped. + * @param canBeCanceled can the user cancel this operation? + * @param usesCrypto does the operation use secure transports (SSL) + * Cancelling the parent will cancel the tqchildren as well (if they can be + * cancelled) and ongoing tqchildren prevent parents from finishing. + * @return The ProgressItem representing the operation. + */ + static ProgressItem * createProgressItem( ProgressItem* parent, + const TQString& id, + const TQString& label, + const TQString& status = TQString(), + bool canBeCanceled = true, + bool usesCrypto = false ) { + return instance()->createProgressItemImpl( parent, id, label, status, + canBeCanceled, usesCrypto ); + } + + /** + * Use this version if you have the id string of the parent and want to + * add a subjob to it. + */ + static ProgressItem * createProgressItem( const TQString& parent, + const TQString& id, + const TQString& label, + const TQString& status = TQString(), + bool canBeCanceled = true, + bool usesCrypto = false ) { + return instance()->createProgressItemImpl( parent, id, label, + status, canBeCanceled, usesCrypto ); + } + + /** + * Version without a parent. + */ + static ProgressItem * createProgressItem( const TQString& id, + const TQString& label, + const TQString& status = TQString(), + bool canBeCanceled = true, + bool usesCrypto = false ) { + return instance()->createProgressItemImpl( 0, id, label, status, + canBeCanceled, usesCrypto ); + } + + + /** + * @return true when there is no more progress item + */ + bool isEmpty() const { return mTransactions.isEmpty(); } + + /** + * @return the only top level progressitem when there's only one. + * Returns 0 if there is no item, or more than one top level item. + * Since this is used to calculate the overall progress, it will also return + * 0 if there is an item which uses a busy indicator, since that will tqinvalidate + * the overall progress. + */ + ProgressItem* singleItem() const; + + /** + * Ask all listeners to show the progress dialog, because there is + * something that wants to be shown. + */ + static void emitShowProgressDialog() { + instance()->emitShowProgressDialogImpl(); + } + + signals: + /** @see ProgressItem::progressItemAdded() */ + void progressItemAdded( KPIM::ProgressItem* ); + /** @see ProgressItem::progressItemProgress() */ + void progressItemProgress( KPIM::ProgressItem*, unsigned int ); + /** @see ProgressItem::progressItemCompleted() */ + void progressItemCompleted( KPIM::ProgressItem* ); + /** @see ProgressItem::progressItemCanceled() */ + void progressItemCanceled( KPIM::ProgressItem* ); + /** @see ProgressItem::progressItemtqStatus() */ + void progressItemtqStatus( KPIM::ProgressItem*, const TQString& ); + /** @see ProgressItem::progressItemLabel() */ + void progressItemLabel( KPIM::ProgressItem*, const TQString& ); + /** @see ProgressItem::progressItemUsesCrypto() */ + void progressItemUsesCrypto( KPIM::ProgressItem*, bool ); + /** @see ProgressItem::progressItemUsesBusyIndicator */ + void progressItemUsesBusyIndicator( KPIM::ProgressItem*, bool ); + + /** + * Emitted when an operation requests the listeners to be shown. + * Use emitShowProgressDialog() to trigger it. + */ + void showProgressDialog(); + public slots: + + /** + * Calls setCompleted() on the item, to make sure it goes away. + * Provided for convenience. + * @param item the canceled item. + */ + void slotStandardCancelHandler( KPIM::ProgressItem* item ); + + /** + * Aborts all running jobs. Bound to "Esc" + */ + void slotAbortAll(); + + private slots: + void slotTransactionCompleted( KPIM::ProgressItem *item ); + + private: + ProgressManager(); + // prevent unsolicited copies + ProgressManager( const ProgressManager& ); + + virtual ProgressItem* createProgressItemImpl( + ProgressItem* parent, const TQString& id, + const TQString& label, const TQString& status, + bool cancellable, bool usesCrypto ); + virtual ProgressItem* createProgressItemImpl( + const TQString& parent, const TQString& id, + const TQString& label, const TQString& status, + bool cancellable, bool usesCrypto ); + void emitShowProgressDialogImpl(); + + TQDict< ProgressItem > mTransactions; + static ProgressManager *mInstance; + static unsigned int uID; +}; + +} + +#endif // __KPIM_PROGRESSMANAGER_H__ diff --git a/libtdepim/qutf7codec.cpp b/libtdepim/qutf7codec.cpp new file mode 100644 index 000000000..dc8ef2a2f --- /dev/null +++ b/libtdepim/qutf7codec.cpp @@ -0,0 +1,550 @@ +/* + qutf7codec.cpp + + A TQTextCodec for UTF-7 (rfc2152). + Copyright (c) 2001 Marc Mutz + See file COPYING for details + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + 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, US + + As a special exception, permission is granted to use this plugin + with any version of TQt by TrollTech AS, Norway. In this case, the + use of this plugin doesn't cause the resulting executable to be + covered by the GNU General Public License. + This exception does not however tqinvalidate any other reasons why the + executable file might be covered by the GNU General Public License. +*/ + + +#include "qutf7codec.h" + +#ifndef TQT_NO_TEXTCODEC + +int TQUtf7Codec::mibEnum() const { + return 1012; +} + +int TQStrictUtf7Codec::mibEnum() const { + return -1012; +} + +const char* TQUtf7Codec::name() const { + return "UTF-7"; +} + +const char* TQStrictUtf7Codec::name() const { + return "X-QT-UTF-7-STRICT"; +} + +const char* TQUtf7Codec::mimeName() const { + return "UTF-7"; +} + +bool TQUtf7Codec::canEncode( TQChar ) const { + return TRUE; +} + +bool TQUtf7Codec::canEncode( const TQString & ) const { + return TRUE; +} + +static uchar base64Set[] = { + 0x00, 0x00, 0x00, 0x00, // '\0' ... + 0x00, 0x11, 0xFF, 0xC0, // ' ' ... '?' + 0x7F, 0xFF, 0xFF, 0xE0, // '@' ... '_' + 0x7F, 0xFF, 0xFF, 0xE0 // '`' ... DEL +}; + +static uchar base64SetWithLastTwoBitsZero[] = { + 0x00, 0x00, 0x00, 0x00, // '\0' ... + 0x00, 0x00, 0x88, 0x80, // ' ' ... '?' + 0x44, 0x44, 0x44, 0x40, // '@' ... '_' + 0x11, 0x11, 0x11, 0x00 // '`' ... DEL +}; + +static uchar directSet[] = { + 0x00, 0x00, 0x00, 0x00, // '\0' ... + 0x01, 0xCF, 0xFF, 0xE1, // ' ' ... '?' + 0x7F, 0xFF, 0xFF, 0xE0, // '@' ... '_' + 0x7F, 0xFF, 0xFF, 0xE0 // '`' ... DEL +}; + +static uchar optDirectSet[] = { + 0x00, 0x00, 0x00, 0x00, // '\0' ... + 0x7E, 0x20, 0x00, 0x1E, // ' ' ... '?' + 0x80, 0x00, 0x00, 0x17, // '@' ... '_' + 0x80, 0x00, 0x00, 0x1C // '`' ... DEL +}; + +static inline bool isOfSet(uchar ch, uchar* set) { + return set[ ch/8 ] & (0x80 >> ( ch%8 )); +} + +int TQUtf7Codec::heuristicContentMatch(const char* chars, int len) const +{ + int stepNo = 0; + int i; + bool shifted = FALSE; + bool rightAfterEscape = FALSE; + bool onlyNullBitsSinceLastBoundary = TRUE; + for ( i = 0; i < len ; i++ ) { + if ((unsigned char)chars[i] >= 128) // 8bit chars not allowed. + break; + if (shifted) { + if ( isOfSet(chars[i],base64Set) ) { + switch (stepNo) { + case 0: + onlyNullBitsSinceLastBoundary = TRUE; + break; + case 3: + onlyNullBitsSinceLastBoundary + = isOfSet(chars[i],base64SetWithLastTwoBitsZero); + break; + case 6: + onlyNullBitsSinceLastBoundary + = ( chars[i] == 'A' || chars[i] == 'Q' || + chars[i] == 'g' || chars[i] == 'w' ); + break; + default: + onlyNullBitsSinceLastBoundary + = onlyNullBitsSinceLastBoundary && (chars[i] == 'A'); + } + stepNo = (stepNo + 1) % 8; + rightAfterEscape = FALSE; + } else { + if (rightAfterEscape && chars[i] != '-') + break; // a '+' must be followed by '-' or a base64 char + if (!onlyNullBitsSinceLastBoundary) + break; // non-zero bits in the tail of the base64 encoding + shifted = FALSE; + stepNo = 0; + } + } else { + if (chars[i] == '+') { + shifted = TRUE; + rightAfterEscape = TRUE; + } + } + } + return i; +} + +class TQUtf7Decoder : public TQTextDecoder { + // the storage for our tqunicode char until it's finished + ushort uc; + // the state of the base64 decoding + // can be 0 (just finished three tqunicode chars) + // 1 (have the upper 6 bits of uc already) + // 2 (have the upper 12 bits of uc already) + // 3 (have the upper 2 bits of uc already) + // .......... + // 7 (have the upper 10 bits of uc already) + // => n (have the upper (n * 6) % 16 bits of uc already) + // "stepNo" cycles through all it's values every three + // tqunicode chars. + char stepNo; + // remembers if we are in shifted-sequence mode + bool shifted; + // remembers if we're just after the initial '+' + // of a shifted-sequence. + bool rightAfterEscape; +public: + TQUtf7Decoder() : uc(0), stepNo(0), shifted(FALSE), rightAfterEscape(FALSE) + { + } + +private: + inline void resetParser() + { + uc = 0; + stepNo = 0; + shifted = FALSE; + rightAfterEscape = FALSE; + } + +public: + TQString toUnicode(const char* chars, int len) + { + TQString result = ""; + for (int i=0; i 127 ) { + qWarning("TQUtf7Decoder: 8bit char found in input. " + "Parser has been re-initialized!"); + resetParser(); + result += TQChar::replacement; + continue; + } + + if (shifted) { // in shifted mode + + // + // first, we check specialities that only occur + // right after the escaping '+': + // + if ( rightAfterEscape && ch == '-' ) { + // a "+-" sequence is a short-circuit encoding + // for just '+': + resetParser(); + result += TQChar('+'); + // we're already done for this "ch", so + continue; + } + + // + // Here we're going to extract the bits represented by "ch": + // + ushort bits; + if ( ch >= 'A' && ch <= 'Z' ) { + bits = ch - 'A'; + } else if ( ch >= 'a' && ch <= 'z' ) { + bits = ch - 'a' + 26; + } else if ( ch >= '0' && ch <= '9' ) { + bits = ch - '0' + 52; + } else if ( ch == '+' ) { + bits = 62; + } else if ( ch == '/' ) { + bits = 63; + } else { + bits = 0; // keep compiler happy + + // + // ch is not of the base64 alphabet. + // Here we are going to check the sequence's validity: + // + if ( rightAfterEscape ) { + // any non-base64 char following an escaping '+' + // makes for an ill-formed sequence. + // Note that we catch (the valid) "+-" pair + // right at the beginning. + qWarning("TQUtf7Decoder: ill-formed input: " + "non-base64 char after escaping \"+\"!"); + } + // pending bits from base64 encoding must be all 0: + if (stepNo >= 1 && uc) { + qWarning("TQUtf7Decoder: ill-formed sequence: " + "non-zero bits in shifted-sequence tail!"); + } + resetParser(); + + // a '-' signifies the end of the shifted-sequence, + // so we just swallow it. + if ( ch == '-' ) + continue; + // end of validity checking. Process ch now... + } + + if ( /*still*/ shifted ) { + // + // now we're going to stuff the "bits" bit bucket into + // the right position inside "uc", emitting a resulting + // TQChar if possible. + // + switch (stepNo) { + // "bits" are the 6 msb's of uc + case 0: uc = bits << 10; break; + + case 1: uc |= bits << 4; break; + + // 4 bits of "bits" complete the first ushort + case 2: uc |= bits >> 2; result += TQChar(uc); + // 2 bits of "bits" make the msb's of the next ushort + uc = bits << 14; break; + case 3: uc |= bits << 8; break; + case 4: uc |= bits << 2; break; + + // 2 bits of "bits" complete the second ushort + case 5: uc |= bits >> 4; result += TQChar(uc); + // 4 bits of "bits" make the msb's of the next ushort + uc = bits << 12; break; + case 6: uc |= bits << 6; break; + + // these 6 bits complete the third ushort + // and also one round of 8 chars -> 3 ushort decoding + case 7: uc |= bits; result += TQChar(uc); + uc = 0; break; + default: ; + } // switch (stepNo) + // increase the step counter + stepNo++; + stepNo %= 8; + rightAfterEscape = FALSE; + // and look at the next char. + continue; + } // fi (still) shifted + } // fi shifted + + // + // if control reaches here, we either weren't in a + // shifted sequence or we just left one by seeing + // a non-base64-char. + // Either way, we have to process "ch" outside + // a shifted-sequence now: + // + if ( ch == '+' ) { + // '+' is the escape char for entering a + // shifted sequence: + shifted = TRUE; + stepNo = 0; + // also, we're right at the beginning where + // special rules apply: + rightAfterEscape = TRUE; + } else { + // US-ASCII values are directly used + result += TQChar(ch); + } + } + + return result; + + } // toUnicode() + +}; // class TQUtf7Decoder + +TQTextDecoder* TQUtf7Codec::makeDecoder() const +{ + return new TQUtf7Decoder; +} + + +class TQUtf7Encoder : public TQTextEncoder { + uchar dontNeedEncodingSet[16]; + ushort outbits; + uint stepNo : 2; + bool shifted : 1; + bool mayContinueShiftedSequence : 1; +public: + TQUtf7Encoder(bool encOpt, bool encLwsp) + : outbits(0), stepNo(0), + shifted(FALSE), mayContinueShiftedSequence(FALSE) + { + for ( int i = 0; i < 16 ; i++) { + dontNeedEncodingSet[i] = directSet[i]; + if (!encOpt) + dontNeedEncodingSet[i] |= optDirectSet[i]; + } + if(!encLwsp) { + dontNeedEncodingSet[' '/8] |= 0x80 >> (' '%8); + dontNeedEncodingSet['\n'/8] |= 0x80 >> ('\n'%8); + dontNeedEncodingSet['\r'/8] |= 0x80 >> ('\r'%8); + dontNeedEncodingSet['\t'/8] |= 0x80 >> ('\t'%8); + } + } + +private: + + char toBase64( ushort u ) { + if ( u < 26 ) + return (char)u + 'A'; + else if ( u < 52 ) + return (char)u - 26 + 'a'; + else if ( u < 62 ) + return (char)u - 52 + '0'; + else if ( u == 62 ) + return '+'; + else + return '/'; + } + + void addToShiftedSequence(TQCString::Iterator & t, ushort u) { + switch (stepNo) { + // no outbits; use uppermost 6 bits of u + case 0: + *t++ = toBase64( u >> 10 ); + *t++ = toBase64( (u & 0x03FF /* umask top 6 bits */ ) >> 4 ); + // save 4 lowest-order bits in outbits[5..2] + outbits = (u & 0x000F) << 2; + break; + + // outbits available; use top two bits of u to complete + // the previous char + case 1: + if (!mayContinueShiftedSequence) { + // if mayContinue, this char has already been written + *t++ = toBase64( outbits | ( u >> 14 ) ); + } + *t++ = toBase64( (u & 0x3F00 /* mask top 2 bits */ ) >> 8 ); + *t++ = toBase64( (u & 0x00FC /* mask msbyte */ ) >> 2 ); + // save 2 lowest-significant bits in outbits[5..4] + outbits = (u & 0x0003) << 4; + break; + + // outbits available; use top four bits of u to complete + // the previous char + case 2: + if (!mayContinueShiftedSequence) { + // if mayContinue, this char has already been written + *t++ = toBase64( outbits | ( u >> 12 ) ); + } + *t++ = toBase64( (u & 0x0FFF) >> 6 ); + *t++ = toBase64( u & 0x003F ); + break; + + default: ; + } + stepNo = (stepNo + 1) % 3; + } + + void endShiftedSequence(TQCString::Iterator & t) { + switch (stepNo) { + case 1: // four outbits still to be written + case 2: // two outbits still to be written + *t++ = toBase64( outbits ); + break; + case 0: // nothing to do + default: ; + } + outbits = 0; + } + + // depending on the stepNo, checks whether we can continue + // an already ended shifted-sequence with char "u". + // This is only possible if the topmost bits fit the + // already written ones (which are all 0 between calls) + bool continueOK( ushort u ) { + return stepNo == 0 || + ( stepNo == 1 && (u & 0xF000) == 0 ) || + ( stepNo == 2 && (u & 0xC000) == 0 ); + } + + void processDoesntNeedEncoding(TQCString::Iterator & t, ushort ch) { + // doesn't need encoding + if (shifted) { + endShiftedSequence(t); + // add "lead-out" to dis-ambiguate following chars: + if (isOfSet((char)ch,base64Set) || ch == '-' ) { + *t++ = '-'; + } + } else if (mayContinueShiftedSequence) { + // if mayContinue is set, this means the + // shifted-sequence needs a lead-out. + mayContinueShiftedSequence = FALSE; + if (isOfSet(ch,base64Set) || ch == '-' ) { + *t++ = '-'; + } + } + *t++ = (uchar)ch; + shifted = FALSE; + stepNo = 0; + } + +public: + TQCString fromUnicode(const TQString & uc, int & len_in_out) + { + // allocate place for worst case: + // len/2 * (5+1) for an alternating sequence of e.g. "A\", + // + 4 for a worst-case of another +ABC encoded char + // + 1 for the trailing \0 + // + int maxreslen = 3 * len_in_out + 5; + TQCString result( maxreslen ); + +#if 0 + // if (len_in_out == 1) { + cout << "\nlen_in_out: " << len_in_out + <<"; shifted: " << (shifted ? "true" : "false") + << ";\n" << "mayContinue: " + << (mayContinueShiftedSequence ? "true" : "false") + << "; stepNo: " << stepNo << ";\n" + << "outbits: " << outbits << endl; + // } +#endif + + // source and destination cursor + const TQChar * s = uc.tqunicode(); + TQCString::Iterator t = result.data(); + + if ( uc.isNull() ) { + // return to ascii requested: + if ( mayContinueShiftedSequence ) + *t++ = '-'; + } else { + // normal operation: + for (int i = 0 ; i < len_in_out ; + i++/*, checkOutBuf(result,maxreslen,t,i,len_in_out,5)*/ ) { + ushort ch = s[i].tqunicode(); + + // + // first, we check whether we might get around encoding: + // + if ( ch < 128 ) { + // + // ch is usAscii, so we have a chance that we don't + // need to encode it. + // + if ( isOfSet((uchar)ch,dontNeedEncodingSet) ) { + processDoesntNeedEncoding(t,ch); + continue; + } else if ( ch == '+' ) { + // '+' is the shift escape character + if (shifted || mayContinueShiftedSequence) { + // if we are already in shifted mode, we just + // encode the '+', too. Compare + // 24bits ("-+-") + some from ending the shifted-sequence + // with 21,33 bits + addToShiftedSequence(t,ch); + mayContinueShiftedSequence = FALSE; + shifted = TRUE; + } else { + // shortcut encoding of '+': + *t++ = '+'; + *t++ = '-'; + } + continue; // done + } // else fall through to encoding + } + // + // need encoding + // + if (!shifted && (!mayContinueShiftedSequence || !continueOK(ch) ) ) { + *t++ = '+'; + stepNo = 0; + } + addToShiftedSequence(t,ch); + shifted = TRUE; + mayContinueShiftedSequence = FALSE; + } + + if ( shifted ) { + endShiftedSequence(t); + mayContinueShiftedSequence = TRUE; + }; + shifted = FALSE; + } + + *t = '\0'; + len_in_out = t - result.data(); + +#if 0 + cout << "len_in_out: " << len_in_out << "; " + << "mayContinue: " << (mayContinueShiftedSequence ? "true" : "false") + << "; stepNo: " << stepNo << endl; +#endif + + Q_ASSERT(len_in_out <= maxreslen-1); + + return result; + } // fromUnicode() + +}; // class TQUtf7Encoder + +TQTextEncoder* TQUtf7Codec::makeEncoder() const { + return new TQUtf7Encoder( false, false ); +} + +TQTextEncoder* TQStrictUtf7Codec::makeEncoder() const { + return new TQUtf7Encoder( true, false ); +} + +#endif // TQT_NO_TEXTCODEC diff --git a/libtdepim/qutf7codec.h b/libtdepim/qutf7codec.h new file mode 100644 index 000000000..4057d276c --- /dev/null +++ b/libtdepim/qutf7codec.h @@ -0,0 +1,96 @@ +/* + qutf7codec.h + + A TQTextCodec for UTF-7 (rfc2152). + Copyright (c) 2001 Marc Mutz + See file COPYING for details + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + 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, US + + As a special exception, permission is granted to use this plugin + with any version of TQt by TrollTech AS, Norway. In this case, the + use of this plugin doesn't cause the resulting executable to be + covered by the GNU General Public License. + This exception does not however tqinvalidate any other reasons why the + executable file might be covered by the GNU General Public License. +*/ + +#ifndef TQUTF7CODEC_H +#define TQUTF7CODEC_H + +#include "tqtextcodec.h" + +#include + +#ifndef TQT_NO_TEXTCODEC + +/** @short A TQTextCodec for the UTF-7 transformation of Unicode. + + This is a TQTextCodec for the UTF-7 transformation of Unicode, + described in RFC2152. + + Use it as you would use any other TQTextCodec. Only if you use the + encoder directly (via makeEncoder), you should bear in mind + that if your application needs the encoder to return to ASCII mode + (like it's the case for RFC2047 mail header encoded words), you + have to tell the encoder by requesting the encoding of a @em null + TQString. + + @author Marc Mutz */ + +class KDE_EXPORT TQUtf7Codec : public TQTextCodec { + bool encOpt, encLwsp; +public: + TQUtf7Codec() : TQTextCodec() {} + + int mibEnum() const; + const char* name() const; + const char* mimeName() const; + + TQTextDecoder* makeDecoder() const; + TQTextEncoder* makeEncoder() const; + + bool canEncode( TQChar ) const; + bool canEncode( const TQString& ) const; + + int heuristicContentMatch( const char* chars, int len ) const; +}; + +/** This is a version of @ref TQUtf7Codec, which should only be used in + MIME transfer. It differs from @ref TQUtf7Codec only in that the + encoder escapes additional characters (the RFC2152 "optional + direct set"), which might not be allowed in RFC822/RFC2047 header + fields. + + You should only use this codec for @em encoding, since it's output + is pure UTF-7 and can equally well be decoded by @ref TQUtf7Codec's + decoder. + + To distinguish between the two variants, this class has MIB enum + -1012 (the nagative of UTF-7) and the somewhat awkward name + "X-QT-UTF-7-STRICT". The MIME preferred charset name is still + "UTF-7", though. + + @short A variant of @ref TQUtf7Codec, which protectes certain + characters in MIME transport + @author Marc Mutz */ +class KDE_EXPORT TQStrictUtf7Codec : public TQUtf7Codec { +public: + TQStrictUtf7Codec() : TQUtf7Codec() {} + + const char* name() const; + int mibEnum() const; + + TQTextEncoder* makeEncoder() const; +}; + +#endif // TQT_NO_TEXTCODEC + +#endif // TQUTF7CODEC_H diff --git a/libtdepim/qutf7codecplugin.cpp b/libtdepim/qutf7codecplugin.cpp new file mode 100644 index 000000000..49eb92c8f --- /dev/null +++ b/libtdepim/qutf7codecplugin.cpp @@ -0,0 +1,62 @@ +/* + qutf7codecplugin.cpp + + A TQTextCodec for UTF-7 (rfc2152). + Copyright (c) 2001 Marc Mutz + See file COPYING for details + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + 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, US + + As a special exception, permission is granted to use this plugin + with any version of TQt by TrollTech AS, Norway. In this case, the + use of this plugin doesn't cause the resulting executable to be + covered by the GNU General Public License. + This exception does not however tqinvalidate any other reasons why the + executable file might be covered by the GNU General Public License. +*/ + +#include "qutf7codec.h" + +#include +#include +#include +#include + +class TQTextCodec; + +// ######### This file isn't compiled currently + +class TQUtf7CodecPlugin : public TQTextCodecPlugin { +public: + TQUtf7CodecPlugin() {} + + TQStringList names() const { return TQStringList() << "UTF-7" << "X-QT-UTF-7-STRICT"; } + TQValueList mibEnums() const { return TQValueList() << 1012 << -1012; } + TQTextCodec * createForMib( int ); + TQTextCodec * createForName( const TQString & ); +}; + +TQTextCodec * TQUtf7CodecPlugin::createForMib( int mib ) { + if ( mib == 1012 ) + return new TQUtf7Codec(); + else if ( mib == -1012 ) + return new TQStrictUtf7Codec(); + return 0; +} + +TQTextCodec * TQUtf7CodecPlugin::createForName( const TQString & name ) { + if ( name == "UTF-7" ) + return new TQUtf7Codec(); + else if ( name == "X-QT-UTF-7-STRICT" ) + return new TQStrictUtf7Codec(); + return 0; +} + +KDE_TQ_EXPORT_PLUGIN( TQUtf7CodecPlugin ); diff --git a/libtdepim/recentaddresses.cpp b/libtdepim/recentaddresses.cpp new file mode 100644 index 000000000..ac790693d --- /dev/null +++ b/libtdepim/recentaddresses.cpp @@ -0,0 +1,181 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- + * + * Copyright (c) 2001-2003 Carsten Pfeiffer + * Copyright (c) 2003 Zack Rusin + * + * KMail is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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 "recentaddresses.h" +#include "libemailfunctions/email.h" + +#include +#include +#include + +#include +#include +#include + + +#include + +using namespace KRecentAddress; + +static KStaticDeleter sd; + +RecentAddresses * RecentAddresses::s_self = 0; + +RecentAddresses * RecentAddresses::self( KConfig *config) +{ + if ( !s_self ) + sd.setObject( s_self, new RecentAddresses(config) ); + return s_self; +} + +RecentAddresses::RecentAddresses(KConfig * config) +{ + if ( !config ) + load( KGlobal::config() ); + else + load( config ); +} + +RecentAddresses::~RecentAddresses() +{ + // if you want this destructor to get called, use a KStaticDeleter + // on s_self +} + +void RecentAddresses::load( KConfig *config ) +{ + TQStringList addresses; + TQString name; + TQString email; + + m_addresseeList.clear(); + KConfigGroupSaver cs( config, "General" ); + m_maxCount = config->readNumEntry( "Maximum Recent Addresses", 40 ); + addresses = config->readListEntry( "Recent Addresses" ); + for ( TQStringList::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { + KABC::Addressee::parseEmailAddress( *it, name, email ); + if ( !email.isEmpty() ) { + KABC::Addressee addr; + addr.setNameFromString( name ); + addr.insertEmail( email, true ); + m_addresseeList.append( addr ); + } + } + + adjustSize(); +} + +void RecentAddresses::save( KConfig *config ) +{ + KConfigGroupSaver cs( config, "General" ); + config->writeEntry( "Recent Addresses", addresses() ); +} + +void RecentAddresses::add( const TQString& entry ) +{ + if ( !entry.isEmpty() && m_maxCount > 0 ) { + TQStringList list = KPIM::splitEmailAddrList( entry ); + for( TQStringList::const_iterator e_it = list.begin(); e_it != list.end(); ++e_it ) { + KPIM::EmailParseResult errorCode = KPIM::isValidEmailAddress( *e_it ); + if ( errorCode != KPIM::AddressOk ) + continue; + TQString email; + TQString fullName; + KABC::Addressee addr; + + KABC::Addressee::parseEmailAddress( *e_it, fullName, email ); + + for ( KABC::Addressee::List::Iterator it = m_addresseeList.begin(); + it != m_addresseeList.end(); ++it ) + { + if ( email == (*it).preferredEmail() ) { + //already inside, remove it here and add it later at pos==1 + m_addresseeList.remove( it ); + break; + } + } + addr.setNameFromString( fullName ); + addr.insertEmail( email, true ); + m_addresseeList.prepend( addr ); + adjustSize(); + } + } +} + +void RecentAddresses::setMaxCount( int count ) +{ + m_maxCount = count; + adjustSize(); +} + +void RecentAddresses::adjustSize() +{ + while ( m_addresseeList.count() > m_maxCount ) + m_addresseeList.remove( m_addresseeList.fromLast() ); +} + +void RecentAddresses::clear() +{ + m_addresseeList.clear(); + adjustSize(); +} + +TQStringList RecentAddresses::addresses() const +{ + TQStringList addresses; + for ( KABC::Addressee::List::ConstIterator it = m_addresseeList.begin(); + it != m_addresseeList.end(); ++it ) + { + addresses.append( (*it).fullEmail() ); + } + return addresses; +} + +RecentAddressDialog::RecentAddressDialog( TQWidget *parent, const char *name ) + : KDialogBase( Plain, i18n( "Edit Recent Addresses" ), Ok | Cancel, Ok, + parent, name, true ) +{ + TQWidget *page = plainPage(); + TQVBoxLayout *tqlayout = new TQVBoxLayout( page, 0, spacingHint() ); + + mEditor = new KEditListBox( i18n( "Recent Addresses" ), page, "", false, + KEditListBox::Add | KEditListBox::Remove ); + tqlayout->addWidget( mEditor ); +} + +void RecentAddressDialog::setAddresses( const TQStringList &addrs ) +{ + mEditor->clear(); + mEditor->insertStringList( addrs ); +} + +TQStringList RecentAddressDialog::addresses() const +{ + return mEditor->items(); +} diff --git a/libtdepim/recentaddresses.h b/libtdepim/recentaddresses.h new file mode 100644 index 000000000..446f6c684 --- /dev/null +++ b/libtdepim/recentaddresses.h @@ -0,0 +1,132 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- + * + * Copyright (c) 2001-2003 Carsten Pfeiffer + * Copyright (c) 2003 Zack Rusin + * + * KMail is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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 RECENTADDRESSES_H +#define RECENTADDRESSES_H + +#include +#include + +#include + +#include + +class KConfig; +class KEditListBox; +namespace KRecentAddress { + +class KDE_EXPORT RecentAddressDialog : public KDialogBase +{ + public: + RecentAddressDialog( TQWidget *parent, const char *name = 0 ); + void setAddresses( const TQStringList &addrs ); + TQStringList addresses() const; + private: + KEditListBox *mEditor; +}; + +/** + * Handles a list of "recent email-addresses". Simply set a max-count and + * call @ref add() to add entries. + * + * @author Carsten Pfeiffer + */ + +class KDE_EXPORT RecentAddresses +{ +public: + ~RecentAddresses(); + /** + * @returns the only possible instance of this class. + */ + static RecentAddresses * self(KConfig *config = 0L); + + /* + * @return true if self() was called, i.e. a RecentAddresses instance exists + */ + static bool exists() { return s_self != 0; } + + /** + * @returns the list of recent addresses. + * Note: an entry doesn't have to be one email address, it can be multiple, + * like "Foo , Bar Baz ". + */ + TQStringList addresses() const; + const KABC::Addressee::List& kabcAddresses() const { return m_addresseeList; } + + /** + * Adds an entry to the list. + * Note: an entry doesn't have to be one email address, it can be multiple, + * like "Foo , Bar Baz ". + */ + void add( const TQString& entry ); + + /** + * Sets the maximum number, the list can hold. The list adjusts to this + * size if necessary. Default maximum is 40. + */ + void setMaxCount( int count ); + + /** + * @returns the current maximum number of entries. + */ + uint maxCount() const { return m_maxCount; } + + /** + * Loads the list of recently used addresses from the configfile. + * Automatically done on startup. + */ + void load( KConfig * ); + + /** + * Saves the list of recently used addresses to the configfile. + * Make sure to call KGlobal::config()->sync() afterwards, to really save. + */ + void save( KConfig * ); + + /** + * Removes all entries from the history. + */ + void clear(); + +private: + RecentAddresses(KConfig *config = 0L); + + KABC::Addressee::List m_addresseeList; + + void adjustSize(); + + uint m_maxCount; + + static RecentAddresses *s_self; +}; + +} + +#endif // KMRECENTADDR_H diff --git a/libtdepim/resourceabc.cpp b/libtdepim/resourceabc.cpp new file mode 100644 index 000000000..dbcc98f87 --- /dev/null +++ b/libtdepim/resourceabc.cpp @@ -0,0 +1,38 @@ +/* + This file is part of libtdepim. + + 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. + + As a special exception, permission is given to link this program + with any edition of TQt, and distribute the resulting executable, + without including the source code for TQt in the source distribution. +*/ + +#include "resourceabc.h" + +using namespace KPIM; + +ResourceABC::ResourceABC( const KConfig* config ) + : KABC::Resource( config ) +{ +} + +ResourceABC::~ResourceABC() +{ +} + +#include "resourceabc.moc" diff --git a/libtdepim/resourceabc.h b/libtdepim/resourceabc.h new file mode 100644 index 000000000..b6ef3ec98 --- /dev/null +++ b/libtdepim/resourceabc.h @@ -0,0 +1,116 @@ +/* + This file is part of libtdepim. + + 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. + + As a special exception, permission is given to link this program + with any edition of TQt, and distribute the resulting executable, + without including the source code for TQt in the source distribution. +*/ + +#ifndef RESOURCEABC_H +#define RESOURCEABC_H + +#include +#include +#include + +// This is here because it can't go to kdelibs/kabc yet, but ultimately +// it should probably go there (maybe redesigned to have a real object +// for subresources). + +namespace KPIM { + +/** + * This class is the implementation of subfolder resources for KABC. + * More methods will be added to give KAddressBook the possibility to + * handle subresources. + */ + +class KDE_EXPORT ResourceABC : public KABC::Resource +{ + Q_OBJECT + TQ_OBJECT + +public: + ResourceABC( const KConfig* ); + virtual ~ResourceABC(); + + /** + * Get the UID to subresource map. This is necessary to implement + * the search order. + * The returned map has the UID as key and the resource it's in as + * the data. + */ + virtual TQMap uidToResourceMap() const = 0; + + /** + * If this resource has subresources, return a TQStringList of them. + * In most cases, resources do not have subresources, so this is + * by default just empty. + */ + virtual TQStringList subresources() const { return TQStringList(); } + + /** + * Is this subresource active or not? + */ + virtual bool subresourceActive( const TQString& ) const { return true; } + + /** + * Is the given subresource writable? + */ + virtual bool subresourceWritable( const TQString& ) const = 0; + + /** + * Completion weight for a given subresource + */ + virtual int subresourceCompletionWeight( const TQString& ) const = 0; + + /** + * Label for a given subresource + */ + virtual TQString subresourceLabel( const TQString& ) const = 0; + +public slots: + /** + * (De-)activate a subresource. + */ + virtual void setSubresourceActive( const TQString &, bool active ) = 0; + + /** + * Set completion weight for a given subresource + */ + virtual void setSubresourceCompletionWeight( const TQString&, int weight ) = 0; + +signals: + /** + * This signal is emitted when a subresource is added. + */ + void signalSubresourceAdded( KPIM::ResourceABC *, const TQString &type, + const TQString &subResource ); + + /** + * This signal is emitted when a subresource is removed. + */ + void signalSubresourceRemoved( KPIM::ResourceABC *, const TQString &type, + const TQString &subResource ); + +}; + +} + +#endif // RESOURCEABC_H diff --git a/libtdepim/sendsmsdialog.cpp b/libtdepim/sendsmsdialog.cpp new file mode 100644 index 000000000..218f9617d --- /dev/null +++ b/libtdepim/sendsmsdialog.cpp @@ -0,0 +1,85 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2005 Con Hennessy + Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ +#include +#include +#include + +#include + +#include "sendsmsdialog.h" + +SendSMSDialog::SendSMSDialog( const TQString &recipientName, TQWidget *parent, const char *name ) + : KDialogBase( Plain, i18n( "Send SMS" ), Ok | Cancel, Ok, parent, name, true, true ) +{ + TQWidget *page = plainPage(); + + TQGridLayout *tqlayout = new TQGridLayout( page, 3, 3, marginHint(), spacingHint() ); + + tqlayout->addWidget( new TQLabel( i18n( "Message" ), page ), 0, 0 ); + + mMessageLength = new TQLabel( "0/160", page ); + mMessageLength->tqsetAlignment( TQt::AlignRight ); + tqlayout->addWidget( mMessageLength, 0, 2 ); + + mText = new TQTextEdit( page ); + tqlayout->addMultiCellWidget( mText, 1, 1, 0, 2 ); + + tqlayout->addWidget( new TQLabel( i18n( "Recipient:" ), page ), 2, 0 ); + tqlayout->addWidget( new TQLabel( recipientName, page ), 2, 2 ); + + setButtonText( Ok, i18n( "Send" ) ); + + connect( mText, TQT_SIGNAL( textChanged() ), + this, TQT_SLOT( updateMessageLength() ) ); + connect( mText, TQT_SIGNAL( textChanged() ), + this, TQT_SLOT( updateButtons() ) ); + + updateButtons(); + + mText->setFocus(); +} + +TQString SendSMSDialog::text() const +{ + return mText->text(); +} + +void SendSMSDialog::updateMessageLength() +{ + int length = mText->length(); + + if( length > 480 ) + mMessageLength->setText( TQString( "%1/%2 (%3)" ).tqarg( length ).tqarg( 500 ).tqarg( 4 ) ); + else if( length > 320 ) + mMessageLength->setText( TQString( "%1/%2 (%3)" ).tqarg( length ).tqarg( 480 ).tqarg( 3 ) ); + else if( length > 160 ) + mMessageLength->setText( TQString( "%1/%2 (%3)" ).tqarg( length ).tqarg( 320 ).tqarg( 2 ) ); + else + mMessageLength->setText( TQString( "%1/%2" ).tqarg( length ).tqarg( 160 ) ); +} + +void SendSMSDialog::updateButtons() +{ + enableButton( Ok, mText->length() > 0 ); +} + +#include "sendsmsdialog.moc" diff --git a/libtdepim/sendsmsdialog.h b/libtdepim/sendsmsdialog.h new file mode 100644 index 000000000..af7a97e9b --- /dev/null +++ b/libtdepim/sendsmsdialog.h @@ -0,0 +1,50 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2005 Con Hennessy + Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ +#ifndef SENDSMSDIALOG_H +#define SENDSMSDIALOG_H + +#include + +class TQLabel; +class TQTextEdit; + +class SendSMSDialog : public KDialogBase +{ + Q_OBJECT + TQ_OBJECT + + public: + SendSMSDialog( const TQString &recipientName, TQWidget *parent, const char *name = 0 ); + + TQString text() const; + + private slots: + void updateMessageLength(); + void updateButtons(); + + private: + TQLabel *mMessageLength; + TQTextEdit *mText; +}; + +#endif + diff --git a/libtdepim/sidebarextension.cpp b/libtdepim/sidebarextension.cpp new file mode 100644 index 000000000..db49dc71f --- /dev/null +++ b/libtdepim/sidebarextension.cpp @@ -0,0 +1,40 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2003 Daniel Molkentin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#include "sidebarextension.h" + +#include +#include + +using namespace KParts; + +SideBarExtension::SideBarExtension(TQWidget *exported, KParts::ReadOnlyPart *parent, const char* name) +: TQObject(parent, name), m_exported(exported), d(0) +{ +} + +SideBarExtension::~SideBarExtension() +{ +} + +#include "sidebarextension.moc" + +// vim: ts=2 sw=2 et diff --git a/libtdepim/sidebarextension.h b/libtdepim/sidebarextension.h new file mode 100644 index 000000000..fc39ef6c6 --- /dev/null +++ b/libtdepim/sidebarextension.h @@ -0,0 +1,69 @@ +/* + This file is part of libtdepim. + + Copyright (C) 2003 Daniel Molkentin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ +#ifndef SIDEBAREXTENSION_H +#define SIDEBAREXTENSION_H + +#include +#include + +class TQWidget; + +namespace KParts +{ + + class ReadOnlyPart; + + /** + * Provides a way to export a widget which will be displayed in Kontacts + * stackview at the left + **/ + class KDE_EXPORT SideBarExtension : public TQObject + { + Q_OBJECT + TQ_OBJECT + + public: + /** + * Constucts a SideBarExtension. + * + * @param exported A TQWidget derived widget that will be provided for the + * users of SideBarExtension. + * @param parent The parent widget. + * @param name The name of the class. + **/ + SideBarExtension(TQWidget *exported, KParts::ReadOnlyPart *parent, const char* name); + ~SideBarExtension(); + + /** + * Retrieve a pointer to the widget. May be 0 if 0 was passed in the constructor + **/ + TQWidget* widget() const { return m_exported; } + + private: + TQWidget* m_exported; + + class SideBarExtensionPrivate; + SideBarExtensionPrivate *d; + }; +} +#endif // SIDEBAREXTENSION_H + +// vim: ts=2 sw=2 et diff --git a/libtdepim/spellingfilter.cpp b/libtdepim/spellingfilter.cpp new file mode 100644 index 000000000..cc94968d4 --- /dev/null +++ b/libtdepim/spellingfilter.cpp @@ -0,0 +1,220 @@ +/** + * spellingfilter.cpp + * + * Copyright (c) 2002 Dave Corrie + * + * This file is part of KMail. + * + * KMail 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 "spellingfilter.h" + +//----------------------------------------------------------------------------- +// SpellingFilter implementation +// + +SpellingFilter::SpellingFilter(const TQString& text, const TQString& quotePrefix, + UrlFiltering filterUrls, EmailAddressFiltering filterEmailAddresses, + const TQStringList& filterStrings) + : mOriginal(text) +{ + TextCensor c(text); + + if(!quotePrefix.isEmpty()) + c.censorQuotations(quotePrefix); + + if(filterUrls) + c.censorUrls(); + + if(filterEmailAddresses) + c.censorEmailAddresses(); + + TQStringList::const_iterator iter = filterStrings.begin(); + while(iter != filterStrings.end()) + { + c.censorString(*iter); + ++iter; + } + + mFiltered = c.censoredText(); +} + +TQString SpellingFilter::originalText() const +{ + return mOriginal; +} + +TQString SpellingFilter::filteredText() const +{ + return mFiltered; +} + +//----------------------------------------------------------------------------- +// SpellingFilter::TextCensor implementation +// + +SpellingFilter::TextCensor::TextCensor(const TQString& s) + : LinkLocator(s) +{ + +} + +void SpellingFilter::TextCensor::censorQuotations(const TQString& quotePrefix) +{ + mPos = 0; + while(mPos < static_cast(mText.length())) + { + // Find start of quotation + findQuotation(quotePrefix); + if(mPos < static_cast(mText.length())) + { + int start = mPos; + skipQuotation(quotePrefix); + + // Replace quotation with spaces + int len = mPos - start; + TQString spaces; + spaces.fill(' ', len); + mText.replace(start, len, spaces); + + //kdDebug(5006) << "censored quotation [" + // << start << ", " << mPos << ")" << endl; + } + } +} + +void SpellingFilter::TextCensor::censorUrls() +{ + mPos = 0; + while(mPos < static_cast(mText.length())) + { + // Find start of url + TQString url; + while(mPos < static_cast(mText.length()) && url.isEmpty()) + { + url = getUrl(); + ++mPos; + } + + if(mPos < static_cast(mText.length()) && !url.isEmpty()) + { + int start = mPos - url.length(); + + // Replace url with spaces + url.fill(' '); + mText.replace(start, url.length(), url); + + //kdDebug(5006) << "censored url [" + // << start << ", " << mPos << ")" << endl; + } + } +} + +void SpellingFilter::TextCensor::censorEmailAddresses() +{ + mPos = 0; + while(mPos < static_cast(mText.length())) + { + // Find start of email address + findEmailAddress(); + if(mPos < static_cast(mText.length())) + { + TQString address = getEmailAddress(); + ++mPos; + if(!address.isEmpty()) + { + int start = mPos - address.length(); + + // Replace address with spaces + address.fill(' '); + mText.replace(start, address.length(), address); + + //kdDebug(5006) << "censored addr [" + // << start << ", "<< mPos << ")" << endl; + } + } + } +} + +void SpellingFilter::TextCensor::censorString(const TQString& s) +{ + mPos = 0; + while(mPos != -1) + { + // Find start of string + mPos = mText.find(s, mPos); + if(mPos != -1) + { + // Replace string with spaces + TQString spaces; + spaces.fill(' ', s.length()); + mText.replace(mPos, s.length(), spaces); + mPos += s.length(); + + //kdDebug(5006) << "censored string [" + // << mPos << ", "<< mPos+s.length() << ")" << endl; + } + } +} + +TQString SpellingFilter::TextCensor::censoredText() const +{ + return mText; +} + +//----------------------------------------------------------------------------- +// text censorship helper functions +// + +bool SpellingFilter::TextCensor::atLineStart() const +{ + return (mPos == 0 && static_cast(mText.length()) > 0) || (mText[mPos - 1] == '\n'); +} + +void SpellingFilter::TextCensor::skipLine() +{ + mPos = mText.find('\n', mPos); + if(mPos == -1) + mPos = static_cast(mText.length()); + else + ++mPos; +} + +bool SpellingFilter::TextCensor::atQuotation(const TQString& quotePrefix) const +{ + return atLineStart() && + mText.mid(mPos, quotePrefix.length()) == quotePrefix; +} + +void SpellingFilter::TextCensor::skipQuotation(const TQString& quotePrefix) +{ + while(atQuotation(quotePrefix)) + skipLine(); +} + +void SpellingFilter::TextCensor::findQuotation(const TQString& quotePrefix) +{ + while(mPos < static_cast(mText.length()) && !atQuotation(quotePrefix)) + skipLine(); +} + +void SpellingFilter::TextCensor::findEmailAddress() +{ + while(mPos < static_cast(mText.length()) && mText[mPos] != '@') + ++mPos; +} + diff --git a/libtdepim/spellingfilter.h b/libtdepim/spellingfilter.h new file mode 100644 index 000000000..4178a888e --- /dev/null +++ b/libtdepim/spellingfilter.h @@ -0,0 +1,77 @@ +/* + * spellingfilter.h + * + * Copyright (c) 2002 Dave Corrie + * + * This file is part of KMail. + * + * KMail 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 SPELLINGFILTER_H_INCLUDED +#define SPELLINGFILTER_H_INCLUDED + +#include +#include +#include "linklocator.h" + +#include + +class KDE_EXPORT SpellingFilter +{ +public: + enum UrlFiltering { DontFilterUrls, FilterUrls }; + enum EmailAddressFiltering { DontFilterEmailAddresses, FilterEmailAddresses }; + + SpellingFilter(const TQString& text, const TQString& quotePrefix, + UrlFiltering filterUrls = FilterUrls, + EmailAddressFiltering filterEmailAddresses = FilterEmailAddresses, + const TQStringList& filterStrings = TQStringList()); + + TQString originalText() const; + TQString filteredText() const; + + class TextCensor; + +private: + const TQString mOriginal; + TQString mFiltered; +}; + +class SpellingFilter::TextCensor : public LinkLocator +{ +public: + TextCensor(const TQString& s); + + void censorQuotations(const TQString& quotePrefix); + void censorUrls(); + void censorEmailAddresses(); + void censorString(const TQString& s); + + TQString censoredText() const; + +private: + bool atLineStart() const; + void skipLine(); + + bool atQuotation(const TQString& quotePrefix) const; + void skipQuotation(const TQString& quotePrefix); + void findQuotation(const TQString& quotePrefix); + + void findEmailAddress(); +}; + +#endif // SPELLINGFILTER_H_INCLUDED + diff --git a/libtdepim/ssllabel.cpp b/libtdepim/ssllabel.cpp new file mode 100644 index 000000000..8068aa001 --- /dev/null +++ b/libtdepim/ssllabel.cpp @@ -0,0 +1,97 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- + * + * This file is part of KMail, the KDE mail client. + * + * Copyright (c) 2003 Zack Rusin + * + * KMail is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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. + */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "ssllabel.h" + +#include +#include + +#include + +namespace KPIM { + +SSLLabel::SSLLabel( TQWidget* parent ) + : TQLabel( parent ) +{ + setState( Done ); +} + +void SSLLabel::setEncrypted( bool enc ) +{ + if ( enc ) { + m_lastEncryptionState = Encrypted; + } else { + m_lastEncryptionState = Unencrypted; + } +} + +SSLLabel::State SSLLabel::lastState() const +{ + return m_lastEncryptionState; +} + +void SSLLabel::setState( State state ) +{ + switch( state ) { + case Encrypted: + TQToolTip::remove( this ); + TQToolTip::add( this, i18n("Connection is encrypted") ); + setPixmap( SmallIcon( "encrypted", KGlobal::instance() ) ); + show(); + break; + case Unencrypted: + TQToolTip::remove( this ); + TQToolTip::add( this, i18n("Connection is unencrypted") ); + setPixmap( SmallIcon( "decrypted" ) ); + show(); + break; + case Done: + TQToolTip::remove( this ); + hide(); + break; + case Clean: + default: + TQToolTip::remove( this ); + hide(); + //we return because we do not save the state as the only + //action we want to perform is to hide ourself + return; + } + m_lastEncryptionState = state; +} + + +} //end namespace KPIM + +//#include "ssllabel.moc" diff --git a/libtdepim/ssllabel.h b/libtdepim/ssllabel.h new file mode 100644 index 000000000..03a841bed --- /dev/null +++ b/libtdepim/ssllabel.h @@ -0,0 +1,59 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- + * + * This file is part of KMail, the KDE mail client. + * + * Copyright (c) 2003 Zack Rusin + * + * KMail is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + * of TQt that use the same license as TQt), 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 + * TQt. 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 SSLLABEL_H +#define SSLLABEL_H + +#include + +namespace KPIM { + + class SSLLabel : public TQLabel + { + public: + enum State { + Encrypted, + Unencrypted, + Clean, + Done + }; + SSLLabel( TQWidget* parent ); + + void setEncrypted( bool enc=true ); + void setState( State state ); + State lastState() const; + private: + State m_lastEncryptionState; + }; + +} + +#endif diff --git a/libtdepim/statusbarprogresswidget.cpp b/libtdepim/statusbarprogresswidget.cpp new file mode 100644 index 000000000..c417905a0 --- /dev/null +++ b/libtdepim/statusbarprogresswidget.cpp @@ -0,0 +1,296 @@ +/* + statusbarprogresswidget.cpp + + This file is part of KMail, the KDE mail client. + + (C) 2004 KMail Authors + Includes StatusbarProgressWidget which is based on KIOLittleProgressDlg + by Matt Koss + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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 "ssllabel.h" +using KPIM::SSLLabel; +#include "progressmanager.h" +using KPIM::ProgressItem; +using KPIM::ProgressManager; + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "progressdialog.h" +#include "statusbarprogresswidget.h" + +using namespace KPIM; + +//----------------------------------------------------------------------------- +StatusbarProgressWidget::StatusbarProgressWidget( ProgressDialog* progressDialog, TQWidget* parent, bool button ) + : TQFrame( parent ), mCurrentItem( 0 ), mProgressDialog( progressDialog ), + mDelayTimer( 0 ), mBusyTimer( 0 ) +{ + m_bShowButton = button; + int w = fontMetrics().width( " 999.9 kB/s 00:00:01 " ) + 8; + box = new TQHBoxLayout( this, 0, 0 ); + + m_pButton = new TQPushButton( this ); + m_pButton->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, + TQSizePolicy::Minimum ) ); + m_pButton->setPixmap( SmallIcon( "up" ) ); + box->addWidget( m_pButton ); + stack = new TQWidgetStack( this ); + stack->setMaximumHeight( fontMetrics().height() ); + box->addWidget( stack ); + + m_sslLabel = new SSLLabel( this ); + box->addWidget( m_sslLabel ); + + TQToolTip::add( m_pButton, i18n("Open detailed progress dialog") ); + + m_pProgressBar = new KProgress( this ); + m_pProgressBar->setLineWidth( 1 ); + m_pProgressBar->setFrameStyle( TQFrame::Box ); + m_pProgressBar->installEventFilter( this ); + m_pProgressBar->setMinimumWidth( w ); + stack->addWidget( m_pProgressBar, 1 ); + + m_pLabel = new TQLabel( TQString(), this ); + m_pLabel->tqsetAlignment( AlignHCenter | AlignVCenter ); + m_pLabel->installEventFilter( this ); + m_pLabel->setMinimumWidth( w ); + stack->addWidget( m_pLabel, 2 ); + m_pButton->setMaximumHeight( fontMetrics().height() ); + setMinimumWidth( tqminimumSizeHint().width() ); + + mode = None; + setMode(); + + connect( m_pButton, TQT_SIGNAL( clicked() ), + progressDialog, TQT_SLOT( slotToggleVisibility() ) ); + + connect ( ProgressManager::instance(), TQT_SIGNAL( progressItemAdded( KPIM::ProgressItem * ) ), + this, TQT_SLOT( slotProgressItemAdded( KPIM::ProgressItem * ) ) ); + connect ( ProgressManager::instance(), TQT_SIGNAL( progressItemCompleted( KPIM::ProgressItem * ) ), + this, TQT_SLOT( slotProgressItemCompleted( KPIM::ProgressItem * ) ) ); + connect ( ProgressManager::instance(), TQT_SIGNAL(progressItemUsesBusyIndicator(KPIM::ProgressItem*,bool)), + this, TQT_SLOT( updateBusyMode() ) ); + + connect ( progressDialog, TQT_SIGNAL( visibilityChanged( bool )), + this, TQT_SLOT( slotProgressDialogVisible( bool ) ) ); + + mDelayTimer = new TQTimer( this ); + connect ( mDelayTimer, TQT_SIGNAL( timeout() ), + this, TQT_SLOT( slotShowItemDelayed() ) ); +} + +// There are three cases: no progressitem, one progressitem (connect to it directly), +// or many progressitems (display busy indicator). Let's call them 0,1,N. +// In slot..Added we can only end up in 1 or N. +// In slot..Removed we can end up in 0, 1, or we can stay in N if we were already. + +void StatusbarProgressWidget::updateBusyMode() +{ + connectSingleItem(); // if going to 1 item + if ( mCurrentItem ) { // Exactly one item + delete mBusyTimer; + mBusyTimer = 0; + mDelayTimer->start( 1000, true ); + } + else { // N items + if ( !mBusyTimer ) { + mBusyTimer = new TQTimer( this ); + connect( mBusyTimer, TQT_SIGNAL( timeout() ), + this, TQT_SLOT( slotBusyIndicator() ) ); + mDelayTimer->start( 1000, true ); + } + } +} + +void StatusbarProgressWidget::slotProgressItemAdded( ProgressItem *item ) +{ + if ( item->parent() ) + return; // we are only interested in top level items + + updateBusyMode(); +} + +void StatusbarProgressWidget::slotProgressItemCompleted( ProgressItem *item ) +{ + if ( item->parent() ) return; // we are only interested in top level items + connectSingleItem(); // if going back to 1 item + if ( ProgressManager::instance()->isEmpty() ) { // No item + // Done. In 5s the progress-widget will close, then we can clean up the statusbar + TQTimer::singleShot( 5000, this, TQT_SLOT( slotClean() ) ); + } else if ( mCurrentItem ) { // Exactly one item + delete mBusyTimer; + mBusyTimer = 0; + activateSingleItemMode(); + } +} + +void StatusbarProgressWidget::connectSingleItem() +{ + if ( mCurrentItem ) { + disconnect ( mCurrentItem, TQT_SIGNAL( progressItemProgress( KPIM::ProgressItem *, unsigned int ) ), + this, TQT_SLOT( slotProgressItemProgress( KPIM::ProgressItem *, unsigned int ) ) ); + mCurrentItem = 0; + } + mCurrentItem = ProgressManager::instance()->singleItem(); + if ( mCurrentItem ) { + connect ( mCurrentItem, TQT_SIGNAL( progressItemProgress( KPIM::ProgressItem *, unsigned int ) ), + this, TQT_SLOT( slotProgressItemProgress( KPIM::ProgressItem *, unsigned int ) ) ); + } +} + +void StatusbarProgressWidget::activateSingleItemMode() +{ + m_pProgressBar->setTotalSteps( 100 ); + m_pProgressBar->setProgress( mCurrentItem->progress() ); + m_pProgressBar->setPercentageVisible( true ); +} + +void StatusbarProgressWidget::slotShowItemDelayed() +{ + bool noItems = ProgressManager::instance()->isEmpty(); + if ( mCurrentItem ) { + activateSingleItemMode(); + } else if ( !noItems ) { // N items + m_pProgressBar->setTotalSteps( 0 ); + m_pProgressBar->setPercentageVisible( false ); + Q_ASSERT( mBusyTimer ); + if ( mBusyTimer ) + mBusyTimer->start( 100 ); + } + + if ( !noItems && mode == None ) { + mode = Progress; + setMode(); + } +} + +void StatusbarProgressWidget::slotBusyIndicator() +{ + int p = m_pProgressBar->progress(); + m_pProgressBar->setProgress( p + 10 ); +} + +void StatusbarProgressWidget::slotProgressItemProgress( ProgressItem *item, unsigned int value ) +{ + Q_ASSERT( item == mCurrentItem); // the only one we should be connected to + m_pProgressBar->setProgress( value ); +} + +void StatusbarProgressWidget::slotSetSSL( bool ssl ) +{ + m_sslLabel->setEncrypted( ssl ); +} + +void StatusbarProgressWidget::setMode() { + switch ( mode ) { + case None: + if ( m_bShowButton ) { + m_pButton->hide(); + } + m_sslLabel->setState( SSLLabel::Done ); + // show the empty label in order to make the status bar look better + stack->show(); + stack->raiseWidget( m_pLabel ); + break; + +#if 0 + case Label: + if ( m_bShowButton ) { + m_pButton->show(); + } + m_sslLabel->setState( m_sslLabel->lastState() ); + stack->show(); + stack->raiseWidget( m_pLabel ); + break; +#endif + + case Progress: + stack->show(); + stack->raiseWidget( m_pProgressBar ); + if ( m_bShowButton ) { + m_pButton->show(); + } + m_sslLabel->setState( m_sslLabel->lastState() ); + break; + } +} + +void StatusbarProgressWidget::slotClean() +{ + // check if a new item showed up since we started the timer. If not, clear + if ( ProgressManager::instance()->isEmpty() ) { + m_pProgressBar->setProgress( 0 ); + //m_pLabel->clear(); + mode = None; + setMode(); + } +} + +bool StatusbarProgressWidget::eventFilter( TQObject *, TQEvent *ev ) +{ + if ( ev->type() == TQEvent::MouseButtonPress ) { + TQMouseEvent *e = (TQMouseEvent*)ev; + + if ( e->button() == Qt::LeftButton && mode != None ) { // toggle view on left mouse button + // Consensus seems to be that we should show/hide the fancy dialog when the user + // clicks anywhere in the small one. + mProgressDialog->slotToggleVisibility(); + return true; + } + } + return false; +} + +void StatusbarProgressWidget::slotProgressDialogVisible( bool b ) +{ + // Update the hide/show button when the detailed one is shown/hidden + if ( b ) { + m_pButton->setPixmap( SmallIcon( "down" ) ); + TQToolTip::remove( m_pButton ); + TQToolTip::add( m_pButton, i18n("Hide detailed progress window") ); + setMode(); + } else { + m_pButton->setPixmap( SmallIcon( "up" ) ); + TQToolTip::remove( m_pButton ); + TQToolTip::add( m_pButton, i18n("Show detailed progress window") ); + } +} + +#include "statusbarprogresswidget.moc" diff --git a/libtdepim/statusbarprogresswidget.h b/libtdepim/statusbarprogresswidget.h new file mode 100644 index 000000000..8b08d2cf9 --- /dev/null +++ b/libtdepim/statusbarprogresswidget.h @@ -0,0 +1,106 @@ +#ifndef __KPIM_STATUSBARPROGRESSWIDGET_H +#define __KPIM_STATUSBARPROGRESSWIDGET_H +/* + statusbarprogresswidget.h + + This file is part of KMail, the KDE mail client. + + (C) 2004 KMail Authors + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail 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 TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), 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 + TQt. 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. +*/ +/** + * A specialized progress widget class, heavily based on + * kio_littleprogress_dlg (it looks similar) + */ + +#include + +class KMMainWidget; +class KProgress; +class TQPushButton; +class TQWidgetStack; +class TQBoxLayout; +class TQLabel; +class TQTimer; + +namespace KPIM { +class SSLLabel; +class ProgressItem; +class ProgressDialog; + +class KDE_EXPORT StatusbarProgressWidget : public TQFrame { + + Q_OBJECT + TQ_OBJECT + +public: + + StatusbarProgressWidget( ProgressDialog* progressDialog, TQWidget* parent, bool button = true ); + +public slots: + + void slotClean(); + void slotSetSSL( bool ); + + void slotProgressItemAdded( KPIM::ProgressItem *i ); + void slotProgressItemCompleted( KPIM::ProgressItem *i ); + void slotProgressItemProgress( KPIM::ProgressItem *i, unsigned int value ); + +protected slots: + void slotProgressDialogVisible( bool ); + void slotShowItemDelayed(); + void slotBusyIndicator(); + void updateBusyMode(); + +protected: + void setMode(); + void connectSingleItem(); + void activateSingleItemMode(); + + virtual bool eventFilter( TQObject *, TQEvent * ); + +private: + KProgress* m_pProgressBar; + TQLabel* m_pLabel; + SSLLabel* m_sslLabel; + TQPushButton* m_pButton; + + enum Mode { None, /*Label,*/ Progress }; + + uint mode; + bool m_bShowButton; + + TQBoxLayout *box; + TQWidgetStack *stack; + ProgressItem *mCurrentItem; + ProgressDialog* mProgressDialog; + TQTimer *mDelayTimer; + TQTimer *mBusyTimer; +}; + +} // namespace + +#endif diff --git a/libtdepim/tdepim.widgets b/libtdepim/tdepim.widgets new file mode 100644 index 000000000..765abc23b --- /dev/null +++ b/libtdepim/tdepim.widgets @@ -0,0 +1,29 @@ +[Global] +PluginName=KDEPimWidgets +Includes=kinstance.h +Init=new KInstance("tdepimwidgets"); + +[KPIM::AddresseeLineEdit] +ToolTip=Addressee Line Edit (KDE-PIM) +WhatsThis=A line edit which lets you select addressees from the addressbook +IncludeFile=libtdepim/addresseelineedit.h +Group=Input (KDE-PIM) + +[KPIM::ClickLineEdit] +ToolTip=Click Line Edit (KDE-PIM) +WhatsThis=A line edit that shows grayed-out default text when no text is set. +IncludeFile=libtdepim/clicklineedit.h +Group=Input (KDE-PIM) + +[KDateEdit] +ToolTip=Date Edit Combobox (KDE-PIM) +WhatsThis=A widget to enter a date. It can also be selected from a date picker calendar. +IncludeFile=libtdepim/kdateedit.h +Group=Input (KDE-PIM) + +[KTimeEdit] +ToolTip=Time Edit Combobox (KDE-PIM) +WhatsThis=A widget to enter a time. It can also be selected from a drop-down list. +IncludeFile=libtdepim/ktimeedit.h +ConstructorArgs=(parent, TQTime::currentTime(), name) +Group=Input (KDE-PIM) diff --git a/libtdepim/tdepimmacros.h b/libtdepim/tdepimmacros.h new file mode 100644 index 000000000..b341ee7ba --- /dev/null +++ b/libtdepim/tdepimmacros.h @@ -0,0 +1,35 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2002-2003 KDE Team + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// WARNING Don't add include guards here, they were removed on purpose + +#include +#include + +#if KDE_IS_VERSION( 3,3,90 ) +/* life is great */ +#else +/* workaround typo that breaks compilation with newer gcc */ +#undef KDE_EXPORT +#define KDE_EXPORT +#undef KDE_NO_EXPORT +#define KDE_NO_EXPORT +#endif diff --git a/libtdepim/tdepimprotocols.h b/libtdepim/tdepimprotocols.h new file mode 100644 index 000000000..e269fcabd --- /dev/null +++ b/libtdepim/tdepimprotocols.h @@ -0,0 +1,32 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2005 Rafal Rzepecki + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDEPIM_KDEPIMPROTOCOLS_H +#define KDEPIM_KDEPIMPROTOCOLS_H + +/* a central place to store protocol strings to avoid knowledge duplication */ + +#define KDEPIMPROTOCOL_CONTACT "uid:" +#define KDEPIMPROTOCOL_EMAIL "kmail:" +#define KDEPIMPROTOCOL_INCIDENCE "urn:x-ical" +#define KDEPIMPROTOCOL_NEWSARTICLE "news:" + +#endif diff --git a/libtdepim/tests/Makefile.am b/libtdepim/tests/Makefile.am new file mode 100644 index 000000000..217676cae --- /dev/null +++ b/libtdepim/tests/Makefile.am @@ -0,0 +1,35 @@ +AM_CPPFLAGS = -I$(top_builddir)/libtdepim -I$(top_srcdir)/libtdepim -I$(top_srcdir)/libemailfunctions $(all_includes) +AM_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +LDADD = ../libtdepim.la $(LIB_KDECORE) + +check_PROGRAMS = testwizard testaddresseelineedit \ + testaddresseeselector \ + testutf7decoder \ + testutf7encoder \ + test_kregexp \ + testdateedit \ + testlinklocator \ + testkincidencechooser + +# disabled because of X dependency +# testdistrlist + +testwizard_SOURCES = testwizard.cpp myconfig.kcfgc +testaddresseelineedit_SOURCES = testaddresseelineedit.cpp +testaddresseeselector_SOURCES = testaddresseeselector.cpp +testutf7encoder_SOURCES = testutf7encoder2.cpp +testutf7decoder_SOURCES = testutf7decoder.cpp +test_kregexp_SOURCES = test_kregexp.cpp +testdateedit_SOURCES = testdateedit.cpp +testlinklocator_SOURCES = testlinklocator.cpp +#testdistrlist_SOURCES = testdistrlist.cpp +testkincidencechooser_SOURCES = testkincidencechooser.cpp + +#TESTS = testdistrlist + +METASOURCES = AUTO + +#example_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +#example_LDADD = ../libtdepim.la $(LIB_KDECORE) +#example_SOURCES = example.cpp exampleprefs_base.kcfgc + diff --git a/libtdepim/tests/myconfig.kcfgc b/libtdepim/tests/myconfig.kcfgc new file mode 100644 index 000000000..35e26c996 --- /dev/null +++ b/libtdepim/tests/myconfig.kcfgc @@ -0,0 +1,11 @@ +# Code generation options for kconfig_compiler +File=propagator_test.kcfg +ClassName=MyConfig +Singleton=true +Mutators=true +#Inherits=KPimPrefs +#IncludeFiles=libtdepim/kpimprefs.h +MemberVariables=public +GlobalEnums=true +ItemAccessors=true +SetUserTexts=true diff --git a/libtdepim/tests/propagator_test.kcfg b/libtdepim/tests/propagator_test.kcfg new file mode 100644 index 000000000..8fc971771 --- /dev/null +++ b/libtdepim/tests/propagator_test.kcfg @@ -0,0 +1,44 @@ + + + + + + + + true + + + + false + + + 0 + + + 1 + + + hallo + + + + + + + + + + + + + + + + + + diff --git a/libtdepim/tests/test_kregexp.cpp b/libtdepim/tests/test_kregexp.cpp new file mode 100644 index 000000000..511687d07 --- /dev/null +++ b/libtdepim/tests/test_kregexp.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +int +main() +{ + KInstance app("# "); + + // test for http://bugs.kde.org/show_bug.cgi?id=54886 + KRegExp3 reg("^"); + TQString res = reg.replace(TQString::tqfromLatin1("Fun stuff"), + TQString::tqfromLatin1("[fun] ")); + kdDebug() << res << endl; + +} diff --git a/libtdepim/tests/testaddresseelineedit.cpp b/libtdepim/tests/testaddresseelineedit.cpp new file mode 100644 index 000000000..12eb3c6b1 --- /dev/null +++ b/libtdepim/tests/testaddresseelineedit.cpp @@ -0,0 +1,44 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Daniel Molkentin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "../addresseelineedit.h" + +int main(int argc, char* argv[]) +{ + KAboutData aboutData("testaddresseelineedit","Test AddresseeLineEdit","0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + + KApplication app; + + KPIM::AddresseeLineEdit *kale = new KPIM::AddresseeLineEdit(0); + kale->resize( 400, 20 ); + kale->show(); + + return app.exec(); + +} + diff --git a/libtdepim/tests/testaddresseeselector.cpp b/libtdepim/tests/testaddresseeselector.cpp new file mode 100644 index 000000000..6b910e4b9 --- /dev/null +++ b/libtdepim/tests/testaddresseeselector.cpp @@ -0,0 +1,52 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Daniel Molkentin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "../addresseeselector.h" +#include "../addresseeemailselection.h" + +int main( int argc, char **argv ) +{ + KAboutData aboutData( "testaddresseeseletor", "Test AddresseeSelector", "0.1" ); + KCmdLineArgs::init( argc, argv, &aboutData ); + + KApplication app; + + KPIM::AddresseeEmailSelection selection; + + KPIM::AddresseeSelectorDialog dlg( &selection ); + dlg.exec(); + + kdDebug() << "to: " << selection.to() << endl; + kdDebug() << "cc: " << selection.cc() << endl; + kdDebug() << "bcc: " << selection.bcc() << endl; + + kdDebug() << "toDistlists: " << selection.toDistributionLists() << endl; + kdDebug() << "ccDistlists: " << selection.ccDistributionLists() << endl; + kdDebug() << "bccDistlists: " << selection.bccDistributionLists() << endl; + + return 0; +} diff --git a/libtdepim/tests/testdateedit.cpp b/libtdepim/tests/testdateedit.cpp new file mode 100644 index 000000000..46fabcfe1 --- /dev/null +++ b/libtdepim/tests/testdateedit.cpp @@ -0,0 +1,68 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. 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 "kdateedit.h" + +#include "testdateedit.h" + +DateEdit::DateEdit( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + TQVBoxLayout *tqlayout = new TQVBoxLayout( this ); + + KDateEdit *edit = new KDateEdit( this ); + tqlayout->addWidget( edit ); + + connect( edit, TQT_SIGNAL( dateChanged( const TQDate& ) ), + this, TQT_SLOT( dateChanged( const TQDate& ) ) ); +} + +void DateEdit::dateChanged( const TQDate &date ) +{ + if ( date.isValid() ) + qDebug( "%s", date.toString().latin1() ); + else + qDebug( "invalid date entered" ); +} + +int main(int argc,char **argv) +{ + KAboutData aboutData( "testdateedit", "Test KDateEdit", "0.1" ); + KCmdLineArgs::init( argc, argv, &aboutData ); + + KApplication app; + + DateEdit dateEdit; + app.setMainWidget( &dateEdit ); + dateEdit.show(); + + app.exec(); +} + +#include "testdateedit.moc" diff --git a/libtdepim/tests/testdateedit.h b/libtdepim/tests/testdateedit.h new file mode 100644 index 000000000..8693ffa00 --- /dev/null +++ b/libtdepim/tests/testdateedit.h @@ -0,0 +1,39 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2004 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef TESTDATEEDIT_H +#define TESTDATEEDIT_H + +#include + +class DateEdit : public TQWidget +{ + Q_OBJECT + TQ_OBJECT + + public: + DateEdit( TQWidget *parent = 0, const char *name = 0 ); + + public slots: + void dateChanged( const TQDate& ); +}; + +#endif diff --git a/libtdepim/tests/testdistrlist.cpp b/libtdepim/tests/testdistrlist.cpp new file mode 100644 index 000000000..f588f9a93 --- /dev/null +++ b/libtdepim/tests/testdistrlist.cpp @@ -0,0 +1,332 @@ +/* This file is part of the KDE project + Copyright (C) 2004 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "testdistrlist.h" + +#include +using KPIM::DistributionList; + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + // Use another directory than the real one, just to keep things clean + // KDEHOME needs to be writable though, for a ksycoca database + setenv( "KDEHOME", TQFile::encodeName( TQDir::homeDirPath() + "/.kde-testdistrlist" ), true ); + setenv( "KDE_FORK_SLAVES", "yes", true ); // simpler, for the final cleanup + + KApplication::disableAutoDcopRegistration(); + KCmdLineArgs::init(argc,argv,"testdistrlist", 0, 0, 0, 0); + KApplication app( false, false ); + + TestDistrList test; + test.setup(); + test.runAll(); + test.cleanup(); + kdDebug() << "All tests OK." << endl; + return 0; +} + +void TestDistrList::setup() +{ + // We need a std addressbook + KABC::AddressBook *ab = KABC::StdAddressBook::self(); + KABC::StdAddressBook::setAutomaticSave( false ); + + // and two contacts + KABC::Addressee addr1; + addr1.setName( "addr1" ); + addr1.setFormattedName( "addr1" ); + addr1.insertEmail( "addr1@kde.org", true ); + addr1.insertEmail( "addr1-alternate@kde.org" ); + ab->insertAddressee( addr1 ); + assert( addr1.emails().count() == 2 ); + + KABC::Addressee addr2; + addr2.setName( "addr2" ); + addr2.insertEmail( "addr2@kde.org", true ); + addr2.insertEmail( "addr2-alternate@kde.org" ); + ab->insertAddressee( addr2 ); + assert( addr2.emails().count() == 2 ); + + assert( !ab->findByName( "addr1" ).isEmpty() ); + assert( !ab->findByName( "addr2" ).isEmpty() ); +} + +void TestDistrList::runAll() +{ + testEmpty(); + testNewList(); + testInsertEntry(); + testRemoveEntry(); + testDuplicate(); + testDeleteList(); +} + +bool TestDistrList::check(const TQString& txt, TQString a, TQString b) +{ + if (a.isEmpty()) + a = TQString(); + if (b.isEmpty()) + b = TQString(); + if (a == b) { + kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl; + } + else { + kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl; + cleanup(); + exit(1); + } + return true; +} + +// taken from KMail +#include +#include +static bool removeDirAndContentsRecursively( const TQString & path ) +{ + kdDebug() << k_funcinfo << path << endl; + bool success = true; + + TQDir d; + d.setPath( path ); + d.setFilter( TQDir::Files | TQDir::Dirs | TQDir::Hidden ); + + const TQFileInfoList *list = d.entryInfoList(); + TQFileInfoListIterator it( *list ); + TQFileInfo *fi; + + while ( (fi = it.current()) != 0 ) { + if( fi->isDir() && !fi->isSymLink() ) { + if ( fi->fileName() != "." && fi->fileName() != ".." ) + success = success && removeDirAndContentsRecursively( fi->absFilePath() ); + } else { + success = success && d.remove( fi->absFilePath() ); + } + ++it; + } + + if ( success ) { + success = success && d.rmdir( path ); // nuke ourselves, we should be empty now + } + return success; +} + +void TestDistrList::cleanup() +{ + kdDebug() << k_funcinfo << endl; + KABC::AddressBook *ab = KABC::StdAddressBook::self(); + ab->clear(); + KABC::StdAddressBook::close(); + + TQString kdehome = TQFile::decodeName( getenv("KDEHOME") ); + KURL urlkdehome; urlkdehome.setPath( kdehome ); + // don't use KIO::NetAccess here since it needs X + // KIO::NetAccess::del( urlkdehome, 0 )i; + assert( removeDirAndContentsRecursively( kdehome ) ); +} + +void TestDistrList::testEmpty() +{ + kdDebug() << k_funcinfo << endl; + DistributionList dl; + assert( dl.isEmpty() ); +} + +void TestDistrList::testNewList() +{ + kdDebug() << k_funcinfo << endl; + DistributionList dl; + dl.setName( "foo" ); + assert( !dl.isEmpty() ); + check( "name set", dl.formattedName(), "foo" ); + assert( DistributionList::isDistributionList( dl ) ); + + KABC::AddressBook *ab = KABC::StdAddressBook::self(); + ab->insertAddressee( dl ); +#if 0 // can't do that until we have KABC::AddressBook::findByFormattedName, or we use setName() + KABC::Addressee::List addrList = ab->findByName( "foo" ); + assert( addrList.count() == 1 ); + KABC::Addressee addr = addrList.first(); + assert( !addr.isEmpty() ); + check( "correct name", addr.name(), "foo" ); + assert( DistributionList::isDistributionList( addr ) ); +#else + KABC::Addressee addr = dl; +#endif + + DistributionList dl2 = DistributionList::findByName( ab, "foo" ); + assert( !dl2.isEmpty() ); + check( "correct name", dl2.formattedName(), "foo" ); + assert( DistributionList::isDistributionList( dl2 ) ); + + // Test the ctor that takes an addressee + DistributionList dl3( addr ); + assert( !dl3.isEmpty() ); + assert( DistributionList::isDistributionList( dl3 ) ); + check( "correct name", dl3.formattedName(), "foo" ); +} + +void TestDistrList::testInsertEntry() +{ + kdDebug() << k_funcinfo << endl; + KABC::AddressBook *ab = KABC::StdAddressBook::self(); + DistributionList dl = DistributionList::findByName( ab, "foo" ); + assert( !dl.isEmpty() ); + +#if 0 // the usual method + KABC::Addressee addr1 = ab->findByName( "addr1" ).first(); + assert( !addr1.isEmpty() ); + dl.insertEntry( addr1 ); +#else // the kolab-resource method + dl.insertEntry( "addr1" ); +#endif + + KABC::Addressee addr2 = ab->findByName( "addr2" ).first(); + assert( !addr2.isEmpty() ); + dl.insertEntry( addr2, "addr2-alternate@kde.org" ); + + // Try inserting it again, should do nothing + dl.insertEntry( addr2, "addr2-alternate@kde.org" ); + + // And insert it with another email address + dl.insertEntry( addr2, "addr2@kde.org" ); + + // Test entries() + DistributionList::Entry::List entries = dl.entries( ab ); + check( "entries count", TQString::number( entries.count() ), "3" ); + check( "first entry", entries[0].addressee.name(), "addr1" ); + check( "first entry", entries[0].email, TQString() ); + check( "second entry", entries[1].addressee.name(), "addr2" ); + check( "second entry", entries[1].email, "addr2-alternate@kde.org" ); + check( "third entry", entries[2].addressee.name(), "addr2" ); + check( "third entry", entries[2].email, "addr2@kde.org" ); + + // Test emails() + TQStringList emails = dl.emails( ab ); + kdDebug() << emails << endl; + assert( emails.count() == 3 ); + check( "first email", emails[0], "addr1 " ); + check( "second email", emails[1], "addr2 " ); + check( "third email", emails[2], "addr2 " ); + + // Commit changes to the addressbook !! + ab->insertAddressee( dl ); +} + +void TestDistrList::testRemoveEntry() +{ + kdDebug() << k_funcinfo << endl; + KABC::AddressBook *ab = KABC::StdAddressBook::self(); + DistributionList dl = DistributionList::findByName( ab, "foo" ); + assert( !dl.isEmpty() ); + DistributionList::Entry::List entries = dl.entries( ab ); + check( "entries count before removeEntry", TQString::number( entries.count() ), "3" ); + + // Removing an empty entry shouldn't do anything + dl.removeEntry( KABC::Addressee() ); + check( "entries count after removing empty entry", TQString::number( dl.entries(ab).count() ), "3" ); + + KABC::Addressee addr1 = ab->findByName( "addr1" ).first(); + assert( !addr1.isEmpty() ); + // Removing an entry with the wrong email passed, shouldn't do anything + dl.removeEntry( addr1, "foo@foobar.com" ); + check( "entries count after removing entry with invalid email", TQString::number( dl.entries(ab).count() ), "3" ); + + // Now remove entry correctly + dl.removeEntry( addr1 ); + check( "removeEntry(addr1) worked", TQString::number( dl.entries(ab).count() ), "2" ); + TQStringList emails = dl.emails( ab ); + assert( emails.count() == 2 ); + check( "first email", emails[0], "addr2 " ); + + // Now move on to addr2. First remove with no or a wrong email (nothing should happen) + KABC::Addressee addr2 = ab->findByName( "addr2" ).first(); + assert( !addr2.isEmpty() ); + dl.removeEntry( addr2 ); + check( "entries count after removing entry with no email", TQString::number( dl.entries(ab).count() ), "2" ); + + // Now remove addr2 correctly + dl.removeEntry( addr2, "addr2@kde.org" ); + check( "entries count after removing addr2", TQString::number( dl.entries(ab).count() ), "1" ); + dl.removeEntry( addr2, "addr2-alternate@kde.org" ); + check( "entries count after removing alternate addr2", TQString::number( dl.entries(ab).count() ), "0" ); + assert( dl.entries(ab).isEmpty() ); + assert( dl.emails(ab).isEmpty() ); + assert( DistributionList::isDistributionList( dl ) ); + + ab->insertAddressee( dl ); +} + +void TestDistrList::testDuplicate() +{ + kdDebug() << k_funcinfo << endl; + // This is a special test for the case where we have a contact and a distr list with the same name + KABC::AddressBook *ab = KABC::StdAddressBook::self(); + KABC::Addressee addr; + addr.setName( "foo" ); + addr.insertEmail( "foo@kde.org", true ); + ab->insertAddressee( addr ); + +#if 0 // we need a findByFormattedName + KABC::Addressee::List addrList = ab->findByName( "foo" ); + assert( addrList.count() == 2 ); + + bool a = DistributionList::isDistributionList( addrList.first() ); + bool b = DistributionList::isDistributionList( addrList.last() ); + // one is a distr list, but not both + assert( a || b ); + // + assert( ! ( a && b ) ); +#endif + + DistributionList dl = DistributionList::findByName( ab, "foo" ); + assert( !dl.isEmpty() ); + assert( DistributionList::isDistributionList( dl ) ); + assert( dl.formattedName() == "foo" ); +} + +void TestDistrList::testDeleteList() +{ + kdDebug() << k_funcinfo << endl; + + KABC::AddressBook *ab = KABC::StdAddressBook::self(); + DistributionList dl = DistributionList::findByName( ab, "foo" ); + assert( !dl.isEmpty() ); + ab->removeAddressee( dl ); + dl = DistributionList::findByName( ab, "foo" ); + assert( dl.isEmpty() ); +} + +#include "testdistrlist.moc" diff --git a/libtdepim/tests/testdistrlist.h b/libtdepim/tests/testdistrlist.h new file mode 100644 index 000000000..3f64527e6 --- /dev/null +++ b/libtdepim/tests/testdistrlist.h @@ -0,0 +1,47 @@ +/* This file is part of the KDE project + Copyright (C) 2004 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef TESTDISTRLIST_H +#define TESTDISTRLIST_H + +#include + +class TestDistrList : public TQObject +{ + Q_OBJECT + TQ_OBJECT + +public: + TestDistrList() {} + void setup(); + void runAll(); + void cleanup(); + + // tests + void testEmpty(); + void testNewList(); + void testInsertEntry(); + void testRemoveEntry(); + void testDuplicate(); + void testDeleteList(); + +private: + bool check(const TQString& txt, TQString a, TQString b); +}; + +#endif diff --git a/libtdepim/tests/testkincidencechooser.cpp b/libtdepim/tests/testkincidencechooser.cpp new file mode 100644 index 000000000..1204f8dc2 --- /dev/null +++ b/libtdepim/tests/testkincidencechooser.cpp @@ -0,0 +1,45 @@ +/* + Copyright (C) 2009 Allen Winter + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include +using namespace KCal; + +#include "kincidencechooser.h" +using namespace KPIM; + +int main( int argc, char **argv ) +{ + KCmdLineArgs::init( argc, argv, "testkincidencechooser", 0, + "KIncidenceChooserTest", "1.0", + "kincidencechooser test app" ); + KApplication app; + KIncidenceChooser *chooser = new KIncidenceChooser(); + + Event event; + event.setSummary( i18n( "Meeting" ) ); + event.setDescription( i18n( "Discuss foo" ) ); + chooser->setIncidence( &event, &event ); + chooser->resize( 600, 600 ); + chooser->show(); + return app.exec(); +} diff --git a/libtdepim/tests/testlinklocator.cpp b/libtdepim/tests/testlinklocator.cpp new file mode 100644 index 000000000..548f61a9b --- /dev/null +++ b/libtdepim/tests/testlinklocator.cpp @@ -0,0 +1,114 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Ingo Kloecker + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// Test program for libtdepim/linklocator.* +#include + +#include +#include +#include + +#include +#include +#include +#include + +static bool check(const TQString& txt, const TQString& a, const TQString& b) +{ + if (a == b) { + kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl; + } + else { + kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl; + exit(1); + } + return true; +} + +static bool checkGetEmailAddress( const TQString & input, + int atPos, + const TQString & expRetVal, + bool allowBadAtPos = false ) +{ + if ( !allowBadAtPos && ( input[atPos] != '@' ) ) { + kdDebug() << "atPos (" << atPos << ") doesn't point to '@' in \"" + << input << "\". Fix the check!" << endl; + exit(1); + } + LinkLocator ll( input, atPos ); + const TQString retVal = ll.getEmailAddress(); + check( "getEmailAddress() \"" + input + "\", " + TQString::number( atPos ), + retVal, expRetVal ); + return true; +} + +int main(int argc, char *argv[]) +{ + KApplication::disableAutoDcopRegistration(); + KCmdLineArgs::init( argc, argv, "testlinklocator", 0, 0, 0, 0 ); + KApplication app( false, false ); + + // empty input + checkGetEmailAddress( TQString(), 0, TQString(), true ); + + // no '@' at scan position + checkGetEmailAddress( "foo@bar.baz", 0, TQString(), true ); + + // '@' in local part + checkGetEmailAddress( "foo@bar@bar.baz", 7, TQString() ); + + // empty local part + checkGetEmailAddress( "@bar.baz", 0, TQString() ); + checkGetEmailAddress( ".@bar.baz", 1, TQString() ); + checkGetEmailAddress( " @bar.baz", 1, TQString() ); + checkGetEmailAddress( ".!#$%&'*+-/=?^_`{|}~@bar.baz", strlen(".!#$%&'*+-/=?^_`{|}~"), TQString() ); + + // allowed special chars in local part of address + checkGetEmailAddress( "a.!#$%&'*+-/=?^_`{|}~@bar.baz", strlen("a.!#$%&'*+-/=?^_`{|}~"), "a.!#$%&'*+-/=?^_`{|}~@bar.baz" ); + + // '@' in domain part + checkGetEmailAddress( "foo@bar@bar.baz", 3, TQString() ); + + // domain part without dot + checkGetEmailAddress( "foo@bar", 3, TQString() ); + checkGetEmailAddress( "foo@bar.", 3, TQString() ); + checkGetEmailAddress( ".foo@bar", 4, TQString() ); + checkGetEmailAddress( "foo@bar ", 3, TQString() ); + checkGetEmailAddress( " foo@bar", 4, TQString() ); + checkGetEmailAddress( "foo@bar-bar", 3, TQString() ); + + // empty domain part + checkGetEmailAddress( "foo@", 3, TQString() ); + checkGetEmailAddress( "foo@.", 3, TQString() ); + checkGetEmailAddress( "foo@-", 3, TQString() ); + + // simple address + checkGetEmailAddress( "foo@bar.baz", 3, "foo@bar.baz" ); + checkGetEmailAddress( "foo@bar.baz.", 3, "foo@bar.baz" ); + checkGetEmailAddress( ".foo@bar.baz", 4, "foo@bar.baz" ); + checkGetEmailAddress( "foo@bar.baz-", 3, "foo@bar.baz" ); + checkGetEmailAddress( "-foo@bar.baz", 4, "foo@bar.baz" ); + checkGetEmailAddress( "foo@bar.baz ", 3, "foo@bar.baz" ); + checkGetEmailAddress( " foo@bar.baz", 4, "foo@bar.baz" ); + checkGetEmailAddress( "foo@bar-bar.baz", 3, "foo@bar-bar.baz" ); + + printf("\nTest OK !\n"); + + return 0; +} + diff --git a/libtdepim/tests/testutf7decoder.cpp b/libtdepim/tests/testutf7decoder.cpp new file mode 100644 index 000000000..b13fb30c3 --- /dev/null +++ b/libtdepim/tests/testutf7decoder.cpp @@ -0,0 +1,26 @@ +#include "qutf7codec.h" +#include "qutf7codec.cpp" +#include +#include +#include + +int main( int argc, char * argv[] ) { + if ( argc == 1 ) { + (void)new TQUtf7Codec; + + TQTextCodec * codec = TQTextCodec::codecForName("utf-7"); + assert(codec); + + TQTextIStream my_cin(stdin); + my_cin.setCodec(codec); + + TQTextOStream my_cout(stdout); + + TQString buffer = my_cin.read(); + + my_cout << buffer; + } else { + qWarning("usage: testutf7decoder string_to_decode\n"); + } + TQTextCodec::deleteAllCodecs(); +} diff --git a/libtdepim/tests/testutf7encoder.cpp b/libtdepim/tests/testutf7encoder.cpp new file mode 100644 index 000000000..2938cd660 --- /dev/null +++ b/libtdepim/tests/testutf7encoder.cpp @@ -0,0 +1,93 @@ +#include "qutf7codec.h" +#include "qutf7codec.cpp" +#include +#include + +void main( int argc, char * argv[] ) { + if ( argc == 2 ) { + TQUtf7Codec * codec = new TQUtf7Codec; + + TQTextEncoder * enc; + + TQString arg = TQString::tqfromLatin1( argv[1] ); + int len; + + cout << "Original string:\n" + << "\"" << argv[1] << "\"\n" << endl; + + cout << "Encode optional direct set and whitespace:\n" << endl; + codec->setEncodeWhitespace(TRUE); + codec->setEncodeOptionalDirect(TRUE); + enc = codec->makeEncoder(); + + len = arg.length(); + cout << (enc->fromUnicode( arg, len )).data() + << "\n" << endl; + + cout << "Same as above, but call fromUnicode() char-wise:\n" << endl; + + delete enc; + enc = codec->makeEncoder(); + + for ( int i = 0 ; i < arg.length() ; i++ ) { + len = 1; + cout << (enc->fromUnicode( TQString(arg[i]), len )).data(); + } + cout << "\n" << endl; + + + + delete enc; + + cout << "Encode optional direct set and not whitespace:\n" << endl; + codec->setEncodeWhitespace(FALSE); + codec->setEncodeOptionalDirect(TRUE); + enc = codec->makeEncoder(); + + len = arg.length(); + cout << (enc->fromUnicode( arg, len )).data() + << "\n" << endl; + + delete enc; + + + cout << "Don't encode optional direct set, but whitespace:\n" << endl; + codec->setEncodeWhitespace(TRUE); + codec->setEncodeOptionalDirect(FALSE); + enc = codec->makeEncoder(); + + len = arg.length(); + cout << (enc->fromUnicode( arg, len )).data() + << "\n" << endl; + + delete enc; + + + cout << "Encode neither optional direct set, nor whitespace:\n" << endl; + codec->setEncodeWhitespace(FALSE); + codec->setEncodeOptionalDirect(FALSE); + enc = codec->makeEncoder(); + + len = arg.length(); + cout << (enc->fromUnicode( arg, len )).data() + << "\n" << endl; + + cout << "Same as above, but call fromUnicode() char-wise:\n" << endl; + + delete enc; + enc = codec->makeEncoder(); + + for ( int i = 0 ; i < arg.length() ; i++ ) { + len = 1; + cout << (enc->fromUnicode( TQString(arg[i]), len )).data(); + } + cout << "\n" << endl; + + + delete enc; + + delete codec; + } else { + qWarning("usage: testutf7encoder string_to_encode\n"); + } +} diff --git a/libtdepim/tests/testutf7encoder2.cpp b/libtdepim/tests/testutf7encoder2.cpp new file mode 100644 index 000000000..65cf8b461 --- /dev/null +++ b/libtdepim/tests/testutf7encoder2.cpp @@ -0,0 +1,45 @@ +#include "qutf7codec.h" +#include "qutf7codec.cpp" +#include +#include +#include +#include + +int main( int argc, char * argv[] ) { + if ( argc == 1 ) { + (void)new TQUtf7Codec; + + TQTextCodec * codec = TQTextCodec::codecForName("utf-7"); + assert(codec); + + TQTextIStream my_cin(stdin); + + TQTextOStream my_cout(stdout); + my_cout.setCodec(codec); + + TQString buffer = my_cin.read(); + + // qDebug("buffer == " + buffer); + +#ifdef USE_STREAM + my_cout << buffer << endl; +#else + TQTextEncoder * enc = codec->makeEncoder(); +#ifdef CHAR_WISE + int len; + for ( int i = 0 ; i < buffer.length() ; i++ ) { + len = 1; + cout << (enc->fromUnicode(TQString(buffer[i]),len)).data(); + } + std::cout << std::endl; +#else + int len = buffer.length(); + std::cout << (enc->fromUnicode(buffer,len)).data() << std::endl;; +#endif // CHAR_WISE + delete enc; +#endif // else USE_STREAM + } else { + qWarning("usage: testutf7encoder2 < infile > outfile\n"); + } + TQTextCodec::deleteAllCodecs(); +} diff --git a/libtdepim/tests/testwizard.cpp b/libtdepim/tests/testwizard.cpp new file mode 100644 index 000000000..d9c9d806c --- /dev/null +++ b/libtdepim/tests/testwizard.cpp @@ -0,0 +1,100 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "myconfig.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include + +class TestConfigWizard : public KConfigWizard +{ + public: + TestConfigWizard() : + KConfigWizard( new KConfigPropagator( MyConfig::self(), + "propagator_test.kcfg" ) ) + { + TQFrame *page = createWizardPage( "My Wizard Page" ); + TQBoxLayout *topLayout = new TQVBoxLayout( page ); + + mFixKMailCheckBox = new TQCheckBox( i18n("Fix KMail"), page ); + topLayout->addWidget( mFixKMailCheckBox ); + + mFixKMailCheckBox->setChecked( MyConfig::fixKMail() ); + + mBreakKMailCheckBox = new TQCheckBox( i18n("Break KMail"), page ); + topLayout->addWidget( mBreakKMailCheckBox ); + + mBreakKMailCheckBox->setChecked( MyConfig::breakKMail() ); + + setupRulesPage(); + setupChangesPage(); + } + + ~TestConfigWizard() + { + } + + void usrReadConfig() + { + } + + void usrWriteConfig() + { + MyConfig::self()->setFixKMail( mFixKMailCheckBox->isChecked() ); + MyConfig::self()->setBreakKMail( mBreakKMailCheckBox->isChecked() ); + } + + private: + TQCheckBox *mFixKMailCheckBox; + TQCheckBox *mBreakKMailCheckBox; +}; + +static const KCmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + KCmdLineLastOption +}; + +int main(int argc,char **argv) +{ + KAboutData aboutData("testwizard","Test KConfigWizard","0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + bool verbose = false; + if ( args->isSet( "verbose" ) ) verbose = true; + + TestConfigWizard wizard; + + wizard.exec(); +} diff --git a/libtdepim/weaver.cpp b/libtdepim/weaver.cpp new file mode 100644 index 000000000..b1dba8de7 --- /dev/null +++ b/libtdepim/weaver.cpp @@ -0,0 +1,550 @@ +/* -*- C++ -*- + + This file implements the Weaver, Job and Thread classes. + + $ Author: Mirko Boehm $ + $ Copyright: (C) 2004, Mirko Boehm $ + $ Contact: mirko@kde.org + http://www.kde.org + http://www.hackerbuero.org $ + $ License: LGPL with the following explicit clarification: + This code may be linked against any version of the TQt toolkit + from Troll Tech, Norway. $ + +*/ + +extern "C" { +#include +} + +#include +#include + +#include "weaver.h" + +namespace KPIM { +namespace ThreadWeaver { + + bool Debug = true; + int DebugLevel = 2; + + Job::Job (TQObject* parent, const char* name) + : TQObject (parent, name), + m_finished (false), + m_mutex (new TQMutex (true) ), + m_thread (0) + { + } + + Job::~Job() + { + } + + void Job::lock() + { + m_mutex->lock(); + } + + void Job::unlock() + { + m_mutex->unlock(); + } + + void Job::execute(Thread *th) + { + m_mutex->lock(); + m_thread = th; + m_mutex->unlock(); + + run (); + + m_mutex->lock(); + setFinished (true); + m_thread = 0; + m_mutex->unlock(); + } + + Thread *Job::thread () + { + TQMutexLocker l (m_mutex); + return m_thread; + } + + bool Job::isFinished() const + { + TQMutexLocker l (m_mutex); + return m_finished; + } + + void Job::setFinished(bool status) + { + TQMutexLocker l (m_mutex); + m_finished = status; + } + + void Job::processEvent (Event *e) + { + switch ( e->action() ) + { + case Event::JobStarted: + emit ( started() ); + break; + case Event::JobFinished: + emit ( done() ); + break; + case Event::JobSPR: + emit ( SPR () ); + m_wc->wakeOne (); + break; + case Event::JobAPR: + emit ( APR () ); + // no wake here ! + break; + default: + break; + } + } + + void Job::triggerSPR () + { + m_mutex->lock (); + m_wc = new TQWaitCondition; + m_mutex->unlock (); + + thread()->post (KPIM::ThreadWeaver::Event::JobSPR, this); + m_wc->wait (); + + m_mutex->lock (); + delete m_wc; + m_wc = 0; + m_mutex->unlock (); + } + + void Job::triggerAPR () + { + m_mutex->lock (); + m_wc = new TQWaitCondition; + m_mutex->unlock (); + + thread()->post (KPIM::ThreadWeaver::Event::JobAPR, this); + m_wc->wait (); + } + + void Job::wakeAPR () + { + TQMutexLocker l(m_mutex); + if ( m_wc!=0 ) + { + m_wc->wakeOne (); + delete m_wc; + m_wc = 0; + } + } + + const int Event::Type = TQEvent::User + 1000; + + Event::Event ( Action action, Thread *thread, Job *job) + : TQCustomEvent ( type () ), + m_action (action), + m_thread (thread), + m_job (job) + { + } + + int Event::type () + { + return Type; + } + + Thread* Event::thread () const + { + if ( m_thread != 0) + { + return m_thread; + } else { + return 0; + } + } + + Job* Event::job () const + { + return m_job; + } + + Event::Action Event::action () const + { + return m_action; + } + + unsigned int Thread::sm_Id; + + Thread::Thread (Weaver *parent) + : TQThread (), + m_parent ( parent ), + m_id ( makeId() ) + { + } + + Thread::~Thread() + { + } + + unsigned int Thread::makeId() + { + static TQMutex mutex; + TQMutexLocker l (&mutex); + + return ++sm_Id; + } + + unsigned int Thread::id() const + { + return m_id; + } + + void Thread::run() + { + Job *job = 0; + + post ( Event::ThreadStarted ); + + while (true) + { + debug ( 3, "Thread::run [%u]: trying to execute the next job.\n", id() ); + + job = m_parent->applyForWork ( this, job ); + + if (job == 0) + { + break; + } else { + post ( Event::JobStarted, job ); + job->execute (this); + post ( Event::JobFinished, job ); + } + } + + post ( Event::ThreadExiting ); + } + + void Thread::post (Event::Action a, Job *j) + { + m_parent->post ( a, this, j); + } + + void Thread::msleep(unsigned long msec) + { + TQThread::msleep(msec); + } + + Weaver::Weaver(TQObject* parent, const char* name, + int inventoryMin, int inventoryMax) + : TQObject(parent, name), + m_active(0), + m_inventoryMin(inventoryMin), + m_inventoryMax(inventoryMax), + m_shuttingDown(false), + m_running (false), + m_suspend (false), + m_mutex ( new TQMutex(true) ) + { + lock(); + + for ( int count = 0; count < m_inventoryMin; ++count) + { + Thread *th = new Thread(this); + m_inventory.append(th); + // this will idle the thread, waiting for a job + th->start(); + + emit (threadCreated (th) ); + } + + unlock(); + } + + Weaver::~Weaver() + { + lock(); + + debug ( 1, "Weaver dtor: destroying inventory.\n" ); + + m_shuttingDown = true; + + unlock(); + + m_jobAvailable.wakeAll(); + + // problem: Some threads might not be asleep yet, just finding + // out if a job is available. Those threads will suspend + // waiting for their next job (a rare case, but not impossible). + // Therefore, if we encounter a thread that has not exited, we + // have to wake it again (which we do in the following for + // loop). + + for ( Thread *th = m_inventory.first(); th; th = m_inventory.next() ) + { + if ( !th->finished() ) + { + m_jobAvailable.wakeAll(); + th->wait(); + } + + emit (threadDestroyed (th) ); + delete th; + + } + + m_inventory.clear(); + + delete m_mutex; + + debug ( 1, "Weaver dtor: done\n" ); + + } + + void Weaver::lock() + { + debug ( 3 , "Weaver::lock: lock (mutex is %s).\n", + ( m_mutex->locked() ? "locked" : "not locked" ) ); + m_mutex->lock(); + } + + void Weaver::unlock() + { + m_mutex->unlock(); + + debug ( 3 , "Weaver::unlock: unlock (mutex is %s).\n", + ( m_mutex->locked() ? "locked" : "not locked" ) ); + } + + int Weaver::threads () const + { + TQMutexLocker l (m_mutex); + return m_inventory.count (); + } + + void Weaver::enqueue(Job* job) + { + lock(); + + m_assignments.append(job); + m_running = true; + + unlock(); + + assignJobs(); + } + + void Weaver::enqueue (TQPtrList jobs) + { + lock(); + + for ( Job * job = jobs.first(); job; job = jobs.next() ) + { + m_assignments.append (job); + } + + unlock(); + + assignJobs(); + } + + bool Weaver::dequeue ( Job* job ) + { + TQMutexLocker l (m_mutex); + return m_assignments.remove (job); + } + + void Weaver::dequeue () + { + TQMutexLocker l (m_mutex); + m_assignments.clear(); + } + + void Weaver::suspend (bool state) + { + lock(); + + if (state) + { + // no need to wake any threads here + m_suspend = true; + if ( m_active == 0 && isEmpty() ) + { // instead of waking up threads: + post (Event::Suspended); + } + } else { + m_suspend = false; + // make sure we emit suspended () even if all threads are sleeping: + assignJobs (); + debug (2, "Weaver::suspend: queueing resumed.\n" ); + } + + unlock(); + } + + void Weaver::assignJobs() + { + m_jobAvailable.wakeAll(); + } + + bool Weaver::event (TQEvent *e ) + { + if ( e->type() >= TQEvent::User ) + { + + if ( e->type() == Event::type() ) + { + Event *event = (Event*) e; + + switch (event->action() ) + { + case Event::JobFinished: + if ( event->job() !=0 ) + { + emit (jobDone (event->job() ) ); + } + break; + case Event::Finished: + emit ( finished() ); + break; + case Event::Suspended: + emit ( suspended() ); + break; + case Event::ThreadSuspended: + if (!m_shuttingDown ) + { + emit (threadSuspended ( event->thread() ) ); + } + break; + case Event::ThreadBusy: + if (!m_shuttingDown ) + { + emit (threadBusy (event->thread() ) ); + } + break; + default: + break; + } + + if ( event->job() !=0 ) + { + event->job()->processEvent (event); + } + } else { + debug ( 0, "Weaver::event: Strange: received unknown user event.\n" ); + } + return true; + } else { + // others - please make sure we are a TQObject! + return TQObject::event ( e ); + } + } + + void Weaver::post (Event::Action a, Thread* t, Job* j) + { + Event *e = new Event ( a, t, j); + TQApplication::postEvent (this, e); + } + + bool Weaver::isEmpty() const + { + TQMutexLocker l (m_mutex); + return m_assignments.count()==0; + } + + Job* Weaver::applyForWork(Thread *th, Job* previous) + { + Job *rc = 0; + bool lastjob = false; + bool suspended = false; + + while (true) + { + lock(); + + if (previous != 0) + { // cleanup and send events: + --m_active; + + debug ( 3, "Weaver::applyForWork: job done, %i jobs left, " + "%i active jobs left.\n", + queueLength(), m_active ); + + if ( m_active == 0 && isEmpty() ) + { + lastjob = true; + m_running = false; + post (Event::Finished); + debug ( 3, "Weaver::applyForWork: last job.\n" ); + } + + if (m_active == 0 && m_suspend == true) + { + suspended = true; + post (Event::Suspended); + debug ( 2, "Weaver::applyForWork: queueing suspended.\n" ); + } + + m_jobFinished.wakeOne(); + } + + previous = 0; + + if (m_shuttingDown == true) + { + unlock(); + + return 0; + } else { + if ( !isEmpty() && m_suspend == false ) + { + rc = m_assignments.getFirst(); + m_assignments.removeFirst (); + ++m_active; + + debug ( 3, "Weaver::applyForWork: job assigned, " + "%i jobs in queue (%i active).\n", + m_assignments.count(), m_active ); + unlock(); + + post (Event::ThreadBusy, th); + + return rc; + } else { + unlock(); + + post (Event::ThreadSuspended, th); + m_jobAvailable.wait(); + } + } + } + } + + int Weaver::queueLength() + { + TQMutexLocker l (m_mutex); + return m_assignments.count(); + } + + bool Weaver::isIdle () const + { + TQMutexLocker l (m_mutex); + return isEmpty() && m_active == 0; + } + + void Weaver::finish() + { + while ( !isIdle() ) + { + debug (2, "Weaver::finish: not done, waiting.\n" ); + m_jobFinished.wait(); + } + debug (1, "Weaver::finish: done.\n\n\n" ); + } + +} +} + +#include "weaver.moc" diff --git a/libtdepim/weaver.h b/libtdepim/weaver.h new file mode 100644 index 000000000..8e82b5811 --- /dev/null +++ b/libtdepim/weaver.h @@ -0,0 +1,451 @@ +/* -*- C++ -*- + + This file declares the Weaver, Job and Thread classes. + + $ Author: Mirko Boehm $ + $ Copyright: (C) 2004, Mirko Boehm $ + $ Contact: mirko@kde.org + http://www.kde.org + http://www.hackerbuero.org $ + $ License: LGPL with the following explicit clarification: + This code may be linked against any version of the TQt toolkit + from Troll Tech, Norway. $ + +*/ + +#ifndef WEAVER_H +#define WEAVER_H + +extern "C" +{ +#include +#include +#include +} + +#include +#include +#include +#include +#include +#include + +#include + +namespace KPIM { +namespace ThreadWeaver { + + /** This method prints a text message on the screen, if debugging is + enabled. Otherwise, it does nothing. The message is thread safe, + therefore providing that the messages appear in the order they where + issued by the different threads. + All messages are suppressed when Debug is false. All messages with a + lower importance (higher number) than DebugLevel will be suppressed, + too. Debug level 0 messages will always be printed as long as + Debug is true. + We use our own debugging method, since debugging threads is a more + complicated experience than debugging single threaded + contexts. This might change in future in the way that debug + prints it's messages to another logging facility provided by + the platform. + Use setDebugLevel () to integrate adapt debug () to your platform. + */ + + KDE_EXPORT extern bool Debug; + KDE_EXPORT extern int DebugLevel; + + KDE_EXPORT inline void setDebugLevel (bool debug, int level) + { + Debug = debug; + DebugLevel = level; + } + + KDE_EXPORT inline void debug(int severity, const char * cformat, ...) +#ifdef __GNUC__ + __attribute__ ( (format (printf, 2, 3 ) ) ) +#endif +; + + KDE_EXPORT inline void debug(int severity, const char * cformat, ...) + { + if ( Debug == true && ( severity<=DebugLevel || severity == 0) ) + { + static TQMutex mutex; + TQString text; + + mutex.lock(); + va_list ap; + va_start( ap, cformat ); + vprintf (cformat, ap); + va_end (ap); + mutex.unlock(); + } + } + + + class Thread; + class Job; + + /** A class to represent the events threads generate and send to the + Weaver object. Examples include the start or end of the processing of a + job. Threads create the event objects and discard them after posting + the event, since the event receiver will assume ownership of the + event. + Events are associated to the sending thread and possibly to a + processed job. + + Note: Do not create and use SPR/APR events, use Job::triggerSPR or + Job::triggerAPR to create the requests. */ + + class KDE_EXPORT Event : public TQCustomEvent + { + public: + enum Action { + NoAction = 0, + Finished, /// All jobs in the queue are done. + Suspended, /// Thread queueing halted. + ThreadStarted, + ThreadExiting, + ThreadBusy, + ThreadSuspended, + JobStarted, + JobFinished, + JobSPR, /// Synchronous Process Request + JobAPR /// Asynchronous Process Request + }; + Event ( Action = NoAction, Thread * = 0, Job *job = 0); + /** Return the (custom defined) event type. */ + static int type (); + /** The ID of the sender thread. */ + Thread* thread () const; + /** The associated job. */ + Job* job () const; + /** The action. */ + Action action () const; + private: + Action m_action; + Thread *m_thread; + Job *m_job; + static const int Type; + }; + + /** A Job is a simple abstraction of an action that is to be + executed in a thread context. + It is essential for the ThreadWeaver library that as a kind of + convention, the different creators of Job objects do not touch the + protected data members of the Job until somehow notified by the + Job. See the SPR signal for an example. + + Jobs may emit process requests as signals. Consider process requests + as a kind of synchronized call to the main thread. + Process Requests are a generic means for Job derivate programmers to have + the jobs interact with the creators (in the main thread) during + processing time. To avoid race + conditions and extensive locking and unlocking, the thread executing the + job is suspended during the period needed to process the request. + + There are two kinds of process requests (we introduce abbreviations, + also in the signal names and the code, + only to save typing). Both are emitted by signals in the main thread: + - Synchronous Process Requests (SPR): Synchronous requests expect that the + complete request is performed in the slots connected to the signals. For + example, to update a widget according to the progress of the job, a SPR + may be used. In such cases, the Job's execution will be resumed + immediately after the signal has been processed. + - Asynchronous Process Requests (APR): For APRs, the job emitting the + signal does not assume anything about the amount of time needed to + perform the operation. Therefore, the thread is not waked after the + signal returns. The creator has to wake to thread whenever it is + ready by calling the wakeAPR method. + + Note: When using an APR, you better make sure to receive the signal + with some object, otherwise the calling thread will block forever! + */ + class KDE_EXPORT Job : public TQObject + { + Q_OBJECT + TQ_OBJECT + public: + /** Construct a Job object. */ + Job(TQObject* parent=0, const char* name=0); + + /** Destructor. */ + virtual ~Job(); + + /** Perform the job. The thread in which this job is executed + is given as a parameter. + Do not overload this method to create your own Job + implementation, overload run(). */ + virtual void execute(Thread*); + + /** Returns true if the jobs's execute method finished. */ + virtual bool isFinished() const; + + /** Wake the thread after an APR has been processed. */ + void wakeAPR (); + + /** Process events related to this job (created by the processing + thread or the weaver or whoever). */ + virtual void processEvent ( Event* ); + + signals: + /** This signal is emitted when a thread starts to process a job. */ + void started (); + /** This signal is emitted when a job has been finished. */ + void done (); + /** This signal is emitted when the job needs some operation done by + the main thread (usually the creator of the job). + It is important to understand that the emitting thread is + suspended until the signal returns. + When + the operation requested has been performed and this signal is + finished, the thread is automatically waked. + What operation needs to be performed has to be negotiated between + the two objects. + Note: This signal is an attempt to provide job programmers with a + generic way to interact while the job is executed. I am interested + in feedback about it's use. */ + void SPR (); + /** Perform an Asynchronous Process Request. See SPR and the generic + Job documentation for a comparison. */ + void APR (); + protected: + /** Lock this Job's mutex. */ + void lock(); + /** Unlock this Job's mutex. */ + void unlock(); + /** The method that actually performs the job. It is called from + execute(). This method is the one to overload it with the + job's task. */ + virtual void run () = 0; + /** Return the thread that executes this job. + Returns zero of the job is not currently executed. */ + Thread *thread(); + /** Call with status = true to mark this job as done. */ + virtual void setFinished(bool status); + /** Trigger a SPR. + This emits a signal in the main thread indicating the necessity of + a synchronized operation. */ + void triggerSPR (); + /** Trigger an APR. + This emit a signal in the main thread indicating the necessity of + an unsynchronized operation. + The calling thread needs to ensure to wake the thread when the + operation is done. */ + void triggerAPR (); + + bool m_finished; + + TQMutex *m_mutex; + + Thread * m_thread; + + TQWaitCondition *m_wc; + }; + + class Weaver; + + /** The class Thread is used to represent the worker threads in + the weaver's inventory. It is not meant to be overloaded. */ + class KDE_EXPORT Thread : public TQThread + { + public: + /** Create a thread. + These thread objects are only used inside the Weaver parent + object. */ + Thread(Weaver *parent); + + /** The destructor. */ + ~Thread(); + + /** Overloaded to execute the assigned job. + This will NOT return until shutdown() is called. The + thread will try to execute one job after the other, asking + the Weaver parent for a new job when the assigned one is + finished. + If no jobs are available, the thread will suspend. + After shutdown() is called, the thread will end as soon as + the currently assigned job is done. + */ + void run(); + + /* Provide the msleep() method (protected in TQThread) to be + available for executed jobs. */ + void msleep(unsigned long msec); + + /** Returns the thread id. + This id marks the respective Thread object, and must + therefore not be confused with, e.g., the pthread thread + ID. */ + unsigned int id() const; + + /** Post an event, will be received and processed by the Weaver. */ + void post (Event::Action, Job* = 0); + + private: + Weaver *m_parent; + + const unsigned int m_id; + + static unsigned int sm_Id; + + static unsigned int makeId(); + }; + + /** A weaver is the manager of worker threads (Thread objects) to + which it assigns jobs from it's queue. */ + class KDE_EXPORT Weaver : public TQObject + { + Q_OBJECT + TQ_OBJECT + public: + Weaver (TQObject* parent=0, const char* name=0, + int inventoryMin = 4, // minimal number of provided threads + int inventoryMax = 32); // maximum number of provided threads + virtual ~Weaver (); + /** Add a job to be executed. */ + virtual void enqueue (Job*); + /** Enqueue all jobs in the given list. + This is an atomic operation, no jobs will start + before all jobs in the list are enqueued. + If you need a couple of jobs done and want to receive the + finished () signal afterwards, use this method to queue + them. Otherwise, when enqueueing your jobs + individually, there is a chance that you receive more than + one finished signal. */ + void enqueue (TQPtrList jobs); + /** Remove a job from the queue. + If the job qas queued but not started so far, it is simple + removed from the queue. For now, it is unsupported to + dequeue a job once its execution has started. + For that case, you will have to provide a method to interrupt your + job's execution (and receive the done signal). + Returns true if the job has been dequeued, false if the + job has already been started or is not found in the + queue. */ + virtual bool dequeue (Job*); + /** Remove all queued jobs. + Please note that this will not kill the threads, therefore + all jobs that are being processed will be continued. */ + virtual void dequeue (); + /** Get notified when a thread has finished a job. + This is done automatically. */ + // virtual void jobFinished(Thread *); + /** Finish all queued operations, then return. + This method is used in imperative programs that cannot react on + events to have the controlling (main) thread wait wait for the + jobs to finish. + Warning: This will suspend your thread! + Warning: If your jobs enter for example an infinite loop, this + will never return! */ + virtual void finish(); + /** Suspend job execution if state = true, otherwise resume + job execution if it was suspended. + When suspending, all threads are allowed to finish the + currently assigned job but will not receive a new + assignment. + When all threads are done processing the assigned job, the + signal suspended will() be emitted. + If you call suspend (true) and there are no jobs left to + be done, you will immidiately receive the suspended() + signal. */ + virtual void suspend (bool state); + /** Is the queue empty? */ + bool isEmpty () const; + /** Is the weaver idle? + The weaver is idle if no jobs are queued and no jobs are processed + by the threads (m_active is zero). */ + bool isIdle () const; + /** Returns the number of pending jobs. */ + int queueLength (); + /** Assign a job to the calling thread. + This is supposed to be called from the Thread objects in + the inventory. + Returns 0 if the weaver is shutting down, telling the + calling thread to finish and exit. + If no jobs are available and shut down is not in progress, + the calling thread is suspended until either condition is + met. + In previous, threads give the job they have completed. If this is + the first job, previous is zero. */ + virtual Job* applyForWork (Thread *thread, Job *previous); + /** Lock the mutex for this weaver. The threads in the + inventory need to lock the weaver's mutex to synchronize + the job management. */ + void lock (); + /** Unlock. See lock(). */ + void unlock (); + /** Post an event that is handled by this object, but in the main + (GUI) thread. Different threads may use this method to communicate + with the main thread. + thread and job mark the objects associated with this event. */ + void post (Event::Action, Thread* = 0, Job* = 0); + /** Returns the current number of threads in the inventory. */ + int threads () const; + signals: + /** This signal is emitted when the Weaver has finished ALL currently + queued jobs. + If a number of jobs is enqueued sequentially, this signal might be + emitted a couple of times (what happens is that all already queued + jobs have been processed while you still add new ones). This is + not a bug, but the intended behaviour. */ + void finished (); + /** Thread queueing has been suspended. + When suspend is called with state = true, all threads are + allowed to finish their job. When the last thread + finished, this signal is emitted. */ + void suspended (); + /** This signal is emitted when a job is done. It is up to the + programmer if this signal or the done signal of the job is more + handy. */ + void jobDone (Job*); +// The following signals are used mainly for debugging purposes. + void threadCreated (Thread *); + void threadDestroyed (Thread *); + void threadBusy (Thread *); + void threadSuspended (Thread *); + + protected: + /** Schedule enqueued jobs to be executed by idle threads. + This will try to distribute as many jobs as possible + to all idle threads. */ + void assignJobs(); + /** Check incoming events for user defined ones. The threads use user + defined events to communicate with the Weaver. */ + bool event ( TQEvent* ); + /** The thread inventory. */ + TQPtrList m_inventory; + /** The job queue. */ + TQPtrList m_assignments; + /** The number of jobs that are assigned to the worker + threads, but not finished. */ + int m_active; + /** Stored setting. */ + int m_inventoryMin; + /** Stored setting . */ + int m_inventoryMax; + /** Wait condition all idle or done threads wait for. */ + TQWaitCondition m_jobAvailable; + /** Wait for a job to finish. */ + TQWaitCondition m_jobFinished; + /** Indicates if the weaver is shutting down and exiting it's + threads. */ + bool m_shuttingDown; + /** m_running is set to true when a job is enqueued and set to false + when the job finishes that was the last in the queue. + E.g., this will flip from false to true to false when you + continuously enqueue one single job. */ + bool m_running; + /** If m_suspend is true, no new jobs will be assigned to + threads. + Jobs may be queued, but will not be processed until suspend + (false) is called. */ + bool m_suspend; + private: + /** Mutex to serialize operations. */ + TQMutex *m_mutex; + }; +} // namespace ThreadWeaver +} // namespace KPIM + +#endif // defined WEAVER_H diff --git a/libtdepim/weaverextensions.cpp b/libtdepim/weaverextensions.cpp new file mode 100644 index 000000000..9859b6d6b --- /dev/null +++ b/libtdepim/weaverextensions.cpp @@ -0,0 +1,62 @@ +/* -*- C++ -*- + + This file implements the Weaver Extensions basics. + + $ Author: Mirko Boehm $ + $ Copyright: (C) 2004, Mirko Boehm $ + $ Contact: mirko@kde.org + http://www.kde.org + http://www.hackerbuero.org $ + $ License: LGPL with the following explicit clarification: + This code may be linked against any version of the TQt toolkit + from Troll Tech, Norway. $ + +*/ + +#include "weaverextensions.h" +#include "weaver.h" + +namespace KPIM { +namespace ThreadWeaver { + + WeaverExtension::WeaverExtension ( TQObject *parent, const char *name) + : TQObject (parent, name) + { + } + + void WeaverExtension::attach (Weaver *w) + { + connect (w, TQT_SIGNAL (threadCreated (Thread *) ), + TQT_SLOT (threadCreated (Thread *) ) ); + connect (w, TQT_SIGNAL (threadDestroyed (Thread *) ), + TQT_SLOT (threadDestroyed (Thread *) ) ); + connect (w, TQT_SIGNAL (threadBusy (Thread *) ), + TQT_SLOT (threadBusy (Thread *) ) ); + connect (w, TQT_SIGNAL (threadSuspended (Thread *) ), + TQT_SLOT (threadSuspended (Thread *) ) ); + } + + WeaverExtension::~WeaverExtension() + { + } + + void WeaverExtension::threadCreated (Thread *) + { + } + + void WeaverExtension::threadDestroyed (Thread *) + { + } + + void WeaverExtension::threadBusy (Thread *) + { + } + + void WeaverExtension::threadSuspended (Thread *) + { + } + +} +} + +#include "weaverextensions.moc" diff --git a/libtdepim/weaverextensions.h b/libtdepim/weaverextensions.h new file mode 100644 index 000000000..26bccadea --- /dev/null +++ b/libtdepim/weaverextensions.h @@ -0,0 +1,60 @@ +/* -*- C++ -*- + + This file declares the Weaver Extensions basics. + + $ Author: Mirko Boehm $ + $ Copyright: (C) 2004, Mirko Boehm $ + $ Contact: mirko@kde.org + http://www.kde.org + http://www.hackerbuero.org $ + $ License: LGPL with the following explicit clarification: + This code may be linked against any version of the TQt toolkit + from Troll Tech, Norway. $ + +*/ + +#ifndef WEAVEREXTENSIONS_H +#define WEAVEREXTENSIONS_H + +#include + +namespace KPIM { +namespace ThreadWeaver { + + class Weaver; + class Thread; + + /** A WeaverExtension can be attached to an existing Weaver object and + will then receive signals on actions the Weaver takes, like starting + to process a specific job, assigning a job to a thread or suspending a + thread. It can be used to monitor the state of a program, but also, + for example, to provide visualization of the Weaver's work load in GUI + programs. Derive from it to actually create an extension. */ + class WeaverExtension : public TQObject + { + Q_OBJECT + TQ_OBJECT + public: + WeaverExtension ( TQObject *parent = 0, const char *name = 0); + /** Attach() is a convenience method that will connect all our + slots to signals emitted by the weaver. It is also possible to + avoid attach() and only connect necessary signals. */ + void attach (Weaver *); + virtual ~WeaverExtension() = 0; + public slots: + // these methods are implemented, but do nothing in the default configuration + // a thread is created: + virtual void threadCreated (Thread *); + // a thread is destroyed: + virtual void threadDestroyed (Thread *); + // the thread is processing a job + virtual void threadBusy (Thread *); + // the thread is suspended and will be waked when jobs become + // available + virtual void threadSuspended (Thread *); + }; + +} // namespace ThreadWeaver +} + +#endif // WEAVEREXTENSIONS_H diff --git a/libtdepim/weaverlogger.cpp b/libtdepim/weaverlogger.cpp new file mode 100644 index 000000000..e5164c804 --- /dev/null +++ b/libtdepim/weaverlogger.cpp @@ -0,0 +1,60 @@ +/* -*- C++ -*- + + This file implements the Thread Logger. + + $ Author: Mirko Boehm $ + $ Copyright: (C) 2004, Mirko Boehm $ + $ Contact: mirko@kde.org + http://www.kde.org + http://www.hackerbuero.org $ + $ License: LGPL with the following explicit clarification: + This code may be linked against any version of the TQt toolkit + from Troll Tech, Norway. $ + +*/ + +#include +#include "weaverlogger.h" + +namespace KPIM { +namespace ThreadWeaver { + + extern void debug(int severity, const char * cformat, ...); + + WeaverThreadLogger::WeaverThreadLogger( TQObject *parent, const char *name) + : WeaverExtension (parent, name) + { + } + + WeaverThreadLogger::~WeaverThreadLogger () + { + } + + void WeaverThreadLogger::threadCreated (KPIM::ThreadWeaver::Thread *thread) + { + debug ( 1, "WeaverThreadLogger: thread (ID: %i) created.\n", + thread->id() ); + } + + void WeaverThreadLogger::threadDestroyed (KPIM::ThreadWeaver::Thread *thread) + { + debug ( 1, "WeaverThreadLogger: thread (ID: %i) destroyed.\n", + thread->id() ); + } + + void WeaverThreadLogger::threadBusy (KPIM::ThreadWeaver::Thread *thread) + { + debug ( 1, "WeaverThreadLogger: thread (ID: %i) is processing a job.\n", + thread->id() ); + } + + void WeaverThreadLogger::threadSuspended (KPIM::ThreadWeaver::Thread *thread) + { + debug ( 1, "WeaverThreadLogger: thread (ID: %i) suspended.\n", + thread->id() ); + } + +} +} + +#include "weaverlogger.moc" diff --git a/libtdepim/weaverlogger.h b/libtdepim/weaverlogger.h new file mode 100644 index 000000000..d4d35ff4f --- /dev/null +++ b/libtdepim/weaverlogger.h @@ -0,0 +1,42 @@ +/* -*- C++ -*- + + This file declares the Thread Logger. + + $ Author: Mirko Boehm $ + $ Copyright: (C) 2004, Mirko Boehm $ + $ Contact: mirko@kde.org + http://www.kde.org + http://www.hackerbuero.org $ + $ License: LGPL with the following explicit clarification: + This code may be linked against any version of the TQt toolkit + from Troll Tech, Norway. $ + +*/ + +#ifndef WEAVERLOGGER_H +#define WEAVERLOGGER_H + +#include "weaverextensions.h" + +namespace KPIM { +namespace ThreadWeaver { + + /** A WeaverThreadLogger may be attached to a Weaver to gain debug + information about thread execution. */ + class WeaverThreadLogger : public WeaverExtension + { + Q_OBJECT + TQ_OBJECT + public: + WeaverThreadLogger( TQObject *parent = 0, const char *name = 0); + ~WeaverThreadLogger(); + void threadCreated (Thread *); + void threadDestroyed (Thread *); + void threadBusy (Thread *); + void threadSuspended (Thread *); + }; + +} +} + +#endif // WEAVERLOGGER_H diff --git a/tdepim.lsm b/tdepim.lsm new file mode 100644 index 000000000..22a6aba6c --- /dev/null +++ b/tdepim.lsm @@ -0,0 +1,12 @@ +Begin4 +Title: tdepim +Version: 3.5.10 +Entered-date: 2008-08-26 +Description: PIM (Personal Information Management) programs + for the K Desktop Environment (KDE) +Keywords: KDE X11 desktop Qt +Author: http://bugs.kde.org/ (KDE Bugtracking System) +Primary-site: http://www.kde.org/download/ +Platforms: Unix, Qt +Copying-policy: GPL, Artistic +End -- cgit v1.2.1