welcome view: add logo and text explaning Ring

It also shows the RingID if a RING account exists.

This replaces the empty "placeholder" view.

Issue: #80846
Change-Id: Ia42684d2ca0c2613416dd131625b5a83c3faeb78
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2a4b485..379e510 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -249,6 +249,8 @@
    src/editcontactview.cpp
    src/native/dbuserrorhandler.h
    src/native/dbuserrorhandler.cpp
+   src/ringwelcomeview.h
+   src/ringwelcomeview.cpp
 )
 
 # compile glib resource files to c code
diff --git a/src/ringmainwindow.cpp b/src/ringmainwindow.cpp
index c1f50ce..6d9de36 100644
--- a/src/ringmainwindow.cpp
+++ b/src/ringmainwindow.cpp
@@ -64,6 +64,7 @@
 #include "generalsettingsview.h"
 #include "callsview.h"
 #include "utils/accounts.h"
+#include "ringwelcomeview.h"
 
 static constexpr const char* CALL_VIEW_NAME             = "calls";
 static constexpr const char* CREATE_ACCOUNT_1_VIEW_NAME = "create1";
@@ -72,7 +73,7 @@
 static constexpr const char* AUDIO_SETTINGS_VIEW_NAME   = "audio";
 static constexpr const char* MEDIA_SETTINGS_VIEW_NAME   = "media";
 static constexpr const char* ACCOUNT_SETTINGS_VIEW_NAME = "accounts";
-static constexpr const char* DEFAULT_VIEW_NAME          = "placeholder";
+static constexpr const char* DEFAULT_VIEW_NAME          = "welcome";
 static constexpr const char* VIEW_CONTACTS              = "contacts";
 static constexpr const char* VIEW_HISTORY               = "history";
 static constexpr const char* VIEW_PRESENCE              = "presence";
@@ -181,8 +182,6 @@
         g_free(new_call_view_name);
     } else {
         /* nothing selected in the call model, so show the default screen */
-
-        /* TODO: replace stack paceholder view */
         gtk_stack_set_transition_type(GTK_STACK(priv->stack_call_view), GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT);
         gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_call_view), DEFAULT_VIEW_NAME);
         gtk_stack_set_transition_type(GTK_STACK(priv->stack_call_view), GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT);
@@ -872,10 +871,9 @@
     auto history_view = history_view_new();
     gtk_container_add(GTK_CONTAINER(priv->scrolled_window_history), history_view);
 
-    /* TODO: replace stack paceholder view */
-    GtkWidget *placeholder_view = gtk_tree_view_new();
-    gtk_widget_show(placeholder_view);
-    gtk_stack_add_named(GTK_STACK(priv->stack_call_view), placeholder_view, DEFAULT_VIEW_NAME);
+    /* welcome/default view */
+    auto welcome_view = ring_welcome_view_new();
+    gtk_stack_add_named(GTK_STACK(priv->stack_call_view), welcome_view, DEFAULT_VIEW_NAME);
 
     /* connect signals */
     GtkTreeSelection *call_selection = calls_view_get_selection(CALLS_VIEW(calls_view));
