OSDN Git Service

設定のリセット処理が抜けていたのを修正
[gefu/Gefu.git] / preferencedialog.cpp
index 6eba542..89750cf 100644 (file)
-#include "colorsamplemodel.h"
-#include"common.h"
+#include "global.h"
+#include "preferences.h"
 #include "preferencedialog.h"
 #include "ui_preferencedialog.h"
 
-#include <QAbstractTableModel>
 #include <QColorDialog>
-#include <QSettings>
 #include <QDebug>
 #include <QDir>
-
-
+#include <QFileDialog>
+#include <QFontDialog>
+#include <QStandardPaths>
 
 PreferenceDialog::PreferenceDialog(QWidget *parent) :
     QDialog(parent),
-    ui(new Ui::PreferenceDialog),
-    m_model(),
-    m_colorMap()
+    ui(new Ui::PreferenceDialog)
 {
-    m_model.setColorMap(&m_colorMap);
-
     ui->setupUi(this);
     ui->tabWidget->setCurrentIndex(0);
-    ui->tabWidget->setTabText(0, "起動と終了");
-    ui->tabWidget->setTabText(1, "色とフォント");
-    ui->sampleEdit->setText(QDir::homePath());
-    ui->sampleTable->setModel(&m_model);
-    ui->sampleTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
-    ui->sampleTable->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
-
-    connect(ui->bootSize, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
-    connect(ui->sizeAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
-    connect(ui->sizeRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
-    connect(ui->bootPos, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
-    connect(ui->posAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
-    connect(ui->posRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
-
-    connect(ui->boxClrBg, SIGNAL(clicked()), this, SLOT(selectBoxColor()));
-    connect(ui->boxClrFg, SIGNAL(clicked()), this, SLOT(selectBoxColor()));
-
-    connect(ui->clrBgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
-    connect(ui->clrBgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
-    connect(ui->clrFgHidden, SIGNAL(clicked()), this, SLOT(selectViewColor()));
-    connect(ui->clrFgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
-    connect(ui->clrFgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
-    connect(ui->clrFgReadonly, SIGNAL(clicked()), this, SLOT(selectViewColor()));
-    connect(ui->clrFgSystem, SIGNAL(clicked()), this, SLOT(selectViewColor()));
-
-    connect(ui->boxFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont()));
-    connect(ui->boxFontBold, SIGNAL(clicked()), this, SLOT(changeFont()));
-    connect(ui->boxFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont()));
-
-    connect(ui->viewFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont()));
-    connect(ui->viewFontBold, SIGNAL(clicked()), this, SLOT(changeFont()));
-    connect(ui->viewFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont()));
-
-    QSettings settings;
-    QString strValue;
-    QSize size;
-    QPoint point;
-    QColor color;
-    QPalette palette;
-    QFont font;
-    QRadioButton *radioBtn;
-
-    //>>>>> 起動と終了
-    // 終了時の確認ダイアログ
-    ui->confirmExit->setChecked(settings.value(IniKey_ConfirmExit, true).toBool());
-    // 起動時のサイズ
-    strValue = settings.value(IniKey_BootSizeSpec, "sizeLast").toString();
-    if (strValue.isEmpty()) {
-        ui->bootSize->setChecked(false);
-    }
-    else {
-        ui->bootSize->setChecked(true);
-        radioBtn = findChild<QRadioButton*>(strValue);
-        if (radioBtn == NULL) {
-            radioBtn = ui->sizeLast;
-        }
-        radioBtn->setChecked(true);
-    }
-    size = settings.value(IniKey_BootSizeAbs, QSize(800, 600)).toSize();
-    ui->absoluteWidth->setValue(size.width());
-    ui->absoluteHeight->setValue(size.height());
-    size = settings.value(IniKey_BootSizeRel, QSize(50, 50)).toSize();
-    ui->relativeWidth->setValue(size.width());
-    ui->relativeHeight->setValue(size.height());
-    // 起動時の位置
-    strValue = settings.value(IniKey_BootPosSpec, "posLast").toString();
-    if (strValue.isEmpty()) {
-        ui->bootPos->setChecked(false);
-    }
-    else {
-        ui->bootPos->setChecked(true);
-        radioBtn = findChild<QRadioButton*>(strValue);
-        if (radioBtn == NULL) {
-            radioBtn = ui->posLast;
-        }
-        radioBtn->setChecked(true);
-    }
-    point = settings.value(IniKey_BootPosAbs, QPoint(0, 0)).toPoint();
-    ui->absoluteLeft->setValue(point.x());
-    ui->absoluteTop->setValue(point.y());
-    point = settings.value(IniKey_BootPosRel, QPoint(0, 0)).toPoint();
-    ui->relativeLeft->setValue(point.x());
-    ui->relativeTop->setValue(point.y());
-    // 起動時の設定削除
-    ui->resetOnBoot->setChecked(settings.value(IniKey_ResetOnBoot, false).toBool());
-
-    //>>>>> 色とフォント
-    //>>>> アドレスボックス
-    palette = QPalette();
-    // 背景色
-    color = settings.value(IniKey_BoxColorBg, QPalette().base().color()).value<QColor>();
-    palette.setColor(QPalette::Base, color);
-    // 文字色
-    color = settings.value(IniKey_BoxColorFg, QPalette().text().color()).value<QColor>();
-    palette.setColor(QPalette::Text, color);
-    // フォント
-    QFont defaultFont = ui->sampleEdit->font();
-    font = settings.value(IniKey_BoxFont, defaultFont).value<QFont>();
-    ui->boxFont->setCurrentText(font.family());
-    ui->boxFontBold->setChecked(font.bold());
-    ui->boxFontSize->setValue(font.pointSize());
-    // サンプル表示
-    ui->sampleEdit->setPalette(palette);
-    ui->sampleEdit->setFont(font);
-    //>>>> ファイルビュー
-    // 背景色
-    color = settings.value(IniKey_ViewColorBgMark, DefaultMarkBgColor).value<QColor>();
-    m_colorMap["clrBgMark"] = color;
-    color = settings.value(IniKey_ViewColorBgNormal, QPalette().base().color()).value<QColor>();
-    m_colorMap["clrBgNormal"] = color;
-    // 文字色
-    color = settings.value(IniKey_ViewColorFgHidden, DefaultHiddenColor).value<QColor>();
-    m_colorMap["clrFgHidden"] = color;
-    color = settings.value(IniKey_ViewColorFgMark, DefaultMarkFgColor).value<QColor>();
-    m_colorMap["clrFgMark"] = color;
-    color = settings.value(IniKey_ViewColorFgNormal, QPalette().text().color()).value<QColor>();
-    m_colorMap["clrFgNormal"] = color;
-    color = settings.value(IniKey_ViewColorFgReadonly, DefaultReadonlyColor).value<QColor>();
-    m_colorMap["clrFgReadonly"] = color;
-    color = settings.value(IniKey_ViewColorFgSystem, DefaultSystemColor).value<QColor>();
-    m_colorMap["clrFgSystem"] = color;
-    // フォント
-    defaultFont = ui->sampleTable->font();
-    font = settings.value(IniKey_ViewFont, defaultFont).value<QFont>();
-    ui->viewFont->setCurrentText(font.family());
-    ui->viewFontBold->setChecked(font.bold());
-    ui->viewFontSize->setValue(font.pointSize());
-    // サンプル表示
-    m_model.setFont(font);
-    m_model.update();
+    ui->lBoxSample->setText(QDir::homePath());
+
+    connect(ui->fvNormal, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->fvNormalBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->fvMarked, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->fvMarkedBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->fvSystem, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->fvHidden, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->fvReadOnly, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->lBoxBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->lBoxFg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->sBoxNormal, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->sBoxNormalBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->sBoxUnmatch, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->sBoxUnmatchBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->tvBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->tvFg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->gvBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->allBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+    connect(ui->allFg, SIGNAL(clicked()), this, SLOT(chooseColor()));
+
+    connect(ui->fvFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
+    connect(ui->lBoxFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
+    connect(ui->sBoxFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
+    connect(ui->tvFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
+    connect(ui->allFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
+
+    connect(ui->browseArchiver, SIGNAL(clicked()), this, SLOT(choosePath()));
+    connect(ui->browseEditor, SIGNAL(clicked()), this, SLOT(choosePath()));
+    connect(ui->browseTerminal, SIGNAL(clicked()), this, SLOT(choosePath()));
+
+    connect(ui->exportAppearance, SIGNAL(clicked()), this, SLOT(exportAppearance()));
+    connect(ui->importAppearance, SIGNAL(clicked()), this, SLOT(importAppearance()));
+
+    Preferences prefs(this);
+
+    // [全般]
+    ui->checkUpdate->setChecked(prefs.isCheckUpdate());
+    ui->confirmQuit->setChecked(prefs.isConfirmQuit());
+    ui->moveAfterCreation->setChecked(prefs.isMoveAfterCreation());
+    ui->openAfterCreation->setChecked(prefs.isOpenAfterCreation());
+    ui->confirmCopy->setChecked(prefs.isConfirmCopy());
+    ui->confirmMove->setChecked(prefs.isConfirmMove());
+    ui->confirmDelete->setChecked(prefs.isConfirmDelete());
+    ui->confirmRename->setChecked(prefs.isConfirmRename());
+    ui->autoCloseCopy->setChecked(prefs.isAutoCloseCopy());
+    ui->autoCloseMove->setChecked(prefs.isAutoCloseMove());
+    ui->autoCloseDelete->setChecked(prefs.isAutoCloseDelete());
+    ui->autoCloseRename->setChecked(prefs.isAutoCloseRename());
+    QRadioButton *radio = findChild<QRadioButton*>("rb" + prefs.getCopyBehavior());
+    if (radio)
+        radio->setChecked(true);
+    else
+        ui->rbOverWriteIfNew->setChecked(true);
+    ui->preferExtensions->setPlainText(prefs.getPreferExtensions());
+    ui->resetOnBoot->setChecked(prefs.isReset());
+
+    // [外観(色)]
+    loadAppearance(prefs);
+
+    // [外観(フォント)]
+    setFont(ui->fvFontSpec, prefs.getFolderViewFont());
+    setFont(ui->lBoxFontSpec, prefs.getLocationBoxFont());
+    setFont(ui->sBoxFontSpec, prefs.getSearchBoxFont());
+    setFont(ui->tvFontSpec, prefs.getTextViewFont());
+
+    ui->lineHeight->setValue(prefs.getLineHeight());
+
+    // [プログラムパス]
+    ui->editorPath->setText(prefs.getEditorPath());
+    ui->terminalPath->setText(prefs.getTerminalPath());
+    ui->archiverPath->setText(prefs.getArchiverPath());
 }
 
 PreferenceDialog::~PreferenceDialog()
@@ -158,171 +95,368 @@ PreferenceDialog::~PreferenceDialog()
     delete ui;
 }
 
-void PreferenceDialog::changeFont()
+void PreferenceDialog::loadAppearance(Preferences &prefs)
 {
-    QFont font;
+    setPalette(ui->fvNormalSample, QPalette::Base, prefs.getFolderViewBgColor());
+    setPalette(ui->fvNormalSample, QPalette::Text, prefs.getFolderViewFgColor());
 
-    if (sender() == ui->boxFont ||
-        sender() == ui->boxFontBold ||
-        sender() == ui->boxFontSize)
-    {
-        font.setBold(ui->boxFontBold->isChecked());
-        font.setPointSize(ui->boxFontSize->value());
-        font.setFamily(ui->boxFont->currentText());
-        ui->sampleEdit->setFont(font);
-    }
-    else {
-        font.setBold(ui->viewFontBold->isChecked());
-        font.setPointSize(ui->viewFontSize->value());
-        font.setFamily(ui->viewFont->currentText());
-        m_model.setFont(font);
-        m_model.update();
-    }
+    setPalette(ui->fvMarkedSample, QPalette::Base, prefs.getFolderViewMarkedBgColor());
+    setPalette(ui->fvMarkedSample, QPalette::Text, prefs.getFolderViewMarkedFgColor());
+
+    setPalette(ui->fvSystemSample, QPalette::Base, prefs.getFolderViewBgColor());
+    setPalette(ui->fvSystemSample, QPalette::Text, prefs.getFolderViewSystemColor());
+
+    setPalette(ui->fvHiddenSample, QPalette::Base, prefs.getFolderViewBgColor());
+    setPalette(ui->fvHiddenSample, QPalette::Text, prefs.getFolderViewHiddenColor());
+
+    setPalette(ui->fvReadOnlySample, QPalette::Base, prefs.getFolderViewBgColor());
+    setPalette(ui->fvReadOnlySample, QPalette::Text, prefs.getFolderViewReadOnlyColor());
+
+    setPalette(ui->lBoxSample, QPalette::Base, prefs.getLocationBoxBgColor());
+    setPalette(ui->lBoxSample, QPalette::Text, prefs.getLocationBoxFgColor());
+
+    setPalette(ui->sBoxNormalSample, QPalette::Base, prefs.getSearchBoxBgColor());
+    setPalette(ui->sBoxNormalSample, QPalette::Text, prefs.getSearchBoxFgColor());
+
+    setPalette(ui->sBoxUnmatchSample, QPalette::Base, prefs.getSearchBoxUnmatchBgColor());
+    setPalette(ui->sBoxUnmatchSample, QPalette::Text, prefs.getSearchBoxUnmatchFgColor());
+
+    setPalette(ui->tvSample, QPalette::Base, prefs.getTextViewBgColor());
+    setPalette(ui->tvSample, QPalette::Text, prefs.getTextViewFgColor());
+
+    setPalette(ui->gvSample, QPalette::Base, prefs.getImageViewBgColor());
+
+    ui->darkFactor->setValue(prefs.getDarkFacotr());
 }
 
-void PreferenceDialog::setControlsEnabled(bool enabled)
+void PreferenceDialog::saveAppearance(Preferences &prefs)
 {
-    if (sender() == ui->bootSize) {
-        ui->sizeAbsolute->setEnabled(enabled);
-        ui->sizeLast->setEnabled(enabled);
-        ui->sizeRelative->setEnabled(enabled);
-        if (enabled) {
-            emit ui->sizeAbsolute->toggled(ui->sizeAbsolute->isChecked());
-            emit ui->sizeRelative->toggled(ui->sizeRelative->isChecked());
-        }
-        else {
-            emit ui->sizeAbsolute->toggled(false);
-            emit ui->sizeRelative->toggled(false);
-        }
-    }
-    else if (sender() == ui->sizeAbsolute) {
-        ui->absoluteHeight->setEnabled(enabled);
-        ui->absoluteWidth->setEnabled(enabled);
-    }
-    else if (sender() == ui->sizeRelative) {
-        ui->relativeHeight->setEnabled(enabled);
-        ui->relativeWidth->setEnabled(enabled);
-    }
-    else if (sender() == ui->bootPos) {
-        ui->posAbsolute->setEnabled(enabled);
-        ui->posCenter->setEnabled(enabled);
-        ui->posLast->setEnabled(enabled);
-        ui->posRelative->setEnabled(enabled);
-        if (enabled) {
-            emit ui->posAbsolute->toggled(ui->posAbsolute->isChecked());
-            emit ui->posRelative->toggled(ui->posRelative->isChecked());
-        }
-        else {
-            emit ui->posAbsolute->toggled(false);
-            emit ui->posRelative->toggled(false);
-        }
-    }
-    else if (sender() == ui->posAbsolute) {
-        ui->absoluteLeft->setEnabled(enabled);
-        ui->absoluteTop->setEnabled(enabled);
-    }
-    else if (sender() == ui->posRelative) {
-        ui->relativeLeft->setEnabled(enabled);
-        ui->relativeTop->setEnabled(enabled);
-    }
+    prefs.setFolderViewBgColor(ui->fvNormalSample->palette().base().color());
+    prefs.setFolderViewFgColor(ui->fvNormalSample->palette().text().color());
+
+    prefs.setFolderViewMarkedBgColor(ui->fvMarkedSample->palette().base().color());
+    prefs.setFolderViewMarkedFgColor(ui->fvMarkedSample->palette().text().color());
+
+    prefs.setFolderViewHiddenColor(ui->fvHiddenSample->palette().text().color());
+    prefs.setFolderViewReadOnlyColor(ui->fvReadOnlySample->palette().text().color());
+    prefs.setFolderViewSystemColor(ui->fvSystemSample->palette().text().color());
+
+    prefs.setLocationBoxBgColor(ui->lBoxSample->palette().base().color());
+    prefs.setLocationBoxFgColor(ui->lBoxSample->palette().text().color());
+
+    prefs.setSearchBoxBgColor(ui->sBoxNormalSample->palette().base().color());
+    prefs.setSearchBoxFgColor(ui->sBoxNormalSample->palette().text().color());
+
+    prefs.setSearchBoxUnmatchBgColor(ui->sBoxUnmatchSample->palette().base().color());
+    prefs.setSearchBoxUnmatchFgColor(ui->sBoxUnmatchSample->palette().text().color());
+
+    prefs.setTextViewBgColor(ui->tvSample->palette().base().color());
+    prefs.setTextViewFgColor(ui->tvSample->palette().text().color());
+
+    prefs.setImageViewBgColor(ui->gvSample->palette().base().color());
+
+    prefs.setDarkFacotr(ui->darkFactor->value());
+}
+
+void PreferenceDialog::setFont(QLabel *label, const QFont &font)
+{
+    label->setFont(font);
+    label->setText(QString("%1, %2pt").arg(font.family()).arg(font.pointSize()));
 }
 
-void PreferenceDialog::selectBoxColor()
+void PreferenceDialog::setPalette(QWidget *w, QPalette::ColorRole role, const QColor &color)
+{
+    QPalette pal = w->palette();
+    pal.setColor(role, color);
+    w->setPalette(pal);
+}
+
+void PreferenceDialog::chooseColor()
 {
     QColor color;
-    QPalette palette = ui->sampleEdit->palette();
-    if (sender() == ui->boxClrBg) {
-        color = palette.background().color();
+
+    if (sender() == ui->fvNormal) {
+        color = ui->fvNormalSample->palette().text().color();
+    }
+    else if (sender() == ui->fvNormalBg) {
+        color = ui->fvNormalSample->palette().base().color();
+    }
+    else if (sender() == ui->fvMarked) {
+        color = ui->fvMarkedSample->palette().text().color();
+    }
+    else if (sender() == ui->fvMarkedBg) {
+        color = ui->fvMarkedSample->palette().base().color();
     }
-    else if (sender() == ui->boxClrFg) {
-        color = palette.text().color();
+    else if (sender() == ui->fvSystem) {
+        color = ui->fvSystemSample->palette().text().color();
+    }
+    else if (sender() == ui->fvHidden) {
+        color = ui->fvHiddenSample->palette().text().color();
+    }
+    else if (sender() == ui->fvReadOnly) {
+        color = ui->fvReadOnlySample->palette().text().color();
+    }
+    else if (sender() == ui->lBoxBg) {
+        color = ui->lBoxSample->palette().base().color();
+    }
+    else if (sender() == ui->lBoxFg) {
+        color = ui->lBoxSample->palette().text().color();
+    }
+    else if (sender() == ui->sBoxNormal) {
+        color = ui->sBoxNormalSample->palette().text().color();
+    }
+    else if (sender() == ui->sBoxNormalBg) {
+        color = ui->sBoxNormalSample->palette().base().color();
+    }
+    else if (sender() == ui->sBoxUnmatch) {
+        color = ui->sBoxUnmatchSample->palette().text().color();
+    }
+    else if (sender() == ui->sBoxUnmatchBg) {
+        color = ui->sBoxUnmatchSample->palette().base().color();
+    }
+    else if (sender() == ui->tvBg) {
+        color = ui->tvSample->palette().base().color();
+    }
+    else if (sender() == ui->tvFg) {
+        color = ui->tvSample->palette().text().color();
+    }
+    else if (sender() == ui->gvBg) {
+        color = ui->gvSample->palette().base().color();
+    }
+    else if (sender() == ui->allBg) {
+        color = ui->fvNormalSample->palette().base().color();
+    }
+    else if (sender() == ui->allFg) {
+        color = ui->fvNormalSample->palette().text().color();
     }
 
-    color = QColorDialog::getColor(color, this, tr("色選択"));
+    color = QColorDialog::getColor(color, this, tr("色選択"));
     if (!color.isValid()) {
         return;
     }
 
-    if (sender() == ui->boxClrBg) {
-        palette.setColor(QPalette::Base, color);
-        ui->sampleEdit->setPalette(palette);
+    QPalette pal;
+    if (sender() == ui->fvNormal) {
+        setPalette(ui->fvNormalSample, QPalette::Text, color);
+    }
+    else if (sender() == ui->fvNormalBg) {
+        setPalette(ui->fvNormalSample, QPalette::Base, color);
+        setPalette(ui->fvHiddenSample, QPalette::Base, color);
+        setPalette(ui->fvReadOnlySample, QPalette::Base, color);
+        setPalette(ui->fvSystemSample, QPalette::Base, color);
+    }
+    else if (sender() == ui->fvMarked) {
+        setPalette(ui->fvMarkedSample, QPalette::Text, color);
+    }
+    else if (sender() == ui->fvMarkedBg) {
+        setPalette(ui->fvMarkedSample, QPalette::Base, color);
+    }
+    else if (sender() == ui->fvSystem) {
+        setPalette(ui->fvSystemSample, QPalette::Text, color);
+    }
+    else if (sender() == ui->fvHidden) {
+        setPalette(ui->fvHiddenSample, QPalette::Text, color);
+    }
+    else if (sender() == ui->fvReadOnly) {
+        setPalette(ui->fvReadOnlySample, QPalette::Text, color);
+    }
+    else if (sender() == ui->lBoxBg) {
+        setPalette(ui->lBoxSample, QPalette::Base, color);
+    }
+    else if (sender() == ui->lBoxFg) {
+        setPalette(ui->lBoxSample, QPalette::Text, color);
+    }
+    else if (sender() == ui->sBoxNormal) {
+        setPalette(ui->sBoxNormalSample, QPalette::Text, color);
+    }
+    else if (sender() == ui->sBoxNormalBg) {
+        setPalette(ui->sBoxNormalSample, QPalette::Base, color);
+    }
+    else if (sender() == ui->sBoxUnmatch) {
+        setPalette(ui->sBoxUnmatchSample, QPalette::Text, color);
+    }
+    else if (sender() == ui->sBoxUnmatchBg) {
+        setPalette(ui->sBoxUnmatchSample, QPalette::Base, color);
+    }
+    else if (sender() == ui->tvBg) {
+        setPalette(ui->tvSample, QPalette::Base, color);
+    }
+    else if (sender() == ui->tvFg) {
+        setPalette(ui->tvSample, QPalette::Text, color);
+    }
+    else if (sender() == ui->gvBg) {
+        setPalette(ui->gvSample, QPalette::Base, color);
+    }
+    else if (sender() == ui->allBg) {
+        setPalette(ui->fvNormalSample, QPalette::Base, color);
+        setPalette(ui->fvHiddenSample, QPalette::Base, color);
+        setPalette(ui->fvReadOnlySample, QPalette::Base, color);
+        setPalette(ui->fvSystemSample, QPalette::Base, color);
+        setPalette(ui->lBoxSample, QPalette::Base, color);
+        setPalette(ui->sBoxNormalSample, QPalette::Base, color);
+        setPalette(ui->tvSample, QPalette::Base, color);
+        setPalette(ui->gvSample, QPalette::Base, color);
+    }
+    else if (sender() == ui->allFg) {
+        setPalette(ui->fvNormalSample, QPalette::Text, color);
+        setPalette(ui->lBoxSample, QPalette::Text, color);
+        setPalette(ui->sBoxNormalSample, QPalette::Text, color);
+        setPalette(ui->tvSample, QPalette::Text, color);
+    }
+}
+
+void PreferenceDialog::chooseFont()
+{
+    QFont font;
+    if (sender() == ui->fvFont) {
+        font = ui->fvFontSpec->font();
+    }
+    else if (sender() == ui->lBoxFont) {
+        font = ui->lBoxFontSpec->font();
+    }
+    else if (sender() == ui->sBoxFont) {
+        font = ui->sBoxFontSpec->font();
+    }
+    else if (sender() == ui->tvFont) {
+        font = ui->tvFontSpec->font();
+    }
+    else if (sender() == ui->allFont) {
+        font = ui->fvFontSpec->font();
+    }
+
+    bool ok;
+    font = QFontDialog::getFont(&ok, font, this, tr("フォントを選択"));
+
+    if (!ok) {
+        return;
+    }
+
+    if (sender() == ui->fvFont) {
+        setFont(ui->fvFontSpec, font);
+    }
+    else if (sender() == ui->lBoxFont) {
+        setFont(ui->lBoxFontSpec, font);
+    }
+    else if (sender() == ui->sBoxFont) {
+        setFont(ui->sBoxFontSpec, font);
+    }
+    else if (sender() == ui->tvFont) {
+        setFont(ui->tvFontSpec, font);
     }
-    else if (sender() == ui->boxClrFg) {
-        palette.setColor(QPalette::Text, color);
-        ui->sampleEdit->setPalette(palette);
+    else if (sender() == ui->allFont) {
+        setFont(ui->fvFontSpec, font);
+        setFont(ui->lBoxFontSpec, font);
+        setFont(ui->sBoxFontSpec, font);
+        setFont(ui->tvFontSpec, font);
     }
 }
 
-void PreferenceDialog::selectViewColor()
+void PreferenceDialog::choosePath()
 {
-    const QString objName = sender()->objectName();
-    QColor color = m_colorMap[objName];
+    QStringList list = QStandardPaths::standardLocations(
+                QStandardPaths::ApplicationsLocation);
+#ifdef Q_OS_WIN
+    QString path = QFileDialog::getOpenFileName(
+                this, tr("アプリケーションを選択"), getenv("PROGRAMFILES"),
+                tr("実行ファイル (*.exe *.com *.bat *.pif);;すべてのファイル (*)"));
+#elif defined(Q_OS_MAC)
+    QString path = QFileDialog::getOpenFileName(
+                this, tr("アプリケーションを選択"), list.at(0),
+                tr("実行ファイル (*.app);;すべてのファイル (*)"));
+#else
+    QString path = QFileDialog::getOpenFileName(
+                this, tr("アプリケーションを選択"), list.at(0),
+                tr("すべてのファイル (*)"));
+#endif
+    if (path.isEmpty()) {
+        return;
+    }
 
-    color = QColorDialog::getColor(color, this, tr("色選択"));
-    if (!color.isValid()) {
+    if (path.indexOf(" ") != -1) {
+        path = QQ(path);
+    }
+
+    if (sender() == ui->browseEditor) {
+        ui->editorPath->setText(path);
+    }
+    else if (sender() == ui->browseTerminal) {
+        ui->terminalPath->setText(path);
+    }
+    else if (sender() == ui->browseArchiver) {
+        ui->archiverPath->setText(path);
+    }
+}
+
+void PreferenceDialog::exportAppearance()
+{
+    QStringList list = QStandardPaths::standardLocations(
+                QStandardPaths::DocumentsLocation);
+    QString path = QFileDialog::getSaveFileName(
+                this, tr("ファイルを選択"), list.at(0) + "/gefu_appearance.ini",
+                tr("設定ファイル (*.ini);;すべてのファイル (*)"));
+    if (path.isEmpty()) {
         return;
     }
 
-    m_colorMap[objName] = color;
-    m_model.update();
+    Preferences prefs(path, this);
+    saveAppearance(prefs);
+}
+
+void PreferenceDialog::importAppearance()
+{
+    QStringList list = QStandardPaths::standardLocations(
+                QStandardPaths::DocumentsLocation);
+    QString path = QFileDialog::getOpenFileName(
+                this, tr("ファイルを選択"), list.at(0),
+                tr("設定ファイル (*.ini);;すべてのファイル (*)"));
+    if (path.isEmpty()) {
+        return;
+    }
+
+    Preferences prefs(path, this);
+    loadAppearance(prefs);
 }
 
 void PreferenceDialog::accept()
 {
-    QSettings settings;
-    QAbstractButton *selected;
-
-    //>>>>> 起動と終了
-    // 終了時の確認ダイアログ
-    settings.setValue(IniKey_ConfirmExit, ui->confirmExit->isChecked());
-    // 起動時のサイズ
-    if (!ui->bootSize->isChecked()) {
-        settings.setValue(IniKey_BootSizeSpec, "");
-    }
-    else {
-        selected = ui->sizeOptions->checkedButton();
-        settings.setValue(IniKey_BootSizeSpec, selected->objectName());
-        QSize size;
-        // 絶対指定
-        size = QSize(ui->absoluteWidth->value(), ui->absoluteHeight->value());
-        settings.setValue(IniKey_BootSizeAbs, size);
-        // 相対指定
-        size = QSize(ui->relativeWidth->value(), ui->relativeHeight->value());
-        settings.setValue(IniKey_BootSizeRel, size);
-    }
-    // 起動時の位置
-    if (!ui->bootPos->isChecked()) {
-        settings.setValue(IniKey_BootPosSpec, "");
-    }
-    else {
-        selected = ui->posOptions->checkedButton();
-        settings.setValue(IniKey_BootPosSpec, selected->objectName());
-        // 絶対指定
-        QPoint pos;
-        pos = QPoint(ui->absoluteLeft->value(), ui->absoluteTop->value());
-        settings.setValue(IniKey_BootPosAbs, pos);
-        // 相対指定
-        pos = QPoint(ui->relativeLeft->value(), ui->relativeTop->value());
-        settings.setValue(IniKey_BootPosRel, pos);
-    }
-    // 起動時の設定削除
-    settings.setValue(IniKey_ResetOnBoot, ui->resetOnBoot->isChecked());
-
-    //>>>>> 色とフォント
-    QFont font = ui->sampleEdit->font();
-    QPalette palette = ui->sampleEdit->palette();
-    settings.setValue(IniKey_BoxColorBg, palette.base().color());
-    settings.setValue(IniKey_BoxColorFg, palette.text().color());
-    settings.setValue(IniKey_BoxFont, font);
-
-    settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]);
-    settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]);
-    settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]);
-    settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]);
-    settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]);
-    settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]);
-    settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]);
-    settings.setValue(IniKey_ViewFont, m_model.font());
+    Preferences prefs(this);
+
+    // [全般]
+    prefs.setCheckUpdate(ui->checkUpdate->isChecked());
+    prefs.setConfirmQuit(ui->confirmQuit->isChecked());
+    prefs.setMoveAfterCreation(ui->moveAfterCreation->isChecked());
+    prefs.setOpenAfterCreation(ui->openAfterCreation->isChecked());
+    prefs.setConfirmCopy(ui->confirmCopy->isChecked());
+    prefs.setConfirmMove(ui->confirmMove->isChecked());
+    prefs.setConfirmDelete(ui->confirmDelete->isChecked());
+    prefs.setConfirmRename(ui->confirmRename->isChecked());
+    prefs.setAutoCloseCopy(ui->autoCloseCopy->isChecked());
+    prefs.setAutoCloseMove(ui->autoCloseMove->isChecked());
+    prefs.setAutoCloseDelete(ui->autoCloseDelete->isChecked());
+    prefs.setAutoCloseRename(ui->autoCloseRename->isChecked());
+
+    QAbstractButton *checked = ui->copyBehavior->checkedButton();
+    prefs.setCopyBehavior(checked->objectName().mid(2));
+
+    prefs.setPreferExtensions(ui->preferExtensions->toPlainText());
+    prefs.setReset(ui->resetOnBoot->isChecked());
+
+    // [外観(色)]
+    saveAppearance(prefs);
+
+    // [外観(フォント)]
+    prefs.setFolderViewFont(ui->fvFontSpec->font());
+    prefs.setLocationBoxFont(ui->lBoxFontSpec->font());
+    prefs.setSearchBoxFont(ui->sBoxFontSpec->font());
+    prefs.setTextViewFont(ui->tvFontSpec->font());
+
+    prefs.setLineHeight(ui->lineHeight->value());
+
+    // [プログラムパス]
+    prefs.setEditorPath(ui->editorPath->text());
+    prefs.setTerminalPath(ui->terminalPath->text());
+    prefs.setArchiverPath(ui->archiverPath->text());
 
     QDialog::accept();
 }
+