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 "mainwindow.h"
13 #include "prefs/prefs.h"
15 #include "thread/threadview.h"
16 #include "thread/threadtabwidget.h"
18 #include "board/boardview.h"
19 #include "board/boardtabwidget.h"
20 #include "bbs/bbsview.h"
21 #include "bbs/bbstabwidget.h"
22 #include "favoriteswindow.h"
24 #include "write/writetabwidget.h"
26 #include "libkita/threadinfo.h"
27 #include "libkita/favoriteboards.h"
28 #include "libkita/favoritethreads.h"
29 #include "libkita/kita_misc.h"
30 #include "libkita/kitaconfig.h"
31 #include "libkita/signalcollection.h"
32 #include "libkita/account.h"
33 #include "libkita/imgmanager.h"
34 #include "libkita/datmanager.h"
35 #include "libkita/boardmanager.h"
37 #include "image/imagetabwidget.h"
39 #include <qdragobject.h>
40 #include <qtextcodec.h>
43 #include <qmessagebox.h>
44 #include <qclipboard.h>
46 #include <klineedit.h>
49 #include <kiconloader.h>
51 #include <kstatusbar.h>
52 #include <kkeydialog.h>
54 #include <kio/netaccess.h>
55 #include <kuserprofile.h>
56 #include <kfiledialog.h>
60 #include <kstandarddirs.h>
62 #include <ksimpleconfig.h>
63 #include <kedittoolbar.h>
64 #include <kstdaccel.h>
66 #include <kstdaction.h>
67 #include <kshortcut.h>
68 #include <kaboutdata.h>
69 #include <kparts/partmanager.h>
70 #include <kdeversion.h>
73 KitaMainWindow::KitaMainWindow()
74 : KParts::DockMainWindow( 0, "Kita" ),
78 KGlobal::locale() ->insertCatalogue( "kitapart" );
81 setAcceptDrops( true );
84 Kita::ImgManager::setup( this );
89 // then, setup our actions
110 statusBar() ->show();
113 m_bbsDock->loadSession();
114 m_subjectDock->loadSession();
115 m_threadDock->loadSession();
116 m_naviDock->loadSession();
117 m_imgDock->loadSession();
118 m_writeDock->loadSession();
119 QString dockConfigPath = locateLocal( "appdata", "dock.conf" );
120 KConfig dockConfig( dockConfigPath );
121 readDockConfig( &dockConfig );
124 m_subjectDock->slotShowDock();
127 m_threadDock->slotShowDock();
130 makeDockInvisible( m_writeDock );
131 m_showImgViewAction->setChecked( FALSE );
134 makeDockInvisible( m_naviDock );
135 m_showNaviAction->setChecked( FALSE );
138 makeDockInvisible( m_imgDock );
139 m_showImgViewAction->setChecked( FALSE );
142 KitaConfig::readConfig( KGlobal::config() );
144 // apply the saved mainwindow settings, if any, and ask the mainwindow
145 // to automatically save settings if changed: window size, toolbar
146 // position, icon size, etc.
147 setAutoSaveSettings();
150 setFont( KitaConfig::listFont() );
152 // allow the view to change the statusbar and caption
153 Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
155 connect( signalCollection, SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ),
156 SLOT( slotOpenURLRequest( const KURL&, const KParts::URLArgs& ) ) );
158 connect( signalCollection, SIGNAL( openURLRequestExt(
159 const KURL&, const KParts::URLArgs&, QString, int, int,
160 const KURL&, const KURL&, const QString&, const QString& ) ),
161 SLOT( slotOpenURLRequestExt(
162 const KURL& , const KParts::URLArgs&, QString, int, int,
163 const KURL&, const KURL&, const QString&, const QString& ) ) );
165 connect( signalCollection, SIGNAL( setMainCaption( const QString& ) ),
166 SLOT( slotSetMainCaption( const QString& ) ) );
168 connect( signalCollection, SIGNAL( setMainStatusbar( const QString& ) ),
169 SLOT( slotSetMainStatusbar( const QString& ) ) );
171 connect( signalCollection, SIGNAL( setMainURLLine( const KURL& ) ),
172 SLOT( setUrl( const KURL& ) ) );
174 connect( signalCollection, SIGNAL( bookmarked( const QString&, bool ) ),
175 SLOT( bookmark( const QString&, bool ) ) );
177 connect( this, SIGNAL( favoritesUpdated() ),
178 signalCollection, SIGNAL( favoritesUpdated() ) );
180 connect( m_urlLine, SIGNAL( returnPressed() ),
181 SLOT( slotURLLine() ) );
183 QPopupMenu* settingsPopup = static_cast<QPopupMenu *>( factory() ->container( "settings", this ) );
184 connect( settingsPopup, SIGNAL( aboutToShow() ),
185 SLOT( settingsMenuAboutToShow() ) );
187 // load favorite boards;
188 loadFavoriteBoards();
192 QString configPath = locateLocal( "appdata", "board_list" );
193 if ( QFile::exists( configPath ) ) {
194 m_bbsTab->showBoardList();
195 m_bbsTab->loadOpened();
197 m_bbsTab->updateBoardList();
205 m_bbsDock->slotShowDock();
207 // update favorite list
208 emit favoritesUpdated();
210 if ( KitaConfig::autoLogin() ) {
215 KitaMainWindow::~KitaMainWindow()
217 /* save dock status */
218 m_bbsDock->saveSession();
219 m_subjectDock->saveSession();
220 m_threadDock->saveSession();
221 m_naviDock->saveSession();
222 m_imgDock->saveSession();
223 m_writeDock->saveSession();
235 saveFavoriteBoards();
241 saveMainWindowSettings( KGlobal::config(), "MainWindow" );
243 KitaConfig::writeConfig( KGlobal::config() );
245 QString dockConfigPath = locateLocal( "appdata", "dock.conf" );
246 KConfig dockConfig( dockConfigPath );
247 writeDockConfig( &dockConfig );
255 Kita::DatManager::deleteAllDatInfo();
258 void KitaMainWindow::load( const KURL& url )
261 // the below code is what you should normally do. in this
262 // example case, we want the url to our own. you probably
263 // want to use this code instead for your app
266 // download the contents
267 if ( KIO::NetAccess::download( url, target ) ) {
271 // load in the file (target is always local)
274 // and remove the temp file
275 KIO::NetAccess::removeTempFile( target );
279 setCaption( url.url() );
280 // m_view->openURL(url);
283 void KitaMainWindow::setupActions()
285 KStdAction::quit( this, SLOT( close() ), actionCollection() );
286 KStdAction::copy( this, SLOT( slotEditCopy() ), actionCollection() );
288 m_toolbarAction = KStdAction::showToolbar( this,
289 SLOT( optionsShowToolbar() ),
290 actionCollection() );
292 m_statusbarAction = KStdAction::showStatusbar( this,
293 SLOT( optionsShowStatusbar() ),
294 actionCollection() );
296 m_boardListAction = new KToggleAction( i18n( "Show board list" ),
299 SLOT( slotToggleShowHide() ),
301 "window_show_board_list" );
303 m_subjectListAction = new KToggleAction( i18n( "Show subject list" ),
306 SLOT( slotToggleShowHide() ),
308 "window_show_subject_list" );
310 m_showImgViewAction = new KToggleAction( i18n( "Show Image Viewer" ),
313 SLOT( slotToggleShowHide() ),
315 "window_show_imgviewer" );
317 m_showNaviAction = new KToggleAction( i18n( "Show KitaNavi" ),
320 SLOT( slotToggleShowHide() ),
322 "window_show_kitanavi" );
324 m_showWriteDockAction = new KToggleAction( i18n( "Show Write Dock" ),
327 SLOT( slotToggleShowHide() ),
329 "window_show_writedock" );
331 m_urlLine = new KLineEdit( "", 0 );
333 new KWidgetAction( m_urlLine,
337 SLOT( slotURLLine() ),
338 actionCollection(), "url_line_action" );
340 KStdAction::keyBindings( this, SLOT( optionsConfigureKeys() ), actionCollection() );
341 KStdAction::configureToolbars( this, SLOT( optionsConfigureToolbars() ), actionCollection() );
342 KStdAction::preferences( this, SLOT( optionsPreferences() ), actionCollection() );
344 /* new KAction( i18n( "Edit Favorites" ),
347 SLOT( favoritesEdit() ),
349 "favorites_edit" );*/
351 new KAction( i18n( "Load board list" ),
354 SLOT( updateBoardList() ),
358 new KAction( i18n( "reset windows" ),
361 SLOT( resetWindowsCust() ),
365 new KAction( i18n( "default 1" ),
368 SLOT( resetWindowsDef1() ),
372 new KAction( i18n( "default 2" ),
375 SLOT( resetWindowsDef2() ),
379 new KAction( i18n( "default 3" ),
382 SLOT( resetWindowsDef3() ),
386 m_toggleViewAction = new KAction(
387 i18n( "&Toggle subject view and thread view" ),
388 KShortcut( Qt::Key_F7 ),
390 SLOT( windowToggleView() ),
392 "window_toggle_view" );
394 new KAction( i18n( "Login" ),
401 setXMLFile( "kitaui.rc" );
402 KMainWindow::createGUI();
403 factory() ->addClient( m_bbsTab );
404 factory() ->addClient( m_subjectTab );
405 factory() ->addClient( m_threadTab );
406 factory() ->addClient( m_imgTab );
407 factory() ->addClient( m_naviTab );
408 factory() ->addClient( m_writeTab );
411 void KitaMainWindow::slotURLLine()
413 KURL url = m_urlLine->text();
414 KURL datURL = Kita::getDatURL( url );
415 m_threadDock->slotShowThread( datURL, KitaConfig::alwaysUseTab() );
418 void KitaMainWindow::saveProperties( KConfig* )
420 // the 'config' object points to the session managed
421 // config file. anything you write here will be available
422 // later when this app is restored
424 // if (m_view->currentURL() != QString::null)
425 // config->writeEntry("lastURL", m_view->currentURL());
426 // KitaConfig::writeConfig( config );
429 void KitaMainWindow::readProperties( KConfig* )
431 // the 'config' object points to the session managed
432 // config file. this function is automatically called whenever
433 // the app is being restored. read in here whatever you wrote
434 // in 'saveProperties'
436 // QString url = config->readEntry("lastURL");
438 // if (url != QString::null)
439 // m_view->openURL(KURL(url));
440 // KitaConfig::readConfig( config );
443 void KitaMainWindow::dragEnterEvent( QDragEnterEvent* event )
445 // accept uri drops only
446 event->accept( QUriDrag::canDecode( event ) );
449 void KitaMainWindow::dropEvent( QDropEvent* event )
451 // this is a very simplistic implementation of a drop event. we
452 // will only accept a dropped URL. the Qt dnd code can do *much*
453 // much more, so please read the docs there
456 // see if we can decode a URI.. if not, just ignore it
457 if ( QUriDrag::decode( event, uri ) ) {
458 // okay, we have a URI.. process it
467 void KitaMainWindow::optionsShowToolbar()
469 // this is all very cut and paste code for showing/hiding the
471 if ( m_toolbarAction->isChecked() ) {
478 void KitaMainWindow::optionsShowStatusbar()
480 // this is all very cut and paste code for showing/hiding the
482 if ( m_statusbarAction->isChecked() ) {
483 statusBar() ->show();
485 statusBar() ->hide();
489 void KitaMainWindow::optionsConfigureKeys()
491 KKeyDialog dlg( TRUE, this );
492 dlg.insert( actionCollection(), "Kita" );
496 void KitaMainWindow::optionsConfigureToolbars()
498 // use the standard toolbar editor
499 KEditToolbar dlg( factory() );
500 connect( &dlg, SIGNAL( newToolbarConfig() ),
501 SLOT( newToolbarConfig() ) );
505 void KitaMainWindow::newToolbarConfig()
507 // this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
508 // recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
509 applyMainWindowSettings( KGlobal::config(), "MainWindow" );
512 void KitaMainWindow::resetWindowsCust() { resetWindows( 0 ); }
513 void KitaMainWindow::resetWindowsDef1() { resetWindows( 1 ); }
514 void KitaMainWindow::resetWindowsDef2() { resetWindows( 2 ); }
515 void KitaMainWindow::resetWindowsDef3() { resetWindows( 3 ); }
517 void KitaMainWindow::resetWindows( int pattern )
519 if ( !m_dummyDock || !m_threadDock || !m_bbsDock
520 || !m_subjectDock || !m_naviDock || !m_imgDock || !m_writeDock ) return ;
522 makeDockVisible( m_threadDock );
523 makeDockVisible( m_bbsDock );
524 makeDockVisible( m_subjectDock );
525 makeDockVisible( m_naviDock );
526 makeDockVisible( m_imgDock );
527 makeDockVisible( m_writeDock );
529 makeDockInvisible( m_threadDock );
530 makeDockInvisible( m_bbsDock );
531 makeDockInvisible( m_subjectDock );
532 makeDockInvisible( m_naviDock );
533 makeDockInvisible( m_imgDock );
534 makeDockInvisible( m_writeDock );
536 m_threadDock->manualDock( m_dummyDock, KDockWidget::DockTop, 100 );
537 m_bbsDock->manualDock( m_threadDock, KDockWidget::DockLeft, 20 );
538 m_subjectDock->manualDock( m_threadDock, KDockWidget::DockTop, 25 );
539 m_imgDock->manualDock( m_threadDock, KDockWidget::DockTop, 25 );
540 m_writeDock->manualDock( m_threadDock, KDockWidget::DockBottom, 75 );
541 m_naviDock->manualDock( m_threadDock, KDockWidget::DockBottom, 50 );
545 /*----------------------------------------*/
548 /* setSession( docked, tabbed ) */
549 m_threadDock ->setSession( TRUE, FALSE );
550 m_bbsDock ->setSession( TRUE, FALSE );
551 m_subjectDock->setSession( TRUE, FALSE );
552 m_imgDock ->setSession( TRUE, FALSE );
553 m_writeDock ->setSession( TRUE, FALSE );
554 m_naviDock ->setSession( TRUE, FALSE );
556 if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
557 if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
558 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( TRUE );
559 if ( m_showNaviAction ) m_showNaviAction->setChecked( TRUE );
560 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( TRUE );
564 /*----------------------------------------*/
567 m_imgDock->toDesktop();
568 m_writeDock->toDesktop();
569 m_naviDock->toDesktop();
571 makeDockInvisible( m_imgDock );
572 makeDockInvisible( m_writeDock );
573 makeDockInvisible( m_naviDock );
575 /* setSession( docked, tabbed ) */
576 m_threadDock ->setSession( TRUE, FALSE );
577 m_bbsDock ->setSession( TRUE, FALSE );
578 m_subjectDock->setSession( TRUE, FALSE );
579 m_imgDock ->setSession( FALSE, FALSE );
580 m_writeDock ->setSession( FALSE, FALSE );
581 m_naviDock ->setSession( FALSE, FALSE );
583 if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
584 if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
585 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
586 if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
587 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
591 /*----------------------------------------*/
594 m_subjectDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
596 m_imgDock->toDesktop();
597 m_writeDock->toDesktop();
598 m_naviDock->toDesktop();
600 makeDockInvisible( m_imgDock );
601 makeDockInvisible( m_writeDock );
602 makeDockInvisible( m_naviDock );
604 /* setSession( docked, tabbed ) */
605 m_threadDock ->setSession( TRUE, TRUE );
606 m_bbsDock ->setSession( TRUE, FALSE );
607 m_subjectDock->setSession( TRUE, TRUE );
608 m_imgDock ->setSession( FALSE, FALSE );
609 m_writeDock ->setSession( FALSE, FALSE );
610 m_naviDock ->setSession( FALSE, FALSE );
612 if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
613 if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
614 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
615 if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
616 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
620 /*----------------------------------------*/
623 m_subjectDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
624 m_naviDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
625 m_imgDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
627 makeDockInvisible( m_imgDock );
628 makeDockInvisible( m_writeDock );
629 makeDockInvisible( m_naviDock );
631 /* setSession( docked, tabbed ) */
632 m_threadDock ->setSession( TRUE, TRUE );
633 m_bbsDock ->setSession( TRUE, FALSE );
634 m_subjectDock->setSession( TRUE, TRUE );
635 m_imgDock ->setSession( TRUE, TRUE );
636 m_writeDock ->setSession( TRUE, FALSE );
637 m_naviDock ->setSession( TRUE, TRUE );
639 if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
640 if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
641 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
642 if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
643 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
648 m_threadDock->slotShowDock();
652 void KitaMainWindow::windowToggleView()
654 //FIXME: m_subjectDock->dockSite() & KDockWidget::DockCenter != 0 °Ê³°¤Î¤È¤¤Ï¤É¤¦¤¹¤ë¡©
655 kdDebug() << "Do toggle" << endl;
656 if ( !m_subjectDock->isVisible()
657 || !m_subjectDock->isActiveWindow() ) m_subjectDock->slotShowDock();
659 m_threadDock->slotShowDock();
663 void KitaMainWindow::settingsMenuAboutToShow()
665 m_toolbarAction->setChecked( toolBar() ->isVisible() );
666 m_statusbarAction->setChecked( statusBar() ->isVisible() );
669 void KitaMainWindow::optionsPreferences()
671 // popup some sort of preference dialog, here
674 connect( &dlg, SIGNAL( fontChanged( const QFont& ) ),
675 SLOT( setFont( const QFont& ) ) );
678 dlg.setInitialSize( QSize( 600, 400 ) );
680 // redo your settings
684 void KitaMainWindow::slotSetMainStatusbar( const QString& statusStr )
686 // display the text on the statusbar
687 statusBar() ->message( statusStr );
690 void KitaMainWindow::setupView()
692 /* dummy Main Dock Widget */
693 m_dummyDock = createDockWidget( "dummy", 0L, 0L, "dummy", "dummy" );
694 m_dummyDock->setDockSite( KDockWidget::DockFullSite );
695 m_dummyDock->setEnableDocking( KDockWidget::DockNone );
696 setView( m_dummyDock );
697 setMainDockWidget( m_dummyDock );
700 m_subjectDock = new KitaSubjectDock( manager(), "subject", 0L, 0L, i18n( "subject" ), i18n( "subject" ) );
701 m_subjectTab = m_subjectDock->setup();
702 connect( m_subjectDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckSubjectToggleAction( bool ) ) );
705 m_bbsDock = new KitaBBSDock( manager(), "board", 0L, 0L, i18n( "board" ), i18n( "board" ) );
706 m_bbsTab = m_bbsDock->setup();
707 connect( m_bbsDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckBoardToggleAction( bool ) ) );
710 m_threadDock = new KitaThreadDock( manager(), "Thread", 0L, 0L, i18n( "Thread" ), i18n( "Thread" ) );
711 m_threadTab = m_threadDock->setupAsMainView();
712 m_threadDock->setDockSite( KDockWidget::DockFullSite );
715 m_naviDock = new KitaThreadDock( manager(), "kitanavi", 0L, 0L, i18n( "KitaNavi" ), i18n( "Navi" ) );
716 m_naviTab = m_naviDock->setupAsKitaNavi();
717 connect( m_naviDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckNaviToggleAction( bool ) ) );
719 if ( !KitaConfig::useKitaNavi() ) m_threadDock ->connectNaviSignals();
720 else m_naviDock->connectNaviSignals();
723 m_imgDock = new KitaImgDock( manager(), "imgviewer", 0L, 0L, i18n( "Kita Image Viewer" ), i18n( "Image" ) );
724 m_imgTab = m_imgDock->setup();
725 connect( m_imgDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckImgToggleAction( bool ) ) );
728 m_writeDock = new KitaWriteDock( manager(), "Write", 0L, 0L, i18n( "Write" ), i18n( "Write" ) );
729 m_writeTab = m_writeDock->setup();
730 connect( m_writeDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckWriteToggleAction( bool ) ) );
732 /* reset dock status */
733 m_boardListAction = NULL;
734 m_subjectListAction = NULL;
735 m_showImgViewAction = NULL;
736 m_showNaviAction = NULL;
737 m_showWriteDockAction = NULL;
741 void KitaMainWindow::closeSubjectView()
743 m_subjectListAction->setChecked( FALSE );
746 void KitaMainWindow::slotCheckBoardToggleAction( bool check )
748 if ( m_boardListAction ) m_boardListAction->setChecked( check );
751 void KitaMainWindow::slotCheckSubjectToggleAction( bool check )
753 if ( m_subjectListAction ) m_subjectListAction->setChecked( check );
756 void KitaMainWindow::slotCheckNaviToggleAction( bool check )
758 if ( m_showNaviAction ) m_showNaviAction->setChecked( check );
761 void KitaMainWindow::slotCheckImgToggleAction( bool check )
763 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( check );
767 void KitaMainWindow::slotCheckWriteToggleAction( bool check )
769 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( check );
773 /* open url */ /* public slot */ /* obsolete */
774 void KitaMainWindow::slotOpenURLRequest( const KURL& url, const KParts::URLArgs& args )
776 slotOpenURLRequestExt( url, args );
782 If mimetype == "kita_open_2chboard", open the board.
783 If mimetype == "kita_open_2chthread", open the thread.
784 If mimetype == "text/html", open url with web browser.
785 if mimetype == QString::null, use KIO::NetAccess::mimetype to decide mime type of url.
788 void KitaMainWindow::slotOpenURLRequestExt(
789 const KURL& url, const KParts::URLArgs& args,
792 const KURL& usrUrl1, const KURL& usrUrl2,
793 const QString& usrStr1, const QString& usrStr2 )
795 // FIXME: support be.2ch.net
796 if ( url.host() == "be.2ch.net" ) {
797 QMessageBox::warning( this,
799 i18n( "be.2ch.net is currently not supported." ) );
803 kdDebug() << QString( "Requested OpenURL: \"%1\"" ).arg( url.url() ) << endl;
804 kdDebug() << QString( "content type: \"%1\"" ).arg( args.contentType() ) << endl;
805 kdDebug() << QString( "service type: \"%1\"" ).arg( args.serviceType ) << endl;
806 kdDebug() << QString( "NewTab: %1, reload: %2" )
807 .arg( args.newTab() ? "yes" : "no" )
808 .arg( args.reload ? "yes" : "no" ) << endl;
811 /* if usr1 == 1, open the board with new tab. */
812 if ( mimetype == "kita_open_2chboard" ) {
813 bool withNewTab = ( usr1 == 1 );
814 m_subjectDock->slotLoadBoard( url, withNewTab );
818 /* open 2ch thread */
819 /* if usr1 == 1, open the thread with new tab. */
820 if ( mimetype == "kita_open_2chthread" ) {
821 bool withNewTab = ( usr1 == 1 );
822 m_threadDock->slotShowThread( url, withNewTab );
826 /* open url with web browser, etc. */
827 if ( mimetype != QString::null ) {
828 if ( KitaConfig::copyOnClick() ) {
829 QClipboard * clipboard = QApplication::clipboard();
830 clipboard->setText( url.prettyURL(), QClipboard::Clipboard );
831 clipboard->setText( url.prettyURL(), QClipboard::Selection );
833 KRun::runURL( url, mimetype );
838 /* open thread with new thread tab */
839 if ( Kita::DatManager::isThreadEnrolled( url ) ) {
840 m_threadDock->slotShowThread( url, true );
845 if ( Kita::ImgManager::isBMP( url ) ) {
846 QMessageBox::warning( this,
848 i18n( "This is a BMP file. It might contain a Troy." ) );
853 /* open with image viewer */
854 /* if usr1 == 0, image viewer is hidden. */
855 /* usrUrl1 is datURL. */
856 if ( KitaConfig::useImageViewer() ) {
857 if ( Kita::ImgManager::isImgFile( url, FALSE ) ) {
859 if ( !usr1 ) m_imgDock->slotHideDock();
860 m_imgDock->slotOpenURL( url, usrUrl1, usr1 );
865 if ( mimetype == QString::null ) {
866 #if KDE_IS_VERSION( 3, 2, 0 )
867 mimetype = KIO::NetAccess::mimetype( url , this );
869 mimetype = KIO::NetAccess::mimetype( url );
873 kdDebug() << QString( "queried MIME type: \"%1\"" ).arg( mimetype ) << endl;
875 /* open with kpart */
876 if ( KitaConfig::usePart() ) {
877 if ( KitaConfig::partMimeList().find( mimetype ) != KitaConfig::partMimeList().end() ) {
878 KService::Ptr service = KServiceTypeProfile::preferredService( mimetype, "KParts/ReadOnlyPart" );
880 QString libName = QFile::encodeName( service->library() );
882 if ( !KitaConfig::useKitaNavi() ) m_threadDock->slotShowPart( url, libName, mimetype );
883 else m_naviDock ->slotShowPart( url, libName, mimetype );
889 if ( KitaConfig::copyOnClick() ) {
890 QClipboard * clipboard = QApplication::clipboard();
891 clipboard->setText( url.prettyURL(), QClipboard::Clipboard );
892 clipboard->setText( url.prettyURL(), QClipboard::Selection );
894 KRun::runURL( url, mimetype );
899 void KitaMainWindow::loadCache()
901 KitaThreadInfo * cache = KitaThreadInfo::getInstance();
902 QString cacheConfigPath = locateLocal( "appdata", "cache" );
903 QFile file( cacheConfigPath );
904 if ( file.open( IO_ReadOnly ) ) {
905 QDataStream stream( &file );
910 void KitaMainWindow::saveCache()
912 KitaThreadInfo * cache = KitaThreadInfo::getInstance();
913 QString cacheConfigPath = locateLocal( "appdata", "cache" );
914 QFile file( cacheConfigPath );
915 if ( file.open( IO_WriteOnly ) ) {
916 QDataStream stream( &file );
923 \fn KitaMainWindow::setFont(QFont& font)
926 void KitaMainWindow::setFont( const QFont& font )
928 m_subjectTab->setFont( font );
929 m_bbsTab->setFont( font );
933 void KitaMainWindow::setUrl( const KURL& url )
935 m_urlLine->setText( url.url() );
938 void KitaMainWindow::bookmark( const QString& datURL, bool on )
940 FavoriteThreads * favorite = FavoriteThreads::getInstance();
943 favorite->insert( datURL );
945 favorite->remove( datURL );
948 emit favoritesUpdated();
951 void KitaMainWindow::loadFavorites()
953 QString favoritesConfigPath = locateLocal( "appdata", "favorites.xml" );
954 QFile file( favoritesConfigPath );
955 if ( file.open( IO_ReadOnly ) ) {
956 QTextStream stream( &file );
957 stream.setEncoding( QTextStream::UnicodeUTF8 );
959 QString xml = stream.read();
960 FavoriteThreads::readFromXML( xml );
964 void KitaMainWindow::saveFavorites()
966 QString favoritesConfigPath = locateLocal( "appdata", "favorites.xml" );
967 QFile file( favoritesConfigPath );
968 if ( file.open( IO_WriteOnly ) ) {
969 QTextStream stream( &file );
970 stream.setEncoding( QTextStream::UnicodeUTF8 );
971 stream << FavoriteThreads::getInstance() ->toXML();
975 void KitaMainWindow::loadCompletion()
977 QString configPath = locateLocal( "appdata", "completion" );
978 KSimpleConfig config( configPath );
980 KitaConfig::setNameCompletionItems( config.readListEntry( "name" ) );
983 void KitaMainWindow::saveCompletion()
985 QString configPath = locateLocal( "appdata", "completion" );
986 KSimpleConfig config( configPath );
988 config.writeEntry( "name", KitaConfig::nameCompletion() ->items() );
992 void KitaMainWindow::loadStyleSheet()
994 QString configPath = locateLocal( "appdata", "stylesheet" );
995 QFile file( configPath );
996 if ( file.open( IO_ReadOnly ) ) {
997 QTextStream stream( &file );
998 stream.setEncoding( QTextStream::UnicodeUTF8 );
1003 while ( ( str = stream.readLine() ) != QString::null ) {
1004 if ( ! str.isEmpty() ) {
1008 KitaConfig::setStyleSheetText( list.join( "\n" ) );
1012 void KitaMainWindow::saveStyleSheet()
1014 QString configPath = locateLocal( "appdata", "stylesheet" );
1015 QFile file( configPath );
1016 if ( file.open( IO_WriteOnly ) ) {
1017 QTextStream stream( &file ) ;
1018 stream.setEncoding( QTextStream::UnicodeUTF8 );
1020 stream << KitaConfig::styleSheetText();
1024 void KitaMainWindow::loadAsciiArt()
1026 QString configPath = locateLocal( "appdata", "asciiart" );
1027 QFile file( configPath );
1028 if ( file.open( IO_ReadOnly ) ) {
1029 QTextStream stream( &file );
1030 stream.setEncoding( QTextStream::UnicodeUTF8 );
1035 while ( ( str = stream.readLine() ) != QString::null ) {
1036 if ( ! str.isEmpty() ) {
1040 KitaConfig::setAsciiArtList( list );
1044 void KitaMainWindow::saveAsciiArt()
1046 QString configPath = locateLocal( "appdata", "asciiart" );
1047 QFile file( configPath );
1048 if ( file.open( IO_WriteOnly ) ) {
1049 QTextStream stream( &file ) ;
1050 stream.setEncoding( QTextStream::UnicodeUTF8 );
1052 QStringList list = KitaConfig::asciiArtList();
1053 QStringList::iterator it;
1054 for ( it = list.begin(); it != list.end(); ++it ) {
1055 stream << ( *it ) << endl;
1060 void KitaMainWindow::loadFavoriteBoards()
1062 QString configPath = locateLocal( "appdata", "favorite_boards.xml" );
1063 QFile file( configPath );
1064 if ( file.open( IO_ReadOnly ) ) {
1065 QTextStream stream( &file );
1066 stream.setEncoding( QTextStream::UnicodeUTF8 );
1068 QString xml = stream.read();
1069 Kita::FavoriteBoards::readFromXML( xml );
1073 void KitaMainWindow::saveFavoriteBoards()
1075 QString configPath = locateLocal( "appdata", "favorite_boards.xml" );
1076 QFile file( configPath );
1077 if ( file.open( IO_WriteOnly ) ) {
1078 QTextStream stream( &file );
1079 stream.setEncoding( QTextStream::UnicodeUTF8 );
1080 stream << Kita::FavoriteBoards::toXML();
1084 void KitaMainWindow::loadAboneIDList()
1086 QString configPath = locateLocal( "appdata", "abone_id" );
1087 QFile file( configPath );
1088 if ( file.open( IO_ReadOnly ) ) {
1089 QTextStream stream( &file );
1090 stream.setEncoding( QTextStream::UnicodeUTF8 );
1095 while ( ( str = stream.readLine() ) != QString::null ) {
1096 if ( ! str.isEmpty() ) {
1100 KitaConfig::setAboneIDList( list );
1104 void KitaMainWindow::saveAboneIDList()
1106 QString configPath = locateLocal( "appdata", "abone_id" );
1107 QFile file( configPath );
1108 if ( file.open( IO_WriteOnly ) ) {
1109 QTextStream stream( &file ) ;
1110 stream.setEncoding( QTextStream::UnicodeUTF8 );
1112 QStringList list = KitaConfig::aboneIDList();
1113 QStringList::iterator it;
1114 for ( it = list.begin(); it != list.end(); ++it ) {
1115 stream << ( *it ) << endl;
1120 void KitaMainWindow::loadAboneNameList()
1122 QString configPath = locateLocal( "appdata", "abone_name" );
1123 QFile file( configPath );
1124 if ( file.open( IO_ReadOnly ) ) {
1125 QTextStream stream( &file );
1126 stream.setEncoding( QTextStream::UnicodeUTF8 );
1131 while ( ( str = stream.readLine() ) != QString::null ) {
1132 if ( ! str.isEmpty() ) {
1136 KitaConfig::setAboneNameList( list );
1140 void KitaMainWindow::saveAboneNameList()
1142 QString configPath = locateLocal( "appdata", "abone_name" );
1143 QFile file( configPath );
1144 if ( file.open( IO_WriteOnly ) ) {
1145 QTextStream stream( &file ) ;
1146 stream.setEncoding( QTextStream::UnicodeUTF8 );
1148 QStringList list = KitaConfig::aboneNameList();
1149 QStringList::iterator it;
1150 for ( it = list.begin(); it != list.end(); ++it ) {
1151 stream << ( *it ) << endl;
1156 void KitaMainWindow::loadAboneWordList()
1158 QString configPath = locateLocal( "appdata", "abone_word" );
1159 QFile file( configPath );
1160 if ( file.open( IO_ReadOnly ) ) {
1161 QTextStream stream( &file );
1162 stream.setEncoding( QTextStream::UnicodeUTF8 );
1167 while ( ( str = stream.readLine() ) != QString::null ) {
1168 if ( ! str.isEmpty() ) {
1172 KitaConfig::setAboneWordList( list );
1176 void KitaMainWindow::saveAboneWordList()
1178 QString configPath = locateLocal( "appdata", "abone_word" );
1179 QFile file( configPath );
1180 if ( file.open( IO_WriteOnly ) ) {
1181 QTextStream stream( &file ) ;
1182 stream.setEncoding( QTextStream::UnicodeUTF8 );
1184 QStringList list = KitaConfig::aboneWordList();
1185 QStringList::iterator it;
1186 for ( it = list.begin(); it != list.end(); ++it ) {
1187 stream << ( *it ) << endl;
1192 void KitaMainWindow::slotSetMainCaption( const QString& captionStr )
1194 setCaption( captionStr );
1197 void KitaMainWindow::slotEditCopy()
1199 QWidget * widget = kapp->focusWidget();
1202 QKeyEvent e( QEvent::KeyPress, Key_C, 'C', ControlButton );
1203 QApplication::sendEvent( widget, &e );
1207 void KitaMainWindow::login()
1209 if ( Kita::Account::login( KitaConfig::userID(), KitaConfig::password() ) ) {
1210 slotSetMainStatusbar( i18n( "Login succeeded." ) );
1212 slotSetMainStatusbar( i18n( "Login failed." ) );
1216 void KitaMainWindow::favoritesEdit()
1218 FavoritesWindow * window = new FavoritesWindow( this );
1222 #include "mainwindow.moc"