OSDN Git Service

KDE 3.0.x support(can compile at least...)
[kita/kita.git] / src / kita.cpp
1 /*
2  * Copyright (C) 2001 Hideki Ikemoto <ikemo@wakaba.jp>
3  */
4
5 #include "kita.h"
6 #include "pref.h"
7 #include "kitathreadview.h"
8 #include "kitasubjectview.h"
9 #include "kitaboardview.h"
10
11 #include <qdragobject.h>
12 #include <kprinter.h>
13 #include <qpainter.h>
14 #include <qpaintdevicemetrics.h>
15 #include <qtextcodec.h>
16
17 #include <kglobal.h>
18 #include <klocale.h>
19 #include <kiconloader.h>
20 #include <kmenubar.h>
21 #include <kstatusbar.h>
22 #include <kkeydialog.h>
23 #include <kaccel.h>
24 #include <kio/netaccess.h>
25 #include <kfiledialog.h>
26 #include <kconfig.h>
27 #include <kurl.h>
28 #include <kurlrequesterdlg.h>
29
30 #include <kedittoolbar.h>
31
32 #include <kstdaccel.h>
33 #include <kaction.h>
34 #include <kstdaction.h>
35
36 Kita::Kita()
37     : KDockMainWindow( 0, "Kita" ),
38     ///      m_view(new KitaView(this)),
39     m_printer(0)
40 {
41   // accept dnd
42   setAcceptDrops(true);
43
44   // setup view, dock
45   setupView();
46
47   // then, setup our actions
48   setupActions();
49
50   // and a status bar
51   statusBar()->show();
52
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();
57
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();
68 }
69
70 Kita::~Kita()
71 {}
72
73 void Kita::load(const KURL& url)
74 {
75   QString target;
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
79
80 #if 0
81   // download the contents
82   if (KIO::NetAccess::download(url, target)) {
83     // set our caption
84     setCaption(url);
85
86     // load in the file (target is always local)
87     loadFile(target);
88
89     // and remove the temp file
90     KIO::NetAccess::removeTempFile(target);
91   }
92 #endif
93
94   setCaption(url.url());
95   //    m_view->openURL(url);
96 }
97
98 void Kita::setupActions()
99 {
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());
106
107   m_toolbarAction = KStdAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection());
108   m_statusbarAction = KStdAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection());
109
110   KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
111   KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
112   KStdAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
113
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");*/
119
120   KAction *loadBoardList = new KAction(i18n("Load BoardList"), 0,
121                                        m_boardView, SLOT(loadBoardList()),
122                                        actionCollection(), "load_board_list");
123   createGUI();
124 }
125
126 void Kita::saveProperties(KConfig *config)
127 {
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
131
132   //    if (m_view->currentURL() != QString::null)
133   //        config->writeEntry("lastURL", m_view->currentURL());
134 }
135
136 void Kita::readProperties(KConfig *config)
137 {
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'
142
143   //    QString url = config->readEntry("lastURL");
144
145   //    if (url != QString::null)
146   //        m_view->openURL(KURL(url));
147 }
148
149 void Kita::dragEnterEvent(QDragEnterEvent *event)
150 {
151   // accept uri drops only
152   event->accept(QUriDrag::canDecode(event));
153 }
154
155 void Kita::dropEvent(QDropEvent *event)
156 {
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
160   QStrList uri;
161
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
165     QString url, target;
166     url = uri.first();
167
168     // load in the file
169     load(KURL(url));
170   }
171 }
172
173 void Kita::fileNew()
174 {
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
177   // button is clicked
178
179   // create a new window
180   (new Kita)->show();
181 }
182
183 void Kita::fileOpen()
184 {
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
187   // button is clicked
188   //    KURL url = KURLRequesterDlg::getURL(QString::null, this, i18n("Open Location") );
189   //    if (!url.isEmpty())
190   //        m_view->openURL(url);
191 }
192
193 void Kita::fileSave()
194 {
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
197   // button is clicked
198
199   // save the current file
200 }
201
202 void Kita::fileSaveAs()
203 {
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
208   }
209 }
210
211 void Kita::filePrint()
212 {
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
215   // button is clicked
216   /*    if (!m_printer) m_printer = new KPrinter;
217       if (m_printer->setup(this))
218       {
219           // setup the printer.  with Qt, you always "print" to a
220           // QPainter.. whether the output medium is a pixmap, a screen,
221           // or paper
222           QPainter p;
223           p.begin(m_printer);
224    
225           // we let our view do the actual printing
226           QPaintDeviceMetrics metrics(m_printer);
227           m_view->print(&p, metrics.height(), metrics.width());
228    
229           // and send the result to the printer
230           p.end();
231       }*/
232 }
233
234 void Kita::optionsShowToolbar()
235 {
236   // this is all very cut and paste code for showing/hiding the
237   // toolbar
238   if (m_toolbarAction->isChecked())
239     toolBar()->show();
240   else
241     toolBar()->hide();
242 }
243
244 void Kita::optionsShowStatusbar()
245 {
246   // this is all very cut and paste code for showing/hiding the
247   // statusbar
248   if (m_statusbarAction->isChecked())
249     statusBar()->show();
250   else
251     statusBar()->hide();
252 }
253
254 void Kita::optionsConfigureKeys()
255 {
256   KKeyDialog::configureKeys(actionCollection(), "kitaui.rc");
257 }
258
259 void Kita::optionsConfigureToolbars()
260 {
261   // use the standard toolbar editor
262   saveMainWindowSettings( KGlobal::config(), settingsGroup() );
263   KEditToolbar dlg(actionCollection());
264   connect(&dlg, SIGNAL(newToolbarConfig()), this, SLOT(newToolbarConfig()));
265   dlg.exec();
266 }
267
268 void Kita::newToolbarConfig()
269 {
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.)
272   createGUI();
273   applyMainWindowSettings( KGlobal::config(), settingsGroup() );
274 }
275
276 void Kita::optionsPreferences()
277 {
278   // popup some sort of preference dialog, here
279   KitaPreferences dlg;
280   if (dlg.exec()) {
281     // redo your settings
282   }
283 }
284
285 void Kita::changeStatusbar(const QString& text)
286 {
287   // display the text on the statusbar
288   statusBar()->message(text);
289 }
290
291 void Kita::changeCaption(const QString& text)
292 {
293   // display the text on the caption
294   setCaption(text);
295 }
296
297 void Kita::setupView()
298 {
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);
305
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);
311
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);
317
318   setView(mainDock);
319   setMainDockWidget(mainDock);
320
321   boardDock->manualDock(mainDock, KDockWidget::DockLeft, 20);
322   subjectDock->manualDock(mainDock, KDockWidget::DockTop);
323 }
324
325 #include "kita.moc"