Skip to content

Commit

Permalink
Add new capplets: system info
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuyaliang authored and lukefromdc committed Oct 2, 2023
1 parent bc4db76 commit 5d9cbe6
Show file tree
Hide file tree
Showing 14 changed files with 1,234 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ requires:
- intltool
- itstool
- libxss
- libgtop
- libmatekbd
- make
- marco
- mate-common
- mate-menus
- polkit
- udisks2
- which
- yelp-tools

Expand Down Expand Up @@ -47,6 +49,7 @@ requires:
- librsvg2-bin
- librsvg2-dev
- libstartup-notification0-dev
- libudisks2-dev
- libx11-dev
- libxcursor-dev
- libxi-dev
Expand Down Expand Up @@ -84,8 +87,10 @@ requires:
- libXScrnSaver-devel
- libcanberra-devel
- libmatekbd-devel
- libgtop2-devel
- librsvg2-devel
- librsvg2-tools
- libudisks2-devel
- make
- marco-devel
- mate-menus-devel
Expand Down Expand Up @@ -118,6 +123,7 @@ requires:
- librsvg2-bin
- librsvg2-dev
- libstartup-notification0-dev
- libudisks2-dev
- libx11-dev
- libxcursor-dev
- libxi-dev
Expand Down
6 changes: 4 additions & 2 deletions capplets/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ SUBDIRS = \
network \
time-admin \
windows \
about-me
about-me \
system-info

DIST_SUBDIRS = \
common \
Expand All @@ -24,6 +25,7 @@ DIST_SUBDIRS = \
time-admin \
windows \
display \
about-me
about-me \
system-info

-include $(top_srcdir)/git.mk
45 changes: 45 additions & 0 deletions capplets/system-info/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is used in MATECC_CAPPLETS_CFLAGS
cappletname = system-info

ui_files = mate-system-info.ui

bin_PROGRAMS = mate-system-info

mate_system_info_LDADD = $(MATECC_CAPPLETS_LIBS)
BUILT_SOURCES = mate-system-info-resources.h mate-system-info-resources.c
nodist_mate_system_info_SOURCES = \
$(BUILT_SOURCES)
mate_system_info_SOURCES = \
mate-system-info.c \
mate-system-info.h \
info-cleanup.c \
info-cleanup.h \
main.c

include $(top_srcdir)/gla11y.mk

desktopdir = $(datadir)/applications
Desktop_in_files = mate-system-info.desktop.in
desktop_DATA = $(Desktop_in_files:.desktop.in=.desktop)

$(desktop_DATA): $(Desktop_in_files)
if USE_NLS
$(AM_V_GEN) $(MSGFMT) --desktop --keyword= --keyword=Name --keyword=Comment --keyword=Keywords --template $< -d $(top_srcdir)/po -o $@
else
$(AM_V_GEN) sed '/^# Translators/d' < $< > $@
endif

mate-system-info-resources.h mate-system-info-resources.c: system-info.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir $(srcdir) $(srcdir)/system-info.gresource.xml)
$(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate --c-name mate_system_info $<

AM_CPPFLAGS = \
$(WARN_CFLAGS) \
$(MATECC_CAPPLETS_CFLAGS) \
-DMATECC_DATA_DIR="\"$(pkgdatadir)\""
CLEANFILES = $(MATECC_CAPPLETS_CLEANFILES) $(desktop_DATA) $(BUILT_SOURCES)
EXTRA_DIST = \
$(ui_files) \
$(Desktop_in_files) \
system-info.gresource.xml

-include $(top_srcdir)/git.mk
133 changes: 133 additions & 0 deletions capplets/system-info/info-cleanup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2010 Red Hat, Inc
* Copyright (C) 2008 William Jon McCann <[email protected]>
*
* 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 2 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/>.
*
*/

#include <glib.h>
#include "info-cleanup.h"

typedef struct
{
char *regex;
char *replacement;
} ReplaceStrings;

static char *
prettify_info (const char *info)
{
g_autofree char *escaped = NULL;
g_autofree gchar *pretty = NULL;
int i;
static const ReplaceStrings rs[] = {
{ "Mesa DRI ", ""},
{ "Mesa Intel", "Intel"},
{ "[(]R[)]", "\302\256"},
{ "[(](tm|TM)[)]", "\342\204\242"},
{ "(ATI|EPYC|AMD FX|Radeon|Ryzen|Threadripper|GeForce RTX) ", "\\1\342\204\242 "},
{ "Gallium \\d+\\.\\d+ on (.*)", "\\1"},
{ " CPU| Processor| \\S+-Core| @ \\d+\\.\\d+GHz", ""},
{ " x86|/MMX|/SSE2|/PCIe", ""},
{ " [(][^)]*(DRM|MESA|LLVM)[^)]*[)]?", ""},
{ "Graphics Controller", "Graphics"},
{ ".*llvmpipe.*", "Software Rendering"},
{ "(AMD .*) [(].*", "\\1"},
{ "(AMD [A-Z])(.*)", "\\1\\L\\2\\E"},
{ "AMD", "AMD<sup>\302\256</sup>"},

};

if (*info == '\0')
return NULL;

escaped = g_markup_escape_text (info, -1);
pretty = g_strdup (g_strstrip (escaped));

for (i = 0; i < G_N_ELEMENTS (rs); i++)
{
g_autoptr(GError) error = NULL;
g_autoptr(GRegex) re = NULL;
g_autofree gchar *new = NULL;

re = g_regex_new (rs[i].regex, 0, 0, &error);
if (re == NULL)
{
g_warning ("Error building regex: %s", error->message);
continue;
}

new = g_regex_replace (re,
pretty,
-1,
0,
rs[i].replacement,
0,
&error);

if (error != NULL)
{
g_warning ("Error replacing %s: %s", rs[i].regex, error->message);
continue;
}

g_free (pretty);
pretty = g_steal_pointer (&new);
}

return g_steal_pointer (&pretty);
}

static char *
remove_duplicate_whitespace (const char *old)
{
g_autofree gchar *new = NULL;
g_autoptr(GRegex) re = NULL;
g_autoptr(GError) error = NULL;

if (old == NULL)
return NULL;

re = g_regex_new ("[ \t\n\r]+", G_REGEX_MULTILINE, 0, &error);
if (re == NULL)
{
g_warning ("Error building regex: %s", error->message);
return g_strdup (old);
}
new = g_regex_replace (re,
old,
-1,
0,
" ",
0,
&error);
if (new == NULL)
{
g_warning ("Error replacing string: %s", error->message);
return g_strdup (old);
}

return g_steal_pointer (&new);
}

char *
info_cleanup (const char *input)
{
g_autofree char *pretty = NULL;

pretty = prettify_info (input);
return remove_duplicate_whitespace (pretty);
}
23 changes: 23 additions & 0 deletions capplets/system-info/info-cleanup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2010 Red Hat, Inc
* Copyright (C) 2008 William Jon McCann <[email protected]>
*
* 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 2 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/>.
*
*/

#include <glib.h>

char *info_cleanup (const char *input);
35 changes: 35 additions & 0 deletions capplets/system-info/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*************************************************************************
File Name: main.c
Copyright (C) 2023 MATE Developers
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 <https://www.gnu.org/licenses/>.
************************************************************************/
#include "mate-system-info.h"
#include "capplet-util.h"

int main (int argc, char *argv[])
{
GtkWidget *dialog;

capplet_init (NULL, &argc, &argv);

dialog = mate_system_info_new ();
mate_system_info_setup (MATE_SYSTEM_INFO (dialog));
g_signal_connect (dialog, "response", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (dialog);

gtk_main ();

return 0;
}
Loading

0 comments on commit 5d9cbe6

Please sign in to comment.