exportoofiledialog.cpp
author insilmaril
Tue Apr 08 08:28:37 2008 +0000 (2008-04-08)
changeset 683 7df0b7986274
parent 357 64819498efbf
permissions -rw-r--r--
1.11.7: Fixed hanging find function
     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 ("/usr/share/vym/exports");
    57 	scanExportConfigs(d);
    58 	d.setPath (d.homeDirPath()+"/.vym/exports");
    59 	scanExportConfigs(d);
    60 	d.setPath (d.currentPath()+"/exports");
    61 	scanExportConfigs(d);
    62 
    63 	connect (
    64 		this,SIGNAL (filterSelected(const QString&)),
    65 		this, SLOT( newConfigPath(const QString &)));
    66 }
    67 
    68 void ExportOOFileDialog::addFilter(const QString &f)
    69 {
    70 	lastFilter=f;
    71 	filters.append (f);
    72 }
    73 
    74 void ExportOOFileDialog::scanExportConfigs(QDir dir)
    75 {
    76 	// Scan existing export configurations
    77 	SimpleSettings set;
    78 	QFile f;
    79 	if (dir.exists())
    80 	{
    81 		// Traverse files
    82         dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    83 
    84         QFileInfoList list = dir.entryInfoList();
    85         for (int i = 0; i < list.size(); ++i) {
    86             QFileInfo fi = list.at(i);
    87 
    88 			if (fi.fileName().endsWith(".conf") )
    89 			{
    90 				configPaths.append (fi.absFilePath());
    91 				set.clear();
    92 				set.readSettings (fi.absFilePath());
    93 				addFilter (set.readEntry(QString("Name")) + " (*.odp)");
    94 			}		
    95         }
    96 	}		
    97 }