[gnote] Import from Tomboy on first startup. (Closes #578981)
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnote] Import from Tomboy on first startup. (Closes #578981)
- Date: Tue, 16 Jun 2009 03:21:24 -0400 (EDT)
commit a29813ad77f4ea848dcb13961996a15149baaed6
Author: Hubert Figuiere <hub figuiere net>
Date: Sun May 31 03:25:35 2009 -0400
Import from Tomboy on first startup. (Closes #578981)
NEWS | 2 +
configure.ac | 1 +
src/Makefile.am | 1 +
src/addinmanager.cpp | 14 +++-
src/addinmanager.hpp | 7 +-
src/addins/Makefile.am | 1 +
src/addins/tomboyimport/Makefile.am | 9 ++
src/addins/tomboyimport/tomboyimportaddin.cpp | 121 +++++++++++++++++++++++++
src/addins/tomboyimport/tomboyimportaddin.hpp | 74 +++++++++++++++
src/importaddin.cpp | 39 ++++++++
src/importaddin.hpp | 58 ++++++++++++
src/notemanager.cpp | 56 +++++++++++-
src/notemanager.hpp | 14 +++-
13 files changed, 387 insertions(+), 10 deletions(-)
---
diff --git a/NEWS b/NEWS
index 313c900..f5cf3b1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+ * Import from Tomboy on first startup. (Closes #578981)
+
0.5.0 -
New features:
diff --git a/configure.ac b/configure.ac
index 1f45f63..f91531f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -228,6 +228,7 @@ src/addins/fixedwidth/Makefile
src/addins/inserttimestamp/Makefile
src/addins/printnotes/Makefile
src/addins/stickynoteimport/Makefile
+src/addins/tomboyimport/Makefile
po/Makefile.in
po/Makefile
help/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index f23036c..b2a353a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -106,6 +106,7 @@ libgnote_a_SOURCES = \
applicationaddin.hpp \
contrast.hpp contrast.cpp \
debug.hpp debug.cpp \
+ importaddin.hpp importaddin.cpp \
keybinder.hpp \
noteaddin.hpp noteaddin.cpp \
notebuffer.hpp notebuffer.cpp \
diff --git a/src/addinmanager.cpp b/src/addinmanager.cpp
index 2d8a719..0d42084 100644
--- a/src/addinmanager.cpp
+++ b/src/addinmanager.cpp
@@ -126,7 +126,12 @@ namespace gnote {
AddinPreferenceFactoryBase * factory = dynamic_cast<AddinPreferenceFactoryBase*>((*f)());
m_addin_prefs.insert(std::make_pair((*iter)->id(), factory));
}
-
+
+ f = dmod->query_interface(ImportAddin::IFACE_NAME);
+ if(f) {
+ ImportAddin * factory = dynamic_cast<ImportAddin*>((*f)());
+ m_import_addins.insert(std::make_pair((*iter)->id(), factory));
+ }
}
}
@@ -165,6 +170,13 @@ namespace gnote {
sharp::map_get_values(m_pref_tab_addins, l);
}
+
+ void AddinManager::get_import_addins(std::list<ImportAddin*> & l) const
+ {
+ sharp::map_get_values(m_import_addins, l);
+ }
+
+
Gtk::Widget * AddinManager::create_addin_preference_widget(const std::string & id)
{
IdAddinPrefsMap::const_iterator iter = m_addin_prefs.find(id);
diff --git a/src/addinmanager.hpp b/src/addinmanager.hpp
index 9a00b3c..2286a8e 100644
--- a/src/addinmanager.hpp
+++ b/src/addinmanager.hpp
@@ -18,8 +18,6 @@
*/
-
-
#ifndef __ADDINMANAGER_HPP__
#define __ADDINMANAGER_HPP__
@@ -32,6 +30,8 @@
#include "sharp/modulemanager.hpp"
#include "note.hpp"
#include "noteaddin.hpp"
+#include "importaddin.hpp"
+
namespace gnote {
@@ -49,6 +49,7 @@ public:
void load_addins_for_note(const Note::Ptr &);
void get_application_addins(std::list<ApplicationAddin*> &) const;
void get_preference_tab_addins(std::list<PreferenceTabAddin *> &) const;
+ void get_import_addins(std::list<ImportAddin*> &) const;
const sharp::ModuleList & get_modules() const
{
@@ -77,6 +78,8 @@ private:
IdInfoMap m_note_addin_infos;
typedef std::map<std::string, PreferenceTabAddin*> IdPrefTabAddinMap;
IdPrefTabAddinMap m_pref_tab_addins;
+ typedef std::map<std::string, ImportAddin *> IdImportAddinMap;
+ IdImportAddinMap m_import_addins;
typedef std::map<std::string, AddinPreferenceFactoryBase*> IdAddinPrefsMap;
IdAddinPrefsMap m_addin_prefs;
sigc::signal<void> m_application_addin_list_changed;
diff --git a/src/addins/Makefile.am b/src/addins/Makefile.am
index 045849d..7bbfbe2 100644
--- a/src/addins/Makefile.am
+++ b/src/addins/Makefile.am
@@ -8,4 +8,5 @@ SUBDIRS = backlinks \
inserttimestamp \
printnotes \
stickynoteimport \
+ tomboyimport \
$(NULL)
\ No newline at end of file
diff --git a/src/addins/tomboyimport/Makefile.am b/src/addins/tomboyimport/Makefile.am
new file mode 100644
index 0000000..31b043e
--- /dev/null
+++ b/src/addins/tomboyimport/Makefile.am
@@ -0,0 +1,9 @@
+
+include $(builddir)/../addins.mk
+
+addinsdir = $(ADDINSDIR)
+addins_LTLIBRARIES = tomboyimport.la
+
+
+tomboyimport_la_SOURCES = tomboyimportaddin.hpp tomboyimportaddin.cpp \
+ $(NULL)
diff --git a/src/addins/tomboyimport/tomboyimportaddin.cpp b/src/addins/tomboyimport/tomboyimportaddin.cpp
new file mode 100644
index 0000000..091b3b0
--- /dev/null
+++ b/src/addins/tomboyimport/tomboyimportaddin.cpp
@@ -0,0 +1,121 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+
+
+#include <glibmm/i18n.h>
+#include <glibmm/miscutils.h>
+
+#include "sharp/directory.hpp"
+#include "sharp/files.hpp"
+#include "debug.hpp"
+#include "note.hpp"
+#include "notemanager.hpp"
+#include "tomboyimportaddin.hpp"
+
+
+using gnote::Note;
+
+namespace tomboyimport {
+
+TomboyImportModule::TomboyImportModule()
+{
+ ADD_INTERFACE_IMPL(TomboyImportAddin);
+}
+const char * TomboyImportModule::id() const
+{
+ return "TomboyImportAddin";
+}
+const char * TomboyImportModule::name() const
+{
+ return _("Tomboy Importer");
+}
+const char * TomboyImportModule::description() const
+{
+ return _("Import your notes from Tomboy.");
+}
+const char * TomboyImportModule::authors() const
+{
+ return _("Hubert Figuiere");
+}
+const char * TomboyImportModule::category() const
+{
+ return "Tools";
+}
+const char * TomboyImportModule::version() const
+{
+ return "0.1";
+}
+
+
+
+void TomboyImportAddin::initialize()
+{
+ m_tomboy_path =
+ Glib::build_filename(Glib::get_home_dir(), ".tomboy");
+
+ m_initialized = true;
+}
+
+
+void TomboyImportAddin::shutdown()
+{
+ m_initialized = false;
+}
+
+
+bool TomboyImportAddin::want_to_run()
+{
+ return sharp::directory_exists(m_tomboy_path);
+}
+
+
+bool TomboyImportAddin::first_run(gnote::NoteManager & manager)
+{
+ int to_import = 0;
+ int imported = 0;
+ bool success;
+
+ DBG_OUT("import path is %s", m_tomboy_path.c_str());
+
+ if(sharp::directory_exists(m_tomboy_path)) {
+ std::list<std::string> files;
+ sharp::directory_get_files_with_ext(m_tomboy_path, ".note", files);
+
+ for(std::list<std::string>::const_iterator iter = files.begin();
+ iter != files.end(); ++iter) {
+ const std::string & file_path(*iter);
+
+ to_import++;
+
+ Note::Ptr note = manager.import_note(file_path);
+
+ if(note) {
+ DBG_OUT("success");
+ success = true;
+ imported++;
+ }
+ }
+ }
+
+ return success;
+}
+
+
+}
diff --git a/src/addins/tomboyimport/tomboyimportaddin.hpp b/src/addins/tomboyimport/tomboyimportaddin.hpp
new file mode 100644
index 0000000..9a6783a
--- /dev/null
+++ b/src/addins/tomboyimport/tomboyimportaddin.hpp
@@ -0,0 +1,74 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+
+
+#ifndef __TOMBOY_IMPORT_ADDIN_HPP_
+#define __TOMBOY_IMPORT_ADDIN_HPP_
+
+#include <string>
+
+#include "sharp/dynamicmodule.hpp"
+#include "importaddin.hpp"
+
+
+namespace tomboyimport {
+
+
+class TomboyImportModule
+ : public sharp::DynamicModule
+{
+public:
+ TomboyImportModule();
+ virtual const char * id() const;
+ virtual const char * name() const;
+ virtual const char * description() const;
+ virtual const char * authors() const;
+ virtual const char * category() const;
+ virtual const char * version() const;
+};
+
+
+DECLARE_MODULE(TomboyImportModule);
+
+class TomboyImportAddin
+ : public gnote::ImportAddin
+{
+public:
+
+ static TomboyImportAddin * create()
+ {
+ return new TomboyImportAddin;
+ }
+ virtual void initialize();
+ virtual void shutdown();
+ virtual bool want_to_run();
+ virtual bool first_run(gnote::NoteManager & manager);
+
+private:
+
+ std::string m_tomboy_path;
+};
+
+
+}
+
+
+#endif
+
diff --git a/src/importaddin.cpp b/src/importaddin.cpp
new file mode 100644
index 0000000..34da3bc
--- /dev/null
+++ b/src/importaddin.cpp
@@ -0,0 +1,39 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "importaddin.hpp"
+
+
+namespace gnote {
+
+ const char * ImportAddin::IFACE_NAME = "gnote::ImportAddin";
+
+ ImportAddin::ImportAddin()
+ : m_initialized(false)
+ {
+ }
+
+
+ bool ImportAddin::initialized ()
+ {
+ return m_initialized;
+ }
+
+}
diff --git a/src/importaddin.hpp b/src/importaddin.hpp
new file mode 100644
index 0000000..282e3d3
--- /dev/null
+++ b/src/importaddin.hpp
@@ -0,0 +1,58 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+
+
+#ifndef __IMPORT_ADDIN_HPP__
+#define __IMPORT_ADDIN_HPP__
+
+#include "applicationaddin.hpp"
+
+namespace gnote {
+
+class NoteManager;
+
+class ImportAddin
+ : public ApplicationAddin
+{
+public:
+ static const char * IFACE_NAME;
+
+ ImportAddin();
+
+ virtual bool initialized();
+
+ /** Return whether the importer want to run at startup or not
+ */
+ virtual bool want_to_run() = 0;
+ /** Run import during first run.
+ * @param manager the NoteManager to import into.
+ * @return true in case of success.
+ */
+ virtual bool first_run(gnote::NoteManager & manager) = 0;
+
+protected:
+ bool m_initialized;
+};
+
+
+}
+
+
+#endif
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 3be1fbe..6ed8976 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -119,6 +119,23 @@ namespace gnote {
m_addin_mgr = create_addin_manager ();
if (is_first_run) {
+ std::list<ImportAddin*> l;
+ m_addin_mgr->get_import_addins(l);
+ bool has_imported = false;
+
+ if(l.empty()) {
+ DBG_OUT("no import plugins");
+ }
+
+ for(std::list<ImportAddin*>::iterator iter = l.begin();
+ iter != l.end(); ++iter) {
+
+ DBG_OUT("importing");
+ (*iter)->initialize();
+ has_imported |= (*iter)->first_run(*this);
+ (*iter)->shutdown();
+ }
+
// First run. Create "Start Here" notes.
create_start_notes ();
}
@@ -264,6 +281,16 @@ namespace gnote {
e.what());
}
}
+
+
+ void NoteManager::add_note(const Note::Ptr & note)
+ {
+ if (note) {
+ note->signal_renamed().connect(sigc::mem_fun(*this, &NoteManager::on_note_rename));
+ note->signal_saved().connect(sigc::mem_fun(*this, &NoteManager::on_note_save));
+ m_notes.push_back(note);
+ }
+ }
void NoteManager::load_notes()
{
@@ -275,11 +302,7 @@ namespace gnote {
const std::string & file_path(*iter);
try {
Note::Ptr note = Note::load(file_path, *this);
- if (note) {
- note->signal_renamed().connect(sigc::mem_fun(*this, &NoteManager::on_note_rename));
- note->signal_saved().connect(sigc::mem_fun(*this, &NoteManager::on_note_save));
- m_notes.push_back(note);
- }
+ add_note(note);
}
catch (const std::exception & e) {
ERR_OUT("Error parsing note XML, skipping \"%s\": %s",
@@ -460,6 +483,29 @@ namespace gnote {
return create_new_note(title, xml_content, "");
}
+ Note::Ptr NoteManager::import_note(const std::string & file_path)
+ {
+ std::string dest_file = Glib::build_filename(m_notes_dir,
+ sharp::file_filename(file_path));
+
+ if(sharp::file_exists(dest_file)) {
+ dest_file = make_new_file_name();
+ }
+ Note::Ptr note;
+ try {
+ sharp::file_copy(file_path, dest_file);
+
+ // TODO: make sure the title IS unique.
+ note = Note::load(dest_file, *this);
+ add_note(note);
+ }
+ catch(...)
+ {
+ }
+ return note;
+ }
+
+
Note::Ptr NoteManager::create_with_guid (const std::string & title, std::string & guid)
{
return create_new_note(title, guid);
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index 711dfff..57dfe88 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -66,8 +66,14 @@ namespace gnote {
{
return *m_addin_mgr;
}
+ const std::string & get_notes_dir() const
+ {
+ return m_notes_dir;
+ }
const std::string & start_note_uri() const
- { return m_start_note_uri; }
+ {
+ return m_start_note_uri;
+ }
Note::Ptr find(const std::string &) const;
Note::Ptr find_by_uri(const std::string &) const;
void delete_note(const Note::Ptr & note);
@@ -75,6 +81,9 @@ namespace gnote {
Note::Ptr create();
Note::Ptr create(const std::string & title);
Note::Ptr create(const std::string & title, const std::string & xml_content);
+ // Import a note read from file_path
+ // Will ensure the sanity including the unique title.
+ Note::Ptr import_note(const std::string & file_path);
Note::Ptr create_with_guid(const std::string & title, std::string & guid);
Note::Ptr get_or_create_template_note();
static std::string get_note_template_content(const std::string & title);
@@ -107,7 +116,8 @@ namespace gnote {
Note::Ptr create_new_note (std::string title, const std::string & guid);
Note::Ptr create_new_note (const std::string & title, const std::string & xml_content,
const std::string & guid);
-
+ /** add the note to the manager and setup signals */
+ void add_note(const Note::Ptr &);
void _common_init(const std::string & directory, const std::string & backup);
std::string m_notes_dir;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]