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

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

SVN commit 440024 by pletourn:

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

BUG:109269


 M  +53 -4     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  +17 -4     kdelibs/kio/kfile/kpropertiesdialog.cpp  


--- branches/KDE/3.5/kdebase/kcontrol/filetypes/keditfiletype.cpp \
#440023:440024 @@ -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>
 
 #ifdef Q_WS_X11
 #include <X11/Xlib.h>
@@ -35,10 +38,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 );
   QListView * dummyListView = new QListView( 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
@@ -111,11 +126,40 @@
 
   if (args->count() == 0)
     KCmdLineArgs::usage();
-  KMimeType::Ptr mime = KMimeType::mimeType( args->arg(0) );
+
+  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 " << args->arg(0) << " not found" << endl;
+      kdFatal() << "Mimetype " << arg << " not found" << endl;
+  }
 
-  FileTypeDialog dlg( mime );
+  FileTypeDialog dlg( mime, createType );
 #if defined Q_WS_X11
   if( args->isSet( "parent" )) {
     bool ok;
@@ -125,7 +169,12 @@
   }
 #endif
   args->clear();
+  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
 
--- branches/KDE/3.5/kdebase/kcontrol/filetypes/keditfiletype.h \
#440023:440024 @@ -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;
 };
--- branches/KDE/3.5/kdebase/kcontrol/filetypes/typeslistitem.cpp \
#440023:440024 @@ -50,6 +50,13 @@
   setText(0, majorType());
 }
 
+TypesListItem::TypesListItem(QListView *parent, KMimeType::Ptr mimetype, \
bool newItem) +  : QListViewItem(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"))
   {
--- branches/KDE/3.5/kdebase/kcontrol/filetypes/typeslistitem.h \
#440023:440024 @@ -43,6 +43,12 @@
    */
   TypesListItem(QListView *parent, KMimeType::Ptr mimetype);
 
+  /**
+   * Create a filetype item not inside a group (used by keditfiletype)
+   * KDE4: merge with previous
+   */
+  TypesListItem(QListView *parent, KMimeType::Ptr mimetype, bool newItem);
+
   ~TypesListItem();
 
   QString name() const { return m_major + "/" + m_minor; }
--- branches/KDE/3.5/kdelibs/kio/kfile/kpropertiesdialog.cpp #440023:440024
@@ -915,7 +915,10 @@
     QPixmap pixMap = iconSet.pixmap( QIconSet::Small, QIconSet::Normal );
     button->setIconSet( iconSet );
     button->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
-    QToolTip::add(button, i18n("Edit file type"));
+    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() ));
 
@@ -1084,11 +1087,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
 }
@@ -2784,7 +2797,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 );
 
@@ -3076,7 +3089,7 @@
      QValueListIterator<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