OSDN Git Service

refactoring.
[kita/kita.git] / kita / src / mainwindow.cpp
index ba197a9..921cfd6 100644 (file)
 
 #include "prefs/prefs.h"
 
-#include "thread/threadview.h"
-#include "thread/threadtabwidget.h"
-
-#include "board/boardview.h"
-#include "board/boardtabwidget.h"
-#include "bbs/bbsview.h"
-#include "bbs/bbstabwidget.h"
-#include "favoriteswindow.h"
-
-#include "write/writetabwidget.h"
+#include "threadview.h"
+#include "threadtabwidget.h"
+#include "boardview.h"
+#include "boardtabwidget.h"
+#include "bbsview.h"
+#include "bbstabwidget.h"
+#include "writetabwidget.h"
+#include "viewmediator.h"
 
 #include "libkita/threadinfo.h"
 #include "libkita/favoriteboards.h"
 #include "libkita/kitaconfig.h"
 #include "libkita/signalcollection.h"
 #include "libkita/account.h"
-#include "libkita/imgmanager.h"
 #include "libkita/datmanager.h"
 #include "libkita/boardmanager.h"
 #include "libkita/config_xt.h"
 #include "libkita/asciiart.h"
 #include "libkita/abone.h"
 
-#include "image/imagetabwidget.h"
-
 #include <qdragobject.h>
 #include <qtextcodec.h>
 #include <qevent.h>
@@ -74,8 +69,7 @@
 #include <kglobal.h>
 
 KitaMainWindow::KitaMainWindow()
-        : KParts::DockMainWindow( 0, "Kita" ),
-        m_printer( 0 )
+        : KDockMainWindow( 0, "Kita" )
 {
     // FIXME: merge *.po
     KGlobal::locale() ->insertCatalogue( "kitapart" );
@@ -83,9 +77,6 @@ KitaMainWindow::KitaMainWindow()
     // accept dnd
     setAcceptDrops( true );
 
-    // setup imgmanager
-    Kita::ImgManager::setup( this );
-
     // setup view, dock
     setupView();
 
@@ -125,8 +116,6 @@ KitaMainWindow::KitaMainWindow()
     m_bbsDock->loadSession();
     m_boardDock->loadSession();
     m_threadDock->loadSession();
-    m_naviDock->loadSession();
-    m_imageDock->loadSession();
     m_writeDock->loadSession();
     QString dockConfigPath = locateLocal( "appdata", "dock.conf" );
     KConfig dockConfig( dockConfigPath );
@@ -140,22 +129,12 @@ KitaMainWindow::KitaMainWindow()
 
     // hide writedock
     makeDockInvisible( m_writeDock );
-    m_showImgViewAction->setChecked( FALSE );
-
-    // hide kitanavi
-    makeDockInvisible( m_naviDock );
-    m_showNaviAction->setChecked( FALSE );
-
-    // hide imageviewer
-    makeDockInvisible( m_imageDock );
-    m_showImgViewAction->setChecked( FALSE );
-
-
-    KitaConfig::readConfig( KGlobal::config() );
-    Kita::Config::self()->readConfig();
 
     // for compativility
     loadCompletion();
+    KitaConfig::readConfig( KGlobal::config() );
+
+    Kita::Config::self()->readConfig();
 
     // apply the saved mainwindow settings, if any, and ask the mainwindow
     // to automatically save settings if changed: window size, toolbar
@@ -168,27 +147,8 @@ KitaMainWindow::KitaMainWindow()
     // allow the view to change the statusbar and caption
     Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
 
-    connect( signalCollection, SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ),
-             SLOT( slotOpenURLRequest( const KURL&, const KParts::URLArgs& ) ) );
-
-    connect( signalCollection, SIGNAL( openURLRequestExt(
-                                           const KURL&, const KParts::URLArgs&, QString, int,
-                                           const KURL& ) ),
-             SLOT( slotOpenURLRequestExt(
-                       const KURL& , const KParts::URLArgs&, QString, int,
-                       const KURL& ) ) );
-
-    connect( signalCollection, SIGNAL( setMainCaption( const QString& ) ),
-             SLOT( slotSetMainCaption( const QString& ) ) );
-
-    connect( signalCollection, SIGNAL( setMainStatusbar( const QString& ) ),
-             SLOT( slotSetMainStatusbar( const QString& ) ) );
-
-    connect( signalCollection, SIGNAL( setMainURLLine( const KURL& ) ),
-             SLOT( setUrl( const KURL& ) ) );
-
-    connect( signalCollection, SIGNAL( bookmarked( const QString&, bool ) ),
-             SLOT( bookmark( const QString&, bool ) ) );
+    connect( signalCollection, SIGNAL( openURLRequestExt( const KURL&, const QString ) ),
+             SLOT( slotOpenURLRequestExt( const KURL&, const QString ) ) );
 
     connect( this, SIGNAL( favoritesUpdated() ),
              signalCollection, SIGNAL( favoritesUpdated() ) );
@@ -234,8 +194,6 @@ KitaMainWindow::~KitaMainWindow()
     m_bbsDock->saveSession();
     m_boardDock->saveSession();
     m_threadDock->saveSession();
