[gnome-control-center/wip/hadess/degraded-power-profile: 1/2] power: Add new power profile info row widget




commit a5b4218061002270ce8202355007c6a4db0c6f59
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jul 15 14:39:58 2021 +0200

    power: Add new power profile info row widget

 panels/power/cc-power-panel.c             |   1 +
 panels/power/cc-power-profile-info-row.c  | 125 +++++++++++++++++++++++++
 panels/power/cc-power-profile-info-row.h  |  36 +++++++
 panels/power/cc-power-profile-info-row.ui |  57 ++++++++++++
 panels/power/icons/info-symbolic.svg      | 150 ++++++++++++++++++++++++++++++
 panels/power/icons/meson.build            |   5 +
 panels/power/meson.build                  |   1 +
 panels/power/power.gresource.xml          |   1 +
 8 files changed, 376 insertions(+)
---
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index 5d57afe59..8acf62dee 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -35,6 +35,7 @@
 #include "cc-battery-row.h"
 #include "cc-brightness-scale.h"
 #include "cc-power-profile-row.h"
+#include "cc-power-profile-info-row.h"
 #include "cc-power-panel.h"
 #include "cc-power-resources.h"
 #include "cc-util.h"
diff --git a/panels/power/cc-power-profile-info-row.c b/panels/power/cc-power-profile-info-row.c
new file mode 100644
index 000000000..d981c4d81
--- /dev/null
+++ b/panels/power/cc-power-profile-info-row.c
@@ -0,0 +1,125 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* cc-list-row.c
+ *
+ * Copyright 2020 Red Hat Inc.
+ *
+ * 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/>.
+ *
+ * Author(s):
+ *   Bastien Nocera <hadess hadess net>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "cc-power-profile-info-row"
+
+#include <config.h>
+
+#include <glib/gi18n.h>
+#include "cc-power-profile-info-row.h"
+
+struct _CcPowerProfileInfoRow
+{
+  GtkListBoxRow parent_instance;
+
+  GtkLabel       *title_label;
+};
+
+G_DEFINE_TYPE (CcPowerProfileInfoRow, cc_power_profile_info_row, GTK_TYPE_LIST_BOX_ROW)
+
+#if 0
+static void
+performance_profile_set_inhibited (CcPowerProfileInfoRow *self,
+                                   const char        *performance_inhibited)
+{
+  const char *text;
+  gboolean inhibited = FALSE;
+
+  if (self->power_profile != CC_POWER_PROFILE_PERFORMANCE)
+    return;
+
+  gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (self->subtitle_label)),
+                                  GTK_STYLE_CLASS_DIM_LABEL);
+  gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (self->subtitle_label)),
+                                  GTK_STYLE_CLASS_ERROR);
+
+  text = get_performance_inhibited_text (performance_inhibited);
+  if (text)
+    inhibited = TRUE;
+  else
+    text = _("High performance and power usage.");
+  gtk_label_set_text (GTK_LABEL (self->subtitle_label), text);
+
+  gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self->subtitle_label)),
+                               inhibited ? GTK_STYLE_CLASS_ERROR : GTK_STYLE_CLASS_DIM_LABEL);
+  gtk_widget_set_sensitive (GTK_WIDGET (self), !inhibited);
+}
+#endif
+static void
+cc_power_profile_info_row_class_init (CcPowerProfileInfoRowClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/power/cc-power-profile-info-row.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, CcPowerProfileInfoRow, title_label);
+}
+
+static void
+cc_power_profile_info_row_init (CcPowerProfileInfoRow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+CcPowerProfileInfoRow *
+cc_power_profile_info_row_new (const char *text)
+{
+  CcPowerProfileInfoRow *self;
+
+  self = g_object_new (CC_TYPE_POWER_PROFILE_INFO_ROW, NULL);
+#if 0
+  self->power_profile = power_profile;
+  switch (self->power_profile)
+    {
+      case CC_POWER_PROFILE_PERFORMANCE:
+        text = _("Performance");
+        subtext = _("High performance and power usage.");
+        icon_name = "power-profile-performance-symbolic";
+        class_name = "performance";
+        break;
+      case CC_POWER_PROFILE_BALANCED:
+        text = _("Balanced Power");
+        subtext = _("Standard performance and power usage.");
+        icon_name = "power-profile-balanced-symbolic";
+        class_name = NULL;
+        break;
+      case CC_POWER_PROFILE_POWER_SAVER:
+        text = _("Power Saver");
+        subtext = _("Reduced performance and power usage.");
+        icon_name = "power-profile-power-saver-symbolic";
+        class_name = "low-power";
+        break;
+      default:
+        g_assert_not_reached ();
+    }
+#endif
+  gtk_label_set_markup (self->title_label, text);
+//  gtk_label_set_markup (self->subtitle_label, subtext);
+//  gtk_image_set_from_icon_name (self->icon_image, icon_name, GTK_ICON_SIZE_MENU);
+//  if (class_name != NULL)
+//    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self->icon_image)), class_name);
+
+  return self;
+}
diff --git a/panels/power/cc-power-profile-info-row.h b/panels/power/cc-power-profile-info-row.h
new file mode 100644
index 000000000..52d055ab2
--- /dev/null
+++ b/panels/power/cc-power-profile-info-row.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* cc-list-row.h
+ *
+ * Copyright 2020 Red Hat Inc
+ *
+ * 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/>.
+ *
+ * Author(s):
+ *   Bastien Nocera <hadess hadess net>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_POWER_PROFILE_INFO_ROW (cc_power_profile_info_row_get_type())
+G_DECLARE_FINAL_TYPE (CcPowerProfileInfoRow, cc_power_profile_info_row, CC, POWER_PROFILE_INFO_ROW, 
GtkListBoxRow)
+
+CcPowerProfileInfoRow *cc_power_profile_info_row_new           (const char *text);
+
+G_END_DECLS
diff --git a/panels/power/cc-power-profile-info-row.ui b/panels/power/cc-power-profile-info-row.ui
new file mode 100644
index 000000000..3fc654623
--- /dev/null
+++ b/panels/power/cc-power-profile-info-row.ui
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="CcPowerProfileInfoRow" parent="GtkListBoxRow">
+    <property name="selectable">False</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="orientation">horizontal</property>
+        <property name="margin-start">12</property>
+        <property name="margin-end">12</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="margin-top">8</property>
+            <property name="margin-bottom">8</property>
+            <child>
+              <object class="GtkImage" id="icon_image">
+                <property name="visible">True</property>
+                <property name="margin-start">6</property>
+                <property name="margin-end">18</property>
+                <property name="icon-name">info-symbolic</property>
+                <property name="icon-size">5</property>
+                <style>
+                  <class name="power-profile"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="title_label">
+                <property name="visible">True</property>
+                <property name="halign">start</property>
+                <property name="expand">True</property>
+                <property name="use-markup">True</property>
+                <property name="use-underline">True</property>
+                <property name="xalign">0</property>
+                <property name="yalign">0.5</property>
+                <property name="margin-end">6</property>
+                <property name="wrap">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
+
diff --git a/panels/power/icons/info-symbolic.svg b/panels/power/icons/info-symbolic.svg
new file mode 100644
index 000000000..502a98a50
--- /dev/null
+++ b/panels/power/icons/info-symbolic.svg
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg height="16px" viewBox="0 0 16 16" width="16px" xmlns="http://www.w3.org/2000/svg"; 
xmlns:xlink="http://www.w3.org/1999/xlink";>
+    <filter id="a" height="100%" width="100%" x="0%" y="0%">
+        <feColorMatrix in="SourceGraphic" type="matrix" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
+    </filter>
+    <mask id="b">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.3"/>
+        </g>
+    </mask>
+    <clipPath id="c">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="d">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/>
+        </g>
+    </mask>
+    <clipPath id="e">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="f">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/>
+        </g>
+    </mask>
+    <clipPath id="g">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="h">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/>
+        </g>
+    </mask>
+    <clipPath id="i">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="j">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/>
+        </g>
+    </mask>
+    <clipPath id="k">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="l">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/>
+        </g>
+    </mask>
+    <clipPath id="m">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="n">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.05"/>
+        </g>
+    </mask>
+    <clipPath id="o">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="p">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.3"/>
+        </g>
+    </mask>
+    <clipPath id="q">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="r">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.5"/>
+        </g>
+    </mask>
+    <clipPath id="s">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="t">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.4"/>
+        </g>
+    </mask>
+    <clipPath id="u">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="v">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.4"/>
+        </g>
+    </mask>
+    <clipPath id="w">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="x">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.5"/>
+        </g>
+    </mask>
+    <clipPath id="y">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <mask id="z">
+        <g filter="url(#a)">
+            <path d="m 0 0 h 16 v 16 h -16 z" fill-opacity="0.5"/>
+        </g>
+    </mask>
+    <clipPath id="A">
+        <path d="m 0 0 h 1024 v 800 h -1024 z"/>
+    </clipPath>
+    <g clip-path="url(#c)" mask="url(#b)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 562.460938 212.058594 h 10.449218 c -1.183594 0.492187 -1.296875 2.460937 0 3 h 
-10.449218 z m 0 0" fill="#2e3436"/>
+    </g>
+    <path d="m 7.90625 1 c -3.828125 0.050781 -6.90625 3.171875 -6.90625 7 c 0 3.867188 3.132812 7 7 7 s 7 
-3.132812 7 -7 s -3.132812 -7 -7 -7 c -0.03125 0 -0.0625 0 -0.09375 0 z m -0.40625 3 h 1 c 0.277344 0 0.5 
0.222656 0.5 0.5 v 1 c 0 0.277344 -0.222656 0.5 -0.5 0.5 h -1 c -0.277344 0 -0.5 -0.222656 -0.5 -0.5 v -1 c 0 
-0.277344 0.222656 -0.5 0.5 -0.5 z m -0.5 3 h 2 v 5 h -2 z m 0 0" fill="#2e3436"/>
+    <g clip-path="url(#e)" mask="url(#d)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 16 632 h 1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/>
+    </g>
+    <g clip-path="url(#g)" mask="url(#f)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 17 631 h 1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/>
+    </g>
+    <g clip-path="url(#i)" mask="url(#h)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 18 634 h 1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/>
+    </g>
+    <g clip-path="url(#k)" mask="url(#j)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 16 634 h 1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/>
+    </g>
+    <g clip-path="url(#m)" mask="url(#l)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 17 635 h 1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/>
+    </g>
+    <g clip-path="url(#o)" mask="url(#n)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 19 635 h 1 v 1 h -1 z m 0 0" fill="#2e3436" fill-rule="evenodd"/>
+    </g>
+    <g clip-path="url(#q)" mask="url(#p)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 136 660 v 7 h 7 v -7 z m 0 0" fill="#2e3436"/>
+    </g>
+    <g clip-path="url(#s)" mask="url(#r)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 199 642 h 3 v 12 h -3 z m 0 0" fill="#2e3436"/>
+    </g>
+    <g clip-path="url(#u)" mask="url(#t)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 209.5 144.160156 c 0.277344 0 0.5 0.222656 0.5 0.5 v 1 c 0 0.277344 -0.222656 0.5 -0.5 
0.5 s -0.5 -0.222656 -0.5 -0.5 v -1 c 0 -0.277344 0.222656 -0.5 0.5 -0.5 z m 0 0" fill="#2e3436"/>
+    </g>
+    <g clip-path="url(#w)" mask="url(#v)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 206.5 144.160156 c 0.277344 0 0.5 0.222656 0.5 0.5 v 1 c 0 0.277344 -0.222656 0.5 -0.5 
0.5 s -0.5 -0.222656 -0.5 -0.5 v -1 c 0 -0.277344 0.222656 -0.5 0.5 -0.5 z m 0 0" fill="#2e3436"/>
+    </g>
+    <g clip-path="url(#y)" mask="url(#x)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 229.5 143.160156 c -0.546875 0 -1 0.457032 -1 1 c 0 0.546875 0.453125 1 1 1 s 1 -0.453125 
1 -1 c 0 -0.542968 -0.453125 -1 -1 -1 z m 0 0" fill="#2e3436"/>
+    </g>
+    <g clip-path="url(#A)" mask="url(#z)" transform="matrix(1 0 0 1 -660 -222)">
+        <path d="m 226.453125 143.160156 c -0.519531 0 -0.953125 0.433594 -0.953125 0.953125 v 0.09375 c 0 
0.519531 0.433594 0.953125 0.953125 0.953125 h 0.09375 c 0.519531 0 0.953125 -0.433594 0.953125 -0.953125 v 
-0.09375 c 0 -0.519531 -0.433594 -0.953125 -0.953125 -0.953125 z m 0 0" fill="#2e3436"/>
+    </g>
+</svg>
diff --git a/panels/power/icons/meson.build b/panels/power/icons/meson.build
index 8165371ea..c56bc65b7 100644
--- a/panels/power/icons/meson.build
+++ b/panels/power/icons/meson.build
@@ -13,3 +13,8 @@ foreach icon_size: icon_sizes
     install_dir: join_paths(control_center_icondir, 'hicolor', icon_size, 'apps')
   )
 endforeach
