| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2002 Jürgen Riegel <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#include <limits> |
| 24 |
|
| 25 |
#include <zlib.h> |
| 26 |
#include <App/License.h> |
| 27 |
#include <Gui/AutoSaver.h> |
| 28 |
|
| 29 |
#include "DlgSettingsDocumentImp.h" |
| 30 |
#include "ui_DlgSettingsDocument.h" |
| 31 |
|
| 32 |
|
| 33 |
using namespace Gui::Dialog; |
| 34 |
|
| 35 |
/* TRANSLATOR Gui::Dialog::DlgSettingsDocumentImp */ |
| 36 |
|
| 37 |
/** |
| 38 |
* Constructs a DlgSettingsDocumentImp which is a child of 'parent', with the |
| 39 |
* name 'name' and widget flags set to 'f' |
| 40 |
*/ |
| 41 |
DlgSettingsDocumentImp::DlgSettingsDocumentImp(QWidget* parent) |
| 42 |
: PreferencePage(parent) |
| 43 |
, ui(new Ui_DlgSettingsDocument) |
| 44 |
{ |
| 45 |
ui->setupUi(this); |
| 46 |
addLicenseTypes(); |
| 47 |
|
| 48 |
ui->prefSaveTransaction->hide(); |
| 49 |
ui->prefDiscardTransaction->hide(); |
| 50 |
|
| 51 |
QString tip = QStringLiteral( |
| 52 |
"<html><head/><body><p>%1</p>" |
| 53 |
"<p>%2: %Y%m%d-%H%M%S</p>" |
| 54 |
"</p></body></html>" |
| 55 |
) |
| 56 |
.arg(tr("The format of the date to use."), tr("Default")); |
| 57 |
QString link = QString::fromLatin1( |
| 58 |
"<html><head/><body>" |
| 59 |
"<a href=\"http://www.cplusplus.com/reference/ctime/strftime/\">%1</a>" |
| 60 |
"</body></html>" |
| 61 |
) |
| 62 |
.arg(tr("Show format documentation")); |
| 63 |
ui->prefSaveBackupDateFormat->setToolTip(tip); |
| 64 |
ui->FormatTimeDocsLabel->setText(link); |
| 65 |
|
| 66 |
ui->prefCountBackupFiles->setMaximum(std::numeric_limits<int>::max()); |
| 67 |
ui->prefCompression->setMinimum(Z_NO_COMPRESSION); |
| 68 |
ui->prefCompression->setMaximum(Z_BEST_COMPRESSION); |
| 69 |
connect( |
| 70 |
ui->prefLicenseType, |
| 71 |
qOverload<int>(&QComboBox::currentIndexChanged), |
| 72 |
this, |
| 73 |
&DlgSettingsDocumentImp::onLicenseTypeChanged |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Destroys the object and frees any allocated resources |
| 79 |
*/ |
| 80 |
DlgSettingsDocumentImp::~DlgSettingsDocumentImp() = default; |
| 81 |
|
| 82 |
void DlgSettingsDocumentImp::saveSettings() |
| 83 |
{ |
| 84 |
ui->prefCheckNewDoc->onSave(); |
| 85 |
ui->prefCompression->onSave(); |
| 86 |
|
| 87 |
ui->prefUndoRedo->onSave(); |
| 88 |
ui->prefUndoRedoSize->onSave(); |
| 89 |
ui->prefSaveTransaction->onSave(); |
| 90 |
ui->prefDiscardTransaction->onSave(); |
| 91 |
ui->prefSaveThumbnail->onSave(); |
| 92 |
ui->prefThumbnailSize->onSave(); |
| 93 |
ui->prefAddLogo->onSave(); |
| 94 |
ui->prefSaveBackupFiles->onSave(); |
| 95 |
ui->prefCountBackupFiles->onSave(); |
| 96 |
ui->prefSaveBackupExtension->onSave(); |
| 97 |
ui->prefSaveBackupDateFormat->onSave(); |
| 98 |
ui->prefDisableVersionCheckOnSave->onSave(); |
| 99 |
ui->prefDuplicateLabel->onSave(); |
| 100 |
ui->prefPartialLoading->onSave(); |
| 101 |
ui->prefLicenseType->onSave(); |
| 102 |
ui->prefLicenseUrl->onSave(); |
| 103 |
ui->prefAuthor->onSave(); |
| 104 |
ui->prefSetAuthorOnSave->onSave(); |
| 105 |
ui->prefCompany->onSave(); |
| 106 |
ui->prefRecovery->onSave(); |
| 107 |
ui->prefAutoSaveEnabled->onSave(); |
| 108 |
ui->prefAutoSaveTimeout->onSave(); |
| 109 |
ui->prefCanAbortRecompute->onSave(); |
| 110 |
|
| 111 |
int timeout = ui->prefAutoSaveTimeout->value(); |
| 112 |
if (!ui->prefAutoSaveEnabled->isChecked()) { |
| 113 |
timeout = 0; |
| 114 |
} |
| 115 |
AutoSaver::instance()->setTimeout(timeout * 60000); |
| 116 |
} |
| 117 |
|
| 118 |
void DlgSettingsDocumentImp::loadSettings() |
| 119 |
{ |
| 120 |
ui->prefCheckNewDoc->onRestore(); |
| 121 |
ui->prefCompression->onRestore(); |
| 122 |
|
| 123 |
ui->prefUndoRedo->onRestore(); |
| 124 |
ui->prefUndoRedoSize->onRestore(); |
| 125 |
ui->prefSaveTransaction->onRestore(); |
| 126 |
ui->prefDiscardTransaction->onRestore(); |
| 127 |
ui->prefSaveThumbnail->onRestore(); |
| 128 |
ui->prefThumbnailSize->onRestore(); |
| 129 |
ui->prefAddLogo->onRestore(); |
| 130 |
ui->prefSaveBackupFiles->onRestore(); |
| 131 |
ui->prefCountBackupFiles->onRestore(); |
| 132 |
ui->prefSaveBackupExtension->onRestore(); |
| 133 |
ui->prefSaveBackupDateFormat->onRestore(); |
| 134 |
ui->prefDisableVersionCheckOnSave->onRestore(); |
| 135 |
ui->prefDuplicateLabel->onRestore(); |
| 136 |
ui->prefPartialLoading->onRestore(); |
| 137 |
ui->prefLicenseType->onRestore(); |
| 138 |
ui->prefLicenseUrl->onRestore(); |
| 139 |
ui->prefAuthor->onRestore(); |
| 140 |
ui->prefSetAuthorOnSave->onRestore(); |
| 141 |
ui->prefCompany->onRestore(); |
| 142 |
ui->prefRecovery->onRestore(); |
| 143 |
ui->prefAutoSaveEnabled->onRestore(); |
| 144 |
ui->prefAutoSaveTimeout->onRestore(); |
| 145 |
ui->prefCanAbortRecompute->onRestore(); |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Sets the strings of the subwidgets using the current language. |
| 150 |
*/ |
| 151 |
void DlgSettingsDocumentImp::changeEvent(QEvent* e) |
| 152 |
{ |
| 153 |
if (e->type() == QEvent::LanguageChange) { |
| 154 |
ui->retranslateUi(this); |
| 155 |
int index = ui->prefLicenseType->currentIndex(); |
| 156 |
addLicenseTypes(); |
| 157 |
ui->prefLicenseType->setCurrentIndex(index); |
| 158 |
} |
| 159 |
else { |
| 160 |
QWidget::changeEvent(e); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
void DlgSettingsDocumentImp::addLicenseTypes() |
| 165 |
{ |
| 166 |
auto add = [&](const char* what) { |
| 167 |
ui->prefLicenseType->addItem(QApplication::translate("Gui::Dialog::DlgSettingsDocument", what)); |
| 168 |
}; |
| 169 |
|
| 170 |
ui->prefLicenseType->clear(); |
| 171 |
for (const auto& licenseItem : App::licenseItems) { |
| 172 |
add(licenseItem.at(App::posnOfFullName)); |
| 173 |
} |
| 174 |
add("Other"); |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Fix Url according to changed type |
| 179 |
*/ |
| 180 |
void DlgSettingsDocumentImp::onLicenseTypeChanged(int index) |
| 181 |
{ |
| 182 |
if (index >= 0 && index < App::countOfLicenses) { |
| 183 |
// existing license |
| 184 |
const char* url {App::licenseItems.at(index).at(App::posnOfUrl)}; |
| 185 |
ui->prefLicenseUrl->setText(QString::fromLatin1(url)); |
| 186 |
ui->prefLicenseUrl->setReadOnly(true); |
| 187 |
} |
| 188 |
else { |
| 189 |
// Other |
| 190 |
ui->prefLicenseUrl->clear(); |
| 191 |
ui->prefLicenseUrl->setReadOnly(false); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
#include "moc_DlgSettingsDocumentImp.cpp" |