Commit cf7421a1 authored by Victor Ananjesky's avatar Victor Ananjesky

Initial commit

parents
Victor Ananjevsky <ananasik@gmail.com>
Zenity Authors:
Glynn Foster <glynn.foster@sun.com>
Mike Newman <mikegtn@gnome.org>
This diff is collapsed. Click to expand it.
This source diff could not be displayed because it is too large. You can view the blob instead.
SUBDIRS = src po data
EXTRA_DIST = COPYING ChangeLog NEWS README README.md AUTHORS TODO THANKS
This diff is collapsed. Click to expand it.
# Yet Another Dialog
====================
Program allows you to display GTK+ dialog boxes from command line or
shell scripts. YAD depends on GTK+ only. Minimal GTK+ version is 2.16.0
This software is licensed under the GPL v.3
Project homepage: https://sourceforge.net/projects/yad-dialog/
Example usage: https://sourceforge.net/p/yad-dialog/wiki/browse_pages/
Mailing list: http://groups.google.com/group/yad-common
Some miscellaneous stuff can be found in data directory including notify-send script
and simple zenity-compatible wrapper
# Building git version
======================
Get git version with command
svn checkout svn://svn.code.sf.net/p/yad-dialog/code/trunk yad-dialog-code
Before run the standard ./configure && make && make install procedure
you need to generate build scripts. This can be done by running command
autoreconf -ivf
For successfully build you may need to install the following packages:
* GNU Autotools (https://www.gnu.org/software/autoconf/ http://www.gnu.org/software/automake/)
* Intltool >= 0.40.0 (http://freedesktop.org/wiki/Software/intltool/)
* GTK+ >= 2.16.0 (http://www.gtk.org)
with appropriate *-dev* packages depending on your distro
Additionally, you can build yad with the following libraries:
* Webkit - for supporting HTML dialog (http://webkitgtk.org)
* GtkSourceView - for enabling syntax highlighting in text-info dialog (https://wiki.gnome.org/Projects/GtkSourceView)
* GtkSpell3 - for support spell checking in text fields (http://gtkspell.sourceforge.net/)
Yad can be built angainst both 2 and 3 versions of GTK+ library. Preferred build with version 2
"Zenity Authors",
"=======",
"Glynn Foster <glynn foster sun com>",
"Mike Newman <mikegtn gnome org>",
"",
"Patches from the following people",
"=================================",
"Darren Adams <darrenadams dsl pipex com>"
"Timo Aaltonen <tjaaltonen gnome cc hut fi>",
"Peter Astrand <astrand lysator liu se>",
"Jonathan Blandford <jrb redhat com>",
"Paul Bolle <pebolle tiscali nl>",
"Paolo Borelli <pborelli katamail com>",
"Leonardo Boshell <p kapcoweb com>",
"Ross Burton <ross burtonini com>",
"Damien Carbery <damien carbery sun com>",
"Anders Carlsson <andersca codefactory se>",
"Ed Catmur <ed catmur co uk>",
"Nicholas Curran <quasar austar net au>",
"John Fleck <jfleck inkstain net>",
"Sebastian Heinlein <glatzor pimpzkru de>",
"James Henstridge <james daa com au>",
"Chris Lahey <clahey ximian com>",
"Mihai T Lazarescu <mihai email it>",
"Sebastian Kapfer <sebastian_kapfer web de>",
"Tomasz Koczko <kloczek pld org pl>",
"Jordi Mallach <jordi sindominio net>",
"Kjartan Maraas <kmaraas gnome org>",
"Breda McColgan <breda mccolgan sun com>",
"Baptiste Mille-Mathias <bmm80 free fr>",
"Buhan Milne <bgmilne linux-mandrake com>",
"Christian Monneckes <c-w-m gmx de>",
"Ivan Noris <vix vazka sk>",
"Carlos Parra <cparra emergya info>",
"Havoc Pennington <hp redhat com>",
"Jan Arne Petersen <jpetersen uni-bonn de>",
"Kevin C Krinke <kckrinke opendoorsoftware com>",
"Sriram Ramkrishna <sri aracnet com>",
"Kristian Rietveld <kris gtk org>",
"Lucas Rocha <lucasr im ufba br>",
"Christian Rose <menthos menthos com>",
"Jakub Steiner <jimmac ximian com>",
"Luke Suchocki <gnome lukiepoo com>",
"Daniel d'Surreal <dagmar speakeasy net>",
"Hidetoshi Tajima <hidetoshi tajima sun com>",
"Tom Tromey <tromey redhat com>",
"Yann <bloch iie cnam fr>",
"Norman Rasmussen <normanr gmail com>",
"Benoît Dejean <tazforever dlfp org>",
- add actions to list, text-info and icons dialogs
- use optional gtksourceview in text-info dialog (done)
- add slideshow to picture dialog (reading uris from stdin)
- add single model for completion and combo-boxes
- add menu for select encodings in html dialog
- add reverse check column for list dialog
- add option for output format of boolean values (upper, lower, num)
- add tooltips for labels
dnl Disable deprecated GTK+ features
AC_DEFUN([GTK_DISABLE_DEPRECATED],
[
AC_ARG_ENABLE(deprecated, [AC_HELP_STRING([--disable-deprecated],
[Disable deprecated GTK functions])],
,[enable_deprecated=yes])
if test x$enable_deprecated = xyes
then
DISABLE_DEPRECATED=
else
DISABLE_DEPRECATED="-DG_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DPANGO_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE"
fi
AC_SUBST(DISABLE_DEPRECATED)
])
AC_INIT([YAD], [0.39.0], [https://sourceforge.net/p/yad-dialog/tickets/], yad, [https://sourceforge.net/projects/yad-dialog/])
AC_CONFIG_AUX_DIR([build])
AM_INIT_AUTOMAKE([1.11 foreign dist-xz no-dist-gzip])
AM_SILENT_RULES([yes])
AC_PREREQ([2.59])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([src])
AM_MAINTAINER_MODE
IT_PROG_INTLTOOL([0.40.0])
AC_PROG_CC
AC_ARG_WITH([gtk],
[AS_HELP_STRING([--with-gtk=gtk2|gtk3],[set the GTK+ version to use (default - gtk2)])],
[case "$with_gtk" in
gtk2|gtk3) ;;
*) AC_MSG_ERROR([invalid gtk version specified]) ;;
esac],
[with_gtk=gtk2])
case "$with_gtk" in
gtk3)
GTK_MODULE="gtk+-3.0"
GTK_REQUIRED="3.0.0"
GTK_PRINT="gtk+-unix-print-3.0"
WEBKIT="webkitgtk-3.0"
SPELL="gtkspell3-3.0"
SOURCEVIEW="gtksourceview-3.0"
;;
gtk2)
GTK_MODULE="gtk+-2.0"
GTK_REQUIRED="2.16.0"
GTK_PRINT="gtk+-unix-print-2.0"
WEBKIT="webkit-1.0"
SPELL="gtkspell3-2.0"
SOURCEVIEW="gtksourceview-2.0"
;;
esac
PKG_CHECK_MODULES([GTK], [$GTK_MODULE >= $GTK_REQUIRED $GTK_PRINT])
AC_SUBST([GTK_CFLAGS])
AC_SUBST([GTK_LIBS])
GTK_DISABLE_DEPRECATED
dnl rgb.txt
AC_ARG_WITH([rgb],
[AS_HELP_STRING([--with-rgb=PATH],
[set path to rgb.txt file (default - /etc/X11/rgb.txt)])],
[with_rgb=$withval], [with_rgb=/etc/X11/rgb.txt])
AC_DEFINE_UNQUOTED([RGB_FILE], ["$with_rgb"], [Path to rgb.txt file])
dnl html widget
AC_ARG_ENABLE([html],
[AS_HELP_STRING([--enable-html],
[Build YAD with HTML widget])],
[build_html=$enableval], [build_html=yes])
if test x$build_html = xyes; then
PKG_CHECK_MODULES([HTML], [$WEBKIT], [have_html=yes], [have_html=no])
else
have_html=no
fi
AC_SUBST([HTML_CFLAGS])
AC_SUBST([HTML_LIBS])
AM_CONDITIONAL([HTML], [test x$have_html = xyes])
if test x$have_html = xyes; then
AC_DEFINE([HAVE_HTML], [1], [Define this if you have webkit installed])
fi
dnl gio support
AC_ARG_ENABLE([gio],
[AS_HELP_STRING([--enable-gio],
[Build YAD with GIO support])],
[build_gio=$enableval], [build_gio=yes])
if test x$build_gio = xyes; then
PKG_CHECK_MODULES([GIO], [gio-2.0], [have_gio=yes], [have_gio=no])
else
have_gio=no
fi
AC_SUBST([GIO_CFLAGS])
AC_SUBST([GIO_LIBS])
if test x$have_gio = xyes; then
AC_DEFINE([HAVE_GIO], [1], [Define this if you have glib gio framework])
fi
dnl spell check
AC_ARG_ENABLE([spell],
[AS_HELP_STRING([--enable-spell],
[Build YAD with Spell check support (default - no)])],
[with_spell=$enableval], [with_spell=no])
if test x$with_spell = xyes; then
PKG_CHECK_MODULES([SPELL], [$SPELL], [have_spell=yes], [have_spell=no])
else
have_spell=no
fi
AC_SUBST([SPELL_CFLAGS])
AC_SUBST([SPELL_LIBS])
if test x$have_spell = xyes; then
AC_DEFINE([HAVE_SPELL], [1], [Define this if you need spell check support])
fi
dnl sourceview
AC_ARG_ENABLE([sourceview],
[AS_HELP_STRING([--enable-sourceview],
[Build YAD with GtkSourceView support (default - no)])],
[with_sourceview=$enableval], [with_sourceview=no])
if test x$with_spell = xyes; then
PKG_CHECK_MODULES([SOURCEVIEW], [$SOURCEVIEW], [have_sourceview=yes], [have_sourceview=no])
else
have_sourceview=no
fi
AC_SUBST([SOURCEVIEW_CFLAGS])
AC_SUBST([SOURCEVIEW_LIBS])
if test x$have_sourceview = xyes; then
AC_DEFINE([HAVE_SOURCEVIEW], [1], [Define this if you need GtkSourceView support])
fi
dnl icon browser
AC_ARG_ENABLE([icon-browser],
[AS_HELP_STRING([--enable-icon-browser],
[Build YAD icon browser])],
[build_ib=$enableval], [build_ib=no])
AM_CONDITIONAL([BUILD_IB], [test x$build_ib = xyes])
# *******************************
# Internationalization
# *******************************
GETTEXT_PACKAGE=yad
AC_SUBST([GETTEXT_PACKAGE])
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"], [Gettext domain])
AM_GLIB_GNU_GETTEXT
# *******************************
AC_SUBST([AM_CFLAGS])
AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_LDFLAGS])
# *******************************
AC_CONFIG_FILES([
Makefile
po/Makefile.in
src/Makefile
data/Makefile
data/icons/Makefile
data/icons/16x16/Makefile
data/icons/24x24/Makefile
data/icons/32x32/Makefile
data/icons/48x48/Makefile
data/icons/96x96/Makefile
data/icons/128x128/Makefile
data/yad.m4
data/yad.spec
])
AC_OUTPUT
echo
echo "Build configuratioh:"
echo " GTK+ version - $with_gtk"
echo " Path to rgb.txt - $with_rgb"
echo " HTML widget - $have_html"
echo " Spell checking - $have_spell"
echo " GtkSourceView - $have_sourceview"
echo " GIO support - $have_gio"
echo " Icon browser - $build_ib"
echo
SUBDIRS = icons
desktop_in_files = yad-icon-browser.desktop.in
if BUILD_IB
desktopdir = $(datadir)/applications
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@
endif
dist_man_MANS = yad.1
m4dir = $(datadir)/aclocal
m4_DATA = yad.m4
EXTRA_DIST = $(desktop_in_files) zenity.sh notify-send
DISTCLEAN_FILES = $(desktop_DATA) $(m4_DATA) yad.spec
iconsdir = $(datadir)/icons/hicolor/128x128/apps
dist_icons_DATA = yad.png
iconsdir = $(datadir)/icons/hicolor/16x16/apps
dist_icons_DATA = yad.png
iconsdir = $(datadir)/icons/hicolor/24x24/apps
dist_icons_DATA = yad.png
iconsdir = $(datadir)/icons/hicolor/32x32/apps
dist_icons_DATA = yad.png
iconsdir = $(datadir)/icons/hicolor/48x48/apps
dist_icons_DATA = yad.png
iconsdir = $(datadir)/icons/hicolor/96x96/apps
dist_icons_DATA = yad.png
SUBDIRS = 16x16 24x24 32x32 48x48 96x96 128x128
gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
install-data-hook:
@-if test -z "$(DESTDIR)"; then \
echo "Updating Gtk icon cache."; \
$(gtk_update_icon_cache); \
else \
echo "*** Icon cache not updated. Remember to run:"; \
echo "***"; \
echo "*** $(gtk_update_icon_cache)"; \
echo "***"; \
fi
uninstall-local:
rm -f $(DESTDIR)$(datadir)/icons/hicolor/icon-theme.cache;
#! /bin/bash
# Defaults
APP="notification"
TIMEOUT=600
ICON="dialog-information"
TITLE=
BODY=
# Parse command line
OPTIND=1
while getopts a:i:t: opt ; do
case "$opt" in
a) APP=$OPTARG ;;
i) ICON=$OPTARG ;;
t) TIMEOUT=$OPTARG ;;
esac
done
shift $(($OPTIND - 1))
[[ "$1" == '--' ]] && shift
TITLE="$1"
shift
BODY="$@"
gdbus call --session --dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.Notify \
"$APP" 0 "$ICON" "$TITLE" "$BODY" "[]" "{}" $TIMEOUT &> /dev/null
[Desktop Entry]
Encoding=UTF-8
_Name=Icon Browser
_Comment=Inspect GTK Icon Theme
Categories=GTK;Development;
Exec=yad-icon-browser
Icon=yad
Terminal=false
Type=Application
StartupNotify=true
This diff is collapsed. Click to expand it.
## -*- Autoconf -*-
#
# Copyright (c) 2008-2011, Vitor Ananjevsky <ananasik@gmail.com>
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# AM_PATH_YAD([MINIMUM-VERSION],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
# ---------------------------------------------------------------------------
AC_DEFUN([AM_PATH_YAD],[
m4_if([$1],[],[
dnl No version check is needed.
if test -z "$YAD"; then
AC_PATH_PROG([YAD], yad, :)
fi
], [
dnl A version check is needed.
if test -z "$YAD"; then
AC_PATH_PROG([YAD], yad, :)
fi
AC_MSG_CHECKING([whether yad version >= $1])
m4_define([yad_version],[@VERSION@])
m4_if(m4_version_compare(yad_version,[$1]),[-1],
[AC_MSG_ERROR([too old (]yad_version[)])],
[AC_MSG_RESULT(yad_version)])
])
if test "$YAD" = :; then
dnl Run any user-specified action, or abort.
m4_default([$3], [AC_MSG_ERROR([Yad not found])])
else
dnl Run any user-specified action.
m4_if([$2],[],[true],[$2])
AC_SUBST([YAD])
fi
])
# norootforbuild
Name: yad
Version: @VERSION@
Release: 1
Summary: A fork of Zenity with many improvements
License: GPLv3
Group: Development/Tools/GUI Builders
URL: http://code.google.com/p/yad/
Source0: %{name}-%{version}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildRequires: gtk2-devel intltool pkgconfig
%description
Yad (yet another dialog) is a fork of Zenity with many improvements, such as
custom buttons, additional dialogs, pop-up menu in notification icon and more.
There were two main reasons to make this fork. The first one is to remove
dependencies on deprecated libraries, such as libglade and gnome-canvas.
And the second one - as for me, Zenity looks like an abandoned project.
Its ChangeLog consists of just "bump version to..." and "translation updated"
for the long time, but many interesting ideas which are ignored by
developers/maintainers were in GNOME Bugzilla.
%debug_package
%prep
%setup -q -n %{name}-%{version}
%build
%configure
%__make %{?jobs:-j%{jobs}}
%install
%makeinstall
%find_lang %{name}
%clean
rm -rf "%{buildroot}"
%files -f %{name}.lang
%defattr(-,root,root,-)
%doc AUTHORS ChangeLog COPYING README THANKS TODO
%{_bindir}/%{name}
%{_datadir}/pixmaps/%{name}.png
%{_mandir}/man1/%{name}.1.gz
%changelog
* Tue Jan 05 2010 - Detlef Reichelt <detlef@links2linux.de> - 0.0.8
- initial build for PackMan <0.0.8>
function zenity ()
{
local ARGS
ARGS=
for a in "$@"; do
case $a in
--info) ARGS="$ARGS --image=gtk-dialog-info" ;;
--question) ARGS="$ARGS --image=gtk-dialog-question" ;;
--warning) ARGS="$ARGS --image=gtk-dialog-warning" ;;
--error) ARGS="$ARGS --image=gtk-dialog-error" ;;
*) ARGS="$ARGS $a"
esac
done
eval set -- $ARGS
yad $@
}
export -f zenity
# yad translations
#
# please keep this list sorted alphabetically
#
de
fr
it
pt_BR
ru
sk
uk
zh_TW
src/about.c
src/calendar.c
src/entry.c
src/file.c
src/font.c
src/form.c
src/html.c
src/icons.c
src/main.c
src/notification.c
src/scale.c
src/list.c
src/option.c
src/multi-progress.c
src/paned.c
src/picture.c
src/print.c
src/progress.c
src/color.c
src/text.c
src/browser.c
src/notebook.c
data/yad-icon-browser.desktop.in
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
AM_CPPFLAGS = \
-DLOCALEDIR=\""$(datadir)/locale"\" \
@DISABLE_DEPRECATED@
bin_PROGRAMS = yad
yad_SOURCES = \
about.c \
calendar.c \
color.c \
dnd.c \
entry.c \
file.c \
font.c \
form.c \
icons.c \
list.c \
multi-progress.c \
notebook.c \
notification.c \
option.c \
paned.c \
picture.c \
print.c \
progress.c \
scale.c \
text.c \
util.c \
main.c \
yad.h \
calendar.xpm
if HTML
yad_SOURCES += html.c
endif
yad_CFLAGS = $(GTK_CFLAGS) $(HTML_CFLAGS) $(SPELL_CFLAGS) $(SOURCEVIEW_CFLAGS)
yad_LDADD = $(GTK_LIBS) $(HTML_LIBS) $(SPELL_LIBS) $(SOURCEVIEW_LIBS)
if BUILD_IB
bin_PROGRAMS += yad-icon-browser
yad_icon_browser_SOURCES = browser.c
yad_icon_browser_CFLAGS = $(GTK_CFLAGS)
yad_icon_browser_LDADD = $(GTK_LIBS)
endif
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include "yad.h"
gint
yad_about (void)
{
GtkWidget *dialog;
const gchar *const authors[] = {
"Victor Ananjevsky <ananasik@gmail.com>",
NULL
};
const gchar *translators = N_("translator-credits");
const gchar *license =
N_("YAD 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.\n\n"
"YAD 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.\n\n"
"You should have received a copy of the GNU General Public License "
"along with YAD. If not, see <http://www.gnu.org/licenses/>.");
gchar *comments = g_strdup_printf (_("Yet Another Dialog\n"
"(show dialog boxes from shell scripts)\n"
"\nBased on Zenity code\n\n"
#ifdef HAVE_HTML
"Built with Webkit\n"
#endif
#ifdef HAVE_SOURCEVIEW
"Built with GtkSourceView\n"
#endif
#ifdef HAVE_SPELL
"Built with GtkSpell\n"
#endif
"Using GTK+ %d.%d.%d\n"),
gtk_major_version, gtk_minor_version, gtk_micro_version);
dialog = gtk_about_dialog_new ();
gtk_window_set_icon_name (GTK_WINDOW (dialog), "yad");
g_object_set (G_OBJECT (dialog),
"name", PACKAGE_NAME,
"version", PACKAGE_VERSION,
"copyright", "Copyright \xc2\xa9 2008-2017, Victor Ananjevsky <ananasik@gmail.com>",
"comments", comments,
"authors", authors,
"website", PACKAGE_URL,
"translator-credits", translators,
"wrap-license", TRUE,
"license", license,
"logo-icon-name", "yad",
NULL);
return gtk_dialog_run (GTK_DIALOG (dialog));
}
This diff is collapsed. Click to expand it.
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <errno.h>
#include "yad.h"
static GtkWidget *calendar;
static GHashTable *details;
static void
parse_details ()
{
FILE *f;
details = g_hash_table_new (g_str_hash, g_str_equal);
/* open details file */
f = fopen (options.calendar_data.details, "r");
if (f == NULL)
{
g_printerr (_("Cannot open file '%s': %s\n"), options.common_data.uri, g_strerror (errno));
return;
}
/* read details file */
while (!feof (f))
{
gchar buf[4096], **dtl;
/* read string */
memset (buf, 0, 4096);
fgets (buf, 4096, f);
if (strlen (buf) > 0)
{
dtl = g_strsplit (buf, " ", 2);
g_hash_table_insert (details, dtl[0], dtl[1]);
}
}
fclose (f);
}
static gchar *
get_details (GtkCalendar * cal, guint year, guint month, guint day, gpointer data)
{
GDate *d;
gchar time_string[128];
gchar *str = NULL;
d = g_date_new_dmy (day, month + 1, year);
if (g_date_valid (d))
{
g_date_strftime (time_string, 127, options.common_data.date_format, d);
str = (gchar *) g_hash_table_lookup (details, time_string);
}
g_date_free (d);
if (str)
return g_strdup (str);
return str;
}
static void
double_click_cb (GtkWidget * w, gpointer data)
{
if (options.plug == -1)
yad_exit (options.data.def_resp);
}
GtkWidget *
calendar_create_widget (GtkWidget * dlg)
{
GtkWidget *w;
gint cal_opts;
w = calendar = gtk_calendar_new ();
gtk_widget_set_name (w, "yad-calendar-widget");
if (options.calendar_data.month > 0 || options.calendar_data.year > 0)
gtk_calendar_select_month (GTK_CALENDAR (w), options.calendar_data.month - 1, options.calendar_data.year);
if (options.calendar_data.day > 0)
gtk_calendar_select_day (GTK_CALENDAR (w), options.calendar_data.day);
if (options.calendar_data.details)
{
parse_details ();
gtk_calendar_set_detail_func (GTK_CALENDAR (w), get_details, NULL, NULL);
}
cal_opts = GTK_CALENDAR_SHOW_HEADING | GTK_CALENDAR_SHOW_DAY_NAMES;
if (options.calendar_data.weeks)
cal_opts |= GTK_CALENDAR_SHOW_WEEK_NUMBERS;
gtk_calendar_set_display_options (GTK_CALENDAR (w), cal_opts);
g_signal_connect (w, "day-selected-double-click", G_CALLBACK (double_click_cb), dlg);
return w;
}
void
calendar_print_result (void)
{
guint day, month, year;
gchar time_string[128];
GDate *date = NULL;
gtk_calendar_get_date (GTK_CALENDAR (calendar), &year, &month, &day);
date = g_date_new_dmy (day, month + 1, year);
g_date_strftime (time_string, 127, options.common_data.date_format, date);
g_print ("%s\n", time_string);
}
/* XPM */
static const char * calendar_xpm[] = {
"16 16 79 1",
" c None",
". c #898D88",
"+ c #898B86",
"@ c #8B8D89",
"# c #945D04",
"$ c #8F5A02",
"% c #8E5902",
"& c #878984",
"* c #BFC0BB",
"= c #D8D9D7",
"- c #945D05",
"; c #D9AC65",
"> c #DEB36F",
", c #A5A7A3",
"' c #E6E8E5",
") c #A9AAA7",
"! c #DFB370",
"~ c #DFB470",
"{ c #F8F8F8",
"] c #E0B571",
"^ c #DCB069",
"/ c #555753",
"( c #D3D5D2",
"_ c #989A95",
": c #D4D6D3",
"< c #E0B671",
"[ c #DEB26E",
"} c #FFFFFF",
"| c #C1C2BF",
"1 c #91938F",
"2 c #C2C3C0",
"3 c #E1B671",
"4 c #F5F5F5",
"5 c #FDFDFD",
"6 c #E6E6E6",
"7 c #DEB26D",
"8 c #808080",
"9 c #686868",
"0 c #5C5C5C",
"a c #989898",
"b c #DEB26C",
"c c #CFCFCF",
"d c #3F3F3F",
"e c #E2B671",
"f c #DFB36C",
"g c #6A6A6A",
"h c #282828",
"i c #A1A1A1",
"j c #E2B570",
"k c #E0E0E0",
"l c #2B2B2B",
"m c #959691",
"n c #888A85",
"o c #646661",
"p c #E2B670",
"q c #616161",
"r c #656565",
"s c #636363",
"t c #8F8F8F",
"u c #EEEEED",
"v c #979893",
"w c #646662",
"x c #E3B670",
"y c #D3D7CF",
"z c #DFB26B",
"A c #E4B76F",
"B c #DBAD64",
"C c #E0B36B",
"D c #E1B46C",
"E c #E1B36C",
"F c #E1B46D",
"G c #E2B56D",
"H c #E2B46D",
"I c #E2B66E",
"J c #E3B56F",
"K c #E3B66F",
"L c #E4B66F",
"M c #DFB169",
"N c #945F05",
" .+@ .+@ ",
"#$%%&*&%%&=&%%$-",
"$;>>,')!~,{)]]^$",
"%>//&(_//&:_//<%",
"%[/}|12}}|1|}/3%",
"%[/}45466454}/3%",
"%7/}66890a66}/3%",
"%b/}6666cd66}/e%",
"%f/}666ghi66}/j%",
"%f/}6666kl6mnop%",
"%f/}66qrst6&u/p%",
"%f/}}}}}}}}vnwx%",
"%f/yyyyyyyyyy/x%",
"%z////////////A%",
"$BCDEFFGHGIJKLM$",
"-$%%%%%%%%%%%%$N"};
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <errno.h>
#include <glib/gprintf.h>
#include "yad.h"
static GtkWidget *color;
static GtkTreeModel *
create_palette ()
{
FILE *fp;
gchar *filename;
gchar buf[1024], *name;
GtkListStore *store;
GdkPixbuf *pb;
GtkTreeIter iter;
gchar *cxpm[] = {
"16 14 1 1",
". c #FFFFFF",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................"
};
gchar cl[] = ". c #FFFFFF";
if (options.color_data.palette)
filename = options.color_data.palette;
else
filename = RGB_FILE;
if ((fp = fopen (filename, "r")) == NULL)
{
g_printerr (_("Can't open file %s: %s\n"), filename, strerror (errno));
return NULL;
}
store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
while ((name = fgets (buf, sizeof (buf), fp)) != NULL)
{
gint r, g, b;
gchar spec[8];
if (buf[0] == '!')
continue;
sscanf (buf, "%d %d %d", &r, &g, &b);
g_sprintf (spec, "#%.2X%.2X%.2X", r, g, b);
g_sprintf (cl, ". c #%.2X%.2X%.2X", r, g, b);
cxpm[1] = cl;
pb = gdk_pixbuf_new_from_xpm_data ((const gchar **) cxpm);
while (g_ascii_isdigit (*name) || g_ascii_isspace (*name))
name++;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, pb, 1, spec, 2, g_strstrip (name), -1);
}
fclose (fp);
return GTK_TREE_MODEL (store);
}
static void
palette_changed (GtkTreeSelection * sel, gpointer data)
{
GtkTreeModel *model;
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (sel, &model, &iter))
{
gchar *clr;
GdkColor c;
gtk_tree_model_get (model, &iter, 1, &clr, -1);
if (gdk_color_parse (clr, &c))
gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (color), &c);
}
}
GtkWidget *
color_create_widget (GtkWidget * dlg)
{
GtkWidget *w;
#if !GTK_CHECK_VERSION(3,0,0)
w = gtk_vbox_new (FALSE, 2);
#else
w = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
#endif
color = gtk_color_selection_new ();
gtk_widget_set_name (color, "yad-color-widget");
gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (color), options.color_data.gtk_palette);
if (options.color_data.init_color)
{
GdkColor c;
if (gdk_color_parse (options.color_data.init_color, &c))
gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (color), &c);
}
gtk_box_pack_start (GTK_BOX (w), color, FALSE, FALSE, 2);
if (options.color_data.use_palette)
{
GtkTreeModel *model;
if ((model = create_palette ()) != NULL)
{
GtkWidget *exp, *sw, *list;
GtkCellRenderer *r;
GtkTreeViewColumn *col;
GtkTreeSelection *sel;
/* create expander */
exp = gtk_expander_new (_("Palette"));
gtk_expander_set_expanded (GTK_EXPANDER (exp), options.color_data.expand_palette);
gtk_container_set_border_width (GTK_CONTAINER (exp), 5);
gtk_box_pack_start (GTK_BOX (w), exp, TRUE, TRUE, 2);
/* create color list */
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), options.hscroll_policy, options.vscroll_policy);
gtk_widget_set_size_request (sw, -1, 75);
gtk_container_add (GTK_CONTAINER (exp), sw);
list = gtk_tree_view_new_with_model (model);
gtk_widget_set_name (list, "yad-color-palette");
g_object_unref (model);
gtk_container_add (GTK_CONTAINER (sw), list);
/* add first columns */
col = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (col, _("Color"));
/* pixbuf */
r = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (col, r, FALSE);
gtk_tree_view_column_set_attributes (col, r, "pixbuf", 0, NULL);
/* color value */
r = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (col, r, TRUE);
gtk_tree_view_column_set_attributes (col, r, "text", 1, NULL);
gtk_tree_view_column_set_sort_column_id (col, 1);
gtk_tree_view_append_column (GTK_TREE_VIEW (list), col);
/* add second column */
r = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (_("Name"), r, "text", 2, NULL);
gtk_tree_view_column_set_sort_column_id (col, 2);
gtk_tree_view_append_column (GTK_TREE_VIEW (list), col);
/* enable searching on Name column */
gtk_tree_view_set_search_column (GTK_TREE_VIEW (list), 2);
/* setup the selection handler */
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
g_signal_connect (G_OBJECT (sel), "changed", G_CALLBACK (palette_changed), NULL);
gtk_widget_show_all (exp);
}
}
return w;
}
void
color_print_result (void)
{
GdkColor c;
guint64 alpha;
gchar *cs;
gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (color), &c);
alpha = gtk_color_selection_get_current_alpha (GTK_COLOR_SELECTION (color));
cs = get_color (&c, alpha);
if (cs)
g_printf ("%s\n", cs);
}
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <glib/gprintf.h>
#include "yad.h"
static void
drop_data_cb (GtkWidget * w, GdkDragContext * dc, gint x, gint y,
GtkSelectionData * sel, guint info, guint t, gpointer data)
{
GdkAtom stgt;
static guint drop_cnt = 0;
stgt = gtk_selection_data_get_target (sel);
if (gtk_targets_include_uri (&stgt, 1))
{
gchar **uris;
gint i = 0;
uris = gtk_selection_data_get_uris (sel);
if (!uris)
return;
while (uris[i])
{
gchar *dstr = g_uri_unescape_string (uris[i], NULL);
if (options.common_data.command)
{
gchar *action = g_strdup_printf ("%s '%s'", options.common_data.command, dstr);
g_spawn_command_line_async (action, NULL);
g_free (action);
}
else
{
g_printf ("%s\n", dstr);
fflush (stdout);
}
g_free (dstr);
i++;
}
g_strfreev (uris);
}
else if (gtk_targets_include_text (&stgt, 1))
{
guchar *str = gtk_selection_data_get_text (sel);
if (str)
{
gchar *dstr = g_uri_unescape_string ((const gchar *) str, NULL);
if (options.common_data.command)
{
gchar *action, *arg;
arg = g_shell_quote (dstr);
action = g_strdup_printf ("%s %s", options.common_data.command, arg);
g_free (arg);
g_spawn_command_line_async (action, NULL);
g_free (action);
}
else
{
g_printf ("%s\n", dstr);
fflush (stdout);
}
g_free (dstr);
g_free (str);
}
}
if (options.dnd_data.exit_on_drop)
{
drop_cnt++;
if (drop_cnt == options.dnd_data.exit_on_drop)
yad_exit (options.data.def_resp);
}
}
void
dnd_init (GtkWidget * w)
{
GtkTargetList *tlist;
GtkTargetEntry *tgts;
gint ntgts;
tlist = gtk_target_list_new (NULL, 0);
gtk_target_list_add_uri_targets (tlist, 0);
gtk_target_list_add_text_targets (tlist, 0);
tgts = gtk_target_table_new_from_list (tlist, &ntgts);
gtk_drag_dest_set (w, GTK_DEST_DEFAULT_ALL, tgts, ntgts, GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (G_OBJECT (w), "drag_data_received", G_CALLBACK (drop_data_cb), NULL);
gtk_target_table_free (tgts, ntgts);
gtk_target_list_unref (tlist);
/* set tooltip */
if (options.dnd_data.tooltip)
{
if (!options.data.no_markup)
gtk_widget_set_tooltip_markup (w, options.data.dialog_text);
else
gtk_widget_set_tooltip_text (w, options.data.dialog_text);
}
}
This diff is collapsed. Click to expand it.
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <glib/gprintf.h>
#include "yad.h"
static GtkWidget *filechooser;
static void
file_activated_cb (GtkFileChooser * chooser, gpointer data)
{
if (options.plug == -1)
yad_exit (options.data.def_resp);
}
gboolean
file_confirm_overwrite (GtkWidget * dlg)
{
if (options.file_data.save && options.file_data.confirm_overwrite && !options.common_data.multi)
{
gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
if (g_file_test (filename, G_FILE_TEST_EXISTS))
{
GtkWidget *d;
gint r;
gchar *buf;
buf = g_strcompress (options.file_data.confirm_text);
d = gtk_message_dialog_new (GTK_WINDOW (dlg), GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", buf);
g_free (buf);
r = gtk_dialog_run (GTK_DIALOG (d));
gtk_widget_destroy (d);
if (r != GTK_RESPONSE_YES)
return FALSE;
}
}
return TRUE;
}
GtkWidget *
file_create_widget (GtkWidget * dlg)
{
GtkWidget *w;
GList *filt;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
if (options.file_data.directory)
{
if (options.file_data.save)
action = GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
else
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
}
else
{
if (options.file_data.save)
action = GTK_FILE_CHOOSER_ACTION_SAVE;
}
w = filechooser = gtk_file_chooser_widget_new (action);
gtk_widget_set_name (w, "yad-file-widget");
if (options.common_data.uri)
{
if (!options.file_data.directory && g_file_test (options.common_data.uri, G_FILE_TEST_IS_DIR))
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), options.common_data.uri);
else
{
gchar *dir = g_path_get_dirname (options.common_data.uri);
if (g_path_is_absolute (options.common_data.uri) == TRUE)
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), dir);
if (options.common_data.uri[strlen (options.common_data.uri) - 1] != '/')
{
gchar *basename = g_path_get_basename (options.common_data.uri);
if (options.file_data.save)
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (w), basename);
else
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), options.common_data.uri);
g_free (basename);
}
g_free (dir);
}
}
else
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), g_get_current_dir ());
if (options.common_data.multi)
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (w), TRUE);
/* add preview */
if (options.common_data.preview)
{
GtkWidget *p = gtk_image_new ();
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (w), p);
g_signal_connect (w, "update-preview", G_CALLBACK (update_preview), p);
}
/* add filters */
for (filt = options.common_data.filters; filt; filt = filt->next)
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (w), GTK_FILE_FILTER (filt->data));
g_signal_connect (w, "map", G_CALLBACK (filechooser_mapped), NULL);
g_signal_connect (w, "file-activated", G_CALLBACK (file_activated_cb), dlg);
return w;
}
void
file_print_result (void)
{
GSList *selections, *iter;
selections = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (filechooser));
for (iter = selections; iter != NULL; iter = iter->next)
{
if (options.common_data.quoted_output)
{
gchar *buf = g_shell_quote (g_filename_to_utf8 ((gchar *) iter->data, -1, NULL, NULL, NULL));
g_printf ("%s", buf);
g_free (buf);
}
else
g_printf ("%s", g_filename_to_utf8 ((gchar *) iter->data, -1, NULL, NULL, NULL));
g_free (iter->data);
if (iter->next != NULL)
g_printf ("%s", options.common_data.separator);
}
g_printf ("\n");
g_slist_free (selections);
}
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <errno.h>
#include <glib/gprintf.h>
#include "yad.h"
static GtkWidget *font;
static void
realize_cb (GtkWidget * w, gpointer d)
{
gtk_font_selection_set_font_name (GTK_FONT_SELECTION (w), options.common_data.font);
}
GtkWidget *
font_create_widget (GtkWidget * dlg)
{
GtkWidget *w;
w = font = gtk_font_selection_new ();
gtk_widget_set_name (w, "yad-font-widget");
if (options.font_data.preview)
gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (w), options.font_data.preview);
/* font must be set after widget inserted in toplevel */
if (options.common_data.font)
g_signal_connect_after (G_OBJECT (w), "realize", G_CALLBACK (realize_cb), NULL);
return w;
}
void
font_print_result (void)
{
if (options.font_data.separate_output)
{
PangoFontFace *face;
PangoFontFamily *family;
gint size;
face = gtk_font_selection_get_face (GTK_FONT_SELECTION (font));
family = gtk_font_selection_get_family (GTK_FONT_SELECTION (font));
size = gtk_font_selection_get_size (GTK_FONT_SELECTION (font));
if (options.common_data.quoted_output)
{
gchar *q1 = g_shell_quote (pango_font_family_get_name (family));
gchar *q2 = g_shell_quote (pango_font_face_get_face_name (face));
g_printf ("%s%s%s%s%d\n", q1, options.common_data.separator, q2,
options.common_data.separator, size / 1000);
g_free (q1);
g_free (q2);
}
else
{
g_printf ("%s%s%s%s%d\n", pango_font_family_get_name (family), options.common_data.separator,
pango_font_face_get_face_name (face), options.common_data.separator, size / 1000);
}
}
else
{
gchar *fn = gtk_font_selection_get_font_name (GTK_FONT_SELECTION (font));
if (options.common_data.quoted_output)
{
gchar *buf = g_shell_quote (fn);
g_printf ("%s\n", buf);
g_free (buf);
}
else
g_printf ("%s\n", fn);
g_free (fn);
}
}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <gdk/gdk.h>
#include "yad.h"
static GtkWidget *notebook;
GtkWidget *
notebook_create_widget (GtkWidget * dlg)
{
GtkWidget *w;
GSList *tab;
/* get shared memory */
tabs = get_tabs (options.common_data.key, TRUE);
if (!tabs)
exit (-1);
/* create widget */
w = notebook = gtk_notebook_new ();
gtk_widget_set_name (w, "yad-notebook-widget");
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (w), options.notebook_data.pos);
gtk_container_set_border_width (GTK_CONTAINER (w), 5);
/* add tabs */
for (tab = options.notebook_data.tabs; tab; tab = tab->next)
{
GtkWidget *a, *s;
a = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_alignment_set_padding (GTK_ALIGNMENT (a),
options.notebook_data.borders, options.notebook_data.borders,
options.notebook_data.borders, options.notebook_data.borders);
s = gtk_socket_new ();
gtk_container_add (GTK_CONTAINER (a), s);
g_object_set_data (G_OBJECT (a), "socket", s);
gtk_notebook_append_page (GTK_NOTEBOOK (w), a, get_label ((gchar *) tab->data, 0));
}
/* set active tab */
if (options.notebook_data.active <= 0)
options.notebook_data.active = 1;
gtk_notebook_set_current_page (GTK_NOTEBOOK (w), options.notebook_data.active - 1);
return w;
}
void
notebook_swallow_childs (void)
{
guint i, n_tabs;
n_tabs = g_slist_length (options.notebook_data.tabs);
/* wait until all children are register */
while (tabs[0].xid != n_tabs)
usleep (1000);
for (i = 1; i <= n_tabs; i++)
{
GtkWidget *s =
GTK_WIDGET (g_object_get_data
(G_OBJECT (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i - 1)), "socket"));
if (tabs[i].pid != -1)
gtk_socket_add_id (GTK_SOCKET (s), tabs[i].xid);
}
}
void
notebook_print_result (void)
{
guint i, n_tabs;
n_tabs = g_slist_length (options.notebook_data.tabs);
for (i = 1; i <= n_tabs; i++)
{
if (tabs[i].pid != -1)
kill (tabs[i].pid, SIGUSR1);
}
}
void
notebook_close_childs (void)
{
guint i, n_tabs;
struct shmid_ds buf;
gboolean is_running = TRUE;
n_tabs = g_slist_length (options.notebook_data.tabs);
for (i = 1; i <= n_tabs; i++)
{
if (tabs[i].pid != -1)
kill (tabs[i].pid, SIGUSR2);
}
/* wait for stop subprocesses */
while (is_running)
{
is_running = FALSE;
for (i = 1; i <= n_tabs; i++)
{
if (tabs[i].pid != -1 && kill (tabs[i].pid, 0) == 0)
{
is_running = TRUE;
break;
}
}
usleep (1000);
}
/* cleanup shared memory */
shmctl (tabs[0].pid, IPC_RMID, &buf);
shmdt (tabs);
}
This diff is collapsed. Click to expand it.
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <gdk/gdk.h>
#include "yad.h"
static GtkWidget *paned;
GtkWidget *
paned_create_widget (GtkWidget * dlg)
{
GtkWidget *w, *s;
/* get shared memory */
tabs = get_tabs (options.common_data.key, TRUE);
if (!tabs)
exit (-1);
/* create widget */
if (options.paned_data.orient == GTK_ORIENTATION_HORIZONTAL)
paned = w = gtk_hpaned_new ();
else
paned = w = gtk_vpaned_new ();
gtk_widget_set_name (w, "yad-paned-widget");
gtk_paned_set_position (GTK_PANED (w), options.paned_data.splitter);
s = gtk_socket_new ();
gtk_paned_add1 (GTK_PANED (w), s);
g_object_set_data (G_OBJECT (w), "s1", s);
s = gtk_socket_new ();
gtk_paned_add2 (GTK_PANED (w), s);
g_object_set_data (G_OBJECT (w), "s2", s);
return w;
}
void
paned_swallow_childs (void)
{
GtkWidget *s1, *s2;
s1 = GTK_WIDGET (g_object_get_data (G_OBJECT (paned), "s1"));
s2 = GTK_WIDGET (g_object_get_data (G_OBJECT (paned), "s2"));
/* wait until all children are register */
while (tabs[0].xid != 2)
usleep (1000);
if (tabs[1].pid != -1)
gtk_socket_add_id (GTK_SOCKET (s1), tabs[1].xid);
if (tabs[2].pid != -1)
gtk_socket_add_id (GTK_SOCKET (s2), tabs[2].xid);
}
void
paned_print_result (void)
{
if (tabs[1].pid != -1)
kill (tabs[1].pid, SIGUSR1);
if (tabs[2].pid != -1)
kill (tabs[2].pid, SIGUSR1);
}
void
paned_close_childs (void)
{
guint i;
struct shmid_ds buf;
gboolean is_running = TRUE;
if (tabs[1].pid != -1)
kill (tabs[1].pid, SIGUSR2);
if (tabs[2].pid != -1)
kill (tabs[2].pid, SIGUSR2);
/* wait for stop subprocesses */
while (is_running)
{
is_running = FALSE;
for (i = 1; i <= 3; i++)
{
if (tabs[i].pid != -1 && kill (tabs[i].pid, 0) == 0)
{
is_running = TRUE;
break;
}
}
usleep (1000);
}
/* cleanup shared memory */
shmctl (tabs[0].pid, IPC_RMID, &buf);
shmdt (tabs);
}
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include "yad.h"
static GtkWidget *picture;
static GtkWidget *viewport;
static GtkWidget *popup_menu;
static GdkPixbufAnimation *anim_pb;
static GdkPixbuf *orig_pb;
static gboolean loaded = FALSE;
static gboolean animated = FALSE;
enum {
SIZE_FIT,
SIZE_ORIG,
SIZE_INC,
SIZE_DEC
};
enum {
ROTATE_LEFT,
ROTATE_RIGHT,
ROTATE_FLIP_VERT,
ROTATE_FLIP_HOR
};
static void
load_picture (gchar *filename)
{
anim_pb = gdk_pixbuf_animation_new_from_file (filename, NULL);
orig_pb = gdk_pixbuf_animation_get_static_image (anim_pb);
if (orig_pb)
{
if (gdk_pixbuf_animation_is_static_image (anim_pb))
gtk_image_set_from_pixbuf (GTK_IMAGE (picture), orig_pb);
else
{
gtk_image_set_from_animation (GTK_IMAGE (picture), anim_pb);
animated = TRUE;
}
loaded = TRUE;
}
else
gtk_image_set_from_stock (GTK_IMAGE (picture), "gtk-missing-image", GTK_ICON_SIZE_DIALOG);
}
void
picture_fit_to_window ()
{
gdouble width, height, ww, wh;
gdouble factor;
if (animated)
return;
width = gdk_pixbuf_get_width (orig_pb);
height = gdk_pixbuf_get_height (orig_pb);
ww = gdk_window_get_width (gtk_viewport_get_view_window (GTK_VIEWPORT (viewport)));
wh = gdk_window_get_height (gtk_viewport_get_view_window (GTK_VIEWPORT (viewport)));
factor = MIN (ww / width, wh / height);
if (factor < 1.0)
{
GdkPixbuf *pb = gdk_pixbuf_scale_simple (g_object_ref (orig_pb), width * factor, height * factor, GDK_INTERP_HYPER);
if (pb)
gtk_image_set_from_pixbuf (GTK_IMAGE (picture), pb);
}
}
static void
change_size_cb (GtkWidget *w, gint type)
{
gdouble width, height;
GdkPixbuf *new_pb, *pb = gtk_image_get_pixbuf (GTK_IMAGE (picture));
if (!pb)
{
g_printerr ("picture: can't get pixbuf\n");
return;
}
width = gdk_pixbuf_get_width (pb);
height = gdk_pixbuf_get_height (pb);
switch (type)
{
case SIZE_FIT:
picture_fit_to_window ();
break;
case SIZE_ORIG:
gtk_image_set_from_pixbuf (GTK_IMAGE (picture), orig_pb);
break;
case SIZE_INC:
new_pb = gdk_pixbuf_scale_simple (pb, width + options.picture_data.inc,
height + options.picture_data.inc, GDK_INTERP_HYPER);
if (new_pb)
{
gtk_image_set_from_pixbuf (GTK_IMAGE (picture), new_pb);
g_object_unref (pb);
}
break;
case SIZE_DEC:
new_pb = gdk_pixbuf_scale_simple (pb, width - options.picture_data.inc,
height - options.picture_data.inc, GDK_INTERP_HYPER);
if (new_pb)
{
gtk_image_set_from_pixbuf (GTK_IMAGE (picture), new_pb);
g_object_unref (pb);
}
break;
}
}
static void
rotate_cb (GtkWidget *w, gint type)
{
GdkPixbuf *new_pb = NULL;
GdkPixbuf *pb = gtk_image_get_pixbuf (GTK_IMAGE (picture));
if (!pb)
{
g_printerr ("picture: can't get pixbuf\n");
return;
}
switch (type)
{
case ROTATE_LEFT:
new_pb = gdk_pixbuf_rotate_simple (pb, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
break;
case ROTATE_RIGHT:
new_pb = gdk_pixbuf_rotate_simple (pb, GDK_PIXBUF_ROTATE_CLOCKWISE);
break;
case ROTATE_FLIP_VERT:
new_pb = gdk_pixbuf_flip (pb, FALSE);
break;
case ROTATE_FLIP_HOR:
new_pb = gdk_pixbuf_flip (pb, TRUE);
break;
}
if (new_pb)
{
gtk_image_set_from_pixbuf (GTK_IMAGE (picture), new_pb);
g_object_unref (pb);
}
}
static void
create_popup_menu ()
{
GtkWidget *mi;
popup_menu = gtk_menu_new ();
mi = gtk_image_menu_item_new_with_label (_("Fit to window"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("gtk-zoom-fit", GTK_ICON_SIZE_MENU));
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (change_size_cb), GINT_TO_POINTER (SIZE_FIT));
mi = gtk_image_menu_item_new_with_label (_("Original size"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("gtk-zoom-100", GTK_ICON_SIZE_MENU));
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (change_size_cb), GINT_TO_POINTER (SIZE_ORIG));
mi = gtk_image_menu_item_new_with_label (_("Increase size"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("gtk-zoom-in", GTK_ICON_SIZE_MENU));
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (change_size_cb), GINT_TO_POINTER (SIZE_INC));
mi = gtk_image_menu_item_new_with_label (_("Decrease size"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("gtk-zoom-out", GTK_ICON_SIZE_MENU));
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (change_size_cb), GINT_TO_POINTER (SIZE_DEC));
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
mi = gtk_image_menu_item_new_with_label (_("Rotate left"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("object-rotate-left", GTK_ICON_SIZE_MENU));
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (rotate_cb), GINT_TO_POINTER (ROTATE_LEFT));
mi = gtk_image_menu_item_new_with_label (_("Rotate right"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("object-rotate-right", GTK_ICON_SIZE_MENU));
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (rotate_cb), GINT_TO_POINTER (ROTATE_RIGHT));
mi = gtk_image_menu_item_new_with_label (_("Flip vertical"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("object-flip-vertical", GTK_ICON_SIZE_MENU));
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (rotate_cb), GINT_TO_POINTER (ROTATE_FLIP_VERT));
mi = gtk_image_menu_item_new_with_label (_("Flip horizontal"));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
gtk_image_new_from_icon_name ("object-flip-horizontal", GTK_ICON_SIZE_MENU));
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (rotate_cb), GINT_TO_POINTER (ROTATE_FLIP_HOR));
}
static gboolean
button_handler (GtkWidget *w, GdkEventButton *ev, gpointer data)
{
if (ev->button == 3)
{
gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL, NULL, NULL, ev->button, ev->time);
return TRUE;
}
return FALSE;
}
static gboolean
key_handler (GtkWidget *w, GdkEventKey *ev, gpointer data)
{
return FALSE;
}
GtkWidget *
picture_create_widget (GtkWidget * dlg)
{
GtkWidget *sw;
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), options.hscroll_policy, options.vscroll_policy);
viewport = gtk_viewport_new (gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (sw)),
gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (sw)));
gtk_container_add (GTK_CONTAINER (sw), viewport);
picture = gtk_image_new ();
gtk_container_add (GTK_CONTAINER (viewport), picture);
/* load picture */
if (options.common_data.uri &&
g_file_test (options.common_data.uri, G_FILE_TEST_EXISTS))
load_picture (options.common_data.uri);
else
gtk_image_set_from_stock (GTK_IMAGE (picture), "gtk-missing-image", GTK_ICON_SIZE_DIALOG);
if (loaded && !animated)
{
create_popup_menu ();
g_signal_connect (G_OBJECT (viewport), "button-press-event", G_CALLBACK (button_handler), NULL);
g_signal_connect (G_OBJECT (viewport), "key-press-event", G_CALLBACK (key_handler), NULL);
}
return sw;
}
This diff is collapsed. Click to expand it.
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include "yad.h"
static GtkWidget *progress_bar;
static GtkWidget *progress_log;
static GtkTextBuffer *log_buffer;
static gboolean
pulsate_progress_bar (gpointer user_data)
{
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progress_bar));
return TRUE;
}
static gboolean
handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
{
static guint pulsate_timeout = 0;
float percentage = 0.0;
if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP))
{
GString *string;
GError *err = NULL;
string = g_string_new (NULL);
if (options.progress_data.pulsate)
{
if (pulsate_timeout == 0)
pulsate_timeout = g_timeout_add (100, pulsate_progress_bar, NULL);
}
while (channel->is_readable != TRUE);
do
{
gint status;
do
{
status = g_io_channel_read_line_string (channel, string, NULL, &err);
while (gtk_events_pending ())
gtk_main_iteration ();
}
while (status == G_IO_STATUS_AGAIN);
if (status != G_IO_STATUS_NORMAL)
{
if (err)
{
g_printerr ("yad_progress_handle_stdin(): %s\n", err->message);
g_error_free (err);
err = NULL;
}
/* stop handling */
g_io_channel_shutdown (channel, TRUE, NULL);
return FALSE;
}
if (string->str[0] == '#')
{
gchar *match;
/* We have a comment, so let's try to change the label or write it to the log */
match = g_strcompress (g_strstrip (string->str + 1));
if (options.progress_data.log)
{
gchar *logline;
GtkTextIter end;
logline = g_strdup_printf ("%s\n", match); /* add new line */
gtk_text_buffer_get_end_iter (log_buffer, &end);
gtk_text_buffer_insert (log_buffer, &end, logline, -1);
g_free (logline);
/* scroll to end */
while (gtk_events_pending ())
gtk_main_iteration ();
gtk_text_buffer_get_end_iter (log_buffer, &end);
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (progress_log), &end, 0, FALSE, 0, 0);
}
else
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress_bar), match);
g_free (match);
}
else
{
if (g_ascii_isdigit (*(string->str)))
{
/* Now try to convert the thing to a number */
percentage = atoi (string->str);
if (percentage >= 100)
{
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0);
if (options.progress_data.autoclose && options.plug == -1)
yad_exit (options.data.def_resp);
}
else
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), percentage / 100.0);
}
}
}
while (g_io_channel_get_buffer_condition (channel) == G_IO_IN);
g_string_free (string, TRUE);
}
if ((condition != G_IO_IN) && (condition != G_IO_IN + G_IO_HUP))
{
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0);
if (options.progress_data.pulsate)
{
g_source_remove (pulsate_timeout);
pulsate_timeout = 0;
}
if (options.progress_data.autoclose && options.plug == -1)
yad_exit (options.data.def_resp);
g_io_channel_shutdown (channel, TRUE, NULL);
return FALSE;
}
return TRUE;
}
GtkWidget *
progress_create_widget (GtkWidget * dlg)
{
GtkWidget *w;
GIOChannel *channel;
// fix it when vertical specified
#if GTK_CHECK_VERSION(3,0,0)
w = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
#else
w = gtk_vbox_new (FALSE, 0);
#endif
progress_bar = gtk_progress_bar_new ();
gtk_widget_set_name (progress_bar, "yad-progress-widget");
if (options.progress_data.log_on_top)
gtk_box_pack_end (GTK_BOX (w), progress_bar, FALSE, FALSE, 0);
else
gtk_box_pack_start (GTK_BOX (w), progress_bar, FALSE, FALSE, 0);
if (options.progress_data.percentage > 100)
options.progress_data.percentage = 100;
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), options.progress_data.percentage / 100.0);
if (options.progress_data.progress_text)
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress_bar), options.progress_data.progress_text);
#if GTK_CHECK_VERSION(3,0,0)
gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR (progress_bar), options.progress_data.rtl);
#else
if (options.progress_data.rtl)
gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (progress_bar), GTK_PROGRESS_RIGHT_TO_LEFT);
#endif
if (options.progress_data.log)
{
GtkWidget *ex, *sw;
ex = gtk_expander_new (options.progress_data.log);
gtk_expander_set_spacing (GTK_EXPANDER (ex), 2);
gtk_expander_set_expanded (GTK_EXPANDER (ex), options.progress_data.log_expanded);
gtk_box_pack_start (GTK_BOX (w), ex, TRUE, TRUE, 2);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), options.hscroll_policy, options.vscroll_policy);
gtk_container_add (GTK_CONTAINER (ex), sw);
progress_log = gtk_text_view_new ();
gtk_widget_set_name (progress_log, "yad-text-widget");
gtk_widget_set_size_request (progress_log, -1, options.progress_data.log_height);
gtk_container_add (GTK_CONTAINER (sw), progress_log);
log_buffer = gtk_text_buffer_new (NULL);
gtk_text_view_set_buffer (GTK_TEXT_VIEW (progress_log), log_buffer);
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (progress_log), 5);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (progress_log), 5);
gtk_text_view_set_editable (GTK_TEXT_VIEW (progress_log), FALSE);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (progress_log), FALSE);
}
#if GTK_CHECK_VERSION(3,0,0)
else
gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (progress_bar), TRUE);
#endif
channel = g_io_channel_unix_new (0);
g_io_channel_set_encoding (channel, NULL, NULL);
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
g_io_add_watch (channel, G_IO_IN | G_IO_HUP, handle_stdin, dlg);
return w;
}
/*
* This file is part of YAD.
*
* YAD 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.
*
* YAD 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 YAD. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
*/
#include "yad.h"
enum {
PLUS_BTN = 0,
MINUS_BTN,
};
static GtkWidget *scale;
static GtkWidget *plus_btn = NULL;
static GtkWidget *minus_btn = NULL;
static void
value_changed_cb (GtkWidget * w, gpointer data)
{
if (options.scale_data.print_partial)
g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale)));
if (options.scale_data.buttons)
{
gdouble v = gtk_range_get_value (GTK_RANGE (scale));
if (v >= options.scale_data.max_value)
gtk_widget_set_sensitive (plus_btn, FALSE);
else
gtk_widget_set_sensitive (plus_btn, TRUE);
if (v <= options.scale_data.min_value)
gtk_widget_set_sensitive (minus_btn, FALSE);
else
gtk_widget_set_sensitive (minus_btn, TRUE);
}
}
static void
vb_pressed (GtkWidget *b, gpointer data)
{
gdouble v, cv = gtk_range_get_value (GTK_RANGE (scale));
switch (GPOINTER_TO_INT (data))
{
case PLUS_BTN:
v = cv + options.scale_data.step;
gtk_range_set_value (GTK_RANGE (scale), MIN (v, options.scale_data.max_value));
break;
case MINUS_BTN:
v = cv - options.scale_data.step;
gtk_range_set_value (GTK_RANGE (scale), MAX (v, options.scale_data.min_value));
break;
}
}
GtkWidget *
scale_create_widget (GtkWidget * dlg)
{
GtkWidget *w;
GtkAdjustment *adj;
gint page;
if (options.scale_data.min_value >= options.scale_data.max_value)
{
g_printerr (_("Maximum value must be greater than minimum value.\n"));
return NULL;
}
/* check for initial value */
if (options.scale_data.have_value)
{
if (options.scale_data.value < options.scale_data.min_value)
{
g_printerr (_("Initial value less than minimal.\n"));
options.scale_data.value = options.scale_data.min_value;
}
else if (options.scale_data.value > options.scale_data.max_value)
{
g_printerr (_("Initial value greater than maximum.\n"));
options.scale_data.value = options.scale_data.max_value;
}
}
else
options.scale_data.value = options.scale_data.min_value;
page = options.scale_data.page == -1 ? options.scale_data.step * 10 : options.scale_data.page;
/* this type conversion needs only for gtk-2.0 */
adj = (GtkAdjustment *) gtk_adjustment_new ((double) options.scale_data.value,
(double) options.scale_data.min_value,
(double) options.scale_data.max_value,
(double) options.scale_data.step,
(double) page,
0.0);
if (options.common_data.vertical)
{
#if GTK_CHECK_VERSION(3,0,0)
scale = gtk_scale_new (GTK_ORIENTATION_VERTICAL, GTK_ADJUSTMENT (adj));
#else
scale = gtk_vscale_new (GTK_ADJUSTMENT (adj));
#endif
gtk_range_set_inverted (GTK_RANGE (scale), !options.scale_data.invert);
}
else
{
#if GTK_CHECK_VERSION(3,0,0)
scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT (adj));
#else
scale = gtk_hscale_new (GTK_ADJUSTMENT (adj));
#endif
gtk_range_set_inverted (GTK_RANGE (scale), options.scale_data.invert);
}
gtk_widget_set_name (scale, "yad-scale-widget");
gtk_scale_set_digits (GTK_SCALE (scale), 0);
if (options.scale_data.hide_value)
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
/* add marks */
if (options.scale_data.marks)
{
GtkPositionType pos;
GSList *m = options.scale_data.marks;
pos = options.common_data.vertical ? GTK_POS_LEFT : GTK_POS_BOTTOM;
for (; m; m = m->next)
{
YadScaleMark *mark = (YadScaleMark *) m->data;
gtk_scale_add_mark (GTK_SCALE (scale), mark->value, pos, mark->name);
}
}
/* create container */
if (options.common_data.vertical)
{
#if GTK_CHECK_VERSION(3,0,0)
w = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
#else
w = gtk_vbox_new (FALSE, 1);
#endif
}
else
{
#if GTK_CHECK_VERSION(3,0,0)
w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1);
#else
w = gtk_hbox_new (FALSE, 1);
#endif
}
/* create buttons */
if (options.scale_data.buttons)
{
minus_btn = gtk_button_new_with_label ("-");
gtk_button_set_relief (GTK_BUTTON (minus_btn), GTK_RELIEF_NONE);
g_signal_connect (G_OBJECT (minus_btn), "clicked", G_CALLBACK (vb_pressed), GINT_TO_POINTER (MINUS_BTN));
gtk_widget_set_sensitive (minus_btn, (options.scale_data.value > options.scale_data.min_value));
plus_btn = gtk_button_new_with_label ("+");
gtk_button_set_relief (GTK_BUTTON (plus_btn), GTK_RELIEF_NONE);
g_signal_connect (G_OBJECT (plus_btn), "clicked", G_CALLBACK (vb_pressed), GINT_TO_POINTER (PLUS_BTN));
gtk_widget_set_sensitive (plus_btn, (options.scale_data.value < options.scale_data.max_value));
}
/* create complex widget */
if (options.scale_data.buttons)
gtk_box_pack_start (GTK_BOX (w), options.common_data.vertical ? plus_btn : minus_btn, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (w), scale, TRUE, TRUE, 2);
if (options.scale_data.buttons)
gtk_box_pack_start (GTK_BOX (w), options.common_data.vertical ? minus_btn : plus_btn, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (scale), "value-changed", G_CALLBACK (value_changed_cb), NULL);
gtk_widget_grab_focus (scale);
return w;
}
void
scale_print_result (void)
{
g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale)));
}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment