2
This file is part of Choqok, the KDE micro-blogging client
4
Copyright (C) 2008-2009 Mehrdad Momeny <mehrdad.momeny@gmail.com>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License as
8
published by the Free Software Foundation; either version 2 of
9
the License or (at your option) version 3 or any later version
10
accepted by the membership of KDE e.V. (or its successor approved
11
by the membership of KDE e.V.), which shall act as a proxy
12
defined in Section 14 of version 3 of the license.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, see http://www.gnu.org/licenses/
24
#include "timelinewidget.h"
25
#include "statustextedit.h"
27
#include "statuswidget.h"
28
#include "constants.h"
29
#include "accountmanager.h"
32
#include <KDE/KLocale>
33
#include <KDE/KMessageBox>
35
#include <KDE/KNotification>
36
#include <KFileDialog>
40
TimeLineWidget::TimeLineWidget( const Account &userAccount, QWidget* parent ) :
45
mCurrentAccount = userAccount;
46
twitter = new Backend( &mCurrentAccount, this );
47
latestHomeStatusId = latestReplyStatusId = 0;
49
homeLayout->setDirection( QBoxLayout::TopToBottom );
50
replyLayout->setDirection( QBoxLayout::TopToBottom );
51
txtNewStatus = new StatusTextEdit( this );
52
lblCounter = new QLabel( this );
53
tabs->setCornerWidget( lblCounter, Qt::TopRightCorner );
54
txtNewStatus->setObjectName( "txtNewStatus" );
55
inputFrame->layout()->addWidget( txtNewStatus );
57
btnAttachMedia->setIcon(KIcon("mail-attachment"));
58
attachMediaFrame->hide();
59
if(mCurrentAccount.serviceType() == Account::Twitter) {
60
mediaToAttach.clear();
61
btnClearMedia->setIcon(KIcon("edit-clear"));
62
connect(btnAttachMedia, SIGNAL(clicked(bool)), SLOT(attachMedia()));
63
connect(btnClearMedia, SIGNAL(clicked(bool)), SLOT(clearMedia()));
65
btnAttachMedia->setEnabled(false);
68
// connect ( toggleArrow, SIGNAL ( clicked() ), this, SLOT ( toggleTwitFieldVisible() ) );
69
connect( txtNewStatus, SIGNAL( charsLeft( int ) ), this, SLOT( checkNewStatusCharactersCount( int ) ) );
70
connect( txtNewStatus, SIGNAL( returnPressed( QString& ) ), this, SLOT( postStatus( QString& ) ) );
71
connect( txtNewStatus, SIGNAL( cleared() ), this, SLOT( txtNewStatusCleared() ) );
72
connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( aboutQuit() ) );
73
QTimer::singleShot( 0, this, SLOT( initObjects() ) );
76
TimeLineWidget::~TimeLineWidget()
81
void TimeLineWidget::aboutQuit()
84
AccountManager::self()->saveFriendsList( mCurrentAccount.alias(), friendsList );
85
saveStatuses( AccountManager::generateStatusBackupFileName( mCurrentAccount.alias(), Backend::HomeTimeLine ),
86
listHomeStatus.values() );
87
saveStatuses( AccountManager::generateStatusBackupFileName( mCurrentAccount.alias(), Backend::ReplyTimeLine ),
88
listReplyStatus.values() );
89
saveStatuses( AccountManager::generateStatusBackupFileName( mCurrentAccount.alias(), Backend::InboxTimeLine ),
90
listInboxStatus.values() );
91
saveStatuses( AccountManager::generateStatusBackupFileName( mCurrentAccount.alias(), Backend::OutboxTimeLine ),
92
listOutboxStatus.values() );
96
void TimeLineWidget::initObjects()
100
txtNewStatus->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
101
txtNewStatus->setTabChangesFocus( true );
102
btnReloadFriends->setIcon( KIcon( "view-refresh" ) );
103
connect( btnReloadFriends, SIGNAL( clicked( bool ) ), this, SLOT( reloadFriendsList() ) );
106
counterF.setBold( true );
107
counterF.setPointSize( 12 );
108
lblCounter->setFont( counterF );
109
checkNewStatusCharactersCount( 140 );
111
connect( twitter, SIGNAL( homeTimeLineReceived( QList< Status >& ) ),
112
this, SLOT( homeTimeLinesReceived( QList< Status >& ) ) );
113
connect( twitter, SIGNAL( replyTimeLineReceived( QList< Status >& ) ),
114
this, SLOT( replyTimeLineReceived( QList< Status >& ) ) );
115
connect( twitter, SIGNAL( directMessagesReceived( QList< Status >& ) ),
116
this, SLOT( directMessagesReceived( QList< Status >& ) ) );
117
connect( twitter, SIGNAL( outboxMessagesReceived( QList< Status >& ) ),
118
this, SLOT( outboxMessagesReceived( QList< Status >& ) ) );
119
connect( twitter, SIGNAL( sigPostNewStatusDone( bool ) ),
120
this, SLOT( postingNewStatusDone( bool ) ) );
121
connect( twitter, SIGNAL( sigFavoritedDone( bool ) ),
122
this, SLOT( requestFavoritedDone( bool ) ) );
123
connect( twitter, SIGNAL( sigDestroyDone( bool ) ),
124
this, SLOT( requestDestroyDone( bool ) ) );
125
connect( twitter, SIGNAL( sigError( const QString& ) ),
126
this, SLOT( error( const QString& ) ) );
127
connect( twitter, SIGNAL( friendsListed( const QStringList& ) ),
128
this, SLOT( friendsListed( const QStringList& ) ) );
129
connect( twitter, SIGNAL( followersListed( const QStringList& ) ),
130
this, SLOT( friendsListed( const QStringList& ) ) );
132
replyToStatusId = unreadStatusCount = unreadStatusInReply = unreadStatusInHome =
133
unreadStatusInInbox = unreadStatusInOutbox = latestInboxStatusId =
134
latestOutboxStatusId = 0;
136
setTabOrder( chkDMessage, comboFriendList );
137
setTabOrder( comboFriendList, btnReloadFriends );
138
setTabOrder( btnReloadFriends, txtNewStatus );
139
setTabOrder( txtNewStatus, chkDMessage );
141
loadConfigurations();
142
txtNewStatus->setFocus( Qt::OtherFocusReason );
146
void TimeLineWidget::checkNewStatusCharactersCount( int numOfChars )
148
if ( numOfChars < 0 ) {
149
lblCounter->setStyleSheet( "QLabel {color: red;}" );
150
} else if ( numOfChars < 30 ) {
151
lblCounter->setStyleSheet( "QLabel {color: rgb(242, 179, 19);}" );
153
lblCounter->setStyleSheet( "QLabel {color: green;}" );
156
if ( numOfChars == 140 ) {
157
txtNewStatus->setMaximumHeight( 28 );
158
lblCounter->setVisible(false);
160
txtNewStatus->setMaximumHeight( 80 );
161
lblCounter->setVisible(true);
164
lblCounter->setText( KGlobal::locale()->formatNumber( numOfChars, 0 ) );
167
void TimeLineWidget::settingsChanged()
170
setDefaultDirection();
171
twitter->settingsChanged();
173
foreach(StatusWidget * s,listHomeStatus)
175
foreach(StatusWidget * s,listInboxStatus)
177
foreach(StatusWidget * s,listOutboxStatus)
179
foreach(StatusWidget * s,listReplyStatus)
183
void TimeLineWidget::updateTimeLines()
186
twitter->requestTimeLine( latestHomeStatusId, Backend::HomeTimeLine );
187
twitter->requestTimeLine( latestReplyStatusId, Backend::ReplyTimeLine );
188
twitter->requestDMessages( latestInboxStatusId, Backend::Inbox );
189
twitter->requestDMessages( latestOutboxStatusId, Backend::Outbox );
191
if ( latestHomeStatusId == 0 || latestReplyStatusId == 0 )
196
emit notify( i18n( "Loading timelines..." ), true );
199
void TimeLineWidget::directMessagesReceived( QList< Status > & msgList )
202
emit notify( i18n( "Latest direct messages received." ) );
203
int count = msgList.count();
206
kDebug() << "Message list is empty";
207
emit notify( i18n( "No new messages received. The list is up to date." ) );
210
addNewStatusesToUi( msgList, inboxLayout, &listInboxStatus, Backend::InboxTimeLine );
211
// inboxScroll->verticalScrollBar()->setSliderPosition( 0 );
212
kDebug() << count << " Statuses received.";
213
if ( !isStartMode ) {
214
unreadStatusInInbox += count;
215
if ( unreadStatusInInbox > 0 )
216
tabs->setTabText( 2, i18n( "Inbox(%1)", unreadStatusInInbox ) );
221
void TimeLineWidget::outboxMessagesReceived( QList< Status > & msgList )
224
emit notify( i18n( "Latest sent messages received." ) );
225
int count = msgList.count();
228
kDebug() << "Message list is empty";
229
emit notify( i18n( "No new messages received. The list is up to date." ) );
232
addNewStatusesToUi( msgList, outboxLayout, &listOutboxStatus, Backend::OutboxTimeLine );
233
// outboxScroll->verticalScrollBar()->setSliderPosition( 0 );
235
kDebug() << count << " Statuses received.";
237
// if ( !isStartMode ) {
238
// unreadStatusInOutbox += count;
239
// if( unreadStatusInOutbox > 0 )
240
// tabs->setTabText ( 3, i18n ( "Outbox(%1)", unreadStatusInOutbox ) );
245
void TimeLineWidget::homeTimeLinesReceived( QList< Status > & statusList )
248
emit notify( i18n( "Latest friend timelines received." ) );
249
int count = statusList.count();
252
kDebug() << "Status list is empty";
253
emit notify( i18n( "No new statuses received. The list is up to date." ) );
256
addNewStatusesToUi( statusList, homeLayout, &listHomeStatus );
257
// homeScroll->verticalScrollBar()->setSliderPosition( 0 );
259
// int count = statusList.count();
260
kDebug() << count << " Statuses received.";
262
if ( !isStartMode ) {
263
unreadStatusInHome += count;
264
if ( unreadStatusInHome > 0 )
265
tabs->setTabText( 0, i18n( "Home(%1)", unreadStatusInHome ) );
270
void TimeLineWidget::replyTimeLineReceived( QList< Status > & statusList )
273
emit notify( i18n( "Latest reply timelines received." ) );
274
int count = statusList.count();
276
kDebug() << "Status list is empty";
277
emit notify( i18n( "No new statuses received. The list is up to date." ) );
280
addNewStatusesToUi( statusList, replyLayout, &listReplyStatus, Backend::ReplyTimeLine );
281
// replyScroll->verticalScrollBar()->setSliderPosition( 0 );
283
// int count = statusList.count();
284
kDebug() << count << " Statuses received.";
286
if ( !isStartMode ) {
287
unreadStatusInReply += count;
288
if ( unreadStatusInReply > 0 )
289
tabs->setTabText( 1, i18n( "Reply(%1)", unreadStatusInReply ) );
294
void TimeLineWidget::addNewStatusesToUi( QList< Status > & statusList, QBoxLayout * layoutToAddStatuses,
295
QMap<qulonglong, StatusWidget*> *list, Backend::TimeLineType type )
298
bool allInOne = Settings::showAllNotifiesInOne();
300
int numOfNewStatuses = statusList.count();
301
QList<Status>::const_iterator it = statusList.constBegin();
302
QList<Status>::const_iterator endIt = statusList.constEnd();
303
bool isThereAnyNewStatusToNotify = false;
304
if ( allInOne && Settings::notifyType() != SettingsBase::LibNotify )
305
notifyStr = ( mCurrentAccount.direction() == Qt::RightToLeft ) ? "<div dir='rtl'>" : "<div dir='ltr'>";
306
for ( ;it != endIt; ++it ) {
307
if ( Settings::doNotShowRepliesOnHome() ) {
308
if ( it->replyToUserId == mCurrentAccount.userId() && type == Backend::HomeTimeLine ) {
310
--unreadStatusInHome;
314
if(list->keys().contains(it->statusId))
318
StatusWidget *wt = new StatusWidget( &mCurrentAccount, this );
319
wt->setAttribute( Qt::WA_DeleteOnClose );
320
wt->setCurrentStatus( *it );
321
connect( wt, SIGNAL( sigReply( const QString&, qulonglong, bool ) ),
322
this, SLOT( prepareReply( const QString&, qulonglong, bool ) ) );
323
connect( wt, SIGNAL( sigFavorite( qulonglong, bool ) ),
324
twitter, SLOT( requestFavorited( qulonglong, bool ) ) );
325
connect( wt, SIGNAL( sigDestroy( qulonglong ) ),
326
this, SLOT( requestDestroy( qulonglong ) ) );
327
connect(wt,SIGNAL(sigSearch(int,QString)),this,SIGNAL(sigSearch(int,QString)));
328
connect(wt, SIGNAL(sigReTweet(const QString&)), this, SLOT(reTweet(const QString&)));
330
list->insert( it->statusId, wt );
331
layoutToAddStatuses->insertWidget( 0, wt );
333
if ( !isStartMode ) {
334
if ( it->user.userId == mCurrentAccount.userId() ) {
336
wt->setUnread( StatusWidget::WithoutNotify );
338
if ( type == Backend::OutboxTimeLine ) {
339
wt->setUnread( StatusWidget::WithoutNotify );
340
} else if ( allInOne ) {
341
notifyStr += "<b>" + it->user.screenName + " : </b>" + it->content + "<br/>";
342
isThereAnyNewStatusToNotify = true;
343
wt->setUnread( StatusWidget::WithoutNotify );
345
wt->setUnread( StatusWidget::WithNotify );
348
listUnreadStatuses.append( wt );
351
if ( allInOne && Settings::notifyType() != SettingsBase::LibNotify )
352
notifyStr += "</div>";
353
qulonglong latestId = statusList.last().statusId;
354
if ( type == Backend::HomeTimeLine && latestId > latestHomeStatusId ) {
355
kDebug() << "Latest home statusId sets to: " << latestId;
356
latestHomeStatusId = latestId;
357
} else if ( type == Backend::ReplyTimeLine && latestId > latestReplyStatusId ) {
358
kDebug() << "Latest reply statusId sets to: " << latestId;
359
latestReplyStatusId = latestId;
360
} else if ( type == Backend::InboxTimeLine && latestId > latestInboxStatusId ) {
361
kDebug() << "Latest inbox statusId sets to: " << latestId;
362
latestInboxStatusId = latestId;
363
} else if ( type == Backend::OutboxTimeLine && latestId > latestOutboxStatusId ) {
364
kDebug() << "Latest outbox statusId sets to: " << latestId;
365
latestOutboxStatusId = latestId;
367
if ( !isStartMode && type != Backend::OutboxTimeLine )
368
checkUnreadStatuses( numOfNewStatuses );
370
if ( isThereAnyNewStatusToNotify ) {
371
showNotify( i18n( "New statuses" ), notifyStr );
374
updateStatusList( list );
377
void TimeLineWidget::abortPostNewStatus()
380
twitter->abortPostNewStatus();
383
void TimeLineWidget::setDefaultDirection()
385
// tabs->widget( 0 )->setLayoutDirection( mCurrentAccount.direction() );
386
// tabs->widget( 1 )->setLayoutDirection( mCurrentAccount.direction() );
387
// tabs->widget( 2 )->setLayoutDirection( mCurrentAccount.direction() );
388
// tabs->widget( 3 )->setLayoutDirection( mCurrentAccount.direction() );
389
// tabs->widget ( 4 )->setLayoutDirection ( mCurrentAccount.direction() );
391
txtNewStatus->setDefaultDirection( mCurrentAccount.direction() );
394
void TimeLineWidget::error( const QString & errMsg )
396
emit notify( i18n( "Failed: %1", errMsg ), true );
399
void TimeLineWidget::postStatus( QString & status )
403
if ( status.size() > MAX_STATUS_SIZE && status.indexOf( QRegExp( "https?://" ) ) == -1 ) {
404
QString err = i18n( "Message text size is greater than the server limit: \
405
the server may truncate or drop it.\nAre you sure you want to post this message?" );
406
if(KMessageBox::warningContinueCancel( this, err ) == KMessageBox::Cancel)
409
txtNewStatus->setEnabled( false );
410
if( mediaToAttach.isEmpty() ) {
411
if ( chkDMessage->isChecked() ) {
412
emit notify( i18n( "Sending direct message...." ), true );
413
twitter->sendDMessage( comboFriendList->currentText(), status );
414
chkDMessage->setChecked( false );
416
emit notify( i18n( "Posting new status...." ), true );
417
twitter->postNewStatus( status, replyToStatusId );
420
emit notify( i18n( "Posting new status...." ), true );
421
twitter->twitPicCreatePost( mediaToAttach, status );
422
mediaToAttach.clear();
426
void TimeLineWidget::postingNewStatusDone( bool isError )
429
// emit sigStatusUpdated( isError );
432
txtNewStatus->clearContentsAndSetDirection( mCurrentAccount.direction() );
433
QString successMsg = i18n( "New status posted successfully" );
434
emit systemNotify( i18n( "Success." ), successMsg, APPNAME );
435
notify( successMsg );
437
lblCounter->setPixmap(KIcon("dialog-ok").pixmap(22));
438
twitter->requestTimeLine(latestHomeStatusId, Backend::HomeTimeLine);
440
lblCounter->setPixmap(KIcon("dialog-cancel").pixmap(22));
441
error( twitter->latestErrorString() );
443
QTimer::singleShot( 3000, this, SLOT( revertCounterLabelShape() ) );
445
lblCounter->setText(QString());
446
txtNewStatus->setFocus( Qt::OtherFocusReason );
447
txtNewStatus->setEnabled( true );
451
bool TimeLineWidget::saveStatuses( QString fileName, QList<StatusWidget*> list )
454
KConfig statusesBackup( "choqok/" + fileName, KConfig::NoGlobals, "data" );
456
///Clear previous data:
457
QStringList prevList = statusesBackup.groupList();
458
int c = prevList.count();
461
for ( int i = 0; i < c; ++i ) {
462
statusesBackup.deleteGroup( prevList[i] );
466
int count = list.count();
468
for ( int i = 0; i < count; ++i ) {
470
KConfigGroup grp( &statusesBackup, QString::number( list[i]->currentStatus().statusId ) );
471
grp.writeEntry( "created_at", list[i]->currentStatus().creationDateTime );
472
grp.writeEntry( "id", list[i]->currentStatus().statusId );
473
grp.writeEntry( "text", list[i]->currentStatus().content );
474
grp.writeEntry( "source", list[i]->currentStatus().source );
475
grp.writeEntry( "truncated", list[i]->currentStatus().isTruncated );
476
grp.writeEntry( "in_reply_to_status_id", list[i]->currentStatus().replyToStatusId );
477
grp.writeEntry( "in_reply_to_user_id", list[i]->currentStatus().replyToUserId );
478
grp.writeEntry( "favorited", list[i]->currentStatus().isFavorited );
479
grp.writeEntry( "in_reply_to_screen_name", list[i]->currentStatus().replyToUserScreenName );
480
grp.writeEntry( "userId", list[i]->currentStatus().user.userId );
481
grp.writeEntry( "screen_name", list[i]->currentStatus().user.screenName );
482
grp.writeEntry( "name", list[i]->currentStatus().user.name );
483
grp.writeEntry( "profile_image_url", list[i]->currentStatus().user.profileImageUrl );
484
grp.writeEntry( "description" , list[i]->currentStatus().user.description );
485
grp.writeEntry( "isDMessage" , list[i]->currentStatus().isDMessage );
486
grp.writeEntry( "location" , list[i]->currentStatus().user.location );
487
grp.writeEntry( "url" , list[i]->currentStatus().user.homePageUrl );
488
grp.writeEntry( "followers_count" , list[i]->currentStatus().user.followersCount );
489
grp.writeEntry( "friends_count" , list[i]->currentStatus().user.friendsCount );
492
statusesBackup.sync();
497
QList< Status > TimeLineWidget::loadStatuses( QString fileName )
500
KConfig statusesBackup( "choqok/" + fileName, KConfig::NoGlobals, "data" );
501
// KConfigGroup entries(&statusesBackup, "Statuses");
502
QList< Status > list;
503
QStringList groupList = statusesBackup.groupList();
504
// kDebug()<<groupList;
505
int count = groupList.count();
507
for ( int i = 0; i < count; ++i ) {
508
KConfigGroup grp( &statusesBackup, groupList[i] );
510
st.creationDateTime = grp.readEntry( "created_at", QDateTime::currentDateTime() );
511
st.statusId = grp.readEntry( "id", ( qulonglong ) 0 );
512
st.content = grp.readEntry( "text", QString() );
513
st.source = grp.readEntry( "source", QString() );
514
st.isTruncated = grp.readEntry( "truncated", false );
515
st.replyToStatusId = grp.readEntry( "in_reply_to_status_id", ( qulonglong ) 0 );
516
st.replyToUserId = grp.readEntry( "in_reply_to_user_id", ( qulonglong ) 0 );
517
st.isFavorited = grp.readEntry( "favorited", false );
518
st.replyToUserScreenName = grp.readEntry( "in_reply_to_screen_name", QString() );
519
st.user.userId = grp.readEntry( "userId", ( qulonglong ) 0 );
520
st.user.screenName = grp.readEntry( "screen_name", QString() );
521
st.user.name = grp.readEntry( "name", QString() );
522
st.user.profileImageUrl = grp.readEntry( "profile_image_url", QString() );
523
st.user.description = grp.readEntry( "description" , QString() );
524
st.isDMessage = grp.readEntry( "isDMessage" , false );
525
st.user.location = grp.readEntry("location", QString());
526
st.user.homePageUrl = grp.readEntry("url", QString());
527
st.user.followersCount = grp.readEntry("followers_count", 0);
528
st.user.friendsCount = grp.readEntry("friends_count", 0);
530
//Sorting The new statuses:
532
int count = list.count();
533
while (( j < count ) && ( st.statusId > list[ j ].statusId ) ) {
536
list.insert( j, st );
542
void TimeLineWidget::prepareReply( const QString &userName, qulonglong statusId, bool dMsg )
547
chkDMessage->setChecked( true );
548
comboFriendList->setCurrentItem( userName, true, 0 );
550
QString current = txtNewStatus->toPlainText();
551
txtNewStatus->setText( '@' + userName + ' ' + current );
552
replyToStatusId = statusId;
553
txtNewStatus->setDefaultDirection( mCurrentAccount.direction() );
555
txtNewStatus->moveCursor( QTextCursor::End );
556
txtNewStatus->setFocus( Qt::OtherFocusReason );
559
void TimeLineWidget::updateStatusList( QMap<qulonglong, StatusWidget*> *list )
562
int toBeDelete = list->count() - Settings::countOfStatusesOnMain();
564
if ( toBeDelete > 0 ) {
565
QMap<qulonglong, StatusWidget*>::const_iterator it = list->constBegin();
566
QMap<qulonglong, StatusWidget*>::const_iterator endIt = list->constEnd();
567
for ( ; it != endIt && toBeDelete > 0; ++it ) {
568
StatusWidget* wt = it.value();
574
list->remove( it.key() );
580
void TimeLineWidget::clearTimeLineList( QMap<qulonglong, StatusWidget * > * list )
586
void TimeLineWidget::loadConfigurations()
589
setDefaultDirection();
590
friendsList = AccountManager::self()->listFriends( mCurrentAccount.alias() );
592
// txtNewStatus->setFriendsList( friendsList );
593
comboFriendList->addItems( friendsList );
594
KCompletion *c = comboFriendList->completionObject( true );;
595
c->setItems( friendsList );
596
c->setCompletionMode( KGlobalSettings::CompletionPopupAuto );
600
QList< Status > lstHome =
601
loadStatuses( AccountManager::generateStatusBackupFileName( mCurrentAccount.alias(),
602
Backend::HomeTimeLine ) );
603
if ( lstHome.count() > 0 )
604
homeTimeLinesReceived( lstHome );
606
QList< Status > lstReply =
607
loadStatuses( AccountManager::generateStatusBackupFileName( mCurrentAccount.alias(),
608
Backend::ReplyTimeLine ) );
609
if ( lstReply.count() > 0 )
610
replyTimeLineReceived( lstReply );
612
QList< Status > lstInbox =
613
loadStatuses( AccountManager::generateStatusBackupFileName( mCurrentAccount.alias(),
614
Backend::InboxTimeLine ) );
615
if ( lstInbox.count() > 0 )
616
directMessagesReceived( lstInbox );
618
QList< Status > lstOutbox =
619
loadStatuses( AccountManager::generateStatusBackupFileName( mCurrentAccount.alias(),
620
Backend::OutboxTimeLine ) );
621
if ( lstOutbox.count() > 0 )
622
outboxMessagesReceived( lstOutbox );
626
void TimeLineWidget::checkUnreadStatuses( int numOfNewStatusesReciened )
629
// if(this->isVisible()){
630
// unreadStatusCount = 0;
632
unreadStatusCount += numOfNewStatusesReciened;
634
emit sigSetUnread( numOfNewStatusesReciened );
635
emit sigSetUnreadOnMainWin( unreadStatusCount );
638
void TimeLineWidget::setUnreadStatusesToReadState()
641
tabs->setTabText( 0, i18nc( "@title:tab", "Home" ) );
642
tabs->setTabText( 1, i18nc( "@title:tab", "Reply" ) );
643
tabs->setTabText( 2, i18nc( "@title:tab", "Inbox" ) );
644
tabs->setTabText( 3, i18nc( "@title:tab", "Outbox" ) );
645
int count = listUnreadStatuses.count();
647
for ( int i = 0;i < count; ++i ) {
648
listUnreadStatuses[i]->setRead();
651
listUnreadStatuses.clear();
652
// if(unreadStatusCount) {
653
// QString s = qApp->styleSheet();
654
// qApp->setStyleSheet(s);
656
// qApp->setStyleSheet( StatusWidget::getColoredStyle() );
658
emit sigSetUnread( -unreadStatusCount );
659
emit sigSetUnreadOnMainWin( 0 );
660
unreadStatusCount = unreadStatusInReply = unreadStatusInHome = 0;
663
void TimeLineWidget::requestFavoritedDone( bool isError )
665
kDebug() << "is Error: " << isError;
669
void TimeLineWidget::requestDestroyDone( bool isError )
671
kDebug() << "is Error: " << isError;
673
toBeDestroied->close();
676
void TimeLineWidget::requestDestroy( qulonglong statusId )
678
if ( KMessageBox::warningYesNo( this, i18n( "Are you sure you wish to destroy this status?" ) ) == KMessageBox::Yes ) {
679
toBeDestroied = qobject_cast<StatusWidget*> ( sender() );
680
if ( toBeDestroied->currentStatus().isDMessage ) {
681
twitter->requestDestroyDMessage( statusId );
683
twitter->requestDestroy( statusId );
685
setUnreadStatusesToReadState();
689
void TimeLineWidget::disableApp()
692
txtNewStatus->setEnabled( false );
695
void TimeLineWidget::enableApp()
698
txtNewStatus->setEnabled( true );
701
Account TimeLineWidget::currentAccount() const
703
return mCurrentAccount;
706
void TimeLineWidget::setCurrentAccount( const Account & account )
708
mCurrentAccount = account;
711
void TimeLineWidget::reloadFriendsList()
715
comboFriendList->setCurrentItem( i18n("Please wait...."), true, 0);
716
// twitter->listFollowersScreenName();
717
twitter->listFriendsScreenName();
720
void TimeLineWidget::friendsListed( const QStringList & list )
723
friendsList.removeDuplicates();
726
comboFriendList->clear();
727
comboFriendList->addItems( friendsList );
728
KCompletion *c = comboFriendList->completionObject( true );
729
c->setItems( friendsList );
730
c->setCompletionMode( KGlobalSettings::CompletionPopupAuto );
733
void TimeLineWidget::showNotify( const QString &title, const QString &message )
735
if ( Settings::notifyType() == SettingsBase::KNotify ) {//KNotify
736
KNotification *notif = new KNotification( "new-status-arrived", parentWidget() );
737
notif->setText( message );
738
notif->setFlags( KNotification::RaiseWidgetOnActivation | KNotification::Persistent );
740
QTimer::singleShot( Settings::notifyInterval()*1000, notif, SLOT( close() ) );
741
} else if ( Settings::notifyType() == SettingsBase::LibNotify ) {//Libnotify!
742
QString msg = message;
743
msg = msg.replace( "<br/>", "\n" );
744
QString libnotifyCmd = QString( "notify-send -t " ) + QString::number( Settings::notifyInterval() * 1000 )
745
+ QString( " -u low \"" ) + title + QString( "\" \"" ) + msg + QString( "\"" );
746
QProcess::execute( libnotifyCmd );
750
void TimeLineWidget::txtNewStatusCleared()
755
void TimeLineWidget::updateUi()
757
if(Settings::showIconsOnTimelineTabs()) {
758
tabs->setTabIcon(0, KIcon( "user-home" ));
759
tabs->setTabIcon(1, KIcon( "edit-undo" ));
760
tabs->setTabIcon(2, KIcon( "mail-folder-inbox" ));
761
tabs->setTabIcon(3, KIcon( "mail-folder-outbox" ));
763
tabs->setTabIcon(0, KIcon());
764
tabs->setTabIcon(1, KIcon());
765
tabs->setTabIcon(2, KIcon());
766
tabs->setTabIcon(3, KIcon());
770
void TimeLineWidget::revertCounterLabelShape()
772
lblCounter->setPixmap( QPixmap() );
773
checkNewStatusCharactersCount( txtNewStatus->countOfRemainsChar() );
776
Backend* TimeLineWidget::getBackend()
781
void TimeLineWidget::reTweet( const QString &text )
784
txtNewStatus->setText( text );
785
txtNewStatus->setFocus(Qt::OtherFocusReason);
788
void TimeLineWidget::attachMedia()
791
QString mediaPath = KFileDialog::getOpenFileName( KUrl("kfiledialog:///image?global"),
792
"image/png image/jpeg image/gif", this,
793
i18n("Select media to attach"));
794
if( !mediaPath.isEmpty() ) {
795
mediaToAttach.setPath(mediaPath);
796
lblMediaName->setText( mediaToAttach.fileName() );
797
lblMediaName->setToolTip(mediaPath);
798
attachMediaFrame->show();
800
txtNewStatus->setFocus(Qt::OtherFocusReason);
803
void TimeLineWidget::clearMedia()
805
lblMediaName->clear();
806
mediaToAttach.clear();
807
attachMediaFrame->hide();
810
void TimeLineWidget::keyPressEvent( QKeyEvent *event )
812
if(event->key() == Qt::Key_Escape){
813
twitter->abortPostNewStatus();
814
txtNewStatus->setEnabled(true);
815
txtNewStatus->setFocus();
819
#include "timelinewidget.moc"