Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project save functionality #8

Merged
merged 9 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ list(APPEND SRC_FILES
src/gui/statusbar
src/gui/storytree
src/gui/treetoolbar
src/project/project
src/project/storyitem
src/project/storymodel
src/data
src/guimain
src/main
src/settings
Expand Down
64 changes: 47 additions & 17 deletions i18n/collett_en_US.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>Collett::CollettStoryModel</name>
<message>
<location filename="../src/project/storymodel.cpp" line="40"/>
<source>Title</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storymodel.cpp" line="40"/>
<source>Words</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::GuiMain</name>
<message>
<location filename="../src/guimain.cpp" line="63"/>
<location filename="../src/guimain.cpp" line="67"/>
<source>%1 %2 Version %3</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::GuiMainToolBar</name>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="39"/>
<location filename="../src/gui/maintoolbar.cpp" line="41"/>
<source>No Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="42"/>
<location filename="../src/gui/maintoolbar.cpp" line="66"/>
<source>New Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="69"/>
<source>Open Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="72"/>
<source>Save Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="76"/>
<source>Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="46"/>
<location filename="../src/gui/maintoolbar.cpp" line="48"/>
<source>Menu</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -53,6 +55,34 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::Project</name>
<message>
<location filename="../src/project/project.cpp" line="75"/>
<location filename="../src/project/project.cpp" line="87"/>
<source>Project not found at: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/project.cpp" line="102"/>
<location filename="../src/project/project.cpp" line="110"/>
<source>Could not create folder: %1</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::StoryModel</name>
<message>
<location filename="../src/project/storymodel.cpp" line="154"/>
<source>Label</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storymodel.cpp" line="158"/>
<source>Words</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>main</name>
<message>
Expand Down
64 changes: 47 additions & 17 deletions i18n/collett_nb_NO.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="nb_NO">
<context>
<name>Collett::CollettStoryModel</name>
<message>
<location filename="../src/project/storymodel.cpp" line="40"/>
<source>Title</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storymodel.cpp" line="40"/>
<source>Words</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::GuiMain</name>
<message>
<location filename="../src/guimain.cpp" line="63"/>
<location filename="../src/guimain.cpp" line="67"/>
<source>%1 %2 Version %3</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::GuiMainToolBar</name>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="39"/>
<location filename="../src/gui/maintoolbar.cpp" line="41"/>
<source>No Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="42"/>
<location filename="../src/gui/maintoolbar.cpp" line="66"/>
<source>New Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="69"/>
<source>Open Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="72"/>
<source>Save Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="76"/>
<source>Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/maintoolbar.cpp" line="46"/>
<location filename="../src/gui/maintoolbar.cpp" line="48"/>
<source>Menu</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -53,6 +55,34 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::Project</name>
<message>
<location filename="../src/project/project.cpp" line="75"/>
<location filename="../src/project/project.cpp" line="87"/>
<source>Project not found at: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/project.cpp" line="102"/>
<location filename="../src/project/project.cpp" line="110"/>
<source>Could not create folder: %1</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::StoryModel</name>
<message>
<location filename="../src/project/storymodel.cpp" line="154"/>
<source>Label</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storymodel.cpp" line="158"/>
<source>Words</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>main</name>
<message>
Expand Down
12 changes: 12 additions & 0 deletions sample/data/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"meta": {
"created": "2021-12-04T16:18:21",
"updated": "2021-12-04T16:18:23"
},
"project": {
"bookTitle": "New Project",
"projectName": "New Project"
},
"settings": {
}
}
17 changes: 17 additions & 0 deletions sample/data/story.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"handle": "ROOT",
"xItems": [
{
"handle": "b32008d7-5b44-43a6-ace3-a7343b2ad496",
"label": "Title Page",
"order": 0,
"wCount": 0
},
{
"handle": "ff608d47-2fac-4d48-9a9c-13d787bc76c2",
"label": "Chapter 1",
"order": 1,
"wCount": 0
}
]
}
2 changes: 2 additions & 0 deletions sample/project.collett
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Collett 0.0.1-alpha0
Project 0.1
7 changes: 7 additions & 0 deletions src/collett.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define COL_VERSION_NUM 0x000001a0
#define COL_VERSION_DATE "2021-11-14"

#define COL_PROJECT_FILE_NAME "project.collett"
#define COL_SETTINGS_FILE_NAME "project.json"
#define COL_STORY_FILE_NAME "story.json"
#define COL_NOTES_FILE_NAME "notes.json"

#define COL_STORY_TREE_COL_COUNT 2

#endif // COLLETT_H
118 changes: 118 additions & 0 deletions src/data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
Collett – Core Data Class
=========================

This file is a part of Collett
Copyright 2020–2021, Veronica Berglyd Olsen

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "data.h"
#include "project.h"
#include "storymodel.h"

#include <QWidget>
#include <QDir>

namespace Collett {

/*
Private Class Declaration
=========================
*/

class CollettDataPrivate
{
public:
static CollettData *instance;

CollettDataPrivate() {};
~CollettDataPrivate() {
qDebug() << "Deconstructing: CollettDataPrivate";
delete m_project;
};

Project *m_project;

bool m_hasProject = false;
};

/*
Public Class Contruction/Deconstruction
=======================================
*/

CollettData *CollettDataPrivate::instance = nullptr;

CollettData *CollettData::instance() {
if (CollettDataPrivate::instance == nullptr) {
CollettDataPrivate::instance = new CollettData();
qDebug() << "CollettData instance created";
}
return CollettDataPrivate::instance;
}

CollettData::CollettData() : d_ptr(new CollettDataPrivate()) {
Q_D(CollettData);
}

CollettData::~CollettData() {}

/*
Public Class Methods
====================
*/

bool CollettData::openProject(const QString &path) {
Q_D(CollettData);

d->m_project = new Project(path);
bool status = d->m_project->openProject();
d->m_hasProject = d->m_project->hasProject();

return status;
}

bool CollettData::saveProject() {
Q_D(CollettData);

if (d->m_hasProject) {
return d->m_project->saveProject();
} else {
return false;
}
}

Project *CollettData::project() {
Q_D(CollettData);

if (d->m_hasProject) {
return d->m_project;
} else {
return nullptr;
}
}

StoryModel *CollettData::storyModel() {
Q_D(CollettData);

if (d->m_hasProject) {
return d->m_project->storyModel();
} else {
return nullptr;
}
}

} // namespace Collett
Loading