Remove some unused code and functions

This commit is contained in:
Tony George 2022-10-15 12:59:13 +05:30 committed by Michael Webster
parent 12791a98ec
commit b481c2e532
13 changed files with 23 additions and 767 deletions

4
src/Core/Main.vala Normal file → Executable file
View File

@ -483,7 +483,7 @@ public class Main : GLib.Object{
private void detect_encrypted_dirs(){
current_system_users = SystemUser.read_users_from_file("/etc/passwd","","");
current_system_users = SystemUser.read_users_from_file("/etc/passwd");
string txt = "";
users_with_encrypted_home = "";
@ -3750,7 +3750,7 @@ public class Main : GLib.Object{
}
if (Device.unmount(mnt_btrfs)){
if (dir_exists(mnt_btrfs) && (dir_count(mnt_btrfs) == 0)){
if (dir_exists(mnt_btrfs) && dir_is_empty(mnt_btrfs)){
dir_delete(mnt_btrfs);
log_debug(_("Removed mount directory: '%s'").printf(mnt_btrfs));
}

2
src/Gtk/AppGtk.vala Normal file → Executable file
View File

@ -51,7 +51,7 @@ public class AppGtk : GLib.Object {
public static int main (string[] args) {
set_locale();
Gtk.init(ref args);
GTK_INITIALIZED = true;

27
src/Utility/AsyncTask.vala Normal file → Executable file
View File

@ -337,35 +337,8 @@ public abstract class AsyncTask : GLib.Object{
// public actions --------------
public void pause() {
Pid sub_child_pid;
foreach (long pid in get_process_children(child_pid)) {
sub_child_pid = (Pid) pid;
process_pause(sub_child_pid);
}
status = AppStatus.PAUSED;
}
public void resume() {
Pid sub_child_pid;
foreach (long pid in get_process_children(child_pid)) {
sub_child_pid = (Pid) pid;
process_resume(sub_child_pid);
}
status = AppStatus.RUNNING;
}
public void stop(AppStatus status_to_update = AppStatus.CANCELLED) {
// we need to un-freeze the processes before we kill them
if (status == AppStatus.PAUSED) {
resume();
}
status = status_to_update;
process_quit(child_pid);

View File

@ -2134,10 +2134,3 @@ public class Device : GLib.Object{
log_debug("");
}
}

View File

@ -266,7 +266,6 @@ public class FsTabEntry : GLib.Object{
return dev_fstab;
}
public void append_option(string option){
if (!options.contains(option)){

143
src/Utility/GtkHelper.vala Normal file → Executable file
View File

@ -179,100 +179,6 @@ namespace TeeJee.GtkHelper{
return val;
}
public GLib.Object gtk_combobox_get_selected_object (ComboBox combo, int index, GLib.Object default_value){
/* Convenience function to get combobox value */
if ((combo.model == null) || (combo.active < 0)) { return default_value; }
TreeIter iter;
GLib.Object val = null;
combo.get_active_iter (out iter);
TreeModel model = (TreeModel) combo.model;
model.get(iter, index, out val);
return val;
}
public int gtk_combobox_get_value_enum (ComboBox combo, int index, int default_value){
/* Convenience function to get combobox value */
if ((combo.model == null) || (combo.active < 0)) { return default_value; }
TreeIter iter;
int val;
combo.get_active_iter (out iter);
TreeModel model = (TreeModel) combo.model;
model.get(iter, index, out val);
return val;
}
// styles ----------------
public static int CSS_AUTO_CLASS_INDEX = 0;
public static void gtk_apply_css(Gtk.Widget[] widgets, string css_style){
var css_provider = new Gtk.CssProvider();
var css = ".style_%d { %s }".printf(++CSS_AUTO_CLASS_INDEX, css_style);
try {
css_provider.load_from_data(css,-1);
} catch (GLib.Error e) {
warning(e.message);
}
foreach(var widget in widgets){
widget.get_style_context().add_provider(
css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
widget.get_style_context().add_class("style_%d".printf(CSS_AUTO_CLASS_INDEX));
}
}
// treeview -----------------
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;
}
public void gtk_treeview_redraw(Gtk.TreeView treeview){
var model = treeview.model;
treeview.model = null;
treeview.model = model;
}
// misc
public bool gtk_container_has_child(Gtk.Container container, Gtk.Widget widget){
foreach(var child in container.get_children()){
if (child == widget){
return true;
}
}
return false;
}
// file chooser ----------------
public Gtk.FileFilter create_file_filter(string group_name, string[] patterns) {
var filter = new Gtk.FileFilter ();
filter.set_filter_name(group_name);
foreach(string pattern in patterns) {
filter.add_pattern (pattern);
}
return filter;
}
// utility ------------------
// add_notebook
@ -338,48 +244,6 @@ namespace TeeJee.GtkHelper{
return col;
}
// add_column_icon_and_text
private Gtk.TreeViewColumn add_column_icon_and_text(Gtk.TreeView treeview, string title,
out Gtk.CellRendererPixbuf cell_pix, out Gtk.CellRendererText cell_text){
// TreeViewColumn
var col = new Gtk.TreeViewColumn();
col.title = title;
cell_pix = new Gtk.CellRendererPixbuf();
cell_pix.xpad = 2;
col.pack_start (cell_pix, false);
cell_text = new Gtk.CellRendererText();
cell_text.xalign = (float) 0.0;
col.pack_start (cell_text, false);
treeview.append_column(col);
return col;
}
// add_column_radio_and_text
private Gtk.TreeViewColumn add_column_radio_and_text(Gtk.TreeView treeview, string title,
out Gtk.CellRendererToggle cell_radio, out Gtk.CellRendererText cell_text){
// TreeViewColumn
var col = new Gtk.TreeViewColumn();
col.title = title;
cell_radio = new Gtk.CellRendererToggle();
cell_radio.xpad = 2;
cell_radio.radio = true;
cell_radio.activatable = true;
col.pack_start (cell_radio, false);
cell_text = new Gtk.CellRendererText();
cell_text.xalign = (float) 0.0;
col.pack_start (cell_text, false);
treeview.append_column(col);
return col;
}
// add_column_icon_radio_text
private Gtk.TreeViewColumn add_column_icon_radio_text(Gtk.TreeView treeview, string title,
out Gtk.CellRendererPixbuf cell_pix, out Gtk.CellRendererToggle cell_radio, out Gtk.CellRendererText cell_text){
@ -477,13 +341,6 @@ namespace TeeJee.GtkHelper{
return label;
}
// add_label_subnote
private Gtk.Label add_label_subnote(Gtk.Box box, string text){
var label = add_label(box, text, false, true);
return label;
}
// add_radio
private Gtk.RadioButton add_radio(Gtk.Box box, string text, Gtk.RadioButton? another_radio_in_group){

34
src/Utility/IconManager.vala Normal file → Executable file
View File

@ -64,9 +64,6 @@ public class IconManager : GLib.Object {
search_paths = new Gee.ArrayList<string>();
string binpath = file_resolve_executable_path(args[0]);
log_debug("bin_path: %s".printf(binpath));
// check absolute location
string path = "/usr/share/%s/images".printf(app_name);
if (dir_exists(path)){
@ -74,17 +71,6 @@ public class IconManager : GLib.Object {
log_debug("found images directory: %s".printf(path));
}
// check relative location
string base_path = file_parent(file_parent(file_parent(binpath)));
if (base_path != "/"){
log_debug("base_path: %s".printf(base_path));
path = path_combine(base_path, path);
if (dir_exists(path)){
search_paths.add(path);
log_debug("found images directory: %s".printf(path));
}
}
refresh_icon_theme();
}
@ -181,26 +167,6 @@ public class IconManager : GLib.Object {
return pixbuf;
}
public static Gtk.Image? lookup_animation(string gif_name){
if (gif_name.length == 0){ return null; }
foreach(string search_path in search_paths){
foreach(string ext in new string[] { ".gif" }){
string img_file = path_combine(search_path, gif_name + ext);
if (file_exists(img_file)){
return new Gtk.Image.from_file(img_file);
}
}
}
return null;
}
public static Gdk.Pixbuf? add_emblem (Gdk.Pixbuf pixbuf, string icon_name, int emblem_size, bool emblem_symbolic, Gtk.CornerType corner_type) {
if (icon_name.length == 0){ return pixbuf; }

88
src/Utility/SystemUser.vala Normal file → Executable file
View File

@ -42,17 +42,6 @@ public class SystemUser : GLib.Object {
public string phone_home = "";
public string other_info = "";
//public string
public string shadow_line = "";
public string pwd_hash = "";
public string pwd_last_changed = "";
public string pwd_age_min = "";
public string pwd_age_max = "";
public string pwd_warning_period = "";
public string pwd_inactivity_period = "";
public string pwd_expiraton_date = "";
public string reserved_field = "";
public bool has_encrypted_home = false;
public bool has_encrypted_private_dirs = false;
public Gee.ArrayList<string> encrypted_dirs = new Gee.ArrayList<string>();
@ -66,14 +55,9 @@ public class SystemUser : GLib.Object {
this.name = name;
}
public static void query_users(bool no_passwords = true){
public static void query_users(){
if (no_passwords){
all_users = read_users_from_file("/etc/passwd","","");
}
else{
all_users = read_users_from_file("/etc/passwd","/etc/shadow","");
}
all_users = read_users_from_file("/etc/passwd");
}
public static Gee.ArrayList<SystemUser> all_users_sorted {
@ -87,15 +71,7 @@ public class SystemUser : GLib.Object {
}
}
public bool is_installed{
get {
return SystemUser.all_users.has_key(name);
}
}
public static Gee.HashMap<string,SystemUser> read_users_from_file(
string passwd_file, string shadow_file, string password){
public static Gee.HashMap<string,SystemUser> read_users_from_file(string passwd_file){
var list = new Gee.HashMap<string,SystemUser>();
@ -117,25 +93,6 @@ public class SystemUser : GLib.Object {
}
}
if (shadow_file.length == 0){
return list;
}
// read 'shadow' file ---------------------------------
txt = file_read(shadow_file);
if (txt.length == 0){
return list;
}
foreach(string line in txt.split("\n")){
if ((line == null) || (line.length == 0)){
continue;
}
parse_line_shadow(line, list);
}
return list;
}
@ -186,45 +143,6 @@ public class SystemUser : GLib.Object {
return user;
}
private static SystemUser? parse_line_shadow(string line, Gee.HashMap<string,SystemUser> list){
if ((line == null) || (line.length == 0)){
return null;
}
SystemUser user = null;
//root:$1$Etg2ExUZ$F9NTP7omafhKIlqaBMqng1:15651:0:99999:7:::
//<username>:$<hash-algo>$<salt>$<hash>:<last-changed>:<change-interval-min>:<change-interval-max>:<change-warning-interval>:<disable-expired-account-after-days>:<days-since-account-disbaled>:<not-used>
string[] fields = line.split(":");
if (fields.length == 9){
string user_name = fields[0].strip();
if (list.has_key(user_name)){
user = list[user_name];
user.shadow_line = line;
user.pwd_hash = fields[1].strip();
user.pwd_last_changed = fields[2].strip();
user.pwd_age_min = fields[3].strip();
user.pwd_age_max = fields[4].strip();
user.pwd_warning_period = fields[5].strip();
user.pwd_inactivity_period = fields[6].strip();
user.pwd_expiraton_date = fields[7].strip();
user.reserved_field = fields[8].strip();
return user;
}
else{
log_error("user in file 'shadow' does not exist in file 'passwd'" + ": %s".printf(user_name));
return null;
}
}
else{
log_error("'shadow' file contains a record with non-standard fields" + ": %d".printf(fields.length));
return null;
}
}
public void check_encrypted_dirs() {
// check encrypted home ------------------------------

121
src/Utility/TeeJee.FileSystem.vala Normal file → Executable file
View File

@ -65,26 +65,12 @@ namespace TeeJee.FileSystem{
// file helpers -----------------------------
public bool file_or_dir_exists(string item_path){
/* check if item exists on disk*/
var item = File.parse_name(item_path);
return item.query_exists();
}
public bool file_exists (string file_path){
/* Check if file exists */
return (FileUtils.test(file_path, GLib.FileTest.EXISTS)
&& !FileUtils.test(file_path, GLib.FileTest.IS_DIR));
}
public bool file_exists_regular (string file_path){
/* Check if file exists */
return ( FileUtils.test(file_path, GLib.FileTest.EXISTS)
&& FileUtils.test(file_path, GLib.FileTest.IS_REGULAR));
}
public bool file_delete(string file_path){
/* Check and delete file */
@ -222,18 +208,6 @@ namespace TeeJee.FileSystem{
return file_exists(dst_file);
}
public bool file_gunzip (string src_file){
string dst_file = src_file;
file_delete(dst_file);
string cmd = "gunzip '%s'".printf(escape_single_quote(src_file));
string std_out, std_err;
exec_sync(cmd, out std_out, out std_err);
return file_exists(dst_file);
}
public string file_resolve_executable_path(string file_path){
if (file_path.has_prefix("/")){
@ -360,51 +334,6 @@ namespace TeeJee.FileSystem{
}
}
public bool filesystem_supports_hardlinks(string path, out bool is_readonly){
bool supports_hardlinks = false;
is_readonly = false;
var test_file = path_combine(path, random_string() + "~");
if (file_write(test_file,"")){
var test_file2 = path_combine(path, random_string() + "~");
var cmd = "ln '%s' '%s'".printf(
escape_single_quote(test_file),
escape_single_quote(test_file2));
log_debug(cmd);
int status = exec_sync(cmd);
cmd = "stat --printf '%%h' '%s'".printf(
escape_single_quote(test_file));
log_debug(cmd);
string std_out, std_err;
status = exec_sync(cmd, out std_out, out std_err);
log_debug("stdout: %s".printf(std_out));
int64 count = 0;
if (int64.try_parse(std_out, out count)){
if (count > 1){
supports_hardlinks = true;
}
}
file_delete(test_file2); // delete if exists
file_delete(test_file);
}
else{
is_readonly = true;
}
return supports_hardlinks;
}
public Gee.ArrayList<string> dir_list_names(string path){
var list = new Gee.ArrayList<string>();
@ -438,42 +367,6 @@ namespace TeeJee.FileSystem{
return (status == 0);
}
// dir info -------------------
// dep: find wc TODO: rewrite
public long dir_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(escape_single_quote(path));
ret_val = exec_script_sync(cmd, out std_out, out std_err);
return long.parse(std_out);
}
// dep: du
public long dir_size(string path){
/* Returns size of files and directories in KB*/
string cmd = "du -s -b '%s'".printf(escape_single_quote(path));
string std_out, std_err;
exec_sync(cmd, out std_out, out std_err);
return long.parse(std_out.split("\t")[0]);
}
// dep: du
public long dir_size_kb(string path){
/* Returns size of files and directories in KB*/
return (long)(dir_size(path) / 1024.0);
}
// misc --------------------
public string format_file_size (
@ -531,21 +424,9 @@ namespace TeeJee.FileSystem{
}
// dep: chmod
public int chmod (string file, string permission){
public int chmod(string file, string permission){
string cmd = "chmod %s '%s'".printf(permission, escape_single_quote(file));
return exec_sync (cmd, null, null);
}
public int rsync(string sourceDirectory, string destDirectory, bool updateExisting, bool deleteExtra){
/* Sync files with rsync */
string cmd = "rsync -avh";
cmd += updateExisting ? "" : " --ignore-existing";
cmd += deleteExtra ? " --delete" : "";
cmd += " '%s'".printf(escape_single_quote(sourceDirectory) + "//");
cmd += " '%s'".printf(escape_single_quote(destDirectory));
return exec_sync (cmd, null, null);
}
}

31
src/Utility/TeeJee.Json.vala Normal file → Executable file
View File

@ -40,17 +40,6 @@ namespace TeeJee.JsonHelper{
}
}
public double json_get_double(Json.Object jobj, string member, double def_value){
var text = json_get_string(jobj, member, def_value.to_string());
double double_value;
if (double.try_parse(text, out double_value)){
return double_value;
}
else{
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));
@ -80,24 +69,4 @@ namespace TeeJee.JsonHelper{
return def_value;
}
}
public Gee.ArrayList<string> json_get_array(
Json.Object jobj,
string member,
Gee.ArrayList<string> def_value){
if (jobj.has_member(member)){
var jarray = jobj.get_array_member(member);
var list = new Gee.ArrayList<string>();
foreach(var node in jarray.get_elements()){
list.add(node.get_string());
}
return list;
}
else{
log_debug ("Member not found in JSON object: " + member);
return def_value;
}
}
}

149
src/Utility/TeeJee.Misc.vala Normal file → Executable file
View File

@ -75,14 +75,6 @@ namespace TeeJee.Misc {
// string formatting -------------------------------------------------
public string format_date(DateTime date){
return date.format ("%Y-%m-%d %H:%M");
}
public string format_date_12_hour(DateTime date){
return date.format ("%Y-%m-%d %I:%M %p");
}
public string format_duration (long millis){
/* Converts time in milliseconds to format '00:00:00.0' */
@ -98,134 +90,13 @@ namespace TeeJee.Misc {
return "%02.0lf:%02.0lf:%02.0lf".printf (hr, min, sec);
}
public string format_time_left(int64 millis){
double mins = (millis * 1.0) / 60000;
double secs = ((millis * 1.0) % 60000) / 1000;
string txt = "";
if (mins >= 1){
txt += "%.0fm ".printf(mins);
}
txt += "%.0fs".printf(secs);
return txt;
}
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 string_replace(string str, string search, string replacement, int count = -1){
string[] arr = str.split(search);
string new_txt = "";
bool first = true;
foreach(string part in arr){
if (first){
new_txt += part;
}
else{
if (count == 0){
new_txt += search;
new_txt += part;
}
else{
new_txt += replacement;
new_txt += part;
count--;
}
}
first = false;
}
return new_txt;
}
public string escape_html(string html){
return GLib.Markup.escape_text(html);
}
public string unescape_html(string html){
return html
.replace("&amp;","&")
.replace("&quot;","\"")
//.replace("&nbsp;"," ") //pango markup throws an error with &nbsp;
.replace("&lt;","<")
.replace("&gt;",">")
;
}
public string uri_encode(string path, bool encode_forward_slash){
string uri = Uri.escape_string(path);
if (!encode_forward_slash){
uri = uri.replace("%2F","/");
}
return uri;
}
public string uri_decode(string path){
return Uri.unescape_string(path);
}
public DateTime datetime_from_string (string date_time_string){
/* Converts date time string to DateTime
*
* Supported inputs:
* 'yyyy-MM-dd'
* 'yyyy-MM-dd HH'
* 'yyyy-MM-dd HH:mm'
* 'yyyy-MM-dd HH:mm:ss'
* */
string[] arr = date_time_string.replace(":"," ").replace("-"," ").strip().split(" ");
int year = (arr.length >= 3) ? int.parse(arr[0]) : 0;
int month = (arr.length >= 3) ? int.parse(arr[1]) : 0;
int day = (arr.length >= 3) ? int.parse(arr[2]) : 0;
int hour = (arr.length >= 4) ? int.parse(arr[3]) : 0;
int min = (arr.length >= 5) ? int.parse(arr[4]) : 0;
int sec = (arr.length >= 6) ? int.parse(arr[5]) : 0;
return new DateTime.utc(year,month,day,hour,min,sec);
}
public string break_string_by_word(string input_text){
string text = "";
string line = "";
foreach(string part in input_text.split(" ")){
line += part + " ";
if (line.length > 50){
text += line.strip() + "\n";
line = "";
}
}
if (line.length > 0){
text += line;
}
if (text.has_suffix("\n")){
text = text[0:text.length-1].strip();
}
return text;
}
public string[] array_concat(string[] a, string[] b){
string[] c = {};
foreach(string str in a){ c += str; }
foreach(string str in b){ c += str; }
return c;
}
public string random_string(int length = 8, string charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"){
string random = "";
for(int i=0;i<length;i++){
@ -236,13 +107,19 @@ namespace TeeJee.Misc {
return random;
}
internal string regex_replace(string expression, string text, string replacement){
public bool is_numeric(string text){
for (int i = 0; i < text.length; i++){
if (!text[i].isdigit()){
return false;
}
try
{
Regex? regex = null;
regex = new Regex(expression, 0);
return regex.replace(text, text.length, 0, replacement);
}
catch (Error e)
{
log_error (e.message);
return text;
}
return true;
}
}

112
src/Utility/TeeJee.Process.vala Normal file → Executable file
View File

@ -53,12 +53,6 @@ namespace TeeJee.ProcessHelper{
//log_debug("TEMP_DIR=" + TEMP_DIR);
}
public string create_temp_subdir(){
var temp = "%s/%s".printf(TEMP_DIR, random_string());
dir_create(temp);
return temp;
}
public int exec_sync (string cmd, out string? std_out = null, out string? std_err = null){
/* Executes single command synchronously.
@ -249,10 +243,6 @@ namespace TeeJee.ProcessHelper{
return TEMP_DIR + "/" + timestamp_numeric() + (new Rand()).next_int().to_string();
}
public void exec_process_new_session(string command){
exec_script_async("setsid %s &".printf(command));
}
// find process -------------------------------
// dep: which
@ -300,50 +290,6 @@ namespace TeeJee.ProcessHelper{
return -1;
}
public int get_pid_by_command(string cmdline){
/* Searches for process using the command line used to start the process.
* Returns the process id if found.
* */
try {
FileEnumerator enumerator;
FileInfo info;
File file = File.parse_name ("/proc");
enumerator = file.enumerate_children ("standard::name", 0);
while ((info = enumerator.next_file()) != null) {
try {
string io_stat_file_path = "/proc/%s/cmdline".printf(info.get_name());
var io_stat_file = File.new_for_path(io_stat_file_path);
if (file.query_exists()){
var dis = new DataInputStream (io_stat_file.read());
string line;
string text = "";
size_t length;
while((line = dis.read_until ("\0", out length)) != null){
text += " " + line;
}
if ((text != null) && text.contains(cmdline)){
return int.parse(info.get_name());
}
} //stream closed
}
catch(Error e){
// do not log
// some processes cannot be accessed by non-admin user
}
}
}
catch(Error e){
log_error (e.message);
}
return -1;
}
// dep: ps TODO: Rewrite using /proc
public bool process_is_running(long pid){
@ -366,28 +312,6 @@ namespace TeeJee.ProcessHelper{
return (ret_val == 0);
}
// dep: pgrep TODO: Rewrite using /proc
public bool process_is_running_by_name(string proc_name){
/* Checks if given process is running */
string cmd = "";
string std_out;
string std_err;
int ret_val;
try{
cmd = "pgrep -f '%s'".printf(proc_name);
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);
}
// dep: ps TODO: Rewrite using /proc
public int[] get_process_children (Pid parent_pid){
@ -453,42 +377,6 @@ namespace TeeJee.ProcessHelper{
}
}
// dep: kill
public int process_pause (Pid procID){
/* Pause/Freeze a process */
return exec_sync ("kill -STOP %d".printf(procID), null, null);
}
// dep: kill
public int process_resume (Pid procID){
/* Resume/Un-freeze a process*/
return exec_sync ("kill -CONT %d".printf(procID), null, null);
}
// dep: ps TODO: Rewrite using /proc
public void process_quit_by_name(string cmd_name, string cmd_to_match, bool exact_match){
/* Kills a specific command */
string std_out, std_err;
exec_sync ("ps w -C '%s'".printf(cmd_name), out std_out, out std_err);
//use 'ps ew -C conky' for all users
string pid = "";
foreach(string line in std_out.split("\n")){
if ((exact_match && line.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 + "] ");
}
}
}
// process priority ---------------------------------------
public void process_set_priority (Pid procID, int prio){

71
src/Utility/TeeJee.System.vala Normal file → Executable file
View File

@ -151,82 +151,17 @@ namespace TeeJee.System{
return get_user_home(get_username_effective());
}
// application -----------------------------------------------
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 "";
}
}
// system ------------------------------------
// dep: cat TODO: rewrite
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;
}
string uptime = file_read("/proc/uptime").split(" ")[0];
double secs = double.parse(uptime);
return secs;
}
// internet helpers ----------------------
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 command_exists(string command){
string path = get_cmd_path(command);
return ((path != null) && (path.length > 0));
}
// open -----------------------------
public bool xdg_open (string file, string user = ""){