Skip to content

Commit

Permalink
Toplevel: split layout from core file.
Browse files Browse the repository at this point in the history
  • Loading branch information
rilian-la-te committed Sep 20, 2017
1 parent 2c8ad76 commit af047d1
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 143 deletions.
3 changes: 2 additions & 1 deletion app/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ static void activate_menu(GSimpleAction *simple, GVariant *param, gpointer data)
{
if (VALA_PANEL_IS_TOPLEVEL(l->data))
{
GList *applets = vala_panel_toplevel_get_applets_list(l->data);
ValaPanelLayout* layout = VALA_PANEL_TOPLEVEL(l->data)->layout;
GList *applets = vala_panel_layout_get_applets_list(layout);
for (GList *il = applets; il != NULL; il = il->next)
{
GSimpleActionGroup *grp;
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set(VALA_FILES
configurator.vala
applet-holder.vala
panel-toplevel.vala
panel-layout.vala
)
vala_precompile(VALA_C ${LIBNAME}
${VALA_FILES}
Expand Down
2 changes: 1 addition & 1 deletion lib/applet-widget.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void activate_remove(GSimpleAction *act, GVariant *param, gpointer obj)
* user manipulates the Configured Plugins list, after we remove this entry.
* Close the configuration dialog if it is open. */
gtk_widget_destroy0(p->toplevel->pref_dialog);
vala_panel_toplevel_remove_applet(p->toplevel, self);
vala_panel_layout_remove_applet(p->toplevel->layout, self);
}
static GtkWidget *vala_panel_applet_get_config_dialog(ValaPanelApplet *self)
{
Expand Down
34 changes: 17 additions & 17 deletions lib/configurator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace ValaPanel
if( tree_sel.get_selected(out model, out it ) )
{
model.get(it, Column.DATA, out pl, -1 );
var desc = Toplevel.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_description();
var desc = Layout.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_description();
plugin_desc.set_text(_(desc) );
configure_button.set_sensitive(pl.is_configurable());
}
Expand All @@ -174,11 +174,11 @@ namespace ValaPanel
Applet pl;
bool expand;
model.get(it, Column.DATA, out pl, Column.EXPAND, out expand, -1 );
if (Toplevel.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_external_data(Data.EXPANDABLE)!=null)
if (Layout.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_external_data(Data.EXPANDABLE)!=null)
{
expand = !expand;
(model as Gtk.ListStore).set(it,Column.EXPAND,expand,-1);
unowned UnitSettings s = toplevel.get_applet_settings(pl);
unowned UnitSettings s = toplevel.layout.get_applet_settings(pl);
s.default_settings.set_boolean(Key.EXPAND,expand);
}
}
Expand All @@ -189,19 +189,19 @@ namespace ValaPanel
* The g_object_set method is touchy about its parameter, so we can't pass the boolean directly. */
Applet pl;
model.get(iter, Column.DATA, out pl, -1);
renderer.visible = (Toplevel.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_external_data(Data.EXPANDABLE)!=null) ? true : false;
renderer.visible = (Layout.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_external_data(Data.EXPANDABLE)!=null) ? true : false;
}
private void update_plugin_list_model()
{
TreeIter it;
var list = new Gtk.ListStore( 3, typeof(string), typeof(bool), typeof(Applet) );
var plugins = toplevel.get_applets_list();
var plugins = toplevel.layout.get_applets_list();
foreach(var widget in plugins)
{
var w = widget as Applet;
var expand = widget.hexpand && widget.vexpand;
list.append(out it );
var name = Toplevel.holder.get_plugin(w,Toplevel.core_settings).plugin_info.get_name();
var name = Layout.holder.get_plugin(w,Toplevel.core_settings).plugin_info.get_name();
list.set(it,
Column.NAME, _(name),
Column.EXPAND, expand,
Expand Down Expand Up @@ -294,7 +294,7 @@ namespace ValaPanel

/* Populate list of available plugins.
* Omit plugins that can only exist once per system if it is already configured. */
foreach(var type in Toplevel.holder.get_all_types())
foreach(var type in Layout.holder.get_all_types())
{
var once = type.get_external_data(Data.ONE_PER_SYSTEM);
if (once == null || !type.is_loaded())
Expand All @@ -320,8 +320,8 @@ namespace ValaPanel
{
string type;
list.get(it, 1, out type, -1 );
toplevel.add_applet(type);
toplevel.update_applet_positions();
toplevel.layout.add_applet(type);
toplevel.layout.update_applet_positions();
update_plugin_list_model();
}
update_widget_position_keys();
Expand Down Expand Up @@ -350,16 +350,16 @@ namespace ValaPanel
(model as Gtk.ListStore).remove(it);
#endif
tree_sel.select_path(tree_path );
toplevel.remove_applet(pl);
toplevel.layout.remove_applet(pl);
}
}
private void update_widget_position_keys()
{
foreach(var w in toplevel.get_applets_list())
foreach(var w in toplevel.layout.get_applets_list())
{
var applet = w as Applet;
uint idx = toplevel.get_applet_position(applet);
unowned UnitSettings s = toplevel.get_applet_settings(applet);
uint idx = toplevel.layout.get_applet_position(applet);
unowned UnitSettings s = toplevel.layout.get_applet_settings(applet);
s.default_settings.set_uint(Key.POSITION,idx);
}
}
Expand All @@ -381,12 +381,12 @@ namespace ValaPanel
model.get(it, Column.DATA, out pl, -1 );
(model as Gtk.ListStore).move_before(ref it, prev );

var i = toplevel.get_applet_position(pl);
var i = toplevel.layout.get_applet_position(pl);
/* reorder in config, 0 is Global */
i = i > 0 ? i : 0;

/* reorder in panel */
toplevel.set_applet_position(pl,(int)i-1);
toplevel.layout.set_applet_position(pl,(int)i-1);
update_widget_position_keys();
return;
}
Expand All @@ -411,9 +411,9 @@ namespace ValaPanel

(model as Gtk.ListStore).move_after(ref it, next );

var i = toplevel.get_applet_position(pl);
var i = toplevel.layout.get_applet_position(pl);
/* reorder in panel */
toplevel.set_applet_position(pl,(int)i+1);
toplevel.layout.set_applet_position(pl,(int)i+1);
update_widget_position_keys();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dbusmenu
146 changes: 146 additions & 0 deletions lib/panel-layout.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* vala-panel
* Copyright (C) 2017 Konstantin Pugin <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using GLib;
using Gtk;
using Gdk;
using Config;

namespace ValaPanel
{
public class Layout : Gtk.Box
{
private static unowned CoreSettings core_settings = null;
internal static AppletHolder holder = null;
public string toplevel_id {get; construct;}
public Layout(ValaPanel.Toplevel top, Gtk.Orientation orient, int spacing)
{
Object(orientation: orient,
spacing: spacing,
baseline_position: BaselinePosition.CENTER,
border_width: 0, hexpand: true, vexpand: true,
toplevel_id: top.uuid);
}
static construct
{
holder = new AppletHolder();
core_settings = Toplevel.core_settings;
}
construct
{
holder.applet_ready_to_place.connect(on_applet_ready_to_place);
holder.applet_loaded.connect(on_applet_loaded);
}
internal void init_applets()
{
foreach(var unit in core_settings.core_settings.get_strv(ValaPanel.Settings.CORE_UNITS))
{
unowned UnitSettings pl = core_settings.get_by_uuid(unit);
if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.toplevel_id)
holder.load_applet(pl);
}
}
internal void add_applet(string type)
{
unowned UnitSettings s = core_settings.add_unit_settings(type,false);
s.default_settings.set_string(Key.NAME,type);
s.default_settings.set_string(Settings.TOPLEVEL_ID,this.toplevel_id);
holder.load_applet(s);
}
private void on_applet_loaded(string type)
{
foreach (var unit in core_settings.core_settings.get_strv(Settings.CORE_UNITS))
{
unowned UnitSettings pl = core_settings.get_by_uuid(unit);
if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.toplevel_id)
{
if (pl.default_settings.get_string(Key.NAME) == type)
{
place_applet(holder.applet_ref(type),pl);
update_applet_positions();
return;
}
}
}
}
private void on_applet_ready_to_place(AppletPlugin applet_plugin, UnitSettings pl)
{
if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.toplevel_id)
place_applet(applet_plugin,pl);
}

internal void place_applet(AppletPlugin applet_plugin, UnitSettings s)
{
var aw = applet_plugin.get_applet_widget(this.get_parent().get_parent() as ValaPanel.Toplevel,s.custom_settings,s.uuid);
unowned Applet applet = aw;
var position = s.default_settings.get_uint(Key.POSITION);
this.pack_start(applet,false, true);
this.reorder_child(applet,(int)position);
if (applet_plugin.plugin_info.get_external_data(Data.EXPANDABLE)!=null)
{
s.default_settings.bind(Key.EXPAND,applet,"hexpand",GLib.SettingsBindFlags.GET);
applet.bind_property("hexpand",applet,"vexpand",BindingFlags.SYNC_CREATE);
}
applet.destroy.connect(()=>{
string uuid = applet.uuid;
applet_destroyed(uuid);
if (this.in_destruction())
core_settings.remove_unit_settings(uuid);
});
}
public void remove_applet(Applet applet)
{
unowned UnitSettings s = core_settings.get_by_uuid(applet.uuid);
applet.destroy();
core_settings.remove_unit_settings_full(s.uuid, true);
}
internal void applet_destroyed(string uuid)
{
unowned UnitSettings s = core_settings.get_by_uuid(uuid);
var name = s.default_settings.get_string(Key.NAME);
holder.applet_unref(name);
}
internal void update_applet_positions()
{
var children = this.get_children();
for (unowned List<unowned Widget> l = children; l != null; l = l.next)
{
var idx = get_applet_settings(l.data as Applet).default_settings.get_uint(Key.POSITION);
this.reorder_child((l.data as Applet),(int)idx);
}
}
public List<unowned Widget> get_applets_list()
{
return this.get_children();
}
internal unowned UnitSettings get_applet_settings(Applet pl)
{
return core_settings.get_by_uuid(pl.uuid);
}
internal uint get_applet_position(Applet pl)
{
int res;
this.child_get(pl,"position",out res, null);
return (uint)res;
}
internal void set_applet_position(Applet pl, int pos)
{
this.reorder_child(pl,pos);
}
}
}
Loading

0 comments on commit af047d1

Please sign in to comment.