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() {}
57 /* show "Main thread" view */ /* public slots */
58 void KitaThreadTabWidget::slotShowMainThread( const KURL& url )
61 KURL datURL = Kita::ParseMisc::parseURL( url, refstr );
62 QString threadName = Kita::DatManager::threadName( datURL );
65 int viewMode = VIEWMODE_MAINVIEW;
66 KitaThreadView* currentView = isThreadView( currentPage() );
67 if ( currentView ) viewMode = currentView->getViewMode();
69 if ( refstr != QString::null ) {
70 int i = refstr.find( "-" );
71 if ( i != -1 ) jumpNum = refstr.left( i ).toInt();
72 else jumpNum = refstr.toInt();
75 KitaThreadView* view = findMainView( datURL );
79 setCurrentPage( indexOf( view ) );
81 if ( view->threadURL().isEmpty() ) {
82 /* Show on the default view */
83 view->showThread( datURL, jumpNum );
85 /* The view is already shown */
86 /* TODO: jump to jumpNum after reloading */
88 view->slotReloadButton( jumpNum );
92 KitaThreadView * newView = createView( threadName );
95 newView->showThread( datURL, jumpNum );
100 slotUpdateThreadTab( datURL );
103 /* close "all" views which URL is url. */ /* public slot */
104 void KitaThreadTabWidget::slotCloseThreadTab( const KURL& url )
107 if ( max == 0 ) return ;
108 KURL datURL = Kita::ParseMisc::parseURLonly( url );
113 KitaThreadView * view = isThreadView( page ( i ) );
115 if ( view->datURL() == datURL ) {
126 /* create KitaThreadView */ /* private */
127 KitaThreadView* KitaThreadTabWidget::createView( QString label )
129 KitaThreadView * view = new KitaThreadView( this );
131 addTab( view, label );
139 void KitaThreadTabWidget::connectSignals()
141 Kita::SignalCollection * signalCollection = Kita::SignalCollection::getInstance();
143 connect( signalCollection, SIGNAL( updateThreadTab( const KURL& ) ),
144 this, SLOT( slotUpdateThreadTab( const KURL& ) ) );
145 connect( signalCollection, SIGNAL( threadFaceChanged() ),
146 SLOT( slotFontChanged() ) );
151 KitaThreadView* KitaThreadTabWidget::findMainView( const KURL& url )
153 KURL datURL = Kita::ParseMisc::parseURLonly( url );
156 if ( max == 0 ) return NULL;
160 KitaThreadView * view = isThreadView( page ( i ) );
162 if ( view->getViewMode() == VIEWMODE_MAINVIEW ) {
164 if ( view->datURL() == datURL
165 || view->datURL().isEmpty() /* default view */
177 KitaThreadView* KitaThreadTabWidget::isThreadView( QWidget* w )
179 KitaThreadView * view = NULL;
181 if ( w->isA( "KitaThreadView" ) ) view = static_cast< KitaThreadView* >( w );
189 void KitaThreadTabWidget::slotUpdateThreadTab( const KURL& url )
191 KURL datURL = Kita::ParseMisc::parseURLonly( url );
193 KitaThreadView * view = findMainView( datURL );
195 QString threadName = Kita::DatManager::threadName( datURL );
197 setTabLabel( view, threadName );
198 setTabToolTip( view, threadName );
202 void KitaThreadTabWidget::slotFontChanged()
204 QFont font = Kita::Config::threadFont();
208 /* protected */ /* virtual */
209 void KitaThreadTabWidget::deleteWidget( QWidget* w )
211 KitaTabWidgetBase::deleteWidget( w );
213 if ( count() == 0 ) {
214 emit setMainCaption( QString::null );
215 ViewMediator::getInstance()->setMainStatusBar( QString::null );
216 emit setMainURLLine( QString::null );
219 KitaThreadView * threadView = createView( "thread" );
222 showPage( threadView );
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 );
514 void KitaThreadDock::slotShowThread( const KURL& url )
518 if ( m_threadTab ) m_threadTab->slotShowMainThread( url );
521 /* show Thread Dock */ /* private slot */
522 void KitaThreadDock::slotShowThreadDock()
524 QWidget * topWidget = topLevelWidget();
525 if ( topWidget->isMinimized() ) topWidget->showNormal();
527 topWidget->setActiveWindow();