-    m_naviDock->saveSession();
-    m_imageDock->saveSession();
     m_writeDock->saveSession();
 
     Kita::AboneConfig::self()->writeConfig();
@@ -261,8 +219,6 @@ KitaMainWindow::~KitaMainWindow()
 
     delete m_bbsDock;
     delete m_threadDock;
-    delete m_naviDock;
-    delete m_imageDock;
     delete m_writeDock;
 
     Kita::DatManager::deleteAllDatInfo();
@@ -270,211 +226,41 @@ KitaMainWindow::~KitaMainWindow()
 
 void KitaMainWindow::load( const KURL& url )
 {
-    QString target;
-    // the below code is what you should normally do.  in this
-    // example case, we want the url to our own.  you probably
-    // want to use this code instead for your app
-
-#if 0
-    // download the contents
-    if ( KIO::NetAccess::download( url, target ) ) {
-        // set our caption
-        setCaption( url );
-
-        // load in the file (target is always local)
-        loadFile( target );
-
-        // and remove the temp file
-        KIO::NetAccess::removeTempFile( target );
-    }
-#endif
-
     setCaption( url.url() );
-    //    m_view->openURL(url);
-}
-
-void KitaMainWindow::setupActions()
-{
-    KStdAction::quit( this, SLOT( close() ), actionCollection() );
-    KStdAction::copy( this, SLOT( slotEditCopy() ), actionCollection() );
-
-    m_toolbarAction = KStdAction::showToolbar( this,
-                      SLOT( optionsShowToolbar() ),
-                      actionCollection() );
-
-    m_statusbarAction = KStdAction::showStatusbar( this,
-                        SLOT( optionsShowStatusbar() ),
-                        actionCollection() );
-
-    m_boardListAction = new KToggleAction( i18n( "Show board list" ),
-                                           0,
-                                           m_bbsDock,
-                                           SLOT( slotToggleShowHide() ),
-                                           actionCollection(),
-                                           "window_show_board_list" );
-
-    m_subjectListAction = new KToggleAction( i18n( "Show subject list" ),
-                          0,
-                          m_boardDock,
-                          SLOT( slotToggleShowHide() ),
-                          actionCollection(),
-                          "window_show_subject_list" );
-
-    m_showImgViewAction = new KToggleAction( i18n( "Show Image Viewer" ),
-                          0,
-                          m_imageDock,
-                          SLOT( slotToggleShowHide() ),
-                          actionCollection(),
-                          "window_show_imgviewer" );
-
-    m_showNaviAction = new KToggleAction( i18n( "Show KitaNavi" ),
-                                          0,
-                                          m_naviDock,
-                                          SLOT( slotToggleShowHide() ),
-                                          actionCollection(),
-                                          "window_show_kitanavi" );
-
-    m_showWriteDockAction = new KToggleAction( i18n( "Show Write Dock" ),
-                            0,
-                            m_writeDock,
-                            SLOT( slotToggleShowHide() ),
-                            actionCollection(),
-                            "window_show_writedock" );
-
-    m_urlLine = new KLineEdit( "", 0 );
-
-    new KWidgetAction( m_urlLine,
-                       i18n( "URL Line" ),
-                       0,
-                       this,
-                       SLOT( slotURLLine() ),
-                       actionCollection(), "url_line_action" );
-
-    KStdAction::keyBindings( this, SLOT( optionsConfigureKeys() ), actionCollection() );
-    KStdAction::configureToolbars( this, SLOT( optionsConfigureToolbars() ), actionCollection() );
-    KStdAction::preferences( this, SLOT( optionsPreferences() ), actionCollection() );
-
-    /*    new KAction( i18n( "Edit Favorites" ),
-                     0,
-                     this,
-                     SLOT( favoritesEdit() ),
-                     actionCollection(),
-                     "favorites_edit" );*/
-
-    new KAction( i18n( "Load board list" ),
-                 0,
-                 m_bbsTab,
-                 SLOT( updateBoardList() ),
-                 actionCollection(),
-                 "load_board_list" );
-
-    new KAction( i18n( "reset windows" ),
-                 0,
-                 this,
-                 SLOT( resetWindowsCust() ),
-                 actionCollection(),
-                 "reset_wincust" );
-
-    new KAction( i18n( "default 1" ),
-                 0,
-                 this,
-                 SLOT( resetWindowsDef1() ),
-                 actionCollection(),
-                 "reset_windef1" );
-
-    new KAction( i18n( "default 2" ),
-                 0,
-                 this,
-                 SLOT( resetWindowsDef2() ),
-                 actionCollection(),
-                 "reset_windef2" );
-
-    new KAction( i18n( "default 3" ),
-                 0,
-                 this,
-                 SLOT( resetWindowsDef3() ),
-                 actionCollection(),
-                 "reset_windef3" );
-
-    m_toggleViewAction = new KAction(
-                             i18n( "&Toggle subject view and thread view" ),
-                             KShortcut( Qt::Key_F7 ),
-                             this,
-                             SLOT( windowToggleView() ),
-                             actionCollection(),
-                             "window_toggle_view" );
-
-    new KAction( i18n( "Login" ),
-                 0,
-                 this,
-                 SLOT( login() ),
-                 actionCollection(),
-                 "login" );
-
-    setXMLFile( "kitaui.rc" );
-    KMainWindow::createGUI();
-    factory() ->addClient( m_bbsTab );
-    factory() ->addClient( m_boardTab );
-    factory() ->addClient( m_threadTab );
-    factory() ->addClient( m_imageTab );
-    factory() ->addClient( m_naviTab );
-    factory() ->addClient( m_writeTab );
-}
-
-void KitaMainWindow::slotURLLine()
-{
-    KURL url = m_urlLine->text();
-    KURL datURL = Kita::getDatURL( url );
-    m_threadDock->slotShowThread( datURL, Kita::Config::alwaysUseTab() );
 }
 
