[gnote] Add ReadOnly add-in



commit 880a949feb008cac07d9e59dd618169065a7efdb
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Fri Aug 23 00:28:13 2013 +0300

    Add ReadOnly add-in
    
    Thanks Debarshi Ray.
    Fixes Bug 588807.

 configure.ac                              |    1 +
 po/POTFILES.in                            |    2 +
 src/addins/Makefile.am                    |    1 +
 src/addins/readonly/Makefile.am           |   19 +++++
 src/addins/readonly/readonly.desktop.in   |    9 ++
 src/addins/readonly/readonlynoteaddin.cpp |  125 +++++++++++++++++++++++++++++
 src/addins/readonly/readonlynoteaddin.hpp |   59 ++++++++++++++
 7 files changed, 216 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ce7d7ec..457b37a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -178,6 +178,7 @@ src/addins/inserttimestamp/Makefile
 src/addins/notedirectorywatcher/Makefile
 src/addins/noteoftheday/Makefile
 src/addins/printnotes/Makefile
+src/addins/readonly/Makefile
 src/addins/replacetitle/Makefile
 src/addins/specialnotes/Makefile
 src/addins/statistics/Makefile
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fb77163..ef6dbba 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -25,6 +25,8 @@ src/addins/noteoftheday/noteoftheday.desktop.in
 src/addins/noteoftheday/noteofthedaypreferences.cpp
 src/addins/printnotes/printnotes.desktop.in
 src/addins/printnotes/printnotesnoteaddin.cpp
+src/addins/readonly/readonly.desktop.in
+src/addins/readonly/readonlynoteaddin.cpp
 src/addins/replacetitle/replacetitle.desktop.in
 src/addins/replacetitle/replacetitlenoteaddin.cpp
 src/addins/specialnotes/specialnotes.desktop.in
diff --git a/src/addins/Makefile.am b/src/addins/Makefile.am
index 52ef422..4f785c8 100644
--- a/src/addins/Makefile.am
+++ b/src/addins/Makefile.am
@@ -10,6 +10,7 @@ SUBDIRS = backlinks \
        notedirectorywatcher \
        noteoftheday \
        printnotes \
+       readonly \
        replacetitle \
        specialnotes \
        statistics \
