Initial import

This commit is contained in:
Pierre Pronchery 2013-12-08 23:45:32 +01:00
commit af375f7e5e
18 changed files with 1224 additions and 0 deletions

50
Makefile Normal file
View File

@ -0,0 +1,50 @@
PACKAGE = Installer
VERSION = 0.0.0
SUBDIRS = doc po src
RM = rm -f
LN = ln -f
TAR = tar -czvf
all: subdirs
subdirs:
@for i in $(SUBDIRS); do (cd "$$i" && $(MAKE)) || exit; done
clean:
@for i in $(SUBDIRS); do (cd "$$i" && $(MAKE) clean) || exit; done
distclean:
@for i in $(SUBDIRS); do (cd "$$i" && $(MAKE) distclean) || exit; done
dist:
$(RM) -r -- $(PACKAGE)-$(VERSION)
$(LN) -s -- . $(PACKAGE)-$(VERSION)
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz -- \
$(PACKAGE)-$(VERSION)/doc/Makefile \
$(PACKAGE)-$(VERSION)/doc/docbook.sh \
$(PACKAGE)-$(VERSION)/doc/installer.xml \
$(PACKAGE)-$(VERSION)/doc/project.conf \
$(PACKAGE)-$(VERSION)/po/Makefile \
$(PACKAGE)-$(VERSION)/po/gettext.sh \
$(PACKAGE)-$(VERSION)/po/POTFILES \
$(PACKAGE)-$(VERSION)/po/fr.po \
$(PACKAGE)-$(VERSION)/po/project.conf \
$(PACKAGE)-$(VERSION)/src/installer.c \
$(PACKAGE)-$(VERSION)/src/main.c \
$(PACKAGE)-$(VERSION)/src/Makefile \
$(PACKAGE)-$(VERSION)/src/installer.h \
$(PACKAGE)-$(VERSION)/src/project.conf \
$(PACKAGE)-$(VERSION)/Makefile \
$(PACKAGE)-$(VERSION)/config.h \
$(PACKAGE)-$(VERSION)/config.sh \
$(PACKAGE)-$(VERSION)/project.conf
$(RM) -- $(PACKAGE)-$(VERSION)
install:
@for i in $(SUBDIRS); do (cd "$$i" && $(MAKE) install) || exit; done
uninstall:
@for i in $(SUBDIRS); do (cd "$$i" && $(MAKE) uninstall) || exit; done
.PHONY: all subdirs clean distclean dist install uninstall

10
config.h Normal file
View File

@ -0,0 +1,10 @@
#define PACKAGE "Installer"
#define VERSION "0.0.0"
#ifndef PREFIX
# define PREFIX "/usr/local"
#endif
#ifndef LIBDIR
# define LIBDIR PREFIX "/lib"
#endif

5
config.sh Normal file
View File

@ -0,0 +1,5 @@
PACKAGE="Installer"
VERSION="0.0.0"
PREFIX="/usr/local"
LIBDIR="${PREFIX}/lib"

33
doc/Makefile Normal file
View File

@ -0,0 +1,33 @@
TARGETS = installer.1 installer.html
PREFIX = /usr/local
DESTDIR =
RM = rm -f
LN = ln -f
MKDIR = mkdir -m 0755 -p
INSTALL = install
all: $(TARGETS)
installer.1: installer.xml
./docbook.sh -P "$(PREFIX)" -- "installer.1"
installer.html: installer.xml
./docbook.sh -P "$(PREFIX)" -- "installer.html"
clean:
$(RM) -- $(installer.1_OBJS) $(installer.html_OBJS)
./docbook.sh -c -P "$(PREFIX)" -- "installer.html"
distclean: clean
$(RM) -- $(TARGETS)
install: $(TARGETS)
./docbook.sh -P "$(DESTDIR)$(PREFIX)" -i -- "installer.1"
./docbook.sh -P "$(DESTDIR)$(PREFIX)" -i -- "installer.html"
uninstall:
./docbook.sh -P "$(DESTDIR)$(PREFIX)" -u -- "installer.1"
./docbook.sh -P "$(DESTDIR)$(PREFIX)" -u -- "installer.html"
.PHONY: all clean distclean install uninstall