-void KitaMainWindow::saveProperties( KConfig* )
+void KitaMainWindow::bookmark( const QString& datURL, bool on )
 {
-    // the 'config' object points to the session managed
-    // config file.  anything you write here will be available
-    // later when this app is restored
+    FavoriteThreads * favorite = FavoriteThreads::getInstance();
 
-    //    if (m_view->currentURL() != QString::null)
-    //        config->writeEntry("lastURL", m_view->currentURL());
-    //    KitaConfig::writeConfig( config );
+    if ( on ) {
+        favorite->insert( datURL );
+    } else {
+        favorite->remove( datURL );
+    }
+    saveFavorites();
+    emit favoritesUpdated();
 }
 
-void KitaMainWindow::readProperties( KConfig* )
+void KitaMainWindow::closeSubjectView()
 {
-    // the 'config' object points to the session managed
-    // config file.  this function is automatically called whenever
-    // the app is being restored.  read in here whatever you wrote
-    // in 'saveProperties'
-
-    //    QString url = config->readEntry("lastURL");
-
-    //    if (url != QString::null)
-    //        m_view->openURL(KURL(url));
-    //    KitaConfig::readConfig( config );
+    m_subjectListAction->setChecked( FALSE );
 }
 
-void KitaMainWindow::dragEnterEvent( QDragEnterEvent* event )
+void KitaMainWindow::login()
 {
-    // accept uri drops only
-    event->accept( QUriDrag::canDecode( event ) );
+    if ( Kita::Account::login( Kita::Config::userID(), Kita::Config::password() ) ) {
+        slotSetMainStatusbar( i18n( "Login succeeded." ) );
+    } else {
+        slotSetMainStatusbar( i18n( "Login failed." ) );
+    }
 }
 
-void KitaMainWindow::dropEvent( QDropEvent* event )
+void KitaMainWindow::newToolbarConfig()
 {
-    // this is a very simplistic implementation of a drop event.  we
-    // will only accept a dropped URL.  the Qt dnd code can do *much*
-    // much more, so please read the docs there
-    QStrList uri;
-
-    // see if we can decode a URI.. if not, just ignore it
-    if ( QUriDrag::decode( event, uri ) ) {
-        // okay, we have a URI.. process it
-        QString url, target;
-        url = uri.first();
-
-        // load in the file
-        load( KURL( url ) );
-    }
+    // this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
+    // recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
+    applyMainWindowSettings( KGlobal::config(), "MainWindow" );
 }
 
 void KitaMainWindow::optionsShowToolbar()
@@ -515,170 +301,6 @@ void KitaMainWindow::optionsConfigureToolbars()
     dlg.exec();
 }
 
