47 |
#include "libkita/threadinfo.h" |
#include "libkita/threadinfo.h" |
48 |
#include "prefs/prefs.h" |
#include "prefs/prefs.h" |
49 |
|
|
50 |
KitaMainWindow::KitaMainWindow() |
using namespace Kita; |
51 |
: KXmlGuiWindow(0) |
|
52 |
|
MainWindow::MainWindow() : KXmlGuiWindow(0) |
53 |
{ |
{ |
54 |
// FIXME: merge *.po |
// FIXME: merge *.po |
55 |
KGlobal::locale() ->insertCatalog("kitapart"); |
KGlobal::locale() ->insertCatalog("kitapart"); |
67 |
loadCache(); |
loadCache(); |
68 |
|
|
69 |
// load ascii art |
// load ascii art |
70 |
Kita::AsciiArtConfig::self()->readConfig(); |
AsciiArtConfig::self()->readConfig(); |
71 |
if (Kita::AsciiArtConfig::self()->asciiArtList().empty()) { |
if (AsciiArtConfig::self()->asciiArtList().empty()) { |
72 |
loadAsciiArt(); |
loadAsciiArt(); |
73 |
} |
} |
74 |
|
|
75 |
// load abone lists |
// load abone lists |
76 |
Kita::AboneConfig::self()->readConfig(); |
AboneConfig::self()->readConfig(); |
77 |
if (Kita::AboneConfig::self()->aboneIDList().empty()) { |
if (AboneConfig::self()->aboneIDList().empty()) { |
78 |
loadAboneIDList(); |
loadAboneIDList(); |
79 |
} |
} |
80 |
|
|
81 |
if (Kita::AboneConfig::self()->aboneNameList().empty()) { |
if (AboneConfig::self()->aboneNameList().empty()) { |
82 |
loadAboneNameList(); |
loadAboneNameList(); |
83 |
} |
} |
84 |
|
|
85 |
if (Kita::AboneConfig::self()->aboneWordList().empty()) { |
if (AboneConfig::self()->aboneWordList().empty()) { |
86 |
loadAboneWordList(); |
loadAboneWordList(); |
87 |
} |
} |
88 |
|
|
92 |
// for compativility |
// for compativility |
93 |
loadCompletion(); |
loadCompletion(); |
94 |
|
|
95 |
Kita::Config::self()->readConfig(); |
Config::self()->readConfig(); |
96 |
|
|
97 |
// apply the saved mainwindow settings, if any, and ask the mainwindow |
// apply the saved mainwindow settings, if any, and ask the mainwindow |
98 |
// to automatically save settings if changed: window size, toolbar |
// to automatically save settings if changed: window size, toolbar |
100 |
setAutoSaveSettings(); |
setAutoSaveSettings(); |
101 |
|
|
102 |
// set list font |
// set list font |
103 |
setFont(Kita::Config::font()); |
setFont(Config::font()); |
104 |
|
|
105 |
// allow the view to change the statusbar and caption |
// allow the view to change the statusbar and caption |
106 |
connect(m_urlLine, SIGNAL(returnPressed()), |
connect(m_urlLine, SIGNAL(returnPressed()), |
130 |
// update favorite list |
// update favorite list |
131 |
ViewMediator::getInstance()->updateFavoriteListView(); |
ViewMediator::getInstance()->updateFavoriteListView(); |
132 |
|
|
133 |
if (Kita::Config::autoLogin()) { |
if (Config::autoLogin()) { |
134 |
login(); |
login(); |
135 |
} |
} |
136 |
} |
} |
137 |
|
|
138 |
KitaMainWindow::~KitaMainWindow() |
MainWindow::~MainWindow() |
139 |
{ |
{ |
140 |
Kita::AboneConfig::self()->writeConfig(); |
AboneConfig::self()->writeConfig(); |
141 |
|
|
142 |
Kita::AsciiArtConfig::self()->writeConfig(); |
AsciiArtConfig::self()->writeConfig(); |
143 |
|
|
144 |
saveFavoriteBoards(); |
saveFavoriteBoards(); |
145 |
|
|
149 |
|
|
150 |
saveMainWindowSettings(KGlobal::config().data()->group("MainWindow")); |
saveMainWindowSettings(KGlobal::config().data()->group("MainWindow")); |
151 |
|
|
152 |
Kita::Config::self()->writeConfig(); |
Config::self()->writeConfig(); |
153 |
|
|
154 |
Kita::DatManager::deleteAllDatInfo(); |
DatManager::deleteAllDatInfo(); |
155 |
} |
} |
156 |
|
|
157 |
void KitaMainWindow::load(const KUrl& url) |
void MainWindow::load(const KUrl& url) |
158 |
{ |
{ |
159 |
setCaption(url.url()); |
setCaption(url.url()); |
160 |
} |
} |
161 |
|
|
162 |
void KitaMainWindow::bookmark(const QString& datURL, bool on) |
void MainWindow::bookmark(const QString& datURL, bool on) |
163 |
{ |
{ |
164 |
FavoriteThreads * favorite = FavoriteThreads::getInstance(); |
FavoriteThreads * favorite = FavoriteThreads::getInstance(); |
165 |
|
|
172 |
ViewMediator::getInstance()->updateFavoriteListView(); |
ViewMediator::getInstance()->updateFavoriteListView(); |
173 |
} |
} |
174 |
|
|
175 |
void KitaMainWindow::login() |
void MainWindow::login() |
176 |
{ |
{ |
177 |
if (Kita::Account::login(Kita::Config::userID(), Kita::Config::password())) { |
if (Account::login(Config::userID(), Config::password())) { |
178 |
setMainStatus(i18n("Login succeeded.")); |
setMainStatus(i18n("Login succeeded.")); |
179 |
} else { |
} else { |
180 |
setMainStatus(i18n("Login failed.")); |
setMainStatus(i18n("Login failed.")); |
181 |
} |
} |
182 |
} |
} |
183 |
|
|
184 |
void KitaMainWindow::newToolbarConfig() |
void MainWindow::newToolbarConfig() |
185 |
{ |
{ |
186 |
// this slot is called when user clicks "Ok" or "Apply" in the toolbar editor. |
// this slot is called when user clicks "Ok" or "Apply" in the toolbar editor. |
187 |
// recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.) |
// recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.) |
188 |
applyMainWindowSettings(KGlobal::config().data()->group("MainWindow")); |
applyMainWindowSettings(KGlobal::config().data()->group("MainWindow")); |
189 |
} |
} |
190 |
|
|
191 |
void KitaMainWindow::optionsShowToolbar() |
void MainWindow::optionsShowToolbar() |
192 |
{ |
{ |
193 |
// this is all very cut and paste code for showing/hiding the |
// this is all very cut and paste code for showing/hiding the |
194 |
// toolbar |
// toolbar |
199 |
} |
} |
200 |
} |
} |
201 |
|
|
202 |
void KitaMainWindow::optionsShowStatusbar() |
void MainWindow::optionsShowStatusbar() |
203 |
{ |
{ |
204 |
// this is all very cut and paste code for showing/hiding the |
// this is all very cut and paste code for showing/hiding the |
205 |
// statusbar |
// statusbar |
210 |
} |
} |
211 |
} |
} |
212 |
|
|
213 |
void KitaMainWindow::optionsConfigureKeys() |
void MainWindow::optionsConfigureKeys() |
214 |
{ |
{ |
215 |
KShortcutsDialog::configure(actionCollection()); |
KShortcutsDialog::configure(actionCollection()); |
216 |
} |
} |
217 |
|
|
218 |
void KitaMainWindow::optionsConfigureToolbars() |
void MainWindow::optionsConfigureToolbars() |
219 |
{ |
{ |
220 |
// use the standard toolbar editor |
// use the standard toolbar editor |
221 |
KEditToolBar dlg(factory()); |
KEditToolBar dlg(factory()); |
224 |
dlg.exec(); |
dlg.exec(); |
225 |
} |
} |
226 |
|
|
227 |
void KitaMainWindow::optionsPreferences() |
void MainWindow::optionsPreferences() |
228 |
{ |
{ |
229 |
// popup some sort of preference dialog, here |
// popup some sort of preference dialog, here |
230 |
if (KConfigDialog::showDialog("Kita Preferences")) { |
if (KConfigDialog::showDialog("Kita Preferences")) { |
231 |
return; |
return; |
232 |
} |
} |
233 |
|
|
234 |
KitaPreferences* dialog = new KitaPreferences(this); |
Preferences* dialog = new Preferences(this); |
235 |
|
|
236 |
connect(dialog, SIGNAL(fontChanged(const QFont&)), |
connect(dialog, SIGNAL(fontChanged(const QFont&)), |
237 |
SLOT(setFont(const QFont&))); |
SLOT(setFont(const QFont&))); |
239 |
dialog->show(); |
dialog->show(); |
240 |
} |
} |
241 |
|
|
242 |
void KitaMainWindow::settingsMenuAboutToShow() |
void MainWindow::settingsMenuAboutToShow() |
243 |
{ |
{ |
244 |
m_toolbarAction->setChecked(toolBar() ->isVisible()); |
m_toolbarAction->setChecked(toolBar() ->isVisible()); |
245 |
m_statusbarAction->setChecked(statusBar() ->isVisible()); |
m_statusbarAction->setChecked(statusBar() ->isVisible()); |
246 |
} |
} |
247 |
|
|
248 |
void KitaMainWindow::setFont(const QFont& font) |
void MainWindow::setFont(const QFont& font) |
249 |
{ |
{ |
250 |
m_boardTab->setFont(font); |
m_boardTab->setFont(font); |
251 |
m_bbsTab->setFont(font); |
m_bbsTab->setFont(font); |
252 |
} |
} |
253 |
|
|
254 |
void KitaMainWindow::setUrl(const KUrl& url) |
void MainWindow::setUrl(const KUrl& url) |
255 |
{ |
{ |
256 |
m_urlLine->setText(url.url()); |
m_urlLine->setText(url.url()); |
257 |
} |
} |
258 |
|
|
259 |
void KitaMainWindow::slotEditCopy() |
void MainWindow::slotEditCopy() |
260 |
{ |
{ |
261 |
QWidget * widget = KApplication::kApplication()->focusWidget(); |
QWidget * widget = KApplication::kApplication()->focusWidget(); |
262 |
|
|
266 |
} |
} |
267 |
} |
} |
268 |
|
|
269 |
void KitaMainWindow::setMainStatus(const QString& statusStr) |
void MainWindow::setMainStatus(const QString& statusStr) |
270 |
{ |
{ |
271 |
// display the text on the statusbar |
// display the text on the statusbar |
272 |
statusBar() ->showMessage(statusStr); |
statusBar() ->showMessage(statusStr); |
273 |
} |
} |
274 |
|
|
275 |
void KitaMainWindow::slotURLLine() |
void MainWindow::slotURLLine() |
276 |
{ |
{ |
277 |
KUrl url = m_urlLine->text(); |
KUrl url = m_urlLine->text(); |
278 |
KUrl datURL = Kita::getDatURL(url); |
KUrl datURL = getDatURL(url); |
279 |
m_threadTab->slotShowMainThread(datURL); |
m_threadTab->slotShowMainThread(datURL); |
280 |
} |
} |
281 |
|
|
283 |
// private method |
// private method |
284 |
// |
// |
285 |
|
|
286 |
void KitaMainWindow::setupActions() |
void MainWindow::setupActions() |
287 |
{ |
{ |
288 |
KStandardAction::quit(this, SLOT(close()), actionCollection()); |
KStandardAction::quit(this, SLOT(close()), actionCollection()); |
289 |
KStandardAction::copy(this, SLOT(slotEditCopy()), actionCollection()); |
KStandardAction::copy(this, SLOT(slotEditCopy()), actionCollection()); |
328 |
factory() ->addClient(m_writeTab); |
factory() ->addClient(m_writeTab); |
329 |
} |
} |
330 |
|
|
331 |
void KitaMainWindow::setupView() |
void MainWindow::setupView() |
332 |
{ |
{ |
333 |
ViewMediator::getInstance()->setMainWindow(this); |
ViewMediator::getInstance()->setMainWindow(this); |
334 |
|
|
338 |
QSplitter* hsplit = new QSplitter(mainWidget); |
QSplitter* hsplit = new QSplitter(mainWidget); |
339 |
mainLayout->addWidget(hsplit); |
mainLayout->addWidget(hsplit); |
340 |
|
|
341 |
m_bbsTab = new KitaBBSTabWidget(hsplit); |
m_bbsTab = new BBSTabWidget(hsplit); |
342 |
|
|
343 |
QSplitter* vsplit = new QSplitter(Qt::Vertical, hsplit); |
QSplitter* vsplit = new QSplitter(Qt::Vertical, hsplit); |
344 |
|
|
345 |
m_boardTab = new KitaBoardTabWidget(vsplit); |
m_boardTab = new BoardTabWidget(vsplit); |
346 |
ViewMediator::getInstance()->setBoardTabWidget(m_boardTab); |
ViewMediator::getInstance()->setBoardTabWidget(m_boardTab); |
347 |
|
|
348 |
m_threadTab = new KitaThreadTabWidget(vsplit); |
m_threadTab = new ThreadTabWidget(vsplit); |
349 |
ViewMediator::getInstance()->setThreadTabWidget(m_threadTab); |
ViewMediator::getInstance()->setThreadTabWidget(m_threadTab); |
350 |
|
|
351 |
hsplit->setSizes(QList<int>() << 100 << 500); |
hsplit->setSizes(QList<int>() << 100 << 500); |
354 |
setCentralWidget(mainWidget); |
setCentralWidget(mainWidget); |
355 |
|
|
356 |
/* write dock */ |
/* write dock */ |
357 |
m_writeTab = new KitaWriteTabWidget(0); |
m_writeTab = new WriteTabWidget(0); |
358 |
ViewMediator::getInstance()->setWriteTabWidget(m_writeTab); |
ViewMediator::getInstance()->setWriteTabWidget(m_writeTab); |
359 |
} |
} |
360 |
|
|
361 |
void KitaMainWindow::loadCache() |
void MainWindow::loadCache() |
362 |
{ |
{ |
363 |
KitaThreadInfo * cache = KitaThreadInfo::getInstance(); |
ThreadInfo * cache = ThreadInfo::getInstance(); |
364 |
QString cacheConfigPath = KStandardDirs::locateLocal("appdata", "cache"); |
QString cacheConfigPath = KStandardDirs::locateLocal("appdata", "cache"); |
365 |
QFile file(cacheConfigPath); |
QFile file(cacheConfigPath); |
366 |
if (file.open(QIODevice::ReadOnly)) { |
if (file.open(QIODevice::ReadOnly)) { |
369 |
} |
} |
370 |
} |
} |
371 |
|
|
372 |
void KitaMainWindow::saveCache() |
void MainWindow::saveCache() |
373 |
{ |
{ |
374 |
KitaThreadInfo * cache = KitaThreadInfo::getInstance(); |
ThreadInfo * cache = ThreadInfo::getInstance(); |
375 |
QString cacheConfigPath = KStandardDirs::locateLocal("appdata", "cache"); |
QString cacheConfigPath = KStandardDirs::locateLocal("appdata", "cache"); |
376 |
QFile file(cacheConfigPath); |
QFile file(cacheConfigPath); |
377 |
if (file.open(QIODevice::WriteOnly)) { |
if (file.open(QIODevice::WriteOnly)) { |
380 |
} |
} |
381 |
} |
} |
382 |
|
|
383 |
void KitaMainWindow::loadFavorites() |
void MainWindow::loadFavorites() |
384 |
{ |
{ |
385 |
QString favoritesConfigPath = KStandardDirs::locateLocal("appdata", "favorites.xml"); |
QString favoritesConfigPath = KStandardDirs::locateLocal("appdata", "favorites.xml"); |
386 |
QFile file(favoritesConfigPath); |
QFile file(favoritesConfigPath); |
393 |
} |
} |
394 |
} |
} |
395 |
|
|
396 |
void KitaMainWindow::saveFavorites() |
void MainWindow::saveFavorites() |
397 |
{ |
{ |
398 |
QString favoritesConfigPath = KStandardDirs::locateLocal("appdata", "favorites.xml"); |
QString favoritesConfigPath = KStandardDirs::locateLocal("appdata", "favorites.xml"); |
399 |
QFile file(favoritesConfigPath); |
QFile file(favoritesConfigPath); |
404 |
} |
} |
405 |
} |
} |
406 |
|
|
407 |
void KitaMainWindow::loadFavoriteBoards() |
void MainWindow::loadFavoriteBoards() |
408 |
{ |
{ |
409 |
QString configPath = KStandardDirs::locateLocal("appdata", "favorite_boards.xml"); |
QString configPath = KStandardDirs::locateLocal("appdata", "favorite_boards.xml"); |
410 |
QFile file(configPath); |
QFile file(configPath); |
413 |
stream.setCodec("UTF-8"); |
stream.setCodec("UTF-8"); |
414 |
|
|
415 |
QString xml = stream.readAll(); |
QString xml = stream.readAll(); |
416 |
Kita::FavoriteBoards::readFromXML(xml); |
FavoriteBoards::readFromXML(xml); |
417 |
} |
} |
418 |
} |
} |
419 |
|
|
420 |
void KitaMainWindow::saveFavoriteBoards() |
void MainWindow::saveFavoriteBoards() |
421 |
{ |
{ |
422 |
QString configPath = KStandardDirs::locateLocal("appdata", "favorite_boards.xml"); |
QString configPath = KStandardDirs::locateLocal("appdata", "favorite_boards.xml"); |
423 |
QFile file(configPath); |
QFile file(configPath); |
424 |
if (file.open(QIODevice::WriteOnly)) { |
if (file.open(QIODevice::WriteOnly)) { |
425 |
QTextStream stream(&file); |
QTextStream stream(&file); |
426 |
stream.setCodec("UTF-8"); |
stream.setCodec("UTF-8"); |
427 |
stream << Kita::FavoriteBoards::toXML(); |
stream << FavoriteBoards::toXML(); |
428 |
} |
} |
429 |
} |
} |
430 |
|
|
431 |
void KitaMainWindow::loadCompletion() |
void MainWindow::loadCompletion() |
432 |
{ |
{ |
433 |
QString configPath = KStandardDirs::locateLocal("appdata", "completion"); |
QString configPath = KStandardDirs::locateLocal("appdata", "completion"); |
434 |
KConfig config(configPath); |
KConfig config(configPath); |
435 |
|
|
436 |
Kita::Config::setNameCompletionList(config.group("").readEntry("name", QStringList() )); |
Config::setNameCompletionList(config.group("").readEntry("name", QStringList() )); |
437 |
} |
} |
438 |
|
|
439 |
void KitaMainWindow::loadAsciiArt() |
void MainWindow::loadAsciiArt() |
440 |
{ |
{ |
441 |
QString configPath = KStandardDirs::locateLocal("appdata", "asciiart"); |
QString configPath = KStandardDirs::locateLocal("appdata", "asciiart"); |
442 |
QFile file(configPath); |
QFile file(configPath); |
452 |
list << str; |
list << str; |
453 |
} |
} |
454 |
} |
} |
455 |
Kita::AsciiArtConfig::setAsciiArtList(list); |
AsciiArtConfig::setAsciiArtList(list); |
456 |
} |
} |
457 |
} |
} |
458 |
|
|
459 |
void KitaMainWindow::loadAboneIDList() |
void MainWindow::loadAboneIDList() |
460 |
{ |
{ |
461 |
QString configPath = KStandardDirs::locateLocal("appdata", "abone_id"); |
QString configPath = KStandardDirs::locateLocal("appdata", "abone_id"); |
462 |
QFile file(configPath); |
QFile file(configPath); |
472 |
list << str; |
list << str; |
473 |
} |
} |
474 |
} |
} |
475 |
Kita::AboneConfig::setAboneIDList(list); |
AboneConfig::setAboneIDList(list); |
476 |
} |
} |
477 |
} |
} |
478 |
|
|
479 |
void KitaMainWindow::loadAboneNameList() |
void MainWindow::loadAboneNameList() |
480 |
{ |
{ |
481 |
QString configPath = KStandardDirs::locateLocal("appdata", "abone_name"); |
QString configPath = KStandardDirs::locateLocal("appdata", "abone_name"); |
482 |
QFile file(configPath); |
QFile file(configPath); |
492 |
list << str; |
list << str; |
493 |
} |
} |
494 |
} |
} |
495 |
Kita::AboneConfig::setAboneNameList(list); |
AboneConfig::setAboneNameList(list); |
496 |
} |
} |
497 |
} |
} |
498 |
|
|
499 |
void KitaMainWindow::loadAboneWordList() |
void MainWindow::loadAboneWordList() |
500 |
{ |
{ |
501 |
QString configPath = KStandardDirs::locateLocal("appdata", "abone_word"); |
QString configPath = KStandardDirs::locateLocal("appdata", "abone_word"); |
502 |
QFile file(configPath); |
QFile file(configPath); |
512 |
list << str; |
list << str; |
513 |
} |
} |
514 |
} |
} |
515 |
Kita::AboneConfig::setAboneWordList(list); |
AboneConfig::setAboneWordList(list); |
516 |
} |
} |
517 |
} |
} |
518 |
|
|