Skip to content

Commit

Permalink
Added preference setting to set default Author & License - fixes #1883
Browse files Browse the repository at this point in the history
* added fields in Prefereces->Default->Document
* new documents take the values of those fields
  • Loading branch information
yorikvanhavre committed Jan 20, 2015
1 parent 17a85e4 commit 645d176
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 26 deletions.
56 changes: 52 additions & 4 deletions src/App/Document.cpp
Expand Up @@ -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");
Expand All @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
234 changes: 212 additions & 22 deletions src/Gui/DlgSettingsDocument.ui
Expand Up @@ -6,14 +6,27 @@
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<height>423</height>
<width>500</width>
<height>593</height>
</rect>
</property>
<property name="windowTitle">
<string>Document</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="4" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>429</width>
<height>37</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="GroupBox5">
<property name="title">
Expand Down Expand Up @@ -92,10 +105,10 @@
<property name="text">
<string>Create new document at start up</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>CreateNewDoc</cstring>
</property>
<property name="prefPath" stdset="0">
Expand Down Expand Up @@ -134,10 +147,10 @@
<property name="text">
<string>Using Undo/Redo on documents</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>UsingUndo</cstring>
</property>
<property name="prefPath" stdset="0">
Expand Down Expand Up @@ -293,30 +306,207 @@
</widget>
</item>
<item row="3" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>429</width>
<height>37</height>
</size>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Authoring and License</string>
</property>
</spacer>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Author name</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefLineEdit" name="prefAuthor">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The name to use on document creation.&lt;/p&gt;&lt;p&gt;Keep blank for anonymous.&lt;/p&gt;&lt;p&gt;You can also use the form:&lt;/p&gt;&lt;p&gt;John Doe &amp;lt;john@doe.com&amp;gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>prefAuthor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="prefSetAuthorOnSave">
<property name="toolTip">
<string>If this is checked, the &quot;Last modified by&quot; field will be set when saving the file</string>
</property>
<property name="text">
<string>Set on save</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>prefSetAuthorOnSave</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Company</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefLineEdit" name="prefCompany">
<property name="toolTip">
<string>The defautl company to use for new files</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>prefCompany</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Default license</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="prefLicenseType">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>The default license for new documents</string>
</property>
<property name="editable">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>prefLicenseType</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
<item>
<property name="text">
<string>All rights reserved</string>
</property>
</item>
<item>
<property name="text">
<string>CreativeCommons Attribution</string>
</property>
</item>
<item>
<property name="text">
<string>CreativeCommons Attribution-ShareAlike</string>
</property>
</item>
<item>
<property name="text">
<string>CreativeCommons Attribution-NoDerivatives</string>
</property>
</item>
<item>
<property name="text">
<string>CreativeCommons Attribution-NonCommercial</string>
</property>
</item>
<item>
<property name="text">
<string>CreativeCommons Attribution-NonCommercial-ShareAlike</string>
</property>
</item>
<item>
<property name="text">
<string>CreativeCommons Attribution-NonCommercial-NoDerivatives</string>
</property>
</item>
<item>
<property name="text">
<string>Public Domain</string>
</property>
</item>
<item>
<property name="text">
<string>FreeArt</string>
</property>
</item>
<item>
<property name="text">
<string>Other</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>License URL</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefLineEdit" name="prefLicenseUrl">
<property name="toolTip">
<string>An URL where the user can find more details about the license</string>
</property>
<property name="text">
<string>http://en.wikipedia.org/wiki/All_rights_reserved</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>prefLicenseUrl</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<class>Gui::PrefComboBox</class>
<extends>QComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefLineEdit</class>
<extends>QLineEdit</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
Expand Down

0 comments on commit 645d176

Please sign in to comment.