mirror of https://github.com/daleclack/My_GtkUi
Add addon apps view
This commit is contained in:
parent
e76866030d
commit
5c31df9695
|
@ -24,7 +24,8 @@ include_directories (${GTK_INCLUDE_DIRS})
|
|||
link_directories (${GTK_LIBRARY_DIRS})
|
||||
|
||||
set(SOURCES src/core/main.cpp src/core/MainWin.cpp src/core/MyStack.cpp
|
||||
src/ui/MyDock.cpp src/ui/MyFinder.cpp src/ui/MyPrefs.cpp)
|
||||
src/ui/MyDock.cpp src/ui/MyFinder.cpp src/ui/MyPrefs.cpp
|
||||
src/ui/AppView.cpp)
|
||||
|
||||
#Compile resources with GCR_CMake
|
||||
|
||||
|
|
|
@ -230,6 +230,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image8">
|
||||
<property name="hexpand">0</property>
|
||||
|
@ -262,6 +263,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image10">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -289,6 +291,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image9">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -316,6 +319,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image11">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -343,6 +347,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image12">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -370,6 +375,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image13">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -397,6 +403,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image14">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -424,6 +431,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image15">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -451,6 +459,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image16">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -478,6 +487,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image17">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -505,6 +515,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image18">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -532,6 +543,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image19">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -559,6 +571,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image20">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -586,6 +599,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image22">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -613,6 +627,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image24">
|
||||
<property name="pixel-size">48</property>
|
||||
|
@ -640,6 +655,7 @@
|
|||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image27">
|
||||
<property name="icon-name">mines_app</property>
|
||||
|
@ -880,6 +896,35 @@
|
|||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="hexpand">1</property>
|
||||
<property name="vexpand">1</property>
|
||||
<layout>
|
||||
<property name="column">0</property>
|
||||
<property name="row">1</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="hexpand">1</property>
|
||||
<property name="vexpand">1</property>
|
||||
<layout>
|
||||
<property name="column">2</property>
|
||||
<property name="row">1</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="height-request">10</property>
|
||||
<layout>
|
||||
<property name="column">2</property>
|
||||
<property name="row">3</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<layout>
|
||||
|
@ -900,9 +945,6 @@
|
|||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<layout>
|
||||
<property name="column">0</property>
|
||||
<property name="row">0</property>
|
||||
|
|
|
@ -7,28 +7,36 @@
|
|||
|
||||
/* @import url("resource://org/gtk/daleclack/reset.css"); */
|
||||
|
||||
.finder_style box{
|
||||
background-color:alpha(white,0.5);
|
||||
}
|
||||
|
||||
.dock_style grid{
|
||||
.finder_style box {
|
||||
background-color: alpha(white, 0.5);
|
||||
}
|
||||
|
||||
.dock_style box{
|
||||
.dock_style grid {
|
||||
background-color: alpha(white, 0.5);
|
||||
}
|
||||
|
||||
.dock_style box {
|
||||
background-color: alpha(white, 0.5);
|
||||
}
|
||||
|
||||
/* Background color in the box should be transparent*/
|
||||
.default_style box{
|
||||
.default_style box {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.default_style separator{
|
||||
.default_style separator {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.default_style grid{
|
||||
.default_style grid {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.default_style stackswitcher {
|
||||
color: transparent;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.default_style gridview{
|
||||
background-color: transparent;
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
#include "AppView.h"
|
||||
|
||||
// Create a model for application
|
||||
static GListModel *create_app_model()
|
||||
{
|
||||
GListStore *store;
|
||||
GList *apps, *temp;
|
||||
|
||||
// Create a list contains the application info
|
||||
store = g_list_store_new(G_TYPE_APP_INFO);
|
||||
|
||||
// Get Appication list
|
||||
apps = g_app_info_get_all();
|
||||
|
||||
// Append apps item to the list
|
||||
for (temp = apps; temp; temp = temp->next)
|
||||
{
|
||||
g_list_store_append(store, temp->data);
|
||||
}
|
||||
|
||||
g_list_free_full(apps, g_object_unref);
|
||||
|
||||
return G_LIST_MODEL(store);
|
||||
}
|
||||
|
||||
static void app_view_setup(GtkListItemFactory *factory, GtkListItem *item)
|
||||
{
|
||||
GtkWidget *app_box, *image, *label;
|
||||
|
||||
// Create widgets
|
||||
app_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
|
||||
image = gtk_image_new();
|
||||
label = gtk_label_new(" ");
|
||||
gtk_image_set_pixel_size(GTK_IMAGE(image), 40);
|
||||
gtk_widget_set_size_request(label, 76, 12);
|
||||
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
|
||||
|
||||
// Append widgets to the box
|
||||
gtk_box_append(GTK_BOX(app_box), image);
|
||||
gtk_box_append(GTK_BOX(app_box), label);
|
||||
|
||||
gtk_list_item_set_child(item, app_box);
|
||||
}
|
||||
|
||||
static void app_view_bind(GtkListItemFactory *factory, GtkListItem *item)
|
||||
{
|
||||
GtkWidget *image;
|
||||
GtkWidget *label;
|
||||
GAppInfo *app_info;
|
||||
|
||||
// Get Widgets
|
||||
image = gtk_widget_get_first_child(gtk_list_item_get_child(item));
|
||||
label = gtk_widget_get_next_sibling(image);
|
||||
app_info = G_APP_INFO(gtk_list_item_get_item(item));
|
||||
|
||||
// Initalize widgets
|
||||
GIcon *icon = g_app_info_get_icon(app_info);
|
||||
if(!icon)
|
||||
{
|
||||
gtk_image_set_from_icon_name(GTK_IMAGE(image), "application-x-executable");
|
||||
}else{
|
||||
gtk_image_set_from_gicon(GTK_IMAGE(image), g_app_info_get_icon(app_info));
|
||||
}
|
||||
gtk_label_set_label(GTK_LABEL(label), g_app_info_get_display_name(app_info));
|
||||
}
|
||||
|
||||
static void app_view_activate(GtkGridView *list, guint position, gpointer data)
|
||||
{
|
||||
GAppInfo *app_info;
|
||||
GdkAppLaunchContext *context;
|
||||
GError *error = NULL;
|
||||
|
||||
app_info = G_APP_INFO(g_list_model_get_item(G_LIST_MODEL(gtk_grid_view_get_model(list)),
|
||||
position));
|
||||
|
||||
/* Prepare the context for launching the application and launch it. This
|
||||
* code is explained in detail in the documentation for GdkAppLaunchContext
|
||||
* and GAppInfo.
|
||||
*/
|
||||
context = gdk_display_get_app_launch_context(gtk_widget_get_display(GTK_WIDGET(list)));
|
||||
if (!g_app_info_launch(app_info,
|
||||
NULL,
|
||||
G_APP_LAUNCH_CONTEXT(context),
|
||||
&error))
|
||||
{
|
||||
// GtkAlertDialog *dialog;
|
||||
|
||||
// /* And because error handling is important, even a simple demo has it:
|
||||
// * We display an error dialog that something went wrong.
|
||||
// */
|
||||
// dialog = gtk_alert_dialog_new("Could not launch %s", g_app_info_get_display_name(app_info));
|
||||
// gtk_alert_dialog_set_detail(dialog, error->message);
|
||||
// gtk_alert_dialog_show(dialog, GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(list))));
|
||||
// g_object_unref(dialog);
|
||||
// g_clear_error(&error);
|
||||
}
|
||||
|
||||
g_object_unref(context);
|
||||
g_object_unref(app_info);
|
||||
}
|
||||
|
||||
GtkWidget *app_view_new()
|
||||
{
|
||||
GtkWidget *list, *sw;
|
||||
GListModel *model;
|
||||
GtkListItemFactory *factory;
|
||||
|
||||
// Create widgets
|
||||
sw = gtk_scrolled_window_new();
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
|
||||
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
||||
|
||||
// Create list item factory
|
||||
factory = gtk_signal_list_item_factory_new();
|
||||
g_signal_connect(factory, "setup", G_CALLBACK(app_view_setup), NULL);
|
||||
g_signal_connect(factory, "bind", G_CALLBACK(app_view_bind), NULL);
|
||||
|
||||
// Create model and view
|
||||
model = create_app_model();
|
||||
list = gtk_grid_view_new(GTK_SELECTION_MODEL(
|
||||
gtk_single_selection_new(model)),
|
||||
factory);
|
||||
g_signal_connect(list, "activate", G_CALLBACK(app_view_activate), NULL);
|
||||
gtk_grid_view_set_min_columns(GTK_GRID_VIEW(list), 8);
|
||||
|
||||
// Add Child
|
||||
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), list);
|
||||
|
||||
return sw;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
GtkWidget *app_view_new();
|
|
@ -1,5 +1,6 @@
|
|||
#include "MyDock.h"
|
||||
#include "MyFinder.h"
|
||||
#include "AppView.h"
|
||||
|
||||
enum PadPage
|
||||
{
|
||||
|
@ -15,8 +16,9 @@ struct _MyDock
|
|||
GtkWidget *dock_box, *main_box, *finder_box,
|
||||
*dock_left, *icons_sw, *main_overlay; // Dock, finder
|
||||
GtkWidget *main_pic, *finder;
|
||||
GtkWidget *btnlaunch, *launchpad_stack, *default_page, // launchpad
|
||||
*launchpad_page, *apps_grid, *apps_stack, *default_box, *addon_box;
|
||||
GtkWidget *btnlaunch, *launchpad_stack, *default_page, *apps_grid, // launchpad
|
||||
*launchpad_page, *apps_stack, *default_box, *addon_box,
|
||||
*apps_switcher, *apps_view, *appgrid_box, *appgrid_label;
|
||||
GtkWidget *btnfiles, *btndraw, *btncalc, *btnedit, *btnimage, // Dock buttons
|
||||
*btnset, *btngame, *btngame24, *btnmine;
|
||||
GtkWidget *image_file, *image_draw, *image_calc, *image_game, // Image widget for dock buttons
|
||||
|
@ -256,7 +258,29 @@ static void my_dock_init(MyDock *self)
|
|||
my_finder_add_style(MY_FINDER(self->finder), provider);
|
||||
|
||||
// Add Apps grid
|
||||
gtk_box_append(GTK_BOX(self->default_box), self->apps_grid);
|
||||
|
||||
// To make the default view layout same as the addon apps view
|
||||
self->appgrid_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
|
||||
self->appgrid_label = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
|
||||
gtk_box_append(GTK_BOX(self->appgrid_box), self->appgrid_label);
|
||||
gtk_box_append(GTK_BOX(self->appgrid_box), self->apps_grid);
|
||||
gtk_box_append(GTK_BOX(self->default_box), self->appgrid_box);
|
||||
gtk_widget_set_halign(self->apps_grid, GTK_ALIGN_CENTER);
|
||||
gtk_grid_set_row_spacing(GTK_GRID(self->apps_grid), 20);
|
||||
|
||||
// Add Addon apps view
|
||||
self->apps_view = app_view_new();
|
||||
gtk_box_append(GTK_BOX(self->addon_box), self->apps_view);
|
||||
gtk_widget_set_halign(self->apps_view, GTK_ALIGN_CENTER);
|
||||
|
||||
// Add a switcher for the apps shown
|
||||
GtkWidget *child = gtk_grid_get_child_at(GTK_GRID(self->launchpad_page), 0, 0);
|
||||
self->apps_switcher = gtk_stack_switcher_new();
|
||||
gtk_stack_switcher_set_stack(GTK_STACK_SWITCHER(self->apps_switcher),
|
||||
GTK_STACK(self->apps_stack));
|
||||
gtk_widget_set_halign(self->apps_switcher, GTK_ALIGN_CENTER);
|
||||
gtk_widget_set_valign(self->apps_switcher, GTK_ALIGN_END);
|
||||
gtk_grid_attach(GTK_GRID(child), self->apps_switcher, 1, 2, 1, 1);
|
||||
|
||||
// Add Style to launchpad page
|
||||
gtk_widget_add_css_class(self->launchpad_page, "dock_style");
|
||||
|
@ -265,7 +289,6 @@ static void my_dock_init(MyDock *self)
|
|||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
// The widget in the launchpad page should use default style
|
||||
GtkWidget *child = gtk_grid_get_child_at(GTK_GRID(self->launchpad_page), 0, 0);
|
||||
gtk_widget_add_css_class(child, "default_style");
|
||||
gtk_style_context_add_provider_for_display(gtk_widget_get_display(child),
|
||||
GTK_STYLE_PROVIDER(provider),
|
||||
|
@ -282,6 +305,18 @@ static void my_dock_init(MyDock *self)
|
|||
gtk_style_context_add_provider_for_display(gtk_widget_get_display(self->dock_box),
|
||||
GTK_STYLE_PROVIDER(provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
// The widget in the dock should use default style
|
||||
gtk_widget_add_css_class(self->apps_switcher, "default_style");
|
||||
gtk_style_context_add_provider_for_display(gtk_widget_get_display(self->apps_switcher),
|
||||
GTK_STYLE_PROVIDER(provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
// The widget in the dock should use default style
|
||||
gtk_widget_add_css_class(self->apps_view, "default_style");
|
||||
gtk_style_context_add_provider_for_display(gtk_widget_get_display(self->apps_view),
|
||||
GTK_STYLE_PROVIDER(provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
}
|
||||
|
||||
static void my_dock_class_init(MyDockClass *klass)
|
||||
|
|
Loading…
Reference in New Issue