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"
36 #include "libkita/config_xt.h"
37 #include "libkita/asciiart.h"
38 #include "libkita/abone.h"
40 #include "image/imagetabwidget.h"
42 #include <qdragobject.h>
43 #include <qtextcodec.h>
46 #include <qmessagebox.h>
47 #include <qclipboard.h>
49 #include <klineedit.h>
52 #include <kiconloader.h>
54 #include <kstatusbar.h>
55 #include <kkeydialog.h>
57 #include <kio/netaccess.h>
58 #include <kuserprofile.h>
59 #include <kfiledialog.h>
63 #include <kstandarddirs.h>
65 #include <ksimpleconfig.h>
66 #include <kedittoolbar.h>
67 #include <kstdaccel.h>
69 #include <kstdaction.h>
70 #include <kshortcut.h>
71 #include <kaboutdata.h>
72 #include <kparts/partmanager.h>
73 #include <kdeversion.h>
76 KitaMainWindow::KitaMainWindow()
77 : KParts::DockMainWindow( 0, "Kita" ),
81 KGlobal::locale() ->insertCatalogue( "kitapart" );
84 setAcceptDrops( true );
87 Kita::ImgManager::setup( this );
92 // then, setup our actions
102 Kita::AsciiArtConfig::self()->readConfig();
103 if ( Kita::AsciiArtConfig::self()->asciiArtList().empty() ) {
108 Kita::AboneConfig::self()->readConfig();
109 if ( Kita::AboneConfig::self()->aboneIDList().empty() ) {
113 if ( Kita::AboneConfig::self()->aboneNameList().empty() ) {
117 if ( Kita::AboneConfig::self()->aboneWordList().empty() ) {
122 statusBar() ->show();
125 m_bbsDock->loadSession();
126 m_boardDock->loadSession();
127 m_threadDock->loadSession();
128 m_naviDock->loadSession();
129 m_imageDock->loadSession();
130 m_writeDock->loadSession();
131 QString dockConfigPath = locateLocal( "appdata", "dock.conf" );
132 KConfig dockConfig( dockConfigPath );
133 readDockConfig( &dockConfig );
136 m_boardDock->slotShowDock();
139 m_threadDock->slotShowDock();
142 makeDockInvisible( m_writeDock );
143 m_showImgViewAction->setChecked( FALSE );
146 makeDockInvisible( m_naviDock );
147 m_showNaviAction->setChecked( FALSE );
150 makeDockInvisible( m_imageDock );
151 m_showImgViewAction->setChecked( FALSE );
154 KitaConfig::readConfig( KGlobal::config() );
155 Kita::Config::self()->readConfig();
157 if ( Kita::Config::self()->nameCompletionList().empty() ) {
161 // apply the saved mainwindow settings, if any, and ask the mainwindow
162 // to automatically save settings if changed: window size, toolbar
163 // position, icon size, etc.
164 setAutoSaveSettings();
167 setFont( Kita::Config::font() );
169 // allow the view to change the statusbar and caption
170 Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
172 connect( signalCollection, SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ),
173 SLOT( slotOpenURLRequest( const KURL&, const KParts::URLArgs& ) ) );
175 connect( signalCollection, SIGNAL( openURLRequestExt(
176 const KURL&, const KParts::URLArgs&, QString, int,
178 SLOT( slotOpenURLRequestExt(
179 const KURL& , const KParts::URLArgs&, QString, int,
182 connect( signalCollection, SIGNAL( setMainCaption( const QString& ) ),
183 SLOT( slotSetMainCaption( const QString& ) ) );
185 connect( signalCollection, SIGNAL( setMainStatusbar( const QString& ) ),
186 SLOT( slotSetMainStatusbar( const QString& ) ) );
188 connect( signalCollection, SIGNAL( setMainURLLine( const KURL& ) ),
189 SLOT( setUrl( const KURL& ) ) );
191 connect( signalCollection, SIGNAL( bookmarked( const QString&, bool ) ),
192 SLOT( bookmark( const QString&, bool ) ) );
194 connect( this, SIGNAL( favoritesUpdated() ),
195 signalCollection, SIGNAL( favoritesUpdated() ) );
197 connect( m_urlLine, SIGNAL( returnPressed() ),
198 SLOT( slotURLLine() ) );
200 QPopupMenu* settingsPopup = static_cast<QPopupMenu *>( factory() ->container( "settings", this ) );
201 connect( settingsPopup, SIGNAL( aboutToShow() ),
202 SLOT( settingsMenuAboutToShow() ) );
204 // load favorite boards;
205 loadFavoriteBoards();
209 QString configPath = locateLocal( "appdata", "board_list" );
210 if ( QFile::exists( configPath ) ) {
211 m_bbsTab->showBoardList();
212 m_bbsTab->loadOpened();
214 m_bbsTab->updateBoardList();
222 m_bbsDock->slotShowDock();
224 // update favorite list
225 emit favoritesUpdated();
227 if ( Kita::Config::autoLogin() ) {
232 KitaMainWindow::~KitaMainWindow()
234 /* save dock status */
235 m_bbsDock->saveSession();
236 m_boardDock->saveSession();
237 m_threadDock->saveSession();
238 m_naviDock->saveSession();
239 m_imageDock->saveSession();
240 m_writeDock->saveSession();
242 Kita::AboneConfig::self()->writeConfig();
246 Kita::AsciiArtConfig::self()->writeConfig();
248 saveFavoriteBoards();
254 saveMainWindowSettings( KGlobal::config(), "MainWindow" );
256 KitaConfig::writeConfig( KGlobal::config() );
257 Kita::Config::self()->writeConfig();
259 QString dockConfigPath = locateLocal( "appdata", "dock.conf" );
260 KConfig dockConfig( dockConfigPath );
261 writeDockConfig( &dockConfig );
269 Kita::DatManager::deleteAllDatInfo();
272 void KitaMainWindow::load( const KURL& url )
275 // the below code is what you should normally do. in this
276 // example case, we want the url to our own. you probably
277 // want to use this code instead for your app
280 // download the contents
281 if ( KIO::NetAccess::download( url, target ) ) {
285 // load in the file (target is always local)
288 // and remove the temp file
289 KIO::NetAccess::removeTempFile( target );
293 setCaption( url.url() );
294 // m_view->openURL(url);
297 void KitaMainWindow::setupActions()
299 KStdAction::quit( this, SLOT( close() ), actionCollection() );
300 KStdAction::copy( this, SLOT( slotEditCopy() ), actionCollection() );
302 m_toolbarAction = KStdAction::showToolbar( this,
303 SLOT( optionsShowToolbar() ),
304 actionCollection() );
306 m_statusbarAction = KStdAction::showStatusbar( this,
307 SLOT( optionsShowStatusbar() ),
308 actionCollection() );
310 m_boardListAction = new KToggleAction( i18n( "Show board list" ),
313 SLOT( slotToggleShowHide() ),
315 "window_show_board_list" );
317 m_subjectListAction = new KToggleAction( i18n( "Show subject list" ),
320 SLOT( slotToggleShowHide() ),
322 "window_show_subject_list" );
324 m_showImgViewAction = new KToggleAction( i18n( "Show Image Viewer" ),
327 SLOT( slotToggleShowHide() ),
329 "window_show_imgviewer" );
331 m_showNaviAction = new KToggleAction( i18n( "Show KitaNavi" ),
334 SLOT( slotToggleShowHide() ),
336 "window_show_kitanavi" );
338 m_showWriteDockAction = new KToggleAction( i18n( "Show Write Dock" ),
341 SLOT( slotToggleShowHide() ),
343 "window_show_writedock" );
345 m_urlLine = new KLineEdit( "", 0 );
347 new KWidgetAction( m_urlLine,
351 SLOT( slotURLLine() ),
352 actionCollection(), "url_line_action" );
354 KStdAction::keyBindings( this, SLOT( optionsConfigureKeys() ), actionCollection() );
355 KStdAction::configureToolbars( this, SLOT( optionsConfigureToolbars() ), actionCollection() );
356 KStdAction::preferences( this, SLOT( optionsPreferences() ), actionCollection() );
358 /* new KAction( i18n( "Edit Favorites" ),
361 SLOT( favoritesEdit() ),
363 "favorites_edit" );*/
365 new KAction( i18n( "Load board list" ),
368 SLOT( updateBoardList() ),
372 new KAction( i18n( "reset windows" ),
375 SLOT( resetWindowsCust() ),
379 new KAction( i18n( "default 1" ),
382 SLOT( resetWindowsDef1() ),
386 new KAction( i18n( "default 2" ),
389 SLOT( resetWindowsDef2() ),
393 new KAction( i18n( "default 3" ),
396 SLOT( resetWindowsDef3() ),
400 m_toggleViewAction = new KAction(
401 i18n( "&Toggle subject view and thread view" ),
402 KShortcut( Qt::Key_F7 ),
404 SLOT( windowToggleView() ),
406 "window_toggle_view" );
408 new KAction( i18n( "Login" ),
415 setXMLFile( "kitaui.rc" );
416 KMainWindow::createGUI();
417 factory() ->addClient( m_bbsTab );
418 factory() ->addClient( m_boardTab );
419 factory() ->addClient( m_threadTab );
420 factory() ->addClient( m_imageTab );
421 factory() ->addClient( m_naviTab );
422 factory() ->addClient( m_writeTab );
425 void KitaMainWindow::slotURLLine()
427 KURL url = m_urlLine->text();
428 KURL datURL = Kita::getDatURL( url );
429 m_threadDock->slotShowThread( datURL, Kita::Config::alwaysUseTab() );
432 void KitaMainWindow::saveProperties( KConfig* )
434 // the 'config' object points to the session managed
435 // config file. anything you write here will be available
436 // later when this app is restored
438 // if (m_view->currentURL() != QString::null)
439 // config->writeEntry("lastURL", m_view->currentURL());
440 // KitaConfig::writeConfig( config );
443 void KitaMainWindow::readProperties( KConfig* )
445 // the 'config' object points to the session managed
446 // config file. this function is automatically called whenever
447 // the app is being restored. read in here whatever you wrote
448 // in 'saveProperties'
450 // QString url = config->readEntry("lastURL");
452 // if (url != QString::null)
453 // m_view->openURL(KURL(url));
454 // KitaConfig::readConfig( config );
457 void KitaMainWindow::dragEnterEvent( QDragEnterEvent* event )
459 // accept uri drops only
460 event->accept( QUriDrag::canDecode( event ) );
463 void KitaMainWindow::dropEvent( QDropEvent* event )
465 // this is a very simplistic implementation of a drop event. we
466 // will only accept a dropped URL. the Qt dnd code can do *much*
467 // much more, so please read the docs there
470 // see if we can decode a URI.. if not, just ignore it
471 if ( QUriDrag::decode( event, uri ) ) {
472 // okay, we have a URI.. process it
481 void KitaMainWindow::optionsShowToolbar()
483 // this is all very cut and paste code for showing/hiding the
485 if ( m_toolbarAction->isChecked() ) {
492 void KitaMainWindow::optionsShowStatusbar()
494 // this is all very cut and paste code for showing/hiding the
496 if ( m_statusbarAction->isChecked() ) {
497 statusBar() ->show();
499 statusBar() ->hide();
503 void KitaMainWindow::optionsConfigureKeys()
505 KKeyDialog dlg( TRUE, this );
506 dlg.insert( actionCollection(), "Kita" );
510 void KitaMainWindow::optionsConfigureToolbars()
512 // use the standard toolbar editor
513 KEditToolbar dlg( factory() );
514 connect( &dlg, SIGNAL( newToolbarConfig() ),
515 SLOT( newToolbarConfig() ) );
519 void KitaMainWindow::newToolbarConfig()
521 // this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
522 // recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
523 applyMainWindowSettings( KGlobal::config(), "MainWindow" );
526 void KitaMainWindow::resetWindowsCust() { resetWindows( 0 ); }
527 void KitaMainWindow::resetWindowsDef1() { resetWindows( 1 ); }
528 void KitaMainWindow::resetWindowsDef2() { resetWindows( 2 ); }
529 void KitaMainWindow::resetWindowsDef3() { resetWindows( 3 ); }
531 void KitaMainWindow::resetWindows( int pattern )
533 if ( !m_dummyDock || !m_threadDock || !m_bbsDock
534 || !m_boardDock || !m_naviDock || !m_imageDock || !m_writeDock ) return ;
536 makeDockVisible( m_threadDock );
537 makeDockVisible( m_bbsDock );
538 makeDockVisible( m_boardDock );
539 makeDockVisible( m_naviDock );
540 makeDockVisible( m_imageDock );
541 makeDockVisible( m_writeDock );
543 makeDockInvisible( m_threadDock );
544 makeDockInvisible( m_bbsDock );
545 makeDockInvisible( m_boardDock );
546 makeDockInvisible( m_naviDock );
547 makeDockInvisible( m_imageDock );
548 makeDockInvisible( m_writeDock );
550 m_threadDock->manualDock( m_dummyDock, KDockWidget::DockTop, 100 );
551 m_bbsDock->manualDock( m_threadDock, KDockWidget::DockLeft, 20 );
552 m_boardDock->manualDock( m_threadDock, KDockWidget::DockTop, 25 );
553 m_imageDock->manualDock( m_threadDock, KDockWidget::DockTop, 25 );
554 m_writeDock->manualDock( m_threadDock, KDockWidget::DockBottom, 75 );
555 m_naviDock->manualDock( m_threadDock, KDockWidget::DockBottom, 50 );
559 /*----------------------------------------*/
562 /* setSession( docked, tabbed ) */
563 m_threadDock ->setSession( TRUE, FALSE );
564 m_bbsDock ->setSession( TRUE, FALSE );
565 m_boardDock->setSession( TRUE, FALSE );
566 m_imageDock ->setSession( TRUE, FALSE );
567 m_writeDock ->setSession( TRUE, FALSE );
568 m_naviDock ->setSession( TRUE, FALSE );
570 if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
571 if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
572 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( TRUE );
573 if ( m_showNaviAction ) m_showNaviAction->setChecked( TRUE );
574 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( TRUE );
578 /*----------------------------------------*/
581 m_imageDock->toDesktop();
582 m_writeDock->toDesktop();
583 m_naviDock->toDesktop();
585 makeDockInvisible( m_imageDock );
586 makeDockInvisible( m_writeDock );
587 makeDockInvisible( m_naviDock );
589 /* setSession( docked, tabbed ) */
590 m_threadDock ->setSession( TRUE, FALSE );
591 m_bbsDock ->setSession( TRUE, FALSE );
592 m_boardDock->setSession( TRUE, FALSE );
593 m_imageDock ->setSession( FALSE, FALSE );
594 m_writeDock ->setSession( FALSE, FALSE );
595 m_naviDock ->setSession( FALSE, FALSE );
597 if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
598 if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
599 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
600 if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
601 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
605 /*----------------------------------------*/
608 m_boardDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
610 m_imageDock->toDesktop();
611 m_writeDock->toDesktop();
612 m_naviDock->toDesktop();
614 makeDockInvisible( m_imageDock );
615 makeDockInvisible( m_writeDock );
616 makeDockInvisible( m_naviDock );
618 /* setSession( docked, tabbed ) */
619 m_threadDock ->setSession( TRUE, TRUE );
620 m_bbsDock ->setSession( TRUE, FALSE );
621 m_boardDock->setSession( TRUE, TRUE );
622 m_imageDock ->setSession( FALSE, FALSE );
623 m_writeDock ->setSession( FALSE, FALSE );
624 m_naviDock ->setSession( FALSE, FALSE );
626 if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
627 if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
628 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
629 if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
630 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
634 /*----------------------------------------*/
637 m_boardDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
638 m_naviDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
639 m_imageDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
641 makeDockInvisible( m_imageDock );
642 makeDockInvisible( m_writeDock );
643 makeDockInvisible( m_naviDock );
645 /* setSession( docked, tabbed ) */
646 m_threadDock ->setSession( TRUE, TRUE );
647 m_bbsDock ->setSession( TRUE, FALSE );
648 m_boardDock->setSession( TRUE, TRUE );
649 m_imageDock ->setSession( TRUE, TRUE );
650 m_writeDock ->setSession( TRUE, FALSE );
651 m_naviDock ->setSession( TRUE, TRUE );
653 if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
654 if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
655 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
656 if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
657 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
662 m_threadDock->slotShowDock();
666 void KitaMainWindow::windowToggleView()
668 //FIXME: m_boardDock->dockSite() & KDockWidget::DockCenter != 0 igai no toki ha dousuru?
669 kdDebug() << "Do toggle" << endl;
670 if ( !m_boardDock->isVisible()
671 || !m_boardDock->isActiveWindow() ) m_boardDock->slotShowDock();
673 m_threadDock->slotShowDock();
677 void KitaMainWindow::settingsMenuAboutToShow()
679 m_toolbarAction->setChecked( toolBar() ->isVisible() );
680 m_statusbarAction->setChecked( statusBar() ->isVisible() );
683 void KitaMainWindow::optionsPreferences()
685 // popup some sort of preference dialog, here
686 if ( KConfigDialog::showDialog( "Kita Preferences" ) ) {
690 KitaPreferences* dialog = new KitaPreferences( this );
692 connect( dialog, SIGNAL( fontChanged( const QFont& ) ),
693 SLOT( setFont( const QFont& ) ) );
698 void KitaMainWindow::slotSetMainStatusbar( const QString& statusStr )
700 // display the text on the statusbar
701 statusBar() ->message( statusStr );
704 void KitaMainWindow::setupView()
706 /* dummy Main Dock Widget */
707 m_dummyDock = createDockWidget( "dummy", 0L, 0L, "dummy", "dummy" );
708 m_dummyDock->setDockSite( KDockWidget::DockFullSite );
709 m_dummyDock->setEnableDocking( KDockWidget::DockNone );
710 setView( m_dummyDock );
711 setMainDockWidget( m_dummyDock );
714 m_boardDock = new KitaBoardDock( manager(), "subject", 0L, 0L, i18n( "subject" ), i18n( "subject" ) );
715 m_boardTab = m_boardDock->setup();
716 connect( m_boardDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckSubjectToggleAction( bool ) ) );
719 m_bbsDock = new KitaBBSDock( manager(), "board", 0L, 0L, i18n( "board" ), i18n( "board" ) );
720 m_bbsTab = m_bbsDock->setup();
721 connect( m_bbsDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckBoardToggleAction( bool ) ) );
724 m_threadDock = new KitaThreadDock( manager(), "Thread", 0L, 0L, i18n( "Thread" ), i18n( "Thread" ) );
725 m_threadTab = m_threadDock->setupAsMainView();
726 m_threadDock->setDockSite( KDockWidget::DockFullSite );
729 m_naviDock = new KitaThreadDock( manager(), "kitanavi", 0L, 0L, i18n( "KitaNavi" ), i18n( "Navi" ) );
730 m_naviTab = m_naviDock->setupAsKitaNavi();
731 connect( m_naviDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckNaviToggleAction( bool ) ) );
733 if ( !Kita::Config::useKitaNavi() ) m_threadDock ->connectNaviSignals();
734 else m_naviDock->connectNaviSignals();
737 m_imageDock = new KitaImgDock( manager(), "imgviewer", 0L, 0L, i18n( "Kita Image Viewer" ), i18n( "Image" ) );
738 m_imageTab = m_imageDock->setup();
739 connect( m_imageDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckImgToggleAction( bool ) ) );
742 m_writeDock = new KitaWriteDock( manager(), "Write", 0L, 0L, i18n( "Write" ), i18n( "Write" ) );
743 m_writeTab = m_writeDock->setup();
744 connect( m_writeDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckWriteToggleAction( bool ) ) );
746 /* reset dock status */
747 m_boardListAction = NULL;
748 m_subjectListAction = NULL;
749 m_showImgViewAction = NULL;
750 m_showNaviAction = NULL;
751 m_showWriteDockAction = NULL;
755 void KitaMainWindow::closeSubjectView()
757 m_subjectListAction->setChecked( FALSE );
760 void KitaMainWindow::slotCheckBoardToggleAction( bool check )
762 if ( m_boardListAction ) m_boardListAction->setChecked( check );
765 void KitaMainWindow::slotCheckSubjectToggleAction( bool check )
767 if ( m_subjectListAction ) m_subjectListAction->setChecked( check );
770 void KitaMainWindow::slotCheckNaviToggleAction( bool check )
772 if ( m_showNaviAction ) m_showNaviAction->setChecked( check );
775 void KitaMainWindow::slotCheckImgToggleAction( bool check )
777 if ( m_showImgViewAction ) m_showImgViewAction->setChecked( check );
781 void KitaMainWindow::slotCheckWriteToggleAction( bool check )
783 if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( check );
787 /* open url */ /* public slot */ /* obsolete */
788 void KitaMainWindow::slotOpenURLRequest( const KURL& url, const KParts::URLArgs& args )
790 slotOpenURLRequestExt( url, args );
796 If mimetype == "kita_open_2chboard", open the board.
797 If mimetype == "kita_open_2chthread", open the thread.
798 If mimetype == "text/html", open url with web browser.
799 if mimetype == QString::null, use KIO::NetAccess::mimetype to decide mime type of url.
802 void KitaMainWindow::slotOpenURLRequestExt(
803 const KURL& url, const KParts::URLArgs& args,
806 const KURL& usrUrl1 )
808 // FIXME: support be.2ch.net
809 if ( url.host() == "be.2ch.net" && url.path().contains( "/test/p.php", true ) < 1 ) {
810 QMessageBox::warning( this,
812 i18n( "be.2ch.net is currently not supported." ) );
816 kdDebug() << QString( "Requested OpenURL: \"%1\"" ).arg( url.url() ) << endl;
817 kdDebug() << QString( "content type: \"%1\"" ).arg( args.contentType() ) << endl;
818 kdDebug() << QString( "service type: \"%1\"" ).arg( args.serviceType ) << endl;
819 kdDebug() << QString( "NewTab: %1, reload: %2" )
820 .arg( args.newTab() ? "yes" : "no" )
821 .arg( args.reload ? "yes" : "no" ) << endl;
824 /* if usr1 == 1, open the board with new tab. */
825 if ( mimetype == "kita_open_2chboard" ) {
826 bool withNewTab = ( usr1 == 1 );
827 m_boardDock->slotLoadBoard( url, withNewTab );
831 /* open 2ch thread */
832 /* if usr1 == 1, open the thread with new tab. */
833 if ( mimetype == "kita_open_2chthread" ) {
834 bool withNewTab = ( usr1 == 1 || usr1 == 2 );
835 bool byBackground = ( usr1 == 2 );
836 m_threadDock->slotShowThread( url, withNewTab, byBackground );
840 /* open url with web browser, etc. */
841 if ( mimetype != QString::null ) {
842 if ( Kita::Config::copyOnClick() ) {
843 QClipboard * clipboard = QApplication::clipboard();
844 clipboard->setText( url.prettyURL(), QClipboard::Clipboard );
845 clipboard->setText( url.prettyURL(), QClipboard::Selection );
847 KRun::runURL( url, mimetype );
852 /* open thread with new thread tab */
853 if ( Kita::DatManager::isThreadEnrolled( url ) ) {
854 m_threadDock->slotShowThread( url, true );
859 if ( Kita::ImgManager::isBMP( url ) ) {
860 QMessageBox::warning( this,
862 i18n( "This is a BMP file. It might contain a Troy." ) );
867 /* open with image viewer */
868 /* if usr1 == 0, image viewer is hidden. */
869 /* usrUrl1 is datURL. */
870 if ( Kita::Config::useImageViewer() ) {
871 if ( Kita::ImgManager::isImgFile( url, FALSE ) ) {
873 if ( !usr1 ) m_imageDock->slotHideDock();
874 m_imageDock->slotOpenURL( url, usrUrl1, usr1 );
879 if ( mimetype == QString::null ) {
880 mimetype = KIO::NetAccess::mimetype( url , this );
882 kdDebug() << QString( "queried MIME type: \"%1\"" ).arg( mimetype ) << endl;
884 /* open with kpart */
885 if ( Kita::Config::usePart() ) {
886 if ( Kita::Config::partMimeList().find( mimetype ) != Kita::Config::partMimeList().end() ) {
887 KService::Ptr service = KServiceTypeProfile::preferredService( mimetype, "KParts/ReadOnlyPart" );
889 QString libName = QFile::encodeName( service->library() );
891 if ( !Kita::Config::useKitaNavi() ) m_threadDock->slotShowPart( url, libName, mimetype );
892 else m_naviDock ->slotShowPart( url, libName, mimetype );
898 if ( Kita::Config::copyOnClick() ) {
899 QClipboard * clipboard = QApplication::clipboard();
900 clipboard->setText( url.prettyURL(), QClipboard::Clipboard );
901 clipboard->setText( url.prettyURL(), QClipboard::Selection );
903 KRun::runURL( url, mimetype );
908 void KitaMainWindow::loadCache()
910 KitaThreadInfo * cache = KitaThreadInfo::getInstance();
911 QString cacheConfigPath = locateLocal( "appdata", "cache" );
912 QFile file( cacheConfigPath );
913 if ( file.open( IO_ReadOnly ) ) {
914 QDataStream stream( &file );
919 void KitaMainWindow::saveCache()
921 KitaThreadInfo * cache = KitaThreadInfo::getInstance();
922 QString cacheConfigPath = locateLocal( "appdata", "cache" );
923 QFile file( cacheConfigPath );
924 if ( file.open( IO_WriteOnly ) ) {
925 QDataStream stream( &file );
932 \fn KitaMainWindow::setFont(QFont& font)
935 void KitaMainWindow::setFont( const QFont& font )
937 m_boardTab->setFont( font );
938 m_bbsTab->setFont( font );
942 void KitaMainWindow::setUrl( const KURL& url )
944 m_urlLine->setText( url.url() );
947 void KitaMainWindow::bookmark( const QString& datURL, bool on )
949 FavoriteThreads * favorite = FavoriteThreads::getInstance();
952 favorite->insert( datURL );
954 favorite->remove( datURL );
957 emit favoritesUpdated();
960 void KitaMainWindow::loadFavorites()
962 QString favoritesConfigPath = locateLocal( "appdata", "favorites.xml" );
963 QFile file( favoritesConfigPath );
964 if ( file.open( IO_ReadOnly ) ) {
965 QTextStream stream( &file );
966 stream.setEncoding( QTextStream::UnicodeUTF8 );
968 QString xml = stream.read();
969 FavoriteThreads::readFromXML( xml );
973 void KitaMainWindow::saveFavorites()
975 QString favoritesConfigPath = locateLocal( "appdata", "favorites.xml" );
976 QFile file( favoritesConfigPath );
977 if ( file.open( IO_WriteOnly ) ) {
978 QTextStream stream( &file );
979 stream.setEncoding( QTextStream::UnicodeUTF8 );
980 stream << FavoriteThreads::getInstance() ->toXML();
984 void KitaMainWindow::loadCompletion()
986 QString configPath = locateLocal( "appdata", "completion" );
987 KSimpleConfig config( configPath );
989 Kita::Config::setNameCompletionList( config.readListEntry( "name" ) );
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 Kita::AsciiArtConfig::setAsciiArtList( list );
1044 void KitaMainWindow::loadFavoriteBoards()
1046 QString configPath = locateLocal( "appdata", "favorite_boards.xml" );
1047 QFile file( configPath );
1048 if ( file.open( IO_ReadOnly ) ) {
1049 QTextStream stream( &file );
1050 stream.setEncoding( QTextStream::UnicodeUTF8 );
1052 QString xml = stream.read();
1053 Kita::FavoriteBoards::readFromXML( xml );
1057 void KitaMainWindow::saveFavoriteBoards()
1059 QString configPath = locateLocal( "appdata", "favorite_boards.xml" );
1060 QFile file( configPath );
1061 if ( file.open( IO_WriteOnly ) ) {
1062 QTextStream stream( &file );
1063 stream.setEncoding( QTextStream::UnicodeUTF8 );
1064 stream << Kita::FavoriteBoards::toXML();
1068 void KitaMainWindow::loadAboneIDList()
1070 QString configPath = locateLocal( "appdata", "abone_id" );
1071 QFile file( configPath );
1072 if ( file.open( IO_ReadOnly ) ) {
1073 QTextStream stream( &file );
1074 stream.setEncoding( QTextStream::UnicodeUTF8 );
1079 while ( ( str = stream.readLine() ) != QString::null ) {
1080 if ( ! str.isEmpty() ) {
1084 Kita::AboneConfig::setAboneIDList( list );
1088 void KitaMainWindow::loadAboneNameList()
1090 QString configPath = locateLocal( "appdata", "abone_name" );
1091 QFile file( configPath );
1092 if ( file.open( IO_ReadOnly ) ) {
1093 QTextStream stream( &file );
1094 stream.setEncoding( QTextStream::UnicodeUTF8 );
1099 while ( ( str = stream.readLine() ) != QString::null ) {
1100 if ( ! str.isEmpty() ) {
1104 Kita::AboneConfig::setAboneNameList( list );
1108 void KitaMainWindow::loadAboneWordList()
1110 QString configPath = locateLocal( "appdata", "abone_word" );
1111 QFile file( configPath );
1112 if ( file.open( IO_ReadOnly ) ) {
1113 QTextStream stream( &file );
1114 stream.setEncoding( QTextStream::UnicodeUTF8 );
1119 while ( ( str = stream.readLine() ) != QString::null ) {
1120 if ( ! str.isEmpty() ) {
1124 Kita::AboneConfig::setAboneWordList( list );
1128 void KitaMainWindow::slotSetMainCaption( const QString& captionStr )
1130 setCaption( captionStr );
1133 void KitaMainWindow::slotEditCopy()
1135 QWidget * widget = kapp->focusWidget();
1138 QKeyEvent e( QEvent::KeyPress, Key_C, 'C', ControlButton );
1139 QApplication::sendEvent( widget, &e );
1143 void KitaMainWindow::login()
1145 if ( Kita::Account::login( Kita::Config::userID(), Kita::Config::password() ) ) {
1146 slotSetMainStatusbar( i18n( "Login succeeded." ) );
1148 slotSetMainStatusbar( i18n( "Login failed." ) );
1152 void KitaMainWindow::favoritesEdit()
1154 FavoritesWindow * window = new FavoritesWindow( this );
1158 #include "mainwindow.moc"