Enhancement: Fixes #180, Make winver less rubbish

This commit is contained in:
Rory Fewell
2024-12-08 01:53:03 +00:00
parent e3011c86f4
commit 0085270e93
23 changed files with 813 additions and 327 deletions

View File

@@ -13,6 +13,11 @@
#define WINTC_CTL_BUTTON_CSS_CLASS "wintc-button"
#define WINTC_CTL_MARGINB_SM_CSS_CLASS "wintc-mb-sm"
#define WINTC_CTL_MARGINL_SM_CSS_CLASS "wintc-ml-sm"
#define WINTC_CTL_MARGINR_SM_CSS_CLASS "wintc-mr-sm"
#define WINTC_CTL_MARGINT_SM_CSS_CLASS "wintc-mt-sm"
#define WINTC_CTL_MARGINB_MD_CSS_CLASS "wintc-mb-md"
#define WINTC_CTL_MARGINL_MD_CSS_CLASS "wintc-ml-md"
#define WINTC_CTL_MARGINR_MD_CSS_CLASS "wintc-mr-md"

View File

@@ -3,10 +3,17 @@
* Adwaita theme, to be overridden by the WinTC themes
*
* Default sizing¬
* sm: 2px
* md: 8px
* lg: 16px
*/
/** small **/
.wintc-mb-sm { margin-bottom: 2px; }
.wintc-ml-sm { margin-left: 2px; }
.wintc-mr-sm { margin-right: 2px; }
.wintc-mt-sm { margin-top: 2px; }
/** medium **/
.wintc-mb-md { margin-bottom: 8px; }
.wintc-ml-md { margin-left: 8px; }

View File

