-
Notifications
You must be signed in to change notification settings - Fork 27
/
KeyhoteeMainWindow.cpp
1735 lines (1481 loc) · 55.6 KB
/
KeyhoteeMainWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "KeyhoteeMainWindow.hpp"
#include "ui_KeyhoteeMainWindow.h"
#include "connectionstatusframe.h"
#include "diagnosticdialog.h"
#include "GitSHA1.h"
#include "KeyhoteeApplication.hpp"
#include "MenuEditControl.hpp"
#include "public_key_address.hpp"
#include "AddressBook/AddressBookModel.hpp"
#include "AddressBook/authorization.hpp"
#include "AddressBook/ContactGui.hpp"
#include "AddressBook/ContactView.hpp"
#include "AddressBook/NewIdentityDialog.hpp"
#include "AddressBook/RequestAuthorization.hpp"
#include "Identity/IdentityObservable.hpp"
#include "BitShares/GitSHA2.h"
#include <fc/git_revision.hpp>
#include "Mail/MailboxModel.hpp"
#include "Mail/MailboxModelRoot.hpp"
#include "Mail/maileditorwindow.hpp"
#include "Options/OptionsDialog.h"
#include "Wallets/ManageWallet.hpp"
#include "Wallets/wallets.hpp"
#include "Wallets/WalletsGui.hpp"
#include <fc/reflect/variant.hpp>
#include <fc/log/logger.hpp>
#include <fc/thread/thread.hpp>
#include <fc/interprocess/process.hpp>
/// QT headers:
#include <QAction>
#include <QCompleter>
#include <QApplication>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#ifdef Q_OS_MAC
//#include <qmacnativetoolbar.h>
#endif
extern bool gMiningIsPossible;
extern QTemporaryFile gLogFile;
KeyhoteeMainWindow* getKeyhoteeWindow()
{
return TKeyhoteeApplication::getInstance()->getMainWindow();
}
enum SidebarItemRoles
{
ContactIdRole = Qt::UserRole
};
enum TopLevelItemIndexes
{
Mailboxes,
Space2,
WalletsItems,
Space3,
Contacts,
Space4,
Requests
};
KeyhoteeMainWindow::KeyhoteeMainWindow(const TKeyhoteeApplication& mainApp) :
_identities_root(nullptr),
_connectionProcessor(*this, bts::application::instance()->get_profile()),
_currentMailbox(nullptr),
_isClosing(false),
_walletsGui(new WalletsGui(this)),
_is_curr_contact_blocked(false),
_is_curr_contact_own(false),
_is_filter_blocked_on(false),
_is_show_blocked_contacts(false),
_bitshares_client_on_startup(true)
{
ui = new Ui::KeyhoteeMainWindow;
ui->setupUi(this);
QString profileName = mainApp.getLoadedProfileName();
QString title = QString("%1 v%2 (%3)").arg(mainApp.getAppName().c_str()).arg(mainApp.getVersionNumberString().c_str()).arg(profileName);
setWindowTitle(title);
setEnabledAttachmentSaveOption(false);
setEnabledDeleteOption(false);
onEnableMailButtons(false);
setEnabledContactOption(false);
QString settings_file = "keyhotee_";
settings_file.append(profileName);
setSettingsFile(settings_file);
readSettings();
QSettings settings("Invictus Innovations", settings_file);
_is_filter_blocked_on = settings.value("FilterBlocked", "").toBool();
ui->actionShow_blocked_contacts->setEnabled(_is_filter_blocked_on);
_bitshares_client_on_startup = settings.value("BitSharesClientOnStartup", "").toBool();
connect(ui->contacts_page, &ContactsTable::contactOpened, this, &KeyhoteeMainWindow::openContactGui);
connect(ui->contacts_page, &ContactsTable::contactDeleted, this, &KeyhoteeMainWindow::deleteContactGui);
#ifdef Q_OS_MAC
//QMacNativeToolBar* native_toolbar = QtMacExtras::setNativeToolBar(ui->toolbar, true);
ui->side_bar->setAttribute(Qt::WA_MacShowFocusRect, 0);
#endif /// Q_OS_MAC
setupStatusBar();
QWidget* empty = new QWidget();
empty->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
ui->toolbar->addWidget(empty);
_search_edit = new QLineEdit(ui->toolbar);
ui->toolbar->addWidget(_search_edit);
_search_edit->setMaximumSize(QSize(150, 22) );
_search_edit->setAttribute(Qt::WA_MacShowFocusRect, 0);
const char* search_style = "QLineEdit { " \
"padding-right: 20px; " \
"padding-left: 5px; " \
"background: url(:/images/search24x16.png);" \
"background-position: right;" \
"background-repeat: no-repeat;" \
"border: 1px solid gray;" \
"border-radius: 10px;}";
_search_edit->setStyleSheet(search_style);
_search_edit->setPlaceholderText(tr("Search") );
QWidget* empty2 = new QWidget();
empty->resize(QSize(10, 10) );
ui->toolbar->addWidget(empty2);
ui->actionEnable_Mining->setEnabled(gMiningIsPossible);
ui->actionEnable_Mining->setVisible(gMiningIsPossible);
ui->side_bar->setModificationsChecker (this);
menuEdit = new MenuEditControl(this, ui->actionCopy, ui->actionCut, ui->actionPaste);
//init ui->actionPaste
onClipboardChanged();
connect(QApplication::clipboard(), &QClipboard::changed, this, &KeyhoteeMainWindow::onClipboardChanged);
// ---------------------- MenuBar
// File
connect(ui->actionOptions, &QAction::triggered, this, &KeyhoteeMainWindow::onOptions);
connect(ui->actionExit, &QAction::triggered, this, &KeyhoteeMainWindow::onExit);
// Edit
connect(ui->actionCopy, &QAction::triggered, this, &KeyhoteeMainWindow::onCopy);
connect(ui->actionCut, &QAction::triggered, this, &KeyhoteeMainWindow::onCut);
connect(ui->actionPaste, &QAction::triggered, this, &KeyhoteeMainWindow::onPaste);
connect(ui->actionSelect_All, &QAction::triggered, this, &KeyhoteeMainWindow::onSelectAll);
// Identity
connect(ui->actionNew_identity, &QAction::triggered, this, &KeyhoteeMainWindow::onNewIdentity);
connect(ui->actionEnable_Mining, &QAction::toggled, this, &KeyhoteeMainWindow::onEnableMining);
// Mail
connect(ui->actionNew_Message, &QAction::triggered, this, &KeyhoteeMainWindow::newMailMessage);
connect(ui->actionSave_attachement, &QAction::triggered, this, &KeyhoteeMainWindow::onSaveAttachement);
// Contact
connect(ui->actionNew_Contact, &QAction::triggered, this, &KeyhoteeMainWindow::addContact);
connect(ui->actionSet_Icon, &QAction::triggered, this, &KeyhoteeMainWindow::onSetIcon);
connect(ui->actionShow_Contacts, &QAction::triggered, this, &KeyhoteeMainWindow::showContacts);
connect(ui->actionRequest_authorization, &QAction::triggered, this, &KeyhoteeMainWindow::onRequestAuthorization);
connect(ui->actionShow_blocked_contacts, &QAction::triggered, this, &KeyhoteeMainWindow::onShowBlockedContacts);
connect(ui->actionBlock, &QAction::triggered, this, &KeyhoteeMainWindow::onBlockContact);
connect(ui->actionUnblock, &QAction::triggered, this, &KeyhoteeMainWindow::onUnblockContact);
connect(ui->actionShare_contact, &QAction::triggered, this, &KeyhoteeMainWindow::onShareContact);
// Help
connect(ui->actionDiagnostic, &QAction::triggered, this, &KeyhoteeMainWindow::onDiagnostic);
connect(ui->actionAbout, &QAction::triggered, this, &KeyhoteeMainWindow::onAbout);
connect(ui->splitter, &QSplitter::splitterMoved, this, &KeyhoteeMainWindow::sideBarSplitterMoved);
connect(ui->side_bar, &TreeWidgetCustom::itemSelectionChanged, this, &KeyhoteeMainWindow::onSidebarSelectionChanged);
connect(ui->side_bar, &TreeWidgetCustom::itemDoubleClicked, this, &KeyhoteeMainWindow::onSidebarDoubleClicked);
connect(ui->side_bar, &TreeWidgetCustom::itemContactRemoved, this, &KeyhoteeMainWindow::onItemContactRemoved);
connect(ui->side_bar, &TreeWidgetCustom::itemContextAcceptRequest, this, &KeyhoteeMainWindow::onItemContextAcceptRequest);
connect(ui->side_bar, &TreeWidgetCustom::itemContextDenyRequest, this, &KeyhoteeMainWindow::onItemContextDenyRequest);
connect(ui->side_bar, &TreeWidgetCustom::itemContextBlockRequest, this, &KeyhoteeMainWindow::onItemContextBlockRequest);
//connect( _search_edit, SIGNAL(textChanged(QString)), this, SLOT(searchEditChanged(QString)) );
connect(_search_edit, &QLineEdit::textChanged, this, &KeyhoteeMainWindow::searchEditChanged);
auto space2 = ui->side_bar->topLevelItem(TopLevelItemIndexes::Space2);
auto space3 = ui->side_bar->topLevelItem(TopLevelItemIndexes::Space3);
auto space_flags = space2->flags() & (~Qt::ItemFlags(Qt::ItemIsSelectable) );
space_flags |= Qt::ItemNeverHasChildren;
space2->setFlags(space_flags);
space3->setFlags(space_flags);
//_identities_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Identities);
_mailboxes_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Mailboxes);
_contacts_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Contacts);
_wallets_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::WalletsItems);
_requests_root = ui->side_bar->topLevelItem(TopLevelItemIndexes::Requests);
_contacts_root->setExpanded(true);
_requests_root->setExpanded(true);
_requests_root->setHidden(true);
//_identities_root->setExpanded(true);
_mailboxes_root->setExpanded(true);
_inbox_root = _mailboxes_root->child(Inbox);
_drafts_root = _mailboxes_root->child(Drafts);
_out_box_root = _mailboxes_root->child(Outbox);
_sent_root = _mailboxes_root->child(Sent);
_spam_root = _mailboxes_root->child(Spam);
setupWallets();
auto app = bts::application::instance();
auto profile = app->get_profile();
auto idents = profile->identities();
auto addressbook = profile->get_addressbook();
_addressbook_model = new AddressBookModel(this, addressbook);
_inbox_model = new MailboxModel(this, profile, profile->get_inbox_db(), *_addressbook_model, _inbox_root, false);
_draft_model = new MailboxModel(this, profile, profile->get_draft_db(), *_addressbook_model, _drafts_root, true);
_pending_model = new MailboxModel(this, profile, profile->get_pending_db(), *_addressbook_model, _out_box_root, false);
_sent_model = new MailboxModel(this, profile, profile->get_sent_db(), *_addressbook_model, _sent_root, false);
_spam_model = new MailboxModel(this, profile, profile->get_spam_db(), *_addressbook_model, _spam_root, false);
_mail_model_root = new MailboxModelRoot();
_mail_model_root->addMailboxModel(_inbox_model);
_mail_model_root->addMailboxModel(_draft_model);
_mail_model_root->addMailboxModel(_pending_model);
_mail_model_root->addMailboxModel(_sent_model);
_mail_model_root->addMailboxModel(_spam_model);
loadStoredRequests(profile->get_request_db());
connect(_addressbook_model, &QAbstractItemModel::dataChanged, this,
&KeyhoteeMainWindow::addressBookDataChanged);
ui->contacts_page->setAddressBook(_addressbook_model);
ui->new_contact->setAddressBook(_addressbook_model);
ui->inbox_page->initial(_connectionProcessor, _inbox_model, Mailbox::Inbox, this);
ui->draft_box_page->initial(_connectionProcessor, _draft_model, Mailbox::Drafts, this);
ui->out_box_page->initial(_connectionProcessor, _pending_model, Mailbox::Outbox, this);
ui->sent_box_page->initial(_connectionProcessor, _sent_model, Mailbox::Sent, this);
ui->spam_box_page->initial(_connectionProcessor, _spam_model, Mailbox::Spam, this);
_mailboxesList.push_back (ui->inbox_page);
_mailboxesList.push_back (ui->draft_box_page);
_mailboxesList.push_back (ui->out_box_page);
_mailboxesList.push_back (ui->sent_box_page);
_mailboxesList.push_back(ui->spam_box_page);
ui->widget_stack->setCurrentWidget(ui->inbox_page);
ui->actionDelete->setShortcut(QKeySequence::Delete);
connect(ui->actionDelete, SIGNAL(triggered()), ui->inbox_page, SLOT(onDeleteMail()));
connect(ui->actionShow_details, SIGNAL(toggled(bool)), ui->inbox_page, SLOT(on_actionShow_details_toggled(bool)));
connect(ui->actionReply, SIGNAL(triggered()), ui->inbox_page, SLOT(onReplyMail()));
connect(ui->actionReply_all, SIGNAL(triggered()), ui->inbox_page, SLOT(onReplyAllMail()));
connect(ui->actionForward, SIGNAL(triggered()), ui->inbox_page, SLOT(onForwardMail()));
wlog("idents: ${idents}", ("idents", idents) );
if(isIdentityPresent() == false )
{
ui->actionNew_Message->setEnabled(false);
ui->actionRequest_authorization->setEnabled(false);
}
for (size_t i = 0; i < idents.size(); ++i)
{
try {
app->mine_name(idents[i].dac_id_string,
profile->get_keychain().get_identity_key(idents[i].dac_id_string).get_public_key(),
idents[i].mining_effort);
}
catch ( const fc::exception& e )
{
wlog( "${e}", ("e",e.to_detail_string()) );
}
}
app->set_mining_intensity(0);
ui->actionEnable_Mining->setChecked(app->get_mining_intensity() != 0);
/*
auto abook = profile->get_addressbook();
auto contacts = abook->get_known_bitnames();
for( auto itr = contacts.begin(); itr != contacts.end(); ++itr )
{
auto new_contact_item = new QTreeWidgetItem(_contacts_root, (QTreeWidgetItem::ItemType)ContactItem );
auto id_rec = app->lookup_name( *itr );
if( !id_rec )
{
new_contact_item->setText( 0, (*itr + " [unknown]").c_str() );
}
else
{
new_contact_item->setText( 0, (*itr + " [" + std::to_string(id_rec->repute)+"]" ).c_str() );
}
}
*/
// add identity observer
IdentityObservable::getInstance().addObserver(this);
QAction* actionMenu = new QAction(tr("Keyhotee"), this);
actionMenu->setCheckable(true);
this->setMenuWindow(ui->menuWindow);
this->registration(actionMenu);
actionMenu->setVisible(false);
}
KeyhoteeMainWindow::~KeyhoteeMainWindow()
{
foreach(TTreeItem2ManageWallet::value_type wallet, _tree_item_2_wallet)
wallet.second->shutdown();
IdentityObservable::getInstance().deleteObserver(this);
delete menuEdit;
delete ui;
}
void KeyhoteeMainWindow::activateMailboxPage(Mailbox* mailBox)
{
ui->widget_stack->setCurrentWidget(mailBox);
connect(ui->actionDelete, SIGNAL(triggered()), mailBox, SLOT(onDeleteMail()));
connect(ui->actionShow_details, SIGNAL(toggled(bool)), mailBox, SLOT(on_actionShow_details_toggled(bool)));
connect(ui->actionReply, SIGNAL(triggered()), mailBox, SLOT(onReplyMail()));
connect(ui->actionReply_all, SIGNAL(triggered()), mailBox, SLOT(onReplyAllMail()));
connect(ui->actionForward, SIGNAL(triggered()), mailBox, SLOT(onForwardMail()));
bool checked = mailBox->isShowDetailsHidden() == false;
ui->actionShow_details->setChecked(checked);
_currentMailbox = mailBox;
_currentMailbox->checkSendMailButtons();
setEnabledAttachmentSaveOption(_currentMailbox->isAttachmentSelected());
setEnabledDeleteOption (_currentMailbox->isSelection());
}
void KeyhoteeMainWindow::addContact()
{
if (checkSaving())
{
connect(ui->new_contact, &ContactView::savedNewContact, this, &KeyhoteeMainWindow::onSavedNewContact);
connect(ui->new_contact, &ContactView::savedNewContact, ui->contacts_page, &ContactsTable::onSavedNewContact);
connect(ui->new_contact, &ContactView::canceledNewContact, this, &KeyhoteeMainWindow::onCanceledNewContact);
connect(ui->new_contact, &ContactView::canceledNewContact, ui->contacts_page, &ContactsTable::onCanceledNewContact);
enableMenu(false);
ui->new_contact->setAddingNewContact(true);
ui->new_contact->setContact(Contact());
ui->contacts_page->addNewContact(*ui->new_contact);
ui->widget_stack->setCurrentWidget(ui->contacts_page);
//ui->widget_stack->setCurrentWidget( ui->new_contact);
}
}
void KeyhoteeMainWindow::addToContacts(const bts::addressbook::wallet_contact& wallet_contact)
{
addContact();
std::string public_key_string = public_key_address(wallet_contact.public_key);
ui->new_contact->setPublicKey(public_key_string.c_str());
}
void KeyhoteeMainWindow::addToContacts(bool silent, std::list<Contact> &contacts)
{
if (silent)
{
for (const auto& contact : contacts)
{
_addressbook_model->storeContact(contact);
showContacts();
}
}
else
{
//only 1 contact on !silent mode
assert(contacts.size() == 1);
addContact();
const Contact &contact = contacts.front();
ui->new_contact->setContactFromvCard(contact);
}
}
void KeyhoteeMainWindow::sideBarSplitterMoved(int pos, int index)
{
if (pos <= 5)
ui->splitter->setHandleWidth(5);
else
ui->splitter->setHandleWidth(0);
}
void KeyhoteeMainWindow::addressBookDataChanged(const QModelIndex& top_left, const QModelIndex& bottom_right,
const QVector<int>& roles)
{
const Contact& changed_contact = _addressbook_model->getContact(top_left);
auto itr = _contact_guis.find(changed_contact.wallet_index);
if (itr != _contact_guis.end() )
itr->second.updateTreeItemDisplay();
}
void KeyhoteeMainWindow::searchEditChanged(QString search_string)
{
auto current_widget = ui->widget_stack->currentWidget();
Mailbox* mailbox = dynamic_cast<Mailbox*>(current_widget);
if (mailbox)
{
mailbox->searchEditChanged(search_string);
return;
}
ContactsTable* contacts_table = dynamic_cast<ContactsTable*>(current_widget);
if (contacts_table)
{
contacts_table->searchEditChanged(search_string);
return;
}
}
bool KeyhoteeMainWindow::isSelectedContactGui(ContactGui* contactGui)
{
QList<QTreeWidgetItem*> selected_items = ui->side_bar->selectedItems();
if (selected_items.size() == 1)
return selected_items[0] == contactGui->_tree_item;
return false;
}
void KeyhoteeMainWindow::onSidebarSelectionChanged()
{
QList<QTreeWidgetItem*> selected_items = ui->side_bar->selectedItems();
if (selected_items.size() )
{
disconnect(ui->actionDelete, SIGNAL(triggered()), this, SLOT(onRemoveContact()));
disconnect(ui->actionDelete, SIGNAL(triggered()), this, SLOT(onDeleteAuthorizationItem()));
disconnect(ui->actionShow_details, SIGNAL(toggled(bool)), ui->contacts_page, SLOT(on_actionShow_details_toggled(bool)));
for (Mailbox* mailBox : _mailboxesList)
{
disconnect(ui->actionDelete, SIGNAL(triggered()), mailBox, SLOT(onDeleteMail()));
disconnect(ui->actionReply, SIGNAL(triggered()), mailBox, SLOT(onReplyMail()));
disconnect(ui->actionReply_all, SIGNAL(triggered()), mailBox, SLOT(onReplyAllMail()));
disconnect(ui->actionForward, SIGNAL(triggered()), mailBox, SLOT(onForwardMail()));
disconnect(ui->actionShow_details, SIGNAL(toggled(bool)), mailBox, SLOT(on_actionShow_details_toggled(bool)));
}
setEnabledDeleteOption (false);
setEnabledAttachmentSaveOption(false);
onEnableMailButtons(false);
setEnabledContactOption(false);
_currentMailbox = nullptr;
ui->actionShow_details->setEnabled(true);
QTreeWidgetItem* selectedItem = selected_items.first();
if (selectedItem->type() == ContactItem)
{
auto con_id = selected_items[0]->data(0, ContactIdRole).toInt();
openContactGui(con_id);
connect(ui->actionDelete, SIGNAL(triggered()), this, SLOT(onRemoveContact()));
connect(ui->actionShow_details, SIGNAL(toggled(bool)), ui->contacts_page, SLOT(on_actionShow_details_toggled(bool)));
if(ui->contacts_page->isShowDetailsHidden())
ui->actionShow_details->setChecked(false);
else
ui->actionShow_details->setChecked(true);
if(_is_filter_blocked_on && _is_show_blocked_contacts && !_is_curr_contact_blocked)
enableBlockedContact(false);
ui->contacts_page->selectRow(con_id);
refreshMenuOptions();
}
else if (selectedItem->type() == IdentityItem)
{
selectIdentityItem(selectedItem);
}
else if (selectedItem == _contacts_root)
{
showContacts();
connect(ui->actionDelete, SIGNAL(triggered()), this, SLOT(onRemoveContact()));
connect(ui->actionShow_details, SIGNAL(toggled(bool)), ui->contacts_page, SLOT(on_actionShow_details_toggled(bool)));
if (ui->contacts_page->isShowDetailsHidden())
ui->actionShow_details->setChecked(false);
else
ui->actionShow_details->setChecked(true);
refreshMenuOptions();
}
else if(selectedItem == _requests_root)
{
}
else if (selectedItem->type() == RequestItem)
{
showAuthorizationItem(static_cast<AuthorizationItem*>(selectedItem));
connect(ui->actionDelete, SIGNAL(triggered()), this, SLOT(onDeleteAuthorizationItem()));
setEnabledDeleteOption(true);
ui->actionShow_details->setEnabled(false);
}
//else if( selected_items[0] == _identities_root )
//{
//}
/// For mailboxes root just select inbox root
else if (selectedItem == _mailboxes_root || selectedItem == _inbox_root)
{
activateMailboxPage(ui->inbox_page);
}
else if (selectedItem == _drafts_root)
{
activateMailboxPage(ui->draft_box_page);
}
else if (selectedItem == _out_box_root)
{
activateMailboxPage(ui->out_box_page);
}
else if (selectedItem == _sent_root)
{
activateMailboxPage(ui->sent_box_page);
}
else if(selectedItem == _spam_root)
{
activateMailboxPage(ui->spam_box_page);
}
else if (selectedItem == _wallets_root)
{
ui->widget_stack->setCurrentWidget(ui->wallets);
ui->actionShow_details->setEnabled(false);
}
else
{
ui->actionShow_details->setEnabled(false);
for (const auto& walletItem : _walletItems)
{
if (selectedItem == walletItem)
{
/// Find and show wallet WebSite
TTreeItem2ManageWallet::const_iterator foundPos = _tree_item_2_wallet.find(selectedItem);
if(foundPos != _tree_item_2_wallet.end())
{
foundPos->second->loadPage();
ui->widget_stack->setCurrentWidget(foundPos->second->getWebWallet());
}
}
}
}
}
}
void KeyhoteeMainWindow::onSidebarDoubleClicked()
{
QList<QTreeWidgetItem*> selected_items = ui->side_bar->selectedItems();
if (selected_items.size() )
{
if (selected_items[0]->type() == ContactItem)
{
ui->contacts_page->selectChat ();
}
}
}
void KeyhoteeMainWindow::selectContactItem(QTreeWidgetItem* item)
{}
void KeyhoteeMainWindow::selectIdentityItem(QTreeWidgetItem* item)
{}
// Menu File
void KeyhoteeMainWindow::onExit()
{
qApp->closeAllWindows();
}
// Menu Edit
void KeyhoteeMainWindow::onCopy()
{
QWidget *focused = focusWidget ();
if (focused == nullptr)
return;
if(focused == ui->side_bar) //TreeView focused
{
if (ui->widget_stack->currentWidget () == ui->contacts_page)
ui->contacts_page->copy ();
}
//contact list
else if(focused == ui->contacts_page->getContactsTableWidget())
{
ui->contacts_page->copy ();
}
else
{
menuEdit->copy();
}
}
void KeyhoteeMainWindow::onCut()
{
menuEdit->cut();
}
void KeyhoteeMainWindow::onPaste()
{
menuEdit->paste();
}
void KeyhoteeMainWindow::onSelectAll()
{
QWidget *focused = focusWidget ();
if (focused == nullptr)
return;
if(ui->side_bar == focused) //TreeView focused
{
if (ui->widget_stack->currentWidget () == ui->contacts_page)
ui->contacts_page->selectAll ();
else if (ui->widget_stack->currentWidget () == _currentMailbox)
_currentMailbox->selectAll ();
else if (ui->widget_stack->currentWidget () == ui->wallets)
; //ui->wallets->selectAll ();
else
assert (0);
}
else
{
menuEdit->selectAll();
}
}
// Menu Identity
void KeyhoteeMainWindow::onNewIdentity()
{
NewIdentityDialog* ident_dialog = new NewIdentityDialog(this);
QObject::connect(ident_dialog, SIGNAL(identityadded()),
this, SLOT(enableNewMessageIcon()));
ident_dialog->exec();
}
bool KeyhoteeMainWindow::isIdentityPresent()
{
auto app = bts::application::instance();
auto profile = app->get_profile();
auto idents = profile->identities();
return (idents.size() != 0);
}
void KeyhoteeMainWindow::enableNewMessageIcon()
{
if(isIdentityPresent() == true )
{
ui->actionNew_Message->setEnabled(true);
ui->actionRequest_authorization->setEnabled(true);
emit checkSendMailSignal();
if (_currentMailbox != nullptr)
{
_currentMailbox->checkSendMailButtons();
}
}
}
void KeyhoteeMainWindow::onEnableMining(bool enabled)
{
auto app = bts::application::instance();
app->set_mining_intensity(enabled ? 100 : 0);
}
// Menu Mail
void KeyhoteeMainWindow::onSaveAttachement()
{
assert (_currentMailbox != nullptr);
_currentMailbox->saveAttachment();
}
// Menu Contact
void KeyhoteeMainWindow::onSetIcon()
{
notSupported();
}
void KeyhoteeMainWindow::onRequestAuthorization()
{
RequestAuthorization *request = new RequestAuthorization(this, _connectionProcessor, _addressbook_model);
connect(request, &RequestAuthorization::authorizationStatus, this, &KeyhoteeMainWindow::onUpdateAuthoStatus);
request->show();
}
void KeyhoteeMainWindow::onShowBlockedContacts()
{
ui->side_bar->setCurrentItem(_contacts_root);
ui->widget_stack->setCurrentWidget(ui->contacts_page);
enableBlockedContact(true);
}
void KeyhoteeMainWindow::onBlockContact()
{
QList<const Contact*> contacts;
ui->contacts_page->getSelectedContacts(contacts);
if(contacts.empty())
return;
if(QMessageBox::question(this, tr("Block Contact"), tr("Are you sure you want to block selected contact(s)?")) == QMessageBox::Button::No)
return;
foreach(const Contact* contact, contacts)
{
if(contact->isOwn())
continue;
Contact temp_contact = *contact;
temp_contact.auth_status = bts::addressbook::authorization_status::i_block;
_addressbook_model->storeContact(temp_contact);
onUpdateAuthoStatus(temp_contact.wallet_index);
if(!_is_filter_blocked_on)
{
_is_curr_contact_blocked = true;
setEnabledContactOption(true);
}
}
}
void KeyhoteeMainWindow::onUnblockContact()
{
QList<const Contact*> contacts;
ui->contacts_page->getSelectedContacts(contacts);
if(contacts.empty())
return;
if(QMessageBox::question(this, tr("Unblock Contact"), tr("Are you sure you want to unblock selected contact(s)?")) == QMessageBox::Button::No)
return;
foreach(const Contact* contact, contacts)
{
if(contact->isOwn() || contact->auth_status != bts::addressbook::i_block)
continue;
Contact temp_contact = *contact;
temp_contact.auth_status = bts::addressbook::authorization_status::unauthorized;
_addressbook_model->storeContact(temp_contact);
onUpdateAuthoStatus(temp_contact.wallet_index);
if(!_is_filter_blocked_on)
{
_is_curr_contact_blocked = false;
setEnabledContactOption(true);
}
}
}
void KeyhoteeMainWindow::displayDiagnosticLog()
{
DiagnosticDialog diagnoslic_dialog;
diagnoslic_dialog.setModal(true);
diagnoslic_dialog.exec();
}
// Menu Help
void KeyhoteeMainWindow::onDiagnostic()
{
displayDiagnosticLog();
}
void KeyhoteeMainWindow::onAbout()
{
QString title(tr("About "));
title += TKeyhoteeApplication::getInstance()->getAppName().c_str();
QString text;
text = tr("<p align='center'><b>");
text += TKeyhoteeApplication::getInstance()->getAppName().c_str();
/// Commented out to avoid difference against install package version.
text += tr(" version ");
text += tr(TKeyhoteeApplication::getInstance()->getVersionNumberString().c_str());
text += tr("</b><br/><br/>");
/// Build tag: <a href="https://github.com/InvictusInnovations/keyhotee/commit/xxxx">xxxx</a>
text += tr("<strong>keyhotee</strong> built from revision: <a href=\"https://github.com/InvictusInnovations/keyhotee/commit/");
text += tr(g_GIT_SHA1);
text += tr("\">");
text += tr(std::string(g_GIT_SHA1).substr(0, 10).c_str());
text += tr("</a>");
text += tr(" (<em>");
text += tr(fc::get_approximate_relative_time_string(fc::time_point_sec(g_GIT_UNIX_TIMESTAMP1)).c_str());
text += tr("</em>)");
text += tr("<br/>");
text += tr("<br/>");
text += tr("<strong>BitShares</strong> built from revision: <a href=\"https://github.com/InvictusInnovations/BitShares/commit/");
text += tr(g_GIT_SHA2);
text += tr("\">");
text += tr(std::string(g_GIT_SHA2).substr(0, 10).c_str());
text += tr("</a>");
text += tr(" (<em>");
text += tr(fc::get_approximate_relative_time_string(fc::time_point_sec(g_GIT_UNIX_TIMESTAMP2)).c_str());
text += tr("</em>)");
text += tr("<br/>");
text += tr("<br/>");
text += tr("<strong>fc</strong> built from revision: <a href=\"https://github.com/InvictusInnovations/fc/commit/");
text += tr(fc::git_revision_sha);
text += tr("\">");
text += tr(std::string(fc::git_revision_sha).substr(0, 10).c_str());
text += tr("</a>");
text += tr(" (<em>");
text += tr(fc::get_approximate_relative_time_string(fc::time_point_sec(fc::git_revision_unix_timestamp)).c_str());
text += tr("</em>)");
text += tr("<br/>");
text += tr("<br/>");
text += tr("Invictus Innovations Inc<br/>");
text += tr("<a href=\"http://invictus-innovations.com/keyhotee/\">http://invictus-innovations.com/keyhotee/</a>");
text += tr("<br/></p>");
QMessageBox::about(this, title, text);
}
void KeyhoteeMainWindow::showContacts()
{
ui->side_bar->setCurrentItem(_contacts_root);
ui->widget_stack->setCurrentWidget(ui->contacts_page);
enableBlockedContact(false);
}
void KeyhoteeMainWindow::newMailMessage()
{
MailEditorMainWindow* mailWindow = new MailEditorMainWindow(this, *_addressbook_model,
_connectionProcessor, true);
mailWindow->show();
}
void KeyhoteeMainWindow::newMailMessageTo(const Contact& contact)
{
MailEditorMainWindow* mailWindow = new MailEditorMainWindow(this, *_addressbook_model,
_connectionProcessor, true);
IMailProcessor::TRecipientPublicKeys toList, emptyList;
toList.push_back(contact.public_key);
mailWindow->SetRecipientList(toList, emptyList, emptyList);
mailWindow->show();
}
void KeyhoteeMainWindow::shareContact(QList<const Contact*>& contacts)
{
assert (contacts.size());
MailEditorMainWindow* mailWindow = new MailEditorMainWindow(this, *_addressbook_model,
_connectionProcessor, true);
for(const Contact* contact : contacts)
{
mailWindow->addContactCard (*contact);
}
mailWindow->show();
}
ContactGui* KeyhoteeMainWindow::getContactGui(int contact_id)
{
auto itr = _contact_guis.find(contact_id);
if (itr != _contact_guis.end() )
return &(itr->second);
return nullptr;
}
void KeyhoteeMainWindow::openContactGui(int contact_id)
{
ui->actionShow_details->setEnabled (true);
if (contact_id == -1) // TODO: define -1 as AddressBookID
{
showContacts();
return;
}
else
{
auto contact_gui = createContactGuiIfNecessary(contact_id);
showContactGui(*contact_gui);
contact_gui->updateTreeItemDisplay();
_is_curr_contact_blocked = contact_gui->_view->getContact().isBlocked();
_is_curr_contact_own = contact_gui->_view->getContact().isOwn();
}
}
ContactGui* KeyhoteeMainWindow::createContactGuiIfNecessary(int contact_id)
{
ContactGui* contact_gui = getContactGui(contact_id);
if (!contact_gui)
{
createContactGui(contact_id);
contact_gui = getContactGui(contact_id);
}
//DLNFIX not too sure we're doing everything in this call that's necessary
// (or that this is the proper call to do it). Anywyas, this is quick fix
// by yuvaraj that should be replaced eventually once we get a proper
// signal emitted when registration occurs for a displayed KeyhoteeId.
contact_gui->_view->checkKeyhoteeIdStatus();
contact_gui->_view->checkSendMailButton();
if(_currentMailbox != nullptr)
_currentMailbox->checkSendMailButtons();
return contact_gui;
}
void KeyhoteeMainWindow::createContactGui(int contact_id)
{
//DLNFIX2 maybe cleanup/refactor ContactGui construction later
auto new_contact_item = new QTreeWidgetItem(_contacts_root,
(QTreeWidgetItem::ItemType)ContactItem);
new_contact_item->setData(0, ContactIdRole, contact_id);
auto view = new ContactView(ui->widget_stack);
QObject::connect(this, SIGNAL(checkSendMailSignal()),
view, SLOT(checkSendMailButton()));
//add new contactGui to map
_contact_guis[contact_id] = ContactGui(new_contact_item, view);
view->setAddressBook(_addressbook_model);
const Contact& contact = _addressbook_model->getContactById(contact_id);
view->setContact(contact);
ui->contacts_page->addContactView(*view);
}
void KeyhoteeMainWindow::showContactGui(ContactGui& contact_gui)
{
if (checkSaving())
{
ui->side_bar->setCurrentItem(contact_gui._tree_item);
//ui->widget_stack->setCurrentWidget( contact_gui._view );
ui->widget_stack->setCurrentWidget(ui->contacts_page);
ui->contacts_page->showView(*contact_gui._view);
if (contact_gui.isChatVisible() || contact_gui._unread_msg_count)
contact_gui._view->onChat();
}
}
void KeyhoteeMainWindow::deleteContactGui(int contact_id)
{
ContactGui* contact_gui = getContactGui(contact_id);
if(contact_gui != nullptr)
{
_contacts_root->removeChild(contact_gui->_tree_item);
_contact_guis.erase(contact_id);
if (_currentMailbox != nullptr)
_currentMailbox->checkSendMailButtons();
}
assert(_contact_guis.find(contact_id) == _contact_guis.end());
}
void KeyhoteeMainWindow::createAuthorizationItem(const TAuthorizationMessage& msg,
const TStoredMailMessage& header)
{
AuthorizationView *view = new AuthorizationView(_connectionProcessor, _addressbook_model, msg, header);
connect(view, &AuthorizationView::authorizationStatus, this, &KeyhoteeMainWindow::onUpdateAuthoStatus);
bool add_to_root = false;
QTreeWidgetItem *item = nullptr;
item = findExistSenderItem(header.from_key, add_to_root);
if(add_to_root)
{
AuthorizationView *view_root = new AuthorizationView(_connectionProcessor, _addressbook_model, msg, header);
connect(view_root, &AuthorizationView::authorizationStatus, this, &KeyhoteeMainWindow::onUpdateAuthoStatus);
AuthorizationItem *authorization_root_item = new AuthorizationItem(view_root,
item, (QTreeWidgetItem::ItemType)RequestItem);
authorization_root_item->setIcon(0, QIcon(":/images/request_authorization.png") );
authorization_root_item->setFromKey(header.from_key);
QString full_name = QString::fromStdString(msg.from_first_name);
full_name += " " + QString::fromStdString(msg.from_last_name);
authorization_root_item->setText(0, full_name);
authorization_root_item->setHidden(false);
authorization_root_item->setData(0, Qt::UserRole, false); // 1 child, information for contextmenu
view_root->setOwnerItem(authorization_root_item);
connect(view_root, &AuthorizationView::itemAcceptRequest, this, &KeyhoteeMainWindow::onItemAcceptRequest);
connect(view_root, &AuthorizationView::itemDenyRequest, this, &KeyhoteeMainWindow::onItemDenyRequest);
connect(view_root, &AuthorizationView::itemBlockRequest, this, &KeyhoteeMainWindow::onItemBlockRequest);
item = authorization_root_item;
}
AuthorizationItem *authorization_item = new AuthorizationItem(view,
item, (QTreeWidgetItem::ItemType)RequestItem);
authorization_item->setIcon(0, QIcon(":/images/request_authorization.png") );
authorization_item->setFromKey(header.from_key);
QDateTime dateTime;
/// \warning time_since_epoch retrieves time in microseconds, but QT expects it in miliseconds.
dateTime.setMSecsSinceEpoch(header.from_sig_time.time_since_epoch().count()/1000);
authorization_item->setText(0, dateTime.toString(Qt::SystemLocaleShortDate));
authorization_item->setHidden(false);
view->setOwnerItem(authorization_item);
connect(view, &AuthorizationView::itemAcceptRequest, this, &KeyhoteeMainWindow::onItemAcceptRequest);
connect(view, &AuthorizationView::itemDenyRequest, this, &KeyhoteeMainWindow::onItemDenyRequest);
connect(view, &AuthorizationView::itemBlockRequest, this, &KeyhoteeMainWindow::onItemBlockRequest);
ui->widget_stack->addWidget(view);