mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kio: remove obsolete hack related to file dialog
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
0d50d69dbb
commit
f6aba57553
1 changed files with 0 additions and 191 deletions
|
@ -529,195 +529,4 @@ KAbstractFileWidget* KFileDialog::fileWidget()
|
||||||
return d->w;
|
return d->w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption,
|
|
||||||
const QString &dir,
|
|
||||||
QFileDialog::Options options);
|
|
||||||
extern _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook;
|
|
||||||
|
|
||||||
typedef QString (*_qt_filedialog_open_filename_hook)(QWidget * parent, const QString &caption,
|
|
||||||
const QString &dir, const QString &filter,
|
|
||||||
QString *selectedFilter,
|
|
||||||
QFileDialog::Options options);
|
|
||||||
extern _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook;
|
|
||||||
|
|
||||||
typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption,
|
|
||||||
const QString &dir, const QString &filter,
|
|
||||||
QString *selectedFilter,
|
|
||||||
QFileDialog::Options options);
|
|
||||||
extern _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook;
|
|
||||||
|
|
||||||
typedef QString (*_qt_filedialog_save_filename_hook)(QWidget * parent, const QString &caption,
|
|
||||||
const QString &dir, const QString &filter,
|
|
||||||
QString *selectedFilter,
|
|
||||||
QFileDialog::Options options);
|
|
||||||
extern _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This class is used to override Qt's QFileDialog calls with KFileDialog ones.
|
|
||||||
* This is necessary because QPrintDialog calls QFileDialog::getSaveFileName() for
|
|
||||||
* the print to file function.
|
|
||||||
*/
|
|
||||||
class KFileDialogQtOverride
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
KFileDialogQtOverride()
|
|
||||||
{
|
|
||||||
if(!qt_filedialog_existing_directory_hook)
|
|
||||||
qt_filedialog_existing_directory_hook=&getExistingDirectory;
|
|
||||||
if(!qt_filedialog_open_filename_hook)
|
|
||||||
qt_filedialog_open_filename_hook=&getOpenFileName;
|
|
||||||
if(!qt_filedialog_open_filenames_hook)
|
|
||||||
qt_filedialog_open_filenames_hook=&getOpenFileNames;
|
|
||||||
if(!qt_filedialog_save_filename_hook)
|
|
||||||
qt_filedialog_save_filename_hook=&getSaveFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
~KFileDialogQtOverride() {
|
|
||||||
if(qt_filedialog_existing_directory_hook == &getExistingDirectory)
|
|
||||||
qt_filedialog_existing_directory_hook = 0;
|
|
||||||
if(qt_filedialog_open_filename_hook == &getOpenFileName)
|
|
||||||
qt_filedialog_open_filename_hook = 0;
|
|
||||||
if(qt_filedialog_open_filenames_hook == &getOpenFileNames)
|
|
||||||
qt_filedialog_open_filenames_hook=0;
|
|
||||||
if(qt_filedialog_save_filename_hook == &getSaveFileName)
|
|
||||||
qt_filedialog_save_filename_hook=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Map a Katie filter string into a KDE one.
|
|
||||||
*/
|
|
||||||
static QString qt2KdeFilter(const QString &f)
|
|
||||||
{
|
|
||||||
QString filter;
|
|
||||||
QTextStream str(&filter, QIODevice::WriteOnly);
|
|
||||||
QStringList list(f.split(";;").replaceInStrings("/", "\\/"));
|
|
||||||
QStringList::const_iterator it(list.begin()),
|
|
||||||
end(list.end());
|
|
||||||
bool first=true;
|
|
||||||
|
|
||||||
for(; it!=end; ++it)
|
|
||||||
{
|
|
||||||
int ob=(*it).lastIndexOf('('),
|
|
||||||
cb=(*it).lastIndexOf(')');
|
|
||||||
|
|
||||||
if(-1!=cb && ob<cb)
|
|
||||||
{
|
|
||||||
if(first)
|
|
||||||
first=false;
|
|
||||||
else
|
|
||||||
str << '\n';
|
|
||||||
str << (*it).mid(ob+1, (cb-ob)-1) << '|' << (*it).mid(0, ob);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Map a KDE filter string into a Qt one.
|
|
||||||
*/
|
|
||||||
static void kde2QtFilter(const QString &orig, const QString &kde, QString *sel)
|
|
||||||
{
|
|
||||||
if(sel)
|
|
||||||
{
|
|
||||||
QStringList list(orig.split(";;"));
|
|
||||||
QStringList::const_iterator it(list.begin()),
|
|
||||||
end(list.end());
|
|
||||||
int pos;
|
|
||||||
|
|
||||||
for(; it!=end; ++it)
|
|
||||||
if(-1!=(pos=(*it).indexOf(kde)) && pos>0 &&
|
|
||||||
('('==(*it)[pos-1] || ' '==(*it)[pos-1]) &&
|
|
||||||
(*it).length()>=kde.length()+pos &&
|
|
||||||
(')'==(*it)[pos+kde.length()] || ' '==(*it)[pos+kde.length()]))
|
|
||||||
{
|
|
||||||
*sel=*it;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir,
|
|
||||||
QFileDialog::Options options)
|
|
||||||
{
|
|
||||||
fileModule(); // make sure i18n is initialized properly, needed for pure Qt applications
|
|
||||||
KUrl url(KFileDialog::getExistingDirectory(KUrl(dir), parent, caption));
|
|
||||||
|
|
||||||
if (url.isLocalFile()) {
|
|
||||||
return url.pathOrUrl();
|
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,
|
|
||||||
const QString &filter, QString *selectedFilter,
|
|
||||||
QFileDialog::Options options)
|
|
||||||
{
|
|
||||||
fileModule(); // make sure i18n is initialized properly, needed for pure Qt applications
|
|
||||||
KFileDialog dlg(KUrl(dir), qt2KdeFilter(filter), parent);
|
|
||||||
|
|
||||||
dlg.setOperationMode(KFileDialog::Opening);
|
|
||||||
dlg.setMode(KFile::File|KFile::LocalOnly);
|
|
||||||
dlg.setCaption(caption);
|
|
||||||
dlg.exec();
|
|
||||||
|
|
||||||
QString rv(dlg.selectedFile());
|
|
||||||
|
|
||||||
if (!rv.isEmpty()) {
|
|
||||||
kde2QtFilter(filter, dlg.currentFilter(), selectedFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QStringList getOpenFileNames(QWidget *parent, const QString &caption, const QString &dir,
|
|
||||||
const QString &filter, QString *selectedFilter,
|
|
||||||
QFileDialog::Options options)
|
|
||||||
{
|
|
||||||
fileModule(); // make sure i18n is initialized properly, needed for pure Qt applications
|
|
||||||
KFileDialog dlg(KUrl(dir), qt2KdeFilter(filter), parent);
|
|
||||||
|
|
||||||
dlg.setOperationMode(KFileDialog::Opening);
|
|
||||||
dlg.setMode(KFile::Files|KFile::LocalOnly);
|
|
||||||
dlg.setCaption(caption);
|
|
||||||
dlg.exec();
|
|
||||||
|
|
||||||
QStringList rv(dlg.selectedFiles());
|
|
||||||
|
|
||||||
if (rv.count()) {
|
|
||||||
kde2QtFilter(filter, dlg.currentFilter(), selectedFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
|
|
||||||
const QString &filter, QString *selectedFilter,
|
|
||||||
QFileDialog::Options options)
|
|
||||||
{
|
|
||||||
fileModule(); // make sure i18n is initialized properly, needed for pure Qt applications
|
|
||||||
KFileDialog dlg(KUrl(dir), qt2KdeFilter(filter), parent);
|
|
||||||
|
|
||||||
dlg.setOperationMode(KFileDialog::Saving);
|
|
||||||
dlg.setMode(KFile::File|KFile::LocalOnly);
|
|
||||||
dlg.setCaption(caption);
|
|
||||||
dlg.setConfirmOverwrite(!(options & QFileDialog::DontConfirmOverwrite));
|
|
||||||
dlg.exec();
|
|
||||||
|
|
||||||
QString rv(dlg.selectedFile());
|
|
||||||
|
|
||||||
if (!rv.isEmpty()) {
|
|
||||||
kde2QtFilter(filter, dlg.currentFilter(), selectedFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
static KFileDialogQtOverride qtOverride;
|
|
||||||
|
|
||||||
#include "moc_kfiledialog.cpp"
|
#include "moc_kfiledialog.cpp"
|
||||||
|
|
Loading…
Add table
Reference in a new issue