author | zautrix <zautrix> | 2004-10-30 01:46:35 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-30 01:46:35 (UTC) |
commit | 6c755a7a8a1e9d9a747267eadf914a6030c9b711 (patch) (unidiff) | |
tree | 14b1b8ed39f50683f095ca5fb7656abd3326854e /kaddressbook | |
parent | c477fa8ba7eacfaba3d154a72153acc7bc46abdc (diff) | |
download | kdepimpi-6c755a7a8a1e9d9a747267eadf914a6030c9b711.zip kdepimpi-6c755a7a8a1e9d9a747267eadf914a6030c9b711.tar.gz kdepimpi-6c755a7a8a1e9d9a747267eadf914a6030c9b711.tar.bz2 |
better cat management in kapi
-rw-r--r-- | kaddressbook/kabcore.cpp | 107 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 2 |
2 files changed, 106 insertions, 3 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 83027ac..9505a23 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -126,18 +126,21 @@ $Id$ | |||
126 | //US#include <qsplitter.h> | 126 | //US#include <qsplitter.h> |
127 | #include <qmap.h> | 127 | #include <qmap.h> |
128 | #include <qdir.h> | 128 | #include <qdir.h> |
129 | #include <qfile.h> | 129 | #include <qfile.h> |
130 | #include <qvbox.h> | 130 | #include <qvbox.h> |
131 | #include <qlayout.h> | 131 | #include <qlayout.h> |
132 | #include <qclipboard.h> | 132 | #include <qclipboard.h> |
133 | #include <qtextstream.h> | 133 | #include <qtextstream.h> |
134 | #include <qradiobutton.h> | ||
135 | #include <qbuttongroup.h> | ||
134 | 136 | ||
135 | #include <libkdepim/categoryselectdialog.h> | 137 | #include <libkdepim/categoryselectdialog.h> |
138 | #include <libkdepim/categoryeditdialog.h> | ||
136 | #include <kabc/vcardconverter.h> | 139 | #include <kabc/vcardconverter.h> |
137 | 140 | ||
138 | 141 | ||
139 | #include "addresseeutil.h" | 142 | #include "addresseeutil.h" |
140 | #include "undocmds.h" | 143 | #include "undocmds.h" |
141 | #include "addresseeeditordialog.h" | 144 | #include "addresseeeditordialog.h" |
142 | #include "viewmanager.h" | 145 | #include "viewmanager.h" |
143 | #include "details/detailsviewcontainer.h" | 146 | #include "details/detailsviewcontainer.h" |
@@ -154,16 +157,51 @@ $Id$ | |||
154 | #include "kaimportoldialog.h" | 157 | #include "kaimportoldialog.h" |
155 | #else | 158 | #else |
156 | #include <unistd.h> | 159 | #include <unistd.h> |
157 | #endif | 160 | #endif |
158 | // sync includes | 161 | // sync includes |
159 | #include <libkdepim/ksyncprofile.h> | 162 | #include <libkdepim/ksyncprofile.h> |
160 | #include <libkdepim/ksyncprefsdialog.h> | 163 | #include <libkdepim/ksyncprefsdialog.h> |
161 | 164 | ||
165 | |||
166 | class KABCatPrefs : public QDialog | ||
167 | { | ||
168 | public: | ||
169 | KABCatPrefs( QWidget *parent=0, const char *name=0 ) : | ||
170 | QDialog( parent, name, true ) | ||
171 | { | ||
172 | setCaption( i18n("Manage new Categories") ); | ||
173 | QVBoxLayout* lay = new QVBoxLayout( this ); | ||
174 | lay->setSpacing( 3 ); | ||
175 | lay->setMargin( 3 ); | ||
176 | QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\naddressees\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); | ||
177 | lay->addWidget( lab ); | ||
178 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); | ||
179 | lay->addWidget( format ); | ||
180 | format->setExclusive ( true ) ; | ||
181 | addCatBut = new QRadioButton(i18n("Add to category list"), format ); | ||
182 | new QRadioButton(i18n("Remove from addressees"), format ); | ||
183 | addCatBut->setChecked( true ); | ||
184 | QPushButton * ok = new QPushButton( i18n("OK"), this ); | ||
185 | lay->addWidget( ok ); | ||
186 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | ||
187 | lay->addWidget( cancel ); | ||
188 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | ||
189 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | ||
190 | resize( 200, 200 ); | ||
191 | } | ||
192 | |||
193 | bool addCat() { return addCatBut->isChecked(); } | ||
194 | private: | ||
195 | QRadioButton* addCatBut; | ||
196 | }; | ||
197 | |||
198 | |||
199 | |||
162 | class KAex2phonePrefs : public QDialog | 200 | class KAex2phonePrefs : public QDialog |
163 | { | 201 | { |
164 | public: | 202 | public: |
165 | KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : | 203 | KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : |
166 | QDialog( parent, name, true ) | 204 | QDialog( parent, name, true ) |
167 | { | 205 | { |
168 | setCaption( i18n("Export to phone options") ); | 206 | setCaption( i18n("Export to phone options") ); |
169 | QVBoxLayout* lay = new QVBoxLayout( this ); | 207 | QVBoxLayout* lay = new QVBoxLayout( this ); |
@@ -951,17 +989,21 @@ void KABCore::setWhoAmI() | |||
951 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); | 989 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); |
952 | return; | 990 | return; |
953 | } | 991 | } |
954 | 992 | ||
955 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); | 993 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); |
956 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) | 994 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) |
957 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); | 995 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); |
958 | } | 996 | } |
959 | 997 | void KABCore::editCategories() | |
998 | { | ||
999 | KPIM::CategoryEditDialog dlg ( KABPrefs::instance(), this, "", true ); | ||
1000 | dlg.exec(); | ||
1001 | } | ||
960 | void KABCore::setCategories() | 1002 | void KABCore::setCategories() |
961 | { | 1003 | { |
962 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); | 1004 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); |
963 | if ( !dlg.exec() ) { | 1005 | if ( !dlg.exec() ) { |
964 | message( i18n("Setting categories cancelled") ); | 1006 | message( i18n("Setting categories cancelled") ); |
965 | return; | 1007 | return; |
966 | } | 1008 | } |
967 | bool merge = false; | 1009 | bool merge = false; |
@@ -983,17 +1025,16 @@ void KABCore::setCategories() | |||
983 | QStringList addrCategories = addr.categories(); | 1025 | QStringList addrCategories = addr.categories(); |
984 | QStringList::Iterator catIt; | 1026 | QStringList::Iterator catIt; |
985 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { | 1027 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { |
986 | if ( !addrCategories.contains( *catIt ) ) | 1028 | if ( !addrCategories.contains( *catIt ) ) |
987 | addrCategories.append( *catIt ); | 1029 | addrCategories.append( *catIt ); |
988 | } | 1030 | } |
989 | addr.setCategories( addrCategories ); | 1031 | addr.setCategories( addrCategories ); |
990 | } | 1032 | } |
991 | |||
992 | mAddressBook->insertAddressee( addr ); | 1033 | mAddressBook->insertAddressee( addr ); |
993 | } | 1034 | } |
994 | } | 1035 | } |
995 | 1036 | ||
996 | if ( uids.count() > 0 ) | 1037 | if ( uids.count() > 0 ) |
997 | setModified( true ); | 1038 | setModified( true ); |
998 | message( i18n("Setting categories completed!") ); | 1039 | message( i18n("Setting categories completed!") ); |
999 | } | 1040 | } |
@@ -1877,16 +1918,19 @@ void KABCore::initActions() | |||
1877 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, | 1918 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, |
1878 | SLOT( setWhoAmI() ), actionCollection(), | 1919 | SLOT( setWhoAmI() ), actionCollection(), |
1879 | "set_personal" ); | 1920 | "set_personal" ); |
1880 | 1921 | ||
1881 | 1922 | ||
1882 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, | 1923 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, |
1883 | SLOT( setCategories() ), actionCollection(), | 1924 | SLOT( setCategories() ), actionCollection(), |
1884 | "edit_set_categories" ); | 1925 | "edit_set_categories" ); |
1926 | mActionEditCategories = new KAction( i18n( "Edit Categories" ), 0, this, | ||
1927 | SLOT( editCategories() ), actionCollection(), | ||
1928 | "edit__categories" ); | ||
1885 | 1929 | ||
1886 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, | 1930 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, |
1887 | SLOT( removeVoice() ), actionCollection(), | 1931 | SLOT( removeVoice() ), actionCollection(), |
1888 | "remove_voice" ); | 1932 | "remove_voice" ); |
1889 | 1933 | ||
1890 | mActionManageCategories= new KAction( i18n( "Manage new categories..." ), 0, this, | 1934 | mActionManageCategories= new KAction( i18n( "Manage new categories..." ), 0, this, |
1891 | SLOT( manageCategories() ), actionCollection(), | 1935 | SLOT( manageCategories() ), actionCollection(), |
1892 | "remove_voice" ); | 1936 | "remove_voice" ); |
@@ -2045,16 +2089,17 @@ void KABCore::addActionsManually() | |||
2045 | mActionDetails->plug( settingsMenu ); | 2089 | mActionDetails->plug( settingsMenu ); |
2046 | //if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) | 2090 | //if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) |
2047 | mActionDetails->plug( tb ); | 2091 | mActionDetails->plug( tb ); |
2048 | settingsMenu->insertSeparator(); | 2092 | settingsMenu->insertSeparator(); |
2049 | mActionBR->plug(settingsMenu ); | 2093 | mActionBR->plug(settingsMenu ); |
2050 | settingsMenu->insertSeparator(); | 2094 | settingsMenu->insertSeparator(); |
2051 | 2095 | ||
2052 | mActionWhoAmI->plug( settingsMenu ); | 2096 | mActionWhoAmI->plug( settingsMenu ); |
2097 | mActionEditCategories->plug( settingsMenu ); | ||
2053 | mActionCategories->plug( settingsMenu ); | 2098 | mActionCategories->plug( settingsMenu ); |
2054 | mActionManageCategories->plug( settingsMenu ); | 2099 | mActionManageCategories->plug( settingsMenu ); |
2055 | 2100 | ||
2056 | 2101 | ||
2057 | mActionWN->plug( helpMenu ); | 2102 | mActionWN->plug( helpMenu ); |
2058 | mActionSyncHowto->plug( helpMenu ); | 2103 | mActionSyncHowto->plug( helpMenu ); |
2059 | mActionKdeSyncHowto->plug( helpMenu ); | 2104 | mActionKdeSyncHowto->plug( helpMenu ); |
2060 | mActionMultiSyncHowto->plug( helpMenu ); | 2105 | mActionMultiSyncHowto->plug( helpMenu ); |
@@ -2102,17 +2147,73 @@ void KABCore::addActionsManually() | |||
2102 | } | 2147 | } |
2103 | void KABCore::showLicence() | 2148 | void KABCore::showLicence() |
2104 | { | 2149 | { |
2105 | KApplication::showLicence(); | 2150 | KApplication::showLicence(); |
2106 | } | 2151 | } |
2107 | 2152 | ||
2108 | void KABCore::manageCategories( ) | 2153 | void KABCore::manageCategories( ) |
2109 | { | 2154 | { |
2110 | 2155 | KABCatPrefs* cp = new KABCatPrefs(); | |
2156 | cp->show(); | ||
2157 | int w =cp->sizeHint().width() ; | ||
2158 | int h = cp->sizeHint().height() ; | ||
2159 | int dw = QApplication::desktop()->width(); | ||
2160 | int dh = QApplication::desktop()->height(); | ||
2161 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
2162 | if ( !cp->exec() ) { | ||
2163 | delete cp; | ||
2164 | return; | ||
2165 | } | ||
2166 | int count = 0; | ||
2167 | message( i18n("Please wait, processing categories...")); | ||
2168 | if ( cp->addCat() ) { | ||
2169 | KABC::AddressBook::Iterator it; | ||
2170 | QStringList catList = KABPrefs::instance()->mCustomCategories; | ||
2171 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | ||
2172 | QStringList catIncList = (*it).categories(); | ||
2173 | int i; | ||
2174 | for( i = 0; i< catIncList.count(); ++i ) { | ||
2175 | if ( !catList.contains (catIncList[i])) { | ||
2176 | catList.append( catIncList[i] ); | ||
2177 | //qDebug("add cat %s ", catIncList[i].latin1()); | ||
2178 | ++count; | ||
2179 | } | ||
2180 | } | ||
2181 | } | ||
2182 | catList.sort(); | ||
2183 | KABPrefs::instance()->mCustomCategories = catList; | ||
2184 | KABPrefs::instance()->writeConfig(); | ||
2185 | message(QString::number( count )+ i18n(" categories added to list! ")); | ||
2186 | } else { | ||
2187 | QStringList catList = KABPrefs::instance()->mCustomCategories; | ||
2188 | QStringList catIncList; | ||
2189 | QStringList newCatList; | ||
2190 | KABC::AddressBook::Iterator it; | ||
2191 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | ||
2192 | QStringList catIncList = (*it).categories(); | ||
2193 | int i; | ||
2194 | if ( catIncList.count() ) { | ||
2195 | newCatList.clear(); | ||
2196 | for( i = 0; i< catIncList.count(); ++i ) { | ||
2197 | if ( catList.contains (catIncList[i])) { | ||
2198 | newCatList.append( catIncList[i] ); | ||
2199 | } | ||
2200 | } | ||
2201 | newCatList.sort(); | ||
2202 | (*it).setCategories( newCatList ); | ||
2203 | mAddressBook->insertAddressee( (*it) ); | ||
2204 | } | ||
2205 | } | ||
2206 | setModified( true ); | ||
2207 | mViewManager->refreshView(); | ||
2208 | mDetails->refreshView(); | ||
2209 | message( i18n("Removing categories done!")); | ||
2210 | } | ||
2211 | delete cp; | ||
2111 | } | 2212 | } |
2112 | void KABCore::removeVoice() | 2213 | void KABCore::removeVoice() |
2113 | { | 2214 | { |
2114 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) | 2215 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) |
2115 | return; | 2216 | return; |
2116 | KABC::Addressee::List list = mViewManager->selectedAddressees(); | 2217 | KABC::Addressee::List list = mViewManager->selectedAddressees(); |
2117 | KABC::Addressee::List::Iterator it; | 2218 | KABC::Addressee::List::Iterator it; |
2118 | for ( it = list.begin(); it != list.end(); ++it ) { | 2219 | for ( it = list.begin(); it != list.end(); ++it ) { |
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index bf5398b..d2ee45d 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h | |||
@@ -239,16 +239,17 @@ class KABCore : public QWidget, public KSyncInterface | |||
239 | void setWhoAmI(); | 239 | void setWhoAmI(); |
240 | 240 | ||
241 | /** | 241 | /** |
242 | Displays the category dialog and applies the result to all | 242 | Displays the category dialog and applies the result to all |
243 | selected contacts. | 243 | selected contacts. |
244 | */ | 244 | */ |
245 | void setCategories(); | 245 | void setCategories(); |
246 | void manageCategories(); | 246 | void manageCategories(); |
247 | void editCategories(); | ||
247 | 248 | ||
248 | /** | 249 | /** |
249 | Sets the field list of the Incremental Search Widget. | 250 | Sets the field list of the Incremental Search Widget. |
250 | */ | 251 | */ |
251 | void setSearchFields( const KABC::Field::List &fields ); | 252 | void setSearchFields( const KABC::Field::List &fields ); |
252 | 253 | ||
253 | /** | 254 | /** |
254 | Search with the current search field for a contact, that matches | 255 | Search with the current search field for a contact, that matches |
@@ -447,16 +448,17 @@ class KABCore : public QWidget, public KSyncInterface | |||
447 | KAction *mActionConfigKAddressbook; | 448 | KAction *mActionConfigKAddressbook; |
448 | KAction *mActionConfigShortcuts; | 449 | KAction *mActionConfigShortcuts; |
449 | KAction *mActionConfigureToolbars; | 450 | KAction *mActionConfigureToolbars; |
450 | KAction *mActionKeyBindings; | 451 | KAction *mActionKeyBindings; |
451 | KToggleAction *mActionJumpBar; | 452 | KToggleAction *mActionJumpBar; |
452 | KToggleAction *mActionDetails; | 453 | KToggleAction *mActionDetails; |
453 | KAction *mActionWhoAmI; | 454 | KAction *mActionWhoAmI; |
454 | KAction *mActionCategories; | 455 | KAction *mActionCategories; |
456 | KAction *mActionEditCategories; | ||
455 | KAction *mActionManageCategories; | 457 | KAction *mActionManageCategories; |
456 | KAction *mActionAboutKAddressbook; | 458 | KAction *mActionAboutKAddressbook; |
457 | KAction *mActionLicence; | 459 | KAction *mActionLicence; |
458 | KAction *mActionFaq; | 460 | KAction *mActionFaq; |
459 | KAction *mActionWN; | 461 | KAction *mActionWN; |
460 | KAction *mActionSyncHowto; | 462 | KAction *mActionSyncHowto; |
461 | KAction *mActionKdeSyncHowto; | 463 | KAction *mActionKdeSyncHowto; |
462 | KAction *mActionMultiSyncHowto; | 464 | KAction *mActionMultiSyncHowto; |