[gnome-builder] greeter: add newcomer project button



commit 2750be2ad0c1570c0c0bdba79a8877c8ce74c745
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 10 00:14:18 2017 -0800

    greeter: add newcomer project button
    
    This is a helper to give us a reusable newcomer project button
    that will be displayed in the greeter. We still have some tweaks
    to do (like including the project language) but this gets us
    started on something.

 src/libide/greeter/ide-newcomer-project.c  |  164 ++++++++++++++++++++++++++++
 src/libide/greeter/ide-newcomer-project.h  |   33 ++++++
 src/libide/greeter/ide-newcomer-project.ui |   27 +++++
 src/libide/greeter/meson.build             |    2 +
 src/libide/libide.gresource.xml            |    1 +
 5 files changed, 227 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/greeter/ide-newcomer-project.c b/src/libide/greeter/ide-newcomer-project.c
new file mode 100644
index 0000000..baa4f88
--- /dev/null
+++ b/src/libide/greeter/ide-newcomer-project.c
@@ -0,0 +1,164 @@
+/* ide-newcomer-project.c
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat 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/>.
+ */
+
+#define G_LOG_DOMAIN "ide-newcomer-project"
+
+#include "ide-newcomer-project.h"
+
+struct _IdeNewcomerProject
+{
+  GtkBin    parent_instance;
+
+  gchar    *uri;
+
+  GtkLabel *label;
+  GtkImage *icon;
+};
+
+enum {
+  PROP_0,
+  PROP_ICON_NAME,
+  PROP_NAME,
+  PROP_URI,
+  N_PROPS
+};
+
+G_DEFINE_TYPE (IdeNewcomerProject, ide_newcomer_project, GTK_TYPE_BIN)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_newcomer_project_destroy (GtkWidget *widget)
+{
+  IdeNewcomerProject *self = IDE_NEWCOMER_PROJECT (widget);
+
+  g_clear_pointer (&self->uri, g_free);
+
+  GTK_WIDGET_CLASS (ide_newcomer_project_parent_class)->destroy (widget);
+}
+
+static void
+ide_newcomer_project_get_property (GObject    *object,
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+  IdeNewcomerProject *self = IDE_NEWCOMER_PROJECT (object);
+
+  switch (prop_id)
+    {
+    case PROP_URI:
+      g_value_set_string (value, ide_newcomer_project_get_uri (self));
+      break;
+
+    case PROP_NAME:
+      g_value_set_string (value, ide_newcomer_project_get_name (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_newcomer_project_set_property (GObject      *object,
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+  IdeNewcomerProject *self = IDE_NEWCOMER_PROJECT (object);
+
+  switch (prop_id)
+    {
+    case PROP_URI:
+      self->uri = g_value_dup_string (value);
+      break;
+
+    case PROP_NAME:
+      gtk_label_set_label (self->label, g_value_get_string (value));
+      break;
+
+    case PROP_ICON_NAME:
+      g_object_set (self->icon, "icon-name", g_value_get_string (value), NULL);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_newcomer_project_class_init (IdeNewcomerProjectClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->get_property = ide_newcomer_project_get_property;
+  object_class->set_property = ide_newcomer_project_set_property;
+
+  widget_class->destroy = ide_newcomer_project_destroy;
+
+  properties [PROP_ICON_NAME] =
+    g_param_spec_string ("icon-name",
+                         "Icon Name",
+                         "The icon to load",
+                         NULL,
+                         (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_NAME] =
+    g_param_spec_string ("name",
+                         "Name",
+                         "The name of the newcomer project",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_URI] =
+    g_param_spec_string ("uri",
+                         "Uri",
+                         "The URL of the project's source code repository",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/ui/ide-newcomer-project.ui");
+  gtk_widget_class_bind_template_child (widget_class, IdeNewcomerProject, label);
+  gtk_widget_class_bind_template_child (widget_class, IdeNewcomerProject, icon);
+}
+
+static void
+ide_newcomer_project_init (IdeNewcomerProject *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+const gchar *
+ide_newcomer_project_get_name (IdeNewcomerProject *self)
+{
+  g_return_val_if_fail (IDE_IS_NEWCOMER_PROJECT (self), NULL);
+
+  return self->label ? gtk_label_get_label (self->label) : NULL;
+}
+
+const gchar *
+ide_newcomer_project_get_uri (IdeNewcomerProject *self)
+{
+  g_return_val_if_fail (IDE_IS_NEWCOMER_PROJECT (self), NULL);
+
+  return self->uri;
+}
diff --git a/src/libide/greeter/ide-newcomer-project.h b/src/libide/greeter/ide-newcomer-project.h
new file mode 100644
index 0000000..8b52778
--- /dev/null
+++ b/src/libide/greeter/ide-newcomer-project.h
@@ -0,0 +1,33 @@
+/* ide-newcomer-project.h
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat 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/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_NEWCOMER_PROJECT (ide_newcomer_project_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeNewcomerProject, ide_newcomer_project, IDE, NEWCOMER_PROJECT, GtkBin)
+
+const gchar *ide_newcomer_project_get_name (IdeNewcomerProject *self);
+const gchar *ide_newcomer_project_get_uri  (IdeNewcomerProject *self);
+GIcon       *ide_newcomer_project_get_icon (IdeNewcomerProject *self);
+
+G_END_DECLS
diff --git a/src/libide/greeter/ide-newcomer-project.ui b/src/libide/greeter/ide-newcomer-project.ui
new file mode 100644
index 0000000..d7c2567
--- /dev/null
+++ b/src/libide/greeter/ide-newcomer-project.ui
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdeNewcomerProject" parent="GtkBin">
+    <property name="border-width">12</property>
+    <child>
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <property name="expand">true</property>
+        <property name="spacing">6</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="GtkImage" id="icon">
+            <property name="expand">true</property>
+            <property name="pixel-size">96</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label">
+            <property name="expand">true</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/libide/greeter/meson.build b/src/libide/greeter/meson.build
index 49c6073..574db12 100644
--- a/src/libide/greeter/meson.build
+++ b/src/libide/greeter/meson.build
@@ -3,6 +3,8 @@ greeter_private_sources = [
   'ide-greeter-perspective.h',
   'ide-greeter-project-row.c',
   'ide-greeter-project-row.h',
+  'ide-newcomer-project.c',
+  'ide-newcomer-project.h',
 ]
 
 libide_private_sources += files(greeter_private_sources)
diff --git a/src/libide/libide.gresource.xml b/src/libide/libide.gresource.xml
index bbcaba3..91c0ca3 100644
--- a/src/libide/libide.gresource.xml
+++ b/src/libide/libide.gresource.xml
@@ -76,6 +76,7 @@
     <file preprocess="xml-stripblanks" alias="ide-editor-view.ui">editor/ide-editor-view.ui</file>
     <file preprocess="xml-stripblanks" 
alias="ide-greeter-perspective.ui">greeter/ide-greeter-perspective.ui</file>
     <file preprocess="xml-stripblanks" 
alias="ide-greeter-project-row.ui">greeter/ide-greeter-project-row.ui</file>
+    <file preprocess="xml-stripblanks" alias="ide-newcomer-project.ui">greeter/ide-newcomer-project.ui</file>
     <file preprocess="xml-stripblanks" alias="ide-omni-bar.ui">workbench/ide-omni-bar.ui</file>
     <file preprocess="xml-stripblanks" 
alias="ide-omni-pausable-row.ui">workbench/ide-omni-pausable-row.ui</file>
     <file preprocess="xml-stripblanks" 
alias="ide-preferences-language-row.ui">preferences/ide-preferences-language-row.ui</file>


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