-void KitaMainWindow::newToolbarConfig()
-{
-    // this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
-    // recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
-    applyMainWindowSettings( KGlobal::config(), "MainWindow" );
-}
-
-void KitaMainWindow::resetWindowsCust() { resetWindows( 0 ); }
-void KitaMainWindow::resetWindowsDef1() { resetWindows( 1 ); }
-void KitaMainWindow::resetWindowsDef2() { resetWindows( 2 ); }
-void KitaMainWindow::resetWindowsDef3() { resetWindows( 3 ); }
-
-void KitaMainWindow::resetWindows( int pattern )
-{
-    if ( !m_dummyDock || !m_threadDock || !m_bbsDock
-            || !m_boardDock || !m_naviDock || !m_imageDock || !m_writeDock ) return ;
-
-    makeDockVisible( m_threadDock );
-    makeDockVisible( m_bbsDock );
-    makeDockVisible( m_boardDock );
-    makeDockVisible( m_naviDock );
-    makeDockVisible( m_imageDock );
-    makeDockVisible( m_writeDock );
-
-    makeDockInvisible( m_threadDock );
-    makeDockInvisible( m_bbsDock );
-    makeDockInvisible( m_boardDock );
-    makeDockInvisible( m_naviDock );
-    makeDockInvisible( m_imageDock );
-    makeDockInvisible( m_writeDock );
-
-    m_threadDock->manualDock( m_dummyDock, KDockWidget::DockTop, 100 );
-    m_bbsDock->manualDock( m_threadDock, KDockWidget::DockLeft, 20 );
-    m_boardDock->manualDock( m_threadDock, KDockWidget::DockTop, 25 );
-    m_imageDock->manualDock( m_threadDock, KDockWidget::DockTop, 25 );
-    m_writeDock->manualDock( m_threadDock, KDockWidget::DockBottom, 75 );
-    m_naviDock->manualDock( m_threadDock, KDockWidget::DockBottom, 50 );
-
-    switch ( pattern ) {
-
-        /*----------------------------------------*/
-    case 0:
-
-        /* setSession( docked, tabbed ) */
-        m_threadDock ->setSession( TRUE, FALSE );
-        m_bbsDock ->setSession( TRUE, FALSE );
-        m_boardDock->setSession( TRUE, FALSE );
-        m_imageDock ->setSession( TRUE, FALSE );
-        m_writeDock ->setSession( TRUE, FALSE );
-        m_naviDock ->setSession( TRUE, FALSE );
-
-        if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
-        if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
-        if ( m_showImgViewAction ) m_showImgViewAction->setChecked( TRUE );
-        if ( m_showNaviAction ) m_showNaviAction->setChecked( TRUE );
-        if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( TRUE );
-
-        break;
-
-        /*----------------------------------------*/
-    case 1:
-
-        m_imageDock->toDesktop();
-        m_writeDock->toDesktop();
-        m_naviDock->toDesktop();
-
-        makeDockInvisible( m_imageDock );
-        makeDockInvisible( m_writeDock );
-        makeDockInvisible( m_naviDock );
-
-        /* setSession( docked, tabbed ) */
-        m_threadDock ->setSession( TRUE, FALSE );
-        m_bbsDock ->setSession( TRUE, FALSE );
-        m_boardDock->setSession( TRUE, FALSE );
-        m_imageDock ->setSession( FALSE, FALSE );
-        m_writeDock ->setSession( FALSE, FALSE );
-        m_naviDock ->setSession( FALSE, FALSE );
-
-        if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
-        if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
-        if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
-        if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
-        if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
-
-        break;
-
-        /*----------------------------------------*/
-    case 2:
-
-        m_boardDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
-
-        m_imageDock->toDesktop();
-        m_writeDock->toDesktop();
-        m_naviDock->toDesktop();
-
-        makeDockInvisible( m_imageDock );
-        makeDockInvisible( m_writeDock );
-        makeDockInvisible( m_naviDock );
-
-        /* setSession( docked, tabbed ) */
-        m_threadDock ->setSession( TRUE, TRUE );
-        m_bbsDock ->setSession( TRUE, FALSE );
-        m_boardDock->setSession( TRUE, TRUE );
-        m_imageDock ->setSession( FALSE, FALSE );
-        m_writeDock ->setSession( FALSE, FALSE );
-        m_naviDock ->setSession( FALSE, FALSE );
-
-        if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
-        if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
-        if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
-        if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
-        if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
-
-        break;
-
-        /*----------------------------------------*/
-    case 3:
-
-        m_boardDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
-        m_naviDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
-        m_imageDock->manualDock( m_threadDock, KDockWidget::DockCenter, 0 );
-
-        makeDockInvisible( m_imageDock );
-        makeDockInvisible( m_writeDock );
-        makeDockInvisible( m_naviDock );
-
-        /* setSession( docked, tabbed ) */
-        m_threadDock ->setSession( TRUE, TRUE );
-        m_bbsDock ->setSession( TRUE, FALSE );
-        m_boardDock->setSession( TRUE, TRUE );
-        m_imageDock ->setSession( TRUE, TRUE );
-        m_writeDock ->setSession( TRUE, FALSE );
-        m_naviDock ->setSession( TRUE, TRUE );
-
-        if ( m_boardListAction ) m_boardListAction->setChecked( TRUE );
-        if ( m_subjectListAction ) m_subjectListAction->setChecked( TRUE );
-        if ( m_showImgViewAction ) m_showImgViewAction->setChecked( FALSE );
-        if ( m_showNaviAction ) m_showNaviAction->setChecked( FALSE );
-        if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( FALSE );
-
-        break;
-    }
-
-    m_threadDock->slotShowDock();
-}
-
-
-void KitaMainWindow::windowToggleView()
-{
-    //FIXME: m_boardDock->dockSite() & KDockWidget::DockCenter != 0 igai no toki ha dousuru?
-    kdDebug() << "Do toggle" << endl;
-    if ( !m_boardDock->isVisible()
-            || !m_boardDock->isActiveWindow() ) m_boardDock->slotShowDock();
-    else {
-        m_threadDock->slotShowDock();
-    }
-}
-
-void KitaMainWindow::settingsMenuAboutToShow()
-{
-    m_toolbarAction->setChecked( toolBar() ->isVisible() );
-    m_statusbarAction->setChecked( statusBar() ->isVisible() );
-}
-
 void KitaMainWindow::optionsPreferences()
 {
     // popup some sort of preference dialog, here
@@ -694,66 +316,32 @@ void KitaMainWindow::optionsPreferences()
     dialog->show();
 }
 
