diff -Nru aptik-battery-monitor-2.1/aptik-battery-monitor.geany aptik-battery-monitor-17.12/aptik-battery-monitor.geany --- aptik-battery-monitor-2.1/aptik-battery-monitor.geany 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/aptik-battery-monitor.geany 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -[indentation] -indent_width=4 -indent_type=1 -indent_hard_tab_width=8 -detect_indent=false -detect_indent_width=false -indent_mode=2 - -[project] -name=aptik-battery-monitor -base_path=/home/teejee/projects/linux/aptik-battery-monitor -description= -file_patterns= - -[long line marker] -long_line_behaviour=1 -long_line_column=80 - -[files] -current_page=8 -FILE_NAME_0=2043;Make;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2Fmakefile;0;4 -FILE_NAME_1=2480;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FBatteryStatsWindow.vala;0;4 -FILE_NAME_2=0;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FAboutWindow.vala;0;4 -FILE_NAME_3=1171;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FAptikBatteryStats.vala;0;4 -FILE_NAME_4=594;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FAptikBatteryStatsGtk.vala;0;4 -FILE_NAME_5=0;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FBatteryBar.vala;0;4 -FILE_NAME_6=6228;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FClasses.vala;0;4 -FILE_NAME_7=0;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FDonationWindow.vala;0;4 -FILE_NAME_8=1108;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FMain.vala;0;4 -FILE_NAME_9=1827;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FSettingsWindow.vala;0;4 -FILE_NAME_10=243;Sh;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fdebian%2Faptik-battery-monitor.postinst;0;4 -FILE_NAME_11=0;Sh;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fdebian%2Faptik-battery-monitor.prerm;0;4 -FILE_NAME_12=472;None;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fdebian%2Fchangelog;0;4 -FILE_NAME_13=37771;Vala;0;EUTF-8;1;1;1;%2Fhome%2Fteejee%2Fprojects%2Flinux%2Faptik-battery-monitor%2Fsrc%2FUtility.vala;0;4 - -[VTE] -last_dir=/media/teejee/f0d933c0-b510-470e-a0ad-a4d42db19453/Dropbox/projects/linux - -[build-menu] -ValaFT_00_LB=_Compile -ValaFT_00_CM= -ValaFT_00_WD= -filetypes=Vala; -NF_00_LB=_Make -NF_00_CM=make all -NF_00_WD= -NF_03_LB=Clean -NF_03_CM=make clean -NF_03_WD= -EX_00_LB=Exec Monitor -EX_00_CM=./aptik-battery-monitor-gtk -EX_00_WD= -EX_01_LB=Exec Bar -EX_01_CM=./aptik-battery-bar -EX_01_WD= -ValaFT_01_LB=_Build -ValaFT_01_CM=make all -ValaFT_01_WD= -NF_01_LB= -NF_01_CM= -NF_01_WD= -NF_02_LB=Install -NF_02_CM=gksu make install -NF_02_WD= - -[file_prefs] -final_new_line=true -ensure_convert_new_lines=false -strip_trailing_spaces=false -replace_tabs=false diff -Nru aptik-battery-monitor-2.1/aptik-battery-monitor.pot aptik-battery-monitor-17.12/aptik-battery-monitor.pot --- aptik-battery-monitor-2.1/aptik-battery-monitor.pot 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/aptik-battery-monitor.pot 2017-12-10 14:02:06.000000000 +0000 @@ -1,6 +1,6 @@ # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR Tony George (teejee2008@gmail.com) -# This file is distributed under the same license as the PACKAGE package. +# This file is distributed under the same license as the aptik-battery-monitor package. # FIRST AUTHOR , YEAR. # #, fuzzy @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: aptik-battery-monitor 1.6\n" "Report-Msgid-Bugs-To: teejee2008@gmail.com\n" -"POT-Creation-Date: 2015-12-13 21:50+0530\n" +"POT-Creation-Date: 2017-12-10 18:57+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,269 +17,152 @@ "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: BatteryStatsWindow.vala:236 -msgid " A Battery Monitoring Utility for Laptops" +#: DiskIndicator.vala:211 +msgid "About" msgstr "" -#: Utility.vala:1685 -msgid "" -"/var/spool on your system is mounted in memory (tmpfs)!!\n" -"\n" -"/var/spool should never be mounted in tmpfs as the user's cron jobs are " -"stored here along with other system files. If you have done this to reduce " -"writes to your SSD, please undo it by editing your /etc/fstab file. This " -"application will not work till this is corrected." -msgstr "" - -#: BatteryStatsWindow.vala:573 -msgid "0.0%" -msgstr "" - -#: BatteryStatsWindow.vala:534 BatteryStatsWindow.vala:543 -#: BatteryStatsWindow.vala:553 BatteryStatsWindow.vala:563 -msgid "0h 0m" -msgstr "" - -#: Main.vala:206 -msgid "App config loaded" -msgstr "" - -#: Main.vala:184 -msgid "App config saved" -msgstr "" - -#: BatteryStatsWindow.vala:207 -msgid "Application Info" -msgstr "" - -#: Main.vala:305 -#, c-format -msgid "Archived" -msgstr "" - -#: AboutWindow.vala:330 -#, c-format -msgid "Artists" +#: DiskIndicator.vala:871 +msgid "Disk Indicator for Linux" msgstr "" -#: AboutWindow.vala:314 +#: DiskIndicator.vala:470 #, c-format -msgid "Authors" -msgstr "" - -#: BatteryStatsWindow.vala:539 -msgid "Average Life" -msgstr "" - -#: AboutWindow.vala:285 -msgid "Back" +msgid "Disk can be safely removed" msgstr "" -#: BatteryStatsWindow.vala:283 BatteryStatsWindow.vala:531 -#: BatteryStatsWindow.vala:619 -msgid "Battery" +#: DiskIndicator.vala:220 +msgid "Donate" msgstr "" -#: BatteryStatsWindow.vala:289 -msgid "CPU" +#: DiskIndicator.vala:774 +msgid "Encrypted Device" msgstr "" -#: Main.vala:314 +#: DiskIndicator.vala:775 #, c-format -msgid "Charging" -msgstr "" - -#: AboutWindow.vala:295 -msgid "Close" +msgid "Enter passphrase to unlock '%s'" msgstr "" -#: Main.vala:149 -msgid "Commands listed below are not available on this system" +#: DiskIndicator.vala:229 +msgid "Exit" msgstr "" -#: AboutWindow.vala:272 AboutWindow.vala:289 -msgid "Credits" +#: DiskIndicator.vala:645 +msgid "Failed to lock" msgstr "" -#: Utility.vala:1624 Utility.vala:1653 -msgid "Crontab is empty" +#: DiskIndicator.vala:669 +msgid "Failed to unlock" msgstr "" -#: BatteryStatsWindow.vala:282 -msgid "Date" +#: DiskIndicator.vala:174 +msgid "ISO" msgstr "" -#: DonationWindow.vala:54 -msgid "" -"Did you find this software useful?\n" -"\n" -"You can buy me a coffee or make a donation via PayPal to show your support. " -"Or just drop me an email and say Hi. This application is completely free and " -"will continue to remain that way. Your contributions will help in keeping " -"this project alive and improving it further.\n" -"\n" -"Feel free to send me an email if you find any issues in this application or " -"if you need any changes. Suggestions and feedback are always welcome.\n" -"\n" -"Thanks,\n" -"Tony George\n" -"(teejeetech@gmail.com)" -msgstr "" - -#: AboutWindow.vala:346 +#: DiskIndicator.vala:538 #, c-format -msgid "Documenters" -msgstr "" - -#: BatteryStatsWindow.vala:187 BatteryStatsWindow.vala:189 -#: DonationWindow.vala:36 -msgid "Donate" -msgstr "" - -#: DonationWindow.vala:74 -msgid "Donate with Google Wallet" +msgid "Is Mounted" msgstr "" -#: DonationWindow.vala:67 -msgid "Donate with PayPal" +#: DiskIndicator.vala:119 +msgid "Lock" msgstr "" -#: AboutWindow.vala:354 +#: DiskIndicator.vala:640 #, c-format -msgid "Donations" +msgid "Locked" msgstr "" -#: Utility.vala:100 -msgid "Error" -msgstr "" - -#: Utility.vala:1838 -msgid "Failed to set ownership" +#: AptikBatteryStats.vala:52 +#, c-format +msgid "Logging stats to file" msgstr "" -#: Main.vala:397 -msgid "File not found" +#: DiskIndicator.vala:82 +msgid "Mount" msgstr "" -#: BatteryStatsWindow.vala:205 -msgid "Info" +#: DiskIndicator.vala:694 +msgid "Mount ISO..." msgstr "" -#: AptikBatteryStats.vala:54 Main.vala:306 +#: DiskIndicator.vala:531 #, c-format -msgid "Logging stats to file" +msgid "Mounted" msgstr "" -#: Main.vala:338 +#: DiskIndicator.vala:722 #, c-format -msgid "Logging summary to file" -msgstr "" - -#: Main.vala:92 -msgid "Missing Dependencies" +msgid "Mounted ISO File" msgstr "" -#: Utility.vala:1189 -msgid "Missing Icon" +#: DiskIndicator.vala:587 +#, c-format +msgid "Not mounted" msgstr "" -#: DonationWindow.vala:95 SettingsWindow.vala:77 -msgid "OK" +#: DiskIndicator.vala:47 +msgid "Open" msgstr "" -#: AptikBatteryStats.vala:85 AptikBatteryStatsGtk.vala:100 +#: AptikBatteryStats.vala:83 msgid "Options" msgstr "" -#: BatteryStatsWindow.vala:569 -msgid "Per Hour" -msgstr "" - -#: Main.vala:150 -msgid "Please install the required packages" -msgstr "" - -#: AptikBatteryStatsGtk.vala:102 -msgid "Print debug information" -msgstr "" - -#: AptikBatteryStats.vala:88 +#: AptikBatteryStats.vala:86 msgid "Print stats from log file sand quit" msgstr "" -#: AptikBatteryStats.vala:87 +#: AptikBatteryStats.vala:85 msgid "Print stats to standard output" msgstr "" -#: BatteryStatsWindow.vala:549 -msgid "Remaining" -msgstr "" - -#: Main.vala:281 -#, c-format -msgid "Removed from charger" -msgstr "" - -#: DonationWindow.vala:81 -msgid "Send Email" -msgstr "" - -#: SettingsWindow.vala:43 +#: DiskIndicator.vala:193 msgid "Settings" msgstr "" -#: AptikBatteryStats.vala:89 AptikBatteryStatsGtk.vala:103 +#: AptikBatteryStats.vala:87 msgid "Show all options" msgstr "" -#: SettingsWindow.vala:61 -msgid "Show battery bar" +#: DiskIndicator.vala:481 +msgid "Swap Device!" msgstr "" -#: Utility.vala:837 -msgid "Stopped" +#: DiskIndicator.vala:482 +msgid "Swap devices cannot be opened in file manager" msgstr "" -#: AptikBatteryStats.vala:83 AptikBatteryStatsGtk.vala:98 +#: AptikBatteryStats.vala:81 msgid "Syntax" msgstr "" -#: AboutWindow.vala:322 -#, c-format -msgid "Third Party Tools" +#: DiskIndicator.vala:568 DiskIndicator.vala:617 +msgid "System Device!" msgstr "" -#: BatteryStatsWindow.vala:559 -msgid "To Full Charge" +#: DiskIndicator.vala:569 DiskIndicator.vala:618 +msgid "System devices cannot be unmounted" msgstr "" -#: AboutWindow.vala:338 -#, c-format -msgid "Translators" -msgstr "" - -#: AptikBatteryStatsGtk.vala:85 -msgid "Unknown option" +#: DiskIndicator.vala:136 +msgid "Unlock" msgstr "" -#: BatteryStatsWindow.vala:637 -msgid "Used" -msgstr "" - -#: DonationWindow.vala:88 -msgid "Visit Website" +#: DiskIndicator.vala:664 +#, c-format +msgid "Unlocked" msgstr "" -#: Utility.vala:100 -msgid "Warning" +#: DiskIndicator.vala:99 +msgid "Unmount" msgstr "" -#: Utility.vala:992 +#: DiskIndicator.vala:469 DiskIndicator.vala:581 #, c-format -msgid "[Error] Another instance of this process is already running" +msgid "Unmounted" msgstr "" -#: Utility.vala:998 -#, c-format -msgid "[Warning] Removed invalid lock file" +#: DiskIndicator.vala:155 +msgid "Usage" msgstr "" diff -Nru aptik-battery-monitor-2.1/BUILD_CONFIG aptik-battery-monitor-17.12/BUILD_CONFIG --- aptik-battery-monitor-2.1/BUILD_CONFIG 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/BUILD_CONFIG 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,6 @@ + +app_fullname="Aptik Battery Monitor" +app_name="aptik-battery-monitor" +pkg_name="aptik-battery-monitor" +pkg_version=$(dpkg-parsechangelog --show-field Version) +git_origin="" diff -Nru aptik-battery-monitor-2.1/build-deb-install.sh aptik-battery-monitor-17.12/build-deb-install.sh --- aptik-battery-monitor-2.1/build-deb-install.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/build-deb-install.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,22 +0,0 @@ -#!/bin/bash - -backup=`pwd` -DIR="$( cd "$( dirname "$0" )" && pwd )" -cd "$DIR" - -rm -rf ../builds - -bzr builddeb --native --build-dir ../builds/temp --result-dir ../builds - -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -ls -l ../builds - -sudo dpkg -i ../builds/*.deb - -cd "$backup" diff -Nru aptik-battery-monitor-2.1/build-deb.sh aptik-battery-monitor-17.12/build-deb.sh --- aptik-battery-monitor-2.1/build-deb.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/build-deb.sh 2017-12-10 14:02:06.000000000 +0000 @@ -2,19 +2,47 @@ backup=`pwd` DIR="$( cd "$( dirname "$0" )" && pwd )" -cd "$DIR" +cd $DIR -rm -rf ../builds +. ./BUILD_CONFIG -bzr builddeb --native --build-dir ../builds/temp --result-dir ../builds +sh build-source.sh -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi +rm -fv release/${pkg_name}-*.deb -ls -l ../builds +build_deb_for_dist() { + +dist=$1 +arch=$2 + +echo "" +echo "==========================================================================" +echo " build-deb.sh : $dist-$arch" +echo "==========================================================================" +echo "" + +rm -rfv release/${arch} +mkdir -pv release/${arch} + +echo "-------------------------------------------------------------------------" + +pbuilder-dist $dist $arch build release/source/${pkg_name}*.dsc --buildresult release/$arch + +if [ $? -ne 0 ]; then cd "$backup"; echo "Failed"; exit 1; fi + +echo "--------------------------------------------------------------------------" + +cp -pv --no-preserve=ownership release/${arch}/${pkg_name}*.deb release/${pkg_name}-v${pkg_version}-${arch}.deb + +if [ $? -ne 0 ]; then cd "$backup"; echo "Failed"; exit 1; fi + +echo "--------------------------------------------------------------------------" + +} + +build_deb_for_dist xenial i386 +build_deb_for_dist xenial amd64 +#build_deb_for_dist stretch armel +#build_deb_for_dist stretch armhf cd "$backup" diff -Nru aptik-battery-monitor-2.1/build-installer.sh aptik-battery-monitor-17.12/build-installer.sh --- aptik-battery-monitor-2.1/build-installer.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/build-installer.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -#!/bin/bash - -app_name='aptik-battery-monitor' -app_fullname='Aptik Battery Monitor' -tgz="../../pbuilder/" -dsc="../../builds/${app_name}*.dsc" -libs="../../libs" - -backup=`pwd` -DIR="$( cd "$( dirname "$0" )" && pwd )" -cd $DIR - -sh build-source.sh -cd installer - -echo "Building installer..." - -chmod u+x ./install.sh - -# build installer ------------------------------------- - -for arch in i386 amd64 -do - -rm -rf ${arch} -mkdir -p ${arch} - -sudo pbuilder --build --buildresult ${arch} --basetgz "${tgz}base-${arch}.tgz" ${dsc} - -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -dpkg-deb -x ${arch}/${app_name}*.deb ${arch}/extracted - -cp -p --no-preserve=ownership -t ${arch}/extracted ./install.sh -cp -p --no-preserve=ownership -t ${arch}/extracted/usr/share/${app_name}/libs ${libs}/${arch}/libgee.so.2 -cp -p --no-preserve=ownership -t ${arch}/extracted/usr/share/${app_name}/libs ${libs}/${arch}/libjson-glib-1.0.so.0 -chmod --recursive 0755 ${arch}/extracted/usr/share/${app_name} - -makeself ${arch}/extracted ./${app_name}-latest-${arch}.run "${app_fullname} (${arch})" ./install.sh - -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -cp -p --no-preserve=ownership ./${arch}/${app_name}*.deb ./${app_name}-latest-${arch}.deb - -done - -cd "$backup" diff -Nru aptik-battery-monitor-2.1/build-installers.sh aptik-battery-monitor-17.12/build-installers.sh --- aptik-battery-monitor-2.1/build-installers.sh 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/build-installers.sh 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,59 @@ +#!/bin/bash + +backup=`pwd` +DIR="$( cd "$( dirname "$0" )" && pwd )" +cd $DIR + +. ./BUILD_CONFIG + +rm -vf release/*.run +rm -vf release/*.deb + +# build debs +sh build-deb.sh + + +for arch in i386 amd64 +do + +rm -rfv release/${arch}/files +mkdir -pv release/${arch}/files + +echo "" +echo "==========================================================================" +echo " build-installers.sh : $arch" +echo "==========================================================================" +echo "" + +dpkg-deb -x release/${pkg_name}-v${pkg_version}-${arch}.deb release/${arch}/files + +if [ $? -ne 0 ]; then cd "$backup"; echo "Failed"; exit 1;fi + +echo "--------------------------------------------------------------------------" + +rm -rfv release/${arch}/${pkg_name}*.* # remove source files created by pbuilder + +cp -pv --no-preserve=ownership release/sanity.config release/${arch}/sanity.config + +if [ -e release/preinst.sh ]; then + cp -pv --no-preserve=ownership release/preinst.sh release/${arch}/preinst.sh +fi + +if [ -e release/postinst.sh ]; then + cp -pv --no-preserve=ownership release/postinst.sh release/${arch}/postinst.sh +fi + +sanity --generate --base-path release/${arch} --out-path release --arch ${arch} + +if [ $? -ne 0 ]; then cd "$backup"; echo "Failed"; exit 1; fi + +mv -v release/*${arch}.run release/${pkg_name}-v${pkg_version}-${arch}.run + +echo "--------------------------------------------------------------------------" + +done + +cp -vf release/*.run ../PACKAGES/ +cp -vf release/*.deb ../PACKAGES/ + +cd "$backup" diff -Nru aptik-battery-monitor-2.1/build-install.sh aptik-battery-monitor-17.12/build-install.sh --- aptik-battery-monitor-2.1/build-install.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/build-install.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -#!/bin/bash - -backup=`pwd` -DIR="$( cd "$( dirname "$0" )" && pwd )" -cd "$DIR" - -sh build-deb.sh - -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -sudo gdebi --non-interactive ../builds/aptik-battery-monitor*.deb - -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -cd "$backup" diff -Nru aptik-battery-monitor-2.1/build-release.sh aptik-battery-monitor-17.12/build-release.sh --- aptik-battery-monitor-2.1/build-release.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/build-release.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,31 +0,0 @@ -#!/bin/bash - -backup=`pwd` -DIR="$( cd "$( dirname "$0" )" && pwd )" -cd "$DIR" - -sh build-installer.sh -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -cd installer -for arch in i386 amd64 -do - cp -p --no-preserve=ownership -t /home/teejee/Dropbox/Public/linux ./aptik-battery-monitor-latest-${arch}.run - cp -p --no-preserve=ownership -t /home/teejee/Dropbox/Public/linux ./aptik-battery-monitor-latest-${arch}.deb -done -cd .. - -sh push.sh -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -cd "$backup" diff -Nru aptik-battery-monitor-2.1/build-source.sh aptik-battery-monitor-17.12/build-source.sh --- aptik-battery-monitor-2.1/build-source.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/build-source.sh 2017-12-10 14:02:06.000000000 +0000 @@ -4,24 +4,43 @@ DIR="$( cd "$( dirname "$0" )" && pwd )" cd "$DIR" -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -rm -rf ../builds - -bzr builddeb --source --native --build-dir ../builds/temp --result-dir ../builds - -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi +. ./BUILD_CONFIG -ls -l ../builds +echo "" +echo "==========================================================================" +echo " build-source.sh" +echo "==========================================================================" +echo "" + +echo "app_name: $app_name" +echo "pkg_name: $pkg_name" +echo "--------------------------------------------------------------------------" + +# clean build dir + +rm -rfv /tmp/builds +mkdir -pv /tmp/builds + +make clean + +rm -rfv release/source +mkdir -pv release/source + +echo "--------------------------------------------------------------------------" + +# build source package +dpkg-source --build ./ + +mv -vf ../$pkg_name*.dsc release/source/ +mv -vf ../$pkg_name*.tar.xz release/source/ + +if [ $? -ne 0 ]; then cd "$backup"; echo "Failed"; exit 1; fi + +echo "--------------------------------------------------------------------------" + +# list files +ls -l release/source + +echo "-------------------------------------------------------------------------" cd "$backup" diff -Nru aptik-battery-monitor-2.1/debian/aptik-battery-monitor.appdata.xml aptik-battery-monitor-17.12/debian/aptik-battery-monitor.appdata.xml --- aptik-battery-monitor-2.1/debian/aptik-battery-monitor.appdata.xml 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/debian/aptik-battery-monitor.appdata.xml 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,27 @@ + + + + aptik-battery-monitor.desktop + CC-BY-SA-3.0 + GPL-3.0 + Aptik Battery Monitor + Battery Monitor for laptops + + +

+ Battery monitor for laptops. Displays detailed statistics for battery life, remaining capacity, and charge/discharge rate. +

