Changeset 6219
- Timestamp:
- 05/26/08 05:28:02 (6 months ago)
- Location:
- trunk/qt4-gui/src/dialogs
- Files:
-
- 2 modified
-
gpgkeymanager.cpp (modified) (15 diffs)
-
gpgkeymanager.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt4-gui/src/dialogs/gpgkeymanager.cpp
r6216 r6219 23 23 24 24 #include <QDialogButtonBox> 25 #include <QGroupBox>26 #include <QHBoxLayout>27 #include <QLabel>28 25 #include <QMenu> 29 #include <QMessageBox>30 26 #include <QPushButton> 31 27 #include <QVBoxLayout> … … 37 33 38 34 #include "core/mainwin.h" 35 #include "core/messagebox.h" 39 36 40 37 #include "helpers/support.h" … … 55 52 bool compare_luser(const struct luser& left, const struct luser& right) 56 53 { 57 return left.alias < right.alias;54 return QString::compare(left.alias, right.alias, Qt::CaseInsensitive) <= 0; 58 55 } 59 56 … … 67 64 QVBoxLayout* lay_main = new QVBoxLayout(this); 68 65 69 // GPG Passphrase box 70 QGroupBox* box_passphrase = new QGroupBox(tr("GPG Passphrase")); 71 lay_main->addWidget( box_passphrase ); 72 73 QHBoxLayout* lay_passphrase = new QHBoxLayout(box_passphrase); 74 75 lbl_passphrase = new QLabel(tr("No passphrase set")); 76 lay_passphrase->addWidget(lbl_passphrase); 77 QPushButton* btn_setPass = new QPushButton(tr("&Set GPG Passphrase")); 78 connect(btn_setPass, SIGNAL(clicked()), SLOT(slot_setPassphrase())); 79 lay_passphrase->addWidget(btn_setPass); 80 81 // GPG User/Key list 82 QHBoxLayout* lay_hbox = new QHBoxLayout(); 83 lay_main->addLayout(lay_hbox); 84 QGroupBox* box_keys = new QGroupBox(tr("User Keys")); 85 lay_hbox->addWidget(box_keys, 1); 86 QVBoxLayout* lay_keys = new QVBoxLayout(box_keys); 87 88 QVBoxLayout* lay_buttonBox = new QVBoxLayout(); 89 lay_hbox->addLayout(lay_buttonBox, 0); 90 QPushButton* btn_add = new QPushButton(tr("&Add")); 91 QPushButton* btn_edit = new QPushButton(tr("&Edit")); 92 QPushButton* btn_remove = new QPushButton(tr("&Remove")); 93 connect(btn_add, SIGNAL(clicked()), SLOT(slot_add())); 94 connect(btn_edit, SIGNAL(clicked()), SLOT(slot_edit())); 95 connect(btn_remove, SIGNAL(clicked()), SLOT(slot_remove())); 96 lbl_dragndrop = new QLabel(tr("Drag&Drop user to add to list.")); 97 lbl_dragndrop->setWordWrap(true); 98 99 // create the keylist 100 lst_keyList = new KeyList(this); 66 lst_keyList = new KeyList(); 101 67 lst_keyList->setAllColumnsShowFocus(true); 102 68 QStringList headers; … … 105 71 connect(lst_keyList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), 106 72 SLOT(slot_doubleClicked(QTreeWidgetItem*))); 107 lay_keys->addWidget(lst_keyList); 108 109 lay_buttonBox->addWidget(btn_add); 110 lay_buttonBox->addWidget(btn_edit); 111 lay_buttonBox->addWidget(btn_remove); 112 lay_buttonBox->addWidget(lbl_dragndrop); 113 lay_buttonBox->addStretch(); 114 115 // Close 73 lay_main->addWidget(lst_keyList); 74 116 75 QDialogButtonBox* buttons = new QDialogButtonBox(); 117 76 lay_main->addWidget(buttons); 118 77 119 QPushButton* btn_close = buttons->addButton(QDialogButtonBox::Close); 120 btn_close->setText(tr("&Close")); 121 connect(btn_close, SIGNAL(clicked()), SLOT(slot_close())); 78 QPushButton* btn; 79 #define BUTTON(role, name, slot) \ 80 btn = buttons->addButton(name, QDialogButtonBox::role); \ 81 connect(btn, SIGNAL(clicked()), SLOT(slot())) 82 83 BUTTON(ActionRole, tr("&Add"), slot_add); 84 BUTTON(ActionRole, tr("&Edit"), slot_edit); 85 BUTTON(ActionRole, tr("&Remove"), slot_remove); 86 87 #undef BUTTON 88 buttons->addButton(QDialogButtonBox::Close); 89 connect(buttons, SIGNAL(rejected()), SLOT(close())); 122 90 123 91 initKeyList(); … … 126 94 } 127 95 128 GPGKeyManager::~GPGKeyManager()129 {}130 131 void GPGKeyManager::slot_setPassphrase()132 {133 QMessageBox::information( this, tr("Set Passphrase"), tr("Not yet implemented. Use licq_gpg.conf.") );134 }135 136 void GPGKeyManager::slot_close()137 {138 close();139 }140 141 96 void GPGKeyManager::slot_edit() 142 97 { 143 QTreeWidgetItem* item = lst_keyList->currentItem(); 144 if (item ) 145 ( (KeyListItem*)item )->edit(); 98 slot_doubleClicked(lst_keyList->currentItem()); 146 99 } 147 100 148 101 void GPGKeyManager::slot_doubleClicked(QTreeWidgetItem* item) 149 102 { 150 if (item )151 ( (KeyListItem*)item)->edit();103 if (item != NULL) 104 dynamic_cast<KeyListItem*>(item)->edit(); 152 105 } 153 106 … … 159 112 FOR_EACH_USER_START(LOCK_R) 160 113 { 161 if (strcmp( pUser->GPGKey(), "") == 0)114 if (strcmp(pUser->GPGKey(), "") == 0) 162 115 { 163 116 luser tmp; … … 182 135 return; 183 136 184 editUser(tmp->szId, tmp->nPPID); 185 } 186 187 void GPGKeyManager::editUser(QString id, unsigned long ppid) 137 lst_keyList->editUser(tmp->szId, tmp->nPPID); 138 } 139 140 void GPGKeyManager::slot_remove() 141 { 142 KeyListItem* item = (KeyListItem*)lst_keyList->currentItem(); 143 if (item != NULL) 144 { 145 if (QueryYesNo(this, tr("Do you want to remove the GPG key binding for the user %1?\n" 146 "The key isn't deleted from your keyring.") 147 .arg(item->text(0)))) 148 { 149 item->unsetKey(); 150 delete item; 151 lst_keyList->resizeColumnsToContents(); 152 } 153 } 154 } 155 156 void GPGKeyManager::initKeyList() 157 { 158 FOR_EACH_USER_START(LOCK_R) 159 { 160 if (strcmp(pUser->GPGKey(), "") != 0) 161 { 162 new KeyListItem(lst_keyList, pUser); 163 } 164 } 165 FOR_EACH_USER_END 166 167 lst_keyList->resizeColumnsToContents(); 168 } 169 170 // THE KEYLIST 171 KeyList::KeyList(QWidget* parent) 172 : QTreeWidget(parent) 173 { 174 setAcceptDrops(true); 175 setRootIsDecorated(false); 176 } 177 178 void KeyList::editUser(QString id, unsigned long ppid) 188 179 { 189 180 KeyListItem* item = NULL; 190 181 bool found = false; 191 182 192 for (int i = 0; i < lst_keyList->topLevelItemCount(); ++i)193 { 194 item = dynamic_cast<KeyListItem*>( lst_keyList->topLevelItem(i));183 for (int i = 0; i < topLevelItemCount(); ++i) 184 { 185 item = dynamic_cast<KeyListItem*>(topLevelItem(i)); 195 186 196 187 if (item->getszId() == id && item->getnPPID() == ppid) … … 206 197 if (u == NULL) 207 198 return; 208 item = new KeyListItem( lst_keyList, u);199 item = new KeyListItem(this, u); 209 200 gUserManager.DropUser(u); 201 resizeColumnsToContents(); 210 202 } 211 203 … … 213 205 }; 214 206 215 void GPGKeyManager::slot_remove()216 {217 KeyListItem* item = (KeyListItem*)lst_keyList->currentItem();218 if ( item )219 {220 if ( QMessageBox::question( this, tr("Remove GPG key"), tr("Do you want to remove the GPG key? The key isn't deleted from your keyring."), QMessageBox::Yes, QMessageBox::No )==QMessageBox::Yes )221 {222 item->unsetKey();223 delete item;224 };225 }226 }227 228 void GPGKeyManager::initKeyList()229 {230 FOR_EACH_USER_START(LOCK_R)231 {232 if ( strcmp( pUser->GPGKey(), "" )!= 0 )233 {234 new KeyListItem( lst_keyList, pUser );235 }236 }237 FOR_EACH_USER_END238 }239 240 241 242 // THE KEYLIST243 KeyList::KeyList(QWidget* parent)244 : QTreeWidget(parent)245 {246 setAcceptDrops(true);247 setRootIsDecorated(false);248 }249 250 KeyList::~KeyList()251 {252 }253 254 207 void KeyList::dragEnterEvent(QDragEnterEvent* event) 255 208 { … … 258 211 } 259 212 260 void KeyList::dragMoveEvent(QDragMoveEvent* /* event */)261 {262 // Do nothing, just overload function so base class won't interfere263 }264 265 213 void KeyList::dropEvent(QDropEvent* event) 266 214 { 267 215 if (!event->mimeData()->hasText()) 268 216 return; 217 269 218 QString text = event->mimeData()->text(); 219 220 if (text.length() <= 4) 221 return; 270 222 271 223 unsigned long nPPID = 0; … … 280 232 FOR_EACH_PROTO_PLUGIN_END; 281 233 282 if (nPPID == 0 || text.length() <= 4) 283 return; 284 285 QString szId = text.mid(4); 286 287 GPGKeyManager* km = dynamic_cast<GPGKeyManager*>(nativeParentWidget()); 288 if (km != NULL) 289 km->editUser(szId, nPPID); 234 if (nPPID == 0) 235 return; 236 237 editUser(text.mid(4), nPPID); 290 238 } 291 239 … … 310 258 setColumnWidth(0, newWidth); 311 259 } 260 } 261 262 void KeyList::resizeColumnsToContents() 263 { 264 for (int i = 0; i < columnCount(); i++) 265 resizeColumnToContents(i); 312 266 } 313 267 … … 319 273 keySelect(NULL) 320 274 { 321 updateText( u ); 322 } 323 324 KeyListItem::~KeyListItem() 325 { 275 updateText(u); 326 276 } 327 277 328 278 void KeyListItem::updateText(ICQUser* u) 329 279 { 330 setText( 0, QString::fromUtf8(u->GetAlias()));331 setText( 1, u->UseGPG() ? tr("Yes") : tr("No"));332 setText( 2, u->GPGKey());280 setText(0, QString::fromUtf8(u->GetAlias())); 281 setText(1, u->UseGPG() ? tr("Yes") : tr("No")); 282 setText(2, u->GPGKey()); 333 283 } 334 284 335 285 void KeyListItem::edit() 336 286 { 337 if ( !keySelect)287 if (keySelect == NULL) 338 288 { 339 289 keySelect = new GPGKeySelect(szId, nPPID); … … 347 297 keySelect = NULL; 348 298 349 if ( u)350 { 351 if ( strcmp(u->GPGKey(),"")==0)299 if (u != NULL) 300 { 301 if (strcmp(u->GPGKey(), "") == 0) 352 302 delete this; 353 303 else 354 updateText( u);304 updateText(u); 355 305 gUserManager.DropUser(u); 306 dynamic_cast<KeyList*>(treeWidget())->resizeColumnsToContents(); 356 307 } 357 308 } -
trunk/qt4-gui/src/dialogs/gpgkeymanager.h
r6216 r6219 24 24 #include <QTreeWidget> 25 25 26 class QLabel;27 28 26 class ICQUser; 29 27 … … 39 37 public: 40 38 GPGKeyManager(QWidget* parent = 0); 41 ~GPGKeyManager();42 39 43 40 private: 44 41 KeyList* lst_keyList; 45 QLabel* lbl_passphrase;46 QLabel* lbl_dragndrop;47 void editUser(QString id, unsigned long ppid);48 42 void initKeyList(); 49 43 50 44 private slots: 51 void slot_setPassphrase();52 void slot_close();53 45 void slot_add(); 54 46 void slot_edit(); 55 47 void slot_remove(); 56 48 void slot_doubleClicked(QTreeWidgetItem* item); 57 58 friend class KeyList;59 49 }; 60 50 … … 65 55 public: 66 56 KeyList(QWidget* parent = 0); 67 ~KeyList(); 57 58 void editUser(QString id, unsigned long ppid); 59 void resizeColumnsToContents(); 68 60 69 61 private: 70 62 void dragEnterEvent(QDragEnterEvent* event); 71 void dragMoveEvent(QDragMoveEvent* event);63 void dragMoveEvent(QDragMoveEvent* /* event */) {}; 72 64 void dropEvent(QDropEvent* event); 73 virtual void resizeEvent(QResizeEvent* e );65 virtual void resizeEvent(QResizeEvent* event); 74 66 }; 75 67 … … 80 72 public: 81 73 KeyListItem(QTreeWidget* parent, ICQUser* u); 82 ~KeyListItem();83 74 84 75 void edit();