-void KitaMainWindow::slotSetMainStatusbar( const QString& statusStr )
+void KitaMainWindow::settingsMenuAboutToShow()
 {
-    // display the text on the statusbar
-    statusBar() ->message( statusStr );
+    m_toolbarAction->setChecked( toolBar() ->isVisible() );
+    m_statusbarAction->setChecked( statusBar() ->isVisible() );
 }
 
-void KitaMainWindow::setupView()
+void KitaMainWindow::setFont( const QFont& font )
 {
-    /* dummy Main Dock Widget */
-    m_dummyDock = createDockWidget( "dummy", 0L, 0L, "dummy", "dummy" );
-    m_dummyDock->setDockSite( KDockWidget::DockFullSite );
-    m_dummyDock->setEnableDocking( KDockWidget::DockNone );
-    setView( m_dummyDock );
-    setMainDockWidget( m_dummyDock );
-
-    /* Subject View */
-    m_boardDock = new KitaBoardDock( manager(), "subject", 0L, 0L, i18n( "subject" ), i18n( "subject" ) );
-    m_boardTab = m_boardDock->setup();
-    connect( m_boardDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckSubjectToggleAction( bool ) ) );
-
-    /* Board View */
-    m_bbsDock = new KitaBBSDock( manager(), "board", 0L, 0L, i18n( "board" ), i18n( "board" ) );
-    m_bbsTab = m_bbsDock->setup();
-    connect( m_bbsDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckBoardToggleAction( bool ) ) );
-
-    /* Thread View */
-    m_threadDock = new KitaThreadDock( manager(), "Thread", 0L, 0L, i18n( "Thread" ), i18n( "Thread" ) );
-    m_threadTab = m_threadDock->setupAsMainView();
-    m_threadDock->setDockSite( KDockWidget::DockFullSite );
-
-    /* KitaNavi */
-    m_naviDock = new KitaThreadDock( manager(), "kitanavi", 0L, 0L, i18n( "KitaNavi" ), i18n( "Navi" ) );
-    m_naviTab = m_naviDock->setupAsKitaNavi();
-    connect( m_naviDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckNaviToggleAction( bool ) ) );
-
-    if ( !Kita::Config::useKitaNavi() ) m_threadDock ->connectNaviSignals();
-    else m_naviDock->connectNaviSignals();
-
-    /* KitaImgViewer */
-    m_imageDock = new KitaImgDock( manager(), "imgviewer", 0L, 0L, i18n( "Kita Image Viewer" ), i18n( "Image" ) );
-    m_imageTab = m_imageDock->setup();
-    connect( m_imageDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckImgToggleAction( bool ) ) );
-
-    /* write dock */
-    m_writeDock = new KitaWriteDock( manager(), "Write", 0L, 0L, i18n( "Write" ), i18n( "Write" ) );
-    m_writeTab = m_writeDock->setup();
-    connect( m_writeDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckWriteToggleAction( bool ) ) );
+    m_boardTab->setFont( font );
+    m_bbsTab->setFont( font );
+}
 
-    /* reset dock status */
-    m_boardListAction = NULL;
-    m_subjectListAction = NULL;
-    m_showImgViewAction = NULL;
-    m_showNaviAction = NULL;
-    m_showWriteDockAction = NULL;
-    resetWindowsDef1();
+void KitaMainWindow::setUrl( const KURL& url )
+{
+    m_urlLine->setText( url.url() );
 }
 
-void KitaMainWindow::closeSubjectView()
+void KitaMainWindow::windowToggleView()
 {
-    m_subjectListAction->setChecked( FALSE );
+    //FIXME: m_boardDock->dockSite() & KDockWidget::DockCenter != 0 igai no toki ha dousuru?
+    kdDebug() << "Do toggle" << endl;
+    if ( !m_boardDock->isVisible()
+            || !m_boardDock->isActiveWindow() ) m_boardDock->slotShowDock();
+    else {
+        m_threadDock->slotShowDock();
+    }
 }
 
 void KitaMainWindow::slotCheckBoardToggleAction( bool check )
@@ -766,143 +354,185 @@ void KitaMainWindow::slotCheckSubjectToggleAction( bool check )
     if ( m_subjectListAction ) m_subjectListAction->setChecked( check );
 }
 
-void KitaMainWindow::slotCheckNaviToggleAction( bool check )
-{
-    if ( m_showNaviAction ) m_showNaviAction->setChecked( check );
-}
-
-void KitaMainWindow::slotCheckImgToggleAction( bool check )
-{
-    if ( m_showImgViewAction ) m_showImgViewAction->setChecked( check );
-}
-
-
 void KitaMainWindow::slotCheckWriteToggleAction( bool check )
 {
     if ( m_showWriteDockAction ) m_showWriteDockAction->setChecked( check );
 }
 
-
-/* open url */ /* public slot */ /* obsolete */
-void KitaMainWindow::slotOpenURLRequest( const KURL& url, const KParts::URLArgs& args )
+void KitaMainWindow::slotEditCopy()
 {
-    slotOpenURLRequestExt( url, args );
-}
+    QWidget * widget = kapp->focusWidget();
 
