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"
13 #include <QtGui/QApplication>
14 #include <QtGui/QClipboard>
15 #include <QtGui/QContextMenuEvent>
18 #include <kactioncollection.h>
21 #include <kstandardaction.h>
22 #include <kstandardshortcut.h>
24 #include "threadview.h"
25 #include "viewmediator.h"
26 #include "libkita/datmanager.h"
27 #include "libkita/globalconfig.h"
28 #include "libkita/kita_misc.h"
32 ThreadTabWidget::ThreadTabWidget(QWidget* parent) : TabWidgetBase(parent)
34 setXMLFile("threadtabwidgetui.rc");
36 m_actionList = actionCollection()->actions();
41 createView(i18nc("@title:tab", "Thread"));
45 ThreadTabWidget::~ThreadTabWidget() {}
47 /* show "Main thread" view */ /* public slots */
48 void ThreadTabWidget::slotShowMainThread(const KUrl& url)
51 KUrl datUrl = getDatUrl(url, refstr);
52 QString threadName = DatManager(datUrl).threadName();
55 int viewMode = VIEWMODE_MAINVIEW;
56 ThreadView* currentView = isThreadView(currentWidget());
57 if (currentView) viewMode = currentView->getViewMode();
59 if (!refstr.isEmpty()) {
60 int i = refstr.indexOf("-");
61 if (i != -1) jumpNum = refstr.left(i).toInt();
62 else jumpNum = refstr.toInt();
65 ThreadView* view = findMainView(datUrl);
69 setCurrentWidget(view);
71 if (view->threadUrl().isEmpty()) {
72 /* Show on the default view */
73 view->showThread(datUrl, jumpNum);
75 /* The view is already shown */
76 /* TODO: jump to jumpNum after reloading */
78 view->slotReloadButton(jumpNum);
82 ThreadView * newView = createView(threadName);
85 newView->showThread(datUrl, jumpNum);
86 setCurrentWidget(newView);
90 slotUpdateThreadTab(datUrl);
93 /* close "all" views which URL is url. */ /* public slot */
94 void ThreadTabWidget::slotCloseThreadTab(const KUrl& url)
97 if (max == 0) return ;
98 KUrl datUrl = getDatUrl(url);
103 ThreadView * view = isThreadView(widget(i));
105 if (view->datUrl() == datUrl) {
116 /* create ThreadView */ /* private */
117 ThreadView* ThreadTabWidget::createView(const QString& label)
119 ThreadView * view = new ThreadView(this);
128 ThreadView* ThreadTabWidget::findMainView(const KUrl& url)
130 KUrl datUrl = getDatUrl(url);
133 if (max == 0) return 0;
137 ThreadView * view = isThreadView(widget(i));
139 if (view->getViewMode() == VIEWMODE_MAINVIEW) {
141 if (view->datUrl() == datUrl
142 || view->datUrl().isEmpty() /* default view */
154 ThreadView* ThreadTabWidget::isThreadView(QWidget* w)
156 return qobject_cast<ThreadView*>(w);
161 void ThreadTabWidget::slotUpdateThreadTab(const KUrl& url)
163 KUrl datUrl = getDatUrl(url);
165 ThreadView * view = findMainView(datUrl);
167 QString threadName = DatManager(datUrl).threadName();
169 setTabText(indexOf(view), threadName);
170 setTabToolTip(indexOf(view), threadName);
174 void ThreadTabWidget::slotFontChanged()
176 QFont font = GlobalConfig::threadFont();
180 /* protected */ /* virtual */
181 void ThreadTabWidget::deleteWidget(QWidget* w)
183 TabWidgetBase::deleteWidget(w);
186 ViewMediator::getInstance()->setMainCaption(QString());
187 ViewMediator::getInstance()->setMainStatus(QString());
188 ViewMediator::getInstance()->setMainUrlLine(KUrl());
191 ThreadView * threadView = createView(i18nc("@title:tab", "Thread"));
194 setCurrentWidget(threadView);
201 /*--------------------------------*/
202 /* ThreadView actions */
206 void ThreadTabWidget::setupActions()
208 KStandardAction::copy(this, SLOT(slotCopyText()),
210 KStandardAction::find(this, SLOT(slotFocusSearchCombo()),
212 KStandardAction::findNext(this, SLOT(slotSearchNext()),
214 KStandardAction::findPrev(this, SLOT(slotSearchPrev()),
217 KAction* gobackAction = actionCollection()->addAction("threadview_goback");
218 gobackAction->setText(i18nc("@action:inmenu", "Go Back Anchor"));
219 gobackAction->setShortcut(Qt::Key_Backspace);
220 gobackAction->setIcon(SmallIcon("arrow-left-double"));
221 connect(gobackAction, SIGNAL(triggered()), this, SLOT(slotGobackAnchor()));
223 KAction* gotoheaderAction
224 = actionCollection()->addAction("threadview_gotoheader");
225 gotoheaderAction->setText(i18nc("@action:inmenu", "Start"));
226 gotoheaderAction->setShortcut(Qt::Key_Home);
227 gotoheaderAction->setIcon(SmallIcon("go-up"));
228 connect(gotoheaderAction, SIGNAL(triggered()),
229 this, SLOT(slotGotoHeader()));
231 KAction* gotofooterAction
232 = actionCollection()->addAction("threadview_gotofooter");
233 gotofooterAction->setText(i18nc("@action:inmenu", "End"));
234 gotofooterAction->setShortcut(Qt::Key_End);
235 gotofooterAction->setIcon(SmallIcon("go-down"));
236 connect(gotofooterAction, SIGNAL(triggered()), this, SLOT(slotGotoFooter()));
238 KAction* reload_action
239 = actionCollection()->addAction("threadview_reload");
240 reload_action->setText(i18nc("@action:button", "Reload"));
241 reload_action->setShortcut(KStandardShortcut::reload());
242 reload_action->setIcon(SmallIcon("view-refresh"));
243 connect(reload_action, SIGNAL(triggered()), this, SLOT(slotReloadButton()));
245 KAction* stopAction = actionCollection()->addAction("threadview_stop");
246 stopAction->setText(i18nc("@action:inmenu", "Stop"));
247 stopAction->setShortcut(Qt::Key_Escape);
248 stopAction->setIcon(SmallIcon("process-stop"));
249 connect(stopAction, SIGNAL(triggered()), this, SLOT(slotStopLoading()));
251 KAction* deleteAction = actionCollection()->addAction("threadview_delete");
252 deleteAction->setText(i18nc("@action:button", "Delete"));
253 deleteAction->setShortcut(Qt::Key_Delete);
254 deleteAction->setIcon(SmallIcon("trash-empty"));
255 connect(deleteAction, SIGNAL(triggered()), this, SLOT(slotDeleteButtonClicked()));
260 /* ThreadView actions */
262 /* copy selected text (Ctrl+C) */ /* public slot */
263 void ThreadTabWidget::slotCopyText()
265 QWidget * w = currentWidget();
266 ThreadView * view = isThreadView(w);
268 QClipboard * clipboard = QApplication::clipboard();
269 QString text = view->selectedText();
270 clipboard->setText(text, QClipboard::Clipboard);
275 void ThreadTabWidget::slotFocusSearchCombo()
277 ThreadView * view = isThreadView(currentWidget());
278 if (view) view->focusSearchCombo();
283 void ThreadTabWidget::slotSearchNext()
285 ThreadView * view = isThreadView(currentWidget());
286 if (view) view->slotSearchNext();
291 void ThreadTabWidget::slotSearchPrev()
293 ThreadView * view = isThreadView(currentWidget());
294 if (view) view->slotSearchPrev();
299 void ThreadTabWidget::slotGobackAnchor()
301 ThreadView * view = isThreadView(currentWidget());
302 if (view) view->slotGobackAnchor();
307 void ThreadTabWidget::slotGotoHeader()
309 ThreadView * view = isThreadView(currentWidget());
310 if (view) view->slotGotoHeader();
315 void ThreadTabWidget::slotGotoFooter()
317 ThreadView * view = isThreadView(currentWidget());
318 if (view) view->slotGotoFooter();
323 void ThreadTabWidget::slotReloadButton()
325 ThreadView * view = isThreadView(currentWidget());
326 if (view) view->slotReloadButton();
331 void ThreadTabWidget::slotStopLoading()
333 ThreadView * view = isThreadView(currentWidget());
334 if (view) view->slotStopLoading();
339 void ThreadTabWidget::slotDeleteButtonClicked()
341 ThreadView * view = isThreadView(currentWidget());
342 if (view) view->slotDeleteButtonClicked();
345 void ThreadTabWidget::contextMenuEvent(QContextMenuEvent* e)
349 foreach (act, m_actionList) {
350 popup.addAction(act);
352 popup.exec(e->globalPos());
353 /* KActionCollection * collection = client->actionCollection();
355 action = new KAction(i18n("goback anchor"), SmallIcon("idea"), KShortcut(), m_threadPart, SLOT(gobackAnchor()), collection, "goback_anchor");
356 emit popupMenu(client, global, url, mimeType, mode);*/ // TODO