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 "writetabwidget.h"
13 #include <QtGui/QClipboard>
16 #include <kactioncollection.h>
17 #include <kmessagebox.h>
19 #include "writeview.h"
20 #include "libkita/boarddatabase.h"
21 #include "libkita/datmanager.h"
22 #include "libkita/kita_misc.h"
26 WriteTabWidget::WriteTabWidget(QWidget* parent) : TabWidgetBase(parent)
28 setXMLFile("writetabwidgetui.rc");
34 WriteTabWidget::~WriteTabWidget() {}
38 void WriteTabWidget::slotShowWriteView(const KUrl& url,
39 const QString& resStr)
41 openWriteView(url, resStr, QString());
46 void WriteTabWidget::openWriteView(const KUrl& url,
47 const QString& resStr, const QString& subject)
49 // TODO: machiBBS kakiko support.
50 BoardDatabase db(url);
51 if (db.type() == Board_MachiBBS) {
52 // KMessageBox::sorry(this,
53 // i18n("Can't write to machi BBS in this version."),
59 WriteView* view = findWriteView(url);
61 if (view->body().length()) {
62 if (KMessageBox::warningYesNo(this,
63 i18n("Do you want to clear the text?"), "Kita")
64 == KMessageBox::No) return;
68 view->setMessage(resStr);
69 setCurrentWidget(view);
74 // create new write view & add it to tab
79 threadName = DatManager(url).threadName();
80 new_dlg = new WriteView(this, url);
81 new_dlg->setMessage(resStr);
82 addTab(new_dlg, threadName);
83 setCurrentWidget(new_dlg);
87 WriteView* WriteTabWidget::findWriteView(const KUrl& url)
89 KUrl datUrl = getDatUrl(url);
90 if (datUrl.isEmpty()) return 0;
93 if (max == 0) return 0;
95 for(int i=0; i < max; i++) {
96 WriteView * view = isWriteView(widget (i));
98 if (view->datUrl() == datUrl) return view;
107 WriteView* WriteTabWidget::isWriteView(QWidget* w)
109 return qobject_cast<WriteView*>(w);
114 /* when thread view is focused, this slot is called */
115 /* See also ThreadView::setFocus. */ /* private slot */
116 void WriteTabWidget::slotChangeWriteTab(const KUrl& url)
120 if (max == 0) return ;
122 // disable all ok buttons.
123 for(int i=0; i < max ; i++) {
124 view = isWriteView(widget(i));
125 if (view) view->slotEnableWriting(false);
128 // show current url page.
129 view = findWriteView(url);
131 if (currentWidget() != view) setCurrentWidget(view);
132 view->slotEnableWriting(true);
137 /* protected */ /* virtual */
138 void WriteTabWidget::deleteWidget(QWidget* w)
140 WriteView * view = isWriteView(w);
142 if (view == 0) return ;
144 if (view->body().length()) {
145 if (KMessageBox::warningYesNo(this,
146 i18n("If you close this dialog, you will lose text.\n"
147 "Do you want to close?"), "Kita") == KMessageBox::No) return;
150 TabWidgetBase::deleteWidget(w);
154 /*--------------------------------*/
155 /* WriteTabWidget actions */
159 void WriteTabWidget::setupActions()
161 KAction* quoteclip_action = actionCollection()->addAction("writeview_quoteclip");
162 quoteclip_action->setText(i18n("quote clipboard"));
163 quoteclip_action->setShortcut(Qt::Key_F2);
164 connect(quoteclip_action, SIGNAL(triggered()), this, SLOT(slotQuoteClipboard()));
169 void WriteTabWidget::slotQuoteClipboard()
171 WriteView * view = isWriteView(currentWidget());
173 QClipboard * clipboard = QApplication::clipboard();
174 QString str = clipboard->text(QClipboard::Selection);
175 if (str.isEmpty()) str = clipboard->text(QClipboard::Clipboard);
176 if (!str.isEmpty()) {
178 QString msg = "\n> " + str.replace('\n', "\n> ") + '\n';
179 view->insertMessage(msg);