diff --git a/src/addins/readonly/Makefile.am b/src/addins/readonly/Makefile.am
new file mode 100644
index 0000000..8d326ce
--- /dev/null
+++ b/src/addins/readonly/Makefile.am
@@ -0,0 +1,19 @@
+
+include $(builddir)/../addins.mk
+
+ INTLTOOL_DESKTOP_RULE@
+
+desktop_in_files = readonly.desktop.in
+desktop_files    = $(desktop_in_files:.desktop.in=.desktop)
+
+addinsdir = $(ADDINSDIR)
+addins_LTLIBRARIES = readonly.la
+addins_DATA = $(desktop_files)
+
+readonly_la_SOURCES = \
+       readonlynoteaddin.hpp \
+       readonlynoteaddin.cpp \
+       $(NULL)
+
+EXTRA_DIST = $(desktop_in_files)
+DISTCLEANFILES = $(desktop_files)
diff --git a/src/addins/readonly/readonly.desktop.in b/src/addins/readonly/readonly.desktop.in
new file mode 100644
index 0000000..626b256
--- /dev/null
+++ b/src/addins/readonly/readonly.desktop.in
@@ -0,0 +1,9 @@
+[AddinInfo]
+Id=ReadOnlyAddin
+_Name=Read Only
+_Description=Mark certain notes as read only
+_Authors=Aurimas Černius, Debarshi Ray and Arief Bayu Purwanto
+Category=Tools
+Version=0.1
+DefaultEnabled=false
+Module=readonly
diff --git a/src/addins/readonly/readonlynoteaddin.cpp b/src/addins/readonly/readonlynoteaddin.cpp
new file mode 100644
index 0000000..fef35e1
--- /dev/null
+++ b/src/addins/readonly/readonlynoteaddin.cpp
@@ -0,0 +1,125 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2010 Debarshi Ray
+ *
+ * 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 <gtkmm/checkmenuitem.h>
+
+#include "itagmanager.hpp"
+#include "notewindow.hpp"
+#include "readonlynoteaddin.hpp"
+#include "tag.hpp"
+
+
+namespace {
+  class ReadOnlyAction
+    : public Gtk::Action
+  {
+  public:
+    typedef Glib::RefPtr<ReadOnlyAction> Ptr;
+    static Ptr create()
+      {
+        return Ptr(new ReadOnlyAction);
+      }
+    bool checked() const
+      {
+        return m_checked;
+      }
+  protected:
+    virtual Gtk::Widget *create_menu_item_vfunc() override
+    {
+      return new Gtk::CheckMenuItem;
+    }
+    virtual void on_activate() override
+    {
+      m_checked = !m_checked;
+      Gtk::Action::on_activate();
+    }
+  private:
+    ReadOnlyAction()
+      : Gtk::Action("ReadOnlyAction")
+      , m_checked(false)
+    {
+      set_label(_("Read Only"));
+      set_tooltip(_("Make this note read-only"));
+    }
+
+    bool m_checked;
+  };
+}
+
+
+namespace readonly {
+
+DECLARE_MODULE(ReadOnlyModule);
+
+ReadOnlyModule::ReadOnlyModule()
+  : sharp::DynamicModule()
+{
+  ADD_INTERFACE_IMPL(ReadOnlyNoteAddin);
+  enabled(false);
+}
+
+
+ReadOnlyNoteAddin::ReadOnlyNoteAddin()
+  : NoteAddin()
+{
+}
+
+ReadOnlyNoteAddin::~ReadOnlyNoteAddin()
+{
+}
+
+void ReadOnlyNoteAddin::initialize()
+{
+}
+
+void ReadOnlyNoteAddin::shutdown()
+{
+}
+
+void ReadOnlyNoteAddin::on_note_opened()
+{
+  m_action = ReadOnlyAction::create();
+  add_note_action(m_action, 700);
+  m_action->signal_activate().connect(
+    sigc::mem_fun(*this, &ReadOnlyNoteAddin::on_menu_item_toggled));
+
+  gnote::ITagManager & m = gnote::ITagManager::obj();
+  const gnote::Tag::Ptr ro_tag = m.get_or_create_system_tag("read-only");
+  if(get_note()->contains_tag(ro_tag)) {
+    //m_item->set_active(true);
+  }
+}
+
+void ReadOnlyNoteAddin::on_menu_item_toggled()
+{
+  gnote::ITagManager & m = gnote::ITagManager::obj();
+  const gnote::Tag::Ptr ro_tag = m.get_or_create_system_tag("read-only");
+  if(ReadOnlyAction::Ptr::cast_dynamic(m_action)->checked()) {
+    get_window()->editor()->set_editable(false);
+    get_note()->add_tag(ro_tag);
+  }
+  else {
+    get_window()->editor()->set_editable(true);
+    get_note()->remove_tag(ro_tag);
+  }
+}
+
+}
diff --git a/src/addins/readonly/readonlynoteaddin.hpp b/src/addins/readonly/readonlynoteaddin.hpp
new file mode 100644
index 0000000..e346004
--- /dev/null
+++ b/src/addins/readonly/readonlynoteaddin.hpp
@@ -0,0 +1,59 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2010 Debarshi Ray
+ *
+ * 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 __READ_ONLY_NOTE_ADDIN_HPP_
+#define __READ_ONLY_NOTE_ADDIN_HPP_
+
+#include "base/macros.hpp"
+#include "sharp/dynamicmodule.hpp"
+#include "noteaddin.hpp"
+
+namespace readonly {
+
+class ReadOnlyModule
+  : public sharp::DynamicModule
+{
+public:
+  ReadOnlyModule();
+};
+
+class ReadOnlyNoteAddin
+  : public gnote::NoteAddin
+{
+public:
+  static ReadOnlyNoteAddin * create()
+    {
+      return new ReadOnlyNoteAddin;
+    }
+
+  virtual ~ReadOnlyNoteAddin();
+  virtual void initialize() override;
+  virtual void shutdown() override;
+  virtual void on_note_opened() override;
+private:
+  ReadOnlyNoteAddin();
+  void on_menu_item_toggled();
+
+  Glib::RefPtr<Gtk::Action> m_action;
+};
+
+}
+
+#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]