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