lib
KoFileDialog.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KoFileDialog.h"
00022 #include "KoDocument.h"
00023 #include <kfilefiltercombo.h>
00024 #include <klocale.h>
00025 #include <kdiroperator.h>
00026 #include <kdebug.h>
00027
00028 KoFileDialog::KoFileDialog(const QString& startDir, const QString& filter,
00029 QWidget *parent, const char *name,
00030 bool modal)
00031 : KFileDialog( startDir, filter, parent, name, modal )
00032 {
00033 connect( filterWidget, SIGNAL( activated( int) ),
00034 this, SLOT( slotChangedfilter( int ) ) );
00035 }
00036
00037 void KoFileDialog::slotChangedfilter( int index )
00038 {
00039
00040
00041 KFile::Mode newMode = KFile::File;
00042 if ( index >= 1 && index <= (int)m_specialFormats.count()
00043 && m_specialFormats[index-1] == KoDocument::SaveAsDirectoryStore ) {
00044 newMode = KFile::Directory;
00045 }
00046 if ( newMode != mode() )
00047 {
00048 ops->setMode( newMode );
00049 updateAutoSelectExtension();
00050 }
00051 }
00052
00053 void KoFileDialog::setSpecialMimeFilter( QStringList& mimeFilter,
00054 const QString& currentFormat, const int specialOutputFlag,
00055 const QString& nativeFormat,
00056 int supportedSpecialFormats )
00057 {
00058 Q_ASSERT( !mimeFilter.isEmpty() );
00059 Q_ASSERT( mimeFilter[0] == nativeFormat );
00060
00061 bool addUncompressed = supportedSpecialFormats & KoDocument::SaveAsDirectoryStore;
00062 bool addFlatXML = supportedSpecialFormats & KoDocument::SaveAsFlatXML;
00063
00064 int idxSpecialOutputFlag = 0;
00065 int numSpecialEntries = 0;
00066 if ( addUncompressed ) {
00067 ++numSpecialEntries;
00068 m_specialFormats.append( KoDocument::SaveAsDirectoryStore );
00069 if ( specialOutputFlag == KoDocument::SaveAsDirectoryStore )
00070 idxSpecialOutputFlag = numSpecialEntries;
00071 }
00072 if ( addFlatXML ) {
00073 ++numSpecialEntries;
00074 m_specialFormats.append( KoDocument::SaveAsFlatXML );
00075 if ( specialOutputFlag == KoDocument::SaveAsFlatXML )
00076 idxSpecialOutputFlag = numSpecialEntries;
00077 }
00078
00079
00080 QStringList::Iterator mimeFilterIt = mimeFilter.at( 1 );
00081 mimeFilter.insert( mimeFilterIt , numSpecialEntries, nativeFormat );
00082
00083
00084
00085
00086 setMimeFilter( mimeFilter, currentFormat.isEmpty() ? nativeFormat : currentFormat );
00087
00088
00089 KMimeType::Ptr type = KMimeType::mimeType( nativeFormat );
00090 int idx = 1;
00091
00092 if ( addUncompressed )
00093 filterWidget->changeItem( i18n("%1 (Uncompressed XML Files)").arg( type->comment() ), idx++ );
00094 if ( addFlatXML )
00095 filterWidget->changeItem( i18n("%1 (Flat XML File)").arg( type->comment() ), idx++ );
00096
00097
00098
00099 if (currentFormat == nativeFormat || currentFormat.isEmpty())
00100 {
00101
00102 filterWidget->setCurrentItem( idxSpecialOutputFlag );
00103 slotChangedfilter( filterWidget->currentItem() );
00104 }
00105
00106 int i = 0;
00107 for (mimeFilterIt = mimeFilter.begin (); mimeFilterIt != mimeFilter.end (); ++mimeFilterIt, i++)
00108 {
00109 KMimeType::Ptr mime = KMimeType::mimeType (*mimeFilterIt);
00110 QString compatString = mime->property ("X-KDE-CompatibleApplication").toString ();
00111 if (!compatString.isEmpty ())
00112 filterWidget->changeItem (i18n ("%1 (%2 Compatible)").arg (mime->comment ()).arg (compatString), i);
00113 }
00114 }
00115
00116 int KoFileDialog::specialEntrySelected()
00117 {
00118 int i = filterWidget->currentItem();
00119
00120 if ( i >= 1 && i <= (int)m_specialFormats.count() )
00121 return m_specialFormats[i-1];
00122 return 0;
00123 }
00124
00125 #include "KoFileDialog.moc"
|