@@ -36,6 +36,8 @@ add_library(
src/application.c
public/application.h
public/assets.h
src/builder.c
public/builder.h
public/debug.h
src/container.c
public/container.h

View File

@@ -0,0 +1,33 @@
#ifndef __COMGTK_BUILDER_H__
#define __COMGTK_BUILDER_H__
#include <gtk/gtk.h>
//
// PUBLIC FUNCTIONS
//
/**
* Retrieve many items at once from a GtkBuilder.
*
* @param builder The builder instance.
* @param ... Object IDs and locations to store them, terminated by NULL.
*/
void wintc_builder_get_objects(
GtkBuilder* builder,
...
);
/**
* Rewrite a widget's label, assuming its existing label is a printf format
* string.
*
* @param widget The widget.
* @param ... The arguments to the printf.
*/
void wintc_widget_printf(
GtkWidget* widget,
...
);
#endif

View File

@@ -3,6 +3,7 @@
#include "@LIB_HEADER_DIR@/application.h"
#include "@LIB_HEADER_DIR@/assets.h"
#include "@LIB_HEADER_DIR@/builder.h"
#include "@LIB_HEADER_DIR@/container.h"
#include "@LIB_HEADER_DIR@/debug.h"
#include "@LIB_HEADER_DIR@/defprocs.h"

View File

@@ -0,0 +1,81 @@
#include <glib.h>
#include <gtk/gtk.h>
#include <stdarg.h>
#include "../public/builder.h"
//
// PUBLIC FUNCTIONS
//
void wintc_builder_get_objects(
GtkBuilder* builder,
...
)
{
va_list ap;
GtkWidget** next_dst;
gchar* next_name;
va_start(ap, builder);
next_name = va_arg(ap, gchar*);
while (next_name)
{
next_dst = va_arg(ap, GtkWidget**);
*next_dst = GTK_WIDGET(gtk_builder_get_object(builder, next_name));
next_name = va_arg(ap, gchar*);
}
va_end(ap);
}
void wintc_widget_printf(
GtkWidget* widget,
...
)
{
GObjectClass* object_class = G_OBJECT_GET_CLASS(widget);
const gchar* property = NULL;
if (g_object_class_find_property(object_class, "label"))
{
property = "label";
}
else if (g_object_class_find_property(object_class, "title"))
{
property = "title";
}
else
{
g_critical("Widget does not support printf: %p", widget);
return;
}
// Perform the printf
//
va_list ap;
gchar* format_string = NULL;
gchar* new_str;
va_start(ap, widget);
g_object_get(
widget,
property, &format_string,
NULL
);
new_str = g_strdup_vprintf(format_string, ap);
g_object_set(
widget,
property, new_str,
NULL
);
va_end(ap);
g_free(format_string);
g_free(new_str);
}

View File

@@ -24,11 +24,13 @@ include(../../packaging/cmake-inc/resources/CMakeLists.txt)
wintc_resolve_library(gdk-pixbuf-2.0 GDK_PIXBUF)
wintc_resolve_library(glib-2.0 GLIB)
wintc_resolve_library(gtk+-3.0 GTK3)
wintc_resolve_library(wintc-comctl WINTC_COMCTL)
wintc_resolve_library(wintc-comgtk WINTC_COMGTK)
wintc_resolve_library(wintc-exec WINTC_EXEC)
wintc_resolve_library(wintc-shcommon WINTC_SHCOMMON)
wintc_resolve_library(wintc-shellext WINTC_SHELLEXT)
wintc_resolve_library(wintc-shlang WINTC_SHLANG)
wintc_resolve_library(wintc-winbrand WINTC_WINBRAND)
wintc_compile_resources()
@@ -38,6 +40,8 @@ add_library(
public/browser.h
src/cpl.c
public/cpl.h
src/dialog.c
public/dialog.h
src/error.c
public/error.h
src/icnvwbeh.c
@@ -76,11 +80,13 @@ target_include_directories(
PRIVATE ${GDK_PIXBUF_INCLUDE_DIRS}
PRIVATE ${GLIB_INCLUDE_DIRS}
PRIVATE ${GTK3_INCLUDE_DIRS}
PRIVATE ${WINTC_COMCTL_INCLUDE_DIRS}
PRIVATE ${WINTC_COMGTK_INCLUDE_DIRS}
PRIVATE ${WINTC_EXEC_INCLUDE_DIRS}
PRIVATE ${WINTC_SHCOMMON_INCLUDE_DIRS}
PRIVATE ${WINTC_SHELLEXT_INCLUDE_DIRS}
PRIVATE ${WINTC_SHLANG_INCLUDE_DIRS}
PRIVATE ${WINTC_WINBRAND_INCLUDE_DIRS}
)
target_link_directories(
@@ -88,11 +94,13 @@ target_link_directories(
PRIVATE ${GDK_PIXBUF_LIBRARY_DIRS}
PRIVATE ${GLIB_LIBRARY_DIRS}
PRIVATE ${GTK3_LIBRARY_DIRS}
PRIVATE ${WINTC_COMCTL_LIBRARY_DIRS}
PRIVATE ${WINTC_COMGTK_LIBRARY_DIRS}
PRIVATE ${WINTC_EXEC_LIBRARY_DIRS}
PRIVATE ${WINTC_SHCOMMON_LIBRARY_DIRS}
PRIVATE ${WINTC_SHELLEXT_LIBRARY_DIRS}
PRIVATE ${WINTC_SHLANG_LIBRARY_DIRS}
PRIVATE ${WINTC_WINBRAND_LIBRARY_DIRS}
)
target_link_libraries(
@@ -100,11 +108,13 @@ target_link_libraries(
PRIVATE ${GDK_PIXBUF_LIBRARIES}
PRIVATE ${GLIB_LIBRARIES}
PRIVATE ${GTK3_LIBRARIES}
PRIVATE ${WINTC_COMCTL_LIBRARIES}
PRIVATE ${WINTC_COMGTK_LIBRARIES}
PRIVATE ${WINTC_EXEC_LIBRARIES}
PRIVATE ${WINTC_SHCOMMON_LIBRARIES}
PRIVATE ${WINTC_SHELLEXT_LIBRARIES}
PRIVATE ${WINTC_SHLANG_LIBRARIES}
PRIVATE ${WINTC_WINBRAND_LIBRARIES}
)
# Installation

View File

@@ -0,0 +1,17 @@
#ifndef __SHELL_DIALOG_H__
#define __SHELL_DIALOG_H__
#include <glib.h>
#include <gtk/gtk.h>
//
// PUBLIC FUNCTIONS
//
void wintc_sh_about(
GtkWindow* parent_wnd,
const gchar* app_name,
const gchar* other_stuff,
const gchar* icon_name
);
#endif

View File

@@ -3,6 +3,7 @@
#include "@LIB_HEADER_DIR@/browser.h"
#include "@LIB_HEADER_DIR@/cpl.h"
#include "@LIB_HEADER_DIR@/dialog.h"
#include "@LIB_HEADER_DIR@/error.h"
#include "@LIB_HEADER_DIR@/icnvwbeh.h"
#include "@LIB_HEADER_DIR@/nmspace.h"

193
shared/shell/src/dialog.c Normal file
View File

@@ -0,0 +1,193 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include <pwd.h>
#include <unistd.h>
#include <wintc/comctl.h>
#include <wintc/comgtk.h>
#include <wintc/shlang.h>
#include <wintc/winbrand.h>
#include "../public/dialog.h"
//
// FORWARD DECLARATIONS
//
static void action_sh_about_ok(
GSimpleAction* action,
GVariant* parameter,
gpointer user_data
);
//
// PUBLIC FUNCTIONS
//
void wintc_sh_about(
GtkWindow* parent_wnd,
const gchar* app_name,
WINTC_UNUSED(const gchar* other_stuff),
const gchar* icon_name
)
{
static const GActionEntry k_actions[] = {
{
.name = "ok",
.activate = action_sh_about_ok,
.parameter_type = NULL,
.state = NULL,
.change_state = NULL
}
};
// Instance dialog from builder
//
GtkBuilder* builder;
GtkWidget* img_banner;
GtkWidget* img_strip;
GtkWidget* img_icon;
GtkWidget* label_appname;
GtkWidget* label_kernel;
GtkWidget* label_stats;
GtkWidget* label_user;
GtkWidget* wnd;
wintc_ctl_install_default_styles();
builder =
gtk_builder_new_from_resource(
"/uk/oddmatics/wintc/shell/dlgabout.ui"
);
wintc_lc_builder_preprocess_widget_text(builder);
wintc_builder_get_objects(
builder,
"main-wnd", &wnd,
"img-banner", &img_banner,
"img-strip", &img_strip,
"img-icon", &img_icon,
"label-appname", &label_appname,
"label-kernel", &label_kernel,
"label-user", &label_user,
"label-stats", &label_stats,
NULL
);
g_object_ref(wnd);
g_object_unref(builder);
// Set up window
//
GdkPixbuf* pixbuf_banner = wintc_brand_get_brand_pixmap(
WINTC_BRAND_PART_BANNER,
NULL
);
GdkPixbuf* pixbuf_strip = wintc_brand_get_brand_pixmap(
WINTC_BRAND_PART_STRIP_STATIC,
NULL
);
struct utsname kernel_info;
struct sysinfo stats;
struct passwd* user_pwd = getpwuid(getuid());
uname(&kernel_info);
sysinfo(&stats);
gtk_image_set_from_pixbuf(
GTK_IMAGE(img_banner),
pixbuf_banner
);
gtk_image_set_from_pixbuf(
GTK_IMAGE(img_strip),
pixbuf_strip
);
wintc_widget_printf(
wnd,
app_name
);
wintc_widget_printf(
label_appname,
app_name
);
wintc_widget_printf(
label_kernel,
kernel_info.release,
wintc_build_get_tag(),
wintc_build_is_debug() ? " (Debug)" : ""
);
wintc_widget_printf(
label_user,
user_pwd->pw_name
);
wintc_widget_printf(
label_stats,
stats.totalram / 1024
);
if (icon_name)
{
gtk_image_set_from_icon_name(
GTK_IMAGE(img_icon),
icon_name,
GTK_ICON_SIZE_DND
);
}
if (parent_wnd)
{
gtk_window_set_transient_for(
GTK_WINDOW(wnd),
GTK_WINDOW(parent_wnd)
);
gtk_window_set_modal(
GTK_WINDOW(wnd),
TRUE
);
}
// Set up actions
//
g_action_map_add_action_entries(
G_ACTION_MAP(wnd),
k_actions,
G_N_ELEMENTS(k_actions),
wnd
);
// Launch window (for application)
//
GApplication* app = g_application_get_default();
if (app)
{
gtk_window_set_application(
GTK_WINDOW(wnd),
GTK_APPLICATION(app)
);
}
gtk_widget_show_all(wnd);
// Clean up
//
g_object_unref(pixbuf_banner);
g_object_unref(pixbuf_strip);
}
//
// PRIVATE FUNCTIONS
//
static void action_sh_about_ok(
WINTC_UNUSED(GSimpleAction* action),
WINTC_UNUSED(GVariant* parameter),
gpointer user_data
)
{
gtk_window_close(GTK_WINDOW(user_data));
}

View File

@@ -0,0 +1,263 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkApplicationWindow" id="main-wnd">
<property name="can-focus">False</property>
<property name="icon-name">help-browser</property>
<property name="resizable">False</property>
<property name="title" translatable="yes">About %s</property>
<property name="type-hint">GDK_WINDOW_TYPE_HINT_MENU</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkImage" id="img-banner">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkImage" id="img-strip">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage" id="img-icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="height-request">32</property>
<property name="width-request">32</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<style>
<class name="wintc-ml-lg" />
<class name="wintc-mr-lg" />
<class name="wintc-mt-md" />
</style>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="halign">GTK_ALIGN_FILL</property>
<property name="hexpand">True</property>
<child>
<object class="GtkLabel" id="label-appname">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="no">Microsoft ® %s</property>
<property name="xalign">0.0</property>
<style>
<class name="wintc-mb-sm" />
<class name="wintc-mt-md" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-kernel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">GTK_ALIGN_START</property>
<property name="label" translatable="no">Version %s (%s)%s</property>
<property name="max-width-chars">54</property>
<property name="wrap">True</property>
<property name="xalign">0.0</property>
<style>
<class name="wintc-mb-sm" />
<class name="wintc-mt-sm" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="no">Copyright © 1985-2005 Microsoft Corporation</property>
<property name="xalign">0.0</property>
<style>
<class name="wintc-mb-lg" />
<class name="wintc-mt-sm" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">GTK_ALIGN_START</property>
<property name="label" translatable="yes">This product is licensed under the terms of the End User License Agreement to:</property>
<property name="max-width-chars">46</property>
<property name="wrap">True</property>
<property name="xalign">0.0</property>
<style>
<class name="wintc-mb-sm" />
<class name="wintc-mt-lg" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-user">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="no">%s</property>
<property name="xalign">0.0</property>
<style>
<class name="wintc-mb-lg" />
<class name="wintc-ml-md" />
<class name="wintc-mt-sm" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">horizontal</property>
<style>
<class name="wintc-mt-lg" />
<class name="wintc-mb-sm" />
<class name="wintc-mr-md" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-stats">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="no">Physical memory available to Windows: %lu KB</property>
<property name="xalign">0.0</property>
<style>
<class name="wintc-mt-sm" />
<class name="wintc-mb-lg" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">6</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">horizontal</property>
<child>
<object class="GtkButton" id="btn-ok">
<property name="label" translatable="yes">OK</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="action-name">win.ok</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack-type">end</property>
<property name="position">0</property>
</packing>
</child>
<style>
<class name="wintc-button-box" />
<class name="wintc-mb-lg" />
<class name="wintc-mr-lg" />
<class name="wintc-mt-lg" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">7</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/uk/oddmatics/wintc/shell">
<!-- DIALOGS -->
<file>dlgabout.ui</file>
<!-- MENUS -->
<file>menuctx.ui</file>
<file>menufs.ui</file>

View File

@@ -501,6 +501,7 @@
<property name="can-focus">False</property>
<property name="label" translatable="yes">About Windows</property>
<property name="use-underline">True</property>
<property name="action-name">win.about</property>
</object>
</child>
</object>

View File

@@ -82,6 +82,11 @@ static void switch_mode_to(
WinTCExplorerWindowMode mode
);
static void action_about(
GSimpleAction* action,
GVariant* parameter,
gpointer user_data
);
static void action_nav_go(
GSimpleAction* action,
GVariant* parameter,
@@ -121,6 +126,13 @@ static const gchar* S_TITLE_FORMAT_INTERNET =
"%s - Microsoft Internet Explorer";
static GActionEntry s_window_actions[] = {
{
.name = "about",
.activate = action_about,
.parameter_type = NULL,
.state = NULL,
.change_state = NULL
},
{
.name = "nav-go",
.activate = action_nav_go,
@@ -1025,6 +1037,17 @@ static void switch_mode_to(
//
// CALLBACKS
//
static void action_about(
WINTC_UNUSED(GSimpleAction* action),
WINTC_UNUSED(GVariant* parameter),
gpointer user_data
)
{
WinTCExplorerWindow* wnd = WINTC_EXPLORER_WINDOW(user_data);
wintc_sh_about(GTK_WINDOW(wnd), "Windows", NULL, NULL);
}
static void action_nav_go(
WINTC_UNUSED(GSimpleAction* action),
GVariant* parameter,

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5)
project(
wintc-shell-winver
wintc-winver
VERSION 1.0
DESCRIPTION "Windows Total Conversion 'About Windows' utility."
LANGUAGES C
@@ -24,26 +24,29 @@ wintc_resolve_library(glib-2.0 GLIB)
wintc_resolve_library(gtk+-3.0 GTK3)
wintc_resolve_library(wintc-comctl WINTC_COMCTL)
wintc_resolve_library(wintc-comgtk WINTC_COMGTK)
wintc_resolve_library(wintc-shell WINTC_SHELL)
wintc_resolve_library(wintc-winbrand WINTC_WINBRAND)
add_executable(
wintc-shell-winver
src/winver.c
wintc-winver
src/application.c
src/application.h
src/main.c
)
set_target_properties(
wintc-shell-winver
wintc-winver
PROPERTIES
OUTPUT_NAME winver
)
target_compile_options(
wintc-shell-winver
wintc-winver
PRIVATE ${WINTC_COMPILE_OPTIONS}
)
target_include_directories(
wintc-shell-winver
wintc-winver
SYSTEM
BEFORE
PRIVATE ${GDK_PIXBUF_INCLUDE_DIRS}
@@ -51,26 +54,29 @@ target_include_directories(
PRIVATE ${GTK3_INCLUDE_DIRS}
PRIVATE ${WINTC_COMCTL_INCLUDE_DIRS}
PRIVATE ${WINTC_COMGTK_INCLUDE_DIRS}
PRIVATE ${WINTC_SHELL_INCLUDE_DIRS}
PRIVATE ${WINTC_WINBRAND_INCLUDE_DIRS}
)
target_link_directories(
wintc-shell-winver
wintc-winver
PRIVATE ${GDK_PIXBUF_LIBRARY_DIRS}
PRIVATE ${GLIB_LIBRARY_DIRS}
PRIVATE ${GTK3_LIBRARY_DIRS}
PRIVATE ${WINTC_COMCTL_LIBRARY_DIRS}
PRIVATE ${WINTC_COMGTK_LIBRARY_DIRS}
PRIVATE ${WINTC_SHELL_LIBRARY_DIRS}
PRIVATE ${WINTC_WINBRAND_LIBRARY_DIRS}
)
target_link_libraries(
wintc-shell-winver
wintc-winver
PRIVATE ${GDK_PIXBUF_LIBRARIES}
PRIVATE ${GLIB_LIBRARIES}
PRIVATE ${GTK3_LIBRARIES}
PRIVATE ${WINTC_COMCTL_LIBRARIES}
PRIVATE ${WINTC_COMGTK_LIBRARIES}
PRIVATE ${WINTC_SHELL_LIBRARIES}
PRIVATE ${WINTC_WINBRAND_LIBRARIES}
)
@@ -80,15 +86,15 @@ if (${WINTC_PKGMGR} STREQUAL "bsdpkg")
wintc_resolve_library(libsysinfo SYSINFO)
target_include_directories(
wintc-shell-winver
wintc-winver
PRIVATE ${SYSINFO_INCLUDE_DIRS}
)
target_link_directories(
wintc-shell-winver
wintc-winver
PRIVATE ${SYSINFO_LIBRARY_DIRS}
)
target_link_libraries(
wintc-shell-winver
wintc-winver
PRIVATE ${SYSINFO_LIBRARIES}
)
endif()
@@ -102,6 +108,6 @@ install(
DESTINATION ${WINTC_ASSETS_INSTALL_DIR}/shell-res
)
install(
TARGETS wintc-shell-winver
TARGETS wintc-winver
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,72 @@
#include <glib.h>
#include <gtk/gtk.h>
#include <wintc/comgtk.h>
#include <wintc/shell.h>
#include "application.h"
//
// GTK OOP CLASS/INSTANCE DEFINITIONS
//
struct _WinTCWinverApplicationClass
{
GtkApplicationClass __parent__;
};
struct _WinTCWinverApplication
{
GtkApplication __parent__;
};
//
// FORWARD DECLARATIONS
//
static void wintc_winver_application_activate(
GApplication* application
);
//
// GTK TYPE DEFINITIONS & CTORS
//
G_DEFINE_TYPE(
WinTCWinverApplication,
wintc_winver_application,
GTK_TYPE_APPLICATION
)
static void wintc_winver_application_class_init(
WinTCWinverApplicationClass* klass
)
{
GApplicationClass* application_class = G_APPLICATION_CLASS(klass);
application_class->activate = wintc_winver_application_activate;
}
static void wintc_winver_application_init(
WINTC_UNUSED(WinTCWinverApplication* self)
) { }
//
// CLASS VIRTUAL METHODS
//
static void wintc_winver_application_activate(
WINTC_UNUSED(GApplication* application)
)
{
wintc_sh_about(NULL, "Windows", NULL, NULL);
}
//
// PUBLIC FUNCTIONS
//
WinTCWinverApplication* wintc_winver_application_new(void)
{
return WINTC_WINVER_APPLICATION(
g_object_new(
wintc_winver_application_get_type(),
"application-id", "uk.oddmatics.wintc.winver",
NULL
)
);
}

View File

@@ -0,0 +1,27 @@
#ifndef __APPLICATION_H__
#define __APPLICATION_H__
#include <glib.h>
#include <gtk/gtk.h>
//
// GTK OOP BOILERPLATE
//
typedef struct _WinTCWinverApplicationClass WinTCWinverApplicationClass;
typedef struct _WinTCWinverApplication WinTCWinverApplication;
#define WINTC_TYPE_WINVER_APPLICATION (wintc_winver_application_get_type())
#define WINTC_WINVER_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WINTC_TYPE_WINVER_APPLICATION, WinTCWinverApplication))
#define WINTC_WINVER_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WINTC_TYPE_WINVER_APPLICATION, WinTCWinverApplicationClass))
#define IS_WINTC_WINVER_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WINTC_TYPE_WINVER_APPLICATION))
#define IS_WINTC_WINVER_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WINTC_TYPE_WINVER_APPLICATION))
#define WINTC_WINVER_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WINTC_TYPE_WINVER_APPLICATION, WinTCWinverApplicationClass))
GType wintc_winver_application_get_type(void) G_GNUC_CONST;
//
// PUBLIC FUNCTIONS
//
WinTCWinverApplication* wintc_winver_application_new(void);
#endif

20
shell/winver/src/main.c Normal file
View File

@@ -0,0 +1,20 @@
#include <glib.h>
#include "application.h"
int main(
int argc,
char* argv[]
)
{
WinTCWinverApplication* app = wintc_winver_application_new();
int status;
g_set_application_name("Winver");
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}

View File

@@ -1,313 +0,0 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <gtk/gtk.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <pwd.h>
#include <wintc/comctl.h>
#include <wintc/comgtk.h>
#include <wintc/winbrand.h>
//
// FORWARD DECLARATIONS
//
static void apply_box_model_style(
GtkWidget* widget,
const gchar* model_part,
const gchar* side,
guint margin
);
static void apply_winver_margin_style(
GtkWidget* widget
);
static GtkWidget* create_winver_label(
const gchar* text
);
static void on_ok_button_clicked(
GtkButton* button,
gpointer user_data
);
static void on_window_destroyed(
GtkWidget* widget,
gpointer user_data
);
//
// ENTRY POINT
//
int main(
int argc,
char* argv[]
)
{
GtkWidget* banner;
GtkWidget* banner_strip;
GtkWidget* box;
GtkWidget* box_buttons;
GtkWidget* button_ok;
GtkWidget* label_copyright;
GtkWidget* label_eula;
GtkWidget* label_eula_user;
GtkWidget* label_memory;
GtkWidget* label_product;
GtkWidget* label_version;
GtkWidget* separator;
GtkWidget* window;
struct sysinfo stats;
struct utsname kernel_info;
gtk_init(&argc, &argv);
wintc_ctl_install_default_styles();
// Create the window
//
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(window, 413, 322);
gtk_window_set_icon_name(GTK_WINDOW(window), "help-browser");
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
gtk_window_set_title(GTK_WINDOW(window), "About Windows");
gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
g_signal_connect(
window,
"destroy",
G_CALLBACK(on_window_destroyed),
NULL
);
// Create banner
//
GError* banner_error = NULL;
GdkPixbuf* banner_pixbuf = NULL;
GError* strip_error = NULL;
GdkPixbuf* strip_pixbuf = NULL;
banner_pixbuf = wintc_brand_get_brand_pixmap(
WINTC_BRAND_PART_BANNER,
&banner_error
);
strip_pixbuf = wintc_brand_get_brand_pixmap(
WINTC_BRAND_PART_STRIP_STATIC,
&strip_error
);
// FIXME: Handle missing branding properly... bleh!
//
if (banner_pixbuf == NULL)
{
wintc_log_error_and_clear(&banner_error);
return 1;
}
if (strip_pixbuf == NULL)
{
wintc_log_error_and_clear(&strip_error);
return 1;
}
banner = gtk_image_new_from_pixbuf(banner_pixbuf);
banner_strip = gtk_image_new_from_pixbuf(strip_pixbuf);
apply_box_model_style(banner_strip, "margin", "bottom", 4);
g_object_unref(banner_pixbuf);
g_object_unref(strip_pixbuf);
// Get kernel info
//
gchar* kernel_version;
uname(&kernel_info);
kernel_version =
g_strdup_printf(
"Version %s (%s)%s",
kernel_info.release,
wintc_build_get_tag(),
wintc_build_is_debug() ? " (Debug)" : ""
);
// Get system info
//
gchar* system_stats;
sysinfo(&stats);
system_stats =
g_strdup_printf(
"Physical memory available to Windows: %lu KB",
stats.totalram / 1024
);
// Create labels
//
struct passwd *user_pwd = getpwuid(getuid());
label_product = create_winver_label("Microsoft ® Windows");
label_version = create_winver_label(kernel_version);
label_copyright = create_winver_label("Copyright © 1985-2005 Microsoft Corporation");
label_eula = create_winver_label("This product is licensed under the terms of the End User License Agreement to:");
label_eula_user = create_winver_label(user_pwd->pw_name);
label_memory = create_winver_label(system_stats);
apply_box_model_style(label_product, "margin", "top", 4);
apply_box_model_style(label_eula, "margin", "top", 30);
apply_box_model_style(label_eula_user, "margin", "left", 60);
apply_box_model_style(label_eula_user, "margin", "bottom", 16);
apply_box_model_style(label_memory, "margin", "top", 4);
// Create separator
//
separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
apply_box_model_style(separator, "margin", "right", 8);
apply_winver_margin_style(separator);
// Create OK button
//
button_ok = gtk_button_new_with_label("OK");
g_signal_connect(
button_ok,
"clicked",
G_CALLBACK(on_ok_button_clicked),
window
);
// Build window contents
//
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
box_buttons = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add(GTK_CONTAINER(window), box);
gtk_box_pack_start(GTK_BOX(box), banner, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), banner_strip, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), label_product, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), label_version, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), label_copyright, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), label_eula, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), label_eula_user, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), separator, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), label_memory, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(box), box_buttons, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(box_buttons), button_ok, FALSE, FALSE, 0);
wintc_widget_add_style_class(
box_buttons,
WINTC_CTL_BUTTON_BOX_CSS_CLASS
);
wintc_widget_add_style_class(
box_buttons,
WINTC_CTL_MARGINB_LG_CSS_CLASS
);
wintc_widget_add_style_class(
box_buttons,
WINTC_CTL_MARGINR_LG_CSS_CLASS
);
// Clear mem
//
g_free(kernel_version);
g_free(system_stats);
// Launch now
//
gtk_widget_show_all(window);
gtk_main();
return 0;
}
//
// PRIVATE FUNCTIONS
//
static void apply_box_model_style(
GtkWidget* widget,
const gchar* model_part,
const gchar* side,
guint margin
)
{
GtkCssProvider* provider = gtk_css_provider_new();
GtkStyleContext* style = gtk_widget_get_style_context(widget);
gchar* style_css = g_slice_alloc0(
sizeof(char) * 40
);
g_sprintf(
style_css,
"* { %s-%s: %dpx; }",
model_part,
side,
margin
);
gtk_css_provider_load_from_data(
provider,
style_css,
-1,
NULL
);
gtk_style_context_add_provider(
style,
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
);
g_object_unref(provider);
g_slice_free1(sizeof(char) * 40, style_css);
}
static void apply_winver_margin_style(
GtkWidget* widget
)
{
apply_box_model_style(widget, "margin", "bottom", 2);
apply_box_model_style(widget, "margin", "left", 52);
apply_box_model_style(widget, "margin", "top", 2);
}
static GtkWidget* create_winver_label(
const gchar* text
)
{
GtkWidget* label = gtk_label_new(text);
gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_max_width_chars(GTK_LABEL(label), 54);
gtk_label_set_xalign(GTK_LABEL(label), 0.0);
apply_winver_margin_style(label);
return label;
}
//
// CALLBACKS
//
static void on_ok_button_clicked(
WINTC_UNUSED(GtkButton* button),
gpointer user_data
)
{
gtk_window_close(
GTK_WINDOW(user_data)
);
}
static void on_window_destroyed(
WINTC_UNUSED(GtkWidget* widget),
WINTC_UNUSED(gpointer user_data)
)
{
gtk_main_quit();
}

View File

@@ -7,9 +7,16 @@
* Author(s): Rory Fewell <roryf@oddmatics.uk>
*/
$metric_sm: 2px;
$metric_md: 6px;
$metric_lg: 12px;
/** small **/
.wintc-mb-sm { margin-bottom: $metric_sm; }
.wintc-ml-sm { margin-left: $metric_sm; }
.wintc-mr-sm { margin-right: $metric_sm; }
.wintc-mt-sm { margin-top: $metric_sm; }
/** medium **/
.wintc-mb-md { margin-bottom: $metric_md; }
.wintc-ml-md { margin-left: $metric_md; }

View File

@@ -25,6 +25,7 @@ wintc_resolve_library(glib-2.0 GLIB)
wintc_resolve_library(gtk+-3.0 GTK3)
wintc_resolve_library(wintc-comgtk WINTC_COMGTK)
wintc_resolve_library(wintc-shcommon WINTC_SHCOMMON)
wintc_resolve_library(wintc-shell WINTC_SHELL)
wintc_resolve_library(wintc-shlang WINTC_SHLANG)
wintc_compile_resources()
@@ -75,6 +76,7 @@ target_include_directories(
PRIVATE ${GTK3_INCLUDE_DIRS}
PRIVATE ${WINTC_COMGTK_INCLUDE_DIRS}
PRIVATE ${WINTC_SHCOMMON_INCLUDE_DIRS}
PRIVATE ${WINTC_SHELL_INCLUDE_DIRS}
PRIVATE ${WINTC_SHLANG_INCLUDE_DIRS}
)
@@ -84,6 +86,7 @@ target_link_directories(
PRIVATE ${GTK3_LIBRARY_DIRS}
PRIVATE ${WINTC_COMGTK_LIBRARY_DIRS}
PRIVATE ${WINTC_SHCOMMON_LIBRARY_DIRS}
PRIVATE ${WINTC_SHELL_LIBRARY_DIRS}
PRIVATE ${WINTC_SHLANG_LIBRARY_DIRS}
)
@@ -93,6 +96,7 @@ target_link_libraries(
PRIVATE ${GTK3_LIBRARIES}
PRIVATE ${WINTC_COMGTK_LIBRARIES}
PRIVATE ${WINTC_SHCOMMON_LIBRARIES}
PRIVATE ${WINTC_SHELL_LIBRARIES}
PRIVATE ${WINTC_SHLANG_LIBRARIES}
)

View File

@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkBox" id="main-box">
@@ -311,7 +310,7 @@
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="action-name">win.notimpl</property>
<property name="action-name">win.about</property>
<property name="label" translatable="yes">About Notepad</property>
<property name="use-underline">True</property>
</object>

View File

@@ -2,6 +2,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <wintc/comgtk.h>
#include <wintc/shell.h>
#include <wintc/shlang.h>
#include "application.h"
@@ -54,6 +55,11 @@ static void action_notimpl(
gpointer user_data
);
static void action_about(
GSimpleAction* action,
GVariant* parameter,
gpointer user_data
);
static void action_exit(
GSimpleAction* action,
GVariant* parameter,
@@ -103,6 +109,13 @@ static GActionEntry s_window_actions[] = {
.change_state = NULL
},
{
.name = "about",
.activate = action_about,
.parameter_type = NULL,
.state = NULL,
.change_state = NULL
},
{
.name = "exit",
.activate = action_exit,
@@ -523,6 +536,17 @@ static void action_notimpl(
wintc_nice_error_and_clear(&error);
}
static void action_about(
WINTC_UNUSED(GSimpleAction* action),
WINTC_UNUSED(GVariant* parameter),
gpointer user_data
)
{
WinTCNotepadWindow* wnd = WINTC_NOTEPAD_WINDOW(user_data);
wintc_sh_about(GTK_WINDOW(wnd), "Notepad", NULL, "wintc-notepad");
}
static void action_exit(
WINTC_UNUSED(GSimpleAction* action),
WINTC_UNUSED(GVariant* parameter),