-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathqweenmainwindow.cpp
More file actions
executable file
·1386 lines (1212 loc) · 47.9 KB
/
qweenmainwindow.cpp
File metadata and controls
executable file
·1386 lines (1212 loc) · 47.9 KB
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
/*
This file is part of Qween.
Copyright (C) 2009-2010 NOSE Takafumi <ahya365@gmail.com>
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 3 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, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, NOSE Takafumi
gives permission to link the code of its release of Qween with the
OpenSSL project's "OpenSSL" library (or with modified versions of it
that use the same license as the "OpenSSL" library), and distribute
the linked executables. You must obey the GNU General Public License
in all respects for all of the code used other than "OpenSSL". 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.
*/
//TODO: 全般的に:ステータスバーに表示をしませう
//TODO: アニメーション
//TODO: タブの並べ替えは振り分け設定ダイアログと連動
#include "qweenmainwindow.h"
#include "ui_qweenmainwindow.h"
#include "aboutdialog.h"
#include "qweensettings.h"
#include "qweentabctrl.h"
#include "settingdialog.h"
#include <QtCore>
#include <QtGui>
#include "urishortensvc.h"
#include "iconmanager.h"
#include "qweenapplication.h"
#include "timelineview.h"
#include "tabsettingsdialog.h"
#include "forwardruledialog.h"
#include "usersmodel.h"
#include "const.h"
#include "xauth.h"
#include "statusbrowser.h"
#include "tabselectdialog.h"
#include "thumbmanager.h"
#include "testingdialog.h"
QweenMainWindow::QweenMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::QweenMainWindow),m_firstShow(true),m_postAfterShorten(false),m_usersModel(NULL),
m_completer(NULL), m_urisvc(NULL), m_xauth(NULL), m_networkMan(NULL), m_idAsUInt64(0), m_in_reply_to_status_id(0), m_newestFriendsStatus(0),m_newestRecvDM(0),m_newestSentDM(0),
m_newestReply(0),m_newestFav(0)
{
ui->setupUi(this);
makeWidgets();
makeConnections();
setupMenus();
setAcceptDrops(true);
settings = QweenSettings::globalSettings();
//ユーザーIDまたはパスワードが無いので設定ダイアログで入力してもらう
if(settings->userid().isEmpty() || settings->password().isEmpty())
{
SettingDialog dlg(this);
if(dlg.exec() != QDialog::Accepted ||
settings->userid().isEmpty() || settings->password().isEmpty())
{
exit(-1); //入力されなかったので終了
}else{
applySettings();
}
}else{
applySettings();
}
restoreGeometry(settings->geometry());
restoreState(settings->windowState());
ui->splitter->restoreState(settings->splitterState());
//TODO: if(outOfScreen()){
//画面内に戻す
//}
//setupWebview
setupTrayIcon();
setupTabs();
setupTimers();
setupTwitter();
}
QweenMainWindow::~QweenMainWindow()
{
delete ui;
m_trayIcon->hide();
if(m_petrelLib)
delete m_petrelLib;
}
void QweenMainWindow::makeWidgets(){
m_petrelLib = new Petrel();
m_timelineTimer = new QTimer(this);
m_DMTimer = new QTimer(this);
m_replyTimer = new QTimer(this);
m_favTimer = new QTimer(this);
m_fetchAnimTimer = new QTimer(this);
m_trayIcon = new QSystemTrayIcon(this);
m_postModeMenu = new QMenu(this);
m_iconMenu = new QMenu(this);
tabWidget = new QweenTabCtrl(ui->splitter);
tabWidget->setTabPosition(QTabWidget::South);
tabWidget->setFocusPolicy(Qt::NoFocus);
ui->splitter->insertWidget(0,tabWidget);
ui->splitter->setStretchFactor(0, 1);
ui->splitter->setStretchFactor(1, 0);
m_usersModel = new UsersModel(QweenApplication::iconManager(), this);
m_proxyModel = new QSortFilterProxyModel(this);
m_proxyModel->setDynamicSortFilter(true);
m_proxyModel->setSourceModel(m_usersModel);
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
m_proxyModel->sort(0, Qt::AscendingOrder);
m_completer = new QCompleter(m_proxyModel, this);
ui->statusText->setCompleter(m_completer);
m_networkMan = new QNetworkAccessManager(this);
ui->lblNameId->setOpenExternalLinks(true);
}
void QweenMainWindow::applySettings(){
ui->statusText->setStyleSheet(settings->inputStyle());
ui->statusText->setRequireCtrlOnEnter(settings->requireCtrlOnEnter());
ui->actMultipleLine->setChecked(settings->multipleLine());
ui->statusText->setMultipleLine(settings->multipleLine());
int size = settings->iconSize()*8 + 8;
if(size==8) size=0;
for(int i=0;i<tabWidget->count();i++){
TimelineView* view = tabWidget->timelineView(i);
view->setIconSize(QSize(size,size));
}
tabWidget->setManageUnread(settings->manageUnread());
updateWindowTitle();
updateTrayIconTitle();
setupTimers();
}
bool QweenMainWindow::isNetworkAvailable(){
foreach(const QNetworkInterface &intf, QNetworkInterface::allInterfaces()) {
if (!intf.isValid()) continue;
if (intf.flags() & QNetworkInterface::IsLoopBack) continue;
if (intf.hardwareAddress().isEmpty()) continue;
if (intf.flags() & QNetworkInterface::IsUp && intf.flags() & QNetworkInterface::IsRunning ) return true;
}
return false;
}
void QweenMainWindow::save(){
QFile tabSettings(QweenApplication::profileDir()+"/tabs.xml");
tabSettings.open(QFile::WriteOnly);
tabWidget->saveState(&tabSettings);
settings->setMultipleLine(ui->statusText->multipleLine());
settings->setGeometry(saveGeometry());
settings->setWindowState(saveState());
settings->setSplitterState(ui->splitter->saveState());
settings->save();
}
void QweenMainWindow::setupMenus()
{
//TODO: 実際にTreeView内でCtrl+Cが機能するようにする
ui->actCopyStot->setText(ui->actCopyStot->text()+"\tCtrl+C");
ui->actCopyIdUri->setText(ui->actCopyIdUri->text()+"\tCtrl+Shift+C");
m_actDivideUriFromZenkaku = new QAction(QIcon(), tr("URLからの全角文字列の切り離し"), this);
m_actDivideUriFromZenkaku->setCheckable(true);
connect(m_actDivideUriFromZenkaku, SIGNAL(triggered(bool)),
this, SLOT(OnActDivideUriFromZenkakuToggled(bool)));
m_postModeMenu->addAction(m_actDivideUriFromZenkaku);
m_actAvoidApiCommand = new QAction(QIcon(), tr("APIコマンドを回避する"), this);
m_actAvoidApiCommand->setCheckable(true);
connect(m_actAvoidApiCommand, SIGNAL(triggered(bool)), this, SLOT(OnActAvoidApiCommandToggled(bool)));
m_postModeMenu->addAction(m_actAvoidApiCommand);
m_actAutoShortenUri = new QAction(QIcon(), tr("自動的にURLを短縮する"), this);
m_actAutoShortenUri->setCheckable(true);
connect(m_actAutoShortenUri, SIGNAL(triggered(bool)), this, SLOT(OnActAutoShortenUriToggled(bool)));
m_postModeMenu->addAction(m_actAutoShortenUri);
m_actReplaceZenkakuSpace = new QAction(QIcon(), tr("全角スペースを半角スペースにする"), this);
m_actReplaceZenkakuSpace->setCheckable(true);
connect(m_actReplaceZenkakuSpace, SIGNAL(triggered(bool)), this, SLOT(OnActReplaceZenkakuSpaceToggled(bool)));
m_postModeMenu->addAction(m_actReplaceZenkakuSpace);
ui->postButton->setMenu(m_postModeMenu);
//ui->hashTagButton->addAction(new QAction(QIcon(), tr("test"), this));
m_actShowIconInBrowser = new QAction(QIcon(), tr("画像をブラウザで表示"), this);
connect(m_actShowIconInBrowser, SIGNAL(triggered()),
this, SLOT(OnShowIconInBrowser()));
m_iconMenu->addAction(m_actShowIconInBrowser);
m_actSaveIcon = new QAction(QIcon(), tr("アイコンを保存..."), this);
connect(m_actSaveIcon, SIGNAL(triggered()),
this, SLOT(OnSaveIcon()));
m_iconMenu->addAction(m_actSaveIcon);
ui->userIconLabel->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->userIconLabel, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(OnIconContextMenu(const QPoint &)));
}
void QweenMainWindow::setupTabs(){
QFile tabSettings(QweenApplication::profileDir()+"/tabs.xml");
if(tabSettings.exists()) tabWidget->restoreState(&tabSettings);
else tabWidget->restoreState(NULL);
}
void QweenMainWindow::setupTimers(){
m_timelineTimer->setInterval(settings->tlUpdateIntv()*1000);
m_timelineTimer->start();
m_DMTimer->setInterval(settings->dmUpdateIntv()*1000);
m_DMTimer->start();
//m_DMTimer->stop();
m_replyTimer->setInterval(settings->replyUpdateIntv()*1000);
m_replyTimer->start();
//m_replyTimer->stop();
m_favTimer->setInterval(600*1000);
m_favTimer->start();
//m_favTimer->stop();
/*m_fetchAnimTimer->setInterval(85);
m_fetchAnimTimer->start();*/
}
void QweenMainWindow::setupTrayIcon(){
m_trayIcon->setIcon(QIcon(":/res/qween_icon.png"));
setWindowIcon(QIcon(":/res/qween_icon.png"));
m_trayIcon->setContextMenu(ui->menu_File);
m_trayIcon->show();
}
void QweenMainWindow::setupTwitter(){
m_petrelLib->abort();
//m_twitLib->Logout(); TODO: EndSessionで置き換える
m_firstFetchFav = m_firstFetchDmSent = m_firstFetchDmRecv = m_firstFetchReply = m_firstFetch = settings->markAsRead1stFetch();
if(settings->useXAuth() && !settings->token().isEmpty()){
m_petrelLib->setToken(settings->token(),settings->tokenSecret());
}else{
m_petrelLib->setLoginInfo(settings->userid(), settings->password(),settings->useXAuth());
}
}
void QweenMainWindow::makeConnections(){
//MainMenu
connect(ui->actExit, SIGNAL(triggered()),
this, SLOT(OnExit()));
connect(ui->actJumpToUnread, SIGNAL(triggered()),
tabWidget, SLOT(jumpToUnread()));
connect(ui->actSetReadAll, SIGNAL(triggered()),
tabWidget, SLOT(setReadAll()));
//PostMode
connect(m_postModeMenu, SIGNAL(aboutToShow()),
this, SLOT(OnPostModeMenuOpen()));
//StatusText->postButton
connect(ui->statusText,SIGNAL(returnPressed()),
ui->postButton,SLOT(click()));
//StatusBrowser
connect(ui->textBrowser,SIGNAL(followCommand(QString)),
this, SLOT(OnFollowCommand(QString)));
connect(ui->textBrowser,SIGNAL(removeCommand(QString)),
this, SLOT(OnRemoveCommand(QString)));
connect(ui->textBrowser,SIGNAL(friendshipCommand(QString)),
this, SLOT(OnFriendshipCommand(QString)));
//TrayIcon
connect(m_trayIcon, SIGNAL(messageClicked()), this, SLOT(OnMessageClicked()));
connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(OnIconActivated(QSystemTrayIcon::ActivationReason)));
//Timers
connect(m_timelineTimer, SIGNAL(timeout()), this, SLOT(OnTimelineTimerTimeout()));
connect(m_DMTimer, SIGNAL(timeout()), this, SLOT(OnDmTimerTimeout()));
connect(m_replyTimer, SIGNAL(timeout()), this, SLOT(OnReplyTimerTimeout()));
connect(m_favTimer, SIGNAL(timeout()), this, SLOT(OnFavTimerTimeout()));
//Twitter
connect(m_petrelLib, SIGNAL(homeTimelineReceived(statuses_t&)),
this, SLOT(OnHomeTimelineReceived(statuses_t&)));
connect(m_petrelLib, SIGNAL(verifyCredentialsReceived(user_t&)),
this, SLOT(OnVerifyCredentialsReceived(user_t&)));
connect(m_petrelLib, SIGNAL(sentDirectMessagesReceived(direct_messages_t&)),
this, SLOT(OnSentDirectMessagesReceived(direct_messages_t&)));
connect(m_petrelLib, SIGNAL(directMessagesReceived(direct_messages_t&)),
this, SLOT(OnDirectMessagesReceived(direct_messages_t&)));
connect(m_petrelLib, SIGNAL(updateReceived(status_t&)),
this, SLOT(OnUpdateReceived(status_t&)));
connect(m_petrelLib, SIGNAL(rateLimitStatusReceived(hash_t&)),
this, SLOT(OnRateLimitStatusReceived(hash_t&)));
connect(m_petrelLib, SIGNAL(mentionsReceived(statuses_t&)),
this, SLOT(OnMentionsReceived(statuses_t&)));
connect(m_petrelLib, SIGNAL(userTimelineReceived(statuses_t&)),
this, SLOT(OnUserTimelineReceived(statuses_t&)));
connect(m_petrelLib, SIGNAL(showFriendshipsReceived(relationship_t&)),
this, SLOT(OnShowFriendshipsReceived(relationship_t&)));
connect(m_petrelLib, SIGNAL(showUsersReceived(user_t&)),
this, SLOT(OnShowUserDetailsReceived(user_t&)));
connect(m_petrelLib, SIGNAL(createFriendshipReceived(user_t&)),
this, SLOT(OnCreateFriendshipReceived(user_t&)));
connect(m_petrelLib, SIGNAL(destroyFriendshipReceived(user_t&)),
this, SLOT(OnDestroyFriendshipReceived(user_t&)));
connect(m_petrelLib, SIGNAL(createFavoriteReceived(status_t&)),
this, SLOT(OnCreateFavoriteReceived(status_t&)));
connect(m_petrelLib, SIGNAL(destroyFavoriteReceived(status_t&)),
this, SLOT(OnDestroyFavoriteReceived(status_t&)));
connect(m_petrelLib, SIGNAL(favoritesReceived(statuses_t&)),
this, SLOT(OnFavoritesReceived(statuses_t&)));
connect(m_petrelLib, SIGNAL(error(int,QString)),
this, SLOT(OnError(int,QString)));
//Tab
connect(tabWidget, SIGNAL(itemSelected(Twitter::TwitterItem)),
this, SLOT(OnItemSelected(Twitter::TwitterItem)));
connect(tabWidget, SIGNAL(favorite()),
this, SLOT(on_actFavorite_triggered()));
connect(tabWidget, SIGNAL(reply()),
this, SLOT(on_actAtReply_triggered()));
connect(tabWidget, SIGNAL(dm()),
this, SLOT(on_actSendDM_triggered()));
//StatusText
connect(ui->statusText, SIGNAL(uriShorteningFinished()),
this, SLOT(OnUriShorteningFinished()));
connect(ui->statusText, SIGNAL(textChanged()),
this, SLOT(on_statusText_textChanged(QString)));
//StatusBrowser
connect(QweenApplication::thumbManager(), SIGNAL(thumbDownloaded(QString)),
ui->textBrowser, SLOT(thumbFetched(QString)));
//Icon
connect(m_networkMan, SIGNAL(finished(QNetworkReply*)),
this, SLOT(OnIconOriginalImageDownloaded(QNetworkReply*)));
}
void QweenMainWindow::OnExit()
{
save();
QweenApplication::exit();
}
void QweenMainWindow::OnHomeTimelineReceived(statuses_t& s){
if(s.status.count()==0) return;
QString popupText;
QString title(tr("新着 ") + QString::number(s.status.count()) + tr("件\n"));
if(settings->showUserInTitle()) title.prepend(m_petrelLib->userid()+" - ");
foreach(QSharedPointer<status_t> ptr, s.status){
Twitter::TwitterItem item(Twitter::Status, ptr, HOME_TIMELINE, false);
if(m_firstFetch) item.setRead(true);
if(m_newestFriendsStatus < item.id()) m_newestFriendsStatus = item.id();
switch(settings->notifyBaloonName()){
case 0:
popupText.append(QString("%1\n").arg(item.status()));
break;
case 1:
popupText.append(QString("%1 : %2\n").arg(item.screenName(), item.status()));
break;
case 2:
popupText.append(QString("%1 : %2\n").arg(item.userName(), item.status()));
break;
}
if(!m_usersModel->userExists(item.userId()))
m_usersModel->appendItem(item);
tabWidget->addItem(item);
}
m_firstFetch = false;
updateWindowTitle();
//TODO: dm, reply, sound
//バルーン・サウンドは最初は抑制するようだ
//設定項目があるのでそこを見るべし
if(settings->notifyOnlyMinimized() && !isMinimized() && isVisible()) return;
m_trayIcon->showMessage(title, popupText, QSystemTrayIcon::MessageIcon(QSystemTrayIcon::Information),
5 * 1000);
}
void QweenMainWindow::OnVerifyCredentialsReceived(user_t& user){
if(user.id!=0){
settings->setToken(m_petrelLib->token());
settings->setTokenSecret(m_petrelLib->tokenSecret());
tabWidget->setMyId(user.id);
m_idAsUInt64 = user.id;
m_petrelLib->homeTimeline(m_newestFriendsStatus,0,20,0);
OnDmTimerTimeout();
OnReplyTimerTimeout();
OnFavTimerTimeout();
}
}
void QweenMainWindow::OnSentDirectMessagesReceived(direct_messages_t& direct_messages){
foreach(QSharedPointer<direct_message_t> ptr, direct_messages.direct_message){
Twitter::TwitterItem item(Twitter::DirectMessage, ptr, SENT_DIRECT_MESSAGES, false);
if(m_firstFetchDmSent) item.setRead(true);
if(m_newestSentDM < item.id()) m_newestSentDM = item.id();
tabWidget->addItem(item);
}
m_firstFetchDmSent = false;
}
void QweenMainWindow::OnDirectMessagesReceived(direct_messages_t& direct_messages){
foreach(QSharedPointer<direct_message_t> ptr, direct_messages.direct_message){
Twitter::TwitterItem item(Twitter::DirectMessage, ptr, DIRECT_MESSAGES, false);
if(m_firstFetchDmRecv) item.setRead(true);
if(m_newestRecvDM < item.id()) m_newestRecvDM = item.id();
if(!m_usersModel->userExists(item.userId()))
m_usersModel->appendItem(item);
tabWidget->addItem(item);
}
m_firstFetchDmRecv = false;
}
void QweenMainWindow::OnUpdateReceived(status_t& status){
ui->statusText->setPlainText("");
ui->statusText->setEnabled(true);
ui->postButton->setEnabled(true);
m_in_reply_to_status_id = 0;
m_latestMyPost = status.text;
QSharedPointer<status_t> s(new status_t(status));
tabWidget->addItem(Twitter::TwitterItem(Twitter::Status, s, UPDATE, false));
updateWindowTitle();
}
void QweenMainWindow::OnRateLimitStatusReceived(hash_t& hash){
QMessageBox::information(this,tr("API情報"),
tr("上限: %1\n残数: %2\nリセット日時: %3\n")
.arg(hash.hourly_limit,
hash.remaining_hits,
hash.reset_time));
}
void QweenMainWindow::OnMentionsReceived(statuses_t& s){
foreach(QSharedPointer<status_t> ptr, s.status){
Twitter::TwitterItem item(Twitter::Status, ptr, MENTIONS, false);
if(m_firstFetchReply) item.setRead(true);
if(m_newestReply < item.id()) m_newestReply = item.id();
if(!m_usersModel->userExists(item.userId()))
m_usersModel->appendItem(item);
tabWidget->addItem(item);
}
m_firstFetchReply = false;
}
void QweenMainWindow::OnFavoritesReceived(statuses_t& s){
foreach(QSharedPointer<status_t> ptr, s.status){
Twitter::TwitterItem item(Twitter::Status, ptr, FAVORITES, false);
if(m_firstFetchFav) item.setRead(true);
if(m_newestFav < item.id()) m_newestFav = item.id();
if(!m_usersModel->userExists(item.userId()))
m_usersModel->appendItem(item);
tabWidget->addItem(item);
}
m_firstFetchFav = false;
}
void QweenMainWindow::OnUserTimelineReceived(statuses_t& s){
QSharedPointer<status_t> st = s.status.takeFirst();
if(!st.isNull())
QMessageBox::information(this,tr("@twj の最新のTweet"),st->text);
}
void QweenMainWindow::OnShowFriendshipsReceived(relationship_t& r){
QString arrow;
QString msg;
if(r.source->followed_by && r.source->following){
arrow = r.source->screen_name + " <-> " + r.target->screen_name;
}else if(r.source->followed_by){
arrow = r.source->screen_name + " <- " + r.target->screen_name;
}else if(r.source->following){
arrow = r.source->screen_name + " -> " + r.target->screen_name;
}else{
QMessageBox::information(this, tr("友達関係"),
tr("フォロー関係はありません。"));
return;
}
QMessageBox::information(this, tr("友達関係"), arrow);
}
void QweenMainWindow::OnShowUserDetailsReceived(user_t& user){
QMessageBox::information(this, tr("プロファイル情報"),
tr("Following : %1\n"
"Followers : %2\n"
"Statuses count : %3\n"
"Location : %4\n"
"Bio : %5")
.arg(QString::number(user.friends_count),
QString::number(user.followers_count),
QString::number(user.statuses_count),
user.location,
user.description));
}
void QweenMainWindow::OnCreateFriendshipReceived(user_t& user){
if(!user.screen_name.isEmpty())
QMessageBox::information(this, "Follow", tr("@%1 をFollow開始しました。").arg(user.screen_name));
//TODO: エラーの場合は失敗とちゃんと言う!
}
void QweenMainWindow::OnDestroyFriendshipReceived(user_t& user){
if(!user.screen_name.isEmpty())
QMessageBox::information(this, "Remove", tr("@%1 をRemoveしました。").arg(user.screen_name));
}
void QweenMainWindow::OnCreateFavoriteReceived(status_t& status){
quint64 id = status.id;
tabWidget->favorited(id,true);
}
void QweenMainWindow::OnDestroyFavoriteReceived(status_t& status){
quint64 id = status.id;
tabWidget->favorited(id,false);
}
void QweenMainWindow::OnError(int role, const QString& msg){
switch(role){
case UPDATE:
{
ui->statusText->setEnabled(true);
ui->postButton->setEnabled(true);
break;
}
default:
QMessageBox::information(this,"error",msg);
break;
}
}
void QweenMainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
case QEvent::WindowStateChange:
if(settings->minimizeToTray() && isMinimized() && isVisible()){
hide();
}
break;
default:
break;
}
}
void QweenMainWindow::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event)
if (settings->minimizeOnClose()) {
hide();
event->ignore();
}else{
save();
}
}
void QweenMainWindow::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat("text/plain"))
event->acceptProposedAction();
}
void QweenMainWindow::dropEvent(QDropEvent *event)
{
ui->statusText->setPlainText(ui->statusText->toPlainText() + event->mimeData()->text());
event->acceptProposedAction();
}
void QweenMainWindow::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
if(isNetworkAvailable() && m_firstShow){
//m_petrelLib->verifyCredentials();
m_firstShow = false;
//TODO: version check
/*
if(settings->checkVersionOnStartup()){
checkNewVersion();
}
*/
}
}
void QweenMainWindow::on_actOptions_triggered()
{
SettingDialog dlg(this);
//bool chgUseApi = false;
if(dlg.exec() == QDialog::Accepted){
applySettings();
if(dlg.loginInfoChanged()){
setupTwitter();
//m_petrelLib->verifyCredentials();
}
}
}
void QweenMainWindow::on_actAboutQt_triggered()
{
QMessageBox::aboutQt(this);
}
void QweenMainWindow::on_actAboutQween_triggered()
{
AboutDialog dlg(this);
dlg.exec();
}
void QweenMainWindow::doPost(){
QString postText = ui->statusText->toPlainText().trimmed();
//空なら戻る
if(postText.isEmpty()){
//TODO: refresh();
return;
}
//整形
//avoid API command
QRegExp apirx("^[+\\-\\[\\]\\s\\\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\\*)([+\\-\\[\\]\\s\\\\.,*/(){}^~|='&%$#\"<>?]+|$)");
//divide between Zenkaku and URI
QRegExp("https?:\\/\\/[-_.!~*'()a-zA-Z0-9;\\/?:\\@&=+\\$,%#]+");
//Replace a Zenkaku space with two spaces
//フッタを付加するか?
bool isRemoveFooter;
isRemoveFooter = false;
//TODO: 複数行かつEnterで投稿する場合,Ctrlが押されていたらfooterをつけない
if(!isRemoveFooter && postText.startsWith("RT @")){
isRemoveFooter = true;
}
/*If (StatusText.Text.StartsWith("D ")) OrElse isRemoveFooter Then
args.status = StatusText.Text.Trim
ElseIf SettingDialog.UseRecommendStatus() Then
' 推奨ステータスを使用する
args.status = StatusText.Text.Trim() + SettingDialog.RecommendStatusText
Else
' テキストボックスに入力されている文字列を使用する
args.status = StatusText.Text.Trim() + " " + SettingDialog.Status.Trim()
End If*/
ui->statusText->setEnabled(false);
ui->postButton->setEnabled(false);
m_petrelLib->update(postText + tr(" ") + settings->statusSuffix(),m_in_reply_to_status_id,"",""); // TODO:クライアント名"Qween"を付加 OAuth対応後
//TODO: Outputz対応?
}
void QweenMainWindow::postOutputz(const QString& str){
QString entryPoint("http://outputz.com/api/post");
/*
* key : 設定ページに表示されている復活の呪文(他人に知られていはいけない)
* uri : アウトプットの URI
* size : アウトプットの文字数
*/
QString key;
QString uri("http://twitter.com/");
int size = str.length();
}
void QweenMainWindow::makeReplyOrDirectStatus(bool isAuto, bool isReply, bool isAll){
Q_UNUSED(isAuto)
Q_UNUSED(isReply)
Q_UNUSED(isAll)
}
void QweenMainWindow::OnUriShorteningFinished(){
if(m_postAfterShorten){
m_postAfterShorten = false;
doPost();
}
}
void QweenMainWindow::on_postButton_clicked()
{
if(settings->uriAutoShorten()){
m_postAfterShorten = true;
ui->statusText->shortenUri();
}else{
doPost();
}
}
void QweenMainWindow::OnTimelineTimerTimeout()
{
//TODO: if not IsNetworkAvailable() exit
m_petrelLib->homeTimeline(m_newestFriendsStatus,0,200,0);
}
void QweenMainWindow::OnDmTimerTimeout(){
//TODO: if not IsNetworkAvailable() exit
m_petrelLib->sentDirectMessages(m_newestSentDM,0,0,1);
m_petrelLib->directMessages(m_newestRecvDM,0,0,1);
}
void QweenMainWindow::OnReplyTimerTimeout(){
//TODO: if not IsNetworkAvailable() exit
m_petrelLib->mentions(m_newestReply,0,0,0);
}
void QweenMainWindow::OnFavTimerTimeout(){
//TODO: if not IsNetworkAvailable() exit
m_petrelLib->favorites(0,0);
}
void QweenMainWindow::OnItemSelected(const Twitter::TwitterItem &item)
{
m_detailItem = item;
QString status(item.status());
QRegExp linkrx(LINK_RX_DATA);
int pos=0;
while ((pos = linkrx.indexIn(status, pos)) != -1) {
QStringList list = linkrx.capturedTexts();
QString str;
QString anchor;
int length;
if (list[1] != ""){ //hashtag
str = list[1];
if (str.at(0) != '#'){
str.remove(0,1);
pos++;
}
QString str2 = str;
str2.remove(0,1);
QUrl url("http://twitter.com/");
url.setFragment("search?q=%23"+str2);
anchor = QString("<a href=\"%2\">%1</a>")
.arg(str,url.toString());
length = str.length();
}
else if(list[2] != ""){ //reply
str = list[2];
if (str.at(0) == '@'){
str.remove(0,1);
pos++;
}else{
str.remove(0,2);
pos+=2;
}
anchor = QString("<a href=\"http://twitter.com/%1\">%1</a>").arg(str);
length = str.length();
}
else if(list[3] != ""){ //URI
str = list[3];
QString content(str);
if(QweenApplication::thumbManager()->isThumbAvailable(str)){
content = QString("<img src=\"%1\">").arg(
QUrl::fromLocalFile(
QweenApplication::thumbManager()->getThumbFilePath(str))
.toString());
}else{
QweenApplication::thumbManager()->fetchThumb(str);
}
anchor = QString("<a href=\"%1\">%2</a>").arg(str,content);
length = str.length();
}
status.replace(pos, length, anchor);
pos += anchor.length();
}
switch(item.type()){
case Twitter::Status:
{
if(item.isProtected()){
status.prepend("<img src=\":/res/lock.png\">");
}
ui->lblNameId->setText(QString("<a href=\"http://twitter.com/%0\">%0</a>/%1").arg(item.screenName()).arg(item.userName()));
ui->lblUpdateDatetime->setText(item.createdAt().toString());
break;
}
case Twitter::DirectMessage:
{
ui->lblNameId->setText("DM: " + item.screenName() + " -> " + item.replyTo());
ui->lblUpdateDatetime->setText(item.createdAt().toString());
break;
}
default:
break;
}
ui->textBrowser->setHtml(tr("<html><body style=\"%1\">")
.arg(settings->statusViewStyle()) +
status + tr("</body></html>"));
if(QweenApplication::iconManager()->isIconAvailable(item.userId())){
QIcon icon(QweenApplication::iconManager()->getIcon(item.userId()));
ui->userIconLabel->setPixmap(icon.pixmap(50,50,QIcon::Normal,QIcon::On));
}else{
ui->userIconLabel->setPixmap(QPixmap(50,50));
QweenApplication::iconManager()->fetchIcon(item.userId(), item.iconUri());
}
ui->userIconLabel->repaint();
updateWindowTitle();
}
void QweenMainWindow::OnPostModeMenuOpen(){
m_actAutoShortenUri->setChecked(settings->uriAutoShorten());
m_actAvoidApiCommand->setChecked(settings->avoidApiCmd());
m_actDivideUriFromZenkaku->setChecked(settings->divideUriFromZenkaku());
m_actReplaceZenkakuSpace->setChecked(settings->replaceZenkakuSpace());
}
void QweenMainWindow::OnUriShortened(const QString& src, const QString& dest){
Q_UNUSED(src)
QMessageBox::information(this, "", dest);
}
void QweenMainWindow::OnIconDownloaded(quint64 userid, const QIcon &icon){
Q_UNUSED(userid)
ui->userIconLabel->setPixmap(icon.pixmap(50,50,QIcon::Normal,QIcon::On));
}
void QweenMainWindow::OnIconContextMenu(const QPoint &pt){
m_iconMenu->exec(ui->userIconLabel->mapToGlobal(pt));
}
void QweenMainWindow::OnShowIconInBrowser(){
if(m_detailItem.type()!=Twitter::Undefined){
QString uri(m_detailItem.iconUri());
QRegExp rx("_normal(\\..+)$");
if(rx.indexIn(uri,0)>=0){
uri.replace(rx,rx.cap(1));
QDesktopServices::openUrl(QUrl(uri));
}
}
}
void QweenMainWindow::OnSaveIcon(){
if(m_detailItem.type()!=Twitter::Undefined){
QString uri(m_detailItem.iconUri());
QRegExp rx("_normal(\\..+)$");
if(rx.indexIn(uri,0)>=0){
uri.replace(rx,rx.cap(1));
int pos = uri.lastIndexOf('/');
QString fileName = QFileDialog::getSaveFileName(this, tr("ファイルを保存"),
uri.right(pos+1),
tr("すべてのファイル (*.*)"));
QNetworkRequest req(uri);
req.setAttribute(QNetworkRequest::User, fileName);
m_networkMan->get(req);
}
}
}
void QweenMainWindow::OnIconOriginalImageDownloaded(QNetworkReply* r){
QFile file(r->request().attribute(QNetworkRequest::User).toString());
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
return;
file.write(r->readAll());
file.close();
}
void QweenMainWindow::OnMessageClicked(){
//FIXME: X11環境だと動かないことがある?
this->raise();
this->activateWindow();
}
void QweenMainWindow::OnIconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
if(!this->isVisible()){
this->setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
this->show();
}
break;
case QSystemTrayIcon::MiddleClick:
break;
default:
;
}
}
void QweenMainWindow::on_statusText_textChanged()
{
//Q_UNUSED(string)
int rest = getRestStatusCount(ui->statusText->toPlainText().trimmed());
ui->lblStatusLength->setText(QString("%1").arg(rest));
if(rest < 0){
ui->statusText->setStyleSheet(settings->inputStyle()+" *{color:rgb(255,0,0);}");
}else{
ui->statusText->setStyleSheet(settings->inputStyle());
}
}
int QweenMainWindow::getRestStatusCount(const QString &str, bool footer)
{
int rv = 140 - str.length();
if(footer)
rv -= settings->statusSuffix().length()+1;
if(settings->avoidApiCmd()){
}
if(settings->replaceZenkakuSpace()){
}
if(settings->divideUriFromZenkaku()){
}
//TODO: フッタ機能と連動
//TODO: Shiftキー
//詳しくはTweenのソースを検索 GetRestStatusCount
return rv;
}
void QweenMainWindow::on_actShowUserStatus_triggered()
{
m_petrelLib->showUsers(m_idAsUInt64,0,"");
}
void QweenMainWindow::on_actApiInfo_triggered()
{
m_petrelLib->rateLimitStatus();
}
void QweenMainWindow::on_actQweenHomepage_triggered()
{
//TODO: ブラウザを設定できるようにする
QDesktopServices::openUrl(QUrl("http://qween.tnose.net/"));
}
void QweenMainWindow::on_actionTest_bitly_triggered()
{
if(m_urisvc) delete m_urisvc;
QInputDialog dlg(this);
dlg.setOption(QInputDialog::UseListViewForComboBoxItems, true);
dlg.setComboBoxEditable(false);
QStringList items;
items << tr("bitly") << tr("tinyurl") << tr("twurl") << tr("isgd") << tr("unu");
dlg.setComboBoxItems(items);
dlg.setWindowTitle("test uri shortener");
dlg.setLabelText("Services:");
if (dlg.exec()==QDialog::Accepted && !dlg.textValue().isEmpty()){
m_urisvc = getUriShortenService(dlg.textValue(), this);
if(m_urisvc){
connect(m_urisvc, SIGNAL(uriShortened(QString,QString)),
this, SLOT(OnUriShortened(QString,QString)));
m_urisvc->shortenAsync("http://is2008.is-a-geek.org/");
}
}
}
void QweenMainWindow::on_statusText_returnPressed()
{
//TODO: 複数行対応?やりたくねー
}
void QweenMainWindow::on_actionTest_iconmanager_triggered()
{
QMessageBox::information(this, "", QString("%1").arg(255,0,16));
}
void QweenMainWindow::on_actionTest_icon_triggered()
{
connect(QweenApplication::iconManager(),SIGNAL(iconDownloaded(quint64,QIcon)),
this,SLOT(OnIconDownloaded(quint64,QIcon)));
QweenApplication::iconManager()->fetchIcon(1261519751, "http://a1.twimg.com/profile_images/525002820/CIMG0272_bigger.JPG");
}
void QweenMainWindow::on_actUpdate_triggered()
{
m_petrelLib->homeTimeline(m_newestFriendsStatus,0,20,0);
//TODO: DM だったら SentDM/ReceivedDMを更新, Favも同様
}
void QweenMainWindow::on_actCopyStot_triggered()
{
//TODO: 複数選択可能にする