aboutsummaryrefslogtreecommitdiff
path: root/src/familiar-players-db.vala
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-12-07 14:18:28 +0000
committerConor Curran <conor.curran@canonical.com>2010-12-07 14:18:28 +0000
commit55b5ef4065d32cca71b745c8dc4790e1b71af0fd (patch)
tree3924e039f2eb72d08738c8017b667cffa37aa5ac /src/familiar-players-db.vala
parent4280f27f7b3f42a73c971664f0cd322780c2bff6 (diff)
downloadayatana-indicator-sound-55b5ef4065d32cca71b745c8dc4790e1b71af0fd.tar.gz
ayatana-indicator-sound-55b5ef4065d32cca71b745c8dc4790e1b71af0fd.tar.bz2
ayatana-indicator-sound-55b5ef4065d32cca71b745c8dc4790e1b71af0fd.zip
tabs to spaces tab width 2
Diffstat (limited to 'src/familiar-players-db.vala')
-rw-r--r--src/familiar-players-db.vala240
1 files changed, 120 insertions, 120 deletions
diff --git a/src/familiar-players-db.vala b/src/familiar-players-db.vala
index 47ddc70..7012b5a 100644
--- a/src/familiar-players-db.vala
+++ b/src/familiar-players-db.vala
@@ -27,138 +27,138 @@ using GLib.Environment;
// TODO: more refactoring needed here
public class FamiliarPlayersDB : GLib.Object
{
- private const string GROUP_NAME = "Seen Database";
- private const string KEY_NAME = "DesktopFiles";
+ private const string GROUP_NAME = "Seen Database";
+ private const string KEY_NAME = "DesktopFiles";
private const string DEFAULT_APP_DESKTOP = "/usr/share/applications/banshee-1.desktop";
- private HashMap<string, bool> players_DB;
- private string file_name;
- private string dir_name;
- private KeyFile key_file;
- private uint write_id;
-
- public FamiliarPlayersDB()
- {
- this.write_id = 0;
- this.players_DB = new HashMap<string, bool>();
+ private HashMap<string, bool> players_DB;
+ private string file_name;
+ private string dir_name;
+ private KeyFile key_file;
+ private uint write_id;
+
+ public FamiliarPlayersDB()
+ {
+ this.write_id = 0;
+ this.players_DB = new HashMap<string, bool>();
if ( !create_key_file() ){
this.players_DB.set(DEFAULT_APP_DESKTOP, true);
this.write_db();
}
- this.dir_name = build_filename(get_user_cache_dir(), "indicators", "sound");
- this.file_name = build_filename(this.dir_name, "familiar-players-db.keyfile");
- if(create_key_file() && check_for_keys() && load_data_from_key_file()){
- debug("keyfiles in place and ready for action");
- }
- else{
- this.key_file = null;
- warning("FamiliarPlayersDB:: problems loading key file - can't go any further");
- }
- }
+ this.dir_name = build_filename(get_user_cache_dir(), "indicators", "sound");
+ this.file_name = build_filename(this.dir_name, "familiar-players-db.keyfile");
+ if(create_key_file() && check_for_keys() && load_data_from_key_file()){
+ debug("keyfiles in place and ready for action");
+ }
+ else{
+ this.key_file = null;
+ warning("FamiliarPlayersDB:: problems loading key file - can't go any further");
+ }
+ }
- private bool create_key_file(){
- bool result = false;
- if (test(this.file_name, GLib.FileTest.EXISTS)) {
- this.key_file = new KeyFile();
- try{
- result = this.key_file.load_from_file(this.file_name, KeyFileFlags.NONE);
- }
- catch(GLib.KeyFileError e){
- warning("FamiliarPlayersDB::create_key_file() - KeyFileError");
- }
- catch(GLib.FileError e){
- warning("FamiliarPlayersDB::create_key_file() - FileError");
- }
- }
- return result;
- }
+ private bool create_key_file(){
+ bool result = false;
+ if (test(this.file_name, GLib.FileTest.EXISTS)) {
+ this.key_file = new KeyFile();
+ try{
+ result = this.key_file.load_from_file(this.file_name, KeyFileFlags.NONE);
+ }
+ catch(GLib.KeyFileError e){
+ warning("FamiliarPlayersDB::create_key_file() - KeyFileError");
+ }
+ catch(GLib.FileError e){
+ warning("FamiliarPlayersDB::create_key_file() - FileError");
+ }
+ }
+ return result;
+ }
- private bool check_for_keys(){
- try{
- if(this.key_file.has_key(GROUP_NAME, KEY_NAME) == true){
- return true;
- }
- }
- catch(KeyFileError e){
- return false;
- }
- warning("Seen DB '%s' does not have key '%s' in group '%s'", this.file_name, KEY_NAME, GROUP_NAME);
- return false;
- }
-
- private bool load_data_from_key_file(){
- try{
- string[] desktops = this.key_file.get_string_list(GROUP_NAME,
- KEY_NAME);
- foreach(string s in desktops){
- this.players_DB.set(s, true);
- }
- return true;
- }
- catch(GLib.KeyFileError error){
- warning("Error loading the Desktop string list");
- return false;
- }
- }
+ private bool check_for_keys(){
+ try{
+ if(this.key_file.has_key(GROUP_NAME, KEY_NAME) == true){
+ return true;
+ }
+ }
+ catch(KeyFileError e){
+ return false;
+ }
+ warning("Seen DB '%s' does not have key '%s' in group '%s'", this.file_name, KEY_NAME, GROUP_NAME);
+ return false;
+ }
+
+ private bool load_data_from_key_file(){
+ try{
+ string[] desktops = this.key_file.get_string_list(GROUP_NAME,
+ KEY_NAME);
+ foreach(string s in desktops){
+ this.players_DB.set(s, true);
+ }
+ return true;
+ }
+ catch(GLib.KeyFileError error){
+ warning("Error loading the Desktop string list");
+ return false;
+ }
+ }
- private bool write_db()
- {
- KeyFile keyfile = new KeyFile();
- string[] desktops = {};
- foreach(string key in this.players_DB.keys){
- desktops += key;
- }
- keyfile.set_string_list(GROUP_NAME,
- KEY_NAME,
- desktops);
- size_t data_length;
- string data = null;
- try{
- data = keyfile.to_data(out data_length);
- }
- catch(GLib.KeyFileError e){
- warning("Problems dumping keyfile to a string");
- return false;
- }
-
- if(create_with_parents(this.dir_name, 0700) != 0){
- warning("Unable to make directory: %s", this.dir_name);
- return false;
- }
+ private bool write_db()
+ {
+ KeyFile keyfile = new KeyFile();
+ string[] desktops = {};
+ foreach(string key in this.players_DB.keys){
+ desktops += key;
+ }
+ keyfile.set_string_list(GROUP_NAME,
+ KEY_NAME,
+ desktops);
+ size_t data_length;
+ string data = null;
+ try{
+ data = keyfile.to_data(out data_length);
+ }
+ catch(GLib.KeyFileError e){
+ warning("Problems dumping keyfile to a string");
+ return false;
+ }
+
+ if(create_with_parents(this.dir_name, 0700) != 0){
+ warning("Unable to make directory: %s", this.dir_name);
+ return false;
+ }
- try{
- if(set_contents(this.file_name, data, (ssize_t)data_length) == false){
- warning("Unable to write out file '%s'", this.file_name);
- }
- }
- catch(FileError err){
- warning("Unable to write out file '%s'", this.file_name);
- }
- return true;
- }
+ try{
+ if(set_contents(this.file_name, data, (ssize_t)data_length) == false){
+ warning("Unable to write out file '%s'", this.file_name);
+ }
+ }
+ catch(FileError err){
+ warning("Unable to write out file '%s'", this.file_name);
+ }
+ return true;
+ }
- public void insert(string desktop)
- {
- if(already_familiar(desktop) == false){
- if(this.write_id != 0){
- Source.remove(this.write_id);
- this.write_id = 0;
- }
- this.write_id = Timeout.add_seconds(60, write_db);
- this.players_DB.set(desktop.dup(), true);
- }
- }
-
- public bool already_familiar(string desktop)
- {
- debug("playerDB->already_familiar - result %s", this.players_DB.keys.contains(desktop).to_string());
- return this.players_DB.keys.contains(desktop);
- }
+ public void insert(string desktop)
+ {
+ if(already_familiar(desktop) == false){
+ if(this.write_id != 0){
+ Source.remove(this.write_id);
+ this.write_id = 0;
+ }
+ this.write_id = Timeout.add_seconds(60, write_db);
+ this.players_DB.set(desktop.dup(), true);
+ }
+ }
+
+ public bool already_familiar(string desktop)
+ {
+ debug("playerDB->already_familiar - result %s", this.players_DB.keys.contains(desktop).to_string());
+ return this.players_DB.keys.contains(desktop);
+ }
- public Gee.Set<string> records()
- {
- return this.players_DB.keys;
- }
+ public Gee.Set<string> records()
+ {
+ return this.players_DB.keys;
+ }
public static string? fetch_icon_name(string desktop_path)
{