diff --git a/src/ringwelcomeview.cpp b/src/ringwelcomeview.cpp
new file mode 100644
index 0000000..fe2763e
--- /dev/null
+++ b/src/ringwelcomeview.cpp
@@ -0,0 +1,178 @@
+/*
+ *  Copyright (C) 2015 Savoir-faire Linux Inc.
+ *  Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#include "ringwelcomeview.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include "utils/accounts.h"
+#include <account.h>
+#include <accountmodel.h>
+
+struct _RingWelcomeView
+{
+    GtkBox parent;
+};
+
+struct _RingWelcomeViewClass
+{
+    GtkBoxClass parent_class;
+};
+
+typedef struct _RingWelcomeViewPrivate RingWelcomeViewPrivate;
+
+struct _RingWelcomeViewPrivate
+{
+    QMetaObject::Connection ringaccount_updated;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(RingWelcomeView, ring_welcome_view, GTK_TYPE_BOX);
+
+#define RING_WELCOME_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_WELCOME_VIEW_TYPE, RingWelcomeViewPrivate))
+
+static void
+show_ring_id(GtkLabel *label, Account *account) {
+    g_return_if_fail(label);
+
+    if (account) {
+        if (!account->username().isEmpty()) {
+            QString hash = "<span fgcolor=\"black\">" + account->username() + "</span>";
+            gtk_label_set_markup(label, hash.toUtf8().constData());
+        } else {
+            g_warning("got ring account, but Ring id is empty");
+            gtk_label_set_markup(label,
+                                 g_strdup_printf("<span fgcolor=\"gray\">%s</span>",
+                                                 _("fetching RingID...")));
+        }
+    }
+}
+
+static void
+ring_welcome_view_init(RingWelcomeView *self)
+{
+    RingWelcomeViewPrivate *priv = RING_WELCOME_VIEW_GET_PRIVATE(self);
+
+    gtk_orientable_set_orientation(GTK_ORIENTABLE(self), GTK_ORIENTATION_VERTICAL);
+    gtk_box_set_spacing(GTK_BOX(self), 15);
+    gtk_box_set_baseline_position(GTK_BOX(self), GTK_BASELINE_POSITION_CENTER);
+    gtk_widget_set_vexpand(GTK_WIDGET(self), TRUE);
+    gtk_widget_set_hexpand(GTK_WIDGET(self), FALSE);
+    gtk_widget_set_valign(GTK_WIDGET(self), GTK_ALIGN_CENTER);
+    gtk_widget_set_halign(GTK_WIDGET(self), GTK_ALIGN_CENTER);
+
+    /* get logo */
+    GError *error = NULL;
+    GdkPixbuf* logo = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-logo-blue",
+                                                            350, -1, TRUE, &error);
+    if (logo == NULL) {
+        g_debug("Could not load logo: %s", error->message);
+        g_clear_error(&error);
+    } else {
+        auto image_ring_logo = gtk_image_new_from_pixbuf(logo);
+        gtk_box_pack_start(GTK_BOX(self), image_ring_logo, FALSE, TRUE, 0);
+    }
+
+    /* welcome text */
+    auto label_welcome_text = gtk_label_new(_("Ring is a secure and distributed voice, video, and chat communication platform that requires no centralized server and leaves the power of privacy in the hands of the user."));
+    gtk_label_set_justify(GTK_LABEL(label_welcome_text), GTK_JUSTIFY_CENTER);
+    gtk_widget_override_font(label_welcome_text, pango_font_description_from_string("12"));
+    gtk_label_set_line_wrap(GTK_LABEL(label_welcome_text), TRUE);
+    /* the max width chars is to limit how much the text expands */
+    gtk_label_set_max_width_chars(GTK_LABEL(label_welcome_text), 50);
+    gtk_label_set_selectable(GTK_LABEL(label_welcome_text), TRUE);
+    gtk_box_pack_start(GTK_BOX(self), label_welcome_text, FALSE, TRUE, 0);
+
+    /* RingID explanation */
+    auto explanation = g_strdup_printf("<span fgcolor=\"gray\">%s</span>",
+                                       C_("Do not translate \"RingID\"", "This is your RingID.\nCopy and share it with your friends!"));
+    auto label_explanation = gtk_label_new(NULL);
+    gtk_label_set_markup(GTK_LABEL(label_explanation), explanation);
+    gtk_label_set_justify(GTK_LABEL(label_explanation), GTK_JUSTIFY_CENTER);
+    gtk_label_set_selectable(GTK_LABEL(label_explanation), TRUE);
+    gtk_widget_set_margin_top(label_explanation, 20);
+    g_free(explanation);
+    /* we migth need to hide the label if a RING account doesn't exist */
+    gtk_widget_set_no_show_all(label_explanation, TRUE);
+    gtk_box_pack_start(GTK_BOX(self), label_explanation, FALSE, TRUE, 0);
+
+    /* RingID label */
+    auto label_ringid = gtk_label_new(NULL);
+    gtk_label_set_selectable(GTK_LABEL(label_ringid), TRUE);
+    gtk_widget_override_font(label_ringid, pango_font_description_from_string("monospace 12"));
+    show_ring_id(GTK_LABEL(label_ringid), get_active_ring_account());
+    gtk_widget_set_no_show_all(label_ringid, TRUE);
+    gtk_box_pack_start(GTK_BOX(self), label_ringid, FALSE, TRUE, 0);
+
+    if (get_active_ring_account()) {
+        gtk_widget_show(label_explanation);
+        gtk_widget_show(label_ringid);
+    }
+
+    priv-> ringaccount_updated = QObject::connect(
+        AccountModel::instance(),
+        &AccountModel::dataChanged,
+        [label_explanation, label_ringid] () {
+            /* check if the active ring account has changed,
+             * eg: if it was deleted */
+            auto account = get_active_ring_account();
+            show_ring_id(GTK_LABEL(label_ringid), get_active_ring_account());
+            if (account) {
+                 gtk_widget_show(label_explanation);
+                 gtk_widget_show(label_ringid);
+            } else {
+                gtk_widget_hide(label_explanation);
+                gtk_widget_hide(label_ringid);
+            }
+        }
+    );
+
+    gtk_widget_show_all(GTK_WIDGET(self));
+}
+
+static void
+ring_welcome_view_dispose(GObject *object)
+{
+    RingWelcomeView *self = RING_WELCOME_VIEW(object);
+    RingWelcomeViewPrivate *priv = RING_WELCOME_VIEW_GET_PRIVATE(self);
+
+    QObject::disconnect(priv->ringaccount_updated);
+
+    G_OBJECT_CLASS(ring_welcome_view_parent_class)->dispose(object);
+}
+
+static void
+ring_welcome_view_finalize(GObject *object)
+{
+    G_OBJECT_CLASS(ring_welcome_view_parent_class)->finalize(object);
+}
+
+static void
+ring_welcome_view_class_init(RingWelcomeViewClass *klass)
+{
+    G_OBJECT_CLASS(klass)->finalize = ring_welcome_view_finalize;
+    G_OBJECT_CLASS(klass)->dispose = ring_welcome_view_dispose;
+}
+
+GtkWidget *
+ring_welcome_view_new()
+{
+    gpointer self = g_object_new(RING_WELCOME_VIEW_TYPE, NULL);
+
+    return (GtkWidget *)self;
+}
diff --git a/src/ringwelcomeview.h b/src/ringwelcomeview.h
new file mode 100644
index 0000000..d01c737
--- /dev/null
+++ b/src/ringwelcomeview.h
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (C) 2015 Savoir-faire Linux Inc.
+ *  Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define RING_WELCOME_VIEW_TYPE            (ring_welcome_view_get_type ())
+#define RING_WELCOME_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), RING_WELCOME_VIEW_TYPE, RingWelcomeView))
+#define RING_WELCOME_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), RING_WELCOME_VIEW_TYPE, RingWelcomeViewClass))
+#define IS_RING_WELCOME_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), RING_WELCOME_VIEW_TYPE))
+#define IS_RING_WELCOME_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), RING_WELCOME_VIEW_TYPE))
+
+typedef struct _RingWelcomeView      RingWelcomeView;
+typedef struct _RingWelcomeViewClass RingWelcomeViewClass;
+
+GType             ring_welcome_view_get_type (void) G_GNUC_CONST;
+GtkWidget        *ring_welcome_view_new      (void);
+
+G_END_DECLS