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 );
131 connect( view, SIGNAL( closeCurrentTab() ), SLOT( slotCloseCurrentTab() ) );
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( closeThreadTab( const KURL& ) ),
146 SLOT( slotCloseThreadTab( const KURL& ) ) );
147 connect( signalCollection, SIGNAL( threadFaceChanged() ),
148 SLOT( slotFontChanged() ) );
153 KitaThreadView* KitaThreadTabWidget::findMainView( const KURL& url )
155 KURL datURL = Kita::ParseMisc::parseURLonly( url );
158 if ( max == 0 ) return NULL;
162 KitaThreadView * view = isThreadView( page ( i ) );
164 if ( view->getViewMode() == VIEWMODE_MAINVIEW ) {
166 if ( view->datURL() == datURL
167 || view->datURL().isEmpty() /* default view */
179 KitaThreadView* KitaThreadTabWidget::isThreadView( QWidget* w )
181 KitaThreadView * view = NULL;
183 if ( w->isA( "KitaThreadView" ) ) view = static_cast< KitaThreadView* >( w );
191 void KitaThreadTabWidget::slotUpdateThreadTab( const KURL& url )
193 KURL datURL = Kita::ParseMisc::parseURLonly( url );
195 KitaThreadView * view = findMainView( datURL );
197 QString threadName = Kita::DatManager::threadName( datURL );
199 setTabLabel( view, threadName );
200 setTabToolTip( view, threadName );
204 void KitaThreadTabWidget::slotFontChanged()
206 QFont font = Kita::Config::threadFont();
210 /* protected */ /* virtual */
211 void KitaThreadTabWidget::deleteWidget( QWidget* w )
213 KitaTabWidgetBase::deleteWidget( w );
215 if ( count() == 0 ) {
216 emit setMainCaption( QString::null );
217 emit setMainStatusbar( QString::null );
218 emit setMainURLLine( QString::null );
221 KitaThreadView * threadView = createView( "thread" );
224 showPage( threadView );
225 emit switchToSubject();
232 /*--------------------------------*/
233 /* KitaThreadView actions */
237 void KitaThreadTabWidget::setupActions()
239 KStdAction::copy( this, SLOT( slotCopyText() ), actionCollection() );
241 new KAction( i18n( "Open with Web Browser" ),
244 SLOT( slotOpenBrowser() ),
246 "threadview_openbrowser" );
248 new KAction( i18n( "copy URL" ),
251 SLOT( slotCopyURL() ),
253 "threadview_copyurl" );
255 new KAction( i18n( "Copy title and URL" ),
258 SLOT( slotCopyTitleURL() ),
260 "threadview_copytitleurl" );
262 new KAction( i18n( "Find" ),
266 SLOT( slotFocusSearchCombo() ),
270 KStdAction::findNext( this,
271 SLOT( slotSearchNext() ),
273 "threadview_findnext" );
275 KStdAction::findPrev( this,
276 SLOT( slotSearchPrev() ),
278 "threadview_findprev" );
280 new KAction( i18n( "go back anchor" ),
284 SLOT( slotGobackAnchor() ),
286 "threadview_goback" );
288 new KAction( i18n( "Start" ),
292 SLOT( slotGotoHeader() ),
294 "threadview_gotoheader" );
296 new KAction( i18n( "End" ),
300 SLOT( slotGotoFooter() ),
302 "threadview_gotofooter" );
304 new KAction( i18n( "Reload" ),
308 SLOT( slotReloadButton() ),
310 "threadview_reload" );
312 new KAction( i18n( "Stop" ),
316 SLOT( slotStopLoading() ),
320 new KAction( i18n( "Delete" ),
324 SLOT( slotDeleteButtonClicked() ),
326 "threadview_delete" );
331 /* KitaThreadView actions */
333 /* copy selected text (Ctrl+C) */ /* public slot */
334 void KitaThreadTabWidget::slotCopyText()
336 QWidget * w = currentPage();
337 KitaThreadView * view = isThreadView( w );
339 QClipboard * clipboard = QApplication::clipboard();
340 QString text = view->selectedText();
341 clipboard->setText( text, QClipboard::Clipboard );
346 void KitaThreadTabWidget::slotOpenBrowser( int idx )
348 QWidget * w = currentPage();
349 if ( idx != -1 ) w = page( idx );
354 KitaThreadView * view = isThreadView( w );
356 new KRun( view->threadURL() );
360 KParts::Part* part = findPartFromWidget( w );
361 if ( part && part->inherits( "KParts::ReadOnlyPart" ) ) {
362 url = static_cast<KParts::ReadOnlyPart*>( part ) ->url();
371 void KitaThreadTabWidget::slotCopyURL( int idx )
373 QWidget * w = currentPage();
374 if ( idx != -1 ) w = page( idx );
376 QClipboard* clipboard = QApplication::clipboard();
378 KitaThreadView * view = isThreadView( w );
380 KURL datURL = view->datURL();
382 QString cliptxt = Kita::DatManager::threadURL( datURL );
383 clipboard->setText( cliptxt , QClipboard::Clipboard );
384 clipboard->setText( cliptxt , QClipboard::Selection );
390 void KitaThreadTabWidget::slotCopyTitleURL( int idx )
392 QWidget * w = currentPage();
393 if ( idx != -1 ) w = page( idx );
395 QClipboard* clipboard = QApplication::clipboard();
397 KitaThreadView * view = isThreadView( w );
399 KURL datURL = view->datURL();
401 QString cliptxt = Kita::DatManager::threadName( datURL )
402 + "\n" + Kita::DatManager::threadURL( datURL );
403 clipboard->setText( cliptxt , QClipboard::Clipboard );
404 clipboard->setText( cliptxt , QClipboard::Selection );
410 void KitaThreadTabWidget::slotFocusSearchCombo()
412 KitaThreadView * view = isThreadView( currentPage() );
413 if ( view ) view->focusSearchCombo();
418 void KitaThreadTabWidget::slotSearchNext()
420 KitaThreadView * view = isThreadView( currentPage() );
421 if ( view ) view->slotSearchNext();
426 void KitaThreadTabWidget::slotSearchPrev()
428 KitaThreadView * view = isThreadView( currentPage() );
429 if ( view ) view->slotSearchPrev();
434 void KitaThreadTabWidget::slotGobackAnchor()
436 KitaThreadView * view = isThreadView( currentPage() );
437 if ( view ) view->slotGobackAnchor();
442 void KitaThreadTabWidget::slotGotoHeader()
444 KitaThreadView * view = isThreadView( currentPage() );
445 if ( view ) view->slotGotoHeader();
450 void KitaThreadTabWidget::slotGotoFooter()
452 KitaThreadView * view = isThreadView( currentPage() );
453 if ( view ) view->slotGotoFooter();
458 void KitaThreadTabWidget::slotReloadButton()
460 KitaThreadView * view = isThreadView( currentPage() );
461 if ( view ) view->slotReloadButton();
466 void KitaThreadTabWidget::slotStopLoading()
468 KitaThreadView * view = isThreadView( currentPage() );
469 if ( view ) view->slotStopLoading();
474 void KitaThreadTabWidget::slotDeleteButtonClicked()
476 KitaThreadView * view = isThreadView( currentPage() );
477 if ( view ) view->slotDeleteButtonClicked();
481 /*---------------------------------------------------------------------*/
482 /*---------------------------------------------------------------------*/
483 /*---------------------------------------------------------------------*/
485 /*---------------------------------------------------------------------*/
486 /*---------------------------------------------------------------------*/
487 /*---------------------------------------------------------------------*/
490 /* Don't forget to call setup later ! */
491 KitaThreadDock::KitaThreadDock( KDockManager* dockManager,
493 const QPixmap &pixmap,
495 const QString& strCaption,
496 const QString& strTabPageLabel,
498 : KitaDockWidgetBase( dockManager, name, pixmap, parent, strCaption, strTabPageLabel, f ) {}
501 KitaThreadDock::~KitaThreadDock() {}
504 /*-----------------------------*/
505 /* Main Thread View */
507 /* setup thig dock as main thread view */ /* public */
508 KitaThreadTabWidget* KitaThreadDock::setupAsMainView()
510 m_threadTab = new KitaThreadTabWidget( this, "Thread View" );
511 setWidget( m_threadTab );
513 Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
514 connect( signalCollection, SIGNAL( switchToThread() ),
515 SLOT( slotShowThreadDock() ) );
521 void KitaThreadDock::slotShowThread( const KURL& url )
525 if ( m_threadTab ) m_threadTab->slotShowMainThread( url );
528 /* show Thread Dock */ /* private slot */
529 void KitaThreadDock::slotShowThreadDock()
531 QWidget * topWidget = topLevelWidget();
532 if ( topWidget->isMinimized() ) topWidget->showNormal();
534 topWidget->setActiveWindow();