138
doc/docbook.sh Executable file
View File

@ -0,0 +1,138 @@
#!/bin/sh
#$Id$
#Copyright (c) 2012-2013 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#variables
PREFIX="/usr/local"
. "../config.sh"
#executables
DEBUG="_debug"
INSTALL="install -m 0644"
MKDIR="mkdir -m 0755 -p"
RM="rm -f"
XSLTPROC="xsltproc --nonet --xinclude"
#functions
#debug
_debug()
{
echo "$@" 1>&2
"$@"
}
#usage
_usage()
{
echo "Usage: docbook.sh [-c|-i|-u][-P prefix] target..." 1>&2
return 1
}
#main
clean=0
install=0
uninstall=0
while getopts "ciuP:" name; do
case "$name" in
c)
clean=1
;;
i)
uninstall=0
install=1
;;
u)
install=0
uninstall=1
;;
P)
PREFIX="$2"
;;
?)
_usage
exit $?
;;
esac
done
shift $((OPTIND - 1))
if [ $# -eq 0 ]; then
_usage
exit $?
fi
[ -z "$DATADIR" ] && DATADIR="$PREFIX/share"
[ -z "$MANDIR" ] && MANDIR="$DATADIR/man"
while [ $# -gt 0 ]; do
target="$1"
source="${target%.*}.xml"
shift
#determine the type
ext="${target##*.}"
ext="${ext##.}"
case "$ext" in
html)
XSL="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"
[ -f "${target%.*}.xsl" ] && XSL="${target%.*}.xsl"
instdir="$DATADIR/doc/$ext/$PACKAGE"
;;
1|2|3|4|5|6|7|8|9)
XSL="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"
instdir="$MANDIR/man$ext"
;;
*)
echo "$0: $target: Unknown type" 1>&2
exit 2
;;
esac
#clean
[ "$clean" -ne 0 ] && continue
#uninstall
if [ "$uninstall" -eq 1 ]; then
$DEBUG $RM -- "$instdir/$target" || exit 2
continue
fi
#install
if [ "$install" -eq 1 ]; then
$DEBUG $MKDIR -- "$instdir" || exit 2
$DEBUG $INSTALL -- "$target" "$instdir/$target" || exit 2
continue
fi
#create
$DEBUG $XSLTPROC -o "$target" "$XSL" "$source"
#XXX ignore errors
if [ $? -ne 0 ]; then
echo "$0: $target: Could not create page" 1>&2
$RM -- "$target"
break
fi
done

78
doc/installer.xml Normal file
View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id$ -->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY firstname "Pierre">
<!ENTITY surname "Pronchery">
<!ENTITY username "khorben">
<!ENTITY email "khorben@defora.org">
<!ENTITY section "1">
<!ENTITY title "Installer User Manual">
<!ENTITY package "DeforaOS Installer">
<!ENTITY name "installer">
<!ENTITY purpose "Presentation tool">
]>
<refentry>
<refentryinfo>
<title>&title;</title>
<productname>&package;</productname>
<authorgroup>
<author>
<firstname>&firstname;</firstname>
<surname>&surname;</surname>
<contrib>Code and documentation.</contrib>
<address>
<email>&email;</email>
</address>
</author>
</authorgroup>
<copyright>
<year>2013</year>
<holder>&firstname; &surname; &lt;&email;&gt;</holder>
</copyright>
<legalnotice>
<para>This manual page was written for the DeforaOS project (and may be
used by others).</para>
<para>Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU General Public License,
Version 3 as published by the Free Software Foundation.</para>
</legalnotice>
</refentryinfo>
<refmeta>
<refentrytitle>&name;</refentrytitle>
<manvolnum>&section;</manvolnum>
</refmeta>
<refnamediv>
<refname>&name;</refname>
<refpurpose>&purpose;</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>&name;</command>
<arg choice="plain"><replaceable>profile</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1 id="description">
<title>Description</title>
<para><command>&name;</command> is a presentation tool.</para>
</refsect1>
<refsect1 id="options">
<title>Options</title>
<para>The filename of an installation profile can be supplied directly on the
command line.</para>
</refsect1>
<refsect1 id="bugs">
<title>Bugs</title>
<para>Issues can be listed and reported online.</para>
</refsect1>
<refsect1 id="see_also">
<title>See also</title>
<para>
<citerefentry>
<refentrytitle>install</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>
</para>
</refsect1>
</refentry>
<!-- vim: set noet ts=1 sw=1 sts=1 tw=80: -->

