[280] | 1 | /* $Id: rgvendorswindow.cc,v 1.4 2002/12/06 08:16:40 mvogt Exp $ */ |
---|
| 2 | #include <cassert> |
---|
| 3 | #include "rgvendorswindow.h" |
---|
| 4 | #include "rgrepositorywin.h" |
---|
| 5 | #include "config.h" |
---|
| 6 | #include "i18n.h" |
---|
| 7 | |
---|
| 8 | RGVendorsEditor::RGVendorsEditor(RGWindow *parent, SourcesList &_lst) |
---|
| 9 | : RGWindow(parent, "vendors"), lst(_lst) |
---|
| 10 | { |
---|
| 11 | selectedrow = -1; |
---|
| 12 | dialog = CreateWidget(); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | RGVendorsEditor::~RGVendorsEditor() |
---|
| 16 | { |
---|
| 17 | gtk_widget_destroy(dialog); |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | GtkWidget *RGVendorsEditor::CreateWidget() |
---|
| 21 | { |
---|
| 22 | GtkWidget *dlgSrcList; |
---|
| 23 | GtkWidget *dialog_vbox1; |
---|
| 24 | GtkWidget *frmMain; |
---|
| 25 | GtkWidget *vbox1; |
---|
| 26 | GtkWidget *scrolledwindow1; |
---|
| 27 | GtkWidget *btnAddNew; |
---|
| 28 | GtkWidget *btnRemove; |
---|
| 29 | GtkWidget *table1; |
---|
| 30 | GtkWidget *lblVendor; |
---|
| 31 | GtkWidget *lblDesc; |
---|
| 32 | GtkWidget *lblFPrint; |
---|
| 33 | GtkWidget *dialog_action_area1; |
---|
| 34 | GtkWidget *hbox1; |
---|
| 35 | GtkWidget *btnOK; |
---|
| 36 | GtkWidget *btnCancel; |
---|
| 37 | |
---|
| 38 | dlgSrcList = gtk_dialog_new(); |
---|
| 39 | gtk_window_set_title(GTK_WINDOW(dlgSrcList), _("Setup Vendors")); |
---|
| 40 | //GTK_WINDOW (dlgSrcList)->type = GTK_WINDOW_DIALOG; |
---|
| 41 | gtk_window_set_modal(GTK_WINDOW(dlgSrcList), TRUE); |
---|
| 42 | gtk_window_set_default_size(GTK_WINDOW(dlgSrcList), -1, 400); |
---|
| 43 | gtk_window_set_policy(GTK_WINDOW(dlgSrcList), TRUE, TRUE, FALSE); |
---|
| 44 | |
---|
| 45 | dialog_vbox1 = GTK_DIALOG(dlgSrcList)->vbox; |
---|
| 46 | gtk_widget_show(dialog_vbox1); |
---|
| 47 | |
---|
| 48 | frmMain = gtk_frame_new(NULL); |
---|
| 49 | gtk_widget_show(frmMain); |
---|
| 50 | gtk_box_pack_start(GTK_BOX(dialog_vbox1), frmMain, TRUE, TRUE, 0); |
---|
| 51 | gtk_container_set_border_width(GTK_CONTAINER(frmMain), 5); |
---|
| 52 | |
---|
| 53 | vbox1 = gtk_vbox_new(FALSE, 0); |
---|
| 54 | gtk_widget_show(vbox1); |
---|
| 55 | gtk_container_add(GTK_CONTAINER(frmMain), vbox1); |
---|
| 56 | gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5); |
---|
| 57 | |
---|
| 58 | scrolledwindow1 = gtk_scrolled_window_new(NULL, NULL); |
---|
| 59 | gtk_widget_show(scrolledwindow1); |
---|
| 60 | gtk_box_pack_start(GTK_BOX(vbox1), scrolledwindow1, TRUE, TRUE, 0); |
---|
| 61 | |
---|
| 62 | char *titles[] = { _("Vendor"), _("Description"), _("FingerPrint") }; |
---|
| 63 | |
---|
| 64 | lstVendors = gtk_clist_new_with_titles(3, titles); |
---|
| 65 | gtk_widget_show(lstVendors); |
---|
| 66 | gtk_container_add(GTK_CONTAINER(scrolledwindow1), lstVendors); |
---|
| 67 | gtk_clist_set_column_width(GTK_CLIST(lstVendors), 0, 60); |
---|
| 68 | gtk_clist_set_column_width(GTK_CLIST(lstVendors), 1, 300); |
---|
| 69 | gtk_clist_set_column_width(GTK_CLIST(lstVendors), 2, 300); |
---|
| 70 | gtk_clist_set_column_auto_resize(GTK_CLIST(lstVendors), 1, TRUE); |
---|
| 71 | gtk_clist_set_column_auto_resize(GTK_CLIST(lstVendors), 2, TRUE); |
---|
| 72 | gtk_clist_column_titles_show(GTK_CLIST(lstVendors)); |
---|
| 73 | |
---|
| 74 | table1 = gtk_table_new(2, 3, FALSE); |
---|
| 75 | gtk_widget_show(table1); |
---|
| 76 | gtk_box_pack_start(GTK_BOX(vbox1), table1, FALSE, TRUE, 0); |
---|
| 77 | gtk_container_set_border_width(GTK_CONTAINER(table1), 5); |
---|
| 78 | gtk_table_set_col_spacings(GTK_TABLE(table1), 10); |
---|
| 79 | |
---|
| 80 | lblVendor = gtk_label_new(_("Vendor")); |
---|
| 81 | gtk_misc_set_alignment(GTK_MISC(lblVendor), 1.0, 0.5); |
---|
| 82 | gtk_widget_show(lblVendor); |
---|
| 83 | gtk_table_attach(GTK_TABLE(table1), lblVendor, 0, 1, 0, 1, |
---|
| 84 | (GtkAttachOptions) (GTK_FILL), |
---|
| 85 | (GtkAttachOptions) (0), 0, 0); |
---|
| 86 | |
---|
| 87 | entryVendor = gtk_entry_new(); |
---|
| 88 | gtk_widget_set_usize(entryVendor, 50, -1); |
---|
| 89 | gtk_widget_show(entryVendor); |
---|
| 90 | gtk_table_attach(GTK_TABLE(table1), entryVendor, 1, 2, 0, 1, |
---|
| 91 | (GtkAttachOptions) (GTK_FILL), |
---|
| 92 | (GtkAttachOptions) (0), 0, 0); |
---|
| 93 | |
---|
| 94 | lblDesc = gtk_label_new(_("Description")); |
---|
| 95 | gtk_widget_show(lblDesc); |
---|
| 96 | gtk_table_attach(GTK_TABLE(table1), lblDesc, 0, 1, 1, 2, |
---|
| 97 | (GtkAttachOptions) (GTK_FILL), |
---|
| 98 | (GtkAttachOptions) (0), 0, 0); |
---|
| 99 | |
---|
| 100 | entryDesc = gtk_entry_new(); |
---|
| 101 | gtk_widget_set_usize(entryDesc, 300, -1); |
---|
| 102 | gtk_widget_show(entryDesc); |
---|
| 103 | gtk_table_attach(GTK_TABLE(table1), entryDesc, 1, 6, 1, 2, |
---|
| 104 | (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), |
---|
| 105 | (GtkAttachOptions) (0), 0, 0); |
---|
| 106 | |
---|
| 107 | lblFPrint = gtk_label_new(_("FingerPrint")); |
---|
| 108 | gtk_widget_show(lblFPrint); |
---|
| 109 | gtk_table_attach(GTK_TABLE(table1), lblFPrint, 0, 1, 2, 3, |
---|
| 110 | (GtkAttachOptions) (GTK_FILL), |
---|
| 111 | (GtkAttachOptions) (0), 0, 0); |
---|
| 112 | |
---|
| 113 | entryFPrint = gtk_entry_new(); |
---|
| 114 | gtk_widget_set_usize(entryFPrint, 300, -1); |
---|
| 115 | gtk_widget_show(entryFPrint); |
---|
| 116 | gtk_table_attach(GTK_TABLE(table1), entryFPrint, 1, 6, 2, 3, |
---|
| 117 | (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), |
---|
| 118 | (GtkAttachOptions) (0), 0, 0); |
---|
| 119 | |
---|
| 120 | dialog_action_area1 = GTK_DIALOG(dlgSrcList)->action_area; |
---|
| 121 | gtk_widget_show(dialog_action_area1); |
---|
| 122 | gtk_container_set_border_width(GTK_CONTAINER(dialog_action_area1), 10); |
---|
| 123 | |
---|
| 124 | hbox1 = gtk_hbox_new(FALSE, 0); |
---|
| 125 | gtk_widget_show(hbox1); |
---|
| 126 | gtk_box_pack_start(GTK_BOX(dialog_action_area1), hbox1, TRUE, TRUE, 8); |
---|
| 127 | |
---|
| 128 | btnOK = gtk_button_new_with_label(_("OK")); |
---|
| 129 | gtk_widget_show(btnOK); |
---|
| 130 | gtk_box_pack_start(GTK_BOX(hbox1), btnOK, TRUE, TRUE, 10); |
---|
| 131 | |
---|
| 132 | btnAddNew = gtk_button_new_with_label(_("Add")); |
---|
| 133 | gtk_widget_show(btnAddNew); |
---|
| 134 | gtk_box_pack_start(GTK_BOX(hbox1), btnAddNew, TRUE, TRUE, 10); |
---|
| 135 | |
---|
| 136 | btnRemove = gtk_button_new_with_label(_("Remove")); |
---|
| 137 | gtk_widget_show(btnRemove); |
---|
| 138 | gtk_box_pack_start(GTK_BOX(hbox1), btnRemove, TRUE, TRUE, 10); |
---|
| 139 | |
---|
| 140 | btnCancel = gtk_button_new_with_label(_("Cancel")); |
---|
| 141 | gtk_widget_show(btnCancel); |
---|
| 142 | gtk_box_pack_start(GTK_BOX(hbox1), btnCancel, TRUE, TRUE, 10); |
---|
| 143 | |
---|
| 144 | gtk_signal_connect(GTK_OBJECT(lstVendors), "select-row", |
---|
| 145 | GTK_SIGNAL_FUNC(UpdateDisplay), (gpointer) this); |
---|
| 146 | gtk_signal_connect(GTK_OBJECT(lstVendors), "unselect-row", |
---|
| 147 | GTK_SIGNAL_FUNC(UnselectRow), (gpointer) this); |
---|
| 148 | |
---|
| 149 | gtk_signal_connect(GTK_OBJECT(btnAddNew), "clicked", |
---|
| 150 | GTK_SIGNAL_FUNC(DoAdd), (gpointer) this); |
---|
| 151 | |
---|
| 152 | gtk_signal_connect(GTK_OBJECT(btnRemove), "clicked", |
---|
| 153 | GTK_SIGNAL_FUNC(DoRemove), (gpointer) this); |
---|
| 154 | |
---|
| 155 | gtk_signal_connect(GTK_OBJECT(btnOK), "clicked", |
---|
| 156 | GTK_SIGNAL_FUNC(DoOK), (gpointer) this); |
---|
| 157 | gtk_signal_connect(GTK_OBJECT(btnCancel), "clicked", |
---|
| 158 | GTK_SIGNAL_FUNC(DoCancel), (gpointer) this); |
---|
| 159 | |
---|
| 160 | return dlgSrcList; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | void RGVendorsEditor::Run() |
---|
| 164 | { |
---|
| 165 | GdkColormap *cmap = gdk_colormap_get_system(); |
---|
| 166 | GdkColor gray; |
---|
| 167 | gray.red = gray.green = gray.blue = 0xAA00; |
---|
| 168 | gdk_color_alloc(cmap, &gray); |
---|
| 169 | |
---|
| 170 | gtk_clist_freeze(GTK_CLIST(lstVendors)); |
---|
| 171 | gtk_clist_clear(GTK_CLIST(lstVendors)); |
---|
| 172 | |
---|
| 173 | for (VendorsListIter it = lst.VendorRecords.begin(); |
---|
| 174 | it != lst.VendorRecords.end(); it++) { |
---|
| 175 | const gchar *rowtxt[] = { |
---|
| 176 | (*it)->VendorID.c_str(), |
---|
| 177 | (*it)->Description.c_str(), |
---|
| 178 | (*it)->FingerPrint.c_str() |
---|
| 179 | }; |
---|
| 180 | gint row = gtk_clist_append(GTK_CLIST(lstVendors), (gchar **) rowtxt); |
---|
| 181 | gtk_clist_set_row_data(GTK_CLIST(lstVendors), row, (gpointer) (*it)); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | gtk_clist_thaw(GTK_CLIST(lstVendors)); |
---|
| 185 | |
---|
| 186 | gtk_widget_show_all(dialog); |
---|
| 187 | gtk_main(); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | void RGVendorsEditor::DoAdd(GtkWidget *, gpointer data) |
---|
| 191 | { |
---|
| 192 | RGVendorsEditor *me = (RGVendorsEditor *) data; |
---|
| 193 | string VendorID; |
---|
| 194 | string Description; |
---|
| 195 | string FingerPrint; |
---|
| 196 | |
---|
| 197 | VendorID = gtk_entry_get_text(GTK_ENTRY(me->entryVendor)); |
---|
| 198 | Description = gtk_entry_get_text(GTK_ENTRY(me->entryDesc)); |
---|
| 199 | FingerPrint = gtk_entry_get_text(GTK_ENTRY(me->entryFPrint)); |
---|
| 200 | |
---|
| 201 | SourcesList::VendorRecord *rec = |
---|
| 202 | me->lst.AddVendor(VendorID, FingerPrint, Description); |
---|
| 203 | |
---|
| 204 | const gchar *rowtxt[] = { |
---|
| 205 | rec->VendorID.c_str(), |
---|
| 206 | rec->Description.c_str(), |
---|
| 207 | rec->FingerPrint.c_str() |
---|
| 208 | }; |
---|
| 209 | |
---|
| 210 | gint row = gtk_clist_append(GTK_CLIST(me->lstVendors), (gchar **) rowtxt); |
---|
| 211 | if (!gtk_clist_row_is_visible(GTK_CLIST(me->lstVendors), row)) |
---|
| 212 | gtk_clist_moveto(GTK_CLIST(me->lstVendors), row, 0, 1.0, 0.0); |
---|
| 213 | gtk_clist_set_row_data(GTK_CLIST(me->lstVendors), row, (gpointer) rec); |
---|
| 214 | gtk_clist_select_row(GTK_CLIST(me->lstVendors), row, 0); |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | void RGVendorsEditor::DoEdit(GtkWidget *, gpointer data) |
---|
| 218 | { |
---|
| 219 | RGVendorsEditor *me = (RGVendorsEditor *) data; |
---|
| 220 | |
---|
| 221 | if (me->selectedrow < 0) |
---|
| 222 | return; /* no row selected */ |
---|
| 223 | |
---|
| 224 | SourcesList::VendorRecord &rec = |
---|
| 225 | *((SourcesList:: |
---|
| 226 | VendorRecord *) gtk_clist_get_row_data(GTK_CLIST(me->lstVendors), |
---|
| 227 | me->selectedrow)); |
---|
| 228 | |
---|
| 229 | rec.VendorID = gtk_entry_get_text(GTK_ENTRY(me->entryVendor)); |
---|
| 230 | rec.Description = gtk_entry_get_text(GTK_ENTRY(me->entryDesc)); |
---|
| 231 | rec.FingerPrint = gtk_entry_get_text(GTK_ENTRY(me->entryFPrint)); |
---|
| 232 | |
---|
| 233 | /* repaint screen */ |
---|
| 234 | gtk_clist_set_text(GTK_CLIST(me->lstVendors), me->selectedrow, |
---|
| 235 | 0, rec.VendorID.c_str()); |
---|
| 236 | gtk_clist_set_text(GTK_CLIST(me->lstVendors), me->selectedrow, |
---|
| 237 | 1, rec.Description.c_str()); |
---|
| 238 | gtk_clist_set_text(GTK_CLIST(me->lstVendors), me->selectedrow, |
---|
| 239 | 2, rec.FingerPrint.c_str()); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | void RGVendorsEditor::DoRemove(GtkWidget *, gpointer data) |
---|
| 243 | { |
---|
| 244 | RGVendorsEditor *me = (RGVendorsEditor *) data; |
---|
| 245 | gint row = me->selectedrow; |
---|
| 246 | if (row < 0) |
---|
| 247 | return; |
---|
| 248 | me->selectedrow = -1; |
---|
| 249 | |
---|
| 250 | SourcesList::VendorRecord *rec = |
---|
| 251 | (SourcesList::VendorRecord *) gtk_clist_get_row_data(GTK_CLIST(me->lstVendors), row); |
---|
| 252 | assert(rec); |
---|
| 253 | |
---|
| 254 | me->lst.RemoveVendor(rec); |
---|
| 255 | gtk_clist_remove(GTK_CLIST(me->lstVendors), row); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | void RGVendorsEditor::DoOK(GtkWidget *, gpointer data) |
---|
| 259 | { |
---|
| 260 | DoEdit(NULL, data); |
---|
| 261 | RGVendorsEditor *me = (RGVendorsEditor *) data; |
---|
| 262 | me->lst.UpdateVendors(); |
---|
| 263 | gtk_main_quit(); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | void RGVendorsEditor::DoCancel(GtkWidget *, gpointer data) |
---|
| 267 | { |
---|
| 268 | //GtkUI::SrcEditor *This = (GtkUI::SrcEditor *)data; |
---|
| 269 | gtk_main_quit(); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | void RGVendorsEditor::UnselectRow(GtkCList * clist, gint row, gint col, |
---|
| 273 | GdkEventButton * event, gpointer data) |
---|
| 274 | { |
---|
| 275 | DoEdit(NULL, data); |
---|
| 276 | RGVendorsEditor *me = (RGVendorsEditor *) data; |
---|
| 277 | me->selectedrow = -1; |
---|
| 278 | |
---|
| 279 | gtk_entry_set_text(GTK_ENTRY(me->entryVendor), ""); |
---|
| 280 | gtk_entry_set_text(GTK_ENTRY(me->entryDesc), ""); |
---|
| 281 | gtk_entry_set_text(GTK_ENTRY(me->entryFPrint), ""); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | void RGVendorsEditor::UpdateDisplay(GtkCList * clist, gint row, gint col, |
---|
| 285 | GdkEventButton * event, gpointer data) |
---|
| 286 | { |
---|
| 287 | DoEdit(NULL, data); |
---|
| 288 | RGVendorsEditor *me = (RGVendorsEditor *) data; |
---|
| 289 | me->selectedrow = row; |
---|
| 290 | |
---|
| 291 | const SourcesList::VendorRecord &rec = |
---|
| 292 | *((SourcesList::VendorRecord *) gtk_clist_get_row_data(clist, row)); |
---|
| 293 | |
---|
| 294 | gtk_entry_set_text(GTK_ENTRY(me->entryVendor), rec.VendorID.c_str()); |
---|
| 295 | gtk_entry_set_text(GTK_ENTRY(me->entryDesc), rec.Description.c_str()); |
---|
| 296 | gtk_entry_set_text(GTK_ENTRY(me->entryFPrint), rec.FingerPrint.c_str()); |
---|
| 297 | } |
---|