OSDN Git Service

refactoring.
[kita/kita.git] / kita / src / mainwindow.cpp
index 3d64439..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 "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"
@@ -148,28 +147,8 @@ KitaMainWindow::KitaMainWindow()
     // allow the view to change the statusbar and caption
     Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
 
-    connect( signalCollection, SIGNAL( openBoard( const KURL& ) ), SLOT( slotOpenBoard( const KURL& ) ) );
-    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() ) );
@@ -390,53 +369,14 @@ void KitaMainWindow::slotEditCopy()
     }
 }
 
-/* open url */ /* public slot */ /* obsolete */
-void KitaMainWindow::slotOpenURLRequest( const KURL& url, const KParts::URLArgs& args )
-{
-    slotOpenURLRequestExt( url, args );
-}
-
-void KitaMainWindow::slotOpenBoard( const KURL& url )
-{
-    m_boardTab->loadBoard( url );
-}
-
 /* 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 )
-{
-    // 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 thread */
-    /* if usr1 == 1, open the thread with new tab. */
-    if ( mimetype == "kita_open_2chthread" ) {
-        m_threadDock->slotShowThread( url );
-        return ;
-    }
-
+void KitaMainWindow::slotOpenURLRequestExt( const KURL& url, const QString mimetype )
+{
     /*  open url with web browser, etc. */
     if ( mimetype != QString::null ) {
         KRun::runURL( url, mimetype );
@@ -449,17 +389,8 @@ void KitaMainWindow::slotOpenURLRequestExt(
         return ;
     }
 
-    if ( mimetype == QString::null ) {
-        mimetype = KIO::NetAccess::mimetype( url , this );
-    }
-    kdDebug() << QString( "queried MIME type: \"%1\"" ).arg( mimetype ) << endl;
-
-    KRun::runURL( url, mimetype );
-}
-
-void KitaMainWindow::slotSetMainCaption( const QString& captionStr )
-{
-    setCaption( captionStr );
+    QString url_mimetype = KIO::NetAccess::mimetype( url , this );
+    KRun::runURL( url, url_mimetype );
 }
 
 void KitaMainWindow::slotSetMainStatusbar( const QString& statusStr )
@@ -558,6 +489,8 @@ void KitaMainWindow::setupActions()
 
 void KitaMainWindow::setupView()
 {
+    ViewMediator::getInstance()->setMainWindow( this );
+
     /* dummy Main Dock Widget */
     m_dummyDock = createDockWidget( "dummy", 0L, 0L, "dummy", "dummy" );
     m_dummyDock->setDockSite( KDockWidget::DockFullSite );
@@ -569,16 +502,21 @@ void KitaMainWindow::setupView()
     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 */
@@ -587,6 +525,7 @@ void KitaMainWindow::setupView()
     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 */