exportoofiledialog.cpp
author insilmaril
Wed, 25 Feb 2009 12:44:10 +0000
branchrelease-1-12-maintained
changeset 57 d045ba89798e
permissions -rw-r--r--
Bugfix: Enabled multiple mapcenters for export to OpenOffice.org
     1 #include <iostream>
     2 
     3 #include "exportoofiledialog.h"
     4 
     5 ExportOOFileDialog::ExportOOFileDialog():QFileDialog()
     6 {
     7 	init();
     8 }
     9 
    10 ExportOOFileDialog::ExportOOFileDialog (QWidget * parent, const QString &caption ):QFileDialog(parent, caption)
    11 {
    12 	init();
    13 }
    14 
    15 bool ExportOOFileDialog::foundConfig()
    16 {
    17 	return !filters.isEmpty();
    18 }
    19 
    20 
    21 QString ExportOOFileDialog::selectedConfig()
    22 {
    23 	QStringList::Iterator itpath=configPaths.begin();
    24 	QStringList::Iterator itf=filters.begin();
    25 	while (itf != filters.end()) 
    26 	{
    27 		if (*itf==selectedFilter()) return *itpath;
    28 		itpath++;	
    29 		itf++;
    30     }
    31 	qWarning ("ExportOOFileDialog::selectedConfig  No filter found!");
    32 	return "";
    33 }
    34 
    35 void ExportOOFileDialog::newConfigPath(const QString &s)
    36 {
    37 	lastFilter=s;
    38 }
    39 
    40 QString ExportOOFileDialog::selectedFile()
    41 {
    42 	return QFileDialog::selectedFile();
    43 }
    44 
    45 
    46 void ExportOOFileDialog::show()
    47 {
    48 	setFilters (filters);
    49 	QFileDialog::show();
    50 }
    51 
    52 void ExportOOFileDialog::init()
    53 {
    54 	setMode( QFileDialog::AnyFile );
    55 	QDir d;
    56 	d.setPath (vymBaseDir.path()+"/exports");
    57 	scanExportConfigs(d);
    58 	d.setPath (d.homeDirPath()+"/.vym/exports");
    59 	scanExportConfigs(d);
    60 
    61 	connect (
    62 		this,SIGNAL (filterSelected(const QString&)),
    63 		this, SLOT( newConfigPath(const QString &)));
    64 }
    65 
    66 void ExportOOFileDialog::addFilter(const QString &f)
    67 {
    68 	lastFilter=f;
    69 	filters.append (f);
    70 }
    71 
    72 void ExportOOFileDialog::scanExportConfigs(QDir dir)
    73 {
    74 	// Scan existing export configurations
    75 	SimpleSettings set;
    76 	QFile f;
    77 	if (dir.exists())
    78 	{
    79 		// Traverse files
    80         dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    81 
    82         QFileInfoList list = dir.entryInfoList();
    83         for (int i = 0; i < list.size(); ++i) {
    84             QFileInfo fi = list.at(i);
    85 
    86 			if (fi.fileName().endsWith(".conf") )
    87 			{
    88 				configPaths.append (fi.absFilePath());
    89 				set.clear();
    90 				set.readSettings (fi.absFilePath());
    91 				addFilter (set.readEntry(QString("Name")) + " (*.odp)");
    92 			}		
    93         }
    94 	}		
    95 }