[Aptitude-svn-commit] r3734 - in branches/aptitude-0.3/aptitude: .
src
Daniel Burrows
dburrows at costa.debian.org
Mon Aug 8 17:31:35 UTC 2005
Author: dburrows
Date: Mon Aug 8 17:31:32 2005
New Revision: 3734
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/apt_config_widgets.cc
branches/aptitude-0.3/aptitude/src/apt_config_widgets.h
branches/aptitude-0.3/aptitude/src/apt_options.cc
branches/aptitude-0.3/aptitude/src/apt_options.h
Log:
Update the configuration widgets for refcounting.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Mon Aug 8 17:31:32 2005
@@ -1,5 +1,11 @@
2005-08-08 Daniel Burrows <dburrows at debian.org>
+ * src/apt_config_widgets.cc, src/apt_config_widgets.h, src/apt_options.cc, src/apt_options.h:
+
+ Convert the configuration <-> UI interface layer to use the
+ reference-counting protocol (and, while I'm at it, stop using
+ multiple inheritance here).
+
* src/main.cc:
Use a counting reference for the initial progress bar.
Modified: branches/aptitude-0.3/aptitude/src/apt_config_widgets.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/apt_config_widgets.cc (original)
+++ branches/aptitude-0.3/aptitude/src/apt_config_widgets.cc Mon Aug 8 17:31:32 2005
@@ -29,15 +29,16 @@
apt_bool_widget::apt_bool_widget(const wstring &_label,
const string &_item, bool _default)
- :vs_checkbutton(flowbox(text_fragment(_label)), aptcfg->FindB(_item, _default)),
- item(_item), my_default(_default)
+ :item(_item), my_default(_default),
+ cb(vs_checkbutton::create(flowbox(text_fragment(_label)),
+ aptcfg->FindB(_item, _default)))
{
}
apt_bool_widget::apt_bool_widget(const string &_label,
const string &_item, bool _default)
- :vs_checkbutton(flowbox(text_fragment(_label)), aptcfg->FindB(_item, _default)),
- item(_item), my_default(_default)
+ :item(_item), my_default(_default),
+ cb(vs_checkbutton::create(flowbox(text_fragment(_label)), aptcfg->FindB(_item, _default)))
{
}
@@ -45,20 +46,20 @@
{
// Setting an option causes it to be saved.
if(aptcfg->ExistsUser(item) ||
- aptcfg->FindB(item, my_default)!=get_checked())
- aptcfg->Set(item, get_checked()?"true":"false");
+ aptcfg->FindB(item, my_default) != cb->get_checked())
+ aptcfg->Set(item, cb->get_checked()?"true":"false");
}
apt_string_widget::apt_string_widget(const string &_item,
const string &_default)
- :vs_editline("", aptcfg->Find(_item, _default.c_str())),
- item(_item), my_default(_default)
+ :item(_item), my_default(_default),
+ el(vs_editline::create("", aptcfg->Find(_item, _default.c_str())))
{
}
void apt_string_widget::commit()
{
- string text=transcode(get_text());
+ string text=transcode(el->get_text());
if(aptcfg->ExistsUser(item) ||
aptcfg->Find(item, my_default.c_str())!=text)
@@ -76,9 +77,9 @@
{
string choice;
- if(selection_valid())
+ if(rg.selection_valid())
{
- choice=choices[get_selected()];
+ choice=choices[rg.get_selected()];
if(aptcfg->ExistsUser(item) ||
aptcfg->Find(item, my_default.c_str())!=choice)
Modified: branches/aptitude-0.3/aptitude/src/apt_config_widgets.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/apt_config_widgets.h (original)
+++ branches/aptitude-0.3/aptitude/src/apt_config_widgets.h Mon Aug 8 17:31:32 2005
@@ -17,9 +17,12 @@
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
-// Our friends the "apt config widgets". These little fellas know how to
-// get their state from the libapt configuration and how to set the
-// configuration on demand. Aren't they cute?
+// Classes that mediate between the configuration layer and the user
+// interface layer. Past versions of this file used multiple
+// inheritance, but in order to handle memory management in an
+// obvious and safe way, I modified this to explicitly make the
+// UI-layer objects public members of the config-layer objects. This
+// is arguably cleaner anyway.
#ifndef APT_CONFIG_WIDGETS_H
#define APT_CONFIG_WIDGETS_H
@@ -33,11 +36,9 @@
#include <string>
#include <vector>
-// This basically just provides a generic interface to commit changes to apt
-// options. Not a descendant of Object because the classes below get Object
-// via vscreen_widget, and things get confused if Object is included twice.
-// (the compiler gets unhappy)
-class apt_config_widget
+// This basically just provides a generic interface to commit changes
+// to apt options.
+class apt_config_widget : public sigc::trackable
{
public:
virtual ~apt_config_widget() {}
@@ -45,7 +46,7 @@
virtual void commit()=0;
};
-class apt_bool_widget:public apt_config_widget, public vs_checkbutton
+class apt_bool_widget : public apt_config_widget
{
std::string item; // the config-item we're associated with.
@@ -56,10 +57,13 @@
apt_bool_widget(const std::string &_label,
const std::string &_item, bool _default);
+ /** The actual underlying object. */
+ vs_checkbutton_ref cb;
+
void commit();
};
-class apt_string_widget:public apt_config_widget, public vs_editline
+class apt_string_widget : public apt_config_widget
{
std::string item; // the config-item we're associated with.
@@ -68,6 +72,9 @@
apt_string_widget(const std::string &_item,
const std::string &_default);
+ /** The underlying object. */
+ vs_editline_ref el;
+
void commit();
};
@@ -75,7 +82,7 @@
* creator of this widget must give each choice an id corresponding
* to its index in the "choices" array.
*/
-class apt_radio_widget:public apt_config_widget, public vs_radiogroup
+class apt_radio_widget : public apt_config_widget
{
std::string item;
@@ -87,6 +94,9 @@
const std::vector<std::string> &choices,
const std::string &_default);
+ /** The underlying interface object. */
+ vs_radiogroup rg;
+
void commit();
};
Modified: branches/aptitude-0.3/aptitude/src/apt_options.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/apt_options.cc (original)
+++ branches/aptitude-0.3/aptitude/src/apt_options.cc Mon Aug 8 17:31:32 2005
@@ -195,7 +195,16 @@
class dialog_manager:public sigc::trackable
{
public:
- dialog_manager(vscreen_widget *_dialog):dialog(_dialog) {}
+ dialog_manager(const vs_widget_ref &_dialog):dialog(_dialog) {}
+
+ ~dialog_manager()
+ {
+ for(vector<apt_config_widget *>::iterator i=widgets.begin();
+ i!=widgets.end(); ++i)
+ delete *i;
+
+ widgets.clear();
+ }
void add_widget(apt_config_widget *w) {widgets.push_back(w);}
@@ -220,25 +229,20 @@
private:
vector<apt_config_widget *> widgets;
- vscreen_widget *dialog;
+ vs_widget_ref dialog;
};
-static void kill_radiogroup(apt_radio_widget *w)
+static vs_widget_ref realize_options_dialog(option_item *items)
{
- delete w;
-}
-
-static vscreen_widget *realize_options_dialog(option_item *items)
-{
- vs_center *center=new vs_center;
+ vs_center_ref center=vs_center::create();
// Create general infrastructure (FIXME: make a plugin dialog widget thingy
// that does this?
- vs_table *table=new vs_table;
+ vs_table_ref table=vs_table::create();
table->set_colsep(1);
- vs_button *okbutton=new vs_button(_("Ok"));
- vs_button *cancelbutton=new vs_button(_("Cancel"));
+ vs_button_ref okbutton=vs_button::create(_("Ok"));
+ vs_button_ref cancelbutton=vs_button::create(_("Cancel"));
table->connect_key("Confirm", &global_bindings, okbutton->pressed.make_slot());
table->connect_key("Cancel", &global_bindings, cancelbutton->pressed.make_slot());
@@ -252,7 +256,7 @@
while(items->type!=option_item::OPTION_END)
{
- vs_label *l=NULL;
+ vs_label_ref l=NULL;
switch(items->type)
{
@@ -262,7 +266,7 @@
items->option_name,
items->b_default);
- table->add_widget(w, row, 0, 1, 2, true, false);
+ table->add_widget(w->cb, row, 0, 1, 2, true, false);
manager->add_widget(w);
}
@@ -273,10 +277,10 @@
apt_string_widget *w=new apt_string_widget(items->option_name,
items->s_default);
- l=new vs_label(_(items->description));
+ l=vs_label::create(_(items->description));
table->add_widget(l, row, 0, 1, 1, false, false);
- table->add_widget(w, row, 1, 1, 1, true, false);
+ table->add_widget(w->el, row, 1, 1, 1, true, false);
manager->add_widget(w);
}
@@ -295,34 +299,29 @@
string curr=aptcfg->Find(items->option_name,
items->s_default);
- // Make sure we always clean up the radio group. (is this
- // safe?)
- center->destroyed.connect(sigc::bind(sigc::ptr_fun(kill_radiogroup),
- w));
-
- l=new vs_label(_(items->description));
+ l=vs_label::create(_(items->description));
for(vector<string>::size_type i=0; i<items->choices.size(); ++i)
{
string choice=items->choices[i];
string description=items->choice_descriptions[i];
- vs_togglebutton *b=new vs_radiobutton(_(description.c_str()),
- choice == curr);
+ vs_togglebutton_ref b=vs_radiobutton::create(_(description.c_str()),
+ choice == curr);
table->add_widget(b, row+i, 1, 1, 1, false, false);
- w->add_button(b, i);
+ w->rg.add_button(b, i);
}
- if(!w->selection_valid())
+ if(!w->rg.selection_valid())
{
// Hm, if it didn't work the first time, why would it
// work the second time?
for(vector<string>::size_type i=0; i<items->choices.size(); ++i)
if(items->choices[i]==curr)
{
- w->select(i);
+ w->rg.select(i);
break;
}
}
@@ -340,7 +339,7 @@
items++;
}
- vs_table *bt=new vs_table;
+ vs_table_ref bt=vs_table::create();
bt->add_widget_opts(okbutton, 0, 0, 1, 1,
vs_table::ALIGN_CENTER | vs_table::EXPAND,
vs_table::ALIGN_CENTER);
@@ -351,7 +350,7 @@
vs_table::ALIGN_CENTER | vs_table::EXPAND | vs_table::FILL,
vs_table::ALIGN_CENTER);
- vs_frame *frame=new vs_frame(table);
+ vs_frame_ref frame=vs_frame::create(table);
center->add_widget(frame);
center->set_bg_style(style_attrs_flip(A_REVERSE));
@@ -359,17 +358,17 @@
return center;
}
-vscreen_widget *make_ui_options_dialog()
+vs_widget_ref make_ui_options_dialog()
{
return realize_options_dialog(ui_options);
}
-vscreen_widget *make_misc_options_dialog()
+vs_widget_ref make_misc_options_dialog()
{
return realize_options_dialog(misc_options);
}
-vscreen_widget *make_dependency_options_dialog()
+vs_widget_ref make_dependency_options_dialog()
{
return realize_options_dialog(dependency_options);
}
Modified: branches/aptitude-0.3/aptitude/src/apt_options.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/apt_options.h (original)
+++ branches/aptitude-0.3/aptitude/src/apt_options.h Mon Aug 8 17:31:32 2005
@@ -9,9 +9,12 @@
class vscreen_widget;
+template<class T> class ref_ptr;
+
+typedef ref_ptr<vscreen_widget> vs_widget_ref;
// hmm, maybe just make this a global variable that gets shown and hidden?
-vscreen_widget *make_ui_options_dialog();
-vscreen_widget *make_misc_options_dialog();
-vscreen_widget *make_dependency_options_dialog();
+vs_widget_ref make_ui_options_dialog();
+vs_widget_ref make_misc_options_dialog();
+vs_widget_ref make_dependency_options_dialog();
#endif
More information about the Aptitude-svn-commit
mailing list