SVN_SILENT made messages (.desktop file)
[kdepim.git] / knode / knmainwidget.cpp
blob4d077c7a12a75b5e6216bdc97480fee0a1cd2cda
1 /*
2 KNode, the KDE newsreader
3 Copyright (c) 2003 Zack Rusin <zack@kde.org>
4 Copyright (c) 2004-2006 Volker Krause <vkrause@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15 #include "knmainwidget.h"
17 #include "headerview.h"
19 #include <Q3Accel>
20 #include <QEvent>
21 #include <QLabel>
22 #include <QVBoxLayout>
23 #include <QMenu>
24 #include <QSplitter>
25 #include <ktoolbar.h>
26 #include <kicon.h>
27 #include <kactioncollection.h>
28 #include <kinputdialog.h>
29 #include <kmessagebox.h>
30 #include <kedittoolbar.h>
31 #include <kstandardaction.h>
32 #include <kdebug.h>
33 #include <kmenubar.h>
34 #include <kiconloader.h>
35 #include <kstatusbar.h>
36 #include <klocale.h>
37 #include <kcmdlineargs.h>
38 #include <k3listviewsearchline.h>
39 #include <khbox.h>
40 #include <kselectaction.h>
41 #include <kstandardshortcut.h>
42 #include <ktoggleaction.h>
43 #include <kxmlguiclient.h>
44 #include <kxmlguifactory.h>
45 #include <ksqueezedtextlabel.h>
47 #include "libkdepim/misc/uistatesaver.h"
48 #include "libkdepim/misc/broadcaststatus.h"
49 #include "libkdepim/addressline/recentaddresses.h"
50 using KPIM::BroadcastStatus;
51 using KPIM::RecentAddresses;
53 #include <mailtransport/transportmanager.h>
54 using MailTransport::TransportManager;
56 //GUI
57 #include "knarticlewindow.h"
58 #include "kncollectionview.h"
59 #include "kncollectionviewitem.h"
60 #include "knhdrviewitem.h"
62 //Core
63 #include "articlewidget.h"
64 #include "knglobals.h"
65 #include "knconfigmanager.h"
66 #include "knarticlemanager.h"
67 #include "knarticlefactory.h"
68 #include "kngroupmanager.h"
69 #include "knnntpaccount.h"
70 #include "knaccountmanager.h"
71 #include "knfiltermanager.h"
72 #include "knfoldermanager.h"
73 #include "knfolder.h"
74 #include "kncleanup.h"
75 #include "utilities.h"
76 #include "knscoring.h"
77 #include "knmemorymanager.h"
78 #include "scheduler.h"
79 #include "settings.h"
81 #include "knodeadaptor.h"
83 using namespace KNode;
85 KNMainWidget::KNMainWidget( KXMLGUIClient* client, QWidget* parent ) :
86 KVBox( parent ),
87 c_olView( 0 ),
88 b_lockui( false ),
89 m_GUIClient( client )
91 (void) new KnodeAdaptor( this );
92 QDBusConnection::sessionBus().registerObject("/KNode", this);
93 knGlobals.top=this;
94 knGlobals.topWidget=this;
96 //------------------------------- <CONFIG> ----------------------------------
97 c_fgManager = knGlobals.configManager();
98 //------------------------------- </CONFIG> ----------------------------------
100 //-------------------------------- <GUI> ------------------------------------
101 // this will enable keyboard-only actions like that don't appear in any menu
102 //actionCollection()->setDefaultShortcutContext( Qt::WindowShortcut );
104 Q3Accel *accel = new Q3Accel( this );
105 initStatusBar();
106 setSpacing( 0 );
107 setMargin( 0 );
108 setLineWidth( 0 );
110 // splitters
111 mPrimarySplitter = new QSplitter( Qt::Horizontal, this );
112 mPrimarySplitter->setObjectName( "mPrimarySplitter" );
113 mSecondSplitter = new QSplitter( Qt::Vertical, mPrimarySplitter );
114 mSecondSplitter->setObjectName( "mSecondSplitter" );
116 //article view
117 mArticleViewer = new ArticleWidget( mPrimarySplitter, client, actionCollection(), true/*main viewer*/ );
119 //collection view
120 c_olView = new KNCollectionView( mSecondSplitter );
122 connect( c_olView, SIGNAL(itemSelectionChanged()),
123 this, SLOT(slotCollectionSelected()) );
124 connect( c_olView, SIGNAL(contextMenu(QTreeWidgetItem*,QPoint)),
125 this, SLOT(slotCollectionRMB(QTreeWidgetItem*,QPoint)) );
126 connect( c_olView, SIGNAL(renamed(QTreeWidgetItem*)),
127 this, SLOT(slotCollectionRenamed(QTreeWidgetItem*)) );
129 accel->connectItem( accel->insertItem(Qt::Key_Up), mArticleViewer, SLOT(scrollUp()) );
130 accel->connectItem( accel->insertItem(Qt::Key_Down), mArticleViewer, SLOT(scrollDown()) );
131 accel->connectItem( accel->insertItem(Qt::Key_PageUp), mArticleViewer, SLOT(scrollPrior()) );
132 accel->connectItem( accel->insertItem(Qt::Key_PageDown), mArticleViewer, SLOT(scrollNext()) );
134 //header view
135 QWidget *dummy = new QWidget( mSecondSplitter );
136 QVBoxLayout *vlay = new QVBoxLayout(dummy);
137 vlay->setSpacing( 0 );
138 vlay->setMargin( 0 );
139 h_drView = new KNHeaderView( dummy );
141 q_uicksearch = new KToolBar( dummy );
142 QLabel *lbl = new QLabel(i18n("&Search:"),dummy);
143 lbl->setObjectName("kde toolbar widget");
144 q_uicksearch->addWidget( lbl );
145 s_earchLineEdit = new K3ListViewSearchLine( q_uicksearch, h_drView );
146 q_uicksearch->addWidget( s_earchLineEdit );
147 lbl->setBuddy(s_earchLineEdit);
149 vlay->addWidget(q_uicksearch);
150 vlay->addWidget(h_drView);
152 connect(h_drView, SIGNAL(itemSelected(Q3ListViewItem*)),
153 SLOT(slotArticleSelected(Q3ListViewItem*)));
154 connect(h_drView, SIGNAL(selectionChanged()),
155 SLOT(slotArticleSelectionChanged()));
156 connect(h_drView, SIGNAL(contextMenu(K3ListView*,Q3ListViewItem*,QPoint)),
157 SLOT(slotArticleRMB(K3ListView*,Q3ListViewItem*,QPoint)));
158 connect(h_drView, SIGNAL(doubleClick(Q3ListViewItem*)),
159 SLOT(slotOpenArticle(Q3ListViewItem*)));
160 connect(h_drView, SIGNAL(sortingChanged(int)),
161 SLOT(slotHdrViewSortingChanged(int)));
163 //actions
164 initActions();
166 // splitter setup
167 mPrimarySplitter->addWidget( c_olView );
168 mPrimarySplitter->addWidget( mSecondSplitter );
169 mSecondSplitter->addWidget( dummy );
170 mSecondSplitter->addWidget( mArticleViewer );
172 //-------------------------------- </GUI> ------------------------------------
174 //-------------------------------- <CORE> ------------------------------------
176 //Network
177 connect( knGlobals.scheduler(), SIGNAL(netActive(bool)), this, SLOT(slotNetworkActive(bool)) );
179 //Filter Manager
180 f_ilManager = knGlobals.filterManager();
181 f_ilManager->setMenuAction(a_ctArtFilter, a_ctArtFilterKeyb);
183 //Article Manager
184 a_rtManager = knGlobals.articleManager();
185 a_rtManager->setView(h_drView);
187 //Group Manager
188 g_rpManager = knGlobals.groupManager();
190 //Folder Manager
191 f_olManager = knGlobals.folderManager();
193 //Account Manager
194 a_ccManager = knGlobals.accountManager();
196 //Article Factory
197 a_rtFactory = KNGlobals::self()->articleFactory();
199 // Score Manager
200 s_coreManager = knGlobals.scoringManager();
201 //connect(s_coreManager, SIGNAL(changedRules()), SLOT(slotReScore()));
202 connect(s_coreManager, SIGNAL(finishedEditing()), SLOT(slotReScore()));
204 QDBusConnection::sessionBus().registerObject( "/", this, QDBusConnection::ExportScriptableSlots );
205 //-------------------------------- </CORE> -----------------------------------
207 //apply saved options
208 readOptions();
210 //apply configuration
211 configChanged();
213 // set the keyboard focus indicator on the first item in the Collection View
214 if( c_olView->firstItem() ) {
215 QTreeWidgetItem *i = c_olView->firstItem();
216 bool open = i->isExpanded();
217 c_olView->setActive( i );
218 i->setExpanded( open );
221 c_olView->setFocus();
223 setStatusMsg();
225 if( firstStart() ) { // open the config dialog on the first start
226 show(); // the settings dialog must appear in front of the main window!
227 slotSettings();
230 actionCollection()->addAssociatedWidget( this );
231 foreach (QAction* action, actionCollection()->actions())
232 action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
235 KNMainWidget::~KNMainWidget()
237 // Avoid that removals of items from c_olView call this object back and lead to a crash.
238 disconnect( c_olView, SIGNAL(itemSelectionChanged()),
239 this, SLOT(slotCollectionSelected()) );
241 knGlobals.reset(); // cleanup
243 h_drView->clear(); //avoid some random crashes in KNHdrViewItem::~KNHdrViewItem()
246 void KNMainWidget::initStatusBar()
248 //statusbar
249 KMainWindow *mainWin = dynamic_cast<KMainWindow*>(topLevelWidget());
250 KStatusBar *sb = mainWin ? mainWin->statusBar() : 0;
251 s_tatusFilter = new KSqueezedTextLabel( QString(), sb );
252 s_tatusFilter->setTextElideMode( Qt::ElideRight );
253 s_tatusFilter->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
254 s_tatusGroup = new KSqueezedTextLabel( QString(), sb );
255 s_tatusGroup->setTextElideMode( Qt::ElideRight );
256 s_tatusGroup->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
259 //================================== GUI =================================
261 void KNMainWidget::setStatusMsg(const QString& text, int id)
263 KMainWindow *mainWin = dynamic_cast<KMainWindow*>(topLevelWidget());
264 KStatusBar *bar = mainWin ? mainWin->statusBar() : 0;
265 if ( !bar )
266 return;
267 bar->clearMessage();
268 if (text.isEmpty() && (id==SB_MAIN)) {
269 BroadcastStatus::instance()->setStatusMsg(i18n(" Ready"));
270 } else {
271 switch(id) {
272 case SB_MAIN:
273 BroadcastStatus::instance()->setStatusMsg(text); break;
274 case SB_GROUP:
275 s_tatusGroup->setText(text); break;
276 case SB_FILTER:
277 s_tatusFilter->setText(text); break;
283 void KNMainWidget::setStatusHelpMsg(const QString& text)
285 KMainWindow *mainWin = dynamic_cast<KMainWindow*>(topLevelWidget());
286 KStatusBar *bar = mainWin ? mainWin->statusBar() : 0;
287 if ( bar )
288 bar->showMessage(text, 2000);
292 void KNMainWidget::updateCaption()
294 QString newCaption=i18n("KDE News Reader");
295 if (g_rpManager->currentGroup()) {
296 newCaption = g_rpManager->currentGroup()->name();
297 if (g_rpManager->currentGroup()->status()==KNGroup::moderated)
298 newCaption += i18n(" (moderated)");
299 } else if (a_ccManager->currentAccount()) {
300 newCaption = a_ccManager->currentAccount()->name();
301 } else if (f_olManager->currentFolder()) {
302 newCaption = f_olManager->currentFolder()->name();
304 emit signalCaptionChangeRequest(newCaption);
307 void KNMainWidget::disableAccels(bool b)
309 #ifdef __GNUC__
310 #warning Port me!
311 #endif
312 /*a_ccel->setEnabled(!b);
313 KMainWindow *mainWin = dynamic_cast<KMainWindow*>(topLevelWidget());
314 KAccel *naccel = mainWin ? mainWin->accel() : 0;
315 if ( naccel )
316 naccel->setEnabled(!b);*/
317 if (b)
318 installEventFilter(this);
319 else
320 removeEventFilter(this);
324 // processEvents with some blocking
325 void KNMainWidget::secureProcessEvents()
327 b_lockui = true;
328 KMainWindow *mainWin = dynamic_cast<KMainWindow*>(topLevelWidget());
329 KMenuBar *mbar = mainWin ? mainWin->menuBar() : 0;
330 if ( mbar )
331 mbar->setEnabled(false);
332 #ifdef __GNUC__
333 #warning Port me!
334 #endif
335 /*a_ccel->setEnabled(false);
336 KAccel *naccel = mainWin ? mainWin->accel() : 0;
337 if ( naccel )
338 naccel->setEnabled(false);*/
339 installEventFilter(this);
341 qApp->processEvents();
343 b_lockui = false;
344 if ( mbar )
345 mbar->setEnabled(true);
346 #ifdef __GNUC__
347 #warning Port me!
348 #endif
349 // a_ccel->setEnabled(true);
350 // if ( naccel )
351 // naccel->setEnabled(true);
352 removeEventFilter(this);
356 QSize KNMainWidget::sizeHint() const
358 return QSize(759,478); // default optimized for 800x600
362 void KNMainWidget::openURL(const QString &url)
364 openURL(KUrl(url));
367 void KNMainWidget::openURL(const KUrl &url)
369 kDebug(5003) << url;
370 QString host = url.host();
371 short int port = url.port();
372 KNNntpAccount::Ptr acc;
374 if (url.url().left(7) == "news://") {
376 // lets see if we already have an account for this host...
377 KNNntpAccount::List list = a_ccManager->accounts();
378 for ( KNNntpAccount::List::Iterator it = list.begin(); it != list.end(); ++it ) {
379 if ( (*it)->server().toLower() == host.toLower() && ( port==-1 || (*it)->port() == port ) ) {
380 acc = *it;
381 break;
385 if(!acc) {
386 acc = KNNntpAccount::Ptr( new KNNntpAccount() );
387 acc->setName(host);
388 acc->setServer(host);
390 if(port!=-1)
391 acc->setPort(port);
393 if(url.hasUser() && url.hasPass()) {
394 acc->setNeedsLogon(true);
395 acc->setUser(url.user());
396 acc->setPass(url.pass());
399 if(!a_ccManager->newAccount(acc))
400 return;
402 } else {
403 if (url.url().left(5) == "news:") {
404 // TODO: make the default server configurable
405 acc = a_ccManager->currentAccount();
406 if ( acc == 0 )
407 acc = a_ccManager->first();
408 } else {
409 kDebug(5003) <<"KNMainWidget::openURL() URL is not a valid news URL";
413 if (acc) {
414 QString decodedUrl = KUrl::fromPercentEncoding( url.url().toLatin1() );
415 bool isMID=decodedUrl.contains('@' );
417 if (!isMID) {
418 QString groupname=url.path( KUrl::RemoveTrailingSlash );
419 while(groupname.startsWith('/'))
420 groupname.remove(0,1);
421 QTreeWidgetItem *item=0;
422 if ( groupname.isEmpty() ) {
423 item=acc->listItem();
424 } else {
425 KNGroup::Ptr grp = g_rpManager->group( groupname, acc );
427 if(!grp) {
428 KNGroupInfo inf(groupname, "");
429 g_rpManager->subscribeGroup(&inf, acc);
430 grp=g_rpManager->group(groupname, acc);
431 if(grp)
432 item=grp->listItem();
434 else
435 item=grp->listItem();
438 if (item) {
439 c_olView->setActive( item );
441 } else {
442 QString groupname = decodedUrl.mid( url.protocol().length()+1 );
443 KNGroup::Ptr g = g_rpManager->currentGroup();
444 if (g == 0)
445 g = g_rpManager->firstGroupOfAccount(acc);
447 if (g) {
448 if ( !ArticleWindow::raiseWindowForArticle( groupname.toLatin1() ) ) { //article not yet opened
449 KNRemoteArticle::Ptr a( new KNRemoteArticle(g) );
450 QString messageID = '<' + groupname + '>';
451 a->messageID()->from7BitString(messageID.toLatin1());
452 ArticleWindow *awin = new ArticleWindow( a );
453 awin->show();
455 } else {
456 // TODO: fetch without group
457 kDebug(5003) <<"KNMainWidget::openURL() account has no groups";
464 // update fonts and colors
465 void KNMainWidget::configChanged()
467 h_drView->readConfig();
468 c_olView->readConfig();
469 a_rtManager->updateListViewItems();
473 void KNMainWidget::initActions()
475 //a_ccel=new KAccel(this);
477 //navigation
478 a_ctNavNextArt = actionCollection()->addAction("go_nextArticle" );
479 a_ctNavNextArt->setText(i18n("&Next Article"));
480 a_ctNavNextArt->setToolTip(i18n("Go to next article"));
481 a_ctNavNextArt->setShortcuts(KShortcut("N; Right"));
482 connect(a_ctNavNextArt, SIGNAL(triggered(bool)), h_drView, SLOT(nextArticle()));
484 a_ctNavPrevArt = actionCollection()->addAction("go_prevArticle" );
485 a_ctNavPrevArt->setText(i18n("&Previous Article"));
486 a_ctNavPrevArt->setShortcuts(KShortcut("P; Left"));
487 a_ctNavPrevArt->setToolTip(i18n("Go to previous article"));
488 connect(a_ctNavPrevArt, SIGNAL(triggered(bool)), h_drView, SLOT(prevArticle()));
490 a_ctNavNextUnreadArt = actionCollection()->addAction("go_nextUnreadArticle");
491 a_ctNavNextUnreadArt->setIcon(KIcon("go-next"));
492 a_ctNavNextUnreadArt->setText(i18n("Next Unread &Article"));
493 connect(a_ctNavNextUnreadArt, SIGNAL(triggered(bool)), SLOT(slotNavNextUnreadArt()));
494 a_ctNavNextUnreadArt->setShortcut(QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_Space));
496 a_ctNavNextUnreadThread = actionCollection()->addAction("go_nextUnreadThread");
497 a_ctNavNextUnreadThread->setIcon(KIcon("go-last"));
498 a_ctNavNextUnreadThread->setText(i18n("Next Unread &Thread"));
499 connect(a_ctNavNextUnreadThread, SIGNAL(triggered(bool)), SLOT(slotNavNextUnreadThread()));
500 a_ctNavNextUnreadThread->setShortcut(QKeySequence(Qt::SHIFT+Qt::Key_Space));
502 a_ctNavNextGroup = actionCollection()->addAction("go_nextGroup");
503 a_ctNavNextGroup->setIcon(KIcon("go-down"));
504 a_ctNavNextGroup->setText(i18n("Ne&xt Group"));
505 connect(a_ctNavNextGroup, SIGNAL(triggered(bool)), c_olView, SLOT(nextGroup()));
506 a_ctNavNextGroup->setShortcut(QKeySequence(Qt::Key_Plus));
508 a_ctNavPrevGroup = actionCollection()->addAction("go_prevGroup");
509 a_ctNavPrevGroup->setIcon(KIcon("go-up"));
510 a_ctNavPrevGroup->setText(i18n("Pre&vious Group"));
511 connect(a_ctNavPrevGroup, SIGNAL(triggered(bool)), c_olView, SLOT(prevGroup()));
512 a_ctNavPrevGroup->setShortcut(QKeySequence(Qt::Key_Minus));
514 a_ctNavReadThrough = actionCollection()->addAction("go_readThrough");
515 a_ctNavReadThrough->setText(i18n("Read &Through Articles"));
516 connect(a_ctNavReadThrough, SIGNAL(triggered(bool)), SLOT(slotNavReadThrough()));
517 a_ctNavReadThrough->setShortcut(QKeySequence(Qt::Key_Space));
519 KAction *action = actionCollection()->addAction("inc_current_folder");
520 action->setText(i18n("Focus on Next Folder"));
521 connect(action, SIGNAL(triggered(bool)), c_olView, SLOT(incCurrentFolder()));
522 action->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Right));
524 action = actionCollection()->addAction("dec_current_folder");
525 action->setText(i18n("Focus on Previous Folder"));
526 connect(action, SIGNAL(triggered(bool)), c_olView, SLOT(decCurrentFolder()));
527 action->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Left));
529 action = actionCollection()->addAction("select_current_folder");
530 action->setText(i18n("Select Folder with Focus"));
531 connect(action, SIGNAL(triggered(bool)), c_olView, SLOT(selectCurrentFolder()));
532 action->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Space));
534 action = actionCollection()->addAction("inc_current_article");
535 action->setText(i18n("Focus on Next Article"));
536 connect(action, SIGNAL(triggered(bool)), h_drView, SLOT(incCurrentArticle()));
537 action->setShortcut(QKeySequence(Qt::ALT+Qt::Key_Right));
539 action = actionCollection()->addAction("dec_current_article");
540 action->setText(i18n("Focus on Previous Article"));
541 connect(action, SIGNAL(triggered(bool)), h_drView, SLOT(decCurrentArticle()));
542 action->setShortcut(QKeySequence(Qt::ALT+Qt::Key_Left));
544 action = actionCollection()->addAction("select_current_article");
545 action->setText(i18n("Select Article with Focus"));
546 connect(action, SIGNAL(triggered(bool)), h_drView, SLOT(selectCurrentArticle()));
547 action->setShortcut(QKeySequence(Qt::ALT+Qt::Key_Space));
549 //collection-view - accounts
550 a_ctAccProperties = actionCollection()->addAction("account_properties");
551 a_ctAccProperties->setIcon(KIcon("document-properties"));
552 a_ctAccProperties->setText(i18n("Account &Properties"));
553 connect(a_ctAccProperties, SIGNAL(triggered(bool)), SLOT(slotAccProperties()));
555 a_ctAccRename = actionCollection()->addAction("account_rename");
556 a_ctAccRename->setIcon(KIcon("edit-rename"));
557 a_ctAccRename->setText(i18n("&Rename Account"));
558 connect(a_ctAccRename, SIGNAL(triggered(bool)), SLOT(slotAccRename()));
560 a_ctAccSubscribe = actionCollection()->addAction("account_subscribe");
561 a_ctAccSubscribe->setIcon(KIcon("news-subscribe"));
562 a_ctAccSubscribe->setText(i18n("&Subscribe to Newsgroups..."));
563 connect(a_ctAccSubscribe, SIGNAL(triggered(bool)), SLOT(slotAccSubscribe()));
565 a_ctAccExpireAll = actionCollection()->addAction("account_expire_all");
566 a_ctAccExpireAll->setText(i18n("&Expire All Groups"));
567 connect(a_ctAccExpireAll, SIGNAL(triggered(bool)), SLOT(slotAccExpireAll()));
569 a_ctAccGetNewHdrs = actionCollection()->addAction("account_dnlHeaders");
570 a_ctAccGetNewHdrs->setIcon(KIcon("mail-receive"));
571 a_ctAccGetNewHdrs->setText(i18n("&Get New Articles in All Groups"));
572 connect(a_ctAccGetNewHdrs, SIGNAL(triggered(bool)), SLOT(slotAccGetNewHdrs()));
574 a_ctAccGetNewHdrsAll = actionCollection()->addAction("account_dnlAllHeaders");
575 a_ctAccGetNewHdrsAll->setIcon(KIcon("mail-receive-all"));
576 a_ctAccGetNewHdrsAll->setText(i18n("&Get New Articles in All Accounts"));
577 connect(a_ctAccGetNewHdrsAll, SIGNAL(triggered(bool)), SLOT(slotAccGetNewHdrsAll()));
579 a_ctAccDelete = actionCollection()->addAction("account_delete");
580 a_ctAccDelete->setIcon(KIcon("edit-delete"));
581 a_ctAccDelete->setText(i18n("&Delete Account"));
582 connect(a_ctAccDelete, SIGNAL(triggered(bool)), SLOT(slotAccDelete()));
584 a_ctAccPostNewArticle = actionCollection()->addAction("article_postNew");
585 a_ctAccPostNewArticle->setIcon(KIcon("mail-message-new"));
586 a_ctAccPostNewArticle->setText(i18n("&Post to Newsgroup..."));
587 connect(a_ctAccPostNewArticle, SIGNAL(triggered(bool)), SLOT(slotAccPostNewArticle()));
588 a_ctAccPostNewArticle->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_N));
590 //collection-view - groups
591 a_ctGrpProperties = actionCollection()->addAction("group_properties");
592 a_ctGrpProperties->setIcon(KIcon("document-properties"));
593 a_ctGrpProperties->setText(i18n("Group &Properties"));
594 connect(a_ctGrpProperties, SIGNAL(triggered(bool)), SLOT(slotGrpProperties()));
596 a_ctGrpRename = actionCollection()->addAction("group_rename");
597 a_ctGrpRename->setIcon(KIcon("edit-rename"));
598 a_ctGrpRename->setText(i18n("Rename &Group"));
599 connect(a_ctGrpRename, SIGNAL(triggered(bool)), SLOT(slotGrpRename()));
601 a_ctGrpGetNewHdrs = actionCollection()->addAction("group_dnlHeaders");
602 a_ctGrpGetNewHdrs->setIcon(KIcon("mail-receive"));
603 a_ctGrpGetNewHdrs->setText(i18n("&Get New Articles"));
604 connect(a_ctGrpGetNewHdrs, SIGNAL(triggered(bool)), SLOT(slotGrpGetNewHdrs()));
606 a_ctGrpExpire = actionCollection()->addAction("group_expire");
607 a_ctGrpExpire->setText(i18n("E&xpire Group"));
608 connect(a_ctGrpExpire, SIGNAL(triggered(bool)), SLOT(slotGrpExpire()));
610 a_ctGrpReorganize = actionCollection()->addAction("group_reorg");
611 a_ctGrpReorganize->setText(i18n("Re&organize Group"));
612 connect(a_ctGrpReorganize, SIGNAL(triggered(bool)), SLOT(slotGrpReorganize()));
614 a_ctGrpUnsubscribe = actionCollection()->addAction("group_unsubscribe");
615 a_ctGrpUnsubscribe->setIcon(KIcon("news-unsubscribe"));
616 a_ctGrpUnsubscribe->setText(i18n("&Unsubscribe From Group"));
617 connect(a_ctGrpUnsubscribe, SIGNAL(triggered(bool)), SLOT(slotGrpUnsubscribe()));
619 a_ctGrpSetAllRead = actionCollection()->addAction("group_allRead");
620 a_ctGrpSetAllRead->setIcon(KIcon("mail-mark-read"));
621 a_ctGrpSetAllRead->setText(i18n("Mark All as &Read"));
622 connect(a_ctGrpSetAllRead, SIGNAL(triggered(bool)), SLOT(slotGrpSetAllRead()));
624 a_ctGrpSetAllUnread = actionCollection()->addAction("group_allUnread");
625 a_ctGrpSetAllUnread->setText(i18n("Mark All as U&nread"));
626 connect(a_ctGrpSetAllUnread, SIGNAL(triggered(bool)), SLOT(slotGrpSetAllUnread()));
628 a_ctGrpSetUnread = actionCollection()->addAction("group_unread");
629 a_ctGrpSetUnread->setText(i18n("Mark Last as Unr&ead..."));
630 connect(a_ctGrpSetUnread, SIGNAL(triggered(bool)), SLOT(slotGrpSetUnread()));
632 action = actionCollection()->addAction("knode_configure_knode");
633 action->setIcon(KIcon("configure"));
634 action->setText(i18n("&Configure KNode..."));
635 connect(action, SIGNAL(triggered(bool)), SLOT(slotSettings()));
637 //collection-view - folder
638 a_ctFolNew = actionCollection()->addAction("folder_new");
639 a_ctFolNew->setIcon(KIcon("folder-new"));
640 a_ctFolNew->setText(i18n("&New Folder"));
641 connect(a_ctFolNew, SIGNAL(triggered(bool)), SLOT(slotFolNew()));
643 a_ctFolNewChild = actionCollection()->addAction("folder_newChild");
644 a_ctFolNewChild->setIcon(KIcon("folder-new"));
645 a_ctFolNewChild->setText(i18n("New &Subfolder"));
646 connect(a_ctFolNewChild, SIGNAL(triggered(bool)), SLOT(slotFolNewChild()));
648 a_ctFolDelete = actionCollection()->addAction("folder_delete");
649 a_ctFolDelete->setIcon(KIcon("edit-delete"));
650 a_ctFolDelete->setText(i18n("&Delete Folder"));
651 connect(a_ctFolDelete, SIGNAL(triggered(bool)), SLOT(slotFolDelete()));
653 a_ctFolRename = actionCollection()->addAction("folder_rename");
654 a_ctFolRename->setIcon(KIcon("edit-rename"));
655 a_ctFolRename->setText(i18n("&Rename Folder"));
656 connect(a_ctFolRename, SIGNAL(triggered(bool)), SLOT(slotFolRename()));
658 a_ctFolCompact = actionCollection()->addAction("folder_compact");
659 a_ctFolCompact->setText(i18n("C&ompact Folder"));
660 connect(a_ctFolCompact, SIGNAL(triggered(bool)), SLOT(slotFolCompact()));
662 a_ctFolCompactAll = actionCollection()->addAction("folder_compact_all");
663 a_ctFolCompactAll->setText(i18n("Co&mpact All Folders"));
664 connect(a_ctFolCompactAll, SIGNAL(triggered(bool)), SLOT(slotFolCompactAll()));
666 a_ctFolEmpty = actionCollection()->addAction("folder_empty");
667 a_ctFolEmpty->setText(i18n("&Empty Folder"));
668 connect(a_ctFolEmpty, SIGNAL(triggered(bool)), SLOT(slotFolEmpty()));
670 a_ctFolMboxImport = actionCollection()->addAction("folder_MboxImport");
671 a_ctFolMboxImport->setText(i18n("&Import MBox Folder..."));
672 connect(a_ctFolMboxImport, SIGNAL(triggered(bool)), SLOT(slotFolMBoxImport()));
674 a_ctFolMboxExport = actionCollection()->addAction("folder_MboxExport");
675 a_ctFolMboxExport->setText(i18n("E&xport as MBox Folder..."));
676 connect(a_ctFolMboxExport, SIGNAL(triggered(bool)), SLOT(slotFolMBoxExport()));
678 //header-view - list-handling
679 a_ctArtSortHeaders = actionCollection()->add<KSelectAction>("view_Sort");
680 a_ctArtSortHeaders->setText(i18n("S&ort"));
681 QStringList items;
682 items += i18n("By &Subject");
683 items += i18n("By S&ender");
684 items += i18n("By S&core");
685 items += i18n("By &Lines");
686 items += i18n("By &Date");
687 a_ctArtSortHeaders->setItems(items);
688 a_ctArtSortHeaders->setShortcutConfigurable(false);
689 connect(a_ctArtSortHeaders, SIGNAL(activated(int)), this, SLOT(slotArtSortHeaders(int)));
691 a_ctArtSortHeadersKeyb = actionCollection()->addAction("view_Sort_Keyb");
692 a_ctArtSortHeadersKeyb->setText(i18n("Sort"));
693 connect(a_ctArtSortHeadersKeyb, SIGNAL(triggered(bool)), SLOT(slotArtSortHeadersKeyb()));
694 a_ctArtSortHeadersKeyb->setShortcut(QKeySequence(Qt::Key_F7));
696 a_ctArtFilter = new KNFilterSelectAction(i18n("&Filter"), "view-filter",
697 actionCollection(), "view_Filter");
698 a_ctArtFilter->setShortcutConfigurable(false);
700 a_ctArtFilterKeyb = actionCollection()->addAction("view_Filter_Keyb");
701 a_ctArtFilterKeyb->setText(i18n("Filter"));
702 a_ctArtFilterKeyb->setShortcut(QKeySequence(Qt::Key_F6));
704 a_ctArtSearch = actionCollection()->addAction("article_search");
705 a_ctArtSearch->setIcon(KIcon("edit-find-mail"));
706 a_ctArtSearch->setText(i18n("&Search Articles..."));
707 connect(a_ctArtSearch, SIGNAL(triggered(bool)), SLOT(slotArtSearch()));
708 a_ctArtSearch->setShortcut(QKeySequence(Qt::Key_F4));
710 a_ctArtRefreshList = actionCollection()->addAction("view_Refresh");
711 a_ctArtRefreshList->setIcon(KIcon("view-refresh"));
712 a_ctArtRefreshList->setText(i18n("&Refresh List"));
713 connect(a_ctArtRefreshList, SIGNAL(triggered(bool)), SLOT(slotArtRefreshList()));
714 a_ctArtRefreshList->setShortcuts(KStandardShortcut::shortcut(KStandardShortcut::Reload));
716 a_ctArtCollapseAll = actionCollection()->addAction("view_CollapseAll");
717 a_ctArtCollapseAll->setText(i18n("&Collapse All Threads"));
718 connect(a_ctArtCollapseAll, SIGNAL(triggered(bool)), SLOT(slotArtCollapseAll()));
720 a_ctArtExpandAll = actionCollection()->addAction("view_ExpandAll");
721 a_ctArtExpandAll->setText(i18n("E&xpand All Threads"));
722 connect(a_ctArtExpandAll, SIGNAL(triggered(bool)), SLOT(slotArtExpandAll()));
724 a_ctArtToggleThread = actionCollection()->addAction("thread_toggle");
725 a_ctArtToggleThread->setText(i18n("&Toggle Subthread"));
726 connect(a_ctArtToggleThread, SIGNAL(triggered(bool)), SLOT(slotArtToggleThread()));
727 a_ctArtToggleThread->setShortcut(QKeySequence(Qt::Key_T));
729 a_ctArtToggleShowThreads = actionCollection()->add<KToggleAction>("view_showThreads");
730 a_ctArtToggleShowThreads->setText(i18n("Show T&hreads"));
731 connect(a_ctArtToggleShowThreads, SIGNAL(triggered(bool)), SLOT(slotArtToggleShowThreads()));
733 a_ctArtToggleShowThreads->setChecked( knGlobals.settings()->showThreads() );
735 //header-view - remote articles
736 a_ctArtSetArtRead = actionCollection()->addAction("article_read");
737 a_ctArtSetArtRead->setIcon(KIcon("mail-mark-read"));
738 a_ctArtSetArtRead->setText(i18n("Mark as &Read"));
739 connect(a_ctArtSetArtRead, SIGNAL(triggered(bool)), SLOT(slotArtSetArtRead()));
740 a_ctArtSetArtRead->setShortcut(QKeySequence(Qt::Key_D));
742 a_ctArtSetArtUnread = actionCollection()->addAction("article_unread");
743 a_ctArtSetArtUnread->setIcon(KIcon("mail-mark-unread"));
744 a_ctArtSetArtUnread->setText(i18n("Mar&k as Unread"));
745 connect(a_ctArtSetArtUnread, SIGNAL(triggered(bool)), SLOT(slotArtSetArtUnread()));
746 a_ctArtSetArtUnread->setShortcut(QKeySequence(Qt::Key_U));
748 a_ctArtSetThreadRead = actionCollection()->addAction("thread_read");
749 a_ctArtSetThreadRead->setText(i18n("Mark &Thread as Read"));
750 connect(a_ctArtSetThreadRead, SIGNAL(triggered(bool)), SLOT(slotArtSetThreadRead()));
751 a_ctArtSetThreadRead->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_D));
753 a_ctArtSetThreadUnread = actionCollection()->addAction("thread_unread");
754 a_ctArtSetThreadUnread->setText(i18n("Mark T&hread as Unread"));
755 connect(a_ctArtSetThreadUnread, SIGNAL(triggered(bool)), SLOT(slotArtSetThreadUnread()));
756 a_ctArtSetThreadUnread->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_U));
758 a_ctArtOpenNewWindow = actionCollection()->addAction("article_ownWindow");
759 a_ctArtOpenNewWindow->setIcon(KIcon("window-new"));
760 a_ctArtOpenNewWindow->setText(i18n("Open in Own &Window"));
761 connect(a_ctArtOpenNewWindow, SIGNAL(triggered(bool)), SLOT(slotArtOpenNewWindow()));
762 a_ctArtOpenNewWindow->setShortcut(QKeySequence(Qt::Key_O));
764 // scoring
765 a_ctScoresEdit = actionCollection()->addAction("scoreedit");
766 a_ctScoresEdit->setIcon(KIcon("document-properties"));
767 a_ctScoresEdit->setText(i18n("&Edit Scoring Rules..."));
768 connect(a_ctScoresEdit, SIGNAL(triggered(bool)), SLOT(slotScoreEdit()));
769 a_ctScoresEdit->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_E));
771 a_ctReScore = actionCollection()->addAction("rescore");
772 a_ctReScore->setText(i18n("Recalculate &Scores"));
773 connect(a_ctReScore, SIGNAL(triggered(bool)), SLOT(slotReScore()));
775 a_ctScoreLower = actionCollection()->addAction("scorelower");
776 a_ctScoreLower->setText(i18n("&Lower Score for Author..."));
777 connect(a_ctScoreLower, SIGNAL(triggered(bool)), SLOT(slotScoreLower()));
778 a_ctScoreLower->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_L));
780 a_ctScoreRaise = actionCollection()->addAction("scoreraise");
781 a_ctScoreRaise->setText(i18n("&Raise Score for Author..."));
782 connect(a_ctScoreRaise, SIGNAL(triggered(bool)), SLOT(slotScoreRaise()));
783 a_ctScoreRaise->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_I));
785 a_ctArtToggleIgnored = actionCollection()->addAction("thread_ignore");
786 a_ctArtToggleIgnored->setIcon(KIcon("go-bottom"));
787 a_ctArtToggleIgnored->setText(i18n("&Ignore Thread"));
788 connect(a_ctArtToggleIgnored, SIGNAL(triggered(bool)), SLOT(slotArtToggleIgnored()));
789 a_ctArtToggleIgnored->setShortcut(QKeySequence(Qt::Key_I));
791 a_ctArtToggleWatched = actionCollection()->addAction("thread_watch");
792 a_ctArtToggleWatched->setIcon(KIcon("go-top"));
793 a_ctArtToggleWatched->setText(i18n("&Watch Thread"));
794 connect(a_ctArtToggleWatched, SIGNAL(triggered(bool)), SLOT(slotArtToggleWatched()));
795 a_ctArtToggleWatched->setShortcut(QKeySequence(Qt::Key_W));
797 //header-view local articles
798 a_ctArtSendOutbox = actionCollection()->addAction("net_sendPending");
799 a_ctArtSendOutbox->setIcon(KIcon("mail-send"));
800 a_ctArtSendOutbox->setText(i18n("Sen&d Pending Messages"));
801 connect(a_ctArtSendOutbox, SIGNAL(triggered(bool)), SLOT(slotArtSendOutbox()));
803 a_ctArtDelete = actionCollection()->addAction("article_delete");
804 a_ctArtDelete->setIcon(KIcon("edit-delete"));
805 a_ctArtDelete->setText(i18n("&Delete Article"));
806 connect(a_ctArtDelete, SIGNAL(triggered(bool)), SLOT(slotArtDelete()));
807 a_ctArtDelete->setShortcut(QKeySequence(Qt::Key_Delete));
809 a_ctArtSendNow = actionCollection()->addAction("article_sendNow");
810 a_ctArtSendNow->setIcon(KIcon("mail-send"));
811 a_ctArtSendNow->setText(i18n("Send &Now"));
812 connect(a_ctArtSendNow, SIGNAL(triggered(bool)), SLOT(slotArtSendNow()));
814 a_ctArtEdit = actionCollection()->addAction("article_edit");
815 a_ctArtEdit->setIcon(KIcon("document-properties"));
816 a_ctArtEdit->setText(i18nc("edit article","&Edit Article..."));
817 connect(a_ctArtEdit, SIGNAL(triggered(bool)), SLOT(slotArtEdit()));
818 a_ctArtEdit->setShortcut(QKeySequence(Qt::Key_E));
820 //network
821 a_ctNetCancel = actionCollection()->addAction("net_stop");
822 a_ctNetCancel->setIcon(KIcon("process-stop"));
823 a_ctNetCancel->setText(i18n("Stop &Network"));
824 connect(a_ctNetCancel, SIGNAL(triggered(bool)), SLOT(slotNetCancel()));
825 a_ctNetCancel->setEnabled(false);
827 a_ctFetchArticleWithID = actionCollection()->addAction("fetch_article_with_id");
828 a_ctFetchArticleWithID->setText(i18n("&Fetch Article with ID..."));
829 connect(a_ctFetchArticleWithID, SIGNAL(triggered(bool)), SLOT(slotFetchArticleWithID()));
830 a_ctFetchArticleWithID->setEnabled(false);
832 a_ctToggleQuickSearch = actionCollection()->add<KToggleAction>("settings_show_quickSearch");
833 a_ctToggleQuickSearch->setText(i18n("Show Quick Search"));
834 connect(a_ctToggleQuickSearch, SIGNAL(triggered(bool)), SLOT(slotToggleQuickSearch()));
837 bool KNMainWidget::firstStart()
839 KConfigGroup conf(knGlobals.config(), "GENERAL");
840 QString ver = conf.readEntry("Version");
841 if(!ver.isEmpty())
842 return false;
844 if ( TransportManager::self()->isEmpty() )
845 TransportManager::self()->createDefaultTransport();
847 conf.writeEntry("Version", KNODE_VERSION);
849 return true;
853 void KNMainWidget::readOptions()
855 KConfigGroup conf(knGlobals.config(), "APPEARANCE");
857 if (conf.readEntry("quicksearch", true))
858 a_ctToggleQuickSearch->setChecked(true);
859 else
860 q_uicksearch->hide();
861 c_olView->readConfig();
862 h_drView->readConfig();
863 a_ctArtSortHeaders->setCurrentItem( h_drView->sortColumn() );
865 resize(787,478); // default optimized for 800x600
866 //applyMainWindowSettings(KGlobal::config(),"mainWindow_options");
868 KPIM::UiStateSaver::restoreState( this, KConfigGroup( knGlobals.config(), "UI State" ) );
872 void KNMainWidget::saveOptions()
874 KConfigGroup conf(knGlobals.config(), "APPEARANCE");
876 conf.writeEntry("quicksearch", !q_uicksearch->isHidden());
877 //saveMainWindowSettings(KGlobal::config(),"mainWindow_options");
879 c_olView->writeConfig();
880 h_drView->writeConfig();
881 mArticleViewer->writeConfig();
883 KConfigGroup cfg( knGlobals.config(), "UI State" );
884 KPIM::UiStateSaver::saveState( this, cfg );
888 bool KNMainWidget::requestShutdown()
890 kDebug(5003) <<"KNMainWidget::requestShutdown()";
892 if( a_rtFactory->jobsPending() &&
893 KMessageBox::No==KMessageBox::warningYesNo(this, i18n(
894 "KNode is currently sending articles. If you quit now you might lose these \
895 articles.\nDo you want to quit anyway?"), QString(), KStandardGuiItem::quit(), KStandardGuiItem::cancel())
897 return false;
899 if(!a_rtFactory->closeComposeWindows())
900 return false;
902 return true;
906 void KNMainWidget::prepareShutdown()
908 kDebug(5003) <<"KNMainWidget::prepareShutdown()";
910 //cleanup article-views
911 ArticleWidget::cleanup();
913 // expire groups (if necessary)
914 KNCleanUp *cup = new KNCleanUp();
915 g_rpManager->expireAll(cup);
916 cup->start();
918 // compact folders
919 KNode::Cleanup *conf=c_fgManager->cleanup();
920 if (conf->compactToday()) {
921 cup->reset();
922 f_olManager->compactAll(cup);
923 cup->start();
924 conf->setLastCompactDate();
927 delete cup;
929 saveOptions();
930 RecentAddresses::self(knGlobals.config())->save( knGlobals.config() );
931 c_fgManager->syncConfig();
932 a_rtManager->deleteTempFiles();
933 g_rpManager->syncGroups();
934 f_olManager->syncFolders();
935 f_ilManager->prepareShutdown();
936 a_ccManager->prepareShutdown();
937 s_coreManager->save();
941 bool KNMainWidget::queryClose()
943 if(b_lockui)
944 return false;
946 if(!requestShutdown())
947 return false;
949 prepareShutdown();
951 return true;
955 void KNMainWidget::fontChange( const QFont & )
957 a_rtFactory->configChanged();
958 ArticleWidget::configChanged();
959 configChanged();
963 void KNMainWidget::paletteChange( const QPalette & )
965 ArticleWidget::configChanged();
966 configChanged();
970 bool KNMainWidget::eventFilter(QObject *o, QEvent *e)
972 if (((e->type() == QEvent::KeyPress) ||
973 (e->type() == QEvent::KeyRelease) ||
974 (e->type() == QEvent::Shortcut) ||
975 (e->type() == QEvent::ShortcutOverride)) &&
976 b_lockui)
977 return true;
978 return QWidget::eventFilter(o, e);
982 void KNMainWidget::getSelectedArticles(KNArticle::List &l)
984 if(!g_rpManager->currentGroup() && !f_olManager->currentFolder())
985 return;
987 for(Q3ListViewItem *i=h_drView->firstChild(); i; i=i->itemBelow())
988 if(i->isSelected() || (static_cast<KNHdrViewItem*>(i)->isActive()))
989 l.append( boost::static_pointer_cast<KNArticle>( static_cast<KNHdrViewItem*>( i )->art ) );
993 void KNMainWidget::getSelectedArticles(KNRemoteArticle::List &l)
995 if(!g_rpManager->currentGroup()) return;
997 for(Q3ListViewItem *i=h_drView->firstChild(); i; i=i->itemBelow())
998 if(i->isSelected() || (static_cast<KNHdrViewItem*>(i)->isActive()))
999 l.append( boost::static_pointer_cast<KNRemoteArticle>( static_cast<KNHdrViewItem*>(i)->art ) );
1003 void KNMainWidget::getSelectedThreads(KNRemoteArticle::List &l)
1005 KNRemoteArticle::Ptr art;
1006 for(Q3ListViewItem *i=h_drView->firstChild(); i; i=i->itemBelow())
1007 if(i->isSelected() || (static_cast<KNHdrViewItem*>(i)->isActive())) {
1008 art = boost::static_pointer_cast<KNRemoteArticle>( static_cast<KNHdrViewItem*>( i )->art );
1009 // ignore the article if it is already in the list
1010 // (multiple aritcles are selected in one thread)
1011 if ( !l.contains(art) )
1012 art->thread(l);
1017 void KNMainWidget::getSelectedArticles( KNLocalArticle::List &l )
1019 if(!f_olManager->currentFolder()) return;
1021 for(Q3ListViewItem *i=h_drView->firstChild(); i; i=i->itemBelow())
1022 if(i->isSelected() || (static_cast<KNHdrViewItem*>(i)->isActive()))
1023 l.append( boost::static_pointer_cast<KNLocalArticle>( static_cast<KNHdrViewItem*>(i)->art ) );
1027 void KNMainWidget::closeCurrentThread()
1029 Q3ListViewItem *item = h_drView->currentItem();
1030 if (item) {
1031 while (item->parent())
1032 item = item->parent();
1033 h_drView->setCurrentItem(item);
1034 item->setOpen(false);
1035 h_drView->ensureItemVisible(item);
1039 void KNMainWidget::slotArticleSelected(Q3ListViewItem *i)
1041 kDebug(5003) <<"KNMainWidget::slotArticleSelected(QListViewItem *i)";
1042 if(b_lockui)
1043 return;
1044 KNArticle::Ptr selectedArticle;
1046 if(i)
1047 selectedArticle=(static_cast<KNHdrViewItem*>(i))->art;
1049 mArticleViewer->setArticle( selectedArticle );
1051 //actions
1052 bool enabled;
1054 enabled=( selectedArticle && selectedArticle->type()==KNArticle::ATremote );
1055 if(a_ctArtSetArtRead->isEnabled() != enabled) {
1056 a_ctArtSetArtRead->setEnabled(enabled);
1057 a_ctArtSetArtUnread->setEnabled(enabled);
1058 a_ctArtSetThreadRead->setEnabled(enabled);
1059 a_ctArtSetThreadUnread->setEnabled(enabled);
1060 a_ctArtToggleIgnored->setEnabled(enabled);
1061 a_ctArtToggleWatched->setEnabled(enabled);
1062 a_ctScoreLower->setEnabled(enabled);
1063 a_ctScoreRaise->setEnabled(enabled);
1066 a_ctArtOpenNewWindow->setEnabled( selectedArticle && (f_olManager->currentFolder()!=f_olManager->outbox())
1067 && (f_olManager->currentFolder()!=f_olManager->drafts()));
1069 enabled=( selectedArticle && selectedArticle->type()==KNArticle::ATlocal );
1070 a_ctArtDelete->setEnabled(enabled);
1071 a_ctArtSendNow->setEnabled(enabled && (f_olManager->currentFolder()==f_olManager->outbox()));
1072 a_ctArtEdit->setEnabled(enabled && ((f_olManager->currentFolder()==f_olManager->outbox())||
1073 (f_olManager->currentFolder()==f_olManager->drafts())));
1077 void KNMainWidget::slotArticleSelectionChanged()
1079 // enable all actions that work with multiple selection
1081 //actions
1082 bool enabled = (g_rpManager->currentGroup()!=0);
1084 if(a_ctArtSetArtRead->isEnabled() != enabled) {
1085 a_ctArtSetArtRead->setEnabled(enabled);
1086 a_ctArtSetArtUnread->setEnabled(enabled);
1087 a_ctArtSetThreadRead->setEnabled(enabled);
1088 a_ctArtSetThreadUnread->setEnabled(enabled);
1089 a_ctArtToggleIgnored->setEnabled(enabled);
1090 a_ctArtToggleWatched->setEnabled(enabled);
1091 a_ctScoreLower->setEnabled(enabled);
1092 a_ctScoreRaise->setEnabled(enabled);
1095 enabled = (f_olManager->currentFolder()!=0);
1096 a_ctArtDelete->setEnabled(enabled);
1097 a_ctArtSendNow->setEnabled(enabled && (f_olManager->currentFolder()==f_olManager->outbox()));
1101 void KNMainWidget::slotCollectionSelected()
1103 kDebug(5003) <<"KNMainWidget::slotCollectionSelected(QListViewItem *i)";
1104 if(b_lockui)
1105 return;
1106 KNCollection::Ptr c;
1107 KNNntpAccount::Ptr selectedAccount;
1108 KNGroup::Ptr selectedGroup;
1109 KNFolder::Ptr selectedFolder;
1111 s_earchLineEdit->clear();
1112 h_drView->clear();
1113 slotArticleSelected(0);
1115 // mark all articles in current group as not new/read
1116 if ( knGlobals.settings()->leaveGroupMarkAsRead() )
1117 a_rtManager->setAllRead( true );
1118 a_rtManager->setAllNotNew();
1120 QTreeWidgetItem *i = c_olView->selectedItems().value( 0 ); // Single item selection
1121 if(i) {
1122 c = static_cast<KNCollectionViewItem*>( i )->collection();
1123 switch(c->type()) {
1124 case KNCollection::CTnntpAccount :
1125 selectedAccount = boost::static_pointer_cast<KNNntpAccount>( c );
1126 if( !i->isExpanded() ) {
1127 i->setExpanded( true );
1129 break;
1130 case KNCollection::CTgroup :
1131 if ( !h_drView->hasFocus() && !mArticleViewer->hasFocus() )
1132 h_drView->setFocus();
1133 selectedGroup = boost::static_pointer_cast<KNGroup>( c );
1134 selectedAccount=selectedGroup->account();
1135 break;
1137 case KNCollection::CTfolder :
1138 if ( !h_drView->hasFocus() && !mArticleViewer->hasFocus() )
1139 h_drView->setFocus();
1140 selectedFolder = boost::static_pointer_cast<KNFolder>( c );
1141 break;
1143 default: break;
1147 a_ccManager->setCurrentAccount(selectedAccount);
1148 g_rpManager->setCurrentGroup(selectedGroup);
1149 f_olManager->setCurrentFolder(selectedFolder);
1150 if (!selectedGroup && !selectedFolder) // called from showHeaders() otherwise
1151 a_rtManager->updateStatusString();
1153 updateCaption();
1155 //actions
1156 bool enabled;
1158 enabled=(selectedGroup) || (selectedFolder && !selectedFolder->isRootFolder());
1159 if(a_ctNavNextArt->isEnabled() != enabled) {
1160 a_ctNavNextArt->setEnabled(enabled);
1161 a_ctNavPrevArt->setEnabled(enabled);
1164 enabled=( selectedGroup!=0 );
1165 if(a_ctNavNextUnreadArt->isEnabled() != enabled) {
1166 a_ctNavNextUnreadArt->setEnabled(enabled);
1167 a_ctNavNextUnreadThread->setEnabled(enabled);
1168 a_ctNavReadThrough->setEnabled(enabled);
1169 a_ctFetchArticleWithID->setEnabled(enabled);
1172 enabled=( selectedAccount!=0 );
1173 if(a_ctAccProperties->isEnabled() != enabled) {
1174 a_ctAccProperties->setEnabled(enabled);
1175 a_ctAccRename->setEnabled(enabled);
1176 a_ctAccSubscribe->setEnabled(enabled);
1177 a_ctAccExpireAll->setEnabled(enabled);
1178 a_ctAccGetNewHdrs->setEnabled(enabled);
1179 a_ctAccGetNewHdrsAll->setEnabled(enabled);
1180 a_ctAccDelete->setEnabled(enabled);
1181 //Laurent fix me
1182 //a_ctAccPostNewArticle->setEnabled(enabled);
1185 enabled=( selectedGroup!=0 );
1186 if(a_ctGrpProperties->isEnabled() != enabled) {
1187 a_ctGrpProperties->setEnabled(enabled);
1188 a_ctGrpRename->setEnabled(enabled);
1189 a_ctGrpGetNewHdrs->setEnabled(enabled);
1190 a_ctGrpExpire->setEnabled(enabled);
1191 a_ctGrpReorganize->setEnabled(enabled);
1192 a_ctGrpUnsubscribe->setEnabled(enabled);
1193 a_ctGrpSetAllRead->setEnabled(enabled);
1194 a_ctGrpSetAllUnread->setEnabled(enabled);
1195 a_ctGrpSetUnread->setEnabled(enabled);
1196 a_ctArtFilter->setEnabled(enabled);
1197 a_ctArtFilterKeyb->setEnabled(enabled);
1198 a_ctArtRefreshList->setEnabled(enabled);
1199 a_ctArtCollapseAll->setEnabled(enabled);
1200 a_ctArtExpandAll->setEnabled(enabled);
1201 a_ctArtToggleShowThreads->setEnabled(enabled);
1202 a_ctReScore->setEnabled(enabled);
1205 a_ctFolNewChild->setEnabled(selectedFolder!=0);
1207 enabled=( selectedFolder!=0 && !selectedFolder->isRootFolder() && !selectedFolder->isStandardFolder() );
1208 if(a_ctFolDelete->isEnabled() != enabled) {
1209 a_ctFolDelete->setEnabled(enabled);
1210 a_ctFolRename->setEnabled(enabled);
1213 enabled=( selectedFolder!=0 && !selectedFolder->isRootFolder() );
1214 if(a_ctFolCompact->isEnabled() != enabled) {
1215 a_ctFolCompact->setEnabled(enabled);
1216 a_ctFolEmpty->setEnabled(enabled);
1217 a_ctFolMboxImport->setEnabled(enabled);
1218 a_ctFolMboxExport->setEnabled(enabled);
1223 void KNMainWidget::slotCollectionRenamed(QTreeWidgetItem *i)
1225 kDebug(5003) <<"KNMainWidget::slotCollectionRenamed(QListViewItem *i)";
1227 if (i) {
1228 static_cast<KNCollectionViewItem*>( i )->collection()->setName( i->text( 0 ) );
1229 updateCaption();
1230 a_rtManager->updateStatusString();
1231 if ( static_cast<KNCollectionViewItem*>( i )->collection()->type() == KNCollection::CTnntpAccount ) {
1232 a_ccManager->accountRenamed( boost::static_pointer_cast<KNNntpAccount>( static_cast<KNCollectionViewItem*>( i )->collection() ) );
1234 disableAccels(false);
1239 void KNMainWidget::slotArticleRMB(K3ListView*, Q3ListViewItem *i, const QPoint &p)
1241 if(b_lockui)
1242 return;
1244 if(i) {
1245 QMenu *popup;
1246 if( (static_cast<KNHdrViewItem*>(i))->art->type()==KNArticle::ATremote) {
1247 popup = popupMenu( "remote_popup" );
1248 } else {
1249 popup = popupMenu( "local_popup" );
1252 if ( popup )
1253 popup->popup(p);
1258 void KNMainWidget::slotCollectionRMB( QTreeWidgetItem *i, const QPoint &pos )
1260 if(b_lockui)
1261 return;
1263 if(i) {
1264 QMenu *popup = 0;
1265 if( static_cast<KNCollectionViewItem*>( i )->collection()->type() == KNCollection::CTgroup ) {
1266 popup = popupMenu( "group_popup" );
1267 } else if ( static_cast<KNCollectionViewItem*>( i )->collection()->type() == KNCollection::CTfolder ) {
1268 if ( boost::static_pointer_cast<KNFolder>( static_cast<KNCollectionViewItem*>( i )->collection() )->isRootFolder() ) {
1269 popup = popupMenu( "root_folder_popup" );
1270 } else {
1271 popup = popupMenu( "folder_popup" );
1273 } else {
1274 popup = popupMenu( "account_popup" );
1276 if ( popup ) {
1277 popup->popup( pos );
1283 void KNMainWidget::slotOpenArticle(Q3ListViewItem *item)
1285 if(b_lockui)
1286 return;
1288 if (item) {
1289 KNArticle::Ptr art = (static_cast<KNHdrViewItem*>(item))->art;
1291 if ((art->type()==KNArticle::ATlocal) && ((f_olManager->currentFolder()==f_olManager->outbox())||
1292 (f_olManager->currentFolder()==f_olManager->drafts()))) {
1293 a_rtFactory->edit( boost::static_pointer_cast<KNLocalArticle>( art ) );
1294 } else {
1295 if ( !ArticleWindow::raiseWindowForArticle( art ) ) {
1296 ArticleWindow *w = new ArticleWindow( art );
1297 w->show();
1304 void KNMainWidget::slotHdrViewSortingChanged(int i)
1306 a_ctArtSortHeaders->setCurrentItem(i);
1310 void KNMainWidget::slotNetworkActive(bool b)
1312 a_ctNetCancel->setEnabled(b);
1316 //------------------------------ <Actions> --------------------------------
1319 void KNMainWidget::slotNavNextUnreadArt()
1321 if ( !h_drView->nextUnreadArticle() )
1322 c_olView->nextGroup();
1326 void KNMainWidget::slotNavNextUnreadThread()
1328 if ( !h_drView->nextUnreadThread() )
1329 c_olView->nextGroup();
1333 void KNMainWidget::slotNavReadThrough()
1335 kDebug(5003) <<"KNMainWidget::slotNavReadThrough()";
1336 if ( !mArticleViewer->atBottom() )
1337 mArticleViewer->scrollNext();
1338 else if(g_rpManager->currentGroup() != 0)
1339 slotNavNextUnreadArt();
1343 void KNMainWidget::slotAccProperties()
1345 kDebug(5003) <<"KNMainWidget::slotAccProperties()";
1346 if(a_ccManager->currentAccount())
1347 a_ccManager->editProperties(a_ccManager->currentAccount());
1348 updateCaption();
1349 a_rtManager->updateStatusString();
1353 void KNMainWidget::slotAccRename()
1355 kDebug(5003) <<"KNMainWidget::slotAccRename()";
1356 if(a_ccManager->currentAccount()) {
1357 // disableAccels(true); // hack: global accels break the inplace renaming
1358 c_olView->editItem( a_ccManager->currentAccount()->listItem(), c_olView->labelColumnIndex() );
1363 void KNMainWidget::slotAccSubscribe()
1365 kDebug(5003) <<"KNMainWidget::slotAccSubscribe()";
1366 if(a_ccManager->currentAccount())
1367 g_rpManager->showGroupDialog(a_ccManager->currentAccount());
1371 void KNMainWidget::slotAccExpireAll()
1373 kDebug(5003) <<"KNMainWidget::slotAccExpireAll()";
1374 if(a_ccManager->currentAccount())
1375 g_rpManager->expireAll(a_ccManager->currentAccount());
1379 void KNMainWidget::slotAccGetNewHdrs()
1381 kDebug(5003) <<"KNMainWidget::slotAccGetNewHdrs()";
1382 if(a_ccManager->currentAccount())
1383 g_rpManager->checkAll(a_ccManager->currentAccount());
1388 void KNMainWidget::slotAccDelete()
1390 kDebug(5003) <<"KNMainWidget::slotAccDelete()";
1391 if(a_ccManager->currentAccount()) {
1392 if (a_ccManager->removeAccount(a_ccManager->currentAccount()))
1393 slotCollectionSelected();
1397 void KNMainWidget::slotAccGetNewHdrsAll()
1399 KNNntpAccount::List list = a_ccManager->accounts();
1400 for ( KNNntpAccount::List::Iterator it = list.begin(); it != list.end(); ++it )
1401 g_rpManager->checkAll( *it );
1404 void KNMainWidget::slotAccPostNewArticle()
1406 kDebug(5003) <<"KNMainWidget::slotAccPostNewArticle()";
1407 if(g_rpManager->currentGroup())
1408 a_rtFactory->createPosting(g_rpManager->currentGroup());
1409 else if(a_ccManager->currentAccount())
1410 a_rtFactory->createPosting(a_ccManager->currentAccount());
1414 void KNMainWidget::slotGrpProperties()
1416 kDebug(5003) <<"slotGrpProperties()";
1417 if(g_rpManager->currentGroup())
1418 g_rpManager->showGroupProperties(g_rpManager->currentGroup());
1419 updateCaption();
1420 a_rtManager->updateStatusString();
1424 void KNMainWidget::slotGrpRename()
1426 kDebug(5003) <<"slotGrpRename()";
1427 if(g_rpManager->currentGroup()) {
1428 // disableAccels(true); // hack: global accels break the inplace renaming
1429 c_olView->editItem( g_rpManager->currentGroup()->listItem(), c_olView->labelColumnIndex() );
1434 void KNMainWidget::slotGrpGetNewHdrs()
1436 kDebug(5003) <<"KNMainWidget::slotGrpGetNewHdrs()";
1437 if(g_rpManager->currentGroup())
1438 g_rpManager->checkGroupForNewHeaders(g_rpManager->currentGroup());
1442 void KNMainWidget::slotGrpExpire()
1444 kDebug(5003) <<"KNMainWidget::slotGrpExpire()";
1445 if(g_rpManager->currentGroup())
1446 g_rpManager->expireGroupNow(g_rpManager->currentGroup());
1450 void KNMainWidget::slotGrpReorganize()
1452 kDebug(5003) <<"KNMainWidget::slotGrpReorganize()";
1453 g_rpManager->reorganizeGroup(g_rpManager->currentGroup());
1457 void KNMainWidget::slotGrpUnsubscribe()
1459 kDebug(5003) <<"KNMainWidget::slotGrpUnsubscribe()";
1460 if(g_rpManager->currentGroup()) {
1461 if(KMessageBox::Yes==KMessageBox::questionYesNo(knGlobals.topWidget,
1462 i18n("Do you really want to unsubscribe from %1?", g_rpManager->currentGroup()->groupname()), QString(), KGuiItem(i18n("Unsubscribe")), KStandardGuiItem::cancel()))
1463 if (g_rpManager->unsubscribeGroup(g_rpManager->currentGroup()))
1464 slotCollectionSelected();
1469 void KNMainWidget::slotGrpSetAllRead()
1471 kDebug(5003) <<"KNMainWidget::slotGrpSetAllRead()";
1473 a_rtManager->setAllRead(true);
1474 if ( knGlobals.settings()->markAllReadGoNext() )
1475 c_olView->nextGroup();
1479 void KNMainWidget::slotGrpSetAllUnread()
1481 kDebug(5003) <<"KNMainWidget::slotGrpSetAllUnread()";
1482 a_rtManager->setAllRead(false);
1485 void KNMainWidget::slotGrpSetUnread()
1487 kDebug(5003) <<"KNMainWidget::slotGrpSetUnread()";
1488 int groupLength = g_rpManager->currentGroup()->length();
1490 bool ok = false;
1491 int res = KInputDialog::getInteger(
1492 i18n( "Mark Last as Unread" ),
1493 i18n( "Enter how many articles should be marked unread:" ), groupLength, 1, groupLength, 1, &ok, this );
1494 if ( ok )
1495 a_rtManager->setAllRead( false, res );
1498 void KNMainWidget::slotFolNew()
1500 kDebug(5003) <<"KNMainWidget::slotFolNew()";
1501 KNFolder::Ptr f = f_olManager->newFolder( KNFolder::Ptr() );
1503 if (f) {
1504 f_olManager->setCurrentFolder(f);
1505 c_olView->setActive( f->listItem() );
1506 slotFolRename();
1511 void KNMainWidget::slotFolNewChild()
1513 kDebug(5003) <<"KNMainWidget::slotFolNew()";
1514 if(f_olManager->currentFolder()) {
1515 KNFolder::Ptr f = f_olManager->newFolder( f_olManager->currentFolder() );
1517 if (f) {
1518 f_olManager->setCurrentFolder(f);
1519 c_olView->setActive( f->listItem() );
1520 slotFolRename();
1526 void KNMainWidget::slotFolDelete()
1528 kDebug(5003) <<"KNMainWidget::slotFolDelete()";
1530 if(!f_olManager->currentFolder() || f_olManager->currentFolder()->isRootFolder())
1531 return;
1533 if(f_olManager->currentFolder()->isStandardFolder())
1534 KMessageBox::sorry(knGlobals.topWidget, i18n("You cannot delete a standard folder."));
1536 else if( KMessageBox::Continue==KMessageBox::warningContinueCancel(knGlobals.topWidget,
1537 i18n("Do you really want to delete this folder and all its children?"),"",KGuiItem(i18n("&Delete"),"edit-delete")) ) {
1539 if(!f_olManager->deleteFolder(f_olManager->currentFolder()))
1540 KMessageBox::sorry(knGlobals.topWidget,
1541 i18n("This folder cannot be deleted because some of\n its articles are currently in use.") );
1542 else
1543 slotCollectionSelected();
1548 void KNMainWidget::slotFolRename()
1550 kDebug(5003) <<"KNMainWidget::slotFolRename()";
1552 if(f_olManager->currentFolder() && !f_olManager->currentFolder()->isRootFolder()) {
1553 if(f_olManager->currentFolder()->isStandardFolder())
1554 KMessageBox::sorry(knGlobals.topWidget, i18n("You cannot rename a standard folder."));
1555 else {
1556 // disableAccels(true); // hack: global accels break the inplace renaming
1557 c_olView->editItem( f_olManager->currentFolder()->listItem(), c_olView->labelColumnIndex() );
1563 void KNMainWidget::slotFolCompact()
1565 kDebug(5003) <<"KNMainWidget::slotFolCompact()";
1566 if(f_olManager->currentFolder() && !f_olManager->currentFolder()->isRootFolder())
1567 f_olManager->compactFolder(f_olManager->currentFolder());
1571 void KNMainWidget::slotFolCompactAll()
1573 kDebug(5003) <<"KNMainWidget::slotFolCompactAll()";
1574 f_olManager->compactAll();
1578 void KNMainWidget::slotFolEmpty()
1580 kDebug(5003) <<"KNMainWidget::slotFolEmpty()";
1581 if(f_olManager->currentFolder() && !f_olManager->currentFolder()->isRootFolder()) {
1582 if(f_olManager->currentFolder()->lockedArticles()>0) {
1583 KMessageBox::sorry(this,
1584 i18n("This folder cannot be emptied at the moment\nbecause some of its articles are currently in use.") );
1585 return;
1587 if( KMessageBox::Continue == KMessageBox::warningContinueCancel(
1588 this, i18n("Do you really want to delete all articles in %1?", f_olManager->currentFolder()->name()),"",KGuiItem(i18n("&Delete"),"edit-delete")) )
1589 f_olManager->emptyFolder(f_olManager->currentFolder());
1594 void KNMainWidget::slotFolMBoxImport()
1596 kDebug(5003) <<"KNMainWidget::slotFolMBoxImport()";
1597 if(f_olManager->currentFolder() && !f_olManager->currentFolder()->isRootFolder()) {
1598 f_olManager->importFromMBox(f_olManager->currentFolder());
1603 void KNMainWidget::slotFolMBoxExport()
1605 kDebug(5003) <<"KNMainWidget::slotFolMBoxExport()";
1606 if(f_olManager->currentFolder() && !f_olManager->currentFolder()->isRootFolder()) {
1607 f_olManager->exportToMBox(f_olManager->currentFolder());
1612 void KNMainWidget::slotArtSortHeaders(int i)
1614 kDebug(5003) <<"KNMainWidget::slotArtSortHeaders(int i)";
1615 h_drView->setSorting( i );
1619 void KNMainWidget::slotArtSortHeadersKeyb()
1621 kDebug(5003) <<"KNMainWidget::slotArtSortHeadersKeyb()";
1623 int newCol = KNHelper::selectDialog(this, i18n("Select Sort Column"), a_ctArtSortHeaders->items(), a_ctArtSortHeaders->currentItem());
1624 if (newCol != -1)
1625 h_drView->setSorting( newCol );
1629 void KNMainWidget::slotArtSearch()
1631 kDebug(5003) <<"KNMainWidget::slotArtSearch()";
1632 a_rtManager->search();
1636 void KNMainWidget::slotArtRefreshList()
1638 kDebug(5003) <<"KNMainWidget::slotArtRefreshList()";
1639 a_rtManager->showHdrs(true);
1643 void KNMainWidget::slotArtCollapseAll()
1645 kDebug(5003) <<"KNMainWidget::slotArtCollapseAll()";
1647 closeCurrentThread();
1648 a_rtManager->setAllThreadsOpen(false);
1649 if (h_drView->currentItem())
1650 h_drView->ensureItemVisible(h_drView->currentItem());
1654 void KNMainWidget::slotArtExpandAll()
1656 kDebug(5003) <<"KNMainWidget::slotArtExpandAll()";
1658 a_rtManager->setAllThreadsOpen(true);
1659 if (h_drView->currentItem())
1660 h_drView->ensureItemVisible(h_drView->currentItem());
1664 void KNMainWidget::slotArtToggleThread()
1666 kDebug(5003) <<"KNMainWidget::slotArtToggleThread()";
1667 if( mArticleViewer->article() && mArticleViewer->article()->listItem()->isExpandable() ) {
1668 bool o = !(mArticleViewer->article()->listItem()->isOpen());
1669 mArticleViewer->article()->listItem()->setOpen( o );
1674 void KNMainWidget::slotArtToggleShowThreads()
1676 kDebug(5003) <<"KNMainWidget::slotArtToggleShowThreads()";
1677 if(g_rpManager->currentGroup()) {
1678 knGlobals.settings()->setShowThreads( !knGlobals.settings()->showThreads() );
1679 a_rtManager->showHdrs(true);
1684 void KNMainWidget::slotArtSetArtRead()
1686 kDebug(5003) <<"KNMainWidget::slotArtSetArtRead()";
1687 if(!g_rpManager->currentGroup())
1688 return;
1690 KNRemoteArticle::List l;
1691 getSelectedArticles(l);
1692 a_rtManager->setRead(l, true);
1696 void KNMainWidget::slotArtSetArtUnread()
1698 kDebug(5003) <<"KNMainWidget::slotArtSetArtUnread()";
1699 if(!g_rpManager->currentGroup())
1700 return;
1702 KNRemoteArticle::List l;
1703 getSelectedArticles(l);
1704 a_rtManager->setRead(l, false);
1708 void KNMainWidget::slotArtSetThreadRead()
1710 kDebug(5003) <<"slotArtSetThreadRead()";
1711 if( !g_rpManager->currentGroup() )
1712 return;
1714 KNRemoteArticle::List l;
1715 getSelectedThreads(l);
1716 a_rtManager->setRead(l, true);
1718 if (h_drView->currentItem()) {
1719 if ( knGlobals.settings()->markThreadReadCloseThread() )
1720 closeCurrentThread();
1721 if ( knGlobals.settings()->markThreadReadGoNext() )
1722 slotNavNextUnreadThread();
1727 void KNMainWidget::slotArtSetThreadUnread()
1729 kDebug(5003) <<"KNMainWidget::slotArtSetThreadUnread()";
1730 if( !g_rpManager->currentGroup() )
1731 return;
1733 KNRemoteArticle::List l;
1734 getSelectedThreads(l);
1735 a_rtManager->setRead(l, false);
1739 void KNMainWidget::slotScoreEdit()
1741 kDebug(5003) <<"KNMainWidget::slotScoreEdit()";
1742 s_coreManager->configure();
1746 void KNMainWidget::slotReScore()
1748 kDebug(5003) <<"KNMainWidget::slotReScore()";
1749 if( !g_rpManager->currentGroup() )
1750 return;
1752 g_rpManager->currentGroup()->scoreArticles(false);
1753 a_rtManager->showHdrs(true);
1757 void KNMainWidget::slotScoreLower()
1759 kDebug(5003) <<"KNMainWidget::slotScoreLower() start";
1760 if( !g_rpManager->currentGroup() )
1761 return;
1763 if ( mArticleViewer->article() && mArticleViewer->article()->type() == KNArticle::ATremote ) {
1764 KNRemoteArticle::Ptr ra = boost::static_pointer_cast<KNRemoteArticle>( mArticleViewer->article() );
1765 s_coreManager->addRule(KNScorableArticle(ra), g_rpManager->currentGroup()->groupname(), -10);
1770 void KNMainWidget::slotScoreRaise()
1772 kDebug(5003) <<"KNMainWidget::slotScoreRaise() start";
1773 if( !g_rpManager->currentGroup() )
1774 return;
1776 if ( mArticleViewer->article() && mArticleViewer->article()->type() == KNArticle::ATremote ) {
1777 KNRemoteArticle::Ptr ra = boost::static_pointer_cast<KNRemoteArticle>( mArticleViewer->article() );
1778 s_coreManager->addRule(KNScorableArticle(ra), g_rpManager->currentGroup()->groupname(), +10);
1783 void KNMainWidget::slotArtToggleIgnored()
1785 kDebug(5003) <<"KNMainWidget::slotArtToggleIgnored()";
1786 if( !g_rpManager->currentGroup() )
1787 return;
1789 KNRemoteArticle::List l;
1790 getSelectedThreads(l);
1791 bool revert = !a_rtManager->toggleIgnored(l);
1792 a_rtManager->rescoreArticles(l);
1794 if (h_drView->currentItem() && !revert) {
1795 if ( knGlobals.settings()->ignoreThreadCloseThread() )
1796 closeCurrentThread();
1797 if ( knGlobals.settings()->ignoreThreadGoNext() )
1798 slotNavNextUnreadThread();
1803 void KNMainWidget::slotArtToggleWatched()
1805 kDebug(5003) <<"KNMainWidget::slotArtToggleWatched()";
1806 if( !g_rpManager->currentGroup() )
1807 return;
1809 KNRemoteArticle::List l;
1810 getSelectedThreads(l);
1811 a_rtManager->toggleWatched(l);
1812 a_rtManager->rescoreArticles(l);
1816 void KNMainWidget::slotArtOpenNewWindow()
1818 kDebug(5003) <<"KNMainWidget::slotArtOpenNewWindow()";
1820 if( mArticleViewer->article() ) {
1821 if ( !ArticleWindow::raiseWindowForArticle( mArticleViewer->article() ) ) {
1822 ArticleWindow *win = new ArticleWindow( mArticleViewer->article() );
1823 win->show();
1829 void KNMainWidget::slotArtSendOutbox()
1831 kDebug(5003) <<"KNMainWidget::slotArtSendOutbox()";
1832 a_rtFactory->sendOutbox();
1836 void KNMainWidget::slotArtDelete()
1838 kDebug(5003) <<"KNMainWidget::slotArtDelete()";
1839 if (!f_olManager->currentFolder())
1840 return;
1842 KNLocalArticle::List lst;
1843 getSelectedArticles(lst);
1845 if(!lst.isEmpty())
1846 a_rtManager->deleteArticles(lst);
1848 if(h_drView->currentItem())
1849 h_drView->setActive( h_drView->currentItem() );
1853 void KNMainWidget::slotArtSendNow()
1855 kDebug(5003) <<"KNMainWidget::slotArtSendNow()";
1856 if (!f_olManager->currentFolder())
1857 return;
1859 KNLocalArticle::List lst;
1860 getSelectedArticles(lst);
1862 if(!lst.isEmpty())
1863 a_rtFactory->sendArticles( lst, true );
1867 void KNMainWidget::slotArtEdit()
1869 kDebug(5003) <<"KNodeVew::slotArtEdit()";
1870 if (!f_olManager->currentFolder())
1871 return;
1873 if ( mArticleViewer->article() && mArticleViewer->article()->type() == KNArticle::ATlocal )
1874 a_rtFactory->edit( boost::static_pointer_cast<KNLocalArticle>( mArticleViewer->article() ) );
1878 void KNMainWidget::slotNetCancel()
1880 kDebug(5003) <<"KNMainWidget::slotNetCancel()";
1881 knGlobals.scheduler()->cancelJobs();
1885 void KNMainWidget::slotFetchArticleWithID()
1887 kDebug(5003) <<"KNMainWidget::slotFetchArticleWithID()";
1888 if( !g_rpManager->currentGroup() )
1889 return;
1891 FetchArticleIdDlg *dlg = new FetchArticleIdDlg( this );
1892 dlg->setObjectName( "messageid" );
1894 if (dlg->exec()) {
1895 QString id = dlg->messageId().simplified();
1896 if ( id.indexOf( QRegExp("*@*", Qt::CaseInsensitive, QRegExp::Wildcard) ) != -1 ) {
1897 if ( id.indexOf( QRegExp("<*>", Qt::CaseInsensitive, QRegExp::Wildcard) ) == -1 ) // add "<>" when necessary
1898 id = QString("<%1>").arg(id);
1900 if ( !ArticleWindow::raiseWindowForArticle( id.toLatin1() ) ) { //article not yet opened
1901 KNRemoteArticle::Ptr a( new KNRemoteArticle( g_rpManager->currentGroup() ) );
1902 a->messageID()->from7BitString(id.toLatin1());
1903 ArticleWindow *awin = new ArticleWindow( a );
1904 awin->show();
1909 KNHelper::saveWindowSize("fetchArticleWithID",dlg->size());
1910 delete dlg;
1914 void KNMainWidget::slotToggleQuickSearch()
1916 if (q_uicksearch->isHidden())
1917 q_uicksearch->show();
1918 else
1919 q_uicksearch->hide();
1923 void KNMainWidget::slotSettings()
1925 c_fgManager->configure();
1928 KActionCollection* KNMainWidget::actionCollection() const
1930 return m_GUIClient->actionCollection();
1933 QMenu * KNMainWidget::popupMenu( const QString &name ) const
1935 Q_ASSERT( m_GUIClient );
1936 Q_ASSERT( m_GUIClient->factory() );
1937 return static_cast<QMenu*>( m_GUIClient->factory()->container( name, m_GUIClient ) );
1940 //--------------------------------
1943 KNode::FetchArticleIdDlg::FetchArticleIdDlg( QWidget *parent ) :
1944 KDialog( parent )
1946 setCaption( i18n("Fetch Article with ID") );
1947 setButtons( KDialog::Ok | KDialog::Cancel );
1948 setModal( true );
1949 KHBox *page = new KHBox( this );
1950 setMainWidget( page );
1952 QLabel *label = new QLabel(i18n("&Message-ID:"),page);
1953 edit = new KLineEdit(page);
1954 label->setBuddy(edit);
1955 edit->setFocus();
1956 enableButtonOk( false );
1957 setButtonText( KDialog::Ok, i18n("&Fetch") );
1958 connect( edit, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
1959 KNHelper::restoreWindowSize("fetchArticleWithID", this, QSize(325,66));
1962 QString KNode::FetchArticleIdDlg::messageId() const
1964 return edit->text();
1967 void KNode::FetchArticleIdDlg::slotTextChanged(const QString &_text )
1969 enableButtonOk( !_text.isEmpty() );
1973 ////////////////////////////////////////////////////////////////////////
1974 //////////////////////// D-Bus implementation
1975 // Move to the next article
1976 void KNMainWidget::nextArticle()
1978 h_drView->nextArticle();
1981 // Move to the previous article
1982 void KNMainWidget::previousArticle()
1984 h_drView->prevArticle();
1987 // Move to the next unread article
1988 void KNMainWidget::nextUnreadArticle()
1990 slotNavNextUnreadArt();
1993 // Move to the next unread thread
1994 void KNMainWidget::nextUnreadThread()
1996 slotNavNextUnreadThread();
1999 // Move to the next group
2000 void KNMainWidget::nextGroup()
2002 c_olView->nextGroup();
2005 // Move to the previous group
2006 void KNMainWidget::previousGroup()
2008 c_olView->prevGroup();
2011 void KNMainWidget::fetchHeaders()
2013 // Simply call the slot
2014 slotAccGetNewHdrs();
2017 void KNMainWidget::expireArticles()
2019 slotAccExpireAll();
2022 // Open the editor to post a new article in the selected group
2023 void KNMainWidget::postArticle()
2025 slotAccPostNewArticle();
2028 // Fetch the new headers in the selected groups
2029 void KNMainWidget::fetchHeadersInCurrentGroup()
2031 slotGrpGetNewHdrs();
2034 // Expire the articles in the current group
2035 void KNMainWidget::expireArticlesInCurrentGroup()
2037 slotGrpExpire();
2040 // Mark all the articles in the current group as read
2041 void KNMainWidget::markAllAsRead()
2043 slotGrpSetAllRead();
2046 // Mark all the articles in the current group as unread
2047 void KNMainWidget::markAllAsUnread()
2049 slotGrpSetAllUnread();
2052 // Mark the current article as read
2053 void KNMainWidget::markAsRead()
2055 slotArtSetArtRead();
2058 // Mark the current article as unread
2059 void KNMainWidget::markAsUnread()
2061 slotArtSetArtUnread();
2064 // Mark the current thread as read
2065 void KNMainWidget::markThreadAsRead()
2067 slotArtSetThreadRead();
2070 // Mark the current thread as unread
2071 void KNMainWidget::markThreadAsUnread()
2073 slotArtSetThreadUnread();
2076 // Send the pending articles
2077 void KNMainWidget::sendPendingMessages()
2079 slotArtSendOutbox();
2082 // Delete the current article
2083 void KNMainWidget::deleteArticle()
2085 slotArtDelete();
2088 // Send the current article
2089 void KNMainWidget::sendNow()
2091 slotArtSendNow();
2094 // Edit the current article
2095 void KNMainWidget::editArticle()
2097 slotArtEdit();
2100 bool KNMainWidget::handleCommandLine()
2102 bool doneSomething = false;
2103 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
2104 if (args->count()>0) {
2105 KUrl url=args->url(0); // we take only one URL
2106 openURL(url);
2107 doneSomething = true;
2109 args->clear();
2110 return doneSomething;
2113 //////////////////////// end D-Bus implementation
2114 ////////////////////////////////////////////////////////////////////////