+
+install_data(
+  'info-symbolic.svg',
+  install_dir: join_paths(control_center_icondir, 'hicolor', 'scalable', 'status')
+)
diff --git a/panels/power/meson.build b/panels/power/meson.build
index 625059dd2..af04b98ed 100644
--- a/panels/power/meson.build
+++ b/panels/power/meson.build
@@ -22,6 +22,7 @@ sources = files(
   'cc-brightness-scale.c',
   'cc-power-panel.c',
   'cc-power-profile-row.c',
+  'cc-power-profile-info-row.c'
 )
 
 sources += gnome.mkenums_simple(
diff --git a/panels/power/power.gresource.xml b/panels/power/power.gresource.xml
index 31e92b415..5a33c8e60 100644
--- a/panels/power/power.gresource.xml
+++ b/panels/power/power.gresource.xml
@@ -4,6 +4,7 @@
     <file preprocess="xml-stripblanks">cc-battery-row.ui</file>
     <file preprocess="xml-stripblanks">cc-power-panel.ui</file>
     <file preprocess="xml-stripblanks">cc-power-profile-row.ui</file>
+    <file preprocess="xml-stripblanks">cc-power-profile-info-row.ui</file>
     <file>battery-levels.css</file>
     <file>power-profiles.css</file>
   </gresource>


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