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