1 /***************************************************************************
2 * Copyright (C) 2004 by Kita Developers *
3 * ikemo@users.sourceforge.jp *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
11 #include "threadtabwidget.h"
12 #include "threadview.h"
15 #include "libkita/kita_misc.h"
16 #include "libkita/parsemisc.h"
17 #include "libkita/signalcollection.h"
18 #include "libkita/datmanager.h"
19 #include "libkita/boardmanager.h"
20 #include "libkita/kita-utf8.h"
21 #include "libkita/kitaconfig.h"
22 #include "libkita/config_xt.h"
25 #include <kstdaccel.h>
29 #include <kpopupmenu.h>
31 #include <qapplication.h>
33 #include <qclipboard.h>
34 #include <qmessagebox.h>
37 /*--------------------------------------------------------------------------------*/
40 KitaThreadTabWidget::KitaThreadTabWidget( QWidget* parent, const char* name, WFlags f )
41 : KitaTabWidgetBase( parent, name, f )
43 setXMLFile( "threadtabwidgetui.rc" );
49 createView( "thread" );
53 KitaThreadTabWidget::~KitaThreadTabWidget() {}
56 /* show "Main thread" view */ /* public slots */
57 void KitaThreadTabWidget::slotShowMainThread( const KURL& url )
60 KURL datURL = Kita::ParseMisc::parseURL( url, refstr );
61 QString threadName = Kita::DatManager::threadName( datURL );
64 int viewMode = VIEWMODE_MAINVIEW;
65 KitaThreadView* currentView = isThreadView( currentPage() );
66 if ( currentView ) viewMode = currentView->getViewMode();
68 if ( refstr != QString::null ) {
69 int i = refstr.find( "-" );
70 if ( i != -1 ) jumpNum = refstr.left( i ).toInt();
71 else jumpNum = refstr.toInt();
74 KitaThreadView* view = findMainView( datURL );
78 setCurrentPage( indexOf( view ) );
80 if ( view->threadURL().isEmpty() ) {
81 /* Show on the default view */
82 view->showThread( datURL, jumpNum );
84 /* The view is already shown */
85 /* TODO: jump to jumpNum after reloading */
87 view->slotReloadButton( jumpNum );
91 KitaThreadView * newView = createView( threadName );
94 newView->showThread( datURL, jumpNum );
99 slotUpdateThreadTab( datURL );
102 /* close "all" views which URL is url. */ /* public slot */
103 void KitaThreadTabWidget::slotCloseThreadTab( const KURL& url )
106 if ( max == 0 ) return ;
107 KURL datURL = Kita::ParseMisc::parseURLonly( url );
112 KitaThreadView * view = isThreadView( page ( i ) );
114 if ( view->datURL() == datURL ) {
125 /* create KitaThreadView */ /* private */
126 KitaThreadView* KitaThreadTabWidget::createView( QString label )
128 KitaThreadView * view = new KitaThreadView( this );
130 addTab( view, label );
138 void KitaThreadTabWidget::connectSignals()
140 Kita::SignalCollection * signalCollection = Kita::SignalCollection::getInstance();
142 connect( signalCollection, SIGNAL( updateThreadTab( const KURL& ) ),
143 this, SLOT( slotUpdateThreadTab( const KURL& ) ) );
144 connect( signalCollection, SIGNAL( threadFaceChanged() ),
145 SLOT( slotFontChanged() ) );
150 KitaThreadView* KitaThreadTabWidget::findMainView( const KURL& url )
152 KURL datURL = Kita::ParseMisc::parseURLonly( url );
155 if ( max == 0 ) return NULL;
159 KitaThreadView * view = isThreadView( page ( i ) );
161 if ( view->getViewMode() == VIEWMODE_MAINVIEW ) {
163 if ( view->datURL() == datURL
164 || view->datURL().isEmpty() /* default view */
176 KitaThreadView* KitaThreadTabWidget::isThreadView( QWidget* w )
178 KitaThreadView * view = NULL;
180 if ( w->isA( "KitaThreadView" ) ) view = static_cast< KitaThreadView* >( w );
188 void KitaThreadTabWidget::slotUpdateThreadTab( const KURL& url )
190 KURL datURL = Kita::ParseMisc::parseURLonly( url );
192 KitaThreadView * view = findMainView( datURL );
194 QString threadName = Kita::DatManager::threadName( datURL );
196 setTabLabel( view, threadName );
197 setTabToolTip( view, threadName );
201 void KitaThreadTabWidget::slotFontChanged()
203 QFont font = Kita::Config::threadFont();
207 /* protected */ /* virtual */
208 void KitaThreadTabWidget::deleteWidget( QWidget* w )
210 KitaTabWidgetBase::deleteWidget( w );
212 if ( count() == 0 ) {
213 emit setMainCaption( QString::null );
214 emit setMainStatusbar( QString::null );
215 emit setMainURLLine( QString::null );
218 KitaThreadView * threadView = createView( "thread" );
221 showPage( threadView );
222 emit switchToSubject();
229 /*--------------------------------*/
230 /* KitaThreadView actions */
234 void KitaThreadTabWidget::setupActions()
236 KStdAction::copy( this, SLOT( slotCopyText() ), actionCollection() );
238 new KAction( i18n( "Open with Web Browser" ),
241 SLOT( slotOpenBrowser() ),
243 "threadview_openbrowser" );
245 new KAction( i18n( "copy URL" ),
248 SLOT( slotCopyURL() ),
250 "threadview_copyurl" );
252 new KAction( i18n( "Copy title and URL" ),
255 SLOT( slotCopyTitleURL() ),
257 "threadview_copytitleurl" );
259 new KAction( i18n( "Find" ),
263 SLOT( slotFocusSearchCombo() ),
267 KStdAction::findNext( this,
268 SLOT( slotSearchNext() ),
270 "threadview_findnext" );
272 KStdAction::findPrev( this,
273 SLOT( slotSearchPrev() ),
275 "threadview_findprev" );
277 new KAction( i18n( "go back anchor" ),
281 SLOT( slotGobackAnchor() ),
283 "threadview_goback" );
285 new KAction( i18n( "Start" ),
289 SLOT( slotGotoHeader() ),
291 "threadview_gotoheader" );
293 new KAction( i18n( "End" ),
297 SLOT( slotGotoFooter() ),
299 "threadview_gotofooter" );
301 new KAction( i18n( "Reload" ),
305 SLOT( slotReloadButton() ),
307 "threadview_reload" );
309 new KAction( i18n( "Stop" ),
313 SLOT( slotStopLoading() ),
317 new KAction( i18n( "Delete" ),
321 SLOT( slotDeleteButtonClicked() ),
323 "threadview_delete" );
328 /* KitaThreadView actions */
330 /* copy selected text (Ctrl+C) */ /* public slot */
331 void KitaThreadTabWidget::slotCopyText()
333 QWidget * w = currentPage();
334 KitaThreadView * view = isThreadView( w );
336 QClipboard * clipboard = QApplication::clipboard();
337 QString text = view->selectedText();
338 clipboard->setText( text, QClipboard::Clipboard );
343 void KitaThreadTabWidget::slotOpenBrowser( int idx )
345 QWidget * w = currentPage();
346 if ( idx != -1 ) w = page( idx );
351 KitaThreadView * view = isThreadView( w );
353 new KRun( view->threadURL() );
357 KParts::Part* part = findPartFromWidget( w );
358 if ( part && part->inherits( "KParts::ReadOnlyPart" ) ) {
359 url = static_cast<KParts::ReadOnlyPart*>( part ) ->url();
368 void KitaThreadTabWidget::slotCopyURL( int idx )
370 QWidget * w = currentPage();
371 if ( idx != -1 ) w = page( idx );
373 QClipboard* clipboard = QApplication::clipboard();
375 KitaThreadView * view = isThreadView( w );
377 KURL datURL = view->datURL();
379 QString cliptxt = Kita::DatManager::threadURL( datURL );
380 clipboard->setText( cliptxt , QClipboard::Clipboard );
381 clipboard->setText( cliptxt , QClipboard::Selection );
387 void KitaThreadTabWidget::slotCopyTitleURL( int idx )
389 QWidget * w = currentPage();
390 if ( idx != -1 ) w = page( idx );
392 QClipboard* clipboard = QApplication::clipboard();
394 KitaThreadView * view = isThreadView( w );
396 KURL datURL = view->datURL();
398 QString cliptxt = Kita::DatManager::threadName( datURL )
399 + "\n" + Kita::DatManager::threadURL( datURL );
400 clipboard->setText( cliptxt , QClipboard::Clipboard );
401 clipboard->setText( cliptxt , QClipboard::Selection );
407 void KitaThreadTabWidget::slotFocusSearchCombo()
409 KitaThreadView * view = isThreadView( currentPage() );
410 if ( view ) view->focusSearchCombo();
415 void KitaThreadTabWidget::slotSearchNext()
417 KitaThreadView * view = isThreadView( currentPage() );
418 if ( view ) view->slotSearchNext();
423 void KitaThreadTabWidget::slotSearchPrev()
425 KitaThreadView * view = isThreadView( currentPage() );
426 if ( view ) view->slotSearchPrev();
431 void KitaThreadTabWidget::slotGobackAnchor()
433 KitaThreadView * view = isThreadView( currentPage() );
434 if ( view ) view->slotGobackAnchor();
439 void KitaThreadTabWidget::slotGotoHeader()
441 KitaThreadView * view = isThreadView( currentPage() );
442 if ( view ) view->slotGotoHeader();
447 void KitaThreadTabWidget::slotGotoFooter()
449 KitaThreadView * view = isThreadView( currentPage() );
450 if ( view ) view->slotGotoFooter();
455 void KitaThreadTabWidget::slotReloadButton()
457 KitaThreadView * view = isThreadView( currentPage() );
458 if ( view ) view->slotReloadButton();
463 void KitaThreadTabWidget::slotStopLoading()
465 KitaThreadView * view = isThreadView( currentPage() );
466 if ( view ) view->slotStopLoading();
471 void KitaThreadTabWidget::slotDeleteButtonClicked()
473 KitaThreadView * view = isThreadView( currentPage() );
474 if ( view ) view->slotDeleteButtonClicked();
478 /*---------------------------------------------------------------------*/
479 /*---------------------------------------------------------------------*/
480 /*---------------------------------------------------------------------*/
482 /*---------------------------------------------------------------------*/
483 /*---------------------------------------------------------------------*/
484 /*---------------------------------------------------------------------*/
487 /* Don't forget to call setup later ! */
488 KitaThreadDock::KitaThreadDock( KDockManager* dockManager,
490 const QPixmap &pixmap,
492 const QString& strCaption,
493 const QString& strTabPageLabel,
495 : KitaDockWidgetBase( dockManager, name, pixmap, parent, strCaption, strTabPageLabel, f ) {}
498 KitaThreadDock::~KitaThreadDock() {}
501 /*-----------------------------*/
502 /* Main Thread View */
504 /* setup thig dock as main thread view */ /* public */
505 KitaThreadTabWidget* KitaThreadDock::setupAsMainView()
507 m_threadTab = new KitaThreadTabWidget( this, "Thread View" );
508 setWidget( m_threadTab );
510 Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
511 connect( signalCollection, SIGNAL( switchToThread() ),
512 SLOT( slotShowThreadDock() ) );
518 void KitaThreadDock::slotShowThread( const KURL& url )
522 if ( m_threadTab ) m_threadTab->slotShowMainThread( url );
525 /* show Thread Dock */ /* private slot */
526 void KitaThreadDock::slotShowThreadDock()
528 QWidget * topWidget = topLevelWidget();
529 if ( topWidget->isMinimized() ) topWidget->showNormal();
531 topWidget->setActiveWindow();