Developer Documentation
Loading...
Searching...
No Matches
RecentFiles.hh
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42//=============================================================================
43//
44// Options used throughout the System
45//
46//=============================================================================
47
54#pragma once
55
56#include <QDir>
57#include <QStringList>
58#include <QString>
59#include <QComboBox>
60#include <QFileDialog>
61#include <stdexcept>
62
64
65namespace OpenFlipper {
66namespace Options {
67
68
69//===========================================================================
72//===========================================================================
73
76 void addRecentFile(QString _file, DataType _type);
77
85 void rememberRecentItem(const QString &propName, const QString &itemName, const int RECENT_ITEMS_MAX_SIZE = 10);
86
91 QStringList getRecentItems(const QString &propName);
92
98 QString getMostRecentItem(const QString &propName);
99
107 inline static void updateComboBox(QComboBox *cb, const QString &value, const char *propName) {
108 if (propName != 0) {
109 cb->clear();
110 if (value.length() > 0)
111 rememberRecentItem(QString::fromUtf8(propName), value);
112 const QStringList content = getRecentItems(QString::fromUtf8(propName));
113 cb->insertItems(0, content);
114 }
115 cb->setEditText(value);
116 }
117
118 enum DialogType {
119 DT_OPEN,
120 DT_SAVE,
121 DT_CHOOSE_PATH,
122 };
123
132 inline static QString obtainPathName(QComboBox *cb, const char *title, const char *filters,
133 const char *propName, DialogType dialog_type = DT_OPEN) {
134 QString result;
135 switch (dialog_type) {
136 case DT_OPEN:
137 result = QFileDialog::getOpenFileName(0, QObject::tr(title), cb->currentText(), QObject::tr(filters));
138 break;
139 case DT_SAVE:
140 result = QFileDialog::getSaveFileName(0, QObject::tr(title), cb->currentText(), QObject::tr(filters));
141 break;
142 case DT_CHOOSE_PATH:
143 result = QFileDialog::getExistingDirectory(0, QObject::tr(title), cb->currentText());
144 break;
145 default:
146 throw std::logic_error("Unknown value for dialog_type.");
147 }
148
149 if (result.length() > 0)
150 updateComboBox(cb, result, propName);
151
152 return result;
153 }
157}
158}
159
#define DLLEXPORT
Predefined datatypes.
Definition DataTypes.hh:83