1 #include "foldermodel.h"
3 #include "preferences.h"
5 #include <QApplication>
7 #include <QDesktopWidget>
9 QString DefaultPreferExtensions()
14 list << "ico" << "ai" << "psd" << "xcf" << "tif" << "tiff" << "wmf";
16 list << "wav" << "mp3" << "ogg" << "midi" << "mid" << "aif" << "aiff";
17 list << "mov" << "mpg" << "mpeg" << "wma" << "wmv" << "asf" << "avi";
18 list << "flac" << "mkv";
20 list << "exe" << "com" << "msi" << "scr";
22 list << "lzh" << "zip" << "cab" << "tar" << "rar" << "gz" << "tgz";
23 list << "bz2" << "xz" << "jar" << "7z" << "dmg";
25 list << "pdf" << "doc" << "docx" << "xls" << "xlsx" << "ppt" << "pptx";
27 list << "ttf" << "ttc";
31 return list.join(",");
34 QFont DefaultFixedFont()
36 QFont font = qApp->font();
38 font.setFamily("MS ゴシック");
39 #elif defined(Q_OS_MAC)
40 font.setFamily("Monaco");
46 Preferences::Preferences(QObject *parent) :
47 QSettings(QSettings::IniFormat,
49 qApp->organizationName(),
50 qApp->applicationName(),
55 Preferences::Preferences(const QString &path, QObject *parent) :
56 QSettings(path, QSettings::IniFormat, parent)
60 #define Key_Filter(side) (side + "/Filter")
61 #define Key_NameFilter(side) (side + "/NameFilter")
62 #define Key_Sort(side) (side + "/Sort")
63 #define Key_Path(side) (side + "/Path")
64 void Preferences::restoreModel(const QString &side, FolderModel *m)
66 qDebug() << "Preferences::restoreModel()" << side;
68 int filter = value(Key_Filter(side), 0).toInt();
69 filter |= QDir::NoDot | QDir::AllDirs | QDir::Files;
70 m->setFilter(QFlag(filter));
72 QString nameFilter = value(Key_NameFilter(side), "*").toString();
73 m->setNameFilters(nameFilter.split(" ", QString::SkipEmptyParts));
75 int sort = QDir::Name | QDir::DirsFirst | QDir::IgnoreCase;
76 sort = value(Key_Sort(side), sort).toInt();
77 m->setSorting(QFlag(sort));
79 QString path = QDir::homePath();
80 path = value(Key_Path(side), path).toString();
84 void Preferences::saveModel(const QString &side, const FolderModel *m)
86 qDebug() << "Preferences::saveModel()" << side;
88 setValue(Key_Filter(side), static_cast<int>(m->filter()));
89 setValue(Key_Sort(side), static_cast<int>(m->sorting()));
90 setValue(Key_Path(side), m->rootPath());
93 #define Key_WindowGeometry "WindowGeometry"
94 #define Key_WindowState "WindowState"
95 void Preferences::restoreWindow(QMainWindow *w)
97 qDebug() << "Preferences::restoreWindow()";
99 QByteArray geometry = value(Key_WindowGeometry).toByteArray();
100 if (geometry.isNull()) {
101 QSize size(700, 400);
103 point.setX((qApp->desktop()->width() - size.width()) / 2);
104 point.setY((qApp->desktop()->height() - size.height()) / 2);
105 w->setGeometry(QRect(point, size));
108 w->restoreGeometry(geometry);
111 QByteArray state = value(Key_WindowState).toByteArray();
112 if (!state.isEmpty()) {
113 w->restoreState(state);
117 void Preferences::saveWindow(const QMainWindow *w)
119 setValue(Key_WindowGeometry, w->saveGeometry());
120 setValue(Key_WindowState, w->saveState());
123 ///////////////////////////////////////////////////////////////////////////////
124 #define Key_BookmarkEntry(i) QString("Bookmark/Entry%1").arg(i)
125 #define Key_BookmarkPath(i) QString("Bookmark/Path%1").arg(i)
126 void Preferences::addBookmark(const QString &name, const QString &path)
129 for (n = 1; !value(Key_BookmarkEntry(n)).isNull(); n++)
132 setValue(Key_BookmarkEntry(n), name);
133 setValue(Key_BookmarkPath(n), path);
136 void Preferences::clearBookmark()
138 beginGroup("Bookmark");
143 QString Preferences::getBookmarkEntry(int n) const
145 return value(Key_BookmarkEntry(n)).toString();
148 QString Preferences::getBookmarkPath(int n) const
150 return value(Key_BookmarkPath(n)).toString();
153 QColor Preferences::folderViewFgColor(bool active) const
155 int darkFactor = 100;
157 darkFactor += getDarkFacotr() * 100;
159 return getFolderViewFgColor().darker(darkFactor);
162 QColor Preferences::folderViewBgColor(bool active) const
164 int darkFactor = 100;
166 darkFactor += getDarkFacotr() * 100;
168 return getFolderViewBgColor().darker(darkFactor);
171 QColor Preferences::folderViewMarkedFgColor(bool active) const
173 int darkFactor = 100;
175 darkFactor += getDarkFacotr() * 100;
177 return getFolderViewMarkedFgColor().darker(darkFactor);
180 QColor Preferences::folderViewMarkedBgColor(bool active) const
182 int darkFactor = 100;
184 darkFactor += getDarkFacotr() * 100;
186 return getFolderViewMarkedBgColor().darker(darkFactor);
189 QColor Preferences::folderViewSystemColor(bool active) const
191 int darkFactor = 100;
193 darkFactor += getDarkFacotr() * 100;
195 return getFolderViewSystemColor().darker(darkFactor);
198 QColor Preferences::folderViewHiddenColor(bool active) const
200 int darkFactor = 100;
202 darkFactor += getDarkFacotr() * 100;
204 return getFolderViewHiddenColor().darker(darkFactor);
207 QColor Preferences::folderViewReadOnlyColor(bool active) const
209 int darkFactor = 100;
211 darkFactor += getDarkFacotr() * 100;
213 return getFolderViewReadOnlyColor().darker(darkFactor);
216 QColor Preferences::locationBoxFgColor(bool active) const
218 int darkFactor = 100;
220 darkFactor += getDarkFacotr() * 100;
222 return getLocationBoxFgColor().darker(darkFactor);
225 QColor Preferences::locationBoxBgColor(bool active) const
227 int darkFactor = 100;
229 darkFactor += getDarkFacotr() * 100;
231 return getLocationBoxBgColor().darker(darkFactor);
234 #define IMPLEMENT_BOOL(key, defVal) \
235 bool Preferences::is##key() const { \
236 return value(#key, def##key()).toBool(); \
238 bool Preferences::def##key() const { \
241 void Preferences::set##key(bool value) { \
242 setValue(#key, value); \
245 IMPLEMENT_BOOL(Reset, false)
246 IMPLEMENT_BOOL(CheckUpdate, true)
247 IMPLEMENT_BOOL(ConfirmQuit, true)
248 IMPLEMENT_BOOL(ConfirmCopy, true)
249 IMPLEMENT_BOOL(AutoCloseCopy, false)
250 IMPLEMENT_BOOL(ConfirmMove, true)
251 IMPLEMENT_BOOL(AutoCloseMove, false)
252 IMPLEMENT_BOOL(ConfirmDelete, true)
253 IMPLEMENT_BOOL(AutoCloseDelete, false)
254 IMPLEMENT_BOOL(ConfirmRename, true)
255 IMPLEMENT_BOOL(AutoCloseRename, false)
256 IMPLEMENT_BOOL(OpenAfterCreation, false)
257 IMPLEMENT_BOOL(MoveAfterCreation, false)
259 #define IMPLEMENT_STRING(key, defVal) \
260 QString Preferences::get##key() const { \
261 return value(#key, def##key()).toString(); \
263 QString Preferences::def##key() const { \
266 void Preferences::set##key(const QString &value) { \
267 setValue(#key, value); \
272 #elif defined(Q_OS_MAC)
273 IMPLEMENT_STRING(ArchiverPath, QQ("/System/Library/CoreServices/Archive Utility.app"))
274 IMPLEMENT_STRING(EditorPath, "/Applications/TextEdit.app")
275 IMPLEMENT_STRING(TerminalPath, "/Applications/Utilities/Terminal.app --args -c cd")
277 IMPLEMENT_STRING(ArchiverPath, QQ("C:/Program Files/Lhaplus/Lhaplus.exe"))
278 IMPLEMENT_STRING(EditorPath, "notepad.exe")
279 IMPLEMENT_STRING(TerminalPath, "cmd.exe /k cd")
282 IMPLEMENT_STRING(CopyBehavior, "OverWriteIfNew")
283 IMPLEMENT_STRING(PreferExtensions, DefaultPreferExtensions())
285 #define IMPLEMENT_COLOR(key, defVal) \
286 QColor Preferences::get##key() const { \
287 return value("Appearance/"#key, def##key()).value<QColor>(); \
289 QColor Preferences::def##key() const { \
292 void Preferences::set##key(const QColor &value) { \
293 setValue("Appearance/"#key, value); \
296 IMPLEMENT_COLOR(FolderViewFgColor, QPalette().text().color())
297 IMPLEMENT_COLOR(FolderViewBgColor, QPalette().base().color())
298 IMPLEMENT_COLOR(FolderViewMarkedFgColor, QColor(128, 0, 0))
299 IMPLEMENT_COLOR(FolderViewMarkedBgColor, QColor(0, 192, 0))
300 IMPLEMENT_COLOR(FolderViewSystemColor, QColor(128, 0, 128))
301 IMPLEMENT_COLOR(FolderViewHiddenColor, QColor(128, 128, 128))
302 IMPLEMENT_COLOR(FolderViewReadOnlyColor, QColor(0, 128, 0))
303 IMPLEMENT_COLOR(LocationBoxFgColor, QPalette().text().color())
304 IMPLEMENT_COLOR(LocationBoxBgColor, QPalette().base().color())
305 IMPLEMENT_COLOR(SearchBoxFgColor, QPalette().text().color())
306 IMPLEMENT_COLOR(SearchBoxBgColor, QPalette().base().color())
307 IMPLEMENT_COLOR(SearchBoxUnmatchFgColor, QColor(255, 0, 0))
308 IMPLEMENT_COLOR(SearchBoxUnmatchBgColor, QPalette().base().color())
309 IMPLEMENT_COLOR(TextViewFgColor, QPalette().text().color())
310 IMPLEMENT_COLOR(TextViewBgColor, QPalette().base().color())
311 IMPLEMENT_COLOR(ImageViewBgColor, QPalette().base().color())
313 #define IMPLEMENT_DOUBLE(key, defVal) \
314 double Preferences::get##key() const { \
315 return value("Appearance/"#key, def##key()).toDouble(); \
317 double Preferences::def##key() const { \
320 void Preferences::set##key(double value) { \
321 setValue("Appearance/"#key, value); \
324 IMPLEMENT_DOUBLE(DarkFacotr, 0)
325 IMPLEMENT_DOUBLE(LineHeight, 1.5)
327 #define IMPLEMENT_FONT(key, defVal) \
328 QFont Preferences::get##key() const { \
329 return value("Appearance/"#key, def##key()).value<QFont>(); \
331 QFont Preferences::def##key() const { \
334 void Preferences::set##key(const QFont &value) { \
335 setValue("Appearance/"#key, value); \
338 IMPLEMENT_FONT(FolderViewFont, DefaultFixedFont())
339 IMPLEMENT_FONT(LocationBoxFont, DefaultFixedFont())
340 IMPLEMENT_FONT(SearchBoxFont, DefaultFixedFont())
341 IMPLEMENT_FONT(TextViewFont, DefaultFixedFont())