[gnome-builder/wip/loganek/libidemm] libidemm: add example C++ plugin



commit cd622e78cc55d9f3cba59c35378bb62fd6a37146
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Wed Apr 6 22:54:28 2016 +0200

    libidemm: add example C++ plugin

 configure.ac                                  |    2 +
 plugins/Makefile.am                           |    1 +
 plugins/hello-cpp/Makefile.am                 |   23 +++++++++
 plugins/hello-cpp/configure.ac                |   24 ++++++++++
 plugins/hello-cpp/hello-cpp.plugin            |    7 +++
 plugins/hello-cpp/hellocppapplicationaddin.cc |   61 +++++++++++++++++++++++++
 plugins/hello-cpp/hellocppapplicationaddin.h  |   50 ++++++++++++++++++++
 plugins/hello-cpp/hellocppplugin.cc           |   35 ++++++++++++++
 8 files changed, 203 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c5b8414..9687869 100644
--- a/configure.ac
+++ b/configure.ac
@@ -255,6 +255,7 @@ m4_include([plugins/gcc/configure.ac])
 m4_include([plugins/gettext/configure.ac])
 m4_include([plugins/git/configure.ac])
 m4_include([plugins/gnome-code-assistance/configure.ac])
+m4_include([plugins/hello-cpp/configure.ac])
 m4_include([plugins/html-completion/configure.ac])
 m4_include([plugins/html-preview/configure.ac])
 m4_include([plugins/jedi/configure.ac])
@@ -543,6 +544,7 @@ echo "  Global File Search ................... : ${enable_file_search_plugin}"
 echo "  GNOME Code Assistance ................ : ${enable_gnome_code_assistance_plugin}"
 echo "  HTML Autocompletion .................. : ${enable_html_completion_plugin}"
 echo "  HTML and Markdown Preview ............ : ${enable_html_preview_plugin}"
+echo "  Example C++.............. ............ : ${enable_hello_cpp_plugin}"
 echo "  JHBuild .............................. : ${enable_jhbuild_plugin}"
 echo "  MinGW ................................ : ${enable_mingw_plugin}"
 echo "  Project Creation ..................... : ${enable_create_project_plugin}"
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 2b08472..d04e7c4 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -15,6 +15,7 @@ SUBDIRS = \
        gettext \
        git \
        gnome-code-assistance \
+       hello-cpp \
        html-completion \
        html-preview \
        jedi \
