Commits

tro...@gmail.com  committed 6362e86

dynamic add/remove accounts in status_choose_bar

  • Participants
  • Parent commits d5e2b7b

Comments (0)

Files changed (2)

File src/status_choose_bar.vala

 		set_icon_size(IconSize.SMALL_TOOLBAR);
 		toolbar_style = ToolbarStyle.ICONS;
 		
-		this.accounts.element_was_removed.connect(remove_account);
+		accounts.insert_new_account.connect((acc) => {
+			add_new_account(acc);
+			update_config();
+		});
+		
+		accounts.element_was_removed.connect((path, acc) => {
+			if(path.contains(":")) //just stream, not account
+			return;
+		
+			foreach(Widget tb in this.get_children()) {
+				if(tb.get_type() != typeof(ToggleToolButton))
+					continue;
+				
+				if(((ToggleToolButton) tb).label == acc.get_hash()) {
+					this.remove(tb);
+				}
+			}
+			
+			update_config();
+		});
 	}
 	
 	public void set_count(int chars) {
 		}
 	}
 	
+	private void add_new_account(AAccount account) {
+		debug(account.s_name);
+		ToggleToolButton tb = new ToggleToolButton();
+		tb.label = account.get_hash();
+		tb.set_tooltip_text("%s (%s)".printf(account.s_name, account.id));
+		
+		if(settings.selected_for_posting.contains(tb.label))
+			tb.set_active(true);
+		
+		account.notify["userpic"].connect((s) => {
+			debug("userpic is loaded");
+			Image img = new Image.from_pixbuf(account.userpic.scale_simple(
+				24, 24, Gdk.InterpType.HYPER));
+			img.show();
+			tb.set_icon_widget(img);
+		});
+		
+		tb.toggled.connect(() => {
+			update_config();
+		});
+		
+		/*
+		if(account.userpic != null) {
+			debug("userpic is ok");
+			Image img = new Image.from_pixbuf(account.userpic);
+			img.pixel_size = 48;
+			tb.set_icon_widget(img);
+		}*/
+		this.add(tb);
+		tb.show();
+	}
+	
 	private void generate_acc() {
 		foreach(AAccount account in this.accounts) {
-			ToggleToolButton tb = new ToggleToolButton();
-			tb.label = account.get_hash();
-			tb.set_tooltip_text("%s (%s)".printf(account.s_name, account.id));
-			
-			if(settings.selected_for_posting.contains(tb.label))
-				tb.set_active(true);
-			
-			account.notify["userpic"].connect((s) => {
-				debug("userpic is loaded");
-				Image img = new Image.from_pixbuf(account.userpic.scale_simple(
-					24, 24, Gdk.InterpType.HYPER));
-				img.show();
-				tb.set_icon_widget(img);
-			});
-			
-			tb.toggled.connect(() => {
-				update_config();
-			});
-			
-			/*
-			if(account.userpic != null) {
-				debug("userpic is ok");
-				Image img = new Image.from_pixbuf(account.userpic);
-				img.pixel_size = 48;
-				tb.set_icon_widget(img);
-			}*/
-			this.add(tb);
+			add_new_account(account);
 		}
 	}
-	
-	private void remove_account(string path, AAccount account) {
-		if(path.contains(":")) //just stream, not account
-			return;
-		
-		update_config();
-	}
 }

File src/template.vala

 			var pat = new Regex("{{" + key + "}}");
 			result = pat.replace(result, -1, 0, map[key]);
 		}
-		debug(result);
+		//debug(result);
 		return result;
 	}