14
doc/project.conf Normal file
View File

@ -0,0 +1,14 @@
targets=installer.1,installer.html
dist=Makefile,docbook.sh,installer.xml
[installer.1]
type=script
script=./docbook.sh
install=
depends=installer.xml
[installer.html]
type=script
script=./docbook.sh
install=
depends=installer.xml

31
po/Makefile Normal file
View File

@ -0,0 +1,31 @@
TARGETS = Installer.pot fr.mo
PREFIX = /usr/local
DESTDIR =
RM = rm -f
LN = ln -f
MKDIR = mkdir -m 0755 -p
INSTALL = install
all: $(TARGETS)
Installer.pot: POTFILES
./gettext.sh -P "$(PREFIX)" -- "Installer.pot"
fr.mo: Installer.pot fr.po
./gettext.sh -P "$(PREFIX)" -- "fr.mo"
clean:
$(RM) -- $(Installer.pot_OBJS) $(fr.mo_OBJS)
./gettext.sh -c -P "$(PREFIX)" -- "fr.mo"
distclean: clean
$(RM) -- $(TARGETS)
install: $(TARGETS)
./gettext.sh -P "$(DESTDIR)$(PREFIX)" -i -- "fr.mo"
uninstall:
./gettext.sh -P "$(DESTDIR)$(PREFIX)" -u -- "fr.mo"
.PHONY: all clean distclean install uninstall

2
po/POTFILES Normal file
View File

@ -0,0 +1,2 @@
../src/installer.c
../src/main.c

71
po/fr.po Normal file
View File

@ -0,0 +1,71 @@
# $Id$
# Copyright (c) 2013 Pierre Pronchery <khorben@defora.org>
# This file is distributed under the same license as the Installer package.
# Pierre Pronchery <khorben@defora.org>, 2013.
#
msgid ""
msgstr ""
"Project-Id-Version: Installer 0.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-12-08 23:43+0100\n"
"PO-Revision-Date: 2013-09-16 14:06+0200\n"
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
"Language-Team: French\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: ../src/installer.c:158
msgid "Welcome to the installer for "
msgstr "Bienvenue dans l'installation de "
#: ../src/installer.c:159
msgid "Welcome to the installer"
msgstr "Bienvenue"
#: ../src/installer.c:172
#, c-format
msgid "%s installer"
msgstr "Installation de %s"
#: ../src/installer.c:183
msgid ""
"Congratulations!\n"
"The installation has completed."
msgstr ""
"Félicitations !\n"
"L'installation est terminée."
#: ../src/installer.c:192
msgid "Installation complete"
msgstr "Installation terminée"
#: ../src/installer.c:202
msgid "Installer - "
msgstr "Installer - "
#: ../src/installer.c:267
msgid "translator-credits"
msgstr "Pierre Pronchery <khorben@defora.org>"
#: ../src/installer.c:313 ../src/installer.c:318
msgid "Question"
msgstr "Question"
#: ../src/installer.c:316
msgid ""
"The install operation is not complete.\n"
"Do you really want to cancel it?"
msgstr ""
"L'installation n'est pas terminée.\n"
"Voulez-vous vraiment l'interrompre en cours ?"
#: ../src/installer.c:340 ../src/installer.c:344
msgid "Error"
msgstr "Erreur"
#: ../src/main.c:78
#, c-format
msgid "Usage: %s profile\n"
msgstr "Usage: %s profil\n"

