2 * Copyright (C) 2001 Hideki Ikemoto <ikemo@wakaba.jp>
7 #include "kitathreadview.h"
8 #include "kitasubjectview.h"
9 #include "kitaboardview.h"
11 #include <qdragobject.h>
14 #include <qpaintdevicemetrics.h>
15 #include <qtextcodec.h>
19 #include <kiconloader.h>
21 #include <kstatusbar.h>
22 #include <kkeydialog.h>
24 #include <kio/netaccess.h>
25 #include <kfiledialog.h>
28 #include <kurlrequesterdlg.h>
30 #include <kedittoolbar.h>
32 #include <kstdaccel.h>
34 #include <kstdaction.h>
37 : KDockMainWindow( 0, "Kita" ),
38 /// m_view(new KitaView(this)),
47 // then, setup our actions
53 // apply the saved mainwindow settings, if any, and ask the mainwindow
54 // to automatically save settings if changed: window size, toolbar
55 // position, icon size, etc.
56 setAutoSaveSettings();
58 // allow the view to change the statusbar and caption
59 connect(m_threadview, SIGNAL(signalChangeStatusbar(const QString&)),
60 this, SLOT(changeStatusbar(const QString&)));
61 connect(m_boardView, SIGNAL(signalLoadBoard(const KURL&, const QString&)),
62 m_subjectView, SLOT(slotLoadBoard(const KURL&, const QString&)));
63 connect(m_subjectView, SIGNAL(signalShowThread(const KURL&, const KURL&, const QString&)),
64 m_threadview, SLOT(slotShowThread(const KURL&, const KURL&, const QString&)));
65 // connect(m_view, SIGNAL(signalChangeCaption(const QString&)),
66 // this, SLOT(changeCaption(const QString&)));
67 m_boardView->loadBoardList();
73 void Kita::load(const KURL& url)
76 // the below code is what you should normally do. in this
77 // example case, we want the url to our own. you probably
78 // want to use this code instead for your app
81 // download the contents
82 if (KIO::NetAccess::download(url, target)) {
86 // load in the file (target is always local)
89 // and remove the temp file
90 KIO::NetAccess::removeTempFile(target);
94 setCaption(url.url());
95 // m_view->openURL(url);
98 void Kita::setupActions()
100 KStdAction::openNew(this, SLOT(fileNew()), actionCollection());
101 KStdAction::open(this, SLOT(fileOpen()), actionCollection());
102 KStdAction::save(this, SLOT(fileSave()), actionCollection());
103 KStdAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
104 KStdAction::print(this, SLOT(filePrint()), actionCollection());
105 KStdAction::quit(kapp, SLOT(quit()), actionCollection());
107 m_toolbarAction = KStdAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection());
108 m_statusbarAction = KStdAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection());
110 KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
111 KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
112 KStdAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
114 // this doesn't do anything useful. it's just here to illustrate
115 // how to insert a custom menu and menu item
116 /* KAction *custom = new KAction(i18n("Cus&tom Menuitem"), 0,
117 this, SLOT(optionsPreferences()),
118 actionCollection(), "custom_action");*/
120 KAction *loadBoardList = new KAction(i18n("Load BoardList"), 0,
121 m_boardView, SLOT(loadBoardList()),
122 actionCollection(), "load_board_list");
126 void Kita::saveProperties(KConfig *config)
128 // the 'config' object points to the session managed
129 // config file. anything you write here will be available
130 // later when this app is restored
132 // if (m_view->currentURL() != QString::null)
133 // config->writeEntry("lastURL", m_view->currentURL());
136 void Kita::readProperties(KConfig *config)
138 // the 'config' object points to the session managed
139 // config file. this function is automatically called whenever
140 // the app is being restored. read in here whatever you wrote
141 // in 'saveProperties'
143 // QString url = config->readEntry("lastURL");
145 // if (url != QString::null)
146 // m_view->openURL(KURL(url));
149 void Kita::dragEnterEvent(QDragEnterEvent *event)
151 // accept uri drops only
152 event->accept(QUriDrag::canDecode(event));
155 void Kita::dropEvent(QDropEvent *event)
157 // this is a very simplistic implementation of a drop event. we
158 // will only accept a dropped URL. the Qt dnd code can do *much*
159 // much more, so please read the docs there
162 // see if we can decode a URI.. if not, just ignore it
163 if (QUriDrag::decode(event, uri)) {
164 // okay, we have a URI.. process it
175 // this slot is called whenever the File->New menu is selected,
176 // the New shortcut is pressed (usually CTRL+N) or the New toolbar
179 // create a new window
183 void Kita::fileOpen()
185 // this slot is called whenever the File->Open menu is selected,
186 // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
188 // KURL url = KURLRequesterDlg::getURL(QString::null, this, i18n("Open Location") );
189 // if (!url.isEmpty())
190 // m_view->openURL(url);
193 void Kita::fileSave()
195 // this slot is called whenever the File->Save menu is selected,
196 // the Save shortcut is pressed (usually CTRL+S) or the Save toolbar
199 // save the current file
202 void Kita::fileSaveAs()
204 // this slot is called whenever the File->Save As menu is selected,
205 KURL file_url = KFileDialog::getSaveURL();
206 if (!file_url.isEmpty() && !file_url.isMalformed()) {
207 // save your info, here
211 void Kita::filePrint()
213 // this slot is called whenever the File->Print menu is selected,
214 // the Print shortcut is pressed (usually CTRL+P) or the Print toolbar
216 /* if (!m_printer) m_printer = new KPrinter;
217 if (m_printer->setup(this))
219 // setup the printer. with Qt, you always "print" to a
220 // QPainter.. whether the output medium is a pixmap, a screen,
225 // we let our view do the actual printing
226 QPaintDeviceMetrics metrics(m_printer);
227 m_view->print(&p, metrics.height(), metrics.width());
229 // and send the result to the printer
234 void Kita::optionsShowToolbar()
236 // this is all very cut and paste code for showing/hiding the
238 if (m_toolbarAction->isChecked())
244 void Kita::optionsShowStatusbar()
246 // this is all very cut and paste code for showing/hiding the
248 if (m_statusbarAction->isChecked())
254 void Kita::optionsConfigureKeys()
256 KKeyDialog::configureKeys(actionCollection(), "kitaui.rc");
259 void Kita::optionsConfigureToolbars()
261 // use the standard toolbar editor
262 saveMainWindowSettings( KGlobal::config(), settingsGroup() );
263 KEditToolbar dlg(actionCollection());
264 connect(&dlg, SIGNAL(newToolbarConfig()), this, SLOT(newToolbarConfig()));
268 void Kita::newToolbarConfig()
270 // this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
271 // recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
273 applyMainWindowSettings( KGlobal::config(), settingsGroup() );
276 void Kita::optionsPreferences()
278 // popup some sort of preference dialog, here
281 // redo your settings
285 void Kita::changeStatusbar(const QString& text)
287 // display the text on the statusbar
288 statusBar()->message(text);
291 void Kita::changeCaption(const QString& text)
293 // display the text on the caption
297 void Kita::setupView()
299 KDockWidget* mainDock;
300 mainDock = createDockWidget("main", 0L, 0L, i18n("main"));
301 m_threadview = new KitaThreadView(mainDock);
302 mainDock->setWidget(m_threadview);
303 mainDock->setDockSite(KDockWidget::DockFullSite);
304 mainDock->setEnableDocking(KDockWidget::DockNone);
306 KDockWidget* subjectDock;
307 subjectDock = createDockWidget("subject", 0L, 0L, i18n("subject"));
308 m_subjectView = new KitaSubjectView(subjectDock);
309 subjectDock->setWidget(m_subjectView);
310 subjectDock->setDockSite(KDockWidget::DockFullSite);
312 KDockWidget* boardDock;
313 boardDock = createDockWidget("board", 0L, 0L, i18n("board"));
314 m_boardView = new KitaBoardView(boardDock);
315 boardDock->setWidget(m_boardView);
316 boardDock->setDockSite(KDockWidget::DockFullSite);
319 setMainDockWidget(mainDock);
321 boardDock->manualDock(mainDock, KDockWidget::DockLeft, 20);
322 subjectDock->manualDock(mainDock, KDockWidget::DockTop);