1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/exportoofiledialog.cpp Fri Mar 05 19:15:08 2010 +0000
1.3 @@ -0,0 +1,95 @@
1.4 +#include <iostream>
1.5 +
1.6 +#include "exportoofiledialog.h"
1.7 +
1.8 +ExportOOFileDialog::ExportOOFileDialog():QFileDialog()
1.9 +{
1.10 + init();
1.11 +}
1.12 +
1.13 +ExportOOFileDialog::ExportOOFileDialog (QWidget * parent, const QString &caption ):QFileDialog(parent, caption)
1.14 +{
1.15 + init();
1.16 +}
1.17 +
1.18 +bool ExportOOFileDialog::foundConfig()
1.19 +{
1.20 + return !filters.isEmpty();
1.21 +}
1.22 +
1.23 +
1.24 +QString ExportOOFileDialog::selectedConfig()
1.25 +{
1.26 + QStringList::Iterator itpath=configPaths.begin();
1.27 + QStringList::Iterator itf=filters.begin();
1.28 + while (itf != filters.end())
1.29 + {
1.30 + if (*itf==selectedFilter()) return *itpath;
1.31 + itpath++;
1.32 + itf++;
1.33 + }
1.34 + qWarning ("ExportOOFileDialog::selectedConfig No filter found!");
1.35 + return "";
1.36 +}
1.37 +
1.38 +void ExportOOFileDialog::newConfigPath(const QString &s)
1.39 +{
1.40 + lastFilter=s;
1.41 +}
1.42 +
1.43 +QString ExportOOFileDialog::selectedFile()
1.44 +{
1.45 + return QFileDialog::selectedFile();
1.46 +}
1.47 +
1.48 +
1.49 +void ExportOOFileDialog::show()
1.50 +{
1.51 + setFilters (filters);
1.52 + QFileDialog::show();
1.53 +}
1.54 +
1.55 +void ExportOOFileDialog::init()
1.56 +{
1.57 + setMode( QFileDialog::AnyFile );
1.58 + QDir d;
1.59 + d.setPath (vymBaseDir.path()+"/exports");
1.60 + scanExportConfigs(d);
1.61 + d.setPath (d.homeDirPath()+"/.vym/exports");
1.62 + scanExportConfigs(d);
1.63 +
1.64 + connect (
1.65 + this,SIGNAL (filterSelected(const QString&)),
1.66 + this, SLOT( newConfigPath(const QString &)));
1.67 +}
1.68 +
1.69 +void ExportOOFileDialog::addFilter(const QString &f)
1.70 +{
1.71 + lastFilter=f;
1.72 + filters.append (f);
1.73 +}
1.74 +
1.75 +void ExportOOFileDialog::scanExportConfigs(QDir dir)
1.76 +{
1.77 + // Scan existing export configurations
1.78 + SimpleSettings set;
1.79 + QFile f;
1.80 + if (dir.exists())
1.81 + {
1.82 + // Traverse files
1.83 + dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
1.84 +
1.85 + QFileInfoList list = dir.entryInfoList();
1.86 + for (int i = 0; i < list.size(); ++i) {
1.87 + QFileInfo fi = list.at(i);
1.88 +
1.89 + if (fi.fileName().endsWith(".conf") )
1.90 + {
1.91 + configPaths.append (fi.absFilePath());
1.92 + set.clear();
1.93 + set.readSettings (fi.absFilePath());
1.94 + addFilter (set.readEntry(QString("Name")) + " (*.odp)");
1.95 + }
1.96 + }
1.97 + }
1.98 +}