+    if ( widget ) {
+        QKeyEvent e( QEvent::KeyPress, Key_C, 'C', ControlButton );
+        QApplication::sendEvent( widget, &e );
+    }
+}
 
 /* open url */
 /*
-  If mimetype == "kita_open_2chboard", open the board.
-  If mimetype == "kita_open_2chthread",  open the thread.
   If mimetype == "text/html", open url with web browser.
   if mimetype == QString::null, use KIO::NetAccess::mimetype to decide mime type of url.
  
 */  /* public slot */
-void KitaMainWindow::slotOpenURLRequestExt(
-    const KURL& url, const KParts::URLArgs& args,
-    QString mimetype,
-    int usr1,
-    const KURL& usrUrl1 )
+void KitaMainWindow::slotOpenURLRequestExt( const KURL& url, const QString mimetype )
 {
-    // FIXME: support be.2ch.net
-    if ( url.host() == "be.2ch.net" && url.path().contains( "/test/p.php", true ) < 1 ) {
-        QMessageBox::warning( this,
-                              "Kita",
-                              i18n( "be.2ch.net is currently not supported." ) );
-        return ;
-    }
-
-    kdDebug() << QString( "Requested OpenURL: \"%1\"" ).arg( url.url() ) << endl;
-    kdDebug() << QString( "content type: \"%1\"" ).arg( args.contentType() ) << endl;
-    kdDebug() << QString( "service type: \"%1\"" ).arg( args.serviceType ) << endl;
-    kdDebug() << QString( "NewTab: %1, reload: %2" )
-    .arg( args.newTab() ? "yes" : "no" )
-    .arg( args.reload ? "yes" : "no" ) << endl;
-
-    /* open 2ch board */
-    /* if usr1 == 1, open the board with new tab. */
-    if ( mimetype == "kita_open_2chboard" ) {
-        bool withNewTab = ( usr1 == 1 );
-        m_boardDock->slotLoadBoard( url, withNewTab );
-        return ;
-    }
-
-    /* open 2ch thread */
-    /* if usr1 == 1, open the thread with new tab. */
-    if ( mimetype == "kita_open_2chthread" ) {
-        bool withNewTab = ( usr1 == 1 || usr1 == 2 );
-        bool byBackground = ( usr1 == 2 );
-        m_threadDock->slotShowThread( url, withNewTab, byBackground );
-        return ;
-    }
-
     /*  open url with web browser, etc. */
     if ( mimetype != QString::null ) {
-        if ( Kita::Config::copyOnClick() ) {
-            QClipboard * clipboard = QApplication::clipboard();
-            clipboard->setText( url.prettyURL(), QClipboard::Clipboard );
-            clipboard->setText( url.prettyURL(), QClipboard::Selection );
-        } else {
-            KRun::runURL( url, mimetype );
-        }
+        KRun::runURL( url, mimetype );
         return ;
     }
 
     /* open thread with new thread tab */
     if ( Kita::DatManager::isThreadEnrolled( url ) ) {
-        m_threadDock->slotShowThread( url, true );
+        m_threadDock->slotShowThread( url );
         return ;
     }
 
-    /* bmp file */
-    if ( Kita::ImgManager::isBMP( url ) ) {
-        QMessageBox::warning( this,
-                              "Kita",
-                              i18n( "This is a BMP file. It might contain a Troy." ) );
-        return ;
-    }
+    QString url_mimetype = KIO::NetAccess::mimetype( url , this );
+    KRun::runURL( url, url_mimetype );
+}
+
+void KitaMainWindow::slotSetMainStatusbar( const QString& statusStr )
+{
+    // display the text on the statusbar
+    statusBar() ->message( statusStr );
+}
+
+void KitaMainWindow::slotURLLine()
+{
+    KURL url = m_urlLine->text();
+    KURL datURL = Kita::getDatURL( url );
+    m_threadDock->slotShowThread( datURL );
+}
 
+//
+// private method
+//
 
