[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE
From:       Pascal Létourneau <pletourn () globetrotter ! net>
Date:       2005-07-29 15:58:21
Message-ID: 1122652701.284703.11467.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 440029 by pletourn:

Don't let the user edit the mimetype 'application/octet-stream'
Create a new mimetype instead


 M  +55 -6     kdebase/kcontrol/filetypes/keditfiletype.cpp  
 M  +2 -0      kdebase/kcontrol/filetypes/keditfiletype.h  
 M  +9 -0      kdebase/kcontrol/filetypes/typeslistitem.cpp  
 M  +6 -0      kdebase/kcontrol/filetypes/typeslistitem.h  
 M  +16 -3     kdelibs/kio/kfile/kpropertiesdialog.cpp  


--- trunk/KDE/kdebase/kcontrol/filetypes/keditfiletype.cpp #440028:440029
@@ -19,12 +19,15 @@
 #include "typeslistitem.h"
 #include "keditfiletype.h"
 
+#include <qfile.h>
+
 #include <dcopclient.h>
 #include <kapplication.h>
 #include <kaboutdata.h>
 #include <kdebug.h>
 #include <kcmdlineargs.h>
 #include <ksycoca.h>
+#include <kstandarddirs.h>
 #include <QX11Info>
 
 #ifdef Q_WS_X11
@@ -36,10 +39,22 @@
   : KDialogBase( 0L, 0, false, QString::null, /* Help | */ Cancel | Apply | Ok,
                  Ok, false )
 {
+  init( mime, false );
+}
+
+FileTypeDialog::FileTypeDialog( KMimeType::Ptr mime, bool newItem )
+  : KDialogBase( 0L, 0, false, QString::null, /* Help | */ Cancel | Apply | Ok,
+                 Ok, false )
+{
+  init( mime, newItem );
+}
+
+void FileTypeDialog::init( KMimeType::Ptr mime, bool newItem )
+{
   m_details = new FileTypeDetails( this );
   Q3ListView * dummyListView = new Q3ListView( m_details );
   dummyListView->hide();
-  m_item = new TypesListItem( dummyListView, mime );
+  m_item = new TypesListItem( dummyListView, mime, newItem );
   m_details->setTypeItem( m_item );
 
   // This code is very similar to kcdialog.cpp
@@ -112,11 +127,40 @@
 
   if (args->count() == 0)
     KCmdLineArgs::usage();
-  KMimeType::Ptr mime = KMimeType::mimeType( args->arg(0) );
-  if (!mime)
-    kdFatal() << "Mimetype " << args->arg(0) << " not found" << endl;
 
-  FileTypeDialog dlg( mime );
+  QString arg = args->arg(0);
+
+  bool createType = arg.startsWith( "*" );
+
+  KMimeType::Ptr mime;
+  
+  if ( createType ) {
+    QString mimeString = "application/x-kdeuser%1";
+    QString loc;
+    int inc = 0;
+    do {
+      ++inc;
+      loc = locateLocal( "mime", mimeString.arg( inc ) + ".desktop" );
+    }
+    while ( QFile::exists( loc ) );
+
+    QStringList patterns;
+    if ( arg.length() > 2 )
+	patterns << arg.lower() << arg.upper();
+    QString comment;
+    if ( arg.startsWith( "*." ) && arg.length() >= 3 ) {
+	QString type = arg.mid( 3 ).prepend( arg[2].upper() );
+        comment = i18n( "%1 File" ).arg( type );
+    }
+    mime = new KMimeType( loc, mimeString.arg( inc ), QString::null, comment, \
patterns ); +  }
+  else { 
+    mime = KMimeType::mimeType( arg );
+    if (!mime)
+      kdFatal() << "Mimetype " << arg << " not found" << endl;
+  }
+
+  FileTypeDialog dlg( mime, createType );
 #if defined Q_WS_X11
   if( args->isSet( "parent" )) {
     bool ok;
@@ -126,7 +170,12 @@
   }
 #endif
   args->clear();
-  dlg.setCaption( i18n("Edit File Type %1").arg(mime->name()) );
+  if ( !createType )
+    dlg.setCaption( i18n("Edit File Type %1").arg(mime->name()) );
+  else {
+    dlg.setCaption( i18n("Create New File Type %1").arg(mime->name()) );
+    dlg.enableButton( KDialogBase::Apply, true );
+  }
   app.setMainWidget( &dlg );
   dlg.show(); // non-modal
 
--- trunk/KDE/kdebase/kcontrol/filetypes/keditfiletype.h #440028:440029
@@ -30,6 +30,7 @@
   Q_OBJECT
 public:
   FileTypeDialog( KMimeType::Ptr mime );
+  FileTypeDialog( KMimeType::Ptr mime, bool newItem );
 
 protected slots:
 
@@ -44,6 +45,7 @@
   void save();
 
 private:
+  void init( KMimeType::Ptr mime, bool newItem );
   FileTypeDetails * m_details;
   TypesListItem * m_item;
 };
--- trunk/KDE/kdebase/kcontrol/filetypes/typeslistitem.cpp #440028:440029
@@ -50,6 +50,13 @@
   setText(0, majorType());
 }
 
