From 645d176a139b2a9707b6e9548fc98379217a0c0c Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 20 Jan 2015 20:01:14 -0200 Subject: [PATCH] Added preference setting to set default Author & License - fixes #1883 * added fields in Prefereces->Default->Document * new documents take the values of those fields --- src/App/Document.cpp | 56 ++++++- src/Gui/DlgSettingsDocument.ui | 234 ++++++++++++++++++++++++++--- src/Gui/DlgSettingsDocumentImp.cpp | 49 ++++++ src/Gui/DlgSettingsDocumentImp.h | 3 + 4 files changed, 316 insertions(+), 26 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 3c493bd8d..8548cb9ab 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -595,13 +595,17 @@ Document::Document(void) Console().Log("+App::Document: %p\n",this); #endif std::string CreationDateString = Base::TimeInfo::currentDateTimeString(); + std::string Author = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Document")->GetASCII("prefAuthor",""); + std::string AuthorComp = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Document")->GetASCII("prefCompany",""); ADD_PROPERTY_TYPE(Label,("Unnamed"),0,Prop_None,"The name of the document"); ADD_PROPERTY_TYPE(FileName,(""),0,Prop_ReadOnly,"The path to the file where the document is saved to"); - ADD_PROPERTY_TYPE(CreatedBy,(""),0,Prop_None,"The creator of the document"); + ADD_PROPERTY_TYPE(CreatedBy,(Author.c_str()),0,Prop_None,"The creator of the document"); ADD_PROPERTY_TYPE(CreationDate,(CreationDateString.c_str()),0,Prop_ReadOnly,"Date of creation"); ADD_PROPERTY_TYPE(LastModifiedBy,(""),0,Prop_None,0); ADD_PROPERTY_TYPE(LastModifiedDate,("Unknown"),0,Prop_ReadOnly,"Date of last modification"); - ADD_PROPERTY_TYPE(Company,(""),0,Prop_None,"Additional tag to save the the name of the company"); + ADD_PROPERTY_TYPE(Company,(AuthorComp.c_str()),0,Prop_None,"Additional tag to save the the name of the company"); ADD_PROPERTY_TYPE(Comment,(""),0,Prop_None,"Additional tag to save a comment"); ADD_PROPERTY_TYPE(Meta,(),0,Prop_None,"Map with additional meta information"); ADD_PROPERTY_TYPE(Material,(),0,Prop_None,"Map with material properties"); @@ -611,8 +615,44 @@ Document::Document(void) ADD_PROPERTY_TYPE(Uid,(id),0,Prop_ReadOnly,"UUID of the document"); // license stuff - ADD_PROPERTY_TYPE(License,("CC-BY 3.0"),0,Prop_None,"License string of the Item"); - ADD_PROPERTY_TYPE(LicenseURL,("http://creativecommons.org/licenses/by/3.0/"),0,Prop_None,"URL to the license text/contract"); + int licenseId = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Document")->GetInt("prefLicenseType",0); + std::string license; + switch (licenseId) { + case 0: + license = "All rights reserved"; + break; + case 1: + license = "CreativeCommons Attribution"; + break; + case 2: + license = "CreativeCommons Attribution-ShareAlike"; + break; + case 3: + license = "CreativeCommons Attribution-NoDerivatives"; + break; + case 4: + license = "CreativeCommons Attribution-NonCommercial"; + break; + case 5: + license = "CreativeCommons Attribution-NonCommercial-ShareAlike"; + break; + case 6: + license = "CreativeCommons Attribution-NonCommercial-NoDerivatives"; + break; + case 7: + license = "Public Domain"; + break; + case 8: + license = "FreeArt"; + break; + default: + license = "Other"; + } + std::string licenseUrl = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Document")->GetASCII("prefLicenseUrl","http://en.wikipedia.org/wiki/All_rights_reserved"); + ADD_PROPERTY_TYPE(License,(license.c_str()),0,Prop_None,"License string of the Item"); + ADD_PROPERTY_TYPE(LicenseURL,(licenseUrl.c_str()),0,Prop_None,"URL to the license text/contract"); // this creates and sets 'TransientDir' in onChanged() ADD_PROPERTY_TYPE(TransientDir,(""),0,PropertyType(Prop_Transient|Prop_ReadOnly), @@ -951,6 +991,14 @@ bool Document::save (void) if (*(FileName.getValue()) != '\0') { std::string LastModifiedDateString = Base::TimeInfo::currentDateTimeString(); LastModifiedDate.setValue(LastModifiedDateString.c_str()); + // set author if needed + bool saveAuthor = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Document")->GetBool("prefSetAuthorOnSave",false); + if (saveAuthor) { + std::string Author = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Document")->GetASCII("prefAuthor",""); + LastModifiedBy.setValue(Author.c_str()); + } // make a tmp. file where to save the project data first and then rename to // the actual file name. This may be useful if overwriting an existing file // fails so that the data of the work up to now isn't lost. diff --git a/src/Gui/DlgSettingsDocument.ui b/src/Gui/DlgSettingsDocument.ui index 93aa5b766..0ca6ddc6b 100644 --- a/src/Gui/DlgSettingsDocument.ui +++ b/src/Gui/DlgSettingsDocument.ui @@ -6,14 +6,27 @@ 0 0 - 470 - 423 + 500 + 593 Document + + + + Qt::Vertical + + + + 429 + 37 + + + + @@ -92,10 +105,10 @@ Create new document at start up - - false - - + + false + + CreateNewDoc @@ -134,10 +147,10 @@ Using Undo/Redo on documents - - true - - + + true + + UsingUndo @@ -293,30 +306,207 @@ - - - Qt::Vertical + + + Authoring and License - - - 429 - 37 - - - + + + + + + + Author name + + + + + + + <html><head/><body><p>The name to use on document creation.</p><p>Keep blank for anonymous.</p><p>You can also use the form:</p><p>John Doe &lt;john@doe.com&gt;</p></body></html> + + + prefAuthor + + + Document + + + + + + + If this is checked, the "Last modified by" field will be set when saving the file + + + Set on save + + + prefSetAuthorOnSave + + + Document + + + + + + + + + + + Company + + + + + + + The defautl company to use for new files + + + prefCompany + + + Document + + + + + + + + + + + Default license + + + + + + + true + + + The default license for new documents + + + false + + + prefLicenseType + + + Document + + + + All rights reserved + + + + + CreativeCommons Attribution + + + + + CreativeCommons Attribution-ShareAlike + + + + + CreativeCommons Attribution-NoDerivatives + + + + + CreativeCommons Attribution-NonCommercial + + + + + CreativeCommons Attribution-NonCommercial-ShareAlike + + + + + CreativeCommons Attribution-NonCommercial-NoDerivatives + + + + + Public Domain + + + + + FreeArt + + + + + Other + + + + + + + + + + + + License URL + + + + + + + An URL where the user can find more details about the license + + + http://en.wikipedia.org/wiki/All_rights_reserved + + + prefLicenseUrl + + + Document + + + + + + + + + Gui::PrefSpinBox + QSpinBox +
Gui/PrefWidgets.h
+
Gui::PrefCheckBox QCheckBox
Gui/PrefWidgets.h
- Gui::PrefSpinBox - QSpinBox + Gui::PrefComboBox + QComboBox +
Gui/PrefWidgets.h
+
+ + Gui::PrefLineEdit + QLineEdit
Gui/PrefWidgets.h
diff --git a/src/Gui/DlgSettingsDocumentImp.cpp b/src/Gui/DlgSettingsDocumentImp.cpp index 4f80e31e2..38478086e 100644 --- a/src/Gui/DlgSettingsDocumentImp.cpp +++ b/src/Gui/DlgSettingsDocumentImp.cpp @@ -43,6 +43,7 @@ DlgSettingsDocumentImp::DlgSettingsDocumentImp( QWidget* parent ) prefCountBackupFiles->setMaximum(INT_MAX); prefCompression->setMinimum(Z_NO_COMPRESSION); prefCompression->setMaximum(Z_BEST_COMPRESSION); + connect( prefLicenseType, SIGNAL(currentIndexChanged(int)), this, SLOT(on_prefLicenseType_changed(int)) ); } /** @@ -67,6 +68,11 @@ void DlgSettingsDocumentImp::saveSettings() prefSaveBackupFiles->onSave(); prefCountBackupFiles->onSave(); prefDuplicateLabel->onSave(); + prefLicenseType->onSave(); + prefLicenseUrl->onSave(); + prefAuthor->onSave(); + prefSetAuthorOnSave->onSave(); + prefCompany->onSave(); } void DlgSettingsDocumentImp::loadSettings() @@ -82,6 +88,11 @@ void DlgSettingsDocumentImp::loadSettings() prefSaveBackupFiles->onRestore(); prefCountBackupFiles->onRestore(); prefDuplicateLabel->onRestore(); + prefLicenseType->onRestore(); + prefLicenseUrl->onRestore(); + prefAuthor->onRestore(); + prefSetAuthorOnSave->onRestore(); + prefCompany->onRestore(); } /** @@ -97,4 +108,42 @@ void DlgSettingsDocumentImp::changeEvent(QEvent *e) } } +/** + * Set the correct URL depending on the license type + */ +void DlgSettingsDocumentImp::on_prefLicenseType_changed(int index) +{ + switch (index) { + case 0: + prefLicenseUrl->setText(QString::fromAscii("http://en.wikipedia.org/wiki/All_rights_reserved")); + break; + case 1: + prefLicenseUrl->setText(QString::fromAscii("http://creativecommons.org/licenses/by/4.0/")); + break; + case 2: + prefLicenseUrl->setText(QString::fromAscii("http://creativecommons.org/licenses/by-sa/4.0/")); + break; + case 3: + prefLicenseUrl->setText(QString::fromAscii("http://creativecommons.org/licenses/by-nd/4.0/")); + break; + case 4: + prefLicenseUrl->setText(QString::fromAscii("http://creativecommons.org/licenses/by-nc/4.0/")); + break; + case 5: + prefLicenseUrl->setText(QString::fromAscii("http://creativecommons.org/licenses/by-nc-sa/4.0/")); + break; + case 6: + prefLicenseUrl->setText(QString::fromAscii("http://creativecommons.org/licenses/by-nc-nd/4.0/")); + break; + case 7: + prefLicenseUrl->setText(QString::fromAscii("http://en.wikipedia.org/wiki/Public_domain")); + break; + case 8: + prefLicenseUrl->setText(QString::fromAscii("http://artlibre.org/licence/lal")); + break; + default: + prefLicenseUrl->setText(QString::fromAscii("")); + } +} + #include "moc_DlgSettingsDocumentImp.cpp" diff --git a/src/Gui/DlgSettingsDocumentImp.h b/src/Gui/DlgSettingsDocumentImp.h index 15785f450..3968ee650 100644 --- a/src/Gui/DlgSettingsDocumentImp.h +++ b/src/Gui/DlgSettingsDocumentImp.h @@ -45,6 +45,9 @@ public: void saveSettings(); void loadSettings(); + +protected Q_SLOTS: + void on_prefLicenseType_changed(int index); protected: void changeEvent(QEvent *e);