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"
14 #include "viewmediator.h"
16 #include "libkita/kita_misc.h"
17 #include "libkita/parsemisc.h"
18 #include "libkita/signalcollection.h"
19 #include "libkita/datmanager.h"
20 #include "libkita/boardmanager.h"
21 #include "libkita/kita-utf8.h"
22 #include "libkita/kitaconfig.h"
23 #include "libkita/config_xt.h"
26 #include <kstdaccel.h>
30 #include <kpopupmenu.h>
32 #include <qapplication.h>
34 #include <qclipboard.h>
35 #include <qmessagebox.h>
38 /*--------------------------------------------------------------------------------*/
41 KitaThreadTabWidget::KitaThreadTabWidget( QWidget* parent, const char* name, WFlags f )
42 : KitaTabWidgetBase( parent, name, f )
44 setXMLFile( "threadtabwidgetui.rc" );
50 createView( "thread" );
54 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()
144 KitaThreadView* KitaThreadTabWidget::findMainView( const KURL& url )
146 KURL datURL = Kita::ParseMisc::parseURLonly( url );
149 if ( max == 0 ) return NULL;
153 KitaThreadView * view = isThreadView( page ( i ) );
155 if ( view->getViewMode() == VIEWMODE_MAINVIEW ) {
157 if ( view->datURL() == datURL
158 || view->datURL().isEmpty() /* default view */
170 KitaThreadView* KitaThreadTabWidget::isThreadView( QWidget* w )
172 KitaThreadView * view = NULL;
174 if ( w->isA( "KitaThreadView" ) ) view = static_cast< KitaThreadView* >( w );
182 void KitaThreadTabWidget::slotUpdateThreadTab( const KURL& url )
184 KURL datURL = Kita::ParseMisc::parseURLonly( url );
186 KitaThreadView * view = findMainView( datURL );
188 QString threadName = Kita::DatManager::threadName( datURL );
190 setTabLabel( view, threadName );
191 setTabToolTip( view, threadName );
195 void KitaThreadTabWidget::slotFontChanged()
197 QFont font = Kita::Config::threadFont();
201 /* protected */ /* virtual */
202 void KitaThreadTabWidget::deleteWidget( QWidget* w )
204 KitaTabWidgetBase::deleteWidget( w );
206 if ( count() == 0 ) {
207 ViewMediator::getInstance()->setMainCaption( QString::null );
208 ViewMediator::getInstance()->setMainStatusBar( QString::null );
209 ViewMediator::getInstance()->setMainURLLine( QString::null );
212 KitaThreadView * threadView = createView( "thread" );
215 showPage( threadView );
222 /*--------------------------------*/
223 /* KitaThreadView actions */
227 void KitaThreadTabWidget::setupActions()
229 KStdAction::copy( this, SLOT( slotCopyText() ), actionCollection() );
231 new KAction( i18n( "Open with Web Browser" ),
234 SLOT( slotOpenBrowser() ),
236 "threadview_openbrowser" );
238 new KAction( i18n( "copy URL" ),
241 SLOT( slotCopyURL() ),
243 "threadview_copyurl" );
245 new KAction( i18n( "Copy title and URL" ),
248 SLOT( slotCopyTitleURL() ),
250 "threadview_copytitleurl" );
252 new KAction( i18n( "Find" ),
256 SLOT( slotFocusSearchCombo() ),
260 KStdAction::findNext( this,
261 SLOT( slotSearchNext() ),
263 "threadview_findnext" );
265 KStdAction::findPrev( this,
266 SLOT( slotSearchPrev() ),
268 "threadview_findprev" );
270 new KAction( i18n( "go back anchor" ),
274 SLOT( slotGobackAnchor() ),
276 "threadview_goback" );
278 new KAction( i18n( "Start" ),
282 SLOT( slotGotoHeader() ),
284 "threadview_gotoheader" );
286 new KAction( i18n( "End" ),
290 SLOT( slotGotoFooter() ),
292 "threadview_gotofooter" );
294 new KAction( i18n( "Reload" ),
298 SLOT( slotReloadButton() ),
300 "threadview_reload" );
302 new KAction( i18n( "Stop" ),
306 SLOT( slotStopLoading() ),
310 new KAction( i18n( "Delete" ),
314 SLOT( slotDeleteButtonClicked() ),
316 "threadview_delete" );
321 /* KitaThreadView actions */
323 /* copy selected text (Ctrl+C) */ /* public slot */
324 void KitaThreadTabWidget::slotCopyText()
326 QWidget * w = currentPage();
327 KitaThreadView * view = isThreadView( w );
329 QClipboard * clipboard = QApplication::clipboard();
330 QString text = view->selectedText();
331 clipboard->setText( text, QClipboard::Clipboard );
336 void KitaThreadTabWidget::slotOpenBrowser( int idx )
338 QWidget * w = currentPage();
339 if ( idx != -1 ) w = page( idx );
344 KitaThreadView * view = isThreadView( w );
346 new KRun( view->threadURL() );
350 KParts::Part* part = findPartFromWidget( w );
351 if ( part && part->inherits( "KParts::ReadOnlyPart" ) ) {
352 url = static_cast<KParts::ReadOnlyPart*>( part ) ->url();
361 void KitaThreadTabWidget::slotCopyURL( int idx )
363 QWidget * w = currentPage();
364 if ( idx != -1 ) w = page( idx );
366 QClipboard* clipboard = QApplication::clipboard();
368 KitaThreadView * view = isThreadView( w );
370 KURL datURL = view->datURL();
372 QString cliptxt = Kita::DatManager::threadURL( datURL );
373 clipboard->setText( cliptxt , QClipboard::Clipboard );
374 clipboard->setText( cliptxt , QClipboard::Selection );
380 void KitaThreadTabWidget::slotCopyTitleURL( int idx )
382 QWidget * w = currentPage();
383 if ( idx != -1 ) w = page( idx );
385 QClipboard* clipboard = QApplication::clipboard();
387 KitaThreadView * view = isThreadView( w );
389 KURL datURL = view->datURL();
391 QString cliptxt = Kita::DatManager::threadName( datURL )
392 + "\n" + Kita::DatManager::threadURL( datURL );
393 clipboard->setText( cliptxt , QClipboard::Clipboard );
394 clipboard->setText( cliptxt , QClipboard::Selection );
400 void KitaThreadTabWidget::slotFocusSearchCombo()
402 KitaThreadView * view = isThreadView( currentPage() );
403 if ( view ) view->focusSearchCombo();
408 void KitaThreadTabWidget::slotSearchNext()
410 KitaThreadView * view = isThreadView( currentPage() );
411 if ( view ) view->slotSearchNext();
416 void KitaThreadTabWidget::slotSearchPrev()
418 KitaThreadView * view = isThreadView( currentPage() );
419 if ( view ) view->slotSearchPrev();
424 void KitaThreadTabWidget::slotGobackAnchor()
426 KitaThreadView * view = isThreadView( currentPage() );
427 if ( view ) view->slotGobackAnchor();
432 void KitaThreadTabWidget::slotGotoHeader()
434 KitaThreadView * view = isThreadView( currentPage() );
435 if ( view ) view->slotGotoHeader();
440 void KitaThreadTabWidget::slotGotoFooter()
442 KitaThreadView * view = isThreadView( currentPage() );
443 if ( view ) view->slotGotoFooter();
448 void KitaThreadTabWidget::slotReloadButton()
450 KitaThreadView * view = isThreadView( currentPage() );
451 if ( view ) view->slotReloadButton();
456 void KitaThreadTabWidget::slotStopLoading()
458 KitaThreadView * view = isThreadView( currentPage() );
459 if ( view ) view->slotStopLoading();
464 void KitaThreadTabWidget::slotDeleteButtonClicked()
466 KitaThreadView * view = isThreadView( currentPage() );
467 if ( view ) view->slotDeleteButtonClicked();
471 /*---------------------------------------------------------------------*/
472 /*---------------------------------------------------------------------*/
473 /*---------------------------------------------------------------------*/
475 /*---------------------------------------------------------------------*/
476 /*---------------------------------------------------------------------*/
477 /*---------------------------------------------------------------------*/
480 /* Don't forget to call setup later ! */
481 KitaThreadDock::KitaThreadDock( KDockManager* dockManager,
483 const QPixmap &pixmap,
485 const QString& strCaption,
486 const QString& strTabPageLabel,
488 : KitaDockWidgetBase( dockManager, name, pixmap, parent, strCaption, strTabPageLabel, f ) {}
491 KitaThreadDock::~KitaThreadDock() {}
494 /*-----------------------------*/
495 /* Main Thread View */
497 /* setup thig dock as main thread view */ /* public */
498 KitaThreadTabWidget* KitaThreadDock::setupAsMainView()
500 m_threadTab = new KitaThreadTabWidget( this, "Thread View" );
501 setWidget( m_threadTab );
507 void KitaThreadDock::slotShowThread( const KURL& url )
511 if ( m_threadTab ) m_threadTab->slotShowMainThread( url );
514 /* show Thread Dock */ /* private slot */
515 void KitaThreadDock::slotShowThreadDock()
517 QWidget * topWidget = topLevelWidget();
518 if ( topWidget->isMinimized() ) topWidget->showNormal();
520 topWidget->setActiveWindow();