169
po/gettext.sh Executable file
View File

@ -0,0 +1,169 @@
#!/bin/sh
#$Id$
#Copyright (c) 2010-2013 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#variables
PREFIX="/usr/local"
. "../config.sh"
LOCALEDIR="$PREFIX/share/locale"
POTFILES="POTFILES"
#executables
DEBUG="_debug"
INSTALL="install -m 0644"
MKDIR="mkdir -p"
MSGFMT="msgfmt"
MSGINIT="msginit"
MSGMERGE="msgmerge"
RM="rm -f"
XGETTEXT="xgettext --force-po"
#functions
#debug
_debug()
{
echo "$@" 1>&2
"$@"
}
#usage
_usage()
{
echo "Usage: gettext.sh [-c|-i|-u][-P prefix] target..." 1>&2
return 1
}
#gettext_mo
_gettext_mo()
{
package="$1"
lang="$2"
_gettext_po "$package" "$lang" || return 1
$DEBUG $MSGFMT -c -v -o "$lang.mo" "$lang.po" || return 1
}
#gettext_po
_gettext_po()
{
package="$1"
lang="$2"
if [ -f "$lang.po" ]; then
$DEBUG $MSGMERGE -U "$lang.po" "$package.pot" || return 1
else
$DEBUG $MSGINIT -l "$lang" -o "$lang.po" -i "$package.pot" \
|| return 1
fi
}
#gettext_pot
_gettext_pot()
{
package="$1"
$DEBUG $XGETTEXT -d "$package" -o "$package.pot" --keyword="_" \
--keyword="N_" -f "$POTFILES" || return 1
}
#main
clean=0
install=0
uninstall=0
while getopts "ciuP:" name; do
case "$name" in
c)
clean=1
;;
i)
uninstall=0
install=1
;;
u)
install=0
uninstall=1
;;
P)
PREFIX="$2"
;;
?)
_usage
exit $?
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
_usage
exit $?
fi
LOCALEDIR="$PREFIX/share/locale"
while [ $# -gt 0 ]; do
target="$1"
lang="${target%%.mo}"
lang="${lang%%.po}"
shift
#clean
[ "$clean" -ne 0 ] && continue
#uninstall
if [ "$uninstall" -eq 1 ]; then
$DEBUG $RM "$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \
|| exit 2
continue
fi
#install
if [ "$install" -eq 1 ]; then
$DEBUG $MKDIR "$LOCALEDIR/$lang/LC_MESSAGES" || exit 2
$DEBUG $INSTALL "$target" \
"$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \
|| exit 2
continue
fi
#create
case "$target" in
*.mo)
_gettext_mo "$PACKAGE" "$lang" || exit 2
;;
*.po)
_gettext_po "$PACKAGE" "$lang" || exit 2
;;
*.pot)
_gettext_pot "${target%%.pot}" || exit 2
;;
*)
exit 2
;;
esac
done

13
po/project.conf Normal file
View File

@ -0,0 +1,13 @@
targets=Installer.pot,fr.mo
dist=Makefile,gettext.sh,POTFILES,fr.po
[Installer.pot]
type=script
script=./gettext.sh
depends=POTFILES
[fr.mo]
type=script
script=./gettext.sh
install=
depends=Installer.pot,fr.po

6
project.conf Normal file
View File

@ -0,0 +1,6 @@
package=Installer
version=0.0.0
config=h,sh
subdirs=doc,po,src
dist=Makefile,config.h,config.sh

