[kde-doc-english] [kig] /: File Loading Based on MIME Types

David E. Narvaez david.narvaez at computer.org
Tue Dec 31 13:45:39 UTC 2013


Git commit 985cbc9c1799b915b47692b17a110346754aea73 by David E. Narvaez.
Committed on 31/12/2013 at 13:41.
Pushed by narvaez into branch 'master'.

File Loading Based on MIME Types

Besides the fact that it loads the files  based on their MIME types,
these changes also modernize the loading of the Kig part by using
KService, and querying the KService for the supported MIME types to load

REVIEW: 114745
GUI: File extensions no longer show in the filters in the Open dialog

M  +0    -7    filters/filter.cc
M  +0    -1    filters/filter.h
M  +23   -36   kig/kig.cpp
M  +1    -1    kig/kig.h
M  +1    -1    kig/kig_part.desktop

http://commits.kde.org/kig/985cbc9c1799b915b47692b17a110346754aea73

diff --git a/filters/filter.cc b/filters/filter.cc
index 8d5a676..7a589db 100644
--- a/filters/filter.cc
+++ b/filters/filter.cc
@@ -105,10 +105,3 @@ bool KigFilters::save( const KigDocument& data, const QString& tofile )
 {
   return KigFilterNative::instance()->save( data, tofile );
 }
-
-/*
-bool KigFilters::save( const KigDocument& data, QTextStream& stream )
-{
-  return KigFilterNative::instance()->save( data, stream );
-}
-*/
diff --git a/filters/filter.h b/filters/filter.h
index 970da7b..ddd7ab6 100644
--- a/filters/filter.h
+++ b/filters/filter.h
@@ -35,7 +35,6 @@ public:
   static KigFilters* instance();
   KigFilter* find (const QString& mime);
 
-//  bool save ( const KigDocument& data, QTextStream& stream );
   /**
    * saving is always done with the native filter.  We don't support
    * output filters..
diff --git a/kig/kig.cpp b/kig/kig.cpp
index e426deb..b3f5c8b 100644
--- a/kig/kig.cpp
+++ b/kig/kig.cpp
@@ -43,9 +43,13 @@
 #include <kapplication.h>
 #include <assert.h>
 
+#include <KService>
+
 Kig::Kig()
   : KParts::MainWindow(), m_part( 0 )
 {
+  KService::Ptr kigpartService = KService::serviceByDesktopName("kig_part");
+
   setObjectName( QLatin1String( "Kig" ) );
   // setting the configation file
   config = new KConfig( "kigrc" );
@@ -54,37 +58,29 @@ Kig::Kig()
   // then, setup our actions
   setupActions();
 
-  // this routine will find and load our Part.  it finds the Part by
-  // name which is a bad idea usually.. but it's alright in this
-  // case since our Part is made for this Shell
-  KPluginLoader libraryLoader( "kigpart" );
+  if ( kigpartService )
+  {
+    m_part = kigpartService->createInstance< KParts::ReadWritePart >( this );
+    m_mimeTypes = kigpartService->mimeTypes();
+    if (m_part)
+    {
+      // tell the KParts::MainWindow that this is indeed the main widget
+      setCentralWidget(m_part->widget());
 
-  libraryLoader.setLoadHints( QLibrary::ExportExternalSymbolsHint );
+      // and integrate the part's GUI with the shell's
+      createGUI(m_part);
 
-  if ( KPluginFactory* factory = libraryLoader.factory() )
-  {
-      // now that the Part is loaded, we cast it to a Part to get
-      // our hands on it
-      m_part = factory->create< KParts::ReadWritePart >( this );
-      if (m_part)
-      {
-	  // tell the KParts::MainWindow that this is indeed the main widget
-	  setCentralWidget(m_part->widget());
-
-	  // and integrate the part's GUI with the shell's
-	  // FIXME!!! disabling for now as it seems to create a unending loop
-	  createGUI(m_part);
-	  // finally show tip-of-day ( if the user wants it :) )
-	  QTimer::singleShot( 0, this, SLOT( startupTipOfDay() ) );
-      }
+      // finally show tip-of-day ( if the user wants it :) )
+      QTimer::singleShot( 0, this, SLOT( startupTipOfDay() ) );
+    }
   }
   else
   {
-      // if we couldn't find our Part, we exit since the Shell by
-      // itself can't do anything useful
-      KMessageBox::error(this, i18n( "Could not find the necessary Kig library, check your installation." ) );
-      KApplication::exit();
-      return;
+    // if we couldn't find our Part, we exit since the Shell by
+    // itself can't do anything useful
+    KMessageBox::error(this, i18n( "Could not find the necessary Kig library, check your installation." ) );
+    QApplication::exit();
+    return;
   }
 
   // we have drag'n'drop
@@ -230,17 +226,8 @@ void Kig::dropEvent(QDropEvent* e)
 
 void Kig::fileOpen()
 {
-  QString formats =
-     i18n( "*.kig *.kigz *.seg *.fgeo *.fig *.FIG|All Supported Files (*.kig *.kigz *.seg *.fgeo *.fig)\n"
-           "*.kig|Kig Documents (*.kig)\n"
-           "*.kigz|Compressed Kig Documents (*.kigz)\n"
-           "*.kgeo|KGeo Documents (*.kgeo)\n"
-           "*.seg|KSeg Documents (*.seg)\n"
-           "*.fgeo|Dr. Geo Documents (*.fgeo)\n"
-           "*.fig *.FIG|Cabri Documents (*.fig *.FIG)" );
-
   // this slot is connected to the KStandardAction::open action...
-  QString file_name = KFileDialog::getOpenFileName( KUrl( "kfiledialog:///document" ), formats );
+  QString file_name = KFileDialog::getOpenFileName( KUrl( "kfiledialog:///document" ), m_mimeTypes.join( " " ) );
 
   if (!file_name.isEmpty()) openUrl(file_name);
 }
diff --git a/kig/kig.h b/kig/kig.h
index fe56bfd..392b76c 100644
--- a/kig/kig.h
+++ b/kig/kig.h
@@ -106,7 +106,7 @@ class Kig : public KParts::MainWindow
   void setupActions();
 
   KParts::ReadWritePart *m_part;
-
+  QStringList m_mimeTypes;
   KRecentFilesAction *m_recentFilesAction;
 
   KConfig* config;
diff --git a/kig/kig_part.desktop b/kig/kig_part.desktop
index 9c7139e..9e0c481 100644
--- a/kig/kig_part.desktop
+++ b/kig/kig_part.desktop
@@ -66,7 +66,7 @@ Name[xh]=KigPart
 Name[x-test]=xxKigPartxx
 Name[zh_CN]=Kig 组件
 Name[zh_TW]=KigPart
-MimeType=application/x-kig;application/x-kgeo;
+MimeType=application/x-kig;application/x-kgeo;image/x-xfig;application/x-cabri;application/x-drgeo;application/x-kseg;
 X-KDE-ServiceTypes=KParts/ReadOnlyPart,KParts/ReadWritePart
 X-KDE-Library=kigpart
 Type=Service


More information about the kde-doc-english mailing list