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 );
228 /*--------------------------------*/
229 /* KitaThreadView actions */
233 void KitaThreadTabWidget::setupActions()
235 KStdAction::copy( this, SLOT( slotCopyText() ), actionCollection() );
237 new KAction( i18n( "Open with Web Browser" ),
240 SLOT( slotOpenBrowser() ),
242 "threadview_openbrowser" );
244 new KAction( i18n( "copy URL" ),
247 SLOT( slotCopyURL() ),
249 "threadview_copyurl" );
251 new KAction( i18n( "Copy title and URL" ),
254 SLOT( slotCopyTitleURL() ),
256 "threadview_copytitleurl" );
258 new KAction( i18n( "Find" ),
262 SLOT( slotFocusSearchCombo() ),
266 KStdAction::findNext( this,
267 SLOT( slotSearchNext() ),
269 "threadview_findnext" );
271 KStdAction::findPrev( this,
272 SLOT( slotSearchPrev() ),
274 "threadview_findprev" );
276 new KAction( i18n( "go back anchor" ),
280 SLOT( slotGobackAnchor() ),
282 "threadview_goback" );
284 new KAction( i18n( "Start" ),
288 SLOT( slotGotoHeader() ),
290 "threadview_gotoheader" );
292 new KAction( i18n( "End" ),
296 SLOT( slotGotoFooter() ),
298 "threadview_gotofooter" );
300 new KAction( i18n( "Reload" ),
304 SLOT( slotReloadButton() ),
306 "threadview_reload" );
308 new KAction( i18n( "Stop" ),
312 SLOT( slotStopLoading() ),
316 new KAction( i18n( "Delete" ),
320 SLOT( slotDeleteButtonClicked() ),
322 "threadview_delete" );
327 /* KitaThreadView actions */
329 /* copy selected text (Ctrl+C) */ /* public slot */
330 void KitaThreadTabWidget::slotCopyText()
332 QWidget * w = currentPage();
333 KitaThreadView * view = isThreadView( w );
335 QClipboard * clipboard = QApplication::clipboard();
336 QString text = view->selectedText();
337 clipboard->setText( text, QClipboard::Clipboard );
342 void KitaThreadTabWidget::slotOpenBrowser( int idx )
344 QWidget * w = currentPage();
345 if ( idx != -1 ) w = page( idx );
350 KitaThreadView * view = isThreadView( w );
352 new KRun( view->threadURL() );
356 KParts::Part* part = findPartFromWidget( w );
357 if ( part && part->inherits( "KParts::ReadOnlyPart" ) ) {
358 url = static_cast<KParts::ReadOnlyPart*>( part ) ->url();
367 void KitaThreadTabWidget::slotCopyURL( int idx )
369 QWidget * w = currentPage();
370 if ( idx != -1 ) w = page( idx );
372 QClipboard* clipboard = QApplication::clipboard();
374 KitaThreadView * view = isThreadView( w );
376 KURL datURL = view->datURL();
378 QString cliptxt = Kita::DatManager::threadURL( datURL );
379 clipboard->setText( cliptxt , QClipboard::Clipboard );
380 clipboard->setText( cliptxt , QClipboard::Selection );
386 void KitaThreadTabWidget::slotCopyTitleURL( int idx )
388 QWidget * w = currentPage();
389 if ( idx != -1 ) w = page( idx );
391 QClipboard* clipboard = QApplication::clipboard();
393 KitaThreadView * view = isThreadView( w );
395 KURL datURL = view->datURL();
397 QString cliptxt = Kita::DatManager::threadName( datURL )
398 + "\n" + Kita::DatManager::threadURL( datURL );
399 clipboard->setText( cliptxt , QClipboard::Clipboard );
400 clipboard->setText( cliptxt , QClipboard::Selection );
406 void KitaThreadTabWidget::slotFocusSearchCombo()
408 KitaThreadView * view = isThreadView( currentPage() );
409 if ( view ) view->focusSearchCombo();
414 void KitaThreadTabWidget::slotSearchNext()
416 KitaThreadView * view = isThreadView( currentPage() );
417 if ( view ) view->slotSearchNext();
422 void KitaThreadTabWidget::slotSearchPrev()
424 KitaThreadView * view = isThreadView( currentPage() );
425 if ( view ) view->slotSearchPrev();
430 void KitaThreadTabWidget::slotGobackAnchor()
432 KitaThreadView * view = isThreadView( currentPage() );
433 if ( view ) view->slotGobackAnchor();
438 void KitaThreadTabWidget::slotGotoHeader()
440 KitaThreadView * view = isThreadView( currentPage() );
441 if ( view ) view->slotGotoHeader();
446 void KitaThreadTabWidget::slotGotoFooter()
448 KitaThreadView * view = isThreadView( currentPage() );
449 if ( view ) view->slotGotoFooter();
454 void KitaThreadTabWidget::slotReloadButton()
456 KitaThreadView * view = isThreadView( currentPage() );
457 if ( view ) view->slotReloadButton();
462 void KitaThreadTabWidget::slotStopLoading()
464 KitaThreadView * view = isThreadView( currentPage() );
465 if ( view ) view->slotStopLoading();
470 void KitaThreadTabWidget::slotDeleteButtonClicked()
472 KitaThreadView * view = isThreadView( currentPage() );
473 if ( view ) view->slotDeleteButtonClicked();
477 /*---------------------------------------------------------------------*/
478 /*---------------------------------------------------------------------*/
479 /*---------------------------------------------------------------------*/
481 /*---------------------------------------------------------------------*/
482 /*---------------------------------------------------------------------*/
483 /*---------------------------------------------------------------------*/
486 /* Don't forget to call setup later ! */
487 KitaThreadDock::KitaThreadDock( KDockManager* dockManager,
489 const QPixmap &pixmap,
491 const QString& strCaption,
492 const QString& strTabPageLabel,
494 : KitaDockWidgetBase( dockManager, name, pixmap, parent, strCaption, strTabPageLabel, f ) {}
497 KitaThreadDock::~KitaThreadDock() {}
500 /*-----------------------------*/
501 /* Main Thread View */
503 /* setup thig dock as main thread view */ /* public */
504 KitaThreadTabWidget* KitaThreadDock::setupAsMainView()
506 m_threadTab = new KitaThreadTabWidget( this, "Thread View" );
507 setWidget( m_threadTab );
513 void KitaThreadDock::slotShowThread( const KURL& url )
517 if ( m_threadTab ) m_threadTab->slotShowMainThread( url );
520 /* show Thread Dock */ /* private slot */
521 void KitaThreadDock::slotShowThreadDock()
523 QWidget * topWidget = topLevelWidget();
524 if ( topWidget->isMinimized() ) topWidget->showNormal();
526 topWidget->setActiveWindow();