OSDN Git Service

>>913
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Sun, 20 Jun 2004 12:37:56 +0000 (12:37 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Sun, 20 Jun 2004 12:37:56 +0000 (12:37 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@1180 56b19765-1e22-0410-a548-a0f45d66c51a

kita/src/kita.cpp
kita/src/kita.h
kita/src/kitathreadtabwidget.cpp
kita/src/kitathreadtabwidget.h

index 0418b05..03dd808 100644 (file)
@@ -38,6 +38,7 @@
 #include <kkeydialog.h>
 #include <kaccel.h>
 #include <kio/netaccess.h>
+#include <kuserprofile.h>
 #include <kfiledialog.h>
 #include <kconfig.h>
 #include <kurl.h>
@@ -280,7 +281,7 @@ void KitaMainWindow::setupActions()
                  actionCollection(),
                  "threadtab_closetab" );
     new KAction( i18n( "&Reload subject list"),
-                 KStdAccel::reload(),
+                 KShortcut(Qt::CTRL | Qt::Key_F5),
                  m_subjectTab,
                  SLOT( reloadSubjectList() ),
                  actionCollection(),
@@ -606,8 +607,24 @@ void KitaMainWindow::closeBoardView()
    m_boardListAction->setChecked( FALSE );
 }
 
-void KitaMainWindow::slotOpenURLRequest( const KURL& url, const KParts::URLArgs& )
+void KitaMainWindow::slotOpenURLRequest( const KURL& url, const KParts::URLArgs& args )
 { 
+    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;
+    QString mimetype = KIO::NetAccess::mimetype( url, this );
+    kdDebug() << QString( "queried MIME type: \"%1\"" ).arg( mimetype ) << endl;
+    if ( mimetype.startsWith( "image/" ) ) {
+        KService::Ptr service = KServiceTypeProfile::preferredService( mimetype, "KParts/ReadOnlyPart" );
+        if ( service ) {
+            QString libName = QFile::encodeName( service->library() );
+            m_threadTab->showAlternativeView( url, libName, mimetype );
+            return;
+        }
+    }
     QRegExp regexp( "http://([^/]*)/([^/]*)/dat/(.*)\\.dat" );
     if ( regexp.search( url.url() ) == -1 ) {
         new KRun( url );
@@ -884,13 +901,13 @@ void KitaMainWindow::saveAboneWordList()
     }    
 }
 
-void KitaMainWindow::switchSubjectView( const QString& datURL, bool newTab)
+void KitaMainWindow::switchSubjectView( const QString&, bool )
 {
     if ( m_subjectListAction->isChecked() )
         m_subjectDock->makeDockVisible();
 }
 
-void KitaMainWindow::switchThreadView( const QString& datURL, bool newtab )
+void KitaMainWindow::switchThreadView( const QString&, bool )
 {
     m_mainDock->makeDockVisible();
 }
index c892f3d..a9621a7 100644 (file)
@@ -122,7 +122,7 @@ private slots:
     void bookmark( const QString& datURL, bool on );
     void slotThread( const Kita::Thread* thread );
     void slotIsKitaActive();
-    void switchSubjectView( const QString& datURL, bool newTab);
+    void switchSubjectView( const QString&, bool );
     void switchThreadView( const QString&, bool );
 
 private:
index bb87d4a..f45c33f 100644 (file)
@@ -40,8 +40,8 @@ KitaThreadTabWidget::KitaThreadTabWidget( QWidget* parent, const char* name, WFl
         : QTabWidget( parent, name, f )
 {
     setTabBar( new KitaThreadTabBar( this ) );
-    connect( tabBar(), SIGNAL( deleteMenuSelected( KitaThreadView* ) ),
-             SLOT( deleteView( KitaThreadView* ) ) );
+    connect( tabBar(), SIGNAL( deleteMenuSelected( QWidget* ) ),
+             SLOT( deleteView( QWidget* ) ) );
 
     m_manager = new KParts::PartManager( topLevelWidget(), this, "KitaPartManager" );
 
@@ -58,7 +58,9 @@ KitaThreadTabWidget::KitaThreadTabWidget( QWidget* parent, const char* name, WFl
 }
 
 KitaThreadTabWidget::~KitaThreadTabWidget()
-{}
+{
+    delete m_manager;
+}
 
 void KitaThreadTabWidget::showThread( const QString& datURL, bool withNewTab )
 {
@@ -111,6 +113,29 @@ KitaThreadView* KitaThreadTabWidget::createView()
     return view;
 }
 
+void KitaThreadTabWidget::showAlternativeView( const KURL& url, const QString& libName, const QString& mimetype )
+{
+    KLibFactory *factory = KLibLoader::self()->factory( libName );
+    if ( !factory ) {
+        QMessageBox::critical( parentWidget(), i18n( " Load Error" ),
+                               QString( i18n( "can't load %1.") ).arg( libName ) );
+        return;
+    }
+    if ( factory->inherits( "KParts::Factory" ) ) {
+        KParts::Part *part = static_cast<KParts::Factory*>(factory)->createPart( this );
+        m_manager->addPart( part );
+        addTab( part->widget(), getTabLabel( url.url() ) );
+        showPage( part->widget() );
+        setTabToolTip( currentPage(), url.url() );
+        KParts::BrowserExtension *ext = KParts::BrowserExtension::childObject( part );
+        if ( ext ) {
+            KParts::URLArgs arg( false, 0, 0, mimetype );
+            ext->setURLArgs( arg );
+        }
+        static_cast<KParts::ReadOnlyPart*>(part)->openURL( url );
+    }
+}
+
 void KitaThreadTabWidget::connectSignals( KitaThreadView* view )
 {
     Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
@@ -146,17 +171,17 @@ KParts::Part* KitaThreadTabWidget::findPartFromView( QWidget* view )
     return NULL;
 }
 
-void KitaThreadTabWidget::deleteView( KitaThreadView* view )
+void KitaThreadTabWidget::deleteView( QWidget* v )
 {
-    kdDebug() << "deleteView(" << static_cast<void*>( view ) << ")" << endl;
+    kdDebug() << "deleteView(" << static_cast<void*>( v ) << ")" << endl;
 
-    removePage( view );
-    m_viewList.remove( view );
+    removePage( v );
+    m_viewList.remove( static_cast<KitaThreadView*>(v) );
 
-    m_manager->removePart( findPartFromView( view ) );
-    delete view;
+    m_manager->removePart( findPartFromView( v ) );
+    delete v;
 
-    if ( count() == 0 ) {
+    if ( m_viewList.count() == 0 ) {
         KitaThreadView * view = createView();
 
         if ( view ) {
@@ -200,19 +225,26 @@ void KitaThreadTabBar::contextMenuEvent( QContextMenuEvent* e )
     popup.insertItem( i18n( "Copy title and URL" ), ID_Copy_Title_URL );
     popup.insertItem( i18n( "Close this tab" ), ID_Close );
 
-    QTabWidget* parent = static_cast<QTabWidget*>( parentWidget() );
-    KitaThreadView* threadView = static_cast<KitaThreadView*>( parent->currentPage() );
+    KitaThreadTabWidget* parent = static_cast<KitaThreadTabWidget*>( parentWidget() );
+    KParts::ReadOnlyPart* view = static_cast<KParts::ReadOnlyPart*>( parent->findPartFromView( parent->currentPage() ) );
     QClipboard* clipboard = QApplication::clipboard();
+    KitaThreadView *threadView = NULL;
+
+    if ( view->className() != "KitaThreadPart" ) {
+        popup.setItemEnabled( ID_Copy_Title_URL, FALSE );
+        threadView = static_cast<KitaThreadView*>( parent->currentPage() );
+    }
 
     switch ( popup.exec( e->globalPos() ) ) {
     case ID_Browser_Open:
-        KRun::runURL( threadView->threadURL(), "text/html" );
+        KRun( view->url() );
         break;
     case ID_Copy_Title_URL:
-        clipboard->setText( threadView->threadName() + "\n" + threadView->threadURL().url() );
+        if ( threadView )
+            clipboard->setText( threadView->threadName() + "\n" + threadView->threadURL().url() );
         break;
     case ID_Close:
-        emit deleteMenuSelected( threadView );
+        emit deleteMenuSelected( view->widget() );
         break;
     default:
         break;
@@ -223,9 +255,7 @@ void KitaThreadTabBar::contextMenuEvent( QContextMenuEvent* e )
 
 void KitaThreadTabWidget::slotCurrentChanged( QWidget * w )
 {
-    KitaThreadView* view = static_cast<KitaThreadView *>( w );
-    view->showStatusBar( "" );
-    m_manager->setActivePart( findPartFromView( view ) );
+    m_manager->setActivePart( findPartFromView( w ) );
 }
 
 const QString KitaThreadTabWidget::getTabLabel( const QString &name )
index ffecbd3..83e6262 100644 (file)
@@ -42,11 +42,13 @@ public:
 
 public slots:
     void showThread( const QString& datURL, bool withNewTab );
-    void deleteView( KitaThreadView* );
+    void deleteView( QWidget* );
     void reloadThread();
     void focusSearchCombo();
     void slotCurrentChanged( QWidget* );
     void closeCurrentTab();
+    void showAlternativeView( const KURL&, const QString&, const QString& );
+
     
 private:
     void connectSignals( KitaThreadView* );
@@ -75,7 +77,7 @@ protected:
     virtual void contextMenuEvent( QContextMenuEvent* e );
 
 signals:
-    void deleteMenuSelected( KitaThreadView* );
+    void deleteMenuSelected( QWidget* );
 };
 
 #endif