diff --git a/plugins/hello-cpp/Makefile.am b/plugins/hello-cpp/Makefile.am
new file mode 100644
index 0000000..44eb253
--- /dev/null
+++ b/plugins/hello-cpp/Makefile.am
@@ -0,0 +1,23 @@
+if ENABLE_HELLO_CPP_PLUGIN
+
+EXTRA_DIST = $(plugin_DATA)
+
+plugindir = $(libdir)/gnome-builder/plugins
+plugin_LTLIBRARIES = libhello-cpp-plugin.la
+dist_plugin_DATA = hello-cpp.plugin
+
+libhello_cpp_plugin_la_SOURCES = \
+       hellocppapplicationaddin.cc \
+       hellocppapplicationaddin.h \
+       hellocppplugin.cc \
+       registermmtype.h \
+       $(NULL)
+
+libhello_cpp_plugin_la_CPPFLAGS = $(GTKMM_CFLAGS) $(PLUGIN_CFLAGS) -I$(top_srcdir)/libidemm
+libhello_cpp_plugin_la_LDFLAGS = $(GTKMM_LIBS) $(PLUGIN_LDFLAGS) -L$(top_srcdir)/libidemm/idemm/.libs 
-lidemm-1.0
+
+include $(top_srcdir)/plugins/Makefile.plugin
+
+endif
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/hello-cpp/configure.ac b/plugins/hello-cpp/configure.ac
new file mode 100644
index 0000000..13adff2
--- /dev/null
+++ b/plugins/hello-cpp/configure.ac
@@ -0,0 +1,24 @@
+m4_define([gtkmm_required_version], [3.18.0])
+
+# --enable-hello-cpp-plugin=yes/no
+AC_ARG_ENABLE([hello-cpp-plugin],
+              [AS_HELP_STRING([--enable-hello-cpp-plugin=@<:@yes/no@:>@],
+                              [Build example C++ plugin with gtkmm.])],
+              [enable_hello_cpp_plugin=$enableval],
+              [enable_hello_cpp_plugin=auto])
+
+AS_IF([test x$enable_hello_cpp_plugin != x$no],[
+       PKG_CHECK_MODULES(GTKMM,
+                         [gtkmm-3.0 >= gtkmm_required_version],
+                         [have_gtkmm=yes],
+                         [have_gtkmm=no])
+
+       AS_IF([test x$enable_hello_cpp_plugin = xyes && x$have_gtkmm = xno],[
+              AC_MSG_ERROR([--enable-hello-cpp-plugin requires gtkmm-3.0 >= gtkmm_required_version])
+       ])
+
+       enable_hello_cpp_plugin=$have_gtkmm
+])
+
+AM_CONDITIONAL(ENABLE_HELLO_CPP_PLUGIN, test x$enable_hello_cpp_plugin = xyes)
+AC_CONFIG_FILES([plugins/hello-cpp/Makefile])
diff --git a/plugins/hello-cpp/hello-cpp.plugin b/plugins/hello-cpp/hello-cpp.plugin
new file mode 100644
index 0000000..2b537a3
--- /dev/null
+++ b/plugins/hello-cpp/hello-cpp.plugin
@@ -0,0 +1,7 @@
+[Plugin]
+Module=hello-cpp-plugin
+Name=Example C++ plugin
+Description=Plugin measures time you spent in the Builder application. Plugin can be used as a template for 
another C++ plugins.
+Authors=Marcin Kolny <marcin kolny gmail com>
+Copyright=Copyright © 2016 Marcin Kolny
+Builtin=true
diff --git a/plugins/hello-cpp/hellocppapplicationaddin.cc b/plugins/hello-cpp/hellocppapplicationaddin.cc
new file mode 100644
index 0000000..720c847
--- /dev/null
+++ b/plugins/hello-cpp/hellocppapplicationaddin.cc
@@ -0,0 +1,61 @@
+/* hellocppapplicationaddin.cc
+ *
+ * Copyright (C) 2016 Marcin Kolny <marcin kolny gmail com>
+ *
+ * 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 "hellocppapplicationaddin.h"
+
+#include <gtkmm/application.h>
+#include <gtkmm/messagedialog.h>
+#include <gtkmm/main.h>
+
+#include <glib/gi18n.h>
+
+#include <iostream>
+#include <cstdio>
+namespace Ide {
+namespace Plugin {
+
+HelloCppApplicationAddin::HelloCppApplicationAddin(GObject *gobj)
+  : Glib::ObjectBase(typeid(HelloCppApplicationAddin)),
+    Glib::Object(gobj),
+    Ide::ApplicationAddin()
+{
+  Gtk::Main::init_gtkmm_internals();
+  Ide::wrap_init();
+}
+
+  void HelloCppApplicationAddin::load_vfunc(const Glib::RefPtr<Ide::Application>& application)
+{
+  using namespace std::chrono;
+
+  application->signal_shutdown().connect([this] {
+      auto stop = steady_clock::now();
+      auto elapsed_seconds = duration_cast<seconds>(stop - start).count();
+      std::string message = _("Wow! You've spent with Builder ") + std::to_string(elapsed_seconds) + _(" 
seconds!");
+      Gtk::MessageDialog(message).run();
+    });
+
+  start = std::chrono::steady_clock::now();
+}
+
+  void HelloCppApplicationAddin::unload_vfunc(const Glib::RefPtr<Ide::Application>& application)
+{
+  std::cout << "Unloading application" << std::endl;
+}
+
+}
+}
diff --git a/plugins/hello-cpp/hellocppapplicationaddin.h b/plugins/hello-cpp/hellocppapplicationaddin.h
new file mode 100644
index 0000000..992f14a
--- /dev/null
+++ b/plugins/hello-cpp/hellocppapplicationaddin.h
@@ -0,0 +1,50 @@
+/* hellocppapplicationaddin.h
+ *
+ * Copyright (C) 2016 Marcin Kolny <marcin kolny gmail com>
+ *
+ * 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 _IDE_PLUGIN_HELLOCPPAPPLICATIONADDIN_H
+#define _IDE_PLUGIN_HELLOCPPAPPLICATIONADDIN_H
+
+#include <idemm.h>
+
+#include <chrono>
+
+namespace Ide {
+namespace Plugin {
+
+class HelloCppApplicationAddin : public Glib::Object, public Ide::ApplicationAddin
+{
+private:
+  std::chrono::time_point<std::chrono::steady_clock> start;
+
+public:
+  typedef GObject BaseObjectType;
+  typedef Glib::Object_Class CppClassType;
+  typedef Glib::Object::BaseClassType BaseClassType;
+
+  static GType get_base_type() { return Glib::Object::get_base_type(); }
+  
+  explicit HelloCppApplicationAddin(GObject *gobj);
+
+  void load_vfunc(const Glib::RefPtr<Ide::Application>& application) override;
+  void unload_vfunc(const Glib::RefPtr<Ide::Application>& application) override;
+};
+
+}
+}
+
+#endif
diff --git a/plugins/hello-cpp/hellocppplugin.cc b/plugins/hello-cpp/hellocppplugin.cc
new file mode 100644
index 0000000..c659bb6
--- /dev/null
+++ b/plugins/hello-cpp/hellocppplugin.cc
@@ -0,0 +1,35 @@
+/* hellocppplugin.cc
+ *
+ * Copyright (C) 2016 Marcin Kolny <marcin kolny gmail com>
+ *
+ * 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 <idemm/registermmtype.h>
+
+#include "hellocppapplicationaddin.h"
+
+#include <libpeas/peas.h>
+
+G_BEGIN_DECLS
+
+void
+peas_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              Ide::ApplicationAddin::get_base_type(),
+                                              Ide::register_mm_type<Ide::Plugin::HelloCppApplicationAddin, 
Ide::ApplicationAddin>("HelloCppApplicationAddin"));
+}
+
+G_END_DECLS


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