46
src/Makefile Normal file
View File

@ -0,0 +1,46 @@
TARGETS = installer
PREFIX = /usr/local
DESTDIR =
BINDIR = $(PREFIX)/bin
SBINDIR = $(PREFIX)/sbin
CC = cc
CPPFLAGSF=
CPPFLAGS=
CFLAGSF = -W `pkg-config --cflags libDesktop`
CFLAGS = -Wall -g -O2
LDFLAGSF= `pkg-config --libs libDesktop`
RM = rm -f
LN = ln -f
MKDIR = mkdir -m 0755 -p
INSTALL = install
all: $(TARGETS)
installer_OBJS = installer.o main.o
installer_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
installer_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
installer: $(installer_OBJS)
$(CC) -o installer $(installer_OBJS) $(installer_LDFLAGS)
installer.o: installer.c installer.h ../config.h
$(CC) -D PREFIX=\"$(PREFIX)\" $(installer_CFLAGS) -c installer.c
main.o: main.c installer.h ../config.h
$(CC) $(installer_CFLAGS) -c main.c
clean:
$(RM) -- $(installer_OBJS)
distclean: clean
$(RM) -- $(TARGETS)
install: $(TARGETS)
$(MKDIR) $(DESTDIR)$(BINDIR)
$(INSTALL) -m 0755 installer $(DESTDIR)$(BINDIR)/installer
uninstall:
$(RM) -- $(DESTDIR)$(BINDIR)/installer
.PHONY: all clean distclean install uninstall

399
src/installer.c Normal file
View File