-    /* open with image viewer */
-    /* if usr1 == 0, image viewer is hidden. */
-    /* usrUrl1 is datURL.                    */
-    if ( Kita::Config::useImageViewer() ) {
-        if ( Kita::ImgManager::isImgFile( url, FALSE ) ) {
+void KitaMainWindow::setupActions()
+{
+    KStdAction::quit( this, SLOT( close() ), actionCollection() );
+    KStdAction::copy( this, SLOT( slotEditCopy() ), actionCollection() );
 
-            if ( !usr1 ) m_imageDock->slotHideDock();
-            m_imageDock->slotOpenURL( url, usrUrl1, usr1 );
-            return ;
-        }
-    }
+    m_toolbarAction = KStdAction::showToolbar( this,
+                      SLOT( optionsShowToolbar() ),
+                      actionCollection() );
 
-    if ( mimetype == QString::null ) {
-        mimetype = KIO::NetAccess::mimetype( url , this );
-    }
-    kdDebug() << QString( "queried MIME type: \"%1\"" ).arg( mimetype ) << endl;
-
-    /* open with kpart */
-    if ( Kita::Config::usePart() ) {
-        if ( Kita::Config::partMimeList().find( mimetype ) != Kita::Config::partMimeList().end() ) {
-            KService::Ptr service = KServiceTypeProfile::preferredService( mimetype, "KParts/ReadOnlyPart" );
-            if ( service ) {
-                QString libName = QFile::encodeName( service->library() );
-
-                if ( !Kita::Config::useKitaNavi() ) m_threadDock->slotShowPart( url, libName, mimetype );
-                else m_naviDock ->slotShowPart( url, libName, mimetype );
-                return ;
-            }
-        }
-    }
+    m_statusbarAction = KStdAction::showStatusbar( this,
+                        SLOT( optionsShowStatusbar() ),
+                        actionCollection() );
 
-    if ( Kita::Config::copyOnClick() ) {
-        QClipboard * clipboard = QApplication::clipboard();
-        clipboard->setText( url.prettyURL(), QClipboard::Clipboard );
-        clipboard->setText( url.prettyURL(), QClipboard::Selection );
-    } else {
-        KRun::runURL( url, mimetype );
-    }
+    m_boardListAction = new KToggleAction( i18n( "Show board list" ),
+                                           0,
+                                           m_bbsDock,
+                                           SLOT( slotToggleShowHide() ),
+                                           actionCollection(),
+                                           "window_show_board_list" );
+
+    m_subjectListAction = new KToggleAction( i18n( "Show subject list" ),
+                          0,
+                          m_boardDock,
+                          SLOT( slotToggleShowHide() ),
+                          actionCollection(),
+                          "window_show_subject_list" );
+
+    m_showWriteDockAction = new KToggleAction( i18n( "Show Write Dock" ),
+                            0,
+                            m_writeDock,
+                            SLOT( slotToggleShowHide() ),
+                            actionCollection(),
+                            "window_show_writedock" );
+
+    m_urlLine = new KLineEdit( "", 0 );
+
+    new KWidgetAction( m_urlLine,
+                       i18n( "URL Line" ),
+                       0,
+                       this,
+                       SLOT( slotURLLine() ),
+                       actionCollection(), "url_line_action" );
+
+    KStdAction::keyBindings( this, SLOT( optionsConfigureKeys() ), actionCollection() );
+    KStdAction::configureToolbars( this, SLOT( optionsConfigureToolbars() ), actionCollection() );
+    KStdAction::preferences( this, SLOT( optionsPreferences() ), actionCollection() );
+
+    new KAction( i18n( "Load board list" ),
+                 0,
+                 m_bbsTab,
+                 SLOT( updateBoardList() ),
+                 actionCollection(),
+                 "load_board_list" );
+
+    m_toggleViewAction = new KAction(
+                             i18n( "&Toggle subject view and thread view" ),
+                             KShortcut( Qt::Key_F7 ),
+                             this,
+                             SLOT( windowToggleView() ),
+                             actionCollection(),
+                             "window_toggle_view" );
+
+    new KAction( i18n( "Login" ),
+                 0,
+                 this,
+                 SLOT( login() ),
+                 actionCollection(),
+                 "login" );
+
+    setXMLFile( "kitaui.rc" );
+    KMainWindow::createGUI();
+    factory() ->addClient( m_bbsTab );
+    factory() ->addClient( m_boardTab );
+    factory() ->addClient( m_threadTab );
+    factory() ->addClient( m_writeTab );
 }
 
+void KitaMainWindow::setupView()
+{
+    ViewMediator::getInstance()->setMainWindow( this );
+
+    /* dummy Main Dock Widget */
+    m_dummyDock = createDockWidget( "dummy", 0L, 0L, "dummy", "dummy" );
+    m_dummyDock->setDockSite( KDockWidget::DockFullSite );
+    m_dummyDock->setEnableDocking( KDockWidget::DockNone );
+    setView( m_dummyDock );
+    setMainDockWidget( m_dummyDock );
+
+    /* Subject View */
+    m_boardDock = new KitaBoardDock( manager(), "subject", 0L, 0L, i18n( "subject" ), i18n( "subject" ) );
+    m_boardTab = new KitaBoardTabWidget( this, "Subject" );
+    m_boardDock->setWidget( m_boardTab );
+    ViewMediator::getInstance()->setBoardDockWidget( m_boardDock );
+    ViewMediator::getInstance()->setBoardTabWidget( m_boardTab );
+    connect( m_boardDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckSubjectToggleAction( bool ) ) );
+
+    /* Board View */
+    m_bbsDock = new KitaBBSDock( manager(), "board", 0L, 0L, i18n( "board" ), i18n( "board" ) );
+    m_bbsTab = m_bbsDock->setup();
+    ViewMediator::getInstance()->setBBSDock( m_bbsDock );
+    connect( m_bbsDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckBoardToggleAction( bool ) ) );
+
+    /* Thread View */
+    m_threadDock = new KitaThreadDock( manager(), "Thread", 0L, 0L, i18n( "Thread" ), i18n( "Thread" ) );
+    m_threadTab = m_threadDock->setupAsMainView();
+    ViewMediator::getInstance()->setThreadDock( m_threadDock );
+    ViewMediator::getInstance()->setThreadTabWidget( m_threadTab );
+    m_threadDock->setDockSite( KDockWidget::DockFullSite );
+
+    /* write dock */
+    m_writeDock = new KitaWriteDock( manager(), "Write", 0L, 0L, i18n( "Write" ), i18n( "Write" ) );
+    m_writeTab = new KitaWriteTabWidget( m_writeDock, "Write View" );
+    m_writeDock->setWidget( m_writeTab );
+    m_writeDock->setWriteTabWidget( m_writeTab );
+    m_writeDock->setup();
+    ViewMediator::getInstance()->setWriteDock( m_writeDock );
+    connect( m_writeDock, SIGNAL( checkToggleAction( bool ) ), SLOT( slotCheckWriteToggleAction( bool ) ) );
+
+    /* reset dock status */
+    m_boardListAction = NULL;
+    m_subjectListAction = NULL;
+    m_showWriteDockAction = NULL;
+}
 
 void KitaMainWindow::loadCache()
 {
@@ -926,36 +556,6 @@ void KitaMainWindow::saveCache()
     }
 }
 