+
+ + + + https://raw.githubusercontent.com/teejee2008/battery-monitor/master/images/discharging.png + + + https://raw.githubusercontent.com/teejee2008/battery-monitor/master/images/charging.png + + + + https://github.com/teejee2008/battery-monitor +
+ diff -Nru aptik-battery-monitor-2.1/debian/bzr-builder.manifest aptik-battery-monitor-17.12/debian/bzr-builder.manifest --- aptik-battery-monitor-2.1/debian/bzr-builder.manifest 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/debian/bzr-builder.manifest 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -# bzr-builder format 0.3 deb-version {debupstream}-0~42 -lp:~teejee2008/aptik-bmon/trunk revid:tony.george.kol@gmail.com-20151213162855-ye9sngltyb64g2xd diff -Nru aptik-battery-monitor-2.1/debian/changelog aptik-battery-monitor-17.12/debian/changelog --- aptik-battery-monitor-2.1/debian/changelog 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/debian/changelog 2017-12-10 14:02:06.000000000 +0000 @@ -1,9 +1,18 @@ -aptik-battery-monitor (2.1-0~42~ubuntu16.04.1) xenial; urgency=low +aptik-battery-monitor (17.12-0~201712101351~ubuntu16.04.1) xenial; urgency=low * Auto build. - -- Tony George Mon, 14 Dec 2015 11:48:00 +0000 + -- Tony George Sun, 10 Dec 2017 14:02:06 +0000 +aptik-battery-monitor (17.12) xenial; urgency=low + + * Display battery health in dashboard + * Updated build scripts + * Added appdata file + * UI improvements + + -- Tony George Sun, 10 Dec 2017 10:00:00 +0530 + aptik-battery-monitor (2.1) trusty; urgency=low * Rotate log file when laptop is removed from charger diff -Nru aptik-battery-monitor-2.1/debian/control aptik-battery-monitor-17.12/debian/control --- aptik-battery-monitor-2.1/debian/control 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/debian/control 2017-12-10 14:02:06.000000000 +0000 @@ -2,7 +2,7 @@ Section: utils Priority: extra Maintainer: Tony George -Build-Depends: debhelper (>= 8.0.0), autotools-dev, valac-0.26, libgtk-3-dev, libgee-0.8-dev, libjson-glib-dev +Build-Depends: debhelper (>= 8.0.0), autotools-dev, valac, libgtk-3-dev, libgee-0.8-dev, libjson-glib-dev Standards-Version: 3.9.3 Homepage: http://teejeetech.blogspot.in/ #Vcs-Git: git://git.debian.org/collab-maint/hello.git diff -Nru aptik-battery-monitor-2.1/debian/git-build-recipe.manifest aptik-battery-monitor-17.12/debian/git-build-recipe.manifest --- aptik-battery-monitor-2.1/debian/git-build-recipe.manifest 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/debian/git-build-recipe.manifest 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,2 @@ +# git-build-recipe format 0.4 deb-version {debupstream}-0~201712101351 +lp:battery-monitor-github git-commit:66bc9be6519d4afc5eddfd9e4eb5fd231e2cf141 Binary files /tmp/tmpF0b_b3/bF366is5cZ/aptik-battery-monitor-2.1/images/charging.png and /tmp/tmpF0b_b3/zVdvlSnfmX/aptik-battery-monitor-17.12/images/charging.png differ Binary files /tmp/tmpF0b_b3/bF366is5cZ/aptik-battery-monitor-2.1/images/discharging.png and /tmp/tmpF0b_b3/zVdvlSnfmX/aptik-battery-monitor-17.12/images/discharging.png differ Binary files /tmp/tmpF0b_b3/bF366is5cZ/aptik-battery-monitor-2.1/images/patreon.png and /tmp/tmpF0b_b3/zVdvlSnfmX/aptik-battery-monitor-17.12/images/patreon.png differ Binary files /tmp/tmpF0b_b3/bF366is5cZ/aptik-battery-monitor-2.1/images/PayPal.png and /tmp/tmpF0b_b3/zVdvlSnfmX/aptik-battery-monitor-17.12/images/PayPal.png differ diff -Nru aptik-battery-monitor-2.1/INSTALL aptik-battery-monitor-17.12/INSTALL --- aptik-battery-monitor-2.1/INSTALL 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/INSTALL 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,6 @@ + +# build +make all + +# install +sudo make install diff -Nru aptik-battery-monitor-2.1/installer/install.sh aptik-battery-monitor-17.12/installer/install.sh --- aptik-battery-monitor-2.1/installer/install.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/installer/install.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,202 +0,0 @@ -#!/bin/bash - -app_name='aptik-battery-monitor' -app_fullname='Aptik Battery Monitor' - -generic_depends=() -debian_depends=() -redhat_depends=() -arch_depends=() - -generic_recommends=() -debian_recommends=() -redhat_recommends=() -arch_recommends=() - -Reset='\e[0m' -Red='\e[1;31m' -Green='\e[1;32m' -Yellow='\e[1;33m' - -CHECK_COLOR_SUPPORT() { - colors=`tput colors` - if [ $colors -gt 1 ]; then - COLORS_SUPPORTED=0 - else - COLORS_SUPPORTED=1 - fi -} - -MSG_INFO() { - add_newline='' - if [ "$2" == 0 ]; then - add_newline='-n' - fi - - if [ $COLORS_SUPPORTED -eq 0 ]; then - echo -e ${add_newline} "[${Yellow}*${Reset}] ${Green}$1${Reset}" - else - echo -e ${add_newline} "[*] $1" - fi -} - -MSG_WARNING() { - add_newline='' - if [ "$2" == 0 ]; then - add_newline='-n' - fi - - if [ $COLORS_SUPPORTED -eq 0 ]; then - echo -e ${add_newline} "[${Red}!${Reset}] ${Yellow}$1${Reset}" - else - echo -e ${add_newline} "[!] $1" - fi -} - -MSG_ERROR() { - add_newline='' - if [ "$2" == 0 ]; then - add_newline='-n' - fi - - if [ $COLORS_SUPPORTED -eq 0 ]; then - echo -e ${add_newline} "[${Red}X${Reset}] ${Yellow}$1${Reset}" - else - echo -e ${add_newline} "[X] $1" - fi -} - -CD_PUSH() { - cd_backup=`pwd` -} - -CD_POP() { - if [ ! -z "${cd_backup}" ]; then - cd "${cd_backup}" - fi -} - -BACKUP_IFS(){ - IFS_backup="${IFS}" -} - -SET_IFS_NEWLINE(){ - IFS=$'\n' -} - -RESET_IFS() { - if [ ! -z "${IFS_backup}" ]; then - IFS="${IFS_backup}" - fi -} - -EXIT(){ - RESET_IFS - CD_POP - exit $1 -} - -WAIT_FOR_INPUT() { - echo "" - echo "Press any key to exit..." - read dummy -} - -GET_SCRIPT_PATH(){ - SCRIPTPATH="$(cd "$(dirname "$0")" && pwd)" - SCRIPTNAME=`basename $0` -} - -RUN_AS_ADMIN() { - if [ ! `id -u` -eq 0 ]; then - GET_SCRIPT_PATH - if command -v sudo >/dev/null 2>&1; then - sudo "${SCRIPTPATH}/${SCRIPTNAME}" - EXIT $? - elif command -v su >/dev/null 2>&1; then - su -c "${SCRIPTPATH}/${SCRIPTNAME}" - EXIT $? - else - echo "" - MSG_ERROR "** Installer must be run as Admin (using 'sudo' or 'su') **" - echo "" - EXIT 1 - fi - fi -} - -CD_PUSH -CHECK_COLOR_SUPPORT -RUN_AS_ADMIN -BACKUP_IFS - -if ! command -v apt-get >/dev/null 2>&1; then - MSG_ERROR "'apt-get' not found" - MSG_ERROR "This application can be used only on Debian-based systems" - WAIT_FOR_INPUT - EXIT 1 -fi - -SET_IFS_NEWLINE - -MSG_INFO "Expanding directories..." -for f in `find ./ -type d -exec echo "{}" \;`; do - directory=`echo "$f" | sed -r 's/^.{2}//'` - mkdir -p -m 755 "/$directory" - echo "/$directory" -done -echo "" - -MSG_INFO "Installing files..." -for f in `find ./ -type f \( ! -iname "install.sh" \) -exec echo "{}" \;`; do - file=`echo "$f" | sed -r 's/^.{2}//'` - install -m 0755 "./$file" "/$file" - echo "/$file" -done -echo "" - -RESET_IFS - -install_dependencies=y - -if command -v apt-get >/dev/null 2>&1; then - - if [ -f /etc/debian_version ]; then - install_dependencies=y - else - MSG_INFO "Found 'apt-get' package manager" - MSG_INFO "Install dependencies with 'apt-get'? (y/n):" "0" - read install_dependencies - if [ "$install_dependencies" == "" ]; then - install_dependencies=y - fi - fi - - if [ "$install_dependencies" == "y" ]; then - MSG_INFO "Installing Debian packages..." - echo "" - for i in "${debian_depends[@]}"; do - MSG_INFO "Installing: $i" - apt-get -y install $i - echo "" - done - fi -fi -echo "" - -mkdir -p /var/log/${app_name} -chmod a+rwx /var/log/${app_name} -/etc/init.d/${app_name} start -update-rc.d ${app_name} defaults - -MSG_INFO "Install completed." -echo "" -echo "******************************************************************" -echo "Start ${app_fullname} using the shortcut in the Applications Menu" -echo "or by running the command: sudo ${app_name}-gtk" -echo "If it fails to start, check and install the following packages:" -echo "Required: ${generic_depends[@]}" -echo "Optional: (none)" -echo "******************************************************************" -WAIT_FOR_INPUT -EXIT 0 diff -Nru aptik-battery-monitor-2.1/LICENSE.md aptik-battery-monitor-17.12/LICENSE.md --- aptik-battery-monitor-2.1/LICENSE.md 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/LICENSE.md 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,166 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff -Nru aptik-battery-monitor-2.1/push.sh aptik-battery-monitor-17.12/push.sh --- aptik-battery-monitor-2.1/push.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/push.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -#!/bin/bash - -backup=`pwd` -DIR="$( cd "$( dirname "$0" )" && pwd )" -cd "$DIR" - -sh build-source.sh - -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -echo "Pushing new revisions to launchpad..." -bzr push lp:~teejee2008/aptik-bmon/trunk - -#check for errors -if [ $? -ne 0 ]; then - cd "$backup" - echo "Failed" - exit 1 -fi - -cd "$backup" - - - - diff -Nru aptik-battery-monitor-2.1/README.md aptik-battery-monitor-17.12/README.md --- aptik-battery-monitor-2.1/README.md 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/README.md 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,72 @@ +# Battery Monitor + +Battery Monitor is a utility to monitor the battery life of laptops. It displays a graph of the change in battery level with time. This is useful to estimate the amount of battery life that you are getting from your laptop, and to check the overall health. + +**Average Life** is the amount of time your laptop takes to go from 100% to 0%. It takes a few charge-discharge cycles to get an accurate estimate of this value. + +**Health** is the remaining life of battery. It is normally 100% when the battery is new, and slowly degrades with time. For example, a two-year old laptop may show health of 80%, which indicates that only 80% of the original capacity is left. + +*Discharging - Displays average life, time remaining and discharge rate* + +![](images/discharging.png) + + + +**Red line** in the graph displays CPU usage. CPU usage is usually high if battery is discharging rapidly. + +**Average life** is the overall battery life of the laptop, i.e. average time taken to go from 100% to 0% . + + + +*Charging - Displays charge rate and time remaining* + +![](images/charging.png) + +## Installation + +#### Ubuntu-based Distributions + +Ubuntu, Linux Mint, Elementary OS, etc. + +Packages are available in the Launchpad PPA for supported Ubuntu releases. +Run the following commands in a terminal window: + +```sh +sudo add-apt-repository -y ppa:teejee2008/ppa +sudo apt-get update +sudo apt-get install aptik-battery-monitor +``` + +DEB and RUN packages are available on [Releases](https://github.com/teejee2008/battery-monitor/releases) page for older Ubuntu releases which have reached end-of-life. + +#### Other Linux Distributions + +Download the .RUN installer from [Releases](https://github.com/teejee2008/battery-monitor/releases) page and execute it in a terminal window: + +```sh +sudo sh ./aptik-battery-monitor*amd64.run # 64-bit, or +sudo sh ./aptik-battery-monitor*i386.run # 32-bit +``` + +Installer can be used on following distribution types: + +- **Fedora** based - Fedora, RedHat, Cent OS, etc (supports **dnf** and **yum**) + +- **Debian** based - Debian, Ubuntu, Linux Mint, Elementary OS, etc (supports **apt**) + +- **Arch** based - Arch Linux, Manjaro, etc (supports **pacman**) + + ​ + +## Donate + +*Battery Monitor* is a non-commercial application. I work on it during my free time based on my requirements and interest. + +**PayPal** ~ If you find this application useful and wish to say thanks, you can buy me a coffee by making a donation with Paypal. Your contributions will help keep the project alive and support future development. + +[![](images/PayPal.png)](https://www.paypal.com/cgi-bin/webscr?business=teejeetech@gmail.com&cmd=_xclick¤cy_code=USD&amount=10&item_name=BatteryMonitor%20Donation) + +**Patreon** ~ You can also sign up as a sponsor on [Patreon.com](https://www.patreon.com/teejeetech). As a patron you will get access to beta releases of new applications that I'm working on. You will also get news and updates about new features that are not published elsewhere. + +[![](images/patreon.png)](https://www.patreon.com/bePatron?u=3059450) + diff -Nru aptik-battery-monitor-2.1/release/postinst.sh aptik-battery-monitor-17.12/release/postinst.sh --- aptik-battery-monitor-2.1/release/postinst.sh 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/release/postinst.sh 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,13 @@ +#!/bin/bash + +app_name='aptik-battery-monitor' +app_fullname='Aptik Battery Monitor' + +echo "Creating log directory..." +mkdir -p /var/log/${app_name} +chmod a+rwx /var/log/${app_name} + +echo "Starting service..." +/etc/init.d/${app_name} start +update-rc.d ${app_name} defaults + diff -Nru aptik-battery-monitor-2.1/release/sanity.config aptik-battery-monitor-17.12/release/sanity.config --- aptik-battery-monitor-2.1/release/sanity.config 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/release/sanity.config 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,7 @@ +app_name: Aptik NG +depends_debian: libgee-0.8-2 libjson-glib-1.0-0 apt aptitude gdebi apt-transport-https pv +depends_redhat: libgee json-glib pv +depends_arch: libgee json-glib pv +depends_generic: libgee json-glib pv +assume_yes: 0 +exec_line: pkexec aptik diff -Nru aptik-battery-monitor-2.1/src/AboutWindow.vala aptik-battery-monitor-17.12/src/AboutWindow.vala --- aptik-battery-monitor-2.1/src/AboutWindow.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/AboutWindow.vala 1970-01-01 00:00:00.000000000 +0000 @@ -1,400 +0,0 @@ -/* - * AboutWindow.vala - * - * Copyright 2015 Tony George - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -using Gtk; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JSON; -using TeeJee.ProcessManagement; -using TeeJee.GtkHelper; -using TeeJee.System; -using TeeJee.Misc; - -public class AboutWindow : Dialog { - private Box vbox_main; - private Box vbox_logo; - private Box vbox_credits; - private Box vbox_lines; - private Box hbox_action; - private Button btn_credits; - private Button btn_close; - - private Gtk.Image img_logo; - private Label lbl_program_name; - private Label lbl_version; - private Label lbl_comments; - private LinkButton lbtn_website; - private Label lbl_copyright; - - private string[] _artists; - public string[] artists{ - get{ - return _artists; - } - set{ - _artists = value; - } - } - - private string[] _authors; - public string[] authors{ - get{ - return _authors; - } - set{ - _authors = value; - } - } - - private string _comments = ""; - public string comments{ - get{ - return _comments; - } - set{ - _comments = value; - } - } - - private string _copyright = ""; - public string copyright{ - get{ - return _copyright; - } - set{ - _copyright = value; - } - } - - private string[] _documenters; - public string[] documenters{ - get{ - return _documenters; - } - set{ - _documenters = value; - } - } - - private string[] _donations; - public string[] donations{ - get{ - return _donations; - } - set{ - _donations = value; - } - } - - private string _license = ""; - public string license{ - get{ - return _license; - } - set{ - _license = value; - } - } - - private Gdk.Pixbuf _logo; - public Gdk.Pixbuf logo{ - get{ - return _logo; - } - set{ - _logo = value; - } - } - - private string _program_name = ""; - public string program_name{ - get{ - return _program_name; - } - set{ - _program_name = value; - } - } - - private string[] _translators; - public string[] translators{ - get{ - return _translators; - } - set{ - _translators = value; - } - } - - private string[] _third_party; - public string[] third_party{ - get{ - return _third_party; - } - set{ - _third_party = value; - } - } - - private string _version = ""; - public string version{ - get{ - return _version; - } - set{ - _version = value; - } - } - - private string _website = ""; - public string website{ - get{ - return _website; - } - set{ - _website = value; - } - } - - private string _website_label = ""; - public string website_label{ - get{ - return _website_label; - } - set{ - _website_label = value; - } - } - - public AboutWindow() { - window_position = WindowPosition.CENTER_ON_PARENT; - set_destroy_with_parent (true); - set_modal (true); - skip_taskbar_hint = false; - set_default_size (450, 400); - - vbox_main = get_content_area(); - vbox_main.margin = 6; - vbox_main.spacing = 6; - - vbox_logo = new Box(Orientation.VERTICAL,0); - vbox_main.add(vbox_logo); - - vbox_credits = new Box(Orientation.VERTICAL,0); - vbox_credits.no_show_all = true; - vbox_main.add(vbox_credits); - - vbox_lines = new Box(Orientation.VERTICAL,0); - vbox_lines.margin_top = 10; - - //logo - img_logo = new Gtk.Image(); - img_logo.margin_top = 6; - img_logo.margin_bottom = 6; - vbox_logo.add(img_logo); - - //program_name - lbl_program_name = new Label(""); - lbl_program_name.set_use_markup(true); - vbox_logo.add(lbl_program_name); - - //version - lbl_version = new Label(""); - lbl_version.set_use_markup(true); - lbl_version.margin_top = 5; - vbox_logo.add(lbl_version); - - //comments - lbl_comments = new Label(""); - lbl_comments.set_use_markup(true); - lbl_comments.margin_top = 10; - vbox_logo.add(lbl_comments); - - //website - lbtn_website = new LinkButton(""); - lbtn_website.margin_top = 5; - vbox_logo.add(lbtn_website); - - lbtn_website.activate_link.connect(()=>{ - try{ - return Gtk.show_uri(null, lbtn_website.uri, Gdk.CURRENT_TIME); - } - catch(Error e){ - return false; - } - }); - - //copyright - lbl_copyright = new Label(""); - lbl_copyright.set_use_markup(true); - lbl_copyright.margin_top = 5; - vbox_logo.add(lbl_copyright); - - //spacer_bottom - var spacer_bottom = new Label(""); - spacer_bottom.margin_top = 20; - vbox_logo.add(spacer_bottom); - - //scroller - var sw_credits = new ScrolledWindow(null, null); - sw_credits.set_shadow_type(ShadowType.ETCHED_IN); - sw_credits.expand = true; - - vbox_credits.add(sw_credits); - sw_credits.add(vbox_lines); - - //hbox_commands -------------------------------------------------- - - hbox_action = (Box) get_action_area(); - - //btn_credits - btn_credits = new Button.with_label(" " + _("Credits")); - btn_credits.set_image (new Image.from_stock ("gtk-about", IconSize.MENU)); - hbox_action.add(btn_credits); - - btn_credits.clicked.connect(()=>{ - vbox_logo.visible = !(vbox_logo.visible); - vbox_credits.visible = !(vbox_credits.visible); - - if ((vbox_credits.visible)&&(!sw_credits.visible)){ - sw_credits.show_all(); - } - - if (vbox_credits.visible){ - btn_credits.label = " " + _("Back"); - btn_credits.set_image (new Image.from_stock ("gtk-go-back", IconSize.MENU)); - } - else{ - btn_credits.label = " " + _("Credits"); - btn_credits.set_image (new Image.from_stock ("gtk-about", IconSize.MENU)); - } - }); - - //btn_close - btn_close = new Button.with_label(" " + _("Close")); - btn_close.set_image (new Image.from_stock ("gtk-close", IconSize.MENU)); - hbox_action.add(btn_close); - - btn_close.clicked.connect(()=>{ this.destroy(); }); - } - - public void initialize() { - title = program_name; - img_logo.pixbuf = logo; - lbl_program_name.label = "%s".printf(program_name); - lbl_version.label = "v%s".printf(version); - lbl_comments.label = "%s".printf(comments); - lbtn_website.uri = website; - lbtn_website.label = website_label; - //lbl_copyright.label = "%s".printf(copyright); - lbl_copyright.label = "%s".printf(copyright); - - if (authors.length > 0){ - add_line("%s\n".printf(_("Authors"))); - foreach(string name in authors){ - add_line("%s\n".printf(name)); - } - add_line("\n"); - } - - if (third_party.length > 0){ - add_line("%s\n".printf(_("Third Party Tools"))); - foreach(string name in third_party){ - add_line("%s\n".printf(name)); - } - add_line("\n"); - } - - if (artists.length > 0){ - add_line("%s\n".printf(_("Artists"))); - foreach(string name in artists){ - add_line("%s\n".printf(name)); - } - add_line("\n"); - } - - if (translators.length > 0){ - add_line("%s\n".printf(_("Translators"))); - foreach(string name in translators){ - add_line("%s\n".printf(name)); - } - add_line("\n"); - } - - if (documenters.length > 0){ - add_line("%s\n".printf(_("Documenters"))); - foreach(string name in documenters){ - add_line("%s\n".printf(name)); - } - add_line("\n"); - } - - if (donations.length > 0){ - add_line("%s\n".printf(_("Donations"))); - foreach(string name in donations){ - add_line("%s\n".printf(name)); - } - add_line("\n"); - } - - if (vbox_lines.get_children().length() == 0){ - btn_credits.visible = false; - } - } - - public void add_line(string text){ - if (text.split(":").length >= 2){ - var link = new LinkButton(text.split(":")[0]); - vbox_lines.add(link); - - string val = text[text.index_of(":") + 1:text.length]; - if (val.contains("@")){ - link.uri = "mailto:" + val; - } - else if(val.has_prefix("http://")){ - link.uri = val; - } - else{ - link.uri = "http://" + val; - } - - link.activate_link.connect(()=>{ - try{ - return Gtk.show_uri(null, link.uri, Gdk.CURRENT_TIME); - } - catch(Error e){ - return false; - } - }); - } - else{ - var lbl = new Label(text); - lbl.set_use_markup(true); - lbl.valign = Align.START; - lbl.wrap = true; - lbl.wrap_mode = Pango.WrapMode.WORD; - vbox_lines.add(lbl); - } - } -} diff -Nru aptik-battery-monitor-2.1/src/aptik-battery-monitor.desktop aptik-battery-monitor-17.12/src/aptik-battery-monitor.desktop --- aptik-battery-monitor-2.1/src/aptik-battery-monitor.desktop 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/aptik-battery-monitor.desktop 2017-12-10 14:02:06.000000000 +0000 @@ -6,7 +6,7 @@ GenericName=Battery Monitor Terminal=false Icon=aptik-battery-monitor -Caption=Battery Monitor +Comment=Battery Monitor X-KDE-StartupNotify=false Categories=System; Name[en_US]=Aptik Battery Monitor diff -Nru aptik-battery-monitor-2.1/src/AptikBatteryStatsGtk.vala aptik-battery-monitor-17.12/src/AptikBatteryStatsGtk.vala --- aptik-battery-monitor-2.1/src/AptikBatteryStatsGtk.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/AptikBatteryStatsGtk.vala 1970-01-01 00:00:00.000000000 +0000 @@ -1,107 +0,0 @@ -/* - * AptikBatteryStatsGtk.vala - * - * Copyright 2015 Tony George - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -using GLib; -using Gtk; -using Gee; -using Json; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JSON; -using TeeJee.ProcessManagement; -using TeeJee.GtkHelper; -using TeeJee.Multimedia; -using TeeJee.System; -using TeeJee.Misc; - -public class AptikBatteryStatsGtk : GLib.Object{ - - public static int main (string[] args) { - set_locale(); - - Gtk.init(ref args); - - init_tmp(); - - App = new Main(args, true); - parse_arguments(args); - - var window = new BatteryStatsWindow (); - window.destroy.connect(Gtk.main_quit); - window.show_all(); - - //start event loop - Gtk.main(); - - App.exit_app(); - - return 0; - } - - private static void set_locale(){ - Intl.setlocale(GLib.LocaleCategory.MESSAGES, AppShortName); - Intl.textdomain(GETTEXT_PACKAGE); - Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "utf-8"); - Intl.bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); - } - - public static bool parse_arguments(string[] args){ - //parse options - for (int k = 1; k < args.length; k++) // Oth arg is app path - { - switch (args[k].down()){ - case "--debug": - LOG_DEBUG = true; - break; - case "--help": - case "--h": - case "-h": - log_msg(help_message()); - exit(0); - return true; - default: - //unknown option - show help and exit - log_error(_("Unknown option") + ": %s".printf(args[k])); - log_msg(help_message()); - exit(1); - return false; - } - } - - return true; - } - - public static string help_message(){ - string msg = "\n" + AppName + " v" + AppVersion + " by Tony George (teejee2008@gmail.com)" + "\n"; - msg += "\n"; - msg += _("Syntax") + ": %s [options]\n".printf(AppShortName); - msg += "\n"; - msg += _("Options") + ":\n"; - msg += "\n"; - msg += " --debug " + _("Print debug information") + "\n"; - msg += " --h[elp] " + _("Show all options") + "\n"; - msg += "\n"; - return msg; - } -} diff -Nru aptik-battery-monitor-2.1/src/AptikBatteryStats.vala aptik-battery-monitor-17.12/src/AptikBatteryStats.vala --- aptik-battery-monitor-2.1/src/AptikBatteryStats.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/AptikBatteryStats.vala 2017-12-10 14:02:06.000000000 +0000 @@ -1,7 +1,7 @@ /* * AptikBatteryStats.vala * - * Copyright 2015 Tony George + * Copyright 2012-2017 Tony George * * 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 @@ -42,8 +42,6 @@ LOG_TIMESTAMP = false; - init_tmp(); - App = new Main(args,false); App.check_for_multiple_instances(); diff -Nru aptik-battery-monitor-2.1/src/BatteryBar.vala aptik-battery-monitor-17.12/src/BatteryBar.vala --- aptik-battery-monitor-2.1/src/BatteryBar.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/BatteryBar.vala 2017-12-10 14:02:06.000000000 +0000 @@ -1,7 +1,7 @@ /* * BatteryBar.vala * - * Copyright 2015 Tony George + * Copyright 2017 Tony George * * 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 diff -Nru aptik-battery-monitor-2.1/src/BatteryStatsWindow.vala aptik-battery-monitor-17.12/src/BatteryStatsWindow.vala --- aptik-battery-monitor-2.1/src/BatteryStatsWindow.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/BatteryStatsWindow.vala 1970-01-01 00:00:00.000000000 +0000 @@ -1,735 +0,0 @@ -/* - * BatteryStatsWindow.vala - * - * Copyright 2015 Tony George - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - - -using Gtk; -using Gee; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JSON; -using TeeJee.ProcessManagement; -using TeeJee.GtkHelper; -using TeeJee.Multimedia; -using TeeJee.System; -using TeeJee.Misc; - -public class BatteryStatsWindow : Window { - private Box vbox_main; - private Box hbox_top_line1; - - private Gtk.DrawingArea drawing_area; - - private Label lbl_stats_line_batt; - private Label lbl_stats_line_used; - - private Label lbl_percent; - private Label lbl_percent_val; - private Label lbl_remaining; - private Label lbl_remaining_val; - private Label lbl_avg_life; - private Label lbl_avg_life_val; - private Label lbl_time_to_charge; - private Label lbl_time_to_charge_val; - private Label lbl_rate; - private Label lbl_rate_val; - - private Gtk.Image img_battery_status; - - BatteryStat stat_current; - int X_INTERVAL = 5; - int X_OFFSET = 30; - int Y_OFFSET = 20; - - uint timer_refresh = 0; - - int def_width = 500; - int def_height = 450; - - private Gdk.RGBA color_white; - private Gdk.RGBA color_black; - private Gdk.RGBA color_red; - private Gdk.RGBA color_blue; - private Gdk.RGBA color_red_100; - - public BatteryStatsWindow() { - destroy.connect(Gtk.main_quit); - init_window(); - } - - public BatteryStatsWindow.with_parent(Window parent) { - set_transient_for(parent); - set_modal(true); - init_window(); - init_window_for_parent(); - } - - public void init_window () { - define_colors(); - - title = "Aptik Battery Monitor" + " v" + AppVersion; - window_position = WindowPosition.CENTER; - resizable = true; - set_default_size (def_width, def_height); - - //vbox_main - vbox_main = new Box (Orientation.VERTICAL, 6); - vbox_main.margin = 6; - add (vbox_main); - - init_header(); - - init_graph(); - - init_stats(); - - //TODO: Should start if not already running - - show_all(); - - timer_refresh_graph(); - - timer_refresh = Timeout.add(30 * 1000, timer_refresh_graph); - } - - public void define_colors(){ - color_white = Gdk.RGBA(); - color_white.parse("white"); - color_white.alpha = 1.0; - - color_black = Gdk.RGBA(); - color_black.parse("black"); - color_black.alpha = 1.0; - - color_red = Gdk.RGBA(); - color_red.parse("red"); - color_red.alpha = 1.0; - - color_blue = Gdk.RGBA(); - color_blue.parse("blue"); - color_blue.alpha = 1.0; - - color_red_100 = Gdk.RGBA(); - color_red_100.parse("#FFCDD2"); - color_red_100.alpha = 1.0; - } - - public void init_window_for_parent() { - //btn_actions.hide(); - //btn_selections.hide(); - } - - public void init_header() { - Gtk.Frame frame_top = new Gtk.Frame (""); - //(frame_stats_line.label_widget as Gtk.Label).use_markup = true; - vbox_main.add (frame_top); - - var grid_top = new Grid(); - grid_top.set_column_spacing (6); - grid_top.set_row_spacing (6); - grid_top.margin_left = 12; - grid_top.margin_right = 6; - grid_top.margin_bottom = 6; - frame_top.add(grid_top); - - lbl_stats_line_batt = new Label(""); - lbl_stats_line_batt.xalign = (float) 0.0; - grid_top.attach(lbl_stats_line_batt, 0, 0, 1, 1); - - lbl_stats_line_used = new Label(""); - lbl_stats_line_used.xalign = (float) 0.0; - grid_top.attach(lbl_stats_line_used, 0, 1, 1, 1); - - var lbl_spacer = new Label(""); - lbl_spacer.hexpand = true; - grid_top.attach(lbl_spacer, 1, 0, 1, 1); - - /* //btn_settings - var btn_settings = new Gtk.Button.from_stock ("gtk-missing-image"); - btn_settings.label = _("Settings"); - //btn_settings.label = ""; - btn_settings.set_tooltip_text (_("Settings")); - //btn_settings.image = get_shared_icon("gnome-settings","config.svg",16); - //btn_settings.always_show_image = true; - //btn_settings.image_position = PositionType.RIGHT; - //hbox_top_line1.add(btn_settings); - - btn_settings.clicked.connect(() => { - var dialog = new SettingsWindow(); - dialog.set_transient_for(this); - dialog.show_all(); - dialog.run(); - dialog.destroy(); - });*/ - - //btn_donate - var btn_donate = new Gtk.Button.from_stock ("gtk-missing-image"); - btn_donate.label = _("Donate"); - btn_donate.label = ""; - btn_donate.set_tooltip_text (_("Donate")); - btn_donate.image = get_shared_icon("donate","donate.svg",24); - btn_donate.always_show_image = true; - btn_donate.image_position = PositionType.RIGHT; - grid_top.attach(btn_donate, 2, 0, 1, 2); - - btn_donate.clicked.connect(() => { - var dialog = new DonationWindow(); - dialog.set_transient_for(this); - dialog.show_all(); - dialog.run(); - dialog.destroy(); - }); - - //btn_about - var btn_about = new Gtk.Button.from_stock ("gtk-about"); - btn_about.label = _("Info"); - btn_about.label = ""; - btn_about.set_tooltip_text (_("Application Info")); - btn_about.image = get_shared_icon("gtk-about","help-info.svg",24); - btn_about.always_show_image = true; - btn_about.image_position = PositionType.RIGHT; - grid_top.attach(btn_about, 3, 0, 1, 2); - - btn_about.clicked.connect (btn_about_clicked); - } - - private void btn_about_clicked () { - var dialog = new AboutWindow(); - dialog.set_transient_for (this); - - dialog.authors = { - "Tony George:teejeetech@gmail.com" - }; - - dialog.translators = { - //"giulux (Italian)", - //"Jorge Jamhour (Brazilian Portuguese):https://launchpad.net/~jorge-jamhour", - //"B. W. Knight (Korean):https://launchpad.net/~kbd0651", - //"Rodion R. (Russian):https://launchpad.net/~r0di0n" - }; - - dialog.documenters = null; - dialog.artists = null; - dialog.donations = null; - - dialog.program_name = AppName; - dialog.comments = _(" A Battery Monitoring Utility for Laptops"); - dialog.copyright = "Copyright © 2015 Tony George (%s)".printf(AppAuthorEmail); - dialog.version = AppVersion; - dialog.logo = get_app_icon(128); - - dialog.license = "This program is free for personal and commercial use and comes with absolutely no warranty. You use this program entirely at your own risk. The author will not be liable for any damages arising from the use of this program."; - dialog.website = "http://teejeetech.in"; - dialog.website_label = "http://teejeetech.blogspot.in"; - - dialog.initialize(); - dialog.show_all(); - } - - public void init_graph() { - drawing_area = new Gtk.DrawingArea(); - drawing_area.set_size_request(400, 200); - drawing_area.margin = 10; - - var sw_graph = new ScrolledWindow(null, null); - sw_graph.set_shadow_type (ShadowType.ETCHED_IN); - sw_graph.expand = true; - - sw_graph.add (drawing_area); - vbox_main.add(sw_graph); - - App.read_battery_stats(); - - drawing_area.add_events(Gdk.EventMask.BUTTON_PRESS_MASK); - - /*drawing_area.button_press_event.connect((event) => { - redraw_graph_area(); - return true; - });*/ - - //this.add_events(Gdk.EventMask.POINTER_MOTION_MASK); - drawing_area.add_events(Gdk.EventMask.POINTER_MOTION_MASK); - - drawing_area.motion_notify_event.connect((event)=>{ - string msg = ""; - BatteryStat stat_last = null; - foreach(var stat in App.battery_stats_list) { - if (stat.date == null) { - continue; - } - - if (Math.fabsf((float)(stat.graph_x - event.x)) < X_INTERVAL) { - msg += _("Date") + ": %s\n".printf(stat.date.format("%d %b %Y, %I:%M %p")); - msg += _("Battery") + ": %0.2f %%, %0.0f mAh, %0.2f Wh, %0.2f V\n".printf( - stat.charge_percent(), - stat.charge_in_mah(), - stat.charge_in_wh(), - stat.voltage() - ); - msg += _("CPU") + ": %0.2f %%".printf(stat.cpu_percent()); - break; - } - - stat_last = stat; - } - - drawing_area.set_tooltip_text(msg); - - return true; - }); - - drawing_area.draw.connect ((context) => { - //weak Gtk.StyleContext style_context = drawing_area.get_style_context (); - //var color_default = style_context.get_color (0); - - var color_default = color_black; - - Gdk.cairo_set_source_rgba (context, color_default); - context.set_line_width (1); - - int stat_count = (App.battery_stats_list.size > 2880) ? 2880 : App.battery_stats_list.size; - - //int w = drawing_area.get_allocated_width(); - int h = drawing_area.get_allocated_height(); - - //int w_eff = w - X_OFFSET; - int h_eff = h - 2 * Y_OFFSET; - - //double pxw = (w_eff / 100.00); - double pxh = (h_eff / 100.00); - - long x0 = X_OFFSET; - long y0 = h - Y_OFFSET; - long x100 = x0 + (stat_count * X_INTERVAL); - long y100 = Y_OFFSET; - - long x, x_prev, y, y_prev, y_cpu, y_prev_cpu; - x = x_prev = x0; - y = y_prev = y_cpu = y_prev_cpu = y0; - - int count = 0; - BatteryStat stat_prev = null; - int count_24_hours = 2880; - - int x_interval_counter = 0; - foreach(var stat in App.battery_stats_list) { - if (stat.date == null) { - continue; - } - count++; - - if (App.battery_stats_list.size > count_24_hours) { - if (count < (App.battery_stats_list.size - 2880)) { - //ignore entries older than latest 2880 records - continue; - } - } - - x += X_INTERVAL; - stat.graph_x = x; - - if (stat_prev != null) { - if (stat_prev.date.add_seconds(Main.BATT_STATS_LOG_INTERVAL + 1).compare(stat.date) < 0) { - - //draw double-vertical lines to indicate time gap - - //------ BEGIN CONTEXT ------------------------------------------- - context.set_line_width (0.5); - Gdk.cairo_set_source_rgba (context, color_default); - - //draw a vertical line - context.move_to(x_prev, y0); - context.line_to(x_prev, y100); - - //draw a vertical line - context.move_to(x, y0); - context.line_to(x, y100); - - context.stroke (); - //------ END CONTEXT ----------------------------------------- - } - else { - //------ BEGIN CONTEXT ------------------------------------------- - context.set_line_width (0.5); - Gdk.cairo_set_source_rgba (context, color_default); - - for (int p = 10; p <= 100; p += 10) { - long y_interval = (long) (h - Y_OFFSET - (p * pxh)); - //draw Y-axis lines - context.move_to(x_prev, y_interval); - context.line_to(x, y_interval); - } - - context.stroke (); - //------ END CONTEXT --------------------------------------------- - - //------ BEGIN CONTEXT ------------------------------------------- - context.set_line_width (1); - Gdk.cairo_set_source_rgba (context, color_default); - - //draw battery line for stat --------------------------- - - context.move_to (x_prev, y_prev); - - y = (long) ((stat.charge_now * 100.00 * pxh) / BatteryStat.batt_charge_full()); - y = h - Y_OFFSET - y; - - context.line_to (x, y); - - context.stroke (); - //------ END CONTEXT --------------------------------------------- - - //------ BEGIN CONTEXT ------------------------------------------- - context.set_line_width (1); - Gdk.cairo_set_source_rgba (context, color_red); - - //draw cpu line for stat ---------------- - - context.move_to (x_prev, y_prev_cpu); - - y_cpu = (long) (stat.cpu_percent() * pxh); - y_cpu = h - Y_OFFSET - y_cpu; - context.line_to (x, y_cpu); - - y_prev_cpu = y_cpu; - - context.stroke (); - //------ END CONTEXT --------------------------------------------- - } - } - - if ((stat_current != null) && (stat_current.date == stat.date)) { - //------ BEGIN CONTEXT ------------------------------------------- - context.set_line_width (0.5); - Gdk.cairo_set_source_rgba (context, color_blue); - //draw a vertical line for selected stat - context.move_to(x, y0); - context.line_to(x, y100); - context.stroke (); - //------ END CONTEXT --------------------------------------------- - } - - //------ BEGIN CONTEXT ------------------------------------------------- - context.set_line_width (1); - Gdk.cairo_set_source_rgba (context, color_default); - - //draw X-axis ticks and time label for stat ----------------- - - x_interval_counter++; - - if (((stat.date.get_minute() % 10) == 0) && (stat.date.get_second() < 30)) { - //draw X-axis tick - context.move_to(x, y0 - 2); - context.line_to(x, y0 + 2); - - if (x_interval_counter >= 20){ - //draw time on X-axis tick - context.move_to (x - 15, h - Y_OFFSET + 20); - context.show_text(stat.date.format("%I:%M %p")); - } - - x_interval_counter = 0; - } - - context.stroke (); - //------ END CONTEXT --------------------------------------------------- - - stat_prev = stat; - if (stat_current == null) { - stat_current = stat; - } - x_prev = x; - y_prev = y; - } - - //------ BEGIN CONTEXT ------------------------------------------------- - - context.set_line_width (1); - Gdk.cairo_set_source_rgba (context, color_default); - - //draw axis lines ----------------------------- - - //draw X-axis line - context.move_to(x0, y0); - context.line_to(x100, y0); - - //draw Y-axis line - context.move_to(x0, y0); - context.line_to(x0, y100); - - context.stroke (); - - //------ END CONTEXT --------------------------------------------------- - - //------ BEGIN CONTEXT ------------------------------------------------- - context.set_line_width (0.5); - - //draw Y-axis markers and labels ------------------------ - - for (int p = 10; p <= 100; p += 10) { - y = (long) (h - Y_OFFSET - (p * pxh)); - - //draw Y-axis markers - context.move_to(x0 + 2, y); - context.line_to(x0 - 2, y); - - /* - //draw Y-axis lines - context.move_to(x0, y); - context.line_to(x100, y); - */ - - //draw Y-axis labels - context.move_to (x0 - X_OFFSET, y); - context.show_text("%d%%".printf(p)); - } - - context.stroke (); - //------ END CONTEXT --------------------------------------------------- - - drawing_area.set_size_request((X_INTERVAL * stat_count) + (2 * X_OFFSET), -1); - - return true; - }); - } - - public void init_stats() { - - //frame_main - Gtk.Frame frame_main = new Gtk.Frame (""); - //(frame_main.label_widget as Gtk.Label).use_markup = true; - vbox_main.add (frame_main); - - var grid_main = new Grid(); - grid_main.set_column_spacing (18); - grid_main.set_row_spacing (6); - grid_main.margin_left = 12; - grid_main.margin_bottom = 6; - frame_main.add(grid_main); - - //percent - lbl_percent = new Label(_("Battery")); - grid_main.attach(lbl_percent, 0, 1, 1, 1); - - lbl_percent_val = new Label("" + _("0h 0m") + ""); - lbl_percent_val.set_use_markup(true); - grid_main.attach(lbl_percent_val, 0, 0, 1, 1); - - //avg_life - lbl_avg_life = new Label(_("Average Life")); - lbl_avg_life.set_no_show_all(true); - grid_main.attach(lbl_avg_life, 1, 1, 1, 1); - - lbl_avg_life_val = new Label("" + _("0h 0m") + ""); - lbl_avg_life_val.set_use_markup(true); - lbl_avg_life_val.set_no_show_all(true); - grid_main.attach(lbl_avg_life_val, 1, 0, 1, 1); - - //remaining - lbl_remaining = new Label(_("Remaining")); - lbl_remaining.set_no_show_all(true); - grid_main.attach(lbl_remaining, 2, 1, 1, 1); - - lbl_remaining_val = new Label("" + _("0h 0m") + ""); - lbl_remaining_val.set_use_markup(true); - lbl_remaining_val.set_no_show_all(true); - grid_main.attach(lbl_remaining_val, 2, 0, 1, 1); - - //remaining_to_charge - lbl_time_to_charge = new Label(_("To Full Charge")); - lbl_time_to_charge.set_no_show_all(true); - grid_main.attach(lbl_time_to_charge, 3, 1, 1, 1); - - lbl_time_to_charge_val = new Label("" + _("0h 0m") + ""); - lbl_time_to_charge_val.set_use_markup(true); - lbl_time_to_charge_val.set_no_show_all(true); - grid_main.attach(lbl_time_to_charge_val, 3, 0, 1, 1); - - //rate - lbl_rate = new Label(_("Per Hour")); - lbl_rate.set_no_show_all(true); - grid_main.attach(lbl_rate, 4, 1, 1, 1); - - lbl_rate_val = new Label("" + _("0.0%") + ""); - lbl_rate_val.set_use_markup(true); - lbl_rate_val.set_no_show_all(true); - grid_main.attach(lbl_rate_val, 4, 0, 1, 1); - - //spacer - var lbl_spacer = new Label(""); - lbl_spacer.hexpand = true; - grid_main.attach(lbl_spacer, 5, 0, 1, 2); - - //battery icon - img_battery_status = get_shared_icon("notification-battery-060", "notification-battery-060.png", 80); - img_battery_status.margin_right = 5; - grid_main.attach(img_battery_status, 6, 0, 1, 2); - } - - public bool timer_refresh_graph() { - //if (timer_pkg_info > 0){ - // Source.remove(timer_pkg_info); - // timer_pkg_info = 0; - //} - - App.read_battery_stats(); - select_latest_stat(); - update_info_current_cycle(); - update_battery_status_icon(); - return true; - } - - private void select_latest_stat(){ - if (App.battery_stats_list.size >= 2){ - var stat0 = App.battery_stats_list[App.battery_stats_list.size - 1]; - var stat1 = App.battery_stats_list[App.battery_stats_list.size - 2]; - stat_current = stat0; - redraw_graph_area(); - update_info_stats(stat0,stat1); - } - } - - private void redraw_graph_area() { - drawing_area.queue_draw_area(0, 0, - drawing_area.get_allocated_width(), - drawing_area.get_allocated_height()); - } - - private void update_info_stats(BatteryStat stat, BatteryStat stat_prev){ - lbl_stats_line_batt.label = _("Battery") + ": %0.2f %%, %0.0f mAh, %0.2f Wh, %0.2f V".printf( - stat.charge_percent(), - stat.charge_in_mah(), - stat.charge_in_wh(), - stat.voltage() - ); - } - - private void update_info_current_cycle(){ - if (App.battery_stats_list.size < 2){ return; } - - var cycle = new BatteryCycle(); - cycle.calculate_stats(App.battery_stats_list); - - //var stat_first = App.battery_stats_list[0]; - var stat_prev = App.battery_stats_list[App.battery_stats_list.size - 2]; - var stat_current = App.battery_stats_list[App.battery_stats_list.size - 1]; - - lbl_stats_line_used.label = _("Used") + ": " + cycle.used_string(); - - lbl_percent_val.label = format_label("%.2f%%".printf(stat_current.charge_percent())); - - if (BatteryStat.is_charging()){ - - //charging ------------------------------ - - lbl_avg_life.visible = lbl_avg_life_val.visible = false; - lbl_remaining.visible = lbl_remaining_val.visible = false; - lbl_time_to_charge.visible = lbl_time_to_charge_val.visible = true; - lbl_rate.visible = lbl_rate_val.visible = true; - - double rate = (stat_current.charge_percent() - stat_prev.charge_percent()) * 2; - double estimated = (100 - stat_current.charge_percent()) / rate; - - if (estimated > 0){ - lbl_time_to_charge_val.label = format_label(BatteryCycle.mins_to_string(estimated)); - } - else{ - lbl_time_to_charge_val.label = format_label("??"); - } - - if (estimated > 0){ - lbl_rate_val.label = format_label("%0.2f%%".printf(rate * 60.0)); - } - else{ - lbl_rate_val.label = format_label("??"); - } - } - else{ - //discharging ------------------------------ - - lbl_avg_life.visible = lbl_avg_life_val.visible = true; - lbl_remaining.visible = lbl_remaining_val.visible = true; - lbl_time_to_charge.visible = lbl_time_to_charge_val.visible = false; - lbl_rate.visible = lbl_rate_val.visible = true; - - double rate = (stat_prev.charge_percent() - stat_current.charge_percent()) * 2; - double estimated = 100 / rate; - - lbl_avg_life_val.label = format_label(cycle.battery_life_string()); - - if (estimated > 0){ - lbl_remaining_val.label = format_label(cycle.remaining_time_string()); - } - else{ - lbl_remaining_val.label = format_label("??"); - } - - if (rate > 0){ - lbl_rate_val.label = format_label("%0.2f%%".printf(cycle.drop_per_min * 60.0)); - } - else{ - lbl_rate_val.label = format_label("??"); - } - } - } - - private string format_label(string text){ - return "" + text + ""; - } - - private void update_battery_status_icon(){ - var icon_name = "notification-battery"; - - var stat = new BatteryStat.read_from_sys(); - double percent = stat.charge_percent(); - - if (percent == 100){ - icon_name += "-100"; - } - else if (percent >= 80){ - icon_name += "-080"; - } - else if (percent >= 60){ - icon_name += "-060"; - } - else if (percent >= 40){ - icon_name += "-040"; - } - else if (percent >= 20){ - icon_name += "-020"; - } - else if (percent >= 0){ - icon_name += "-000"; - } - - if (BatteryStat.is_charging()){ - icon_name += "-plugged"; - } - - var img = get_shared_icon(icon_name, "%s.png".printf(icon_name), 48); - if (img != null){ - img_battery_status.set_from_pixbuf(img.pixbuf); - } - } -} - diff -Nru aptik-battery-monitor-2.1/src/Classes.vala aptik-battery-monitor-17.12/src/Classes.vala --- aptik-battery-monitor-2.1/src/Classes.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Classes.vala 1970-01-01 00:00:00.000000000 +0000 @@ -1,254 +0,0 @@ -/* - * Classes.vala - * - * Copyright 2015 Tony George - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -using GLib; -using Gtk; -using Gee; -using Json; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JSON; -using TeeJee.ProcessManagement; -using TeeJee.GtkHelper; -using TeeJee.Multimedia; -using TeeJee.System; -using TeeJee.Misc; - -public class BatteryStat : GLib.Object{ - public DateTime date; - public long charge_now = 0; - public long voltage_now = 0; - public long cpu_usage = 0; - - public long graph_x = 0; - - public static const string BATT_STATS_CHARGE_NOW = "/sys/class/power_supply/BAT0/charge_now"; - public static const string BATT_STATS_CHARGE_FULL = "/sys/class/power_supply/BAT0/charge_full"; - public static const string BATT_STATS_CHARGE_FULL_DESIGN = "/sys/class/power_supply/BAT0/charge_full_design"; - public static const string BATT_STATS_VOLTAGE_NOW = "/sys/class/power_supply/BAT0/voltage_now"; - public static const string BATT_STATS_STATUS = "/sys/class/power_supply/BAT0/status"; - - public BatteryStat.read_from_sys(){ - this.date = new DateTime.now_local(); - this.charge_now = batt_charge_now(); - this.voltage_now = batt_voltage_now(); - this.cpu_usage = (long) (ProcStats.get_cpu_usage() * 1000); - } - - public BatteryStat.from_delimited_string(string line){ - var arr = line.split("|"); - if (arr.length == 4){ - DateTime date_utc = new DateTime.from_unix_utc(int64.parse(arr[0])); - this.date = date_utc.to_local(); - this.charge_now = long.parse(arr[1]); - this.voltage_now = long.parse(arr[2]); - this.cpu_usage = long.parse(arr[3]); - } - } - - public string to_delimited_string(){ - var txt = date.to_utc().to_unix().to_string() + "|"; - txt += charge_now.to_string() + "|"; - txt += voltage_now.to_string() + "|"; - txt += cpu_usage.to_string(); - txt += "\n"; - return txt; - } - - public string to_friendly_string(){ - var txt = ""; - txt += date.format("%F %H:%M:%S"); //%d %b %Y, %I:%M %p - txt += ", %6.2f%%, %5.0f mAh, %6.2f Wh".printf( - charge_percent(), - charge_in_mah(), - charge_in_wh() - ); - txt += ", %6.2f V".printf(voltage()); - txt += ", %6.2f %% CPU".printf(cpu_percent()); - txt += "\n"; - return txt; - } - - public double voltage(){ - return (voltage_now / 1000000.00); - } - - public double charge_percent(){ - return (((charge_now * 1.00) / batt_charge_full()) * 100); - } - - public double charge_in_mah(){ - return (charge_now / 1000.0); - } - - public double charge_in_wh(){ - return ((charge_in_mah() * voltage()) / 1000.00); - } - - public double cpu_percent(){ - return (cpu_usage / 1000.00); - } - - public static double batt_charge_percent(){ - return (((batt_charge_now() * 1.00) / batt_charge_full()) * 100); - } - - public static long batt_charge_now(){ - string val = read_sys_stat_file(BATT_STATS_CHARGE_NOW); - if (val.length == 0) { return 0; } - return long.parse(val); - } - - public static long batt_charge_full(){ - string val = read_sys_stat_file(BATT_STATS_CHARGE_FULL); - if (val.length == 0) { return 0; } - return long.parse(val); - } - - public static long batt_charge_full_design(){ - string val = read_sys_stat_file(BATT_STATS_CHARGE_FULL_DESIGN); - if (val.length == 0) { return 0; } - return long.parse(val); - } - - public static long batt_voltage_now(){ - string val = read_sys_stat_file(BATT_STATS_VOLTAGE_NOW); - if (val.length == 0) { return 0; } - return long.parse(val); - } - - public static bool is_charging(){ - string val = read_sys_stat_file(BATT_STATS_STATUS); - return (val == "Charging"); - } - - public static string read_sys_stat_file(string statFile){ - try{ - var file = File.new_for_path(statFile); - if (file.query_exists()){ - var dis = new DataInputStream (file.read()); - string line = dis.read_line (null); - if (line != null) { - return line; - } - } //stream closed - } - catch (Error e){ - log_error (e.message); - } - - return ""; - } -} - - -public class BatteryCycle : GLib.Object{ - public DateTime date; - public double total_drop = 0.0; - public double total_mins = 0.0; - public double drop_per_min = 0.0; - public double average_battery_life_in_mins = 0.0; - public double remaining_mins = 0.0; - - public BatteryCycle(){ - - } - - public void calculate_stats(Gee.ArrayList list){ - BatteryStat stat_last = null; - total_drop = 0.0; - total_mins = 0.0; - drop_per_min = 0.0; - foreach(BatteryStat stat in list){ - if ((stat_last != null) - && (stat.charge_percent() < stat_last.charge_percent()) - && (stat_last.date.add_seconds(Main.BATT_STATS_LOG_INTERVAL + 1).compare(stat.date) > 0)) - { - total_drop += (stat_last.charge_percent() - stat.charge_percent()); - total_mins += 0.5; - } - stat_last = stat; - - } - - if (stat_last != null){ - date = stat_last.date; - } - - if (total_mins > 0){ - drop_per_min = (total_drop / total_mins); - } - - if (drop_per_min > 0){ - average_battery_life_in_mins = (100.0 / drop_per_min); - - if (stat_last != null){ - remaining_mins = (stat_last.charge_percent() / drop_per_min); - } - } - } - - public string to_delimited_string(){ - var txt = date.to_utc().to_unix().to_string() + "|"; - txt += "%.0f|".printf(total_drop * 1000); - txt += "%.0f\n".printf(total_mins * 1000); - return txt; - } - - public string to_friendly_string(){ - var txt = ""; - txt += date.format("%F %H:%M:%S"); - txt += ", Used %0.2f %% in %.0fh %.0fm @ %0.1f %% per hour".printf( - total_drop, - (total_mins / 60.0), - (total_mins % 60.0), - (drop_per_min * 60.0) - ); - txt += "\n"; - return txt; - } - - public string used_string(){ - return "%0.2f %% in %.0fh %.0fm @ %0.1f %% per hour".printf( - total_drop, - (total_mins / 60.0), - (total_mins % 60.0), - (drop_per_min * 60.0) - ); - } - - public string battery_life_string(){ - return "%.0fh %.0fm".printf(average_battery_life_in_mins / 60, average_battery_life_in_mins % 60); - } - - public string remaining_time_string(){ - return "%.0fh %.0fm".printf(remaining_mins / 60, remaining_mins % 60); - } - - public static string mins_to_string(double mins){ - return "%.0fh %.0fm".printf(mins / 60, mins % 60); - } -} - - diff -Nru aptik-battery-monitor-2.1/src/Common/BatteryCycle.vala aptik-battery-monitor-17.12/src/Common/BatteryCycle.vala --- aptik-battery-monitor-2.1/src/Common/BatteryCycle.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Common/BatteryCycle.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,127 @@ +/* + * BatteryCycle.vala + * + * Copyright 2012-2017 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +using GLib; +using Gtk; +using Gee; +using Json; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.Multimedia; +using TeeJee.System; +using TeeJee.Misc; + +public class BatteryCycle : GLib.Object{ + + public DateTime date; + public double total_drop = 0.0; + public double total_mins = 0.0; + public double drop_per_min = 0.0; + public double average_battery_life_in_mins = 0.0; + public double remaining_mins = 0.0; + + public BatteryCycle(){ + + } + + public void calculate_stats(Gee.ArrayList list){ + BatteryStat stat_last = null; + total_drop = 0.0; + total_mins = 0.0; + drop_per_min = 0.0; + foreach(BatteryStat stat in list){ + if ((stat_last != null) + && (stat.charge_percent() < stat_last.charge_percent()) + && (stat_last.date.add_seconds(Main.BATT_STATS_LOG_INTERVAL + 1).compare(stat.date) > 0)) + { + total_drop += (stat_last.charge_percent() - stat.charge_percent()); + total_mins += 0.5; + } + stat_last = stat; + + } + + if (stat_last != null){ + date = stat_last.date; + } + + if (total_mins > 0){ + drop_per_min = (total_drop / total_mins); + } + + if (drop_per_min > 0){ + average_battery_life_in_mins = (100.0 / drop_per_min); + + if (stat_last != null){ + remaining_mins = (stat_last.charge_percent() / drop_per_min); + } + } + } + + public string to_delimited_string(){ + var txt = date.to_utc().to_unix().to_string() + "|"; + txt += "%.0f|".printf(total_drop * 1000); + txt += "%.0f\n".printf(total_mins * 1000); + return txt; + } + + public string to_friendly_string(){ + var txt = ""; + txt += date.format("%F %H:%M:%S"); + txt += ", Used %0.2f %% in %.0fh %.0fm @ %0.1f %% per hour".printf( + total_drop, + (total_mins / 60.0), + (total_mins % 60.0), + (drop_per_min * 60.0) + ); + txt += "\n"; + return txt; + } + + public string used_string(){ + return "%0.2f %% in %.0fh %.0fm @ %0.1f %% per hour".printf( + total_drop, + (total_mins / 60.0), + (total_mins % 60.0), + (drop_per_min * 60.0) + ); + } + + public string battery_life_string(){ + return "%.0fh %.0fm".printf(average_battery_life_in_mins / 60, average_battery_life_in_mins % 60); + } + + public string remaining_time_string(){ + return "%.0fh %.0fm".printf(remaining_mins / 60, remaining_mins % 60); + } + + public static string mins_to_string(double mins){ + return "%.0fh %.0fm".printf(mins / 60, mins % 60); + } +} + + diff -Nru aptik-battery-monitor-2.1/src/Common/BatteryStat.vala aptik-battery-monitor-17.12/src/Common/BatteryStat.vala --- aptik-battery-monitor-2.1/src/Common/BatteryStat.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Common/BatteryStat.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,174 @@ +/* + * BatteryStat.vala + * + * Copyright 2012-2017 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +using GLib; +using Gtk; +using Gee; +using Json; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.Multimedia; +using TeeJee.System; +using TeeJee.Misc; + +public class BatteryStat : GLib.Object{ + + public DateTime date; + public long charge_now = 0; + public long voltage_now = 0; + public long cpu_usage = 0; + + public long graph_x = 0; + + public const string BATT_STATS_CHARGE_NOW = "/sys/class/power_supply/BAT0/charge_now"; + public const string BATT_STATS_CHARGE_FULL = "/sys/class/power_supply/BAT0/charge_full"; + public const string BATT_STATS_CHARGE_FULL_DESIGN = "/sys/class/power_supply/BAT0/charge_full_design"; + public const string BATT_STATS_VOLTAGE_NOW = "/sys/class/power_supply/BAT0/voltage_now"; + public const string BATT_STATS_STATUS = "/sys/class/power_supply/BAT0/status"; + + public BatteryStat.read_from_sys(){ + this.date = new DateTime.now_local(); + this.charge_now = batt_charge_now(); + this.voltage_now = batt_voltage_now(); + this.cpu_usage = (long) (ProcStats.get_cpu_usage() * 1000); + } + + public BatteryStat.from_delimited_string(string line){ + var arr = line.split("|"); + if (arr.length == 4){ + DateTime date_utc = new DateTime.from_unix_utc(int64.parse(arr[0])); + this.date = date_utc.to_local(); + this.charge_now = long.parse(arr[1]); + this.voltage_now = long.parse(arr[2]); + this.cpu_usage = long.parse(arr[3]); + } + } + + public string to_delimited_string(){ + var txt = date.to_utc().to_unix().to_string() + "|"; + txt += charge_now.to_string() + "|"; + txt += voltage_now.to_string() + "|"; + txt += cpu_usage.to_string(); + txt += "\n"; + return txt; + } + + public string to_friendly_string(){ + var txt = ""; + txt += date.format("%F %H:%M:%S"); //%d %b %Y, %I:%M %p + txt += ", %6.2f%%, %5.0f mAh, %6.2f Wh".printf( + charge_percent(), + charge_in_mah(), + charge_in_wh() + ); + txt += ", %6.2f V".printf(voltage()); + txt += ", %6.2f %% CPU".printf(cpu_percent()); + txt += "\n"; + return txt; + } + + public double voltage(){ + return (voltage_now / 1000000.00); + } + + public double charge_percent(){ + return (((charge_now * 1.00) / batt_charge_full()) * 100); + } + + public double charge_in_mah(){ + return (charge_now / 1000.0); + } + + public double charge_in_wh(){ + return ((charge_in_mah() * voltage()) / 1000.00); + } + + public double cpu_percent(){ + return (cpu_usage / 1000.00); + } + + public static double batt_charge_percent(){ + return (((batt_charge_now() * 1.00) / batt_charge_full()) * 100); + } + + public static long batt_charge_now(){ + string val = read_sys_stat_file(BATT_STATS_CHARGE_NOW); + if (val.length == 0) { return 0; } + return long.parse(val); + } + + public static long batt_charge_full(){ + string val = read_sys_stat_file(BATT_STATS_CHARGE_FULL); + if (val.length == 0) { return 0; } + return long.parse(val); + } + + public static long batt_charge_full_design(){ + string val = read_sys_stat_file(BATT_STATS_CHARGE_FULL_DESIGN); + if (val.length == 0) { return 0; } + return long.parse(val); + } + + public static double batt_health(){ + if (batt_charge_full_design() > 0){ + return ((batt_charge_full() * 100.0) / batt_charge_full_design()); + } + else{ + return 0; + } + } + + public static long batt_voltage_now(){ + string val = read_sys_stat_file(BATT_STATS_VOLTAGE_NOW); + if (val.length == 0) { return 0; } + return long.parse(val); + } + + public static bool is_charging(){ + string val = read_sys_stat_file(BATT_STATS_STATUS); + return (val == "Charging"); + } + + public static string read_sys_stat_file(string statFile){ + try{ + var file = File.new_for_path(statFile); + if (file.query_exists()){ + var dis = new DataInputStream (file.read()); + string line = dis.read_line (null); + if (line != null) { + return line; + } + } //stream closed + } + catch (Error e){ + log_error (e.message); + } + + return ""; + } +} + diff -Nru aptik-battery-monitor-2.1/src/Common/Main.vala aptik-battery-monitor-17.12/src/Common/Main.vala --- aptik-battery-monitor-2.1/src/Common/Main.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Common/Main.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,434 @@ +/* + * Main.vala + * + * Copyright 2012-2017 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +using GLib; +using Gtk; +using Gee; +using Json; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.Multimedia; +using TeeJee.System; +using TeeJee.Misc; + +public Main App; +public const string AppName = "Aptik Battery Monitor"; +public const string AppShortName = "aptik-battery-monitor"; +public const string AppVersion = "17.12"; +public const string AppAuthor = "Tony George"; +public const string AppAuthorEmail = "teejeetech@gmail.com"; + +const string GETTEXT_PACKAGE = ""; +const string LOCALE_DIR = "/usr/share/locale"; + +extern void exit(int exit_code); + +public class Main : GLib.Object { + public static string BATT_STATS_CACHE_FILE = "/var/log/aptik-battery-monitor/stats.log"; + public static string BATT_STATS_HIST_FILE = "/var/log/aptik-battery-monitor/history.log"; + + public static int BATT_STATS_LOG_INTERVAL = 30; + public static double BATT_STATS_ARCHIVE_LEVEL = 99.00; + + public bool gui_mode = false; + public string user_login = ""; + public string user_home = ""; + public int user_uid = -1; + + public bool print_stats = false; + public string command = ""; + + public string temp_dir = ""; + public string backup_dir = ""; + public string share_dir = "/usr/share"; + public string app_conf_path = ""; + + public Gee.ArrayList battery_stats_list; + public BatteryStat stat_current; + public BatteryStat stat_prev; + public BatteryStat stat_prev2; + + public Main(string[] args, bool _gui_mode) { + + gui_mode = _gui_mode; + + init_tmp(); + + //config file + string home = Environment.get_home_dir(); + app_conf_path = home + "/.config/aptik-battery-monitor.json"; + + //load settings if GUI mode + if (gui_mode) { + load_app_config(); + } + + //check dependencies + string message; + if (!check_dependencies(out message)) { + if (gui_mode) { + string title = _("Missing Dependencies"); + gtk_messagebox(title, message, null, true); + } + exit(0); + } + + //initialize backup_dir as current directory for CLI mode + if (!gui_mode) { + backup_dir = Environment.get_current_dir() + "/"; + } + + try { + //create temp dir + temp_dir = get_temp_file_path(); + + var f = File.new_for_path(temp_dir); + if (f.query_exists()) { + Posix.system("rm -rf %s".printf(temp_dir)); + } + f.make_directory_with_parents(); + } + catch (Error e) { + log_error (e.message); + } + + //get user info + user_login = get_user_login(); + user_home = "/home/" + user_login; + user_uid = get_user_id(user_login); + + //BATT_STATS_CACHE_FILE = "%s/.local/log/aptik-battery-monitor/stats.log".printf(user_home); + + battery_stats_list = new Gee.ArrayList(); + } + + public void check_for_multiple_instances(){ + var app_lock = new ApplicationLock("aptik-battery-monitor", false); + if (app_lock.another_instance_is_running()){ + exit(0); + } + else{ + app_lock.create_lock(); + } + } + + public bool check_dependencies(out string msg) { + msg = ""; + + string[] dependencies = { "grep", "find" }; + + string path; + foreach(string cmd_tool in dependencies) { + path = get_cmd_path (cmd_tool); + if ((path == null) || (path.length == 0)) { + msg += " * " + cmd_tool + "\n"; + } + } + + if (msg.length > 0) { + msg = _("Commands listed below are not available on this system") + ":\n\n" + msg + "\n"; + msg += _("Please install the required packages"); + log_msg(msg); + return false; + } + else { + return true; + } + } + + /* Common */ + + public string create_log_dir() { + string log_dir = backup_dir + "logs/" + timestamp3(); + create_dir(log_dir); + return log_dir; + } + + public void save_app_config() { + var config = new Json.Object(); + + var json = new Json.Generator(); + json.pretty = true; + json.indent = 2; + var node = new Json.Node(NodeType.OBJECT); + node.set_object(config); + json.set_root(node); + + try { + json.to_file(this.app_conf_path); + } catch (Error e) { + log_error (e.message); + } + + if (gui_mode) { + log_msg(_("App config saved") + ": '%s'".printf(app_conf_path)); + } + } + + public void load_app_config() { + var f = File.new_for_path(app_conf_path); + if (!f.query_exists()) { + return; + } + + var parser = new Json.Parser(); + try { + parser.load_from_file(this.app_conf_path); + } + catch (Error e) { + log_error (e.message); + } + + //var node = parser.get_root(); + //var config = node.get_object(); + + if (gui_mode) { + log_msg(_("App config loaded") + ": '%s'".printf(this.app_conf_path)); + } + } + + public void exit_app() { + + save_app_config(); + + try { + //delete temporary files + var f = File.new_for_path(temp_dir); + if (f.query_exists()) { + f.delete(); + } + } + catch (Error e) { + log_error (e.message); + } + } + + /* Battery Stats */ + + public void log_battery_stats(bool print_stats) { + try { + // get stats ---------------------- + + var stat = new BatteryStat.read_from_sys(); + stat_current = stat; + + //create or open log + var file = File.new_for_path(BATT_STATS_CACHE_FILE); + if (!file.query_exists()) { + create_empty_log_file(BATT_STATS_CACHE_FILE); + battery_stats_list.clear(); + } + + //check if log needs rotation + check_and_rotate_log(); + + //add entry to log + battery_stats_list.add(stat); + var fos = file.append_to (FileCreateFlags.NONE); + var dos = new DataOutputStream (fos); + dos.put_string(stat.to_delimited_string()); + if (print_stats) { + stdout.printf(stat.to_friendly_string()); + } + + //rotate references + stat_prev2 = stat_prev; + stat_prev = stat_current; + } + catch (Error e) { + log_error (e.message); + } + } + + public bool check_and_rotate_log(){ + // rotates log file when battery drops after removing from charger + + bool rotated = false; + + if ((stat_prev != null) && (stat_prev2 != null)) { + + //check if charge levels for [stat_prev2, stat_prev, stat] are like + //[ 79.80, 80.00, 79.50] - increase and then decrease, or like + //[100.00, 100.00, 99.70] - same values and then decrease + + if((stat_current.charge_percent() < stat_prev.charge_percent()) + && ( (stat_prev.charge_percent() > stat_prev2.charge_percent()) + || (stat_prev2.charge_percent() == stat_prev.charge_percent()) + )) + { + + if (print_stats) { + stdout.printf("\n[" + _("Removed from charger") + "]\n\n"); + } + + log_battery_cycle_summary(); + + // create or open log ------------ + var file = File.new_for_path(BATT_STATS_CACHE_FILE); + if (!file.query_exists()) { + create_empty_log_file(BATT_STATS_CACHE_FILE); + battery_stats_list.clear(); + } + var date_label = (new DateTime.now_local()).format("%F_%H-%M-%S"); + var archive = File.new_for_path(BATT_STATS_CACHE_FILE + "." + date_label); + + try{ + file.move(archive, FileCopyFlags.NONE); + create_empty_log_file(BATT_STATS_CACHE_FILE); + rotated = true; + } + catch(Error e){ + log_error (e.message); + } + + if (print_stats) { + stdout.printf(_("Archived") + ": '%s'\n".printf(archive.get_path())); + stdout.printf(_("Logging stats to file") + ": '%s'\n\n".printf(BATT_STATS_CACHE_FILE)); + } + } + + if ((stat_current.charge_percent() > stat_prev.charge_percent()) + && (stat_prev.charge_percent() < stat_prev2.charge_percent())) + { + if (print_stats) { + stdout.printf("\n[" + _("Charging") + "]\n\n"); + } + } + } + + return rotated; + } + + public void log_battery_cycle_summary(){ + try { + //create or open hist log + var file = File.new_for_path(BATT_STATS_HIST_FILE); + if (!file.query_exists()) { + create_empty_log_file(BATT_STATS_HIST_FILE); + } + + var cycle = new BatteryCycle(); + cycle.calculate_stats(App.battery_stats_list); + + //log cycle summary + var fos = file.append_to (FileCreateFlags.NONE); + var dos = new DataOutputStream (fos); + dos.put_string(cycle.to_delimited_string()); + if (print_stats) { + stdout.printf(_("Logging summary to file") + ": '%s'\n".printf(BATT_STATS_HIST_FILE)); + stdout.printf(cycle.to_friendly_string() + "\n"); + } + } + catch (Error e) { + log_error (e.message); + } + } + + private void create_empty_log_file(string file_path) { + try { + var file = File.new_for_path(file_path); + var parent_dir = file.get_parent(); + + if (!parent_dir.query_exists()) { + parent_dir.make_directory_with_parents(); + Posix.system("chmod a+rwx '%s'".printf(parent_dir.get_path())); + } + + if (!file.query_exists()) { + Posix.system("touch '%s'".printf(file.get_path())); + Posix.system("chmod a+rwx '%s'".printf(file.get_path())); + } + } + catch (Error e) { + log_error (e.message); + } + } + + public void read_battery_stats() { + log_debug("call: read_battery_stats"); + var timer = timer_start(); + + try { + battery_stats_list = new Gee.ArrayList(); + + var file = File.new_for_path (BATT_STATS_CACHE_FILE); + if (file.query_exists ()) { + var dis = new DataInputStream (file.read()); + + string line; + while ((line = dis.read_line (null)) != null) { + var stat = new BatteryStat.from_delimited_string(line); + battery_stats_list.add(stat); + } + + if (battery_stats_list.size >= 1){ + stat_current = battery_stats_list[battery_stats_list.size - 1]; + } + if (battery_stats_list.size >= 2){ + stat_prev = battery_stats_list[battery_stats_list.size - 2]; + } + if (battery_stats_list.size >= 3){ + stat_prev2 = battery_stats_list[battery_stats_list.size - 3]; + } + + log_debug("read_battery_stats: %s".printf(timer_elapsed_string(timer))); + } + else { + log_error (_("File not found") + ": %s".printf(BATT_STATS_CACHE_FILE)); + } + } + catch (Error e) { + log_error (e.message); + } + } + + public void print_log_file(){ + BatteryStat stat_last = null; + foreach (BatteryStat stat in App.battery_stats_list){ + if ((stat_last != null) + && (stat_last.date.add_seconds(Main.BATT_STATS_LOG_INTERVAL + 1).compare(stat.date) < 0)) + { + stdout.printf(string.nfill(79, '-') + "\n"); + + var diff = stat.date.difference(stat_last.date); + + var hr = (int64) (diff / (1000000.0 * 60 * 60)); + diff = (int64) (diff % (1000000.0 * 60 * 60)); + var min = (int64) (diff / (1000000.0 * 60)); + diff = (int64) (diff % (1000000.0 * 60)); + var sec = (int64) (diff / (1000000.0)); + + stdout.printf("Gap: %02lld:%02lld:%02lld\n".printf(hr,min,sec)); + stdout.printf(string.nfill(79, '-') + "\n"); + } + + stdout.printf(stat.to_friendly_string()); + stat_last = stat; + } + } +} + diff -Nru aptik-battery-monitor-2.1/src/Common/Utility.vala aptik-battery-monitor-17.12/src/Common/Utility.vala --- aptik-battery-monitor-2.1/src/Common/Utility.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Common/Utility.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,2168 @@ +/* + * Utility.vala + * + * Copyright 2012 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +using Gtk; +using Json; +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.Multimedia; +using TeeJee.System; +using TeeJee.Misc; + +/* +extern void exit(int exit_code); +*/ + +namespace TeeJee.Logging{ + + /* Functions for logging messages to console and log files */ + + using TeeJee.Misc; + + public DataOutputStream dos_log; + + public bool LOG_ENABLE = true; + public bool LOG_TIMESTAMP = true; + public bool LOG_COLORS = true; + public bool LOG_DEBUG = false; + public bool LOG_COMMANDS = false; + + public void log_msg (string message, bool highlight = false){ + + if (!LOG_ENABLE) { return; } + + string msg = ""; + + if (highlight && LOG_COLORS){ + msg += "\033[1;38;5;34m"; + } + + if (LOG_TIMESTAMP){ + msg += "[" + timestamp() + "] "; + } + + msg += message; + + if (highlight && LOG_COLORS){ + msg += "\033[0m"; + } + + msg += "\n"; + + stdout.printf (msg); + + try { + if (dos_log != null){ + dos_log.put_string ("[%s] %s\n".printf(timestamp(), message)); + } + } + catch (Error e) { + stdout.printf (e.message); + } + } + + public void log_error (string message, bool highlight = false, bool is_warning = false){ + if (!LOG_ENABLE) { return; } + + string msg = ""; + + if (highlight && LOG_COLORS){ + msg += "\033[1;38;5;160m"; + } + + if (LOG_TIMESTAMP){ + msg += "[" + timestamp() + "] "; + } + + string prefix = (is_warning) ? _("Warning") : _("Error"); + + msg += prefix + ": " + message; + + if (highlight && LOG_COLORS){ + msg += "\033[0m"; + } + + msg += "\n"; + + stdout.printf (msg); + + try { + if (dos_log != null){ + dos_log.put_string ("[%s] %s: %s\n".printf(timestamp(), prefix, message)); + } + } + catch (Error e) { + stdout.printf (e.message); + } + } + + public void log_debug (string message){ + if (!LOG_ENABLE) { return; } + + if (LOG_DEBUG){ + log_msg (message); + } + else{ + try { + if (dos_log != null){ + dos_log.put_string ("[%s] %s\n".printf(timestamp(), message)); + } + } + catch (Error e) { + stdout.printf (e.message); + } + } + } +} + +namespace TeeJee.FileSystem{ + + /* Convenience functions for handling files and directories */ + + using TeeJee.Logging; + using TeeJee.FileSystem; + using TeeJee.ProcessManagement; + using TeeJee.Misc; + + public void file_delete(string filePath){ + + /* Check and delete file */ + + try { + var file = File.new_for_path (filePath); + if (file.query_exists ()) { + file.delete (); + } + } catch (Error e) { + log_error (e.message); + } + } + + public bool file_exists (string filePath){ + + /* Check if file exists */ + + return ( FileUtils.test(filePath, GLib.FileTest.EXISTS) && FileUtils.test(filePath, GLib.FileTest.IS_REGULAR)); + } + + public void file_copy (string src_file, string dest_file){ + try{ + var file_src = File.new_for_path (src_file); + if (file_src.query_exists()) { + var file_dest = File.new_for_path (dest_file); + file_src.copy(file_dest,FileCopyFlags.OVERWRITE,null,null); + } + } + catch(Error e){ + log_error (e.message); + } + } + + public bool dir_exists (string filePath){ + + /* Check if directory exists */ + + return ( FileUtils.test(filePath, GLib.FileTest.EXISTS) && FileUtils.test(filePath, GLib.FileTest.IS_DIR)); + } + + public bool create_dir (string filePath){ + + /* Creates a directory along with parents */ + + try{ + var dir = File.parse_name (filePath); + if (dir.query_exists () == false) { + dir.make_directory_with_parents (null); + } + return true; + } + catch (Error e) { + log_error (e.message); + return false; + } + } + + public bool move_file (string sourcePath, string destPath){ + + /* Move file from one location to another */ + + try{ + File fromFile = File.new_for_path (sourcePath); + File toFile = File.new_for_path (destPath); + fromFile.move (toFile, FileCopyFlags.NONE); + return true; + } + catch (Error e) { + log_error (e.message); + return false; + } + } + + public bool copy_file (string sourcePath, string destPath){ + + /* Copy file from one location to another */ + + try{ + File fromFile = File.new_for_path (sourcePath); + File toFile = File.new_for_path (destPath); + fromFile.copy (toFile, FileCopyFlags.NONE); + return true; + } + catch (Error e) { + log_error (e.message); + return false; + } + } + + public string? read_file (string file_path){ + + /* Reads text from file */ + + string txt; + size_t size; + + try{ + GLib.FileUtils.get_contents (file_path, out txt, out size); + return txt; + } + catch (Error e){ + log_error (e.message); + } + + return null; + } + + public DateTime? get_file_modification_time (string file_path){ + try{ + var file = File.new_for_path (file_path); + if (file.query_exists()) { + var info = file.query_info("*",FileQueryInfoFlags.NONE); + TimeVal modified = info.get_modification_time(); + return new DateTime.from_timeval_local(modified); + } + else{ + log_error("File not found: %s".printf(file_path)); + } + } + catch (Error e) { + log_error (e.message); + } + + return null; + } + + public bool write_file (string file_path, string contents){ + + /* Write text to file */ + + try{ + var file = File.new_for_path (file_path); + if (file.query_exists ()) { file.delete (); } + var file_stream = file.create (FileCreateFlags.REPLACE_DESTINATION); + var data_stream = new DataOutputStream (file_stream); + data_stream.put_string (contents); + data_stream.close(); + return true; + } + catch (Error e) { + log_error (e.message); + return false; + } + } + + public long get_file_count(string path){ + + /* Return total count of files and directories */ + + string cmd = ""; + string std_out; + string std_err; + int ret_val; + + cmd = "find \"%s\" | wc -l".printf(path); + ret_val = execute_command_script_sync(cmd, out std_out, out std_err); + return long.parse(std_out); + } + + public long get_file_size(string path){ + + /* Returns size of files and directories in KB*/ + + string cmd = ""; + string output = ""; + + cmd = "du -s \"%s\"".printf(path); + output = execute_command_sync_get_output(cmd); + return long.parse(output.split("\t")[0]); + } + + public string get_file_size_formatted(string path){ + + /* Returns size of files and directories in KB*/ + + string cmd = ""; + string output = ""; + + cmd = "du -s -h \"%s\"".printf(path); + output = execute_command_sync_get_output(cmd); + return output.split("\t")[0].strip(); + } + + public int chmod (string file, string permission){ + + /* Change file permissions */ + + return execute_command_sync ("chmod " + permission + " \"%s\"".printf(file)); + } + + public string resolve_relative_path (string filePath){ + + /* Resolve the full path of given file using 'realpath' command */ + + string filePath2 = filePath; + if (filePath2.has_prefix ("~")){ + filePath2 = Environment.get_home_dir () + "/" + filePath2[2:filePath2.length]; + } + + try { + string output = ""; + Process.spawn_command_line_sync("realpath \"%s\"".printf(filePath2), out output); + output = output.strip (); + if (FileUtils.test(output, GLib.FileTest.EXISTS)){ + return output; + } + } + catch(Error e){ + log_error (e.message); + } + + return filePath2; + } + + public int rsync (string sourceDirectory, string destDirectory, bool updateExisting, bool deleteExtra){ + + /* Sync files with rsync */ + + string cmd = "rsync --recursive --perms --chmod=a=rwx"; + cmd += updateExisting ? "" : " --ignore-existing"; + cmd += deleteExtra ? " --delete" : ""; + cmd += " \"%s\"".printf(sourceDirectory + "//"); + cmd += " \"%s\"".printf(destDirectory); + return execute_command_sync (cmd); + } +} + +namespace TeeJee.JSON{ + + using TeeJee.Logging; + + /* Convenience functions for reading and writing JSON files */ + + public string json_get_string(Json.Object jobj, string member, string def_value){ + if (jobj.has_member(member)){ + return jobj.get_string_member(member); + } + else{ + log_error ("Member not found in JSON object: " + member, false, true); + return def_value; + } + } + + public bool json_get_bool(Json.Object jobj, string member, bool def_value){ + if (jobj.has_member(member)){ + return bool.parse(jobj.get_string_member(member)); + } + else{ + log_error ("Member not found in JSON object: " + member, false, true); + return def_value; + } + } + + public int json_get_int(Json.Object jobj, string member, int def_value){ + if (jobj.has_member(member)){ + return int.parse(jobj.get_string_member(member)); + } + else{ + log_error ("Member not found in JSON object: " + member, false, true); + return def_value; + } + } + +} + +namespace TeeJee.ProcessManagement{ + using TeeJee.Logging; + using TeeJee.FileSystem; + using TeeJee.Misc; + + public string TEMP_DIR; + + /* Convenience functions for executing commands and managing processes */ + + public static void init_tmp(){ + string std_out, std_err; + + TEMP_DIR = Environment.get_tmp_dir() + "/" + AppShortName; + create_dir(TEMP_DIR); + + execute_command_script_sync("echo 'ok'",out std_out,out std_err, true); + if ((std_out == null)||(std_out.strip() != "ok")){ + TEMP_DIR = Environment.get_home_dir() + "/.temp/" + AppShortName; + execute_command_sync("rm -rf '%s'".printf(TEMP_DIR)); + create_dir(TEMP_DIR); + } + + //log_debug("TEMP_DIR=" + TEMP_DIR); + } + + public int execute_command_sync (string cmd){ + + /* Executes single command synchronously and returns exit code + * Pipes and multiple commands are not supported */ + + try { + int exitCode; + Process.spawn_command_line_sync(cmd, null, null, out exitCode); + return exitCode; + } + catch (Error e){ + log_error (e.message); + return -1; + } + } + + public string execute_command_sync_get_output (string cmd){ + + /* Executes single command synchronously and returns std_out + * Pipes and multiple commands are not supported */ + + try { + int exitCode; + string std_out; + Process.spawn_command_line_sync(cmd, out std_out, null, out exitCode); + return std_out; + } + catch (Error e){ + log_error (e.message); + return ""; + } + } + + public bool execute_command_script_async (string cmd){ + + /* Creates a temporary bash script with given commands and executes it asynchronously + * Return value indicates if script was started successfully */ + + try { + + string scriptfile = create_temp_bash_script (cmd); + + string[] argv = new string[1]; + argv[0] = scriptfile; + + Pid child_pid; + Process.spawn_async_with_pipes( + null, //working dir + argv, //argv + null, //environment + SpawnFlags.SEARCH_PATH, + null, + out child_pid); + return true; + } + catch (Error e){ + log_error (e.message); + return false; + } + } + + public string? create_temp_bash_script (string script_text, bool supress_errors = false){ + + /* Creates a temporary bash script with given commands + * Returns the script file path */ + + var sh = ""; + sh += "#!/bin/bash\n"; + sh += script_text; + + string script_path = get_temp_file_path() + ".sh"; + + try{ + //write script file + var file = File.new_for_path (script_path); + if (file.query_exists ()) { file.delete (); } + var file_stream = file.create (FileCreateFlags.REPLACE_DESTINATION); + var data_stream = new DataOutputStream (file_stream); + data_stream.put_string (sh); + data_stream.close(); + + // set execute permission + chmod (script_path, "u+x"); + + return script_path; + } + catch (Error e) { + if (!supress_errors){ + log_error (e.message); + } + } + + return null; + } + + public string get_temp_file_path(){ + + /* Generates temporary file path */ + + return TEMP_DIR + "/" + timestamp2() + (new Rand()).next_int().to_string(); + } + + public int execute_command_script_sync (string script, out string std_out, out string std_err, bool supress_errors = false){ + + /* Executes commands synchronously + * Returns exit code, output messages and error messages. + * Commands are written to a temporary bash script and executed. */ + + string path = create_temp_bash_script(script,supress_errors); + + try { + + string[] argv = new string[1]; + argv[0] = path; + + int exit_code; + + Process.spawn_sync ( + TEMP_DIR, //working dir + argv, //argv + null, //environment + SpawnFlags.SEARCH_PATH, + null, // child_setup + out std_out, + out std_err, + out exit_code + ); + + return exit_code; + } + catch (Error e){ + if (!supress_errors){ + log_error (e.message); + } + return -1; + } + } + + public int execute_command_script_sync2 (string script){ + + /* Executes commands synchronously + * Returns exit code, output messages and error messages. + * Commands are written to a temporary bash script and executed. */ + + string path = create_temp_bash_script(script); + + try { + + string[] argv = new string[1]; + argv[0] = path; + + int exit_code; + + Process.spawn_sync ( + TEMP_DIR, //working dir + argv, //argv + null, //environment + SpawnFlags.SEARCH_PATH, + null, // child_setup + null, + null, + out exit_code + ); + + return exit_code; + } + catch (Error e){ + log_error (e.message); + return -1; + } + } + + public bool execute_command_script_in_terminal_sync (string script){ + + /* Executes a command script in a terminal window */ + //TODO: Remove this + + try { + + string[] argv = new string[3]; + argv[0] = "x-terminal-emulator"; + argv[1] = "-e"; + argv[2] = script; + + Process.spawn_sync ( + TEMP_DIR, //working dir + argv, //argv + null, //environment + SpawnFlags.SEARCH_PATH, + null // child_setup + ); + + return true; + } + catch (Error e){ + log_error (e.message); + return false; + } + } + + public int execute_bash_script_fullscreen_sync (string script_file){ + + /* Executes a bash script synchronously. + * Script is executed in a fullscreen terminal window */ + + string path; + + path = get_cmd_path ("xfce4-terminal"); + if ((path != null)&&(path != "")){ + return execute_command_sync ("xfce4-terminal --fullscreen -e \"%s\"".printf(script_file)); + } + + path = get_cmd_path ("gnome-terminal"); + if ((path != null)&&(path != "")){ + return execute_command_sync ("gnome-terminal --full-screen -e \"%s\"".printf(script_file)); + } + + path = get_cmd_path ("xterm"); + if ((path != null)&&(path != "")){ + return execute_command_sync ("xterm --fullscreen -e \"%s\"".printf(script_file)); + } + + //default terminal - unknown, normal window + path = get_cmd_path ("x-terminal-emulator"); + if ((path != null)&&(path != "")){ + return execute_command_sync ("x-terminal-emulator -e \"%s\"".printf(script_file)); + } + + return -1; + } + + public int execute_bash_script_sync (string script_file){ + + /* Executes a bash script synchronously in the default terminal window */ + + string path = get_cmd_path ("x-terminal-emulator"); + if ((path != null)&&(path != "")){ + return execute_command_sync ("x-terminal-emulator -e \"%s\"".printf(script_file)); + } + + return -1; + } + + public string get_cmd_path (string cmd){ + + /* Returns the full path to a command */ + + try { + int exitCode; + string stdout, stderr; + Process.spawn_command_line_sync("which " + cmd, out stdout, out stderr, out exitCode); + return stdout; + } + catch (Error e){ + log_error (e.message); + return ""; + } + } + + public int get_pid_by_name (string name){ + + /* Get the process ID for a process with given name */ + + try{ + string output = ""; + Process.spawn_command_line_sync("pidof \"%s\"".printf(name), out output); + if (output != null){ + string[] arr = output.split ("\n"); + if (arr.length > 0){ + return int.parse (arr[0]); + } + } + } + catch (Error e) { + log_error (e.message); + } + + return -1; + } + + public bool process_is_running_by_name(string proc_name){ + + /* Checks if given process is running + * Note: We are not using 'psgrep -f' as it cannot be used for an exact match*/ + + /* TODO: This matches processes ending with proc_name. Should not match */ + + string txt = execute_command_sync_get_output ("ps w -C '%s'".printf(proc_name)); + //use 'ps ew -C ''' for all users + + foreach(string line in txt.split("\n")){ + string padded_line = line + " "; + if (padded_line.index_of(proc_name + " ") > -1){ + return true; + } + } + + return false; + } + + public bool process_is_running(long pid){ + + /* Checks if given process is running */ + + string cmd = ""; + string std_out; + string std_err; + int ret_val; + + try{ + cmd = "ps --pid %ld".printf(pid); + Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); + } + catch (Error e) { + log_error (e.message); + return false; + } + + return (ret_val == 0); + } + + public int[] get_process_children (Pid parentPid){ + + /* Returns the list of child processes spawned by given process */ + + string output; + + try { + Process.spawn_command_line_sync("ps --ppid %d".printf(parentPid), out output); + } + catch(Error e){ + log_error (e.message); + } + + int pid; + int[] procList = {}; + string[] arr; + + foreach (string line in output.split ("\n")){ + arr = line.strip().split (" "); + if (arr.length < 1) { continue; } + + pid = 0; + pid = int.parse (arr[0]); + + if (pid != 0){ + procList += pid; + } + } + return procList; + } + + + public void process_kill(Pid process_pid, bool killChildren = true){ + + /* Kills specified process and its children (optional) */ + + int[] child_pids = get_process_children (process_pid); + Posix.kill (process_pid, 15); + + if (killChildren){ + Pid childPid; + foreach (long pid in child_pids){ + childPid = (Pid) pid; + Posix.kill (childPid, 15); + } + } + } + + public int process_pause (Pid procID){ + + /* Pause/Freeze a process */ + + return execute_command_sync ("kill -STOP %d".printf(procID)); + } + + public int process_resume (Pid procID){ + + /* Resume/Un-freeze a process*/ + + return execute_command_sync ("kill -CONT %d".printf(procID)); + } + + public void command_kill(string cmd_name, string cmd_to_match, bool exact_match){ + + /* Kills a specific command */ + + string txt = execute_command_sync_get_output ("ps w -C '%s'".printf(cmd_name)); + //use 'ps ew -C conky' for all users + + string pid = ""; + foreach(string line in txt.split("\n")){ + if ((exact_match && line.strip().has_suffix(cmd_to_match)) + || (!exact_match && (line.index_of(cmd_to_match) != -1))){ + pid = line.strip().split(" ")[0]; + Posix.kill ((Pid) int.parse(pid), 15); + log_debug(_("Stopped") + ": [PID=" + pid + "] "); + } + } + } + + + public void process_set_priority (Pid procID, int prio){ + + /* Set process priority */ + + if (Posix.getpriority (Posix.PRIO_PROCESS, procID) != prio) + Posix.setpriority (Posix.PRIO_PROCESS, procID, prio); + } + + public int process_get_priority (Pid procID){ + + /* Get process priority */ + + return Posix.getpriority (Posix.PRIO_PROCESS, procID); + } + + public void process_set_priority_normal (Pid procID){ + + /* Set normal priority for process */ + + process_set_priority (procID, 0); + } + + public void process_set_priority_low (Pid procID){ + + /* Set low priority for process */ + + process_set_priority (procID, 5); + } + + + public bool user_is_admin (){ + + /* Check if current application is running with admin priviledges */ + + try{ + // create a process + string[] argv = { "sleep", "10" }; + Pid procId; + Process.spawn_async(null, argv, null, SpawnFlags.SEARCH_PATH, null, out procId); + + // try changing the priority + Posix.setpriority (Posix.PRIO_PROCESS, procId, -5); + + // check if priority was changed successfully + if (Posix.getpriority (Posix.PRIO_PROCESS, procId) == -5) + return true; + else + return false; + } + catch (Error e) { + log_error (e.message); + return false; + } + } + + public string get_user_login(){ + /* + Returns Login ID of current user. + If running as 'sudo' it will return Login ID of the actual user. + */ + + string cmd = "echo ${SUDO_USER:-$(whoami)}"; + string std_out; + string std_err; + int ret_val; + ret_val = execute_command_script_sync(cmd, out std_out, out std_err); + + string user_name; + if ((std_out == null) || (std_out.length == 0)){ + user_name = "root"; + } + else{ + user_name = std_out.strip(); + } + + return user_name; + } + + public int get_user_id(string user_login){ + /* + Returns UID of specified user. + */ + + int uid = -1; + string cmd = "id %s -u".printf(user_login); + string txt = execute_command_sync_get_output(cmd); + if ((txt != null) && (txt.length > 0)){ + uid = int.parse(txt); + } + + return uid; + } + + + public string get_app_path (){ + + /* Get path of current process */ + + try{ + return GLib.FileUtils.read_link ("/proc/self/exe"); + } + catch (Error e){ + log_error (e.message); + return ""; + } + } + + public string get_app_dir (){ + + /* Get parent directory of current process */ + + try{ + return (File.new_for_path (GLib.FileUtils.read_link ("/proc/self/exe"))).get_parent ().get_path (); + } + catch (Error e){ + log_error (e.message); + return ""; + } + } + + + public class ApplicationLock{ + string pid_current = ""; + string app_name = ""; + bool gui_mode = false; + + public ApplicationLock(string _app_name, bool _gui_mode){ + app_name = _app_name; + gui_mode = _gui_mode; + pid_current = ((long)Posix.getpid()).to_string(); + } + + public string lock_file{ + owned get { + return "/var/run/lock/%s.lock".printf(app_name); + } + } + + public bool another_instance_is_running(){ + try{ + var file = File.new_for_path (lock_file); + if (file.query_exists()) { + var dis = new DataInputStream (file.read()); + string line; + + if ((line = dis.read_line (null)) != null) { + long pid = long.parse(line.strip()); + + if (process_is_running(pid)){ + stderr.printf(_("[Error] Another instance of this process is already running") + " (PID=%ld)\n".printf(pid)); + stderr.flush(); + + return true; + } + else{ + stderr.printf(_("[Warning] Removed invalid lock file") + ": '%s'\n".printf(lock_file)); + stderr.flush(); + + file.delete(); + return false; + } + } + + dis.close(); + } + + return false; + } + catch (Error e) { + stderr.printf (e.message); + stderr.flush(); + return false; + } + } + + public void create_lock(){ + try{ + var file = File.new_for_path (lock_file); + var fs = file.create (FileCreateFlags.REPLACE_DESTINATION); + var dos = new DataOutputStream (fs); + dos.put_string (pid_current); + dos.close(); + } + catch (Error e) { + log_error (e.message); + } + } + + public void remove_lock(){ + try{ + var file = File.new_for_path (lock_file); + if (file.query_exists()) { + file.delete(); + } + } + catch (Error e) { + log_error (e.message); + } + } + } + +} + +namespace TeeJee.GtkHelper{ + + using Gtk; + + public void gtk_do_events (){ + + /* Do pending events */ + + while(Gtk.events_pending ()) + Gtk.main_iteration (); + } + + public void gtk_set_busy (bool busy, Gtk.Window win) { + + /* Show or hide busy cursor on window */ + + Gdk.Cursor? cursor = null; + + if (busy){ + cursor = new Gdk.Cursor(Gdk.CursorType.WATCH); + } + else{ + cursor = new Gdk.Cursor(Gdk.CursorType.ARROW); + } + + var window = win.get_window (); + + if (window != null) { + window.set_cursor (cursor); + } + + gtk_do_events (); + } + + public void gtk_messagebox(string title, string message, Gtk.Window? parent_win, bool is_error = false){ + + /* Shows a simple message box */ + + Gtk.MessageType type = Gtk.MessageType.INFO; + if (is_error){ + type = Gtk.MessageType.ERROR; + } + else{ + type = Gtk.MessageType.INFO; + } + + var dlg = new Gtk.MessageDialog.with_markup(null, Gtk.DialogFlags.MODAL, type, Gtk.ButtonsType.OK, message); + dlg.title = title; + dlg.set_default_size (200, -1); + if (parent_win != null){ + dlg.set_transient_for(parent_win); + dlg.set_modal(true); + } + dlg.run(); + dlg.destroy(); + } + + public bool gtk_combobox_set_value (ComboBox combo, int index, string val){ + + /* Conveniance function to set combobox value */ + + TreeIter iter; + string comboVal; + TreeModel model = (TreeModel) combo.model; + + bool iterExists = model.get_iter_first (out iter); + while (iterExists){ + model.get(iter, 1, out comboVal); + if (comboVal == val){ + combo.set_active_iter(iter); + return true; + } + iterExists = model.iter_next (ref iter); + } + + return false; + } + + public string gtk_combobox_get_value (ComboBox combo, int index, string default_value){ + + /* Conveniance function to get combobox value */ + + if ((combo.model == null) || (combo.active < 0)) { return default_value; } + + TreeIter iter; + string val = ""; + combo.get_active_iter (out iter); + TreeModel model = (TreeModel) combo.model; + model.get(iter, index, out val); + + return val; + } + + public class CellRendererProgress2 : Gtk.CellRendererProgress{ + public override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) { + if (text == "--") + return; + + int diff = (int) ((cell_area.height - height)/2); + + // Apply the new height into the bar, and center vertically: + Gdk.Rectangle new_area = Gdk.Rectangle() ; + new_area.x = cell_area.x; + new_area.y = cell_area.y + diff; + new_area.width = width - 5; + new_area.height = height; + + base.render(cr, widget, background_area, new_area, flags); + } + } + + public Gdk.Pixbuf? get_app_icon(int icon_size, string format = ".png"){ + var img_icon = get_shared_icon(AppShortName, AppShortName + format,icon_size,"pixmaps"); + if (img_icon != null){ + return img_icon.pixbuf; + } + else{ + return null; + } + } + + public Gtk.Image? get_shared_icon(string icon_name, string fallback_icon_file_name, int icon_size, string icon_directory = AppShortName + "/images"){ + Gdk.Pixbuf pix_icon = null; + Gtk.Image img_icon = null; + + try { + Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default(); + pix_icon = icon_theme.load_icon (icon_name, icon_size, 0); + } catch (Error e) { + //log_error (e.message); + } + + string fallback_icon_file_path = "/usr/share/%s/%s".printf(icon_directory, fallback_icon_file_name); + + if (pix_icon == null){ + try { + pix_icon = new Gdk.Pixbuf.from_file_at_size (fallback_icon_file_path, icon_size, icon_size); + } catch (Error e) { + log_error (e.message); + } + } + + if (pix_icon == null){ + log_error (_("Missing Icon") + ": '%s', '%s'".printf(icon_name, fallback_icon_file_path)); + } + else{ + img_icon = new Gtk.Image.from_pixbuf(pix_icon); + } + + return img_icon; + } + + public int gtk_treeview_model_count(TreeModel model){ + int count = 0; + TreeIter iter; + if (model.get_iter_first(out iter)){ + count++; + while(model.iter_next(ref iter)){ + count++; + } + } + return count; + } +} + +namespace TeeJee.Multimedia{ + + using TeeJee.Logging; + + /* Functions for working with audio/video files */ + + public long get_file_duration(string filePath){ + + /* Returns the duration of an audio/video file using MediaInfo */ + + string output = "0"; + + try { + Process.spawn_command_line_sync("mediainfo \"--Inform=General;%Duration%\" \"" + filePath + "\"", out output); + } + catch(Error e){ + log_error (e.message); + } + + return long.parse(output); + } + + public string get_file_crop_params (string filePath){ + + /* Returns cropping parameters for a video file using avconv */ + + string output = ""; + string error = ""; + + try { + Process.spawn_command_line_sync("avconv -i \"%s\" -vf cropdetect=30 -ss 5 -t 5 -f matroska -an -y /dev/null".printf(filePath), out output, out error); + } + catch(Error e){ + log_error (e.message); + } + + int w=0,h=0,x=10000,y=10000; + int num=0; + string key,val; + string[] arr; + + foreach (string line in error.split ("\n")){ + if (line == null) { continue; } + if (line.index_of ("crop=") == -1) { continue; } + + foreach (string part in line.split (" ")){ + if (part == null || part.length == 0) { continue; } + + arr = part.split (":"); + if (arr.length != 2) { continue; } + + key = arr[0].strip (); + val = arr[1].strip (); + + switch (key){ + case "x": + num = int.parse (arr[1]); + if (num < x) { x = num; } + break; + case "y": + num = int.parse (arr[1]); + if (num < y) { y = num; } + break; + case "w": + num = int.parse (arr[1]); + if (num > w) { w = num; } + break; + case "h": + num = int.parse (arr[1]); + if (num > h) { h = num; } + break; + } + } + } + + if (x == 10000 || y == 10000) + return "%i:%i:%i:%i".printf(0,0,0,0); + else + return "%i:%i:%i:%i".printf(w,h,x,y); + } + + public string get_mediainfo (string filePath){ + + /* Returns the multimedia properties of an audio/video file using MediaInfo */ + + string output = ""; + + try { + Process.spawn_command_line_sync("mediainfo \"%s\"".printf(filePath), out output); + } + catch(Error e){ + log_error (e.message); + } + + return output; + } + + + +} + +namespace TeeJee.System{ + + using TeeJee.ProcessManagement; + using TeeJee.Logging; + + public double get_system_uptime_seconds(){ + + /* Returns the system up-time in seconds */ + + string cmd = ""; + string std_out; + string std_err; + int ret_val; + + try{ + cmd = "cat /proc/uptime"; + Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); + string uptime = std_out.split(" ")[0]; + double secs = double.parse(uptime); + return secs; + } + catch(Error e){ + log_error (e.message); + return 0; + } + } + + public string get_desktop_name(){ + + /* Return the names of the current Desktop environment */ + + int pid = -1; + + pid = get_pid_by_name("cinnamon"); + if (pid > 0){ + return "Cinnamon"; + } + + pid = get_pid_by_name("xfdesktop"); + if (pid > 0){ + return "Xfce"; + } + + pid = get_pid_by_name("lxsession"); + if (pid > 0){ + return "LXDE"; + } + + pid = get_pid_by_name("gnome-shell"); + if (pid > 0){ + return "Gnome"; + } + + pid = get_pid_by_name("wingpanel"); + if (pid > 0){ + return "Elementary"; + } + + pid = get_pid_by_name("unity-panel-service"); + if (pid > 0){ + return "Unity"; + } + + pid = get_pid_by_name("plasma-desktop"); + if (pid > 0){ + return "KDE"; + } + + return "Unknown"; + } + + public bool check_internet_connectivity(){ + int exit_code = -1; + string std_err; + string std_out; + + try { + string cmd = "ping -c 1 google.com"; + Process.spawn_command_line_sync(cmd, out std_out, out std_err, out exit_code); + } + catch (Error e){ + log_error (e.message); + } + + return (exit_code == 0); + } + + public bool shutdown (){ + + /* Shutdown the system immediately */ + + try{ + string[] argv = { "shutdown", "-h", "now" }; + Pid procId; + Process.spawn_async(null, argv, null, SpawnFlags.SEARCH_PATH, null, out procId); + return true; + } + catch (Error e) { + log_error (e.message); + return false; + } + } + + public bool xdg_open (string file){ + string path; + path = get_cmd_path ("xdg-open"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("xdg-open \"" + file + "\""); + } + return false; + } + + public bool exo_open_folder (string dir_path, bool xdg_open_try_first = true){ + + /* Tries to open the given directory in a file manager */ + + /* + xdg-open is a desktop-independent tool for configuring the default applications of a user. + Inside a desktop environment (e.g. GNOME, KDE, Xfce), xdg-open simply passes the arguments + to that desktop environment's file-opener application (gvfs-open, kde-open, exo-open, respectively). + We will first try using xdg-open and then check for specific file managers if it fails. + */ + + string path; + + if (xdg_open_try_first){ + //try using xdg-open + path = get_cmd_path ("xdg-open"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("xdg-open \"" + dir_path + "\""); + } + } + + path = get_cmd_path ("nemo"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("nemo \"" + dir_path + "\""); + } + + path = get_cmd_path ("nautilus"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("nautilus \"" + dir_path + "\""); + } + + path = get_cmd_path ("thunar"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("thunar \"" + dir_path + "\""); + } + + path = get_cmd_path ("pantheon-files"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("pantheon-files \"" + dir_path + "\""); + } + + path = get_cmd_path ("marlin"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("marlin \"" + dir_path + "\""); + } + + if (xdg_open_try_first == false){ + //try using xdg-open + path = get_cmd_path ("xdg-open"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("xdg-open \"" + dir_path + "\""); + } + } + + return false; + } + + public bool exo_open_textfile (string txt){ + + /* Tries to open the given text file in a text editor */ + + string path; + + path = get_cmd_path ("exo-open"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("exo-open \"" + txt + "\""); + } + + path = get_cmd_path ("gedit"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("gedit --new-document \"" + txt + "\""); + } + + return false; + } + + public bool exo_open_url (string url){ + + /* Tries to open the given text file in a text editor */ + + string path; + + path = get_cmd_path ("exo-open"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("exo-open \"" + url + "\""); + } + + path = get_cmd_path ("firefox"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("firefox \"" + url + "\""); + } + + path = get_cmd_path ("chromium-browser"); + if ((path != null)&&(path != "")){ + return execute_command_script_async ("chromium-browser \"" + url + "\""); + } + + return false; + } + + public GLib.Timer timer_start(){ + var timer = new GLib.Timer(); + timer.start(); + return timer; + } + + public ulong timer_elapsed(GLib.Timer timer){ + ulong microseconds; + double seconds; + seconds = timer.elapsed (out microseconds); + return microseconds; + } + + public void sleep(int milliseconds){ + Thread.usleep ((ulong) milliseconds * 1000); + } + + public string timer_elapsed_string(GLib.Timer timer, bool stop = true){ + ulong microseconds; + double seconds; + seconds = timer.elapsed (out microseconds); + if (stop){ + timer.stop(); + } + return "%.0f ms".printf((seconds * 1000 ) + microseconds/1000); + } + + public void timer_elapsed_print(GLib.Timer timer, bool stop = true){ + ulong microseconds; + double seconds; + seconds = timer.elapsed (out microseconds); + if (stop){ + timer.stop(); + } + log_msg("%s %lu\n".printf(seconds.to_string(), microseconds)); + } + + public bool crontab_remove(string search_string){ + string cmd = ""; + string std_out; + string std_err; + int ret_val; + + cmd = "crontab -l | sed '/%s/d' | crontab -".printf(search_string); + ret_val = execute_command_script_sync(cmd, out std_out, out std_err); + + if (ret_val != 0){ + log_error(std_err); + return false; + } + else{ + return true; + } + } + + public bool crontab_add(string entry){ + string cmd = ""; + string std_out; + string std_err; + int ret_val; + + try{ + string crontab = crontab_read(); + crontab += crontab.has_suffix("\n") ? "" : "\n"; + crontab += entry + "\n"; + + //remove empty lines + crontab = crontab.replace("\n\n","\n"); //remove empty lines in middle + crontab = crontab.has_prefix("\n") ? crontab[1:crontab.length] : crontab; //remove empty lines in beginning + + string temp_file = get_temp_file_path(); + write_file(temp_file, crontab); + + cmd = "crontab \"%s\"".printf(temp_file); + Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); + + if (ret_val != 0){ + log_error(std_err); + return false; + } + else{ + return true; + } + } + catch(Error e){ + log_error (e.message); + return false; + } + } + + public string crontab_read(){ + string cmd = ""; + string std_out; + string std_err; + int ret_val; + + try { + cmd = "crontab -l"; + Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); + if (ret_val != 0){ + log_debug(_("Crontab is empty")); + return ""; + } + else{ + return std_out; + } + } + catch (Error e){ + log_error (e.message); + return ""; + } + } + + public string crontab_search(string search_string, bool use_regex_matching = false){ + string cmd = ""; + string std_out; + string std_err; + int ret_val; + + try{ + Regex rex = null; + MatchInfo match; + if (use_regex_matching){ + rex = new Regex(search_string); + } + + cmd = "crontab -l"; + Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); + if (ret_val != 0){ + log_debug(_("Crontab is empty")); + } + else{ + foreach(string line in std_out.split("\n")){ + if (use_regex_matching && (rex != null)){ + if (rex.match (line, 0, out match)){ + return line.strip(); + } + } + else { + if (line.contains(search_string)){ + return line.strip(); + } + } + } + } + + return ""; + } + catch(Error e){ + log_error (e.message); + return ""; + } + } + + public bool check_if_path_is_mounted_on_tmpfs( + string path, bool show_msg, Gtk.Window? parent_window, bool exit_app) + { + int status = Posix.system("df --type=tmpfs '%s' > /dev/null 2>&1".printf(path)); + + if (status == 0){ + if (show_msg){ + string msg = _("/var/spool on your system is mounted in memory (tmpfs)!!\n\n/var/spool should never be mounted in tmpfs as the user's cron jobs are stored here along with other system files. If you have done this to reduce writes to your SSD, please undo it by editing your /etc/fstab file. This application will not work till this is corrected."); + + if (parent_window != null){ + gtk_messagebox("System Issue",msg,parent_window,true); + } + else{ + log_error(msg); + } + } + if (exit_app){ + exit(1); + } + } + + return (status == 0); + } + + public const string RC_LOCAL_FILE = "/etc/rc.local"; + + //admin access needed + public bool rc_local_add(string line_to_add){ + try { + if (!file_exists(RC_LOCAL_FILE)) { + log_error ("File not found: %s".printf(RC_LOCAL_FILE)); + return false; + } + + var txt = read_file(RC_LOCAL_FILE); + var lines = new Gee.ArrayList(); + foreach (string line in txt.split("\n")) { + lines.add(line); + } + + Regex rex_exit_line = new Regex("""^[ \t]*exit[ \t\(]*0[ \t\)]*$"""); + MatchInfo match; + + for (int i = 0; i < lines.size; i++) { + string line = lines[i]; + if (rex_exit_line.match (line, 0, out match)) { + lines.insert(i, line_to_add); + break; + } + } + + txt = ""; + for (int i = 0; i < lines.size; i++) { + string line = lines[i]; + bool is_last_line = (i == lines.size - 1); + if ((line.length == 0) && is_last_line) { + continue; + } + txt += line + "\n"; + } + write_file(RC_LOCAL_FILE, txt); + Posix.system("chmod a+x %s".printf(RC_LOCAL_FILE)); + + return true; + } + catch (Error e) { + log_error (e.message); + return false; + } + } + + //admin access needed + public bool rc_local_remove(string line_to_remove){ + try { + if (!file_exists(RC_LOCAL_FILE)) { + log_error ("File not found: %s".printf(RC_LOCAL_FILE)); + return false; + } + + var txt = read_file(RC_LOCAL_FILE); + var lines = new Gee.ArrayList(); + foreach (string line in txt.split("\n")) { + lines.add(line); + } + + for (int i = 0; i < lines.size; i++) { + string line = lines[i]; + if (line == line_to_remove) { + lines.remove(line); + break; + } + } + + txt = ""; + for (int i = 0; i < lines.size; i++) { + string line = lines[i]; + bool is_last_line = (i == lines.size - 1); + if ((line.length == 0) && is_last_line) { + continue; + } + txt += line + "\n"; + } + write_file(RC_LOCAL_FILE, txt); + Posix.system("chmod a+x %s".printf(RC_LOCAL_FILE)); + + return true; + } + catch (Error e) { + log_error (e.message); + return false; + } + } + + private DateTime dt_last_notification = null; + private const int NOTIFICATION_INTERVAL = 3; + + public int notify_send (string title, string message, int durationMillis, string urgency, string dialog_type = "info"){ + + /* Displays notification bubble on the desktop */ + + int retVal = 0; + + switch (dialog_type){ + case "error": + case "info": + case "warning": + //ok + break; + default: + dialog_type = "info"; + break; + } + + long seconds = 9999; + if (dt_last_notification != null){ + DateTime dt_end = new DateTime.now_local(); + TimeSpan elapsed = dt_end.difference(dt_last_notification); + seconds = (long)(elapsed * 1.0 / TimeSpan.SECOND); + } + + if (seconds > NOTIFICATION_INTERVAL){ + string s = "notify-send -t %d -u %s -i %s \"%s\" \"%s\"".printf(durationMillis, urgency, "gtk-dialog-" + dialog_type, title, message); + retVal = execute_command_sync (s); + dt_last_notification = new DateTime.now_local(); + } + + return retVal; + } + + public bool set_directory_ownership(string dir_name, string login_name){ + try { + string cmd = "chown %s -R %s".printf(login_name, dir_name); + int exit_code; + Process.spawn_command_line_sync(cmd, null, null, out exit_code); + + if (exit_code == 0){ + //log_msg(_("Ownership changed to '%s' for files in directory '%s'").printf(login_name, dir_name)); + return true; + } + else{ + log_error(_("Failed to set ownership") + ": %s, %s".printf(login_name, dir_name)); + return false; + } + } + catch (Error e){ + log_error (e.message); + return false; + } + } + + public class ProcStats{ + public double user = 0; + public double nice = 0; + public double system = 0; + public double idle = 0; + public double iowait = 0; + + public double user_delta = 0; + public double nice_delta = 0; + public double system_delta = 0; + public double idle_delta = 0; + public double iowait_delta = 0; + + public double usage_percent = 0; + + public static ProcStats stat_prev = null; + + public ProcStats(string line){ + string[] arr = line.split(" "); + int col = 0; + if (arr[col++] == "cpu"){ + if (arr[col].length == 0){ col++; }; + + user = double.parse(arr[col++]); + nice = double.parse(arr[col++]); + system = double.parse(arr[col++]); + idle = double.parse(arr[col++]); + iowait = double.parse(arr[col++]); + + if (ProcStats.stat_prev != null){ + user_delta = user - ProcStats.stat_prev.user; + nice_delta = nice - ProcStats.stat_prev.nice; + system_delta = system - ProcStats.stat_prev.system; + idle_delta = idle - ProcStats.stat_prev.idle; + iowait_delta = iowait - ProcStats.stat_prev.iowait; + + usage_percent = (user_delta + nice_delta + system_delta) * 100 / (user_delta + nice_delta + system_delta + idle_delta); + } + else{ + usage_percent = 0; + + } + + ProcStats.stat_prev = this; + } + } + + //returns 0 when it is called first time + public static double get_cpu_usage(){ + string txt = read_file("/proc/stat"); + foreach(string line in txt.split("\n")){ + string[] arr = line.split(" "); + if (arr[0] == "cpu"){ + ProcStats stat = new ProcStats(line); + return stat.usage_percent; + } + } + return 0; + } + } +} + +namespace TeeJee.Misc { + + /* Various utility functions */ + + using Gtk; + using TeeJee.Logging; + using TeeJee.FileSystem; + using TeeJee.ProcessManagement; + + public class DistInfo : GLib.Object{ + + /* Class for storing information about linux distribution */ + + public string dist_id = ""; + public string description = ""; + public string release = ""; + public string codename = ""; + + public DistInfo(){ + dist_id = ""; + description = ""; + release = ""; + codename = ""; + } + + public string full_name(){ + if (dist_id == ""){ + return ""; + } + else{ + string val = ""; + val += dist_id; + val += (release.length > 0) ? " " + release : ""; + val += (codename.length > 0) ? " (" + codename + ")" : ""; + return val; + } + } + + public static DistInfo get_dist_info(string root_path){ + + /* Returns information about the Linux distribution + * installed at the given root path */ + + DistInfo info = new DistInfo(); + + string dist_file = root_path + "/etc/lsb-release"; + var f = File.new_for_path(dist_file); + if (f.query_exists()){ + + /* + DISTRIB_ID=Ubuntu + DISTRIB_RELEASE=13.04 + DISTRIB_CODENAME=raring + DISTRIB_DESCRIPTION="Ubuntu 13.04" + */ + + foreach(string line in read_file(dist_file).split("\n")){ + + if (line.split("=").length != 2){ continue; } + + string key = line.split("=")[0].strip(); + string val = line.split("=")[1].strip(); + + if (val.has_prefix("\"")){ + val = val[1:val.length]; + } + + if (val.has_suffix("\"")){ + val = val[0:val.length-1]; + } + + switch (key){ + case "DISTRIB_ID": + info.dist_id = val; + break; + case "DISTRIB_RELEASE": + info.release = val; + break; + case "DISTRIB_CODENAME": + info.codename = val; + break; + case "DISTRIB_DESCRIPTION": + info.description = val; + break; + } + } + } + else{ + + dist_file = root_path + "/etc/os-release"; + f = File.new_for_path(dist_file); + if (f.query_exists()){ + + /* + NAME="Ubuntu" + VERSION="13.04, Raring Ringtail" + ID=ubuntu + ID_LIKE=debian + PRETTY_NAME="Ubuntu 13.04" + VERSION_ID="13.04" + HOME_URL="http://www.ubuntu.com/" + SUPPORT_URL="http://help.ubuntu.com/" + BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" + */ + + foreach(string line in read_file(dist_file).split("\n")){ + + if (line.split("=").length != 2){ continue; } + + string key = line.split("=")[0].strip(); + string val = line.split("=")[1].strip(); + + switch (key){ + case "ID": + info.dist_id = val; + break; + case "VERSION_ID": + info.release = val; + break; + //case "DISTRIB_CODENAME": + //info.codename = val; + //break; + case "PRETTY_NAME": + info.description = val; + break; + } + } + } + } + + return info; + } + + } + + public static Gdk.RGBA hex_to_rgba (string hex_color){ + + /* Converts the color in hex to RGBA */ + + string hex = hex_color.strip().down(); + if (hex.has_prefix("#") == false){ + hex = "#" + hex; + } + + Gdk.RGBA color = Gdk.RGBA(); + if(color.parse(hex) == false){ + color.parse("#000000"); + } + color.alpha = 255; + + return color; + } + + public static string rgba_to_hex (Gdk.RGBA color, bool alpha = false, bool prefix_hash = true){ + + /* Converts the color in RGBA to hex */ + + string hex = ""; + + if (alpha){ + hex = "%02x%02x%02x%02x".printf((uint)(Math.round(color.red*255)), + (uint)(Math.round(color.green*255)), + (uint)(Math.round(color.blue*255)), + (uint)(Math.round(color.alpha*255))) + .up(); + } + else { + hex = "%02x%02x%02x".printf((uint)(Math.round(color.red*255)), + (uint)(Math.round(color.green*255)), + (uint)(Math.round(color.blue*255))) + .up(); + } + + if (prefix_hash){ + hex = "#" + hex; + } + + return hex; + } + + public string timestamp2 (){ + + /* Returns a numeric timestamp string */ + + return "%ld".printf((long) time_t ()); + } + + public string timestamp (){ + + /* Returns a formatted timestamp string */ + + Time t = Time.local (time_t ()); + return t.format ("%H:%M:%S"); + } + + public string timestamp3 (){ + + /* Returns a formatted timestamp string */ + + Time t = Time.local (time_t ()); + return t.format ("%Y-%d-%m_%H-%M-%S"); + } + + public string format_file_size (int64 size){ + + /* Format file size in MB */ + + return "%0.1f MB".printf (size / (1024.0 * 1024)); + } + + public string format_duration (long millis){ + + /* Converts time in milliseconds to format '00:00:00.0' */ + + double time = millis / 1000.0; // time in seconds + + double hr = Math.floor(time / (60.0 * 60)); + time = time - (hr * 60 * 60); + double min = Math.floor(time / 60.0); + time = time - (min * 60); + double sec = Math.floor(time); + + return "%02.0lf:%02.0lf:%02.0lf".printf (hr, min, sec); + } + + public double parse_time (string time){ + + /* Converts time in format '00:00:00.0' to milliseconds */ + + string[] arr = time.split (":"); + double millis = 0; + if (arr.length >= 3){ + millis += double.parse(arr[0]) * 60 * 60; + millis += double.parse(arr[1]) * 60; + millis += double.parse(arr[2]); + } + return millis; + } + + public string escape_html(string html){ + return html + .replace("&","&") + .replace("\"",""") + //.replace(" "," ") //pango markup throws an error with   + .replace("<","<") + .replace(">",">") + ; + } + + public string unescape_html(string html){ + return html + .replace("&","&") + .replace(""","\"") + //.replace(" "," ") //pango markup throws an error with   + .replace("<","<") + .replace(">",">") + ; + } +} diff -Nru aptik-battery-monitor-2.1/src/DiskIndicator.vala aptik-battery-monitor-17.12/src/DiskIndicator.vala --- aptik-battery-monitor-2.1/src/DiskIndicator.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/DiskIndicator.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,885 @@ + +using GLib; +using Gtk; +using Gee; +using Json; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JsonHelper; +using TeeJee.ProcessHelper; +using TeeJee.GtkHelper; +using TeeJee.System; +using TeeJee.Misc; + +using AppIndicator; + +public class DiskIndicator: GLib.Object{ + + protected Gee.ArrayList device_list; + protected Indicator indicator; + protected string icon; + protected string name; + protected DateTime last_refresh_date = null; + + public DiskIndicator(){ + + App.disk_indicator = this; + + this.name = "Disk Manager"; + this.icon = "disks"; + this.indicator = new Indicator( + "indicator_diskman", icon, IndicatorCategory.APPLICATION_STATUS); + + //indicator.set_status(IndicatorStatus.ACTIVE); + + + indicator.set_status(IndicatorStatus.ACTIVE); + + refresh_tray_icon(); + + refresh_device_list(); + + var menu = new Gtk.Menu(); + + // open ------------------------------------- + + var item = new Gtk.ImageMenuItem.with_label(_("Open")); + menu.append(item); + var item_open = item; + + item.always_show_image = true; + item.set_image(get_shared_icon("inode-directory","locked.png",16)); + item.set_reserve_indicator(false); + + item.activate.connect(()=>{ + var submenu = get_menu("open"); + item_open.set_submenu(submenu); + }); + + item.activate(); + + // eject ------------------------------------- + + /* + item = new Gtk.MenuItem.with_label(_("Eject")); + menu.append(item); + var item_eject = item; + + item.activate.connect(()=>{ + var submenu = get_menu("eject"); + item_eject.set_submenu(submenu); + }); + + item.activate(); + */ + + // mount ------------------------------------- + + var separator = new Gtk.SeparatorMenuItem (); + menu.add (separator); + + item = new Gtk.ImageMenuItem.with_label(_("Mount")); + menu.append(item); + var item_mount = item; + + item.always_show_image = true; + item.set_image(get_shared_icon("","drive-harddisk.svg",16)); + item.set_reserve_indicator(false); + + item.activate.connect(()=>{ + var submenu = get_menu("mount"); + item_mount.set_submenu(submenu); + }); + + item.activate(); + + // unmount ------------------------------------- + + item = new Gtk.ImageMenuItem.with_label(_("Unmount")); + menu.append(item); + var item_unmount = item; + + item.always_show_image = true; + item.set_image(get_shared_icon("media-eject","",16)); + item.set_reserve_indicator(false); + + item.activate.connect(()=>{ + var submenu = get_menu("unmount"); + item_unmount.set_submenu(submenu); + }); + + item.activate(); + + // lock ------------------------------------- + + separator = new Gtk.SeparatorMenuItem (); + menu.add (separator); + + item = new Gtk.ImageMenuItem.with_label(_("Lock")); + menu.append(item); + var item_lock = item; + + item.always_show_image = true; + item.set_image(get_shared_icon("","locked.png",16)); + item.set_reserve_indicator(false); + + item.activate.connect(()=>{ + var submenu = get_menu("lock"); + item_lock.set_submenu(submenu); + }); + + item.activate(); + + // unlock ------------------------------------- + + item = new Gtk.ImageMenuItem.with_label(_("Unlock")); + menu.append(item); + var item_unlock = item; + + item.always_show_image = true; + item.set_image(get_shared_icon("","unlocked.png",16)); + + item.activate.connect(()=>{ + var submenu = get_menu("unlock"); + item_unlock.set_submenu(submenu); + }); + + item.activate(); + + // usage ------------------------------------- + + separator = new Gtk.SeparatorMenuItem (); + menu.add (separator); + + item = new Gtk.ImageMenuItem.with_label(_("Usage")); + menu.append(item); + var item_usage = item; + + item.always_show_image = true; + item.set_image(get_shared_icon("disk-usage-analyzer","disk-usage-analyzer.svg",16)); + + item.activate.connect(()=>{ + var submenu = get_menu("usage"); + item_usage.set_submenu(submenu); + }); + + item.activate(); + + // iso ------------------------------------- + + separator = new Gtk.SeparatorMenuItem (); + menu.add (separator); + + item = new Gtk.ImageMenuItem.with_label(_("ISO")); + menu.append(item); + var item_iso = item; + + item.always_show_image = true; + item.set_image(get_shared_icon("media-optical","media-optical.png",16)); + + item.activate.connect(()=>{ + var submenu = get_menu("iso"); + item_iso.set_submenu(submenu); + }); + + item.activate(); + + // settings ------------------------------------- + + separator = new Gtk.SeparatorMenuItem (); + menu.add (separator); + + item = new Gtk.ImageMenuItem.with_label(_("Settings")); + menu.append(item); + var item_settings = item; + + item.always_show_image = true; + item.set_image(get_shared_icon("preferences-system","settings.png",16)); + + item.activate.connect(()=>{ + var dlg = new SettingsWindow(null); + }); + + //item.activate(); + + // about ------------------------------------- + + separator = new Gtk.SeparatorMenuItem (); + menu.add (separator); + + item = new Gtk.ImageMenuItem.with_label(_("About")); + menu.append(item); + + item.activate.connect(() => { + btn_about_clicked(); + }); + + // donate ------------------------------------- + + item = new Gtk.ImageMenuItem.with_label(_("Donate")); + menu.append(item); + + item.activate.connect(() => { + btn_donate_clicked(); + }); + + // exit ------------------------------------- + + item = new Gtk.ImageMenuItem.with_label(_("Exit")); + menu.append(item); + + item.activate.connect(() => { + App.exit_app(); + exit(0); + }); + + indicator.set_menu(menu); + menu.show_all(); + } + + public void refresh_tray_icon(){ + if (App.use_custom_tray_icon && file_exists(App.custom_tray_icon_path)){ + log_msg("Setting custom tray icon"); + indicator.set_icon_theme_path(file_parent(App.custom_tray_icon_path)); + indicator.set_icon(file_basename(App.custom_tray_icon_path).replace(".png","").replace(".svg","").replace(".jpg","").replace(".jpeg","")); + } + else{ + this.icon = "disks"; + indicator.set_icon_theme_path("/usr/share/%s/images".printf(AppShortName)); + indicator.set_icon("disks"); + } + } + + private void refresh_device_list_if_stale(){ + var period = (new DateTime.now_local()).add_seconds(-10); + if ((device_list == null) || (last_refresh_date == null) || (last_refresh_date.compare(period) < 0)){ + device_list = Device.get_block_devices(true); + last_refresh_date = new DateTime.now_local(); + } + } + + private void refresh_device_list(){ + device_list = Device.get_block_devices(true); + last_refresh_date = new DateTime.now_local(); + } + + private Gtk.Menu get_menu (string action = "") { + + //log_debug("get_menu(\"%s\")".printf(action)); + + refresh_device_list_if_stale(); + + var menu = new Gtk.Menu(); + menu.reserve_toggle_size = false; + + var dummy_window = new Gtk.Window(); + + for(int i=0; i < device_list.size; i++){ + + var dev = device_list[i]; + + if (dev.size_bytes < 10 * KB){ + continue; + } + + switch(action){ + case "open": + bool show = (dev.type == "disk") || (dev.type == "loop") || !dev.is_encrypted_partition() || !dev.has_children(); + if (!show){ + continue; + } + break; + case "eject": + bool show = ((dev.type == "disk") || (dev.type == "loop")) && (dev.removable); + if (!show){ + continue; + } + break; + case "mount": + bool show = (dev.type == "disk") || ((dev.mount_points.size == 0) && (!dev.is_encrypted_partition() || !dev.has_children())); + if (!show){ + continue; + } + break; + case "unmount": + case "usage": + bool show = (dev.type == "disk") + || ((dev.type == "loop") && dev.has_children()) + || (dev.mount_points.size > 0); + if (!show){ + continue; + } + break; + case "lock": + bool show = (dev.type == "disk") || (dev.is_on_encrypted_partition()); + if (!show){ + continue; + } + break; + case "unlock": + bool show = (dev.type == "disk") || (dev.is_encrypted_partition() && !dev.has_children()); + if (!show){ + continue; + } + break; + + case "iso": + continue; + } + + Gtk.Image icon = null; + + //if (action != "usage"){ + if ((dev.type == "crypt") && (dev.pkname.length > 0)){ + icon = get_shared_icon("","unlocked.png",16); + } + else if (dev.fstype.contains("luks")){ + icon = get_shared_icon("","locked.png",16); + } + else if (dev.fstype.contains("iso9660") || (dev.type == "loop")){ + icon = get_shared_icon("media-optical","media-optical.png",16); + } + else{ + icon = get_shared_icon("","drive-harddisk.svg",16); + } + //} + + var name = ""; + + switch(action){ + case "usage": + + if ((dev.type == "disk") || ((dev.type == "loop") && dev.has_children())){ + name += "%s".printf(dev.description_simple()); + break; + } + + name += "%s ~ %s".printf(dev.short_name_with_parent, dev.description_usage()); + + if ((dev.used_bytes > 0) && (dev.size_bytes > 0)){ + double usage_percent = (dev.used_bytes * 10.0) / dev.size_bytes; + int used_count = (int) usage_percent; + int free_count = 10 - used_count; + + name += " "; + for(int j = 0; j < used_count; j++){ + name += "▮"; + } + for(int j = 0; j < free_count; j++){ + name += "▯"; + } + } + else{ + name += " "; + for(int j = 0; j < 10; j++){ + //name += "░";░ ▒ ▓ ⬜ ⬛ ▯ ▮ + } + } + + break; + + default: + name += "%s".printf(dev.description_simple()); + break; + } + + if ((dev.type != "disk") && ((action == "open") || (action == "unmount"))){ + if (dev.mount_points.size > 0){ + name += " ~ " + dev.mount_points[0].mount_point; + } + } + + var item = new Gtk.ImageMenuItem.with_label (name); + item.set_reserve_indicator(false); + menu.append(item); + + if (((dev.type == "loop") && dev.has_parent()) || (dev.type == "crypt") || (dev.type == "part") || (dev.type == "lvm")){ + item.always_show_image = true; + item.set_image(icon); + } + + /*foreach(var child in gtk_container_get_children(item)){ + //log_debug(child.get_type().to_string() + "-" + typeof(Gtk.Label).to_string()); + if (child is Gtk.Label){ + Gtk.Label label = (Gtk.Label) child; + label.set_use_markup(true); + label.set_markup(name); + //log_debug("markup=%s".printf(name)); + break; + } + }*/ + + // set sensitive ---------------------------------------- + + switch(action){ + case "eject": + if ((dev.type == "disk") || ((dev.type == "loop") && (dev.has_children()))){ + item.sensitive = false; + foreach(var child in dev.children){ + if (child.has_children()){ + foreach(var decendant in child.children){ + if (decendant.mount_points.size > 0){ + item.sensitive = true; + break; + } + } + } + else{ + if (child.mount_points.size > 0){ + item.sensitive = true; + break; + } + } + } + } + break; + case "open": + case "usage": + case "mount": + case "unmount": + case "lock": + case "unlock": + if ((dev.type == "disk") || ((dev.type == "loop") && (dev.has_children()))){ + item.sensitive = false; + } + break; + } + + // actions ------------------------------------------ + + switch(action){ + case "eject": + item.activate.connect(() => { + + foreach(var child in dev.children){ + + // unmount if mounted + if (child.mount_points.size > 0){ + bool ok = Device.unmount_udisks(child.device, dummy_window); + if (!ok){ + return; + } + } + + // Note: We only need to unmount. Locking LUKS devices is not required. + // As long as all partitions are unmounted, the device can be safely removed + } + + string title = "%s: %s".printf(_("Unmounted"), dev.device);; + string msg = "%s\n%s".printf(_("Disk can be safely removed"), dev.description_simple()); + OSDNotify.notify_send(title, msg, 2000, "normal", "info"); + + device_list = null; + }); + break; + + case "open": + item.activate.connect(() => { + + if (dev.fstype == "swap"){ + string title = _("Swap Device!"); + string message = _("Swap devices cannot be opened in file manager"); + gtk_messagebox(title, message, null, true); + return; + } + + // unlock + if (dev.is_encrypted_partition()){ + var dev_unlocked = luks_unlock(dev); + if (dev_unlocked == null){ + return; + } + else{ + dev = dev_unlocked; + } + } + + // mount if unmounted + if (dev.mount_points.size == 0){ + bool ok = Device.automount_udisks(dev.device, dummy_window); + if (!ok){ + return; + } + else{ + dev = dev.query_changes(); + } + } + + // browse + if (dev.mount_points.size > 0){ + var mp = dev.mount_points[0]; + exo_open_folder(mp.mount_point); + } + + device_list = null; + }); + break; + + case "mount": + item.activate.connect(() => { + + // mount if unmounted + if (dev.mount_points.size == 0){ + bool ok = Device.automount_udisks(dev.device, dummy_window); + if (!ok){ + return; + } + else{ + dev = dev.query_changes(); + if (dev.mount_points.size > 0){ + string title = "%s: %s".printf(_("Mounted"), dev.device); + string msg = "%s".printf(dev.mount_points[0].mount_point); + OSDNotify.notify_send(title, msg, 2000, "normal", "info"); + } + } + } + else{ + string title = "%s: %s".printf(_("Is Mounted"), dev.device); + string msg = "%s".printf(dev.mount_points[0].mount_point); + OSDNotify.notify_send(title, msg, 2000, "normal", "info"); + } + + device_list = null; + }); + break; + + case "unmount": + item.activate.connect(() => { + + bool is_system = false; + foreach (var mnt in dev.mount_points){ + switch (mnt.mount_point){ + case "/": + case "/boot": + case "/boot/efi": + case "/home": + is_system = true; + break; + default: + if (dev.fstype == "swap"){ + is_system = true; + } + break; + } + } + + if (is_system){ + string title = _("System Device!"); + string message = _("System devices cannot be unmounted"); + gtk_messagebox(title, message, null, true); + return; + } + + // unmount if mounted + if (dev.mount_points.size > 0){ + bool ok = Device.unmount_udisks(dev.device, dummy_window); + if (!ok){ + return; + } + else{ + string title = "%s %s".printf(_("Unmounted"), dev.device); + string msg = ""; + OSDNotify.notify_send(title, msg, 2000, "normal", "info"); + } + } + else{ + string title = "%s: %s".printf(_("Not mounted"), dev.device); + string msg = ""; + OSDNotify.notify_send(title, msg, 2000, "normal", "info"); + } + + device_list = null; + }); + break; + + case "lock": + item.activate.connect(() => { + + bool is_system = false; + foreach (var mnt in dev.mount_points){ + switch (mnt.mount_point){ + case "/": + case "/boot": + case "/boot/efi": + case "/home": + is_system = true; + break; + default: + if (dev.fstype == "swap"){ + is_system = true; + } + break; + } + } + + if (is_system){ + string title = _("System Device!"); + string message = _("System devices cannot be unmounted"); + gtk_messagebox(title, message, null, true); + return; + } + + // unmount if mounted + if (dev.mount_points.size > 0){ + bool ok = Device.unmount_udisks(dev.device, dummy_window); + if (!ok){ + return; + } + else{ + dev = dev.query_changes(); + } + } + + // lock if unlocked + if (dev.is_on_encrypted_partition()){ + + bool ok = luks_lock(dev); + + if (ok){ + string title = "%s %s".printf(_("Locked"), dev.device); + string msg = ""; + OSDNotify.notify_send(title, msg, 2000, "normal", "info"); + } + else{ + string title = _("Failed to lock"); + string message = App.daemon.error_message; + gtk_messagebox(title, message, null, true); + } + } + + device_list = null; + }); + break; + + case "unlock": + item.activate.connect(() => { + + // unlock + if (dev.is_encrypted_partition()){ + + var dev_unlocked = luks_unlock(dev); + + if (dev_unlocked != null){ + string title = "%s %s".printf(_("Unlocked"), dev.device); + string msg = "/dev/mapper/%s".printf(dev_unlocked.mapped_name); + OSDNotify.notify_send(title, msg, 2000, "normal", "info"); + } + else{ + string title = _("Failed to unlock"); + string message = App.daemon.error_message; + gtk_messagebox(title, message, null, true); + } + } + + device_list = null; + + }); + break; + + case "usage": + + item.activate.connect(() => { + open_baobab(dev); + }); + + break; + } + } + + // mount iso ------------------------------------- + + if (action == "iso"){ + + var item = new Gtk.ImageMenuItem.with_label (_("Mount ISO...")); + item.set_reserve_indicator(false); + menu.append(item); + + item.always_show_image = true; + var icon = get_shared_icon("media-optical","media-optical.png",16); + item.set_image(icon); + + item.activate.connect(() => { + + var filters = new Gee.ArrayList(); + var filter = create_file_filter("All Files", { "*" }); + filters.add(filter); + filter = create_file_filter("ISO Image File (*.iso)", { "*.iso" }); + filters.add(filter); + var default_filter = filter; + + var selected_files = gtk_select_files(dummy_window, true, false, filters, default_filter); + string iso_file = (selected_files.size > 0) ? selected_files[0] : ""; + if ((iso_file.length == 0) || !file_exists(iso_file)){ + return; + } + + var loop_dev = Device.automount_udisks_iso(iso_file, dummy_window); + + if (loop_dev != null){ + + // notify + string title = "%s".printf(_("Mounted ISO File")); + string msg = "%s".printf(loop_dev.device); + OSDNotify.notify_send(title, msg, 2000, "normal", "info"); + + if (loop_dev.has_children()){ + // get first iso9660 partition + var list = Device.get_block_devices_using_lsblk(); + foreach(var dev in list){ + if ((dev.pkname == loop_dev.device.replace("/dev/","")) && (dev.fstype == "iso9660")){ + loop_dev = dev; + break; + } + } + } + + // browse + if (loop_dev != null){ + var mps = Device.get_device_mount_points(loop_dev.device); + if (mps.size > 0){ + var mp = mps[0]; + exo_open_folder(mp.mount_point); + } + } + } + }); + } + + menu.show_all(); + + return menu; + } + + private Device? luks_unlock(Device dev_locked){ + + var dev = dev_locked; + + if (!dev.is_encrypted_partition()){ + log_error("luks_unlock: is_encrypted_partition(): false"); + return null; + } + + var dummy_window = new Gtk.Window(); + + App.init_daemon(); + + while (!App.daemon.is_ready){ + sleep(100); + } + + log_debug("Prompting user for passphrase.."); + + var password = gtk_inputbox( + _("Encrypted Device"), + _("Enter passphrase to unlock '%s'").printf(dev.device), + dummy_window, true); + + if (password == null){ + log_debug("User cancelled the password prompt"); + return null; + } + + string cmd = "luks_unlock|%s|%s".printf(dev.device, password); + App.daemon.send_command(cmd); + + Device dev_unlocked = null; + dev = dev.query_changes(); + if (dev.has_children()){ + dev_unlocked = dev.children[0]; + } + + return dev_unlocked; + } + + private bool luks_lock(Device dev_unlocked){ + + Device dev_luks = null; + if (dev_unlocked.is_on_encrypted_partition()){ + dev_luks = dev_unlocked; + } + else if (dev_unlocked.is_encrypted_partition() && (dev_unlocked.has_children())){ + dev_luks = dev_unlocked.children[0]; + } + + App.init_daemon(); + + while (!App.daemon.is_ready){ + sleep(100); + } + + string cmd = "luks_lock|%s".printf(dev_luks.device); + int status = App.daemon.send_command(cmd); + return (status == 0); + } + + private void open_baobab(Device dev){ + + if ((dev.used_bytes > 0) && (dev.mount_points.size > 0)){ + string cmd = "baobab '%s'\n".printf(dev.mount_points[0].mount_point); + string std_out, std_err; + exec_script_sync(cmd, out std_out, out std_err, false, true); + } + + /*if ((dev.used_bytes > 0) && (dev.mount_points.size > 0)){ + + App.init_daemon(); + + while (!App.daemon.is_ready){ + sleep(100); + } + + string cmd = "open_baobab|%s".printf(dev.mount_points[0].mount_point); + App.daemon.send_command(cmd); + }*/ + } + + public void btn_donate_clicked(){ + var dialog = new DonationWindow(); + //dialog.set_transient_for(this); + dialog.show_all(); + dialog.run(); + dialog.destroy(); + } + + private void btn_about_clicked (){ + + var dialog = new AboutWindow(); + //dialog.set_transient_for(this); + + dialog.authors = { + "Tony George:teejeetech@gmail.com" + }; + + dialog.translators = { + + }; + + dialog.contributors = { + + }; + + dialog.third_party = { + + }; + + dialog.documenters = null; + dialog.artists = null; + dialog.donations = null; + + dialog.program_name = AppName; + dialog.comments = _("Disk Indicator for Linux"); + dialog.copyright = "Copyright © 2016 Tony George (%s)".printf(AppAuthorEmail); + dialog.version = AppVersion; + dialog.logo = get_shared_icon_pixbuf("disks","disks.png", 128); + + dialog.license = "This program is free for personal and commercial use and comes with absolutely no warranty. You use this program entirely at your own risk. The author will not be liable for any damages arising from the use of this program."; + dialog.website = "http://teejeetech.in"; + dialog.website_label = "http://teejeetech.blogspot.in"; + + dialog.initialize(); + dialog.show_all(); + } + +} + diff -Nru aptik-battery-monitor-2.1/src/DonationWindow.vala aptik-battery-monitor-17.12/src/DonationWindow.vala --- aptik-battery-monitor-2.1/src/DonationWindow.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/DonationWindow.vala 1970-01-01 00:00:00.000000000 +0000 @@ -1,101 +0,0 @@ -/* - * DonationWindow.vala - * - * Copyright 2012 Tony George - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -using Gtk; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JSON; -using TeeJee.ProcessManagement; -using TeeJee.GtkHelper; -using TeeJee.System; -using TeeJee.Misc; - -public class DonationWindow : Dialog { - public DonationWindow() { - set_title(_("Donate")); - window_position = WindowPosition.CENTER_ON_PARENT; - set_destroy_with_parent (true); - set_modal (true); - set_deletable(true); - set_skip_taskbar_hint(false); - set_default_size (400, 20); - icon = get_app_icon(16); - - //vbox_main - Box vbox_main = get_content_area(); - vbox_main.margin = 6; - vbox_main.homogeneous = false; - - get_action_area().visible = false; - - //lbl_message - Label lbl_message = new Gtk.Label(""); - string msg = _("Did you find this software useful?\n\nYou can buy me a coffee or make a donation via PayPal to show your support. Or just drop me an email and say Hi. This application is completely free and will continue to remain that way. Your contributions will help in keeping this project alive and improving it further.\n\nFeel free to send me an email if you find any issues in this application or if you need any changes. Suggestions and feedback are always welcome.\n\nThanks,\nTony George\n(teejeetech@gmail.com)"); - lbl_message.label = msg; - lbl_message.wrap = true; - vbox_main.pack_start(lbl_message,true,true,0); - - //vbox_actions - Box vbox_actions = new Box (Orientation.VERTICAL, 6); - vbox_actions.margin_left = 50; - vbox_actions.margin_right = 50; - vbox_actions.margin_top = 20; - vbox_main.pack_start(vbox_actions,false,false,0); - - //btn_donate_paypal - Button btn_donate_paypal = new Button.with_label(" " + _("Donate with PayPal") + " "); - vbox_actions.add(btn_donate_paypal); - btn_donate_paypal.clicked.connect(()=>{ - xdg_open("https://www.paypal.com/cgi-bin/webscr?business=teejeetech@gmail.com&cmd=_xclick¤cy_code=USD&amount=10&item_name=AptikBatteryMonitor%20Donation"); - }); - - //btn_donate_wallet - Button btn_donate_wallet = new Button.with_label(" " + _("Donate with Google Wallet") + " "); - vbox_actions.add(btn_donate_wallet); - btn_donate_wallet.clicked.connect(()=>{ - xdg_open("https://support.google.com/mail/answer/3141103?hl=en"); - }); - - //btn_send_email - Button btn_send_email = new Button.with_label(" " + _("Send Email") + " "); - vbox_actions.add(btn_send_email); - btn_send_email.clicked.connect(()=>{ - xdg_open("mailto:teejeetech@gmail.com"); - }); - - //btn_visit - Button btn_visit = new Button.with_label(" " + _("Visit Website") + " "); - vbox_actions.add(btn_visit); - btn_visit.clicked.connect(()=>{ - xdg_open("http://www.teejeetech.in"); - }); - - //btn_exit - Button btn_exit = new Button.with_label(" " + _("OK") + " "); - vbox_actions.add(btn_exit); - btn_exit.clicked.connect(() => { - this.destroy(); - }); - } -} diff -Nru aptik-battery-monitor-2.1/src/Gtk/AboutWindow.vala aptik-battery-monitor-17.12/src/Gtk/AboutWindow.vala --- aptik-battery-monitor-2.1/src/Gtk/AboutWindow.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Gtk/AboutWindow.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,400 @@ +/* + * AboutWindow.vala + * + * Copyright 2012-2017 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +using Gtk; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.System; +using TeeJee.Misc; + +public class AboutWindow : Dialog { + private Box vbox_main; + private Box vbox_logo; + private Box vbox_credits; + private Box vbox_lines; + private Box hbox_action; + private Button btn_credits; + private Button btn_close; + + private Gtk.Image img_logo; + private Label lbl_program_name; + private Label lbl_version; + private Label lbl_comments; + private LinkButton lbtn_website; + private Label lbl_copyright; + + private string[] _artists; + public string[] artists{ + get{ + return _artists; + } + set{ + _artists = value; + } + } + + private string[] _authors; + public string[] authors{ + get{ + return _authors; + } + set{ + _authors = value; + } + } + + private string _comments = ""; + public string comments{ + get{ + return _comments; + } + set{ + _comments = value; + } + } + + private string _copyright = ""; + public string copyright{ + get{ + return _copyright; + } + set{ + _copyright = value; + } + } + + private string[] _documenters; + public string[] documenters{ + get{ + return _documenters; + } + set{ + _documenters = value; + } + } + + private string[] _donations; + public string[] donations{ + get{ + return _donations; + } + set{ + _donations = value; + } + } + + private string _license = ""; + public string license{ + get{ + return _license; + } + set{ + _license = value; + } + } + + private Gdk.Pixbuf _logo; + public Gdk.Pixbuf logo{ + get{ + return _logo; + } + set{ + _logo = value; + } + } + + private string _program_name = ""; + public string program_name{ + get{ + return _program_name; + } + set{ + _program_name = value; + } + } + + private string[] _translators; + public string[] translators{ + get{ + return _translators; + } + set{ + _translators = value; + } + } + + private string[] _third_party; + public string[] third_party{ + get{ + return _third_party; + } + set{ + _third_party = value; + } + } + + private string _version = ""; + public string version{ + get{ + return _version; + } + set{ + _version = value; + } + } + + private string _website = ""; + public string website{ + get{ + return _website; + } + set{ + _website = value; + } + } + + private string _website_label = ""; + public string website_label{ + get{ + return _website_label; + } + set{ + _website_label = value; + } + } + + public AboutWindow() { + window_position = WindowPosition.CENTER_ON_PARENT; + set_destroy_with_parent (true); + set_modal (true); + skip_taskbar_hint = false; + set_default_size (450, 400); + + vbox_main = get_content_area(); + vbox_main.margin = 6; + vbox_main.spacing = 6; + + vbox_logo = new Box(Orientation.VERTICAL,0); + vbox_main.add(vbox_logo); + + vbox_credits = new Box(Orientation.VERTICAL,0); + vbox_credits.no_show_all = true; + vbox_main.add(vbox_credits); + + vbox_lines = new Box(Orientation.VERTICAL,0); + vbox_lines.margin_top = 10; + + //logo + img_logo = new Gtk.Image(); + img_logo.margin_top = 6; + img_logo.margin_bottom = 6; + vbox_logo.add(img_logo); + + //program_name + lbl_program_name = new Label(""); + lbl_program_name.set_use_markup(true); + vbox_logo.add(lbl_program_name); + + //version + lbl_version = new Label(""); + lbl_version.set_use_markup(true); + lbl_version.margin_top = 5; + vbox_logo.add(lbl_version); + + //comments + lbl_comments = new Label(""); + lbl_comments.set_use_markup(true); + lbl_comments.margin_top = 10; + vbox_logo.add(lbl_comments); + + //website + lbtn_website = new LinkButton(""); + lbtn_website.margin_top = 5; + vbox_logo.add(lbtn_website); + + lbtn_website.activate_link.connect(()=>{ + try{ + return Gtk.show_uri(null, lbtn_website.uri, Gdk.CURRENT_TIME); + } + catch(Error e){ + return false; + } + }); + + //copyright + lbl_copyright = new Label(""); + lbl_copyright.set_use_markup(true); + lbl_copyright.margin_top = 5; + vbox_logo.add(lbl_copyright); + + //spacer_bottom + var spacer_bottom = new Label(""); + spacer_bottom.margin_top = 20; + vbox_logo.add(spacer_bottom); + + //scroller + var sw_credits = new ScrolledWindow(null, null); + sw_credits.set_shadow_type(ShadowType.ETCHED_IN); + sw_credits.expand = true; + + vbox_credits.add(sw_credits); + sw_credits.add(vbox_lines); + + //hbox_commands -------------------------------------------------- + + hbox_action = (Box) get_action_area(); + + //btn_credits + btn_credits = new Button.with_label(" " + _("Credits")); + btn_credits.set_image (new Image.from_stock ("gtk-about", IconSize.MENU)); + hbox_action.add(btn_credits); + + btn_credits.clicked.connect(()=>{ + vbox_logo.visible = !(vbox_logo.visible); + vbox_credits.visible = !(vbox_credits.visible); + + if ((vbox_credits.visible)&&(!sw_credits.visible)){ + sw_credits.show_all(); + } + + if (vbox_credits.visible){ + btn_credits.label = " " + _("Back"); + btn_credits.set_image (new Image.from_stock ("gtk-go-back", IconSize.MENU)); + } + else{ + btn_credits.label = " " + _("Credits"); + btn_credits.set_image (new Image.from_stock ("gtk-about", IconSize.MENU)); + } + }); + + //btn_close + btn_close = new Button.with_label(" " + _("Close")); + btn_close.set_image (new Image.from_stock ("gtk-close", IconSize.MENU)); + hbox_action.add(btn_close); + + btn_close.clicked.connect(()=>{ this.destroy(); }); + } + + public void initialize() { + title = program_name; + img_logo.pixbuf = logo; + lbl_program_name.label = "%s".printf(program_name); + lbl_version.label = "v%s".printf(version); + lbl_comments.label = "%s".printf(comments); + lbtn_website.uri = website; + lbtn_website.label = website_label; + //lbl_copyright.label = "%s".printf(copyright); + lbl_copyright.label = "%s".printf(copyright); + + if (authors.length > 0){ + add_line("%s\n".printf(_("Authors"))); + foreach(string name in authors){ + add_line("%s\n".printf(name)); + } + add_line("\n"); + } + + if (third_party.length > 0){ + add_line("%s\n".printf(_("Third Party Tools"))); + foreach(string name in third_party){ + add_line("%s\n".printf(name)); + } + add_line("\n"); + } + + if (artists.length > 0){ + add_line("%s\n".printf(_("Artists"))); + foreach(string name in artists){ + add_line("%s\n".printf(name)); + } + add_line("\n"); + } + + if (translators.length > 0){ + add_line("%s\n".printf(_("Translators"))); + foreach(string name in translators){ + add_line("%s\n".printf(name)); + } + add_line("\n"); + } + + if (documenters.length > 0){ + add_line("%s\n".printf(_("Documenters"))); + foreach(string name in documenters){ + add_line("%s\n".printf(name)); + } + add_line("\n"); + } + + if (donations.length > 0){ + add_line("%s\n".printf(_("Donations"))); + foreach(string name in donations){ + add_line("%s\n".printf(name)); + } + add_line("\n"); + } + + if (vbox_lines.get_children().length() == 0){ + btn_credits.visible = false; + } + } + + public void add_line(string text){ + if (text.split(":").length >= 2){ + var link = new LinkButton(text.split(":")[0]); + vbox_lines.add(link); + + string val = text[text.index_of(":") + 1:text.length]; + if (val.contains("@")){ + link.uri = "mailto:" + val; + } + else if(val.has_prefix("http://")){ + link.uri = val; + } + else{ + link.uri = "http://" + val; + } + + link.activate_link.connect(()=>{ + try{ + return Gtk.show_uri(null, link.uri, Gdk.CURRENT_TIME); + } + catch(Error e){ + return false; + } + }); + } + else{ + var lbl = new Label(text); + lbl.set_use_markup(true); + lbl.valign = Align.START; + lbl.wrap = true; + lbl.wrap_mode = Pango.WrapMode.WORD; + vbox_lines.add(lbl); + } + } +} diff -Nru aptik-battery-monitor-2.1/src/Gtk/AptikBatteryStatsGtk.vala aptik-battery-monitor-17.12/src/Gtk/AptikBatteryStatsGtk.vala --- aptik-battery-monitor-2.1/src/Gtk/AptikBatteryStatsGtk.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Gtk/AptikBatteryStatsGtk.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,105 @@ +/* + * AptikBatteryStatsGtk.vala + * + * Copyright 2012-2017 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +using GLib; +using Gtk; +using Gee; +using Json; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.Multimedia; +using TeeJee.System; +using TeeJee.Misc; + +public class AptikBatteryStatsGtk : GLib.Object{ + + public static int main (string[] args) { + set_locale(); + + Gtk.init(ref args); + + App = new Main(args, true); + parse_arguments(args); + + var window = new BatteryStatsWindow (); + window.destroy.connect(Gtk.main_quit); + window.show_all(); + + //start event loop + Gtk.main(); + + App.exit_app(); + + return 0; + } + + private static void set_locale(){ + Intl.setlocale(GLib.LocaleCategory.MESSAGES, AppShortName); + Intl.textdomain(GETTEXT_PACKAGE); + Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "utf-8"); + Intl.bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); + } + + public static bool parse_arguments(string[] args){ + //parse options + for (int k = 1; k < args.length; k++) // Oth arg is app path + { + switch (args[k].down()){ + case "--debug": + LOG_DEBUG = true; + break; + case "--help": + case "--h": + case "-h": + log_msg(help_message()); + exit(0); + return true; + default: + //unknown option - show help and exit + log_error(_("Unknown option") + ": %s".printf(args[k])); + log_msg(help_message()); + exit(1); + return false; + } + } + + return true; + } + + public static string help_message(){ + string msg = "\n" + AppName + " v" + AppVersion + " by Tony George (teejee2008@gmail.com)" + "\n"; + msg += "\n"; + msg += _("Syntax") + ": %s [options]\n".printf(AppShortName); + msg += "\n"; + msg += _("Options") + ":\n"; + msg += "\n"; + msg += " --debug " + _("Print debug information") + "\n"; + msg += " --h[elp] " + _("Show all options") + "\n"; + msg += "\n"; + return msg; + } +} diff -Nru aptik-battery-monitor-2.1/src/Gtk/BatteryStatsWindow.vala aptik-battery-monitor-17.12/src/Gtk/BatteryStatsWindow.vala --- aptik-battery-monitor-2.1/src/Gtk/BatteryStatsWindow.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Gtk/BatteryStatsWindow.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,772 @@ +/* + * BatteryStatsWindow.vala + * + * Copyright 2012-2017 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + + +using Gtk; +using Gee; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.Multimedia; +using TeeJee.System; +using TeeJee.Misc; + +public class BatteryStatsWindow : Window { + + private Box vbox_main; + + private Gtk.DrawingArea drawing_area; + + private Label lbl_stats_line_batt; + private Label lbl_stats_line_used; + + private Label lbl_percent; + private Label lbl_percent_val; + private Label lbl_remaining; + private Label lbl_remaining_val; + private Label lbl_avg_life; + private Label lbl_avg_life_val; + private Label lbl_time_to_charge; + private Label lbl_time_to_charge_val; + private Label lbl_rate; + private Label lbl_rate_val; + private Label lbl_health; + private Label lbl_health_val; + + private Gtk.Image img_battery_status; + + BatteryStat stat_current; + int X_INTERVAL = 5; + int X_OFFSET = 30; + int Y_OFFSET = 20; + + uint timer_refresh = 0; + + int def_width = 500; + int def_height = 500; + + private Gdk.RGBA color_white; + private Gdk.RGBA color_black; + private Gdk.RGBA color_red; + private Gdk.RGBA color_blue; + private Gdk.RGBA color_red_100; + + public BatteryStatsWindow() { + destroy.connect(Gtk.main_quit); + init_window(); + } + + public BatteryStatsWindow.with_parent(Window parent) { + set_transient_for(parent); + set_modal(true); + init_window(); + init_window_for_parent(); + } + + public void init_window () { + define_colors(); + + title = "Aptik Battery Monitor" + " v" + AppVersion; + window_position = WindowPosition.CENTER; + resizable = true; + set_default_size (def_width, def_height); + + //vbox_main + vbox_main = new Box (Orientation.VERTICAL, 6); + vbox_main.margin = 6; + add (vbox_main); + + init_header(); + + init_graph(); + + init_stats(); + + //TODO: Should start if not already running + + show_all(); + + timer_refresh_graph(); + + timer_refresh = Timeout.add(30 * 1000, timer_refresh_graph); + } + + public void define_colors(){ + + color_white = Gdk.RGBA(); + color_white.parse("white"); + color_white.alpha = 1.0; + + color_black = Gdk.RGBA(); + color_black.parse("black"); + color_black.alpha = 1.0; + + color_red = Gdk.RGBA(); + color_red.parse("red"); + color_red.alpha = 1.0; + + color_blue = Gdk.RGBA(); + color_blue.parse("blue"); + color_blue.alpha = 1.0; + + color_red_100 = Gdk.RGBA(); + color_red_100.parse("#FFCDD2"); + color_red_100.alpha = 1.0; + } + + public void init_window_for_parent() { + //btn_actions.hide(); + //btn_selections.hide(); + } + + public void init_header() { + + Gtk.Frame frame_top = new Gtk.Frame (""); + //(frame_stats_line.label_widget as Gtk.Label).use_markup = true; + vbox_main.add (frame_top); + + var grid_top = new Grid(); + grid_top.set_column_spacing (6); + grid_top.set_row_spacing (6); + grid_top.margin_left = 12; + grid_top.margin_right = 6; + grid_top.margin_bottom = 6; + frame_top.add(grid_top); + + lbl_stats_line_batt = new Label(""); + lbl_stats_line_batt.xalign = (float) 0.0; + grid_top.attach(lbl_stats_line_batt, 0, 0, 1, 1); + + lbl_stats_line_used = new Label(""); + lbl_stats_line_used.xalign = (float) 0.0; + grid_top.attach(lbl_stats_line_used, 0, 1, 1, 1); + + var lbl_spacer = new Label(""); + lbl_spacer.hexpand = true; + grid_top.attach(lbl_spacer, 1, 0, 1, 1); + + /* //btn_settings + var btn_settings = new Gtk.Button.from_stock ("gtk-missing-image"); + btn_settings.label = _("Settings"); + //btn_settings.label = ""; + btn_settings.set_tooltip_text (_("Settings")); + //btn_settings.image = get_shared_icon("gnome-settings","config.svg",16); + //btn_settings.always_show_image = true; + //btn_settings.image_position = PositionType.RIGHT; + //hbox_top_line1.add(btn_settings); + + btn_settings.clicked.connect(() => { + var dialog = new SettingsWindow(); + dialog.set_transient_for(this); + dialog.show_all(); + dialog.run(); + dialog.destroy(); + });*/ + + //btn_donate + var btn_donate = new Gtk.Button.from_stock ("gtk-missing-image"); + btn_donate.label = _("Donate"); + btn_donate.label = ""; + btn_donate.set_tooltip_text (_("Donate")); + btn_donate.image = get_shared_icon("donate","donate.svg",24); + btn_donate.always_show_image = true; + btn_donate.image_position = PositionType.RIGHT; + grid_top.attach(btn_donate, 2, 0, 1, 2); + + btn_donate.clicked.connect(() => { + var dialog = new DonationWindow(); + dialog.set_transient_for(this); + dialog.show_all(); + dialog.run(); + dialog.destroy(); + }); + + //btn_about + var btn_about = new Gtk.Button.from_stock ("gtk-about"); + btn_about.label = _("Info"); + btn_about.label = ""; + btn_about.set_tooltip_text (_("Application Info")); + btn_about.image = get_shared_icon("gtk-about","help-info.svg",24); + btn_about.always_show_image = true; + btn_about.image_position = PositionType.RIGHT; + grid_top.attach(btn_about, 3, 0, 1, 2); + + btn_about.clicked.connect (btn_about_clicked); + } + + private void btn_about_clicked () { + + var dialog = new AboutWindow(); + dialog.set_transient_for (this); + + dialog.authors = { + "Tony George:teejeetech@gmail.com" + }; + + dialog.translators = { + //"giulux (Italian)", + //"Jorge Jamhour (Brazilian Portuguese):https://launchpad.net/~jorge-jamhour", + //"B. W. Knight (Korean):https://launchpad.net/~kbd0651", + //"Rodion R. (Russian):https://launchpad.net/~r0di0n" + }; + + dialog.documenters = null; + dialog.artists = null; + dialog.donations = null; + + dialog.program_name = AppName; + dialog.comments = _(" A Battery Monitoring Utility for Laptops"); + dialog.copyright = "Copyright © 2012-2018 Tony George (%s)".printf(AppAuthorEmail); + dialog.version = AppVersion; + dialog.logo = get_app_icon(128); + + dialog.license = "This program is free for personal and commercial use and comes with absolutely no warranty. You use this program entirely at your own risk. The author will not be liable for any damages arising from the use of this program."; + dialog.website = "http://teejeetech.in"; + dialog.website_label = "http://teejeetech.blogspot.in"; + + dialog.initialize(); + dialog.show_all(); + } + + public void init_graph() { + + drawing_area = new Gtk.DrawingArea(); + drawing_area.set_size_request(400, 200); + drawing_area.margin = 10; + + var sw_graph = new ScrolledWindow(null, null); + sw_graph.set_shadow_type (ShadowType.ETCHED_IN); + sw_graph.expand = true; + + sw_graph.add (drawing_area); + vbox_main.add(sw_graph); + + drawing_area.add_events(Gdk.EventMask.BUTTON_PRESS_MASK); + + /*drawing_area.button_press_event.connect((event) => { + redraw_graph_area(); + return true; + });*/ + + //this.add_events(Gdk.EventMask.POINTER_MOTION_MASK); + drawing_area.add_events(Gdk.EventMask.POINTER_MOTION_MASK); + + drawing_area.motion_notify_event.connect((event)=>{ + string msg = ""; + BatteryStat stat_last = null; + foreach(var stat in App.battery_stats_list) { + if (stat.date == null) { + continue; + } + + if (Math.fabsf((float)(stat.graph_x - event.x)) < X_INTERVAL) { + msg += _("Date") + ": %s\n".printf(stat.date.format("%d %b %Y, %I:%M %p")); + msg += _("Battery") + ": %0.2f %%, %0.0f mAh, %0.2f Wh, %0.2f V\n".printf( + stat.charge_percent(), + stat.charge_in_mah(), + stat.charge_in_wh(), + stat.voltage() + ); + msg += _("CPU") + ": %0.2f %%".printf(stat.cpu_percent()); + break; + } + + stat_last = stat; + } + + drawing_area.set_tooltip_text(msg); + + return true; + }); + + drawing_area.draw.connect ((context) => { + //weak Gtk.StyleContext style_context = drawing_area.get_style_context (); + //var color_default = style_context.get_color (0); + + var color_default = color_black; + + Gdk.cairo_set_source_rgba (context, color_default); + context.set_line_width (1); + + int stat_count = (App.battery_stats_list.size > 2880) ? 2880 : App.battery_stats_list.size; + + //int w = drawing_area.get_allocated_width(); + int h = drawing_area.get_allocated_height(); + + //int w_eff = w - X_OFFSET; + int h_eff = h - 2 * Y_OFFSET - 10; + + //double pxw = (w_eff / 100.00); + double pxh = (h_eff / 100.00); + + long x0 = X_OFFSET; + long y0 = h - Y_OFFSET - 10; + long x100 = x0 + (stat_count * X_INTERVAL); + long y100 = Y_OFFSET; + + long x, x_prev, y, y_prev, y_cpu, y_prev_cpu; + x = x_prev = x0; + y = y_prev = y_cpu = y_prev_cpu = y0; + + int count = 0; + BatteryStat stat_prev = null; + int count_24_hours = 2880; + + int x_interval_counter = 0; + foreach(var stat in App.battery_stats_list) { + if (stat.date == null) { + continue; + } + count++; + + if (App.battery_stats_list.size > count_24_hours) { + if (count < (App.battery_stats_list.size - 2880)) { + //ignore entries older than latest 2880 records + continue; + } + } + + x += X_INTERVAL; + stat.graph_x = x; + + if (stat_prev != null) { + if (stat_prev.date.add_seconds(Main.BATT_STATS_LOG_INTERVAL + 1).compare(stat.date) < 0) { + + //draw double-vertical lines to indicate time gap + + //------ BEGIN CONTEXT ------------------------------------------- + context.set_line_width (0.5); + Gdk.cairo_set_source_rgba (context, color_default); + + //draw a vertical line + context.move_to(x_prev, y0); + context.line_to(x_prev, y100); + + //draw a vertical line + context.move_to(x, y0); + context.line_to(x, y100); + + context.stroke (); + //------ END CONTEXT ----------------------------------------- + } + else { + //------ BEGIN CONTEXT ------------------------------------------- + context.set_line_width (0.5); + Gdk.cairo_set_source_rgba (context, color_default); + + for (int p = 10; p <= 100; p += 10) { + long y_interval = (long) (h - Y_OFFSET - 10 - (p * pxh)); + //draw Y-axis lines + context.move_to(x_prev, y_interval); + context.line_to(x, y_interval); + } + + context.stroke (); + //------ END CONTEXT --------------------------------------------- + + //------ BEGIN CONTEXT ------------------------------------------- + context.set_line_width (1); + Gdk.cairo_set_source_rgba (context, color_default); + + //draw battery line for stat --------------------------- + + context.move_to (x_prev, y_prev); + + y = (long) ((stat.charge_now * 100.00 * pxh) / BatteryStat.batt_charge_full()); + y = h - Y_OFFSET - 10 - y; + + context.line_to (x, y); + + context.stroke (); + //------ END CONTEXT --------------------------------------------- + + //------ BEGIN CONTEXT ------------------------------------------- + context.set_line_width (1); + Gdk.cairo_set_source_rgba (context, color_red); + + //draw cpu line for stat ---------------- + + context.move_to (x_prev, y_prev_cpu); + + y_cpu = (long) (stat.cpu_percent() * pxh); + y_cpu = h - Y_OFFSET - 10 - y_cpu; + context.line_to (x, y_cpu); + + y_prev_cpu = y_cpu; + + context.stroke (); + //------ END CONTEXT --------------------------------------------- + } + } + + if ((stat_current != null) && (stat_current.date == stat.date)) { + //------ BEGIN CONTEXT ------------------------------------------- + context.set_line_width (0.5); + Gdk.cairo_set_source_rgba (context, color_blue); + //draw a vertical line for selected stat + context.move_to(x, y0); + context.line_to(x, y100); + context.stroke (); + //------ END CONTEXT --------------------------------------------- + } + + //------ BEGIN CONTEXT ------------------------------------------------- + context.set_line_width (1); + Gdk.cairo_set_source_rgba (context, color_default); + + //draw X-axis ticks and time label for stat ----------------- + + x_interval_counter++; + + if (((stat.date.get_minute() % 10) == 0) && (stat.date.get_second() < 30)) { + //draw X-axis tick + context.move_to(x, y0 - 2); + context.line_to(x, y0 + 2); + + if (x_interval_counter >= 20){ + //draw time on X-axis tick + context.move_to (x - 15, h - Y_OFFSET - 10 + 20); + context.show_text(stat.date.format("%I:%M %p")); + } + + x_interval_counter = 0; + } + + context.stroke (); + //------ END CONTEXT --------------------------------------------------- + + stat_prev = stat; + if (stat_current == null) { + stat_current = stat; + } + x_prev = x; + y_prev = y; + } + + //------ BEGIN CONTEXT ------------------------------------------------- + + context.set_line_width (1); + Gdk.cairo_set_source_rgba (context, color_default); + + //draw axis lines ----------------------------- + + //draw X-axis line + context.move_to(x0, y0); + context.line_to(x100, y0); + + //draw Y-axis line + context.move_to(x0, y0); + context.line_to(x0, y100); + + context.stroke (); + + //------ END CONTEXT --------------------------------------------------- + + //------ BEGIN CONTEXT ------------------------------------------------- + context.set_line_width (0.5); + + //draw Y-axis markers and labels ------------------------ + + for (int p = 10; p <= 100; p += 10) { + y = (long) (h - Y_OFFSET - 10 - (p * pxh)); + + //draw Y-axis markers + context.move_to(x0 + 2, y); + context.line_to(x0 - 2, y); + + /* + //draw Y-axis lines + context.move_to(x0, y); + context.line_to(x100, y); + */ + + //draw Y-axis labels + context.move_to (x0 - X_OFFSET, y); + context.show_text("%d%%".printf(p)); + } + + context.stroke (); + //------ END CONTEXT --------------------------------------------------- + + drawing_area.set_size_request((X_INTERVAL * stat_count) + (2 * X_OFFSET), -1); + + return true; + }); + } + + public void init_stats() { + + //frame_main + Gtk.Frame frame_main = new Gtk.Frame (""); + //(frame_main.label_widget as Gtk.Label).use_markup = true; + vbox_main.add (frame_main); + + var grid_main = new Grid(); + grid_main.set_column_spacing (18); + grid_main.set_row_spacing (6); + grid_main.margin_left = 18; + grid_main.margin_bottom = 6; + frame_main.add(grid_main); + + int col = -1; + + //percent + lbl_percent = new Label(_("Battery")); + grid_main.attach(lbl_percent, ++col, 1, 1, 1); + + lbl_percent_val = new Label("" + _("0h 0m") + ""); + lbl_percent_val.set_use_markup(true); + grid_main.attach(lbl_percent_val, col, 0, 1, 1); + + //avg_life + lbl_avg_life = new Label(_("Average Life")); + lbl_avg_life.set_no_show_all(true); + grid_main.attach(lbl_avg_life, ++col, 1, 1, 1); + + lbl_avg_life_val = new Label("" + _("0h 0m") + ""); + lbl_avg_life_val.set_use_markup(true); + lbl_avg_life_val.set_no_show_all(true); + grid_main.attach(lbl_avg_life_val, col, 0, 1, 1); + + //remaining + lbl_remaining = new Label(_("Remaining")); + lbl_remaining.set_no_show_all(true); + grid_main.attach(lbl_remaining, ++col, 1, 1, 1); + + lbl_remaining_val = new Label("" + _("0h 0m") + ""); + lbl_remaining_val.set_use_markup(true); + lbl_remaining_val.set_no_show_all(true); + grid_main.attach(lbl_remaining_val, col, 0, 1, 1); + + //remaining_to_charge + lbl_time_to_charge = new Label(_("To Full Charge")); + lbl_time_to_charge.set_no_show_all(true); + grid_main.attach(lbl_time_to_charge, ++col, 1, 1, 1); + + lbl_time_to_charge_val = new Label("" + _("0h 0m") + ""); + lbl_time_to_charge_val.set_use_markup(true); + lbl_time_to_charge_val.set_no_show_all(true); + grid_main.attach(lbl_time_to_charge_val, col, 0, 1, 1); + + //rate + lbl_rate = new Label(_("Per Hour")); + lbl_rate.set_no_show_all(true); + grid_main.attach(lbl_rate, ++col, 1, 1, 1); + + lbl_rate_val = new Label("" + _("0.0%") + ""); + lbl_rate_val.set_use_markup(true); + lbl_rate_val.set_no_show_all(true); + grid_main.attach(lbl_rate_val, col, 0, 1, 1); + + //health + lbl_health = new Label(_("Health")); + lbl_health.set_no_show_all(true); + grid_main.attach(lbl_health, ++col, 1, 1, 1); + + lbl_health_val = new Label("" + _("0.0%") + ""); + lbl_health_val.set_use_markup(true); + lbl_health_val.set_no_show_all(true); + grid_main.attach(lbl_health_val, col, 0, 1, 1); + + //spacer + var lbl_spacer = new Label(""); + lbl_spacer.hexpand = true; + grid_main.attach(lbl_spacer, ++col, 0, 1, 2); + + //battery icon + img_battery_status = get_shared_icon("notification-battery-060", "notification-battery-060.png", 80); + img_battery_status.margin_right = 5; + grid_main.attach(img_battery_status, ++col, 0, 1, 2); + } + + public bool timer_refresh_graph() { + + //if (timer_pkg_info > 0){ + // Source.remove(timer_pkg_info); + // timer_pkg_info = 0; + //} + + App.read_battery_stats(); + select_latest_stat(); + update_info_current_cycle(); + update_battery_status_icon(); + return true; + } + + private void select_latest_stat(){ + + if (App.battery_stats_list.size >= 2){ + var stat0 = App.battery_stats_list[App.battery_stats_list.size - 1]; + var stat1 = App.battery_stats_list[App.battery_stats_list.size - 2]; + stat_current = stat0; + redraw_graph_area(); + update_info_stats(stat0,stat1); + } + } + + private void redraw_graph_area() { + drawing_area.queue_draw_area(0, 0, + drawing_area.get_allocated_width(), + drawing_area.get_allocated_height()); + } + + private void update_info_stats(BatteryStat stat, BatteryStat stat_prev){ + lbl_stats_line_batt.label = _("Battery") + ": %0.2f %%, %0.0f mAh, %0.2f Wh, %0.2f V".printf( + stat.charge_percent(), + stat.charge_in_mah(), + stat.charge_in_wh(), + stat.voltage() + ); + } + + private void update_info_current_cycle(){ + + if (App.battery_stats_list.size < 2){ return; } + + var cycle = new BatteryCycle(); + cycle.calculate_stats(App.battery_stats_list); + + //var stat_first = App.battery_stats_list[0]; + var stat_prev = App.battery_stats_list[App.battery_stats_list.size - 2]; + var stat_current = App.battery_stats_list[App.battery_stats_list.size - 1]; + + lbl_stats_line_used.label = _("Used") + ": " + cycle.used_string(); + + lbl_percent_val.label = format_label("%.0f%%".printf(stat_current.charge_percent())); + + if (BatteryStat.is_charging()){ + + //charging ------------------------------ + + lbl_avg_life.visible = lbl_avg_life_val.visible = false; + lbl_remaining.visible = lbl_remaining_val.visible = false; + lbl_time_to_charge.visible = lbl_time_to_charge_val.visible = true; + lbl_rate.visible = lbl_rate_val.visible = true; + lbl_health.visible = lbl_health_val.visible = true; + + double rate = (stat_current.charge_percent() - stat_prev.charge_percent()) * 2; + double estimated = (100 - stat_current.charge_percent()) / rate; + + if (estimated > 0){ + lbl_time_to_charge_val.label = format_label(BatteryCycle.mins_to_string(estimated)); + } + else{ + lbl_time_to_charge_val.label = format_label("??"); + } + + if (estimated > 0){ + lbl_rate_val.label = format_label("+%0.0f%%".printf(rate * 60.0)); + } + else{ + lbl_rate_val.label = format_label("??"); + } + + if (BatteryStat.batt_health() > 0){ + lbl_health_val.label = format_label("%0.0f%%".printf(BatteryStat.batt_health())); + } + else{ + lbl_health_val.label = format_label("??"); + } + } + else{ + + //discharging ------------------------------ + + lbl_avg_life.visible = lbl_avg_life_val.visible = true; + lbl_remaining.visible = lbl_remaining_val.visible = true; + lbl_time_to_charge.visible = lbl_time_to_charge_val.visible = false; + lbl_rate.visible = lbl_rate_val.visible = true; + lbl_health.visible = lbl_health_val.visible = true; + + double rate = (stat_prev.charge_percent() - stat_current.charge_percent()) * 2; + double estimated = 100 / rate; + + lbl_avg_life_val.label = format_label(cycle.battery_life_string()); + + if (estimated > 0){ + lbl_remaining_val.label = format_label(cycle.remaining_time_string()); + } + else{ + lbl_remaining_val.label = format_label("??"); + } + + if (rate > 0){ + lbl_rate_val.label = format_label("-%0.0f%%".printf(cycle.drop_per_min * 60.0)); + } + else{ + lbl_rate_val.label = format_label("??"); + } + } + + if (BatteryStat.batt_health() > 0){ + lbl_health_val.label = format_label("%0.0f%%".printf(BatteryStat.batt_health())); + } + else{ + lbl_health_val.label = format_label("??"); + } + } + + private string format_label(string text){ + return "" + text + ""; + } + + private void update_battery_status_icon(){ + + var icon_name = "notification-battery"; + + var stat = new BatteryStat.read_from_sys(); + double percent = stat.charge_percent(); + + if (percent == 100){ + icon_name += "-100"; + } + else if (percent >= 80){ + icon_name += "-080"; + } + else if (percent >= 60){ + icon_name += "-060"; + } + else if (percent >= 40){ + icon_name += "-040"; + } + else if (percent >= 20){ + icon_name += "-020"; + } + else if (percent >= 0){ + icon_name += "-000"; + } + + if (BatteryStat.is_charging()){ + icon_name += "-plugged"; + } + + var img = get_shared_icon(icon_name, "%s.png".printf(icon_name), 48); + if (img != null){ + img_battery_status.set_from_pixbuf(img.pixbuf); + } + } +} + diff -Nru aptik-battery-monitor-2.1/src/Gtk/DonationWindow.vala aptik-battery-monitor-17.12/src/Gtk/DonationWindow.vala --- aptik-battery-monitor-2.1/src/Gtk/DonationWindow.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Gtk/DonationWindow.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,108 @@ +/* + * DonationWindow.vala + * + * Copyright 2012 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +using Gtk; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.System; +using TeeJee.Misc; + +public class DonationWindow : Dialog { + + public DonationWindow() { + + set_title(_("Donate")); + window_position = WindowPosition.CENTER_ON_PARENT; + set_destroy_with_parent (true); + set_modal (true); + set_deletable(true); + set_skip_taskbar_hint(false); + set_default_size(400, 20); + icon = get_app_icon(16); + + //vbox_main + var vbox_main = get_content_area(); + vbox_main.margin = 6; + vbox_main.margin_right = 12; + vbox_main.homogeneous = false; + + get_action_area().visible = false; + + //lbl_message + var lbl_message = new Gtk.Label(""); + string msg = _("Did you find this application useful?\n\nYou can buy me a coffee if you wish to say thanks, by making a donation with Paypal. Your contributions will help keep this project alive and support future development.\n\n~ Tony George (teejeetech@gmail.com)"); + lbl_message.label = msg; + lbl_message.wrap = true; + vbox_main.pack_start(lbl_message,true,true,0); + + //vbox_actions + var vbox_actions = new Box (Orientation.VERTICAL, 6); + vbox_actions.margin_left = 50; + vbox_actions.margin_right = 50; + vbox_actions.margin_top = 20; + vbox_actions.margin_bottom = 10; + vbox_main.pack_start(vbox_actions,false,false,0); + + // donate_paypal ------------------------------ + + var button = new Button.with_label(_("Donate with PayPal")); + vbox_actions.add(button); + + button.clicked.connect(()=>{ + xdg_open("https://www.paypal.com/cgi-bin/webscr?business=teejeetech@gmail.com&cmd=_xclick¤cy_code=USD&amount=10&item_name=AptikBatteryMonitor%20Donation"); + }); + + // home page ------------------------- + + button = new Button.with_label(_("Project Home Page")); + button.set_tooltip_text("https://github.com/teejee2008/battery-monitor"); + vbox_actions.add(button); + + button.clicked.connect(()=>{ + xdg_open("https://github.com/teejee2008/battery-monitor"); + }); + + // issue tracker -------------------------- + + button = new Button.with_label(_("Issue Tracker")); + button.set_tooltip_text(_("Issue Tracker ~ Report Issues, Request Features, Ask Questions")); + vbox_actions.add(button); + + button.clicked.connect(()=>{ + xdg_open("https://github.com/teejee2008/battery-monitor/issues"); + }); + + // close ------------------------- + + button = new Button.with_label(_("OK")); + vbox_actions.add(button); + + button.clicked.connect(() => { + this.destroy(); + }); + } +} diff -Nru aptik-battery-monitor-2.1/src/Gtk/SettingsWindow.vala aptik-battery-monitor-17.12/src/Gtk/SettingsWindow.vala --- aptik-battery-monitor-2.1/src/Gtk/SettingsWindow.vala 1970-01-01 00:00:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Gtk/SettingsWindow.vala 2017-12-10 14:02:06.000000000 +0000 @@ -0,0 +1,85 @@ +/* + * SettingsWindow.vala + * + * Copyright 2012-2017 Tony George + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + + +using Gtk; +using Gee; + +using TeeJee.Logging; +using TeeJee.FileSystem; +using TeeJee.JSON; +using TeeJee.ProcessManagement; +using TeeJee.GtkHelper; +using TeeJee.Multimedia; +using TeeJee.System; +using TeeJee.Misc; + +public class SettingsWindow : Dialog { + + private Gtk.Switch switch_show_bar; + + public SettingsWindow() { + //set_size_request(500, 300); + set_title(_("Settings")); + window_position = WindowPosition.CENTER_ON_PARENT; + set_destroy_with_parent (true); + set_modal (true); + set_deletable(true); + set_skip_taskbar_hint(true); + icon = get_app_icon(16); + + //vbox_main + Box vbox_main = get_content_area(); + vbox_main.margin = 6; + vbox_main.homogeneous = false; + + var hbox_show_bar = new Box (Orientation.HORIZONTAL, 6); + hbox_show_bar.margin = 6; + vbox_main.add (hbox_show_bar); + + //lbl_message + Label lbl_bar_enable = new Gtk.Label(_("Show battery bar")); + hbox_show_bar.add(lbl_bar_enable); + + //switch_show_bar + switch_show_bar = new Gtk.Switch(); + switch_show_bar.halign = Align.END; + //switch_show_bar.active = App.is_battery_bar_enabled(); + hbox_show_bar.add(switch_show_bar); + + switch_show_bar.notify["active"].connect(() => { + //App.set_battery_bar_status_cron(switch_show_bar.active); + }); + + var hbox_action = (Box) get_action_area(); + + //btn_close + var btn_close = new Button.with_label(" " + _("OK")); + btn_close.set_image (new Image.from_stock ("gtk-ok", IconSize.MENU)); + hbox_action.add(btn_close); + + btn_close.clicked.connect(()=>{ this.destroy(); }); + } +} + + diff -Nru aptik-battery-monitor-2.1/src/Main.vala aptik-battery-monitor-17.12/src/Main.vala --- aptik-battery-monitor-2.1/src/Main.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Main.vala 1970-01-01 00:00:00.000000000 +0000 @@ -1,430 +0,0 @@ -/* - * Main.vala - * - * Copyright 2015 Tony George - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -using GLib; -using Gtk; -using Gee; -using Json; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JSON; -using TeeJee.ProcessManagement; -using TeeJee.GtkHelper; -using TeeJee.Multimedia; -using TeeJee.System; -using TeeJee.Misc; - -public Main App; -public const string AppName = "Aptik Battery Monitor"; -public const string AppShortName = "aptik-battery-monitor"; -public const string AppVersion = "2.1"; -public const string AppAuthor = "Tony George"; -public const string AppAuthorEmail = "teejeetech@gmail.com"; - -const string GETTEXT_PACKAGE = ""; -const string LOCALE_DIR = "/usr/share/locale"; - -extern void exit(int exit_code); - -public class Main : GLib.Object { - public static string BATT_STATS_CACHE_FILE = "/var/log/aptik-battery-monitor/stats.log"; - public static string BATT_STATS_HIST_FILE = "/var/log/aptik-battery-monitor/history.log"; - - public static int BATT_STATS_LOG_INTERVAL = 30; - public static double BATT_STATS_ARCHIVE_LEVEL = 99.00; - - public bool gui_mode = false; - public string user_login = ""; - public string user_home = ""; - public int user_uid = -1; - - public bool print_stats = false; - public string command = ""; - - public string temp_dir = ""; - public string backup_dir = ""; - public string share_dir = "/usr/share"; - public string app_conf_path = ""; - - public Gee.ArrayList battery_stats_list; - public BatteryStat stat_current; - public BatteryStat stat_prev; - public BatteryStat stat_prev2; - - public Main(string[] args, bool _gui_mode) { - - gui_mode = _gui_mode; - - //config file - string home = Environment.get_home_dir(); - app_conf_path = home + "/.config/aptik-battery-monitor.json"; - - //load settings if GUI mode - if (gui_mode) { - load_app_config(); - } - - //check dependencies - string message; - if (!check_dependencies(out message)) { - if (gui_mode) { - string title = _("Missing Dependencies"); - gtk_messagebox(title, message, null, true); - } - exit(0); - } - - //initialize backup_dir as current directory for CLI mode - if (!gui_mode) { - backup_dir = Environment.get_current_dir() + "/"; - } - - try { - //create temp dir - temp_dir = get_temp_file_path(); - - var f = File.new_for_path(temp_dir); - if (f.query_exists()) { - Posix.system("rm -rf %s".printf(temp_dir)); - } - f.make_directory_with_parents(); - } - catch (Error e) { - log_error (e.message); - } - - //get user info - user_login = get_user_login(); - user_home = "/home/" + user_login; - user_uid = get_user_id(user_login); - - //BATT_STATS_CACHE_FILE = "%s/.local/log/aptik-battery-monitor/stats.log".printf(user_home); - } - - public void check_for_multiple_instances(){ - var app_lock = new ApplicationLock("aptik-battery-monitor", false); - if (app_lock.another_instance_is_running()){ - exit(0); - } - else{ - app_lock.create_lock(); - } - } - - public bool check_dependencies(out string msg) { - msg = ""; - - string[] dependencies = { "grep", "find" }; - - string path; - foreach(string cmd_tool in dependencies) { - path = get_cmd_path (cmd_tool); - if ((path == null) || (path.length == 0)) { - msg += " * " + cmd_tool + "\n"; - } - } - - if (msg.length > 0) { - msg = _("Commands listed below are not available on this system") + ":\n\n" + msg + "\n"; - msg += _("Please install the required packages"); - log_msg(msg); - return false; - } - else { - return true; - } - } - - /* Common */ - - public string create_log_dir() { - string log_dir = backup_dir + "logs/" + timestamp3(); - create_dir(log_dir); - return log_dir; - } - - public void save_app_config() { - var config = new Json.Object(); - - var json = new Json.Generator(); - json.pretty = true; - json.indent = 2; - var node = new Json.Node(NodeType.OBJECT); - node.set_object(config); - json.set_root(node); - - try { - json.to_file(this.app_conf_path); - } catch (Error e) { - log_error (e.message); - } - - if (gui_mode) { - log_msg(_("App config saved") + ": '%s'".printf(app_conf_path)); - } - } - - public void load_app_config() { - var f = File.new_for_path(app_conf_path); - if (!f.query_exists()) { - return; - } - - var parser = new Json.Parser(); - try { - parser.load_from_file(this.app_conf_path); - } - catch (Error e) { - log_error (e.message); - } - - //var node = parser.get_root(); - //var config = node.get_object(); - - if (gui_mode) { - log_msg(_("App config loaded") + ": '%s'".printf(this.app_conf_path)); - } - } - - public void exit_app() { - - save_app_config(); - - try { - //delete temporary files - var f = File.new_for_path(temp_dir); - if (f.query_exists()) { - f.delete(); - } - } - catch (Error e) { - log_error (e.message); - } - } - - /* Battery Stats */ - - public void log_battery_stats(bool print_stats) { - try { - // get stats ---------------------- - - var stat = new BatteryStat.read_from_sys(); - stat_current = stat; - - //create or open log - var file = File.new_for_path(BATT_STATS_CACHE_FILE); - if (!file.query_exists()) { - create_empty_log_file(BATT_STATS_CACHE_FILE); - battery_stats_list.clear(); - } - - //check if log needs rotation - check_and_rotate_log(); - - //add entry to log - battery_stats_list.add(stat); - var fos = file.append_to (FileCreateFlags.NONE); - var dos = new DataOutputStream (fos); - dos.put_string(stat.to_delimited_string()); - if (print_stats) { - stdout.printf(stat.to_friendly_string()); - } - - //rotate references - stat_prev2 = stat_prev; - stat_prev = stat_current; - } - catch (Error e) { - log_error (e.message); - } - } - - public bool check_and_rotate_log(){ - // rotates log file when battery drops after removing from charger - - bool rotated = false; - - if ((stat_prev != null) && (stat_prev2 != null)) { - - //check if charge levels for [stat_prev2, stat_prev, stat] are like - //[ 79.80, 80.00, 79.50] - increase and then decrease, or like - //[100.00, 100.00, 99.70] - same values and then decrease - - if((stat_current.charge_percent() < stat_prev.charge_percent()) - && ( (stat_prev.charge_percent() > stat_prev2.charge_percent()) - || (stat_prev2.charge_percent() == stat_prev.charge_percent()) - )) - { - - if (print_stats) { - stdout.printf("\n[" + _("Removed from charger") + "]\n\n"); - } - - log_battery_cycle_summary(); - - // create or open log ------------ - var file = File.new_for_path(BATT_STATS_CACHE_FILE); - if (!file.query_exists()) { - create_empty_log_file(BATT_STATS_CACHE_FILE); - battery_stats_list.clear(); - } - var date_label = (new DateTime.now_local()).format("%F_%H-%M-%S"); - var archive = File.new_for_path(BATT_STATS_CACHE_FILE + "." + date_label); - - try{ - file.move(archive, FileCopyFlags.NONE); - create_empty_log_file(BATT_STATS_CACHE_FILE); - rotated = true; - } - catch(Error e){ - log_error (e.message); - } - - if (print_stats) { - stdout.printf(_("Archived") + ": '%s'\n".printf(archive.get_path())); - stdout.printf(_("Logging stats to file") + ": '%s'\n\n".printf(BATT_STATS_CACHE_FILE)); - } - } - - if ((stat_current.charge_percent() > stat_prev.charge_percent()) - && (stat_prev.charge_percent() < stat_prev2.charge_percent())) - { - if (print_stats) { - stdout.printf("\n[" + _("Charging") + "]\n\n"); - } - } - } - - return rotated; - } - - public void log_battery_cycle_summary(){ - try { - //create or open hist log - var file = File.new_for_path(BATT_STATS_HIST_FILE); - if (!file.query_exists()) { - create_empty_log_file(BATT_STATS_HIST_FILE); - } - - var cycle = new BatteryCycle(); - cycle.calculate_stats(App.battery_stats_list); - - //log cycle summary - var fos = file.append_to (FileCreateFlags.NONE); - var dos = new DataOutputStream (fos); - dos.put_string(cycle.to_delimited_string()); - if (print_stats) { - stdout.printf(_("Logging summary to file") + ": '%s'\n".printf(BATT_STATS_HIST_FILE)); - stdout.printf(cycle.to_friendly_string() + "\n"); - } - } - catch (Error e) { - log_error (e.message); - } - } - - private void create_empty_log_file(string file_path) { - try { - var file = File.new_for_path(file_path); - var parent_dir = file.get_parent(); - - if (!parent_dir.query_exists()) { - parent_dir.make_directory_with_parents(); - Posix.system("chmod a+rwx '%s'".printf(parent_dir.get_path())); - } - - if (!file.query_exists()) { - Posix.system("touch '%s'".printf(file.get_path())); - Posix.system("chmod a+rwx '%s'".printf(file.get_path())); - } - } - catch (Error e) { - log_error (e.message); - } - } - - public void read_battery_stats() { - log_debug("call: read_battery_stats"); - var timer = timer_start(); - - try { - battery_stats_list = new Gee.ArrayList(); - - var file = File.new_for_path (BATT_STATS_CACHE_FILE); - if (file.query_exists ()) { - var dis = new DataInputStream (file.read()); - - string line; - while ((line = dis.read_line (null)) != null) { - var stat = new BatteryStat.from_delimited_string(line); - battery_stats_list.add(stat); - } - - if (battery_stats_list.size >= 1){ - stat_current = battery_stats_list[battery_stats_list.size - 1]; - } - if (battery_stats_list.size >= 2){ - stat_prev = battery_stats_list[battery_stats_list.size - 2]; - } - if (battery_stats_list.size >= 3){ - stat_prev2 = battery_stats_list[battery_stats_list.size - 3]; - } - - log_debug("read_battery_stats: %s".printf(timer_elapsed_string(timer))); - } - else { - log_error (_("File not found") + ": %s".printf(BATT_STATS_CACHE_FILE)); - } - } - catch (Error e) { - log_error (e.message); - } - } - - public void print_log_file(){ - BatteryStat stat_last = null; - foreach (BatteryStat stat in App.battery_stats_list){ - if ((stat_last != null) - && (stat_last.date.add_seconds(Main.BATT_STATS_LOG_INTERVAL + 1).compare(stat.date) < 0)) - { - stdout.printf(string.nfill(79, '-') + "\n"); - - var diff = stat.date.difference(stat_last.date); - - var hr = (int64) (diff / (1000000.0 * 60 * 60)); - diff = (int64) (diff % (1000000.0 * 60 * 60)); - var min = (int64) (diff / (1000000.0 * 60)); - diff = (int64) (diff % (1000000.0 * 60)); - var sec = (int64) (diff / (1000000.0)); - - stdout.printf("Gap: %02lld:%02lld:%02lld\n".printf(hr,min,sec)); - stdout.printf(string.nfill(79, '-') + "\n"); - } - - stdout.printf(stat.to_friendly_string()); - stat_last = stat; - } - } -} - diff -Nru aptik-battery-monitor-2.1/src/makefile aptik-battery-monitor-17.12/src/makefile --- aptik-battery-monitor-2.1/src/makefile 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/makefile 2017-12-10 14:02:06.000000000 +0000 @@ -11,22 +11,30 @@ app_name_full='Aptik Battery Monitor' all: - #build binaries + # build binaries - #aptik-battery-monitor - valac -X -D'GETTEXT_PACKAGE="${app_name}"' --Xcc="-lm" -X -Wl,-rpath,/usr/share/${app_name}/libs --thread "Main.vala" "Classes.vala" "Utility.vala" "AptikBatteryStats.vala" "DonationWindow.vala" "AboutWindow.vala" -o "aptik-battery-monitor" --pkg glib-2.0 --pkg gio-unix-2.0 --pkg posix --pkg gtk+-3.0 --pkg gee-0.8 --pkg libsoup-2.4 --pkg json-glib-1.0 + # aptik-battery-monitor + valac -X -D'GETTEXT_PACKAGE="${app_name}"' --Xcc="-lm" --thread \ + Common/*.vala "AptikBatteryStats.vala" \ + -o "aptik-battery-monitor" \ + --pkg glib-2.0 --pkg gio-unix-2.0 --pkg posix --pkg gee-0.8 \ + --pkg gtk+-3.0 --pkg libsoup-2.4 --pkg json-glib-1.0 + + # aptik-battery-monitor-gtk + valac -X -D'GETTEXT_PACKAGE="${app_name}"' --Xcc="-lm" --thread \ + Common/*.vala Gtk/*.vala \ + -o "aptik-battery-monitor-gtk" \ + --pkg glib-2.0 --pkg gio-unix-2.0 --pkg posix --pkg gee-0.8 \ + --pkg gtk+-3.0 --pkg libsoup-2.4 --pkg json-glib-1.0 - #aptik-battery-monitor-gtk - valac -X -D'GETTEXT_PACKAGE="${app_name}"' --Xcc="-lm" -X -Wl,-rpath,/usr/share/${app_name}/libs --thread "Main.vala" "Classes.vala" "Utility.vala" "AptikBatteryStatsGtk.vala" "BatteryStatsWindow.vala" "DonationWindow.vala" "AboutWindow.vala" "SettingsWindow.vala" -o "aptik-battery-monitor-gtk" --pkg glib-2.0 --pkg gio-unix-2.0 --pkg posix --pkg gtk+-3.0 --pkg gee-0.8 --pkg libsoup-2.4 --pkg json-glib-1.0 - - #aptik-battery-bar - #valac -X -D'GETTEXT_PACKAGE="${app_name}"' --Xcc="-lm" -X -Wl,-rpath,/usr/share/${app_name}/libs --thread "Main.vala" "Classes.vala" "Utility.vala" "BatteryBar.vala" -o "aptik-battery-bar" --pkg glib-2.0 --pkg gio-unix-2.0 --pkg posix --pkg gtk+-3.0 --pkg gee-0.8 --pkg libsoup-2.4 --pkg json-glib-1.0 - - #update translation template + # update translation template xgettext --language=C --keyword=_ --copyright-holder='Tony George (teejee2008@gmail.com)' --package-name='${app_name}' --package-version='1.6' --msgid-bugs-address='teejee2008@gmail.com' --escape --sort-output -o ../${app_name}.pot *.vala clean: - rm -rf *.o ${app_name} + rm -rfv ../release/{source,i386,amd64,armel,armhf} + rm -rfv ../release/*.{run,deb} + rm -rfv *.c *.o *.mo + rm -fv ${app_name} ${app_name}-gtk install: mkdir -p "$(DESTDIR)$(bindir)" @@ -36,6 +44,7 @@ mkdir -p "$(DESTDIR)$(launcherdir)" mkdir -p "$(DESTDIR)$(sharedir)/${app_name}" mkdir -p "$(DESTDIR)$(sharedir)/pixmaps" + mkdir -p "$(DESTDIR)$(sharedir)/appdata" mkdir -p "$(DESTDIR)$(logdir)/aptik-battery-monitor" mkdir -p "$(DESTDIR)/etc/init.d" #mkdir -p "$(DESTDIR)$(localedir)/it_IT/LC_MESSAGES" @@ -47,8 +56,7 @@ install -m 0755 ${app_name} "$(DESTDIR)$(bindir)" install -m 0755 ${app_name}-gtk "$(DESTDIR)$(bindir)" install -m 0755 ${app_name}-uninstall "$(DESTDIR)$(bindir)" - #install -m 0755 aptik-battery-bar "$(DESTDIR)$(bindir)" - + #shared files cp -dpr --no-preserve=ownership -t "$(DESTDIR)$(sharedir)/${app_name}" ./share/${app_name}/* chmod --recursive 0755 $(DESTDIR)$(sharedir)/${app_name}/* @@ -59,6 +67,9 @@ #app icon install -m 0755 ./share/pixmaps/${app_name}.svg "$(DESTDIR)$(sharedir)/pixmaps/" + # appdata + install -m 0755 ../debian/${app_name}.appdata.xml "$(DESTDIR)$(sharedir)/appdata" + #service install -m 0755 ${app_name}-service "$(DESTDIR)/etc/init.d/${app_name}" @@ -70,22 +81,24 @@ uninstall: - #binary + # binary rm -f "$(DESTDIR)$(bindir)/${app_name}" rm -f "$(DESTDIR)$(bindir)/${app_name}-gtk" rm -f "$(DESTDIR)$(bindir)/${app_name}-uninstall" - #rm -f "$(DESTDIR)$(bindir)/aptik-battery-bar" - #shared files + # shared files rm -rf "$(DESTDIR)$(sharedir)/${app_name}" - #launcher + # launcher rm -f "$(DESTDIR)$(launcherdir)/${app_name}.desktop" - #app icon + # app icon rm -f "$(DESTDIR)$(sharedir)/pixmaps/${app_name}.svg" - #service + # app data + rm -f "$(DESTDIR)$(sharedir)/appdata/${app_name}.appdata.xml" + + # service rm -f "$(DESTDIR)/etc/init.d/${app_name}" #translations diff -Nru aptik-battery-monitor-2.1/src/SettingsWindow.vala aptik-battery-monitor-17.12/src/SettingsWindow.vala --- aptik-battery-monitor-2.1/src/SettingsWindow.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/SettingsWindow.vala 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -/* - * SettingsWindow.vala - * - * Copyright 2015 Tony George - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - - -using Gtk; -using Gee; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JSON; -using TeeJee.ProcessManagement; -using TeeJee.GtkHelper; -using TeeJee.Multimedia; -using TeeJee.System; -using TeeJee.Misc; - -public class SettingsWindow : Dialog { - - private Gtk.Switch switch_show_bar; - - public SettingsWindow() { - //set_size_request(500, 300); - set_title(_("Settings")); - window_position = WindowPosition.CENTER_ON_PARENT; - set_destroy_with_parent (true); - set_modal (true); - set_deletable(true); - set_skip_taskbar_hint(true); - icon = get_app_icon(16); - - //vbox_main - Box vbox_main = get_content_area(); - vbox_main.margin = 6; - vbox_main.homogeneous = false; - - var hbox_show_bar = new Box (Orientation.HORIZONTAL, 6); - hbox_show_bar.margin = 6; - vbox_main.add (hbox_show_bar); - - //lbl_message - Label lbl_bar_enable = new Gtk.Label(_("Show battery bar")); - hbox_show_bar.add(lbl_bar_enable); - - //switch_show_bar - switch_show_bar = new Gtk.Switch(); - switch_show_bar.halign = Align.END; - //switch_show_bar.active = App.is_battery_bar_enabled(); - hbox_show_bar.add(switch_show_bar); - - switch_show_bar.notify["active"].connect(() => { - //App.set_battery_bar_status_cron(switch_show_bar.active); - }); - - var hbox_action = (Box) get_action_area(); - - //btn_close - var btn_close = new Button.with_label(" " + _("OK")); - btn_close.set_image (new Image.from_stock ("gtk-ok", IconSize.MENU)); - hbox_action.add(btn_close); - - btn_close.clicked.connect(()=>{ this.destroy(); }); - } -} - - diff -Nru aptik-battery-monitor-2.1/src/Utility.vala aptik-battery-monitor-17.12/src/Utility.vala --- aptik-battery-monitor-2.1/src/Utility.vala 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/src/Utility.vala 1970-01-01 00:00:00.000000000 +0000 @@ -1,2168 +0,0 @@ -/* - * Utility.vala - * - * Copyright 2012 Tony George - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -using Gtk; -using Json; -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JSON; -using TeeJee.ProcessManagement; -using TeeJee.GtkHelper; -using TeeJee.Multimedia; -using TeeJee.System; -using TeeJee.Misc; - -/* -extern void exit(int exit_code); -*/ - -namespace TeeJee.Logging{ - - /* Functions for logging messages to console and log files */ - - using TeeJee.Misc; - - public DataOutputStream dos_log; - - public bool LOG_ENABLE = true; - public bool LOG_TIMESTAMP = true; - public bool LOG_COLORS = true; - public bool LOG_DEBUG = false; - public bool LOG_COMMANDS = false; - - public void log_msg (string message, bool highlight = false){ - - if (!LOG_ENABLE) { return; } - - string msg = ""; - - if (highlight && LOG_COLORS){ - msg += "\033[1;38;5;34m"; - } - - if (LOG_TIMESTAMP){ - msg += "[" + timestamp() + "] "; - } - - msg += message; - - if (highlight && LOG_COLORS){ - msg += "\033[0m"; - } - - msg += "\n"; - - stdout.printf (msg); - - try { - if (dos_log != null){ - dos_log.put_string ("[%s] %s\n".printf(timestamp(), message)); - } - } - catch (Error e) { - stdout.printf (e.message); - } - } - - public void log_error (string message, bool highlight = false, bool is_warning = false){ - if (!LOG_ENABLE) { return; } - - string msg = ""; - - if (highlight && LOG_COLORS){ - msg += "\033[1;38;5;160m"; - } - - if (LOG_TIMESTAMP){ - msg += "[" + timestamp() + "] "; - } - - string prefix = (is_warning) ? _("Warning") : _("Error"); - - msg += prefix + ": " + message; - - if (highlight && LOG_COLORS){ - msg += "\033[0m"; - } - - msg += "\n"; - - stdout.printf (msg); - - try { - if (dos_log != null){ - dos_log.put_string ("[%s] %s: %s\n".printf(timestamp(), prefix, message)); - } - } - catch (Error e) { - stdout.printf (e.message); - } - } - - public void log_debug (string message){ - if (!LOG_ENABLE) { return; } - - if (LOG_DEBUG){ - log_msg (message); - } - else{ - try { - if (dos_log != null){ - dos_log.put_string ("[%s] %s\n".printf(timestamp(), message)); - } - } - catch (Error e) { - stdout.printf (e.message); - } - } - } -} - -namespace TeeJee.FileSystem{ - - /* Convenience functions for handling files and directories */ - - using TeeJee.Logging; - using TeeJee.FileSystem; - using TeeJee.ProcessManagement; - using TeeJee.Misc; - - public void file_delete(string filePath){ - - /* Check and delete file */ - - try { - var file = File.new_for_path (filePath); - if (file.query_exists ()) { - file.delete (); - } - } catch (Error e) { - log_error (e.message); - } - } - - public bool file_exists (string filePath){ - - /* Check if file exists */ - - return ( FileUtils.test(filePath, GLib.FileTest.EXISTS) && FileUtils.test(filePath, GLib.FileTest.IS_REGULAR)); - } - - public void file_copy (string src_file, string dest_file){ - try{ - var file_src = File.new_for_path (src_file); - if (file_src.query_exists()) { - var file_dest = File.new_for_path (dest_file); - file_src.copy(file_dest,FileCopyFlags.OVERWRITE,null,null); - } - } - catch(Error e){ - log_error (e.message); - } - } - - public bool dir_exists (string filePath){ - - /* Check if directory exists */ - - return ( FileUtils.test(filePath, GLib.FileTest.EXISTS) && FileUtils.test(filePath, GLib.FileTest.IS_DIR)); - } - - public bool create_dir (string filePath){ - - /* Creates a directory along with parents */ - - try{ - var dir = File.parse_name (filePath); - if (dir.query_exists () == false) { - dir.make_directory_with_parents (null); - } - return true; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - public bool move_file (string sourcePath, string destPath){ - - /* Move file from one location to another */ - - try{ - File fromFile = File.new_for_path (sourcePath); - File toFile = File.new_for_path (destPath); - fromFile.move (toFile, FileCopyFlags.NONE); - return true; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - public bool copy_file (string sourcePath, string destPath){ - - /* Copy file from one location to another */ - - try{ - File fromFile = File.new_for_path (sourcePath); - File toFile = File.new_for_path (destPath); - fromFile.copy (toFile, FileCopyFlags.NONE); - return true; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - public string? read_file (string file_path){ - - /* Reads text from file */ - - string txt; - size_t size; - - try{ - GLib.FileUtils.get_contents (file_path, out txt, out size); - return txt; - } - catch (Error e){ - log_error (e.message); - } - - return null; - } - - public DateTime? get_file_modification_time (string file_path){ - try{ - var file = File.new_for_path (file_path); - if (file.query_exists()) { - var info = file.query_info("*",FileQueryInfoFlags.NONE); - TimeVal modified = info.get_modification_time(); - return new DateTime.from_timeval_local(modified); - } - else{ - log_error("File not found: %s".printf(file_path)); - } - } - catch (Error e) { - log_error (e.message); - } - - return null; - } - - public bool write_file (string file_path, string contents){ - - /* Write text to file */ - - try{ - var file = File.new_for_path (file_path); - if (file.query_exists ()) { file.delete (); } - var file_stream = file.create (FileCreateFlags.REPLACE_DESTINATION); - var data_stream = new DataOutputStream (file_stream); - data_stream.put_string (contents); - data_stream.close(); - return true; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - public long get_file_count(string path){ - - /* Return total count of files and directories */ - - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - cmd = "find \"%s\" | wc -l".printf(path); - ret_val = execute_command_script_sync(cmd, out std_out, out std_err); - return long.parse(std_out); - } - - public long get_file_size(string path){ - - /* Returns size of files and directories in KB*/ - - string cmd = ""; - string output = ""; - - cmd = "du -s \"%s\"".printf(path); - output = execute_command_sync_get_output(cmd); - return long.parse(output.split("\t")[0]); - } - - public string get_file_size_formatted(string path){ - - /* Returns size of files and directories in KB*/ - - string cmd = ""; - string output = ""; - - cmd = "du -s -h \"%s\"".printf(path); - output = execute_command_sync_get_output(cmd); - return output.split("\t")[0].strip(); - } - - public int chmod (string file, string permission){ - - /* Change file permissions */ - - return execute_command_sync ("chmod " + permission + " \"%s\"".printf(file)); - } - - public string resolve_relative_path (string filePath){ - - /* Resolve the full path of given file using 'realpath' command */ - - string filePath2 = filePath; - if (filePath2.has_prefix ("~")){ - filePath2 = Environment.get_home_dir () + "/" + filePath2[2:filePath2.length]; - } - - try { - string output = ""; - Process.spawn_command_line_sync("realpath \"%s\"".printf(filePath2), out output); - output = output.strip (); - if (FileUtils.test(output, GLib.FileTest.EXISTS)){ - return output; - } - } - catch(Error e){ - log_error (e.message); - } - - return filePath2; - } - - public int rsync (string sourceDirectory, string destDirectory, bool updateExisting, bool deleteExtra){ - - /* Sync files with rsync */ - - string cmd = "rsync --recursive --perms --chmod=a=rwx"; - cmd += updateExisting ? "" : " --ignore-existing"; - cmd += deleteExtra ? " --delete" : ""; - cmd += " \"%s\"".printf(sourceDirectory + "//"); - cmd += " \"%s\"".printf(destDirectory); - return execute_command_sync (cmd); - } -} - -namespace TeeJee.JSON{ - - using TeeJee.Logging; - - /* Convenience functions for reading and writing JSON files */ - - public string json_get_string(Json.Object jobj, string member, string def_value){ - if (jobj.has_member(member)){ - return jobj.get_string_member(member); - } - else{ - log_error ("Member not found in JSON object: " + member, false, true); - return def_value; - } - } - - public bool json_get_bool(Json.Object jobj, string member, bool def_value){ - if (jobj.has_member(member)){ - return bool.parse(jobj.get_string_member(member)); - } - else{ - log_error ("Member not found in JSON object: " + member, false, true); - return def_value; - } - } - - public int json_get_int(Json.Object jobj, string member, int def_value){ - if (jobj.has_member(member)){ - return int.parse(jobj.get_string_member(member)); - } - else{ - log_error ("Member not found in JSON object: " + member, false, true); - return def_value; - } - } - -} - -namespace TeeJee.ProcessManagement{ - using TeeJee.Logging; - using TeeJee.FileSystem; - using TeeJee.Misc; - - public string TEMP_DIR; - - /* Convenience functions for executing commands and managing processes */ - - public static void init_tmp(){ - string std_out, std_err; - - TEMP_DIR = Environment.get_tmp_dir() + "/" + AppShortName; - create_dir(TEMP_DIR); - - execute_command_script_sync("echo 'ok'",out std_out,out std_err, true); - if ((std_out == null)||(std_out.strip() != "ok")){ - TEMP_DIR = Environment.get_home_dir() + "/.temp/" + AppShortName; - execute_command_sync("rm -rf '%s'".printf(TEMP_DIR)); - create_dir(TEMP_DIR); - } - - //log_debug("TEMP_DIR=" + TEMP_DIR); - } - - public int execute_command_sync (string cmd){ - - /* Executes single command synchronously and returns exit code - * Pipes and multiple commands are not supported */ - - try { - int exitCode; - Process.spawn_command_line_sync(cmd, null, null, out exitCode); - return exitCode; - } - catch (Error e){ - log_error (e.message); - return -1; - } - } - - public string execute_command_sync_get_output (string cmd){ - - /* Executes single command synchronously and returns std_out - * Pipes and multiple commands are not supported */ - - try { - int exitCode; - string std_out; - Process.spawn_command_line_sync(cmd, out std_out, null, out exitCode); - return std_out; - } - catch (Error e){ - log_error (e.message); - return ""; - } - } - - public bool execute_command_script_async (string cmd){ - - /* Creates a temporary bash script with given commands and executes it asynchronously - * Return value indicates if script was started successfully */ - - try { - - string scriptfile = create_temp_bash_script (cmd); - - string[] argv = new string[1]; - argv[0] = scriptfile; - - Pid child_pid; - Process.spawn_async_with_pipes( - null, //working dir - argv, //argv - null, //environment - SpawnFlags.SEARCH_PATH, - null, - out child_pid); - return true; - } - catch (Error e){ - log_error (e.message); - return false; - } - } - - public string? create_temp_bash_script (string script_text, bool supress_errors = false){ - - /* Creates a temporary bash script with given commands - * Returns the script file path */ - - var sh = ""; - sh += "#!/bin/bash\n"; - sh += script_text; - - string script_path = get_temp_file_path() + ".sh"; - - try{ - //write script file - var file = File.new_for_path (script_path); - if (file.query_exists ()) { file.delete (); } - var file_stream = file.create (FileCreateFlags.REPLACE_DESTINATION); - var data_stream = new DataOutputStream (file_stream); - data_stream.put_string (sh); - data_stream.close(); - - // set execute permission - chmod (script_path, "u+x"); - - return script_path; - } - catch (Error e) { - if (!supress_errors){ - log_error (e.message); - } - } - - return null; - } - - public string get_temp_file_path(){ - - /* Generates temporary file path */ - - return TEMP_DIR + "/" + timestamp2() + (new Rand()).next_int().to_string(); - } - - public int execute_command_script_sync (string script, out string std_out, out string std_err, bool supress_errors = false){ - - /* Executes commands synchronously - * Returns exit code, output messages and error messages. - * Commands are written to a temporary bash script and executed. */ - - string path = create_temp_bash_script(script,supress_errors); - - try { - - string[] argv = new string[1]; - argv[0] = path; - - int exit_code; - - Process.spawn_sync ( - TEMP_DIR, //working dir - argv, //argv - null, //environment - SpawnFlags.SEARCH_PATH, - null, // child_setup - out std_out, - out std_err, - out exit_code - ); - - return exit_code; - } - catch (Error e){ - if (!supress_errors){ - log_error (e.message); - } - return -1; - } - } - - public int execute_command_script_sync2 (string script){ - - /* Executes commands synchronously - * Returns exit code, output messages and error messages. - * Commands are written to a temporary bash script and executed. */ - - string path = create_temp_bash_script(script); - - try { - - string[] argv = new string[1]; - argv[0] = path; - - int exit_code; - - Process.spawn_sync ( - TEMP_DIR, //working dir - argv, //argv - null, //environment - SpawnFlags.SEARCH_PATH, - null, // child_setup - null, - null, - out exit_code - ); - - return exit_code; - } - catch (Error e){ - log_error (e.message); - return -1; - } - } - - public bool execute_command_script_in_terminal_sync (string script){ - - /* Executes a command script in a terminal window */ - //TODO: Remove this - - try { - - string[] argv = new string[3]; - argv[0] = "x-terminal-emulator"; - argv[1] = "-e"; - argv[2] = script; - - Process.spawn_sync ( - TEMP_DIR, //working dir - argv, //argv - null, //environment - SpawnFlags.SEARCH_PATH, - null // child_setup - ); - - return true; - } - catch (Error e){ - log_error (e.message); - return false; - } - } - - public int execute_bash_script_fullscreen_sync (string script_file){ - - /* Executes a bash script synchronously. - * Script is executed in a fullscreen terminal window */ - - string path; - - path = get_cmd_path ("xfce4-terminal"); - if ((path != null)&&(path != "")){ - return execute_command_sync ("xfce4-terminal --fullscreen -e \"%s\"".printf(script_file)); - } - - path = get_cmd_path ("gnome-terminal"); - if ((path != null)&&(path != "")){ - return execute_command_sync ("gnome-terminal --full-screen -e \"%s\"".printf(script_file)); - } - - path = get_cmd_path ("xterm"); - if ((path != null)&&(path != "")){ - return execute_command_sync ("xterm --fullscreen -e \"%s\"".printf(script_file)); - } - - //default terminal - unknown, normal window - path = get_cmd_path ("x-terminal-emulator"); - if ((path != null)&&(path != "")){ - return execute_command_sync ("x-terminal-emulator -e \"%s\"".printf(script_file)); - } - - return -1; - } - - public int execute_bash_script_sync (string script_file){ - - /* Executes a bash script synchronously in the default terminal window */ - - string path = get_cmd_path ("x-terminal-emulator"); - if ((path != null)&&(path != "")){ - return execute_command_sync ("x-terminal-emulator -e \"%s\"".printf(script_file)); - } - - return -1; - } - - public string get_cmd_path (string cmd){ - - /* Returns the full path to a command */ - - try { - int exitCode; - string stdout, stderr; - Process.spawn_command_line_sync("which " + cmd, out stdout, out stderr, out exitCode); - return stdout; - } - catch (Error e){ - log_error (e.message); - return ""; - } - } - - public int get_pid_by_name (string name){ - - /* Get the process ID for a process with given name */ - - try{ - string output = ""; - Process.spawn_command_line_sync("pidof \"%s\"".printf(name), out output); - if (output != null){ - string[] arr = output.split ("\n"); - if (arr.length > 0){ - return int.parse (arr[0]); - } - } - } - catch (Error e) { - log_error (e.message); - } - - return -1; - } - - public bool process_is_running_by_name(string proc_name){ - - /* Checks if given process is running - * Note: We are not using 'psgrep -f' as it cannot be used for an exact match*/ - - /* TODO: This matches processes ending with proc_name. Should not match */ - - string txt = execute_command_sync_get_output ("ps w -C '%s'".printf(proc_name)); - //use 'ps ew -C ''' for all users - - foreach(string line in txt.split("\n")){ - string padded_line = line + " "; - if (padded_line.index_of(proc_name + " ") > -1){ - return true; - } - } - - return false; - } - - public bool process_is_running(long pid){ - - /* Checks if given process is running */ - - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - try{ - cmd = "ps --pid %ld".printf(pid); - Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); - } - catch (Error e) { - log_error (e.message); - return false; - } - - return (ret_val == 0); - } - - public int[] get_process_children (Pid parentPid){ - - /* Returns the list of child processes spawned by given process */ - - string output; - - try { - Process.spawn_command_line_sync("ps --ppid %d".printf(parentPid), out output); - } - catch(Error e){ - log_error (e.message); - } - - int pid; - int[] procList = {}; - string[] arr; - - foreach (string line in output.split ("\n")){ - arr = line.strip().split (" "); - if (arr.length < 1) { continue; } - - pid = 0; - pid = int.parse (arr[0]); - - if (pid != 0){ - procList += pid; - } - } - return procList; - } - - - public void process_kill(Pid process_pid, bool killChildren = true){ - - /* Kills specified process and its children (optional) */ - - int[] child_pids = get_process_children (process_pid); - Posix.kill (process_pid, 15); - - if (killChildren){ - Pid childPid; - foreach (long pid in child_pids){ - childPid = (Pid) pid; - Posix.kill (childPid, 15); - } - } - } - - public int process_pause (Pid procID){ - - /* Pause/Freeze a process */ - - return execute_command_sync ("kill -STOP %d".printf(procID)); - } - - public int process_resume (Pid procID){ - - /* Resume/Un-freeze a process*/ - - return execute_command_sync ("kill -CONT %d".printf(procID)); - } - - public void command_kill(string cmd_name, string cmd_to_match, bool exact_match){ - - /* Kills a specific command */ - - string txt = execute_command_sync_get_output ("ps w -C '%s'".printf(cmd_name)); - //use 'ps ew -C conky' for all users - - string pid = ""; - foreach(string line in txt.split("\n")){ - if ((exact_match && line.strip().has_suffix(cmd_to_match)) - || (!exact_match && (line.index_of(cmd_to_match) != -1))){ - pid = line.strip().split(" ")[0]; - Posix.kill ((Pid) int.parse(pid), 15); - log_debug(_("Stopped") + ": [PID=" + pid + "] "); - } - } - } - - - public void process_set_priority (Pid procID, int prio){ - - /* Set process priority */ - - if (Posix.getpriority (Posix.PRIO_PROCESS, procID) != prio) - Posix.setpriority (Posix.PRIO_PROCESS, procID, prio); - } - - public int process_get_priority (Pid procID){ - - /* Get process priority */ - - return Posix.getpriority (Posix.PRIO_PROCESS, procID); - } - - public void process_set_priority_normal (Pid procID){ - - /* Set normal priority for process */ - - process_set_priority (procID, 0); - } - - public void process_set_priority_low (Pid procID){ - - /* Set low priority for process */ - - process_set_priority (procID, 5); - } - - - public bool user_is_admin (){ - - /* Check if current application is running with admin priviledges */ - - try{ - // create a process - string[] argv = { "sleep", "10" }; - Pid procId; - Process.spawn_async(null, argv, null, SpawnFlags.SEARCH_PATH, null, out procId); - - // try changing the priority - Posix.setpriority (Posix.PRIO_PROCESS, procId, -5); - - // check if priority was changed successfully - if (Posix.getpriority (Posix.PRIO_PROCESS, procId) == -5) - return true; - else - return false; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - public string get_user_login(){ - /* - Returns Login ID of current user. - If running as 'sudo' it will return Login ID of the actual user. - */ - - string cmd = "echo ${SUDO_USER:-$(whoami)}"; - string std_out; - string std_err; - int ret_val; - ret_val = execute_command_script_sync(cmd, out std_out, out std_err); - - string user_name; - if ((std_out == null) || (std_out.length == 0)){ - user_name = "root"; - } - else{ - user_name = std_out.strip(); - } - - return user_name; - } - - public int get_user_id(string user_login){ - /* - Returns UID of specified user. - */ - - int uid = -1; - string cmd = "id %s -u".printf(user_login); - string txt = execute_command_sync_get_output(cmd); - if ((txt != null) && (txt.length > 0)){ - uid = int.parse(txt); - } - - return uid; - } - - - public string get_app_path (){ - - /* Get path of current process */ - - try{ - return GLib.FileUtils.read_link ("/proc/self/exe"); - } - catch (Error e){ - log_error (e.message); - return ""; - } - } - - public string get_app_dir (){ - - /* Get parent directory of current process */ - - try{ - return (File.new_for_path (GLib.FileUtils.read_link ("/proc/self/exe"))).get_parent ().get_path (); - } - catch (Error e){ - log_error (e.message); - return ""; - } - } - - - public class ApplicationLock{ - string pid_current = ""; - string app_name = ""; - bool gui_mode = false; - - public ApplicationLock(string _app_name, bool _gui_mode){ - app_name = _app_name; - gui_mode = _gui_mode; - pid_current = ((long)Posix.getpid()).to_string(); - } - - public string lock_file{ - owned get { - return "/var/run/lock/%s.lock".printf(app_name); - } - } - - public bool another_instance_is_running(){ - try{ - var file = File.new_for_path (lock_file); - if (file.query_exists()) { - var dis = new DataInputStream (file.read()); - string line; - - if ((line = dis.read_line (null)) != null) { - long pid = long.parse(line.strip()); - - if (process_is_running(pid)){ - stderr.printf(_("[Error] Another instance of this process is already running") + " (PID=%ld)\n".printf(pid)); - stderr.flush(); - - return true; - } - else{ - stderr.printf(_("[Warning] Removed invalid lock file") + ": '%s'\n".printf(lock_file)); - stderr.flush(); - - file.delete(); - return false; - } - } - - dis.close(); - } - - return false; - } - catch (Error e) { - stderr.printf (e.message); - stderr.flush(); - return false; - } - } - - public void create_lock(){ - try{ - var file = File.new_for_path (lock_file); - var fs = file.create (FileCreateFlags.REPLACE_DESTINATION); - var dos = new DataOutputStream (fs); - dos.put_string (pid_current); - dos.close(); - } - catch (Error e) { - log_error (e.message); - } - } - - public void remove_lock(){ - try{ - var file = File.new_for_path (lock_file); - if (file.query_exists()) { - file.delete(); - } - } - catch (Error e) { - log_error (e.message); - } - } - } - -} - -namespace TeeJee.GtkHelper{ - - using Gtk; - - public void gtk_do_events (){ - - /* Do pending events */ - - while(Gtk.events_pending ()) - Gtk.main_iteration (); - } - - public void gtk_set_busy (bool busy, Gtk.Window win) { - - /* Show or hide busy cursor on window */ - - Gdk.Cursor? cursor = null; - - if (busy){ - cursor = new Gdk.Cursor(Gdk.CursorType.WATCH); - } - else{ - cursor = new Gdk.Cursor(Gdk.CursorType.ARROW); - } - - var window = win.get_window (); - - if (window != null) { - window.set_cursor (cursor); - } - - gtk_do_events (); - } - - public void gtk_messagebox(string title, string message, Gtk.Window? parent_win, bool is_error = false){ - - /* Shows a simple message box */ - - Gtk.MessageType type = Gtk.MessageType.INFO; - if (is_error){ - type = Gtk.MessageType.ERROR; - } - else{ - type = Gtk.MessageType.INFO; - } - - var dlg = new Gtk.MessageDialog.with_markup(null, Gtk.DialogFlags.MODAL, type, Gtk.ButtonsType.OK, message); - dlg.title = title; - dlg.set_default_size (200, -1); - if (parent_win != null){ - dlg.set_transient_for(parent_win); - dlg.set_modal(true); - } - dlg.run(); - dlg.destroy(); - } - - public bool gtk_combobox_set_value (ComboBox combo, int index, string val){ - - /* Conveniance function to set combobox value */ - - TreeIter iter; - string comboVal; - TreeModel model = (TreeModel) combo.model; - - bool iterExists = model.get_iter_first (out iter); - while (iterExists){ - model.get(iter, 1, out comboVal); - if (comboVal == val){ - combo.set_active_iter(iter); - return true; - } - iterExists = model.iter_next (ref iter); - } - - return false; - } - - public string gtk_combobox_get_value (ComboBox combo, int index, string default_value){ - - /* Conveniance function to get combobox value */ - - if ((combo.model == null) || (combo.active < 0)) { return default_value; } - - TreeIter iter; - string val = ""; - combo.get_active_iter (out iter); - TreeModel model = (TreeModel) combo.model; - model.get(iter, index, out val); - - return val; - } - - public class CellRendererProgress2 : Gtk.CellRendererProgress{ - public override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) { - if (text == "--") - return; - - int diff = (int) ((cell_area.height - height)/2); - - // Apply the new height into the bar, and center vertically: - Gdk.Rectangle new_area = Gdk.Rectangle() ; - new_area.x = cell_area.x; - new_area.y = cell_area.y + diff; - new_area.width = width - 5; - new_area.height = height; - - base.render(cr, widget, background_area, new_area, flags); - } - } - - public Gdk.Pixbuf? get_app_icon(int icon_size, string format = ".png"){ - var img_icon = get_shared_icon(AppShortName, AppShortName + format,icon_size,"pixmaps"); - if (img_icon != null){ - return img_icon.pixbuf; - } - else{ - return null; - } - } - - public Gtk.Image? get_shared_icon(string icon_name, string fallback_icon_file_name, int icon_size, string icon_directory = AppShortName + "/images"){ - Gdk.Pixbuf pix_icon = null; - Gtk.Image img_icon = null; - - try { - Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default(); - pix_icon = icon_theme.load_icon (icon_name, icon_size, 0); - } catch (Error e) { - //log_error (e.message); - } - - string fallback_icon_file_path = "/usr/share/%s/%s".printf(icon_directory, fallback_icon_file_name); - - if (pix_icon == null){ - try { - pix_icon = new Gdk.Pixbuf.from_file_at_size (fallback_icon_file_path, icon_size, icon_size); - } catch (Error e) { - log_error (e.message); - } - } - - if (pix_icon == null){ - log_error (_("Missing Icon") + ": '%s', '%s'".printf(icon_name, fallback_icon_file_path)); - } - else{ - img_icon = new Gtk.Image.from_pixbuf(pix_icon); - } - - return img_icon; - } - - public int gtk_treeview_model_count(TreeModel model){ - int count = 0; - TreeIter iter; - if (model.get_iter_first(out iter)){ - count++; - while(model.iter_next(ref iter)){ - count++; - } - } - return count; - } -} - -namespace TeeJee.Multimedia{ - - using TeeJee.Logging; - - /* Functions for working with audio/video files */ - - public long get_file_duration(string filePath){ - - /* Returns the duration of an audio/video file using MediaInfo */ - - string output = "0"; - - try { - Process.spawn_command_line_sync("mediainfo \"--Inform=General;%Duration%\" \"" + filePath + "\"", out output); - } - catch(Error e){ - log_error (e.message); - } - - return long.parse(output); - } - - public string get_file_crop_params (string filePath){ - - /* Returns cropping parameters for a video file using avconv */ - - string output = ""; - string error = ""; - - try { - Process.spawn_command_line_sync("avconv -i \"%s\" -vf cropdetect=30 -ss 5 -t 5 -f matroska -an -y /dev/null".printf(filePath), out output, out error); - } - catch(Error e){ - log_error (e.message); - } - - int w=0,h=0,x=10000,y=10000; - int num=0; - string key,val; - string[] arr; - - foreach (string line in error.split ("\n")){ - if (line == null) { continue; } - if (line.index_of ("crop=") == -1) { continue; } - - foreach (string part in line.split (" ")){ - if (part == null || part.length == 0) { continue; } - - arr = part.split (":"); - if (arr.length != 2) { continue; } - - key = arr[0].strip (); - val = arr[1].strip (); - - switch (key){ - case "x": - num = int.parse (arr[1]); - if (num < x) { x = num; } - break; - case "y": - num = int.parse (arr[1]); - if (num < y) { y = num; } - break; - case "w": - num = int.parse (arr[1]); - if (num > w) { w = num; } - break; - case "h": - num = int.parse (arr[1]); - if (num > h) { h = num; } - break; - } - } - } - - if (x == 10000 || y == 10000) - return "%i:%i:%i:%i".printf(0,0,0,0); - else - return "%i:%i:%i:%i".printf(w,h,x,y); - } - - public string get_mediainfo (string filePath){ - - /* Returns the multimedia properties of an audio/video file using MediaInfo */ - - string output = ""; - - try { - Process.spawn_command_line_sync("mediainfo \"%s\"".printf(filePath), out output); - } - catch(Error e){ - log_error (e.message); - } - - return output; - } - - - -} - -namespace TeeJee.System{ - - using TeeJee.ProcessManagement; - using TeeJee.Logging; - - public double get_system_uptime_seconds(){ - - /* Returns the system up-time in seconds */ - - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - try{ - cmd = "cat /proc/uptime"; - Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); - string uptime = std_out.split(" ")[0]; - double secs = double.parse(uptime); - return secs; - } - catch(Error e){ - log_error (e.message); - return 0; - } - } - - public string get_desktop_name(){ - - /* Return the names of the current Desktop environment */ - - int pid = -1; - - pid = get_pid_by_name("cinnamon"); - if (pid > 0){ - return "Cinnamon"; - } - - pid = get_pid_by_name("xfdesktop"); - if (pid > 0){ - return "Xfce"; - } - - pid = get_pid_by_name("lxsession"); - if (pid > 0){ - return "LXDE"; - } - - pid = get_pid_by_name("gnome-shell"); - if (pid > 0){ - return "Gnome"; - } - - pid = get_pid_by_name("wingpanel"); - if (pid > 0){ - return "Elementary"; - } - - pid = get_pid_by_name("unity-panel-service"); - if (pid > 0){ - return "Unity"; - } - - pid = get_pid_by_name("plasma-desktop"); - if (pid > 0){ - return "KDE"; - } - - return "Unknown"; - } - - public bool check_internet_connectivity(){ - int exit_code = -1; - string std_err; - string std_out; - - try { - string cmd = "ping -c 1 google.com"; - Process.spawn_command_line_sync(cmd, out std_out, out std_err, out exit_code); - } - catch (Error e){ - log_error (e.message); - } - - return (exit_code == 0); - } - - public bool shutdown (){ - - /* Shutdown the system immediately */ - - try{ - string[] argv = { "shutdown", "-h", "now" }; - Pid procId; - Process.spawn_async(null, argv, null, SpawnFlags.SEARCH_PATH, null, out procId); - return true; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - public bool xdg_open (string file){ - string path; - path = get_cmd_path ("xdg-open"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("xdg-open \"" + file + "\""); - } - return false; - } - - public bool exo_open_folder (string dir_path, bool xdg_open_try_first = true){ - - /* Tries to open the given directory in a file manager */ - - /* - xdg-open is a desktop-independent tool for configuring the default applications of a user. - Inside a desktop environment (e.g. GNOME, KDE, Xfce), xdg-open simply passes the arguments - to that desktop environment's file-opener application (gvfs-open, kde-open, exo-open, respectively). - We will first try using xdg-open and then check for specific file managers if it fails. - */ - - string path; - - if (xdg_open_try_first){ - //try using xdg-open - path = get_cmd_path ("xdg-open"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("xdg-open \"" + dir_path + "\""); - } - } - - path = get_cmd_path ("nemo"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("nemo \"" + dir_path + "\""); - } - - path = get_cmd_path ("nautilus"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("nautilus \"" + dir_path + "\""); - } - - path = get_cmd_path ("thunar"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("thunar \"" + dir_path + "\""); - } - - path = get_cmd_path ("pantheon-files"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("pantheon-files \"" + dir_path + "\""); - } - - path = get_cmd_path ("marlin"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("marlin \"" + dir_path + "\""); - } - - if (xdg_open_try_first == false){ - //try using xdg-open - path = get_cmd_path ("xdg-open"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("xdg-open \"" + dir_path + "\""); - } - } - - return false; - } - - public bool exo_open_textfile (string txt){ - - /* Tries to open the given text file in a text editor */ - - string path; - - path = get_cmd_path ("exo-open"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("exo-open \"" + txt + "\""); - } - - path = get_cmd_path ("gedit"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("gedit --new-document \"" + txt + "\""); - } - - return false; - } - - public bool exo_open_url (string url){ - - /* Tries to open the given text file in a text editor */ - - string path; - - path = get_cmd_path ("exo-open"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("exo-open \"" + url + "\""); - } - - path = get_cmd_path ("firefox"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("firefox \"" + url + "\""); - } - - path = get_cmd_path ("chromium-browser"); - if ((path != null)&&(path != "")){ - return execute_command_script_async ("chromium-browser \"" + url + "\""); - } - - return false; - } - - public GLib.Timer timer_start(){ - var timer = new GLib.Timer(); - timer.start(); - return timer; - } - - public ulong timer_elapsed(GLib.Timer timer){ - ulong microseconds; - double seconds; - seconds = timer.elapsed (out microseconds); - return microseconds; - } - - public void sleep(int milliseconds){ - Thread.usleep ((ulong) milliseconds * 1000); - } - - public string timer_elapsed_string(GLib.Timer timer, bool stop = true){ - ulong microseconds; - double seconds; - seconds = timer.elapsed (out microseconds); - if (stop){ - timer.stop(); - } - return "%.0f ms".printf((seconds * 1000 ) + microseconds/1000); - } - - public void timer_elapsed_print(GLib.Timer timer, bool stop = true){ - ulong microseconds; - double seconds; - seconds = timer.elapsed (out microseconds); - if (stop){ - timer.stop(); - } - log_msg("%s %lu\n".printf(seconds.to_string(), microseconds)); - } - - public bool crontab_remove(string search_string){ - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - cmd = "crontab -l | sed '/%s/d' | crontab -".printf(search_string); - ret_val = execute_command_script_sync(cmd, out std_out, out std_err); - - if (ret_val != 0){ - log_error(std_err); - return false; - } - else{ - return true; - } - } - - public bool crontab_add(string entry){ - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - try{ - string crontab = crontab_read(); - crontab += crontab.has_suffix("\n") ? "" : "\n"; - crontab += entry + "\n"; - - //remove empty lines - crontab = crontab.replace("\n\n","\n"); //remove empty lines in middle - crontab = crontab.has_prefix("\n") ? crontab[1:crontab.length] : crontab; //remove empty lines in beginning - - string temp_file = get_temp_file_path(); - write_file(temp_file, crontab); - - cmd = "crontab \"%s\"".printf(temp_file); - Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); - - if (ret_val != 0){ - log_error(std_err); - return false; - } - else{ - return true; - } - } - catch(Error e){ - log_error (e.message); - return false; - } - } - - public string crontab_read(){ - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - try { - cmd = "crontab -l"; - Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); - if (ret_val != 0){ - log_debug(_("Crontab is empty")); - return ""; - } - else{ - return std_out; - } - } - catch (Error e){ - log_error (e.message); - return ""; - } - } - - public string crontab_search(string search_string, bool use_regex_matching = false){ - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - try{ - Regex rex = null; - MatchInfo match; - if (use_regex_matching){ - rex = new Regex(search_string); - } - - cmd = "crontab -l"; - Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); - if (ret_val != 0){ - log_debug(_("Crontab is empty")); - } - else{ - foreach(string line in std_out.split("\n")){ - if (use_regex_matching && (rex != null)){ - if (rex.match (line, 0, out match)){ - return line.strip(); - } - } - else { - if (line.contains(search_string)){ - return line.strip(); - } - } - } - } - - return ""; - } - catch(Error e){ - log_error (e.message); - return ""; - } - } - - public bool check_if_path_is_mounted_on_tmpfs( - string path, bool show_msg, Gtk.Window? parent_window, bool exit_app) - { - int status = Posix.system("df --type=tmpfs '%s' > /dev/null 2>&1".printf(path)); - - if (status == 0){ - if (show_msg){ - string msg = _("/var/spool on your system is mounted in memory (tmpfs)!!\n\n/var/spool should never be mounted in tmpfs as the user's cron jobs are stored here along with other system files. If you have done this to reduce writes to your SSD, please undo it by editing your /etc/fstab file. This application will not work till this is corrected."); - - if (parent_window != null){ - gtk_messagebox("System Issue",msg,parent_window,true); - } - else{ - log_error(msg); - } - } - if (exit_app){ - exit(1); - } - } - - return (status == 0); - } - - public const string RC_LOCAL_FILE = "/etc/rc.local"; - - //admin access needed - public bool rc_local_add(string line_to_add){ - try { - if (!file_exists(RC_LOCAL_FILE)) { - log_error ("File not found: %s".printf(RC_LOCAL_FILE)); - return false; - } - - var txt = read_file(RC_LOCAL_FILE); - var lines = new Gee.ArrayList(); - foreach (string line in txt.split("\n")) { - lines.add(line); - } - - Regex rex_exit_line = new Regex("""^[ \t]*exit[ \t\(]*0[ \t\)]*$"""); - MatchInfo match; - - for (int i = 0; i < lines.size; i++) { - string line = lines[i]; - if (rex_exit_line.match (line, 0, out match)) { - lines.insert(i, line_to_add); - break; - } - } - - txt = ""; - for (int i = 0; i < lines.size; i++) { - string line = lines[i]; - bool is_last_line = (i == lines.size - 1); - if ((line.length == 0) && is_last_line) { - continue; - } - txt += line + "\n"; - } - write_file(RC_LOCAL_FILE, txt); - Posix.system("chmod a+x %s".printf(RC_LOCAL_FILE)); - - return true; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - //admin access needed - public bool rc_local_remove(string line_to_remove){ - try { - if (!file_exists(RC_LOCAL_FILE)) { - log_error ("File not found: %s".printf(RC_LOCAL_FILE)); - return false; - } - - var txt = read_file(RC_LOCAL_FILE); - var lines = new Gee.ArrayList(); - foreach (string line in txt.split("\n")) { - lines.add(line); - } - - for (int i = 0; i < lines.size; i++) { - string line = lines[i]; - if (line == line_to_remove) { - lines.remove(line); - break; - } - } - - txt = ""; - for (int i = 0; i < lines.size; i++) { - string line = lines[i]; - bool is_last_line = (i == lines.size - 1); - if ((line.length == 0) && is_last_line) { - continue; - } - txt += line + "\n"; - } - write_file(RC_LOCAL_FILE, txt); - Posix.system("chmod a+x %s".printf(RC_LOCAL_FILE)); - - return true; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - private DateTime dt_last_notification = null; - private const int NOTIFICATION_INTERVAL = 3; - - public int notify_send (string title, string message, int durationMillis, string urgency, string dialog_type = "info"){ - - /* Displays notification bubble on the desktop */ - - int retVal = 0; - - switch (dialog_type){ - case "error": - case "info": - case "warning": - //ok - break; - default: - dialog_type = "info"; - break; - } - - long seconds = 9999; - if (dt_last_notification != null){ - DateTime dt_end = new DateTime.now_local(); - TimeSpan elapsed = dt_end.difference(dt_last_notification); - seconds = (long)(elapsed * 1.0 / TimeSpan.SECOND); - } - - if (seconds > NOTIFICATION_INTERVAL){ - string s = "notify-send -t %d -u %s -i %s \"%s\" \"%s\"".printf(durationMillis, urgency, "gtk-dialog-" + dialog_type, title, message); - retVal = execute_command_sync (s); - dt_last_notification = new DateTime.now_local(); - } - - return retVal; - } - - public bool set_directory_ownership(string dir_name, string login_name){ - try { - string cmd = "chown %s -R %s".printf(login_name, dir_name); - int exit_code; - Process.spawn_command_line_sync(cmd, null, null, out exit_code); - - if (exit_code == 0){ - //log_msg(_("Ownership changed to '%s' for files in directory '%s'").printf(login_name, dir_name)); - return true; - } - else{ - log_error(_("Failed to set ownership") + ": %s, %s".printf(login_name, dir_name)); - return false; - } - } - catch (Error e){ - log_error (e.message); - return false; - } - } - - public class ProcStats{ - public double user = 0; - public double nice = 0; - public double system = 0; - public double idle = 0; - public double iowait = 0; - - public double user_delta = 0; - public double nice_delta = 0; - public double system_delta = 0; - public double idle_delta = 0; - public double iowait_delta = 0; - - public double usage_percent = 0; - - public static ProcStats stat_prev = null; - - public ProcStats(string line){ - string[] arr = line.split(" "); - int col = 0; - if (arr[col++] == "cpu"){ - if (arr[col].length == 0){ col++; }; - - user = double.parse(arr[col++]); - nice = double.parse(arr[col++]); - system = double.parse(arr[col++]); - idle = double.parse(arr[col++]); - iowait = double.parse(arr[col++]); - - if (ProcStats.stat_prev != null){ - user_delta = user - ProcStats.stat_prev.user; - nice_delta = nice - ProcStats.stat_prev.nice; - system_delta = system - ProcStats.stat_prev.system; - idle_delta = idle - ProcStats.stat_prev.idle; - iowait_delta = iowait - ProcStats.stat_prev.iowait; - - usage_percent = (user_delta + nice_delta + system_delta) * 100 / (user_delta + nice_delta + system_delta + idle_delta); - } - else{ - usage_percent = 0; - - } - - ProcStats.stat_prev = this; - } - } - - //returns 0 when it is called first time - public static double get_cpu_usage(){ - string txt = read_file("/proc/stat"); - foreach(string line in txt.split("\n")){ - string[] arr = line.split(" "); - if (arr[0] == "cpu"){ - ProcStats stat = new ProcStats(line); - return stat.usage_percent; - } - } - return 0; - } - } -} - -namespace TeeJee.Misc { - - /* Various utility functions */ - - using Gtk; - using TeeJee.Logging; - using TeeJee.FileSystem; - using TeeJee.ProcessManagement; - - public class DistInfo : GLib.Object{ - - /* Class for storing information about linux distribution */ - - public string dist_id = ""; - public string description = ""; - public string release = ""; - public string codename = ""; - - public DistInfo(){ - dist_id = ""; - description = ""; - release = ""; - codename = ""; - } - - public string full_name(){ - if (dist_id == ""){ - return ""; - } - else{ - string val = ""; - val += dist_id; - val += (release.length > 0) ? " " + release : ""; - val += (codename.length > 0) ? " (" + codename + ")" : ""; - return val; - } - } - - public static DistInfo get_dist_info(string root_path){ - - /* Returns information about the Linux distribution - * installed at the given root path */ - - DistInfo info = new DistInfo(); - - string dist_file = root_path + "/etc/lsb-release"; - var f = File.new_for_path(dist_file); - if (f.query_exists()){ - - /* - DISTRIB_ID=Ubuntu - DISTRIB_RELEASE=13.04 - DISTRIB_CODENAME=raring - DISTRIB_DESCRIPTION="Ubuntu 13.04" - */ - - foreach(string line in read_file(dist_file).split("\n")){ - - if (line.split("=").length != 2){ continue; } - - string key = line.split("=")[0].strip(); - string val = line.split("=")[1].strip(); - - if (val.has_prefix("\"")){ - val = val[1:val.length]; - } - - if (val.has_suffix("\"")){ - val = val[0:val.length-1]; - } - - switch (key){ - case "DISTRIB_ID": - info.dist_id = val; - break; - case "DISTRIB_RELEASE": - info.release = val; - break; - case "DISTRIB_CODENAME": - info.codename = val; - break; - case "DISTRIB_DESCRIPTION": - info.description = val; - break; - } - } - } - else{ - - dist_file = root_path + "/etc/os-release"; - f = File.new_for_path(dist_file); - if (f.query_exists()){ - - /* - NAME="Ubuntu" - VERSION="13.04, Raring Ringtail" - ID=ubuntu - ID_LIKE=debian - PRETTY_NAME="Ubuntu 13.04" - VERSION_ID="13.04" - HOME_URL="http://www.ubuntu.com/" - SUPPORT_URL="http://help.ubuntu.com/" - BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" - */ - - foreach(string line in read_file(dist_file).split("\n")){ - - if (line.split("=").length != 2){ continue; } - - string key = line.split("=")[0].strip(); - string val = line.split("=")[1].strip(); - - switch (key){ - case "ID": - info.dist_id = val; - break; - case "VERSION_ID": - info.release = val; - break; - //case "DISTRIB_CODENAME": - //info.codename = val; - //break; - case "PRETTY_NAME": - info.description = val; - break; - } - } - } - } - - return info; - } - - } - - public static Gdk.RGBA hex_to_rgba (string hex_color){ - - /* Converts the color in hex to RGBA */ - - string hex = hex_color.strip().down(); - if (hex.has_prefix("#") == false){ - hex = "#" + hex; - } - - Gdk.RGBA color = Gdk.RGBA(); - if(color.parse(hex) == false){ - color.parse("#000000"); - } - color.alpha = 255; - - return color; - } - - public static string rgba_to_hex (Gdk.RGBA color, bool alpha = false, bool prefix_hash = true){ - - /* Converts the color in RGBA to hex */ - - string hex = ""; - - if (alpha){ - hex = "%02x%02x%02x%02x".printf((uint)(Math.round(color.red*255)), - (uint)(Math.round(color.green*255)), - (uint)(Math.round(color.blue*255)), - (uint)(Math.round(color.alpha*255))) - .up(); - } - else { - hex = "%02x%02x%02x".printf((uint)(Math.round(color.red*255)), - (uint)(Math.round(color.green*255)), - (uint)(Math.round(color.blue*255))) - .up(); - } - - if (prefix_hash){ - hex = "#" + hex; - } - - return hex; - } - - public string timestamp2 (){ - - /* Returns a numeric timestamp string */ - - return "%ld".printf((long) time_t ()); - } - - public string timestamp (){ - - /* Returns a formatted timestamp string */ - - Time t = Time.local (time_t ()); - return t.format ("%H:%M:%S"); - } - - public string timestamp3 (){ - - /* Returns a formatted timestamp string */ - - Time t = Time.local (time_t ()); - return t.format ("%Y-%d-%m_%H-%M-%S"); - } - - public string format_file_size (int64 size){ - - /* Format file size in MB */ - - return "%0.1f MB".printf (size / (1024.0 * 1024)); - } - - public string format_duration (long millis){ - - /* Converts time in milliseconds to format '00:00:00.0' */ - - double time = millis / 1000.0; // time in seconds - - double hr = Math.floor(time / (60.0 * 60)); - time = time - (hr * 60 * 60); - double min = Math.floor(time / 60.0); - time = time - (min * 60); - double sec = Math.floor(time); - - return "%02.0lf:%02.0lf:%02.0lf".printf (hr, min, sec); - } - - public double parse_time (string time){ - - /* Converts time in format '00:00:00.0' to milliseconds */ - - string[] arr = time.split (":"); - double millis = 0; - if (arr.length >= 3){ - millis += double.parse(arr[0]) * 60 * 60; - millis += double.parse(arr[1]) * 60; - millis += double.parse(arr[2]); - } - return millis; - } - - public string escape_html(string html){ - return html - .replace("&","&") - .replace("\"",""") - //.replace(" "," ") //pango markup throws an error with   - .replace("<","<") - .replace(">",">") - ; - } - - public string unescape_html(string html){ - return html - .replace("&","&") - .replace(""","\"") - //.replace(" "," ") //pango markup throws an error with   - .replace("<","<") - .replace(">",">") - ; - } -} diff -Nru aptik-battery-monitor-2.1/translate.sh aptik-battery-monitor-17.12/translate.sh --- aptik-battery-monitor-2.1/translate.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/translate.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -msginit -l or_IN -o oriya.po -i timeshift.pot - -echo "Finished" -read dummy diff -Nru aptik-battery-monitor-2.1/upload.sh aptik-battery-monitor-17.12/upload.sh --- aptik-battery-monitor-2.1/upload.sh 2015-12-14 11:48:00.000000000 +0000 +++ aptik-battery-monitor-17.12/upload.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -#!/bin/bash - -backup=`pwd` -DIR="$( cd "$( dirname "$0" )" && pwd )" -cd "$DIR" - -sh ./build-source.sh -dput ppa:teejee2008/ppa ../builds/aptik-battery-monitor*.changes - -cd "$backup"