kofiledialog.cpp
00001
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 if ( index == KoDocument::SaveAsDirectoryStore ){
00040 ops->setMode(KFile::Directory);
00041 } else {
00042 ops->setMode(KFile::File);
00043 }
00044 updateAutoSelectExtension();
00045 }
00046
00047 void KoFileDialog::setSpecialMimeFilter( QStringList& mimeFilter,
00048 const QString& currentFormat, const int specialOutputFlag,
00049 const QString& nativeFormat,
00050 int supportedSpecialFormats )
00051 {
00052 Q_ASSERT( !mimeFilter.isEmpty() );
00053 Q_ASSERT( mimeFilter[0] == nativeFormat );
00054
00055 bool add1dot1 = supportedSpecialFormats & KoDocument::SaveAsKOffice1dot1;
00056 bool addUncompressed = supportedSpecialFormats & KoDocument::SaveAsDirectoryStore;
00057
00058 int idxSpecialOutputFlag = 0;
00059 int numSpecialEntries = 0;
00060 if ( add1dot1 ) {
00061 ++numSpecialEntries;
00062 m_specialFormats.append( KoDocument::SaveAsKOffice1dot1 );
00063 if ( specialOutputFlag == KoDocument::SaveAsKOffice1dot1 )
00064 idxSpecialOutputFlag = numSpecialEntries;
00065 }
00066 if ( addUncompressed ) {
00067 ++numSpecialEntries;
00068 m_specialFormats.append( KoDocument::SaveAsDirectoryStore );
00069 if ( specialOutputFlag == KoDocument::SaveAsDirectoryStore )
00070 idxSpecialOutputFlag = numSpecialEntries;
00071 }
00072
00073
00074 QStringList::Iterator mimeFilterIt = mimeFilter.at( 1 );
00075 mimeFilter.insert( mimeFilterIt , numSpecialEntries, nativeFormat );
00076
00077
00078
00079
00080 setMimeFilter( mimeFilter, currentFormat.isEmpty() ? nativeFormat : currentFormat );
00081
00082
00083 KMimeType::Ptr type = KMimeType::mimeType( nativeFormat );
00084 int idx = 1;
00085 if ( add1dot1 )
00086 filterWidget->changeItem( i18n("%1 (KOffice-1.1 Format)").arg( type->comment() ), idx++ );
00087 if ( addUncompressed )
00088 filterWidget->changeItem( i18n("%1 (Uncompressed XML Files)").arg( type->comment() ), idx++ );
00089
00090
00091
00092 if (currentFormat == nativeFormat || currentFormat.isEmpty())
00093 {
00094
00095 filterWidget->setCurrentItem( idxSpecialOutputFlag );
00096 slotChangedfilter( filterWidget->currentItem() );
00097 }
00098
00099 int i = 0;
00100 for (mimeFilterIt = mimeFilter.begin (); mimeFilterIt != mimeFilter.end (); ++mimeFilterIt, i++)
00101 {
00102 KMimeType::Ptr mime = KMimeType::mimeType (*mimeFilterIt);
00103 QString compatString = mime->property ("X-KDE-CompatibleApplication").toString ();
00104 if (!compatString.isEmpty ())
00105 filterWidget->changeItem (i18n ("%1 (%2 Compatible)").arg (mime->comment ()).arg (compatString), i);
00106 }
00107 }
00108
00109 int KoFileDialog::specialEntrySelected()
00110 {
00111 int i = filterWidget->currentItem();
00112
00113 if ( i >= 1 && i <= (int)m_specialFormats.count() )
00114 return m_specialFormats[i-1];
00115 return 0;
00116 }
00117
00118 #include "kofiledialog.moc"
This file is part of the documentation for lib Library Version 1.4.2.