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()
140 Kita::SignalCollection * signalCollection = Kita::SignalCollection::getInstance();
141 connect( signalCollection, SIGNAL( threadFaceChanged() ),
142 SLOT( slotFontChanged() ) );
147 KitaThreadView* KitaThreadTabWidget::findMainView( const KURL& url )
149 KURL datURL = Kita::ParseMisc::parseURLonly( url );
152 if ( max == 0 ) return NULL;
156 KitaThreadView * view = isThreadView( page ( i ) );
158 if ( view->getViewMode() == VIEWMODE_MAINVIEW ) {
160 if ( view->datURL() == datURL
161 || view->datURL().isEmpty() /* default view */
173 KitaThreadView* KitaThreadTabWidget::isThreadView( QWidget* w )
175 KitaThreadView * view = NULL;
177 if ( w->isA( "KitaThreadView" ) ) view = static_cast< KitaThreadView* >( w );
185 void KitaThreadTabWidget::slotUpdateThreadTab( const KURL& url )
187 KURL datURL = Kita::ParseMisc::parseURLonly( url );
189 KitaThreadView * view = findMainView( datURL );
191 QString threadName = Kita::DatManager::threadName( datURL );
193 setTabLabel( view, threadName );
194 setTabToolTip( view, threadName );
198 void KitaThreadTabWidget::slotFontChanged()
200 QFont font = Kita::Config::threadFont();
204 /* protected */ /* virtual */
205 void KitaThreadTabWidget::deleteWidget( QWidget* w )
207 KitaTabWidgetBase::deleteWidget( w );
209 if ( count() == 0 ) {
210 ViewMediator::getInstance()->setMainCaption( QString::null );
211 ViewMediator::getInstance()->setMainStatusBar( QString::null );
212 ViewMediator::getInstance()->setMainURLLine( QString::null );
215 KitaThreadView * threadView = createView( "thread" );
218 showPage( threadView );
225 /*--------------------------------*/
226 /* KitaThreadView actions */
230 void KitaThreadTabWidget::setupActions()
232 KStdAction::copy( this, SLOT( slotCopyText() ), actionCollection() );
234 new KAction( i18n( "Open with Web Browser" ),
237 SLOT( slotOpenBrowser() ),
239 "threadview_openbrowser" );
241 new KAction( i18n( "copy URL" ),
244 SLOT( slotCopyURL() ),
246 "threadview_copyurl" );
248 new KAction( i18n( "Copy title and URL" ),
251 SLOT( slotCopyTitleURL() ),
253 "threadview_copytitleurl" );
255 new KAction( i18n( "Find" ),
259 SLOT( slotFocusSearchCombo() ),
263 KStdAction::findNext( this,
264 SLOT( slotSearchNext() ),
266 "threadview_findnext" );
268 KStdAction::findPrev( this,
269 SLOT( slotSearchPrev() ),
271 "threadview_findprev" );
273 new KAction( i18n( "go back anchor" ),
277 SLOT( slotGobackAnchor() ),
279 "threadview_goback" );
281 new KAction( i18n( "Start" ),
285 SLOT( slotGotoHeader() ),
287 "threadview_gotoheader" );
289 new KAction( i18n( "End" ),
293 SLOT( slotGotoFooter() ),
295 "threadview_gotofooter" );
297 new KAction( i18n( "Reload" ),
301 SLOT( slotReloadButton() ),
303 "threadview_reload" );
305 new KAction( i18n( "Stop" ),
309 SLOT( slotStopLoading() ),
313 new KAction( i18n( "Delete" ),
317 SLOT( slotDeleteButtonClicked() ),
319 "threadview_delete" );
324 /* KitaThreadView actions */
326 /* copy selected text (Ctrl+C) */ /* public slot */
327 void KitaThreadTabWidget::slotCopyText()
329 QWidget * w = currentPage();
330 KitaThreadView * view = isThreadView( w );
332 QClipboard * clipboard = QApplication::clipboard();
333 QString text = view->selectedText();
334 clipboard->setText( text, QClipboard::Clipboard );
339 void KitaThreadTabWidget::slotOpenBrowser( int idx )
341 QWidget * w = currentPage();
342 if ( idx != -1 ) w = page( idx );
347 KitaThreadView * view = isThreadView( w );
349 new KRun( view->threadURL() );
353 KParts::Part* part = findPartFromWidget( w );
354 if ( part && part->inherits( "KParts::ReadOnlyPart" ) ) {
355 url = static_cast<KParts::ReadOnlyPart*>( part ) ->url();
364 void KitaThreadTabWidget::slotCopyURL( int idx )
366 QWidget * w = currentPage();
367 if ( idx != -1 ) w = page( idx );
369 QClipboard* clipboard = QApplication::clipboard();
371 KitaThreadView * view = isThreadView( w );
373 KURL datURL = view->datURL();
375 QString cliptxt = Kita::DatManager::threadURL( datURL );
376 clipboard->setText( cliptxt , QClipboard::Clipboard );
377 clipboard->setText( cliptxt , QClipboard::Selection );
383 void KitaThreadTabWidget::slotCopyTitleURL( int idx )
385 QWidget * w = currentPage();
386 if ( idx != -1 ) w = page( idx );
388 QClipboard* clipboard = QApplication::clipboard();
390 KitaThreadView * view = isThreadView( w );
392 KURL datURL = view->datURL();
394 QString cliptxt = Kita::DatManager::threadName( datURL )
395 + "\n" + Kita::DatManager::threadURL( datURL );
396 clipboard->setText( cliptxt , QClipboard::Clipboard );
397 clipboard->setText( cliptxt , QClipboard::Selection );
403 void KitaThreadTabWidget::slotFocusSearchCombo()
405 KitaThreadView * view = isThreadView( currentPage() );
406 if ( view ) view->focusSearchCombo();
411 void KitaThreadTabWidget::slotSearchNext()
413 KitaThreadView * view = isThreadView( currentPage() );
414 if ( view ) view->slotSearchNext();
419 void KitaThreadTabWidget::slotSearchPrev()
421 KitaThreadView * view = isThreadView( currentPage() );
422 if ( view ) view->slotSearchPrev();
427 void KitaThreadTabWidget::slotGobackAnchor()
429 KitaThreadView * view = isThreadView( currentPage() );
430 if ( view ) view->slotGobackAnchor();
435 void KitaThreadTabWidget::slotGotoHeader()
437 KitaThreadView * view = isThreadView( currentPage() );
438 if ( view ) view->slotGotoHeader();
443 void KitaThreadTabWidget::slotGotoFooter()
445 KitaThreadView * view = isThreadView( currentPage() );
446 if ( view ) view->slotGotoFooter();
451 void KitaThreadTabWidget::slotReloadButton()
453 KitaThreadView * view = isThreadView( currentPage() );
454 if ( view ) view->slotReloadButton();
459 void KitaThreadTabWidget::slotStopLoading()
461 KitaThreadView * view = isThreadView( currentPage() );
462 if ( view ) view->slotStopLoading();
467 void KitaThreadTabWidget::slotDeleteButtonClicked()
469 KitaThreadView * view = isThreadView( currentPage() );
470 if ( view ) view->slotDeleteButtonClicked();
474 /*---------------------------------------------------------------------*/
475 /*---------------------------------------------------------------------*/
476 /*---------------------------------------------------------------------*/
478 /*---------------------------------------------------------------------*/
479 /*---------------------------------------------------------------------*/
480 /*---------------------------------------------------------------------*/
483 /* Don't forget to call setup later ! */
484 KitaThreadDock::KitaThreadDock( KDockManager* dockManager,
486 const QPixmap &pixmap,
488 const QString& strCaption,
489 const QString& strTabPageLabel,
491 : KitaDockWidgetBase( dockManager, name, pixmap, parent, strCaption, strTabPageLabel, f ) {}
494 KitaThreadDock::~KitaThreadDock() {}
497 /*-----------------------------*/
498 /* Main Thread View */
500 /* setup thig dock as main thread view */ /* public */
501 KitaThreadTabWidget* KitaThreadDock::setupAsMainView()
503 m_threadTab = new KitaThreadTabWidget( this, "Thread View" );
504 setWidget( m_threadTab );
510 void KitaThreadDock::slotShowThread( const KURL& url )
514 if ( m_threadTab ) m_threadTab->slotShowMainThread( url );
517 /* show Thread Dock */ /* private slot */
518 void KitaThreadDock::slotShowThreadDock()
520 QWidget * topWidget = topLevelWidget();
521 if ( topWidget->isMinimized() ) topWidget->showNormal();
523 topWidget->setActiveWindow();