From b095c6c5d46d838e36cc89e987c9f6350bd4baf0 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Tue, 10 Jul 2012 13:57:40 +0200 Subject: [PATCH 1/1] Initial commit The status-area-displayblanking-applet is a Maemo status menu applet to easily change the display blanking mode without having to go through the settings. --- Makefile | 19 ++ data/display-blanking-icon.0.png | Bin 0 -> 577 bytes data/display-blanking-icon.1.png | Bin 0 -> 891 bytes data/display-blanking-icon.2.png | Bin 0 -> 1638 bytes data/display-blanking-icon.3.png | Bin 0 -> 578 bytes data/display-blanking-icon.4.png | Bin 0 -> 564 bytes ...status-area-displayblanking-applet.desktop | 6 + debian/changelog | 5 + debian/compat | 1 + debian/control | 13 ++ debian/install | 7 + debian/rules | 49 +++++ po/Makefile | 76 +++++++ po/POTFILES.in | 1 + po/es_AR.po | 44 +++++ po/status-area-displayblanking-applet.pot | 44 +++++ src/Makefile | 19 ++ src/lib-display-blanking-status-menu-widget.c | 186 ++++++++++++++++++ 18 files changed, 470 insertions(+) create mode 100644 Makefile create mode 100644 data/display-blanking-icon.0.png create mode 100644 data/display-blanking-icon.1.png create mode 100644 data/display-blanking-icon.2.png create mode 100644 data/display-blanking-icon.3.png create mode 100644 data/display-blanking-icon.4.png create mode 100644 data/status-area-displayblanking-applet.desktop create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/install create mode 100755 debian/rules create mode 100644 po/Makefile create mode 100644 po/POTFILES.in create mode 100644 po/es_AR.po create mode 100644 po/status-area-displayblanking-applet.pot create mode 100644 src/Makefile create mode 100644 src/lib-display-blanking-status-menu-widget.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b6fe518 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +SUBDIRS=src po +BUILDDIR=build + +all: subdirs + +subdirs: $(SUBDIRS) + +$(SUBDIRS): + $(MAKE) -C $@ + +.PHONY: all clean install $(SUBDIRS) + +clean: + for d in $(SUBDIRS); do (cd $$d; $(MAKE) clean); done + +install: + for d in $(SUBDIRS); do (cd $$d; $(MAKE) install); done + + diff --git a/data/display-blanking-icon.0.png b/data/display-blanking-icon.0.png new file mode 100644 index 0000000000000000000000000000000000000000..77c43dc09c5c2ab90b7aaf2a4025b16a8543b752 GIT binary patch literal 577 zcmV-H0>1r;P)3q!G?%%sENEpY!Jj=YT{akw_#G$)!;?Jv2@8DbOle*0=3; z``u0f(=?xrMx!_VexEpwOOd=glGxUO4>fTn3UjzgNJ$H3VFmStT(Jv}81LjaN_VLTq=IL_Zwrzq&U zo?B?o^GK2eAq2Klp0+sHHQCg$@wv)PO^P0#G7mT8w}SwFgb)Nlz;d~~(7Oi}NYfPG_lctD!od$JunN8^6jz~8fjExweV@f*vA1s) zA`nFpK@jXUcp(Bp2z=is%d*`5q2^IhR;4h{;CmOiN+~?3z&!#Fh5#4!AKo!ff@I0?{;kV8}rBcDu@8Tc7hLaY2|MJgyAaBk) zSepc*TCK*7Z=dl`TJUuMP`JSQS;R1m^9gjj-4D91KY4KPSCjFmG|Oc&nY;(mUAGeV zbzMKwH0@!T*18bllk2*#fR8(`Re;;TwUX`E6mZsOKq8SyBoc{4@*ndP1BCpEP)e_g+g61=B+j zBJHKY7o)ZYyRIp5A{PrwSVi7H($37=gI22TM0S%{whH@$z3j}g&oj?E!^}WNMn*

rBeB9XJ_ZT_4ReS-R@W@&*$^Z%*?RAzyIax z>gv}g+j3_+HyVwv%H=ZEYLz&S$>nksi$w~B!k|wa$82wJ(`vP@#DM2{G@DI~F%N+A z4bFAWg_x+IxZnxWLtvNb6qS0uelwx{%dJ=d8I38+X z7^4!~$8j8#Qq0fKv$V8?wU(`|Eml@mI6gie`dw}uYTR{QmY0{Ao10^5YKqy}SpZ6< z5`{v6!^1<$Db1AEJxTsD_XD_0QgW0eIi#qx+w;x3@Qb28=NTL4Z;U ztrIp5zvuVAe<1HVCZ864NjR9*daU2td;f2Ca2Vk)JL;|S+(Ok_Ou+|bq z5n&h({n@$SOFH@*oIx^aDx)-Tc13wr#9Az=iFB7Kg9Jt}2a+TqilWyRK1jeAtW8Vk zgaM-kW9-m!%w6VE_*zMdV2xn3{98iMGjtgx)F1837JjmXdMl3LpinAZoswPx!wfh> zBlT|4dG|gcdFu5#?RI-);`@`>bS+6N=uYoR(#PtTOu%s*+Wvb4559$m3-H&I=gtF{ zz5nlYI=q>i;-(aEP4B!RB6uo?vbmR<1D(mqNp9BuAb7X{PpbeUH}LeyGd?JN%I&v4 zIepL-xFv5hF|qUC46LoKJ@$Qn{_bqrG=1+%_DLHX8*FZF4sCC>TGVQ_p8<2xt;B8L z_rLHwuQX0q5>XWW)@rrB0e-pgS_OCqaL4Rg#Q@E-31nnsWMpJyWMur0`3IRq1wrrQ RSUUg!002ovPDHLkV1lCGqgns} literal 0 HcmV?d00001 diff --git a/data/display-blanking-icon.2.png b/data/display-blanking-icon.2.png new file mode 100644 index 0000000000000000000000000000000000000000..d9adce42da8b210c41fbcd4a3c88ebb8400c3730 GIT binary patch literal 1638 zcmV-s2ATPZP)>+DQE+?{nN%hFlW zovzS7EVnQJ8=hz8KhMlF@c-D@&`KYMhK8O2dg~11nZCZh4_72GG&JW_EV=<$-|#&YwSz>$*gvQMPT{#@4M{ZzsF1 z%jL_L$!4=_2B(xl)3jxCOw(j;ZjLYv4+6^*NT<`Arl+TIT^9f$1Y=`k%+1Y}51FQs zNF=I8z_Kia5IBy*?CdO>rjbl04d6at{;mY>7DtX8scG39I&_GcnHj<`tSCQP54En8 zA`C-C>kf7#OH80!k@@AV3I#X_^EPpFcRiq)&a9XJQ8kf`GTwLBgj(zN7bZ;lhO#+th0T zJPboz*Tr!hgb-!lZrE8qzd2421jOTU(oTk))4=A>B@qLrtNKDgc zjyy_3Lj#s&5zzx$Hr341>nTMub$1 zW-l`~Hbz@p8>VU2W)74}p;Btu-1hc%)XrgSDY*Yr$)y`t8Qb|b5iO4PZ;2xv9(!Se zHx4|@$lIGZckW#E2&_g5V=;}NfBXs~Q@4wa7ykMV(Za&4GdSA(oZG)r4g^ywvjxnqwgSJP|1t?sW-2ej0wV<5i}or|*q` zH1Ef2`vx{~(&;q5@2?y1VvLWE^WdjH;JqKcL~8;F7Ou{R;5W~Gi^o5Di(}s(=FFKh zm6wpN>sX0)atA+v*L&gGIEN1(uF4{(>pK1Y{rvuiZ}O+~E4*_y|Gt0c_qh7oPTqa@ z4N|ET?d|Oq6YvbfpmFjuae3Y*MJIaX@CrG7I zBoYad$z)}we$Spgziw`Be%Z3DvV_*wR$5zIt45-!sfnH6ewd5b2he~g9(7k{rlH6P%)fC%Y*Xb`26^;1Gc;62#w zucnakyG^yo#-^&y5T~TJHs!BjgiR-%9wtY`qa#>PBO67qU2?$@5 zwH2)vaK~}5ZF|KNiX}~yl!QL0;`XZmzDS^IlX$VBtopz}2t=Ura{zT4e4c+@g_;L$EnLFAM-^Ji=vUJx8-{^3e+%Ke z*f(^DL+BJnK?hx!_p}bw+~^yI!L_R?4tD<(vBN9zhxr4qZI5meM+xtPsn-v|DqRgnJ( kQ7Z~y=R07*qoM6N<$f=Wdh%K!iX literal 0 HcmV?d00001 diff --git a/data/display-blanking-icon.3.png b/data/display-blanking-icon.3.png new file mode 100644 index 0000000000000000000000000000000000000000..6850b9a86836b4925f7ec85336147c406f4d1a8d GIT binary patch literal 578 zcmV-I0=@l-P)v z(P+HiC}7+6v%z5Sw$telhG8a>7YYTc)hgrh_(ikXe06dxe|oa(x-Z-9Hr;L)r4;#m zo=T-csZ{ziM=3?W-^cg;R0K@Z#PdAjI6eZ-7jPWs`eZUeDFr|jMGS{SJkR@k>kI=S z#NI;BW;3EFLQ0A2x)_FmWm!ewCh%jez&d)pUaH5YTrM-6PKo3A+nwqwSS)hm+h^v-b@xR$YcjREiU4rnwQjYgxbURcu_AF`T!n$0Z;n?6?*D@-=KG|;z8)K1oWcxR`F75 zp(1u^N&|tqCY#JOUaaW4-LADsQ<(3VnIyk2^PfLtK%>!UG#ZU&V~q1II*#)gsOBu| zn_8{*cCCQpI8O$H!Rv0fOB6-9NM0-!sZ=VA$Kz+MR_n#@W9He(v)Sxk)<_ zrfE_xmpM2%_%$aCL;C$bzVBxuU|ANP=b@B31TGeEUH9r_G9e5@0Hl-*heJHi`*Z0G z10h6eq382CQc8j#U^bg!7zVa&mw@ZQx0M2`Xf~UfmQB50XF8ptl)7-9nWtTvBne6> z;yA|l{k7q9BakEsQcB`D{^xtmT?dcj7%An(&oK8j_)Y|t^}Sduw)RYOUxQ~Nu-uqQ zlBD(yGmZLQe(^MeZ(ZPjTH#Iww%JiK6;Mi{l-gPFjRn%|D5(laDUnjn{pYAM(+T%?o{Hg5aOw2S@-i)>p>8F z^nL#&@L}z-3UCv+lC%A)0PpMyXfzs)Mx)Va_Lv`gWe1=~ift7D0000 Tue, 10 Jul 2012 19:52:11 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..2bec831 --- /dev/null +++ b/debian/control @@ -0,0 +1,13 @@ +Source: status-area-displayblanking-applet +Section: user/desktop +Priority: optional +Maintainer: Leandro Lucarella +Build-Depends: debhelper (>= 5), libgtk2.0-dev, libglib2.0-dev, libhildon1-dev, libhildondesktop1-dev, gettext + +Package: status-area-displayblanking-applet +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, hildon-desktop (>= 1:2.2.142-11) +XSBC-Maemo-Display-Name: Display Blanking Applet +Description: Hildon Status Menu plugin to control the display blanking mode. + This status menu applet let you easily change the display blanking mode right + from the status menu, without having to go through the settings. diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..5d7fa8c --- /dev/null +++ b/debian/install @@ -0,0 +1,7 @@ +data/display-blanking-icon.0.png usr/share/icons/hicolor/48x48/hildon +data/display-blanking-icon.1.png usr/share/icons/hicolor/48x48/hildon +data/display-blanking-icon.2.png usr/share/icons/hicolor/48x48/hildon +data/display-blanking-icon.3.png usr/share/icons/hicolor/48x48/hildon +data/display-blanking-icon.4.png usr/share/icons/hicolor/48x48/hildon +src/lib-displayblanking-status-menu.so usr/lib/hildon-desktop +data/status-area-displayblanking-applet.desktop usr/share/applications/hildon-status-menu diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..185125a --- /dev/null +++ b/debian/rules @@ -0,0 +1,49 @@ +#!/usr/bin/make -f +# Uncomment this to turn on verbose mode. +# export DH_VERBOSE=1 + +build: build-stamp + +build-stamp: + dh_testdir + $(MAKE) + touch build-stamp + +clean: + dh_testdir + dh_testroot + $(MAKE) clean + rm -f build-stamp install-stamp + # Add here commands to clean up after the build process. + dh_clean + +install: install-stamp +install-stamp: build-stamp + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + $(MAKE) DESTDIR=$(CURDIR)/debian/status-area-displayblanking-applet install + + touch install-stamp + +# Build architecture-independent files here. +binary-indep: build install + dh_testdir + dh_testroot + dh_install + #dh_installdocs + #dh_installchangelogs + #dh_compress + dh_fixperms + dh_shlibdeps + dh_makeshlibs + dh_installdeb + dh_gencontrol + dh_md5sums + dh_builddeb + +binary-arch: + +binary: binary-indep +.PHONY: build clean binary-arch binary-indep binary install diff --git a/po/Makefile b/po/Makefile new file mode 100644 index 0000000..e2423bf --- /dev/null +++ b/po/Makefile @@ -0,0 +1,76 @@ + + +GETTEXT_PACKAGE = status-area-displayblanking-applet +PACKAGE = status-area-displayblanking-applet + +SHELL = /bin/sh + +prefix = /usr +DATADIRNAME = share +itlocaledir = $(prefix)/$(DATADIRNAME)/locale + +INSTALL = install -c +INSTALL_DATA = ${INSTALL} -m 644 + +GMSGFMT = msgfmt +MSGFMT = msgfmt +XGETTEXT = xgettext +MSGMERGE = msgmerge + +PO_LINGUAS= es_AR + +USE_LINGUAS= es_AR + +POFILES=$(shell LINGUAS="$(PO_LINGUAS)"; for lang in $$LINGUAS; do printf "$$lang.po "; done) + +DISTFILES = Makefile POTFILES.in $(POFILES) +EXTRA_DISTFILES = ChangeLog POTFILES.skip Makevars LINGUAS + +POTFILES = ../src/lib-display-blanking-status-menu-widget.c +# This comment gets stripped out + +CATALOGS=$(shell LINGUAS="$(USE_LINGUAS)"; for lang in $$LINGUAS; do printf "$$lang.gmo "; done) + +.SUFFIXES: +.SUFFIXES: .po .gmo .mo + +.po.mo: + $(MSGFMT) -o $@ $< + +.po.gmo: + file=`echo $* | sed 's,.*/,,'`.gmo \ + && rm -f $$file && $(GMSGFMT) -o $$file $< + +all: compile + +compile: $(CATALOGS) + +$(GETTEXT_PACKAGE).pot: $(POTFILES) + $(XGETTEXT) --package-name=$(PACKAGE) -o $(GETTEXT_PACKAGE).pot $(POTFILES) + +install: all + @linguas="$(USE_LINGUAS)"; \ + for lang in $$linguas; do \ + dir=$(DESTDIR)$(itlocaledir)/$$lang/LC_MESSAGES; \ + mkdir -p $$dir; \ + if test -r $$lang.gmo; then \ + $(INSTALL_DATA) $$lang.gmo $$dir/$(GETTEXT_PACKAGE).mo; \ + echo "installing $$lang.gmo as $$dir/$(GETTEXT_PACKAGE).mo"; \ + fi; \ + done + +clean: + rm -f *.mo *.gmo + +update-po: + $(MAKE) $(GETTEXT_PACKAGE).pot + @linguas="$(USE_LINGUAS)"; \ + for lang in $$linguas; do \ + echo "$$lang:"; \ + if test -r $$lang.po; then \ + $(MSGMERGE) -U $$lang.po $(GETTEXT_PACKAGE).pot; \ + else \ + cp $(GETTEXT_PACKAGE).pot $$lang.po; \ + fi; \ + done + diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..c4b19e2 --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1 @@ +src/lib-display-blanking-status-menu-widget.c diff --git a/po/es_AR.po b/po/es_AR.po new file mode 100644 index 0000000..2a06e76 --- /dev/null +++ b/po/es_AR.po @@ -0,0 +1,44 @@ +# .pot file for display blanking applet. +# Copyright (C) 2012 +# This file is distributed under the same license as the status-area-displayblanking-applet package. +# Leandro Lucarella , 2012. +# +msgid "" +msgstr "" +"Project-Id-Version: status-area-displayblanking-applet\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-07-10 03:19+0200\n" +"PO-Revision-Date: 2012-07-10 02:14+0200\n" +"Last-Translator: Leandro Lucarella \n" +"Language-Team: Leandro Lucarella \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: ../src/lib-display-blanking-status-menu-widget.c:45 +msgid "Enabled" +msgstr "Activado" + +#: ../src/lib-display-blanking-status-menu-widget.c:46 +msgid "Only on battery" +msgstr "Sólo con batería" + +#: ../src/lib-display-blanking-status-menu-widget.c:47 +msgid "Blanking only on battery" +msgstr "Apagar sólo con batería" + +#: ../src/lib-display-blanking-status-menu-widget.c:48 +msgid "Disabled" +msgstr "Desactivado" + +#: ../src/lib-display-blanking-status-menu-widget.c:49 +msgid "Only dimming" +msgstr "Sólo ahorro de energía" + +#: ../src/lib-display-blanking-status-menu-widget.c:95 +msgid "Changed display blanking mode to: %s" +msgstr "Modo de apagado de pantalla cambiado a: %s" + +#: ../src/lib-display-blanking-status-menu-widget.c:117 +msgid "Display blanking mode" +msgstr "Apagado de pantalla" diff --git a/po/status-area-displayblanking-applet.pot b/po/status-area-displayblanking-applet.pot new file mode 100644 index 0000000..dd6f043 --- /dev/null +++ b/po/status-area-displayblanking-applet.pot @@ -0,0 +1,44 @@ +# .pot file for display blanking applet. +# Copyright (C) 2012 +# This file is distributed under the same license as the status-area-displayblanking-applet package. +# Leandro Lucarella , 2012. +# +msgid "" +msgstr "" +"Project-Id-Version: status-area-displayblanking-applet\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-07-10 03:19+0200\n" +"PO-Revision-Date: 2012-07-10 02:14+0200\n" +"Last-Translator: Leandro Lucarella \n" +"Language-Team: Leandro Lucarella \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: ../src/lib-display-blanking-status-menu-widget.c:45 +msgid "Enabled" +msgstr "" + +#: ../src/lib-display-blanking-status-menu-widget.c:46 +msgid "Only on battery" +msgstr "" + +#: ../src/lib-display-blanking-status-menu-widget.c:47 +msgid "Blanking only on battery" +msgstr "" + +#: ../src/lib-display-blanking-status-menu-widget.c:48 +msgid "Disabled" +msgstr "" + +#: ../src/lib-display-blanking-status-menu-widget.c:49 +msgid "Only dimming" +msgstr "" + +#: ../src/lib-display-blanking-status-menu-widget.c:95 +msgid "Changed display blanking mode to: %s" +msgstr "" + +#: ../src/lib-display-blanking-status-menu-widget.c:117 +msgid "Display blanking mode" +msgstr "" diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..20c4ad3 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,19 @@ +OBJS=lib-display-blanking-status-menu-widget.o +SOURCES=lib-display-blanking-status-menu-widget.c +LIB=lib-displayblanking-status-menu.so +PKG_FLAGS=$(shell pkg-config hildon-1 libhildondesktop-1 --libs --cflags) +CCFLAGS=-shared +CC=gcc + +all:$(LIB) + +$(LIB):$(OBJS) + $(CC) $(CCFLAGS) $(PKG_FLAGS) $(OBJS) -o $(LIB) + +.c.o: + $(CC) $(CCFLAGS) $(PKG_FLAGS) -c $< -o $@ + +.PHONE: clean all + +clean: + rm -f $(OBJS) $(LIB) diff --git a/src/lib-display-blanking-status-menu-widget.c b/src/lib-display-blanking-status-menu-widget.c new file mode 100644 index 0000000..1d7227e --- /dev/null +++ b/src/lib-display-blanking-status-menu-widget.c @@ -0,0 +1,186 @@ + /*********************************************************************************** + * Display blanking status area plugin + * Copyright (C) 2012 Leandro Lucarella + * Based on status-area-orientationlock-applet by Mohammad Abu-Garbeyyeh. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + ***********************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + + +#define TYPE_DISPLAY_BLANKING_STATUS_PLUGIN (display_blanking_status_plugin_get_type ()) + +#define DISPLAY_BLANKING_STATUS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + TYPE_DISPLAY_BLANKING_STATUS_PLUGIN, DisplayBlankingStatusPlugin)) + +#define DISPLAY_BLANKING_STATUS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \ + TYPE_DISPLAY_BLANKING_STATUS_PLUGIN, DisplayBlankingStatusPluginClass)) + +#define IS_DISPLAY_BLANKING_STATUS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + TYPE_DISPLAY_BLANKING_STATUS_PLUGIN)) + +#define IS_DISPLAY_BLANKING_STATUS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + TYPE_DISPLAY_BLANKING_STATUS_PLUGIN)) + +#define DISPLAY_BLANKING_STATUS_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + TYPE_DISPLAY_BLANKING_STATUS_PLUGIN, DisplayBlankingStatusPluginClass)) + +#define STATUS_AREA_DISPLAY_BLANKING_ICON_SIZE 18 + +typedef struct _DisplayBlankingStatusPlugin DisplayBlankingStatusPlugin; +typedef struct _DisplayBlankingStatusPluginClass DisplayBlankingStatusPluginClass; +typedef struct _DisplayBlankingStatusPluginPrivate DisplayBlankingStatusPluginPrivate; + +struct _DisplayBlankingStatusPlugin +{ + HDStatusMenuItem parent; + + DisplayBlankingStatusPluginPrivate *priv; +}; + +struct _DisplayBlankingStatusPluginClass +{ + HDStatusMenuItemClass parent; +}; + +GType display_blanking_status_plugin_get_type (void); + +#define DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE (obj, \ + TYPE_DISPLAY_BLANKING_STATUS_PLUGIN, \ + DisplayBlankingStatusPluginPrivate)) + +#define GCONF_KEY_DISPLAY_BLANKING "/system/osso/dsm/display/inhibit_blank_mode" + +// Shoud contain one, and only one "%d" +#define DISPLAY_BLANKING_ICON_TEMPLATE "display-blanking-icon.%d" + +#define GETTEXT_DOM "status-area-displayblanking-applet" +#define gettext_noop(str) (str) + +#define DISPLAY_BLANKING_MODES 5 +static const char *_DisplayBlankingDescription[DISPLAY_BLANKING_MODES] = +{ + gettext_noop ("Both enabled"), + gettext_noop ("Both only on battery"), + gettext_noop ("Blanking only on battery"), + gettext_noop ("Both disabled"), + gettext_noop ("Only dimming") +}; + +struct _DisplayBlankingStatusPluginPrivate +{ + GtkWidget *button; + GConfClient *gconf_client; + gpointer data; +}; + +HD_DEFINE_PLUGIN_MODULE (DisplayBlankingStatusPlugin, + display_blanking_status_plugin, HD_TYPE_STATUS_MENU_ITEM); + +static void +display_blanking_status_plugin_class_finalize ( + DisplayBlankingStatusPluginClass *klass) +{ +} + +static void +display_blanking_status_plugin_class_init (DisplayBlankingStatusPluginClass *c) +{ + g_type_class_add_private (c, sizeof (DisplayBlankingStatusPluginPrivate)); +} + +static void +display_blanking_status_plugin_mode_set (DisplayBlankingStatusPluginPrivate *priv, + gboolean update) +{ + // Should be enough if DISPLAY_BLANKING_MODES stays in 1 digit, "%d" + // provides space for that digit and '\0' + static char icon_name[sizeof (DISPLAY_BLANKING_ICON_TEMPLATE)]; + + // Get the mode to set + gint mode = gconf_client_get_int (priv->gconf_client, + GCONF_KEY_DISPLAY_BLANKING, NULL); + if (update) + mode = (mode + 1) % DISPLAY_BLANKING_MODES; + + // Toggle display blanking + gconf_client_set_int (priv->gconf_client, GCONF_KEY_DISPLAY_BLANKING, + mode, NULL); + + // Update button text and status bar icon + hildon_button_set_value (HILDON_BUTTON (priv->button), + dgettext (GETTEXT_DOM, _DisplayBlankingDescription[mode])); + int r = snprintf (icon_name, sizeof (icon_name), + DISPLAY_BLANKING_ICON_TEMPLATE, mode); + g_assert(r < sizeof (icon_name)); // otherwise it was truncated + GtkWidget *icon = gtk_image_new_from_icon_name (icon_name, + GTK_ICON_SIZE_DIALOG); + hildon_button_set_image (HILDON_BUTTON (priv->button), icon); + + // Show a notification banner (only if updating) + if (update) { + GtkWidget *banner = hildon_banner_show_informationf (priv->button, NULL, + dgettext (GETTEXT_DOM, "Changed display blanking mode to: %s"), + _DisplayBlankingDescription[mode]); + hildon_banner_set_timeout (HILDON_BANNER (banner), 5000); + } +} + +static void +display_blanking_status_plugin_on_button_clicked (GtkWidget *button, + DisplayBlankingStatusPlugin *plugin) +{ + display_blanking_status_plugin_mode_set ( + DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE (plugin), TRUE); +} + +static void +display_blanking_status_plugin_init (DisplayBlankingStatusPlugin *plugin) +{ + plugin->priv = DISPLAY_BLANKING_STATUS_PLUGIN_GET_PRIVATE (plugin); + + plugin->priv->gconf_client = gconf_client_get_default(); + g_assert(GCONF_IS_CLIENT(plugin->priv->gconf_client)); + + plugin->priv->button = hildon_button_new (HILDON_SIZE_FINGER_HEIGHT | + HILDON_SIZE_AUTO_WIDTH, HILDON_BUTTON_ARRANGEMENT_VERTICAL); + gtk_button_set_alignment (GTK_BUTTON (plugin->priv->button), 0, 0); + hildon_button_set_style (HILDON_BUTTON (plugin->priv->button), + HILDON_BUTTON_STYLE_PICKER); + hildon_button_set_title (HILDON_BUTTON (plugin->priv->button), + dgettext (GETTEXT_DOM, "Display blanking mode")); + + display_blanking_status_plugin_mode_set (plugin->priv, FALSE); + + g_signal_connect (plugin->priv->button, "clicked", + G_CALLBACK (display_blanking_status_plugin_on_button_clicked), + plugin); + + gtk_container_add (GTK_CONTAINER (plugin), plugin->priv->button); + + gtk_widget_show_all (plugin->priv->button); + + gtk_widget_show (GTK_WIDGET (plugin)); +} + -- 2.43.0