@ -0,0 +1,399 @@
/* $Id$ */
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Installer */
/* 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, version 3 of the License.
*
* 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 <stdio.h>
#include <string.h>
#include <libintl.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <System.h>
#include <Desktop.h>
#include "installer.h"
#include "../config.h"
#define _(string) gettext(string)
#define N_(string) (string)
/* Installer */
/* private */
/* types */
struct _Installer
{
char * profile;
Config * config;
/* widgets */
GtkWidget * window;
/* preferences */
GtkWidget * pr_window;
/* find */
GtkWidget * fi_dialog;
GtkListStore * fi_store;
GtkWidget * fi_text;
/* about */
GtkWidget * ab_window;
};
/* prototypes */
/* useful */
/* callbacks */
static void _installer_on_about(gpointer data);
static void _installer_on_cancel(gpointer data);
static void _installer_on_close(gpointer data);
static gboolean _installer_on_closex(gpointer data);
static void _installer_on_prepare(GtkWidget * widget, GtkWidget * page,
gpointer data);
/* public */
/* functions */
/* essential */
/* installer_new */
static void _new_page_first(Installer * installer, GdkPixbuf * pixbuf);
static void _new_page_last(Installer * installer, GdkPixbuf * pixbuf);
static void _new_set_title(Installer * installer);
Installer * installer_new(char const * profile)
{
Installer * installer;
GtkIconTheme * icontheme;
GtkAccelGroup * group;
GtkWidget * widget;
char const * icon;
#if GTK_CHECK_VERSION(2, 14, 0)
const int flags = GTK_ICON_LOOKUP_FORCE_SIZE;
#else
const int flags = 0;
#endif
GdkPixbuf * pixbuf = NULL;
if((installer = object_new(sizeof(*installer))) == NULL)
return NULL;
installer->profile = strdup(profile);
installer->config = config_new();
/* check for errors */
if(installer->profile == NULL
|| installer->config == NULL
/* FIXME no longer expect an absolute path */
|| config_load(installer->config, profile) != 0)
{
object_delete(installer);
return NULL;
}
/* widgets */
icontheme = gtk_icon_theme_get_default();
group = gtk_accel_group_new();
/* window */
installer->window = gtk_assistant_new();
gtk_window_add_accel_group(GTK_WINDOW(installer->window), group);
g_object_unref(group);
gtk_window_set_default_size(GTK_WINDOW(installer->window), 400, 300);
g_signal_connect_swapped(installer->window, "delete-event", G_CALLBACK(
_installer_on_closex), installer);
g_signal_connect_swapped(installer->window, "cancel", G_CALLBACK(
_installer_on_cancel), installer);
g_signal_connect_swapped(installer->window, "close", G_CALLBACK(
_installer_on_close), installer);
g_signal_connect(installer->window, "prepare", G_CALLBACK(
_installer_on_prepare), installer);
_new_set_title(installer);
#if GTK_CHECK_VERSION(2, 6, 0)
gtk_window_set_icon_name(GTK_WINDOW(installer->window),
"system-software-install");
#endif
widget = gtk_button_new_from_stock(GTK_STOCK_ABOUT);
g_signal_connect_swapped(widget, "clicked", G_CALLBACK(
_installer_on_about), installer);
gtk_widget_show(widget);
gtk_assistant_add_action_widget(GTK_ASSISTANT(installer->window),
widget);
/* load the desired icon */
if((icon = config_get(installer->config, NULL, "icon")) != NULL)
pixbuf = gtk_icon_theme_load_icon(icontheme, icon, 48, flags,
NULL);
/* first page */
_new_page_first(installer, pixbuf);
/* last page */
_new_page_last(installer, pixbuf);
if(pixbuf != NULL)
g_object_unref(pixbuf);
gtk_widget_show_all(installer->window);
/* about */
installer->ab_window = NULL;
return installer;
}
static void _new_page_first(Installer * installer, GdkPixbuf * pixbuf)
{
GtkAssistant * assistant = GTK_ASSISTANT(installer->window);
GtkWidget * widget;
char const * package;
char const * title;
char const * description;
char buf[256];
package = config_get(installer->config, NULL, "package");
title = config_get(installer->config, NULL, "title");
description = config_get(installer->config, NULL, "description");
if(description != NULL)
widget = gtk_label_new(description);
else
{
snprintf(buf, sizeof(buf), "%s%s", (package != NULL)
? _("Welcome to the installer for ")
: _("Welcome to the installer"),
(package != NULL) ? package : "");
widget = gtk_label_new(buf);
}
gtk_assistant_insert_page(assistant, widget, 0);
gtk_assistant_set_page_complete(assistant, widget, TRUE);
if(pixbuf != NULL)
gtk_assistant_set_page_header_image(assistant, widget, pixbuf);
if(title != NULL)
gtk_assistant_set_page_title(assistant, widget, title);
else
{
if(package != NULL)
snprintf(buf, sizeof(buf), _("%s installer"), package);
gtk_assistant_set_page_title(assistant, widget, buf);
}
gtk_assistant_set_page_type(assistant, widget,
GTK_ASSISTANT_PAGE_INTRO);
}
static void _new_page_last(Installer * installer, GdkPixbuf * pixbuf)
{
GtkWidget * widget;
widget = gtk_label_new(_("Congratulations!\n"
"The installation has completed."));
gtk_assistant_append_page(GTK_ASSISTANT(installer->window), widget);
gtk_assistant_set_page_complete(GTK_ASSISTANT(installer->window),
widget, TRUE);
if(pixbuf != NULL)
gtk_assistant_set_page_header_image(GTK_ASSISTANT(
installer->window), widget, pixbuf);
gtk_assistant_set_page_title(GTK_ASSISTANT(installer->window), widget,
_("Installation complete"));
gtk_assistant_set_page_type(GTK_ASSISTANT(installer->window), widget,
GTK_ASSISTANT_PAGE_SUMMARY);
}
static void _new_set_title(Installer * installer)
{
char buf[256];
/* FIXME replace with a configuration value instead */
snprintf(buf, sizeof(buf), "%s%s", _("Installer - "),
installer->profile);
gtk_window_set_title(GTK_WINDOW(installer->window), buf);
}
/* installer_delete */
void installer_delete(Installer * installer)
{
object_delete(installer);
}
/* useful */
/* installer_about */
/* callbacks */
static gboolean _about_on_closex(gpointer data);
void installer_about(Installer * installer)
{
char const * authors[2] = { NULL, NULL };
char const * comments;
char const * copyright;
char const * icon = "system-software-install";
char const * license;
char const * package = PACKAGE;
char const * version = VERSION;
char const * website;
char const * p;
if(installer->ab_window != NULL)
{
gtk_widget_show(installer->ab_window);
return;
}
/* load the configuration */
authors[0] = config_get(installer->config, NULL, "authors");
comments = config_get(installer->config, NULL, "comments");
copyright = config_get(installer->config, NULL, "copyright");
if((p = config_get(installer->config, NULL, "icon")) != NULL)
icon = p;
license = config_get(installer->config, NULL, "license");
if((p = config_get(installer->config, NULL, "package")) != NULL)
package = p;
if((p = config_get(installer->config, NULL, "version")) != NULL)
version = p;
website = config_get(installer->config, NULL, "website");
/* create the window */
installer->ab_window = desktop_about_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(installer->ab_window),
GTK_WINDOW(installer->window));
if(authors[0] != NULL)
desktop_about_dialog_set_authors(installer->ab_window,
authors);
if(comments != NULL)
desktop_about_dialog_set_comments(installer->ab_window,
comments);
if(copyright != NULL)
desktop_about_dialog_set_copyright(installer->ab_window,
copyright);
desktop_about_dialog_set_logo_icon_name(installer->ab_window, icon);
if(license != NULL)
desktop_about_dialog_set_license(installer->ab_window, license);
desktop_about_dialog_set_name(installer->ab_window, package);
desktop_about_dialog_set_translator_credits(installer->ab_window,
_("translator-credits"));
desktop_about_dialog_set_version(installer->ab_window, version);
if(website != NULL)
desktop_about_dialog_set_website(installer->ab_window, website);
g_signal_connect_swapped(G_OBJECT(installer->ab_window), "delete-event",
G_CALLBACK(_about_on_closex), installer);
gtk_widget_show(installer->ab_window);
}
static gboolean _about_on_closex(gpointer data)
{
Installer * installer = data;
gtk_widget_hide(installer->ab_window);
return TRUE;
}
/* installer_close */
int installer_close(Installer * installer)
{
GtkAssistant * assistant = GTK_ASSISTANT(installer->window);
gint n;
GtkWidget * page;
GtkWidget * dialog;
int res;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
n = gtk_assistant_get_current_page(assistant);
page = gtk_assistant_get_nth_page(assistant, n);
/* check for unsaved changes */
if(gtk_assistant_get_n_pages(assistant) == (n + 1)
&& page != NULL
&& gtk_assistant_get_page_complete(assistant, page))
{
/* we are on the last page and it is complete */
gtk_widget_hide(installer->window);
gtk_main_quit();
return 0;
}
dialog = gtk_message_dialog_new(GTK_WINDOW(installer->window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
#if GTK_CHECK_VERSION(2, 6, 0)
"%s", _("Question"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
#endif
"%s", _("The install operation is not complete.\n"
"Do you really want to cancel it?"));
gtk_window_set_title(GTK_WINDOW(dialog), _("Question"));
res = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
if(res == GTK_RESPONSE_YES)
{
gtk_widget_hide(installer->window);
gtk_main_quit();
return 0;
}
return 1;
}
/* installer_error */
int installer_error(Installer * installer, char const * message, int ret)
{
GtkWidget * dialog;
dialog = gtk_message_dialog_new(GTK_WINDOW(installer->window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
#if GTK_CHECK_VERSION(2, 6, 0)
"%s", _("Error"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
#endif
"%s", message);
gtk_window_set_title(GTK_WINDOW(dialog), _("Error"));
g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
gtk_widget_destroy), NULL);
gtk_widget_show(dialog);
return ret;
}
/* private */
/* useful */
/* callbacks */
/* installer_on_about */
static void _installer_on_about(gpointer data)
{
Installer * installer = data;
installer_about(installer);
}
/* installer_on_cancel */
static void _installer_on_cancel(gpointer data)
{
Installer * installer = data;
installer_close(installer);
}
/* installer_on_close */
static void _installer_on_close(gpointer data)
{
Installer * installer = data;
installer_close(installer);
}
/* installer_on_closex */
static gboolean _installer_on_closex(gpointer data)
{
Installer * installer = data;
installer_close(installer);
return TRUE;
}
/* installer_on_prepare */
static void _installer_on_prepare(GtkWidget * widget, GtkWidget * page,
gpointer data)
{
Installer * installer = data;
/* FIXME implement */
}

34
src/installer.h Normal file
View File

@ -0,0 +1,34 @@
/* $Id$ */
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Installer */
/* 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, version 3 of the License.
*
* 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/>. */
#ifndef INSTALLER_INSTALLER_H
# define INSTALLER_INSTALLER_H
/* public */
/* types */
typedef struct _Installer Installer;
/* functions */
/* essential */
Installer * installer_new(char const * profile);
void installer_delete(Installer * installer);
/* useful */
int installer_error(Installer * installer, char const * message, int ret);
#endif /* !INSTALLER_INSTALLER_H */

104
src/main.c Normal file
View File

@ -0,0 +1,104 @@
/* $Id$ */
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Installer */
/* 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, version 3 of the License.
*
* 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 <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <locale.h>
#include <libintl.h>
#include <gtk/gtk.h>
#include <System.h>
#include "installer.h"
#include "../config.h"
#define _(string) gettext(string)
/* constants */
#ifndef PROGNAME
# define PROGNAME "installer"
#endif
#ifndef PREFIX
# define PREFIX "/usr/local"
#endif
#ifndef DATADIR
# define DATADIR PREFIX "/share"
#endif
#ifndef LOCALEDIR
# define LOCALEDIR DATADIR "/locale"
#endif
/* private */
/* prototypes */
static int _installer(char const * profile);
static int _error(char const * message, int ret);
static int _usage(void);
/* functions */
/* installer */
static int _installer(char const * profile)
{
Installer * installer;
if((installer = installer_new(profile)) == NULL)
return -_error(error_get(), 1);
gtk_main();
installer_delete(installer);
return 0;
}
/* error */
static int _error(char const * message, int ret)
{
fprintf(stderr, "%s: %s\n", PROGNAME, message);
return ret;
}
/* usage */
static int _usage(void)
{
fprintf(stderr, _("Usage: %s profile\n"), PROGNAME);
return 1;
}
/* public */
/* functions */
/* main */
int main(int argc, char * argv[])
{
int o;
if(setlocale(LC_ALL, "") == NULL)
_error(strerror(errno), 1);
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
gtk_init(&argc, &argv);
while((o = getopt(argc, argv, "")) != -1)
switch(o)
{
default:
return _usage();
}
if(optind + 1 != argc)
return _usage();
return (_installer(argv[optind]) == 0) ? 0 : 2;
}

21
src/project.conf Normal file
View File

@ -0,0 +1,21 @@
targets=installer
#cppflags=-DEMBEDDED
cflags_force=-W `pkg-config --cflags libDesktop`
cflags=-Wall -g -O2
ldflags_force=`pkg-config --libs libDesktop`
dist=Makefile,installer.h
[installer]
type=binary
sources=installer.c,main.c
install=$(BINDIR)
[main.c]
depends=installer.h,../config.h
[installer.c]
depends=installer.h,../config.h
cppflags=-D PREFIX=\"$(PREFIX)\"
[installer.c]
depends=installer.h,../config.h