-
-/*!
-    \fn KitaMainWindow::setFont(QFont& font)
- */
-
-void KitaMainWindow::setFont( const QFont& font )
-{
-    m_boardTab->setFont( font );
-    m_bbsTab->setFont( font );
-}
-
-
-void KitaMainWindow::setUrl( const KURL& url )
-{
-    m_urlLine->setText( url.url() );
-}
-
-void KitaMainWindow::bookmark( const QString& datURL, bool on )
-{
-    FavoriteThreads * favorite = FavoriteThreads::getInstance();
-
-    if ( on ) {
-        favorite->insert( datURL );
-    } else {
-        favorite->remove( datURL );
-    }
-    saveFavorites();
-    emit favoritesUpdated();
-}
-
 void KitaMainWindow::loadFavorites()
 {
     QString favoritesConfigPath = locateLocal( "appdata", "favorites.xml" );
@@ -980,6 +580,30 @@ void KitaMainWindow::saveFavorites()
     }
 }
 
+void KitaMainWindow::loadFavoriteBoards()
+{
+    QString configPath = locateLocal( "appdata", "favorite_boards.xml" );
+    QFile file( configPath );
+    if ( file.open( IO_ReadOnly ) ) {
+        QTextStream stream( &file );
+        stream.setEncoding( QTextStream::UnicodeUTF8 );
+
+        QString xml = stream.read();
+        Kita::FavoriteBoards::readFromXML( xml );
+    }
+}
+
+void KitaMainWindow::saveFavoriteBoards()
+{
+    QString configPath = locateLocal( "appdata", "favorite_boards.xml" );
+    QFile file( configPath );
+    if ( file.open( IO_WriteOnly ) ) {
+        QTextStream stream( &file );
+        stream.setEncoding( QTextStream::UnicodeUTF8 );
+        stream << Kita::FavoriteBoards::toXML();
+    }
+}
+
 void KitaMainWindow::loadCompletion()
 {
     QString configPath = locateLocal( "appdata", "completion" );
@@ -1040,30 +664,6 @@ void KitaMainWindow::loadAsciiArt()
     }
 }
 
-void KitaMainWindow::loadFavoriteBoards()
-{
-    QString configPath = locateLocal( "appdata", "favorite_boards.xml" );
-    QFile file( configPath );
-    if ( file.open( IO_ReadOnly ) ) {
-        QTextStream stream( &file );
-        stream.setEncoding( QTextStream::UnicodeUTF8 );
-
-        QString xml = stream.read();
-        Kita::FavoriteBoards::readFromXML( xml );
-    }
-}
-
-void KitaMainWindow::saveFavoriteBoards()
-{
-    QString configPath = locateLocal( "appdata", "favorite_boards.xml" );
-    QFile file( configPath );
-    if ( file.open( IO_WriteOnly ) ) {
-        QTextStream stream( &file );
-        stream.setEncoding( QTextStream::UnicodeUTF8 );
-        stream << Kita::FavoriteBoards::toXML();
-    }
-}
-
 void KitaMainWindow::loadAboneIDList()
 {
     QString configPath = locateLocal( "appdata", "abone_id" );
@@ -1124,34 +724,4 @@ void KitaMainWindow::loadAboneWordList()
     }
 }
 
-void KitaMainWindow::slotSetMainCaption( const QString& captionStr )
-{
-    setCaption( captionStr );
-}
-
-void KitaMainWindow::slotEditCopy()
-{
-    QWidget * widget = kapp->focusWidget();
-
-    if ( widget ) {
-        QKeyEvent e( QEvent::KeyPress, Key_C, 'C', ControlButton );
-        QApplication::sendEvent( widget, &e );
-    }
-}
-
-void KitaMainWindow::login()
-{
-    if ( Kita::Account::login( Kita::Config::userID(), Kita::Config::password() ) ) {
-        slotSetMainStatusbar( i18n( "Login succeeded." ) );
-    } else {
-        slotSetMainStatusbar( i18n( "Login failed." ) );
-    }
-}
-
-void KitaMainWindow::favoritesEdit()
-{
-    FavoritesWindow * window = new FavoritesWindow( this );
-    window->show();
-}
-
 #include "mainwindow.moc"