+TypesListItem::TypesListItem(Q3ListView *parent, KMimeType::Ptr mimetype, bool \
newItem) +  : Q3ListViewItem(parent), metaType(false), m_bNewItem(newItem), \
m_askSave(2) +{
+  init(mimetype);
+  setText(0, majorType());
+}
+
 TypesListItem::~TypesListItem()
 {
 }
@@ -139,6 +146,8 @@
 
 bool TypesListItem::isMimeTypeDirty() const
 {
+  if ( m_bNewItem )
+    return true;
   if ((m_mimetype->name() != name()) &&
       (name() != "application/octet-stream"))
   {
--- trunk/KDE/kdebase/kcontrol/filetypes/typeslistitem.h #440028:440029
@@ -43,6 +43,12 @@
    */
   TypesListItem(Q3ListView *parent, KMimeType::Ptr mimetype);
 
+  /**
+   * Create a filetype item not inside a group (used by keditfiletype)
+   * KDE4: merge with previous
+   */
+  TypesListItem(Q3ListView *parent, KMimeType::Ptr mimetype, bool newItem);
+
   ~TypesListItem();
 
   QString name() const { return m_major + "/" + m_minor; }
--- trunk/KDE/kdelibs/kio/kfile/kpropertiesdialog.cpp #440028:440029
@@ -914,6 +914,9 @@
     QPixmap pixMap = iconSet.pixmap( QIcon::Small, QIcon::Normal );
     button->setIconSet( iconSet );
     button->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
+    if ( d->mimeType == KMimeType::defaultMimeType() )
+       QToolTip::add(button, i18n("Create new file type"));
+    else
     QToolTip::add(button, i18n("Edit file type"));
 
     connect( button, SIGNAL( clicked() ), SLOT( slotEditFileType() ));
@@ -1083,11 +1086,21 @@
 void KFilePropsPlugin::slotEditFileType()
 {
 #ifdef Q_WS_X11
+  QString mime;
+  if ( d->mimeType == KMimeType::defaultMimeType() ) {
+    int pos = d->oldFileName.findRev( '.' );
+    if ( pos != -1 )
+	mime = "*" + d->oldFileName.mid(pos);
+    else
+	mime = "*";
+  }
+  else
+    mime = d->mimeType;
     //TODO: wrap for win32 or mac?
   QString keditfiletype = QString::fromLatin1("keditfiletype");
   KRun::runCommand( keditfiletype
                     + " --parent " + QString::number( \
                (ulong)properties->topLevelWidget()->winId())
-                    + " " + KProcess::quote(d->mimeType),
+                    + " " + KProcess::quote(mime),
                     keditfiletype, keditfiletype /*unused*/);
 #endif
 }
@@ -2779,7 +2792,7 @@
   readonly->setChecked( ro );
 
   if ( unmountedStr.isEmpty() )
-    unmountedStr = KMimeType::mimeType(QString::fromLatin1("application/octet-stream"))->KServiceType::icon(); \
// default icon +    unmountedStr = \
KMimeType::defaultMimeTypePtr()->KServiceType::icon(); // default icon  
   unmounted->setIcon( unmountedStr );
 
@@ -3071,7 +3084,7 @@
      Q3ValueListIterator<KMimeType::Ptr> it(mimetypes.begin());
      for (; it != mimetypes.end(); ++it) {
         QString mimetype = (*it)->name();
-        if (mimetype == "application/octet-stream")
+        if (mimetype == KMimeType::defaultMimeType())
            continue;
         int index = mimetype.find("/");
         QString maj = mimetype.left(index);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic