[280] | 1 | /* rgrepositorywin.cc - gtk editor for the sources.list file |
---|
| 2 | * |
---|
| 3 | * Copyright (c) (c) 1999 Patrick Cole <z@amused.net> |
---|
| 4 | * (c) 2002 Synaptic development team |
---|
| 5 | * |
---|
| 6 | * Author: Patrick Cole <z@amused.net> |
---|
| 7 | * Michael Vogt <mvo@debian.org> |
---|
| 8 | * Gustavo Niemeyer <niemeyer@conectiva.com> |
---|
| 9 | * |
---|
| 10 | * This program is free software; you can redistribute it and/or |
---|
| 11 | * modify it under the terms of the GNU General Public License as |
---|
| 12 | * published by the Free Software Foundation; either version 2 of the |
---|
| 13 | * License, or (at your option) any later version. |
---|
| 14 | * |
---|
| 15 | * This program is distributed in the hope that it will be useful, |
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | * GNU General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with this program; if not, write to the Free Software |
---|
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
| 23 | * USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <apt-pkg/error.h> |
---|
| 27 | #include <apt-pkg/configuration.h> |
---|
| 28 | #include <apt-pkg/sourcelist.h> |
---|
| 29 | #include <glib.h> |
---|
| 30 | #include <cassert> |
---|
| 31 | #include "rgrepositorywin.h" |
---|
| 32 | #include "rguserdialog.h" |
---|
| 33 | #include "rgmisc.h" |
---|
| 34 | #include "config.h" |
---|
| 35 | #include "i18n.h" |
---|
| 36 | |
---|
| 37 | #if HAVE_RPM |
---|
| 38 | enum { ITEM_TYPE_RPM, |
---|
| 39 | ITEM_TYPE_RPMSRC, |
---|
| 40 | ITEM_TYPE_RPMDIR, |
---|
| 41 | ITEM_TYPE_RPMSRCDIR, |
---|
| 42 | ITEM_TYPE_REPOMD, |
---|
| 43 | ITEM_TYPE_REPOMDSRC, |
---|
| 44 | ITEM_TYPE_DEB, |
---|
| 45 | ITEM_TYPE_DEBSRC |
---|
| 46 | }; |
---|
| 47 | #else |
---|
| 48 | enum { ITEM_TYPE_DEB, |
---|
| 49 | ITEM_TYPE_DEBSRC, |
---|
| 50 | ITEM_TYPE_RPM, |
---|
| 51 | ITEM_TYPE_RPMSRC, |
---|
| 52 | ITEM_TYPE_RPMDIR, |
---|
| 53 | ITEM_TYPE_RPMSRCDIR, |
---|
| 54 | ITEM_TYPE_REPOMD, |
---|
| 55 | ITEM_TYPE_REPOMDSRC |
---|
| 56 | }; |
---|
| 57 | #endif |
---|
| 58 | |
---|
| 59 | enum { |
---|
| 60 | STATUS_COLUMN, |
---|
| 61 | TYPE_COLUMN, |
---|
| 62 | VENDOR_COLUMN, |
---|
| 63 | URI_COLUMN, |
---|
| 64 | DISTRIBUTION_COLUMN, |
---|
| 65 | SECTIONS_COLUMN, |
---|
| 66 | RECORD_COLUMN, |
---|
| 67 | DISABLED_COLOR_COLUMN, |
---|
| 68 | N_SOURCES_COLUMNS |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | void RGRepositoryEditor::item_toggled(GtkCellRendererToggle *cell, |
---|
| 72 | gchar *path_str, gpointer data) |
---|
| 73 | { |
---|
| 74 | RGRepositoryEditor *me = (RGRepositoryEditor *)g_object_get_data(G_OBJECT(cell), "me"); |
---|
| 75 | GtkTreeModel *model = (GtkTreeModel *) data; |
---|
| 76 | GtkTreePath *path = gtk_tree_path_new_from_string(path_str); |
---|
| 77 | GtkTreeIter iter; |
---|
| 78 | gboolean toggle_item; |
---|
| 79 | gchar *section = NULL; |
---|
| 80 | |
---|
| 81 | /* get toggled iter */ |
---|
| 82 | gtk_tree_model_get_iter(model, &iter, path); |
---|
| 83 | gtk_tree_model_get(model, &iter, |
---|
| 84 | STATUS_COLUMN, &toggle_item, |
---|
| 85 | SECTIONS_COLUMN, §ion, -1); |
---|
| 86 | |
---|
| 87 | /* do something with the value */ |
---|
| 88 | toggle_item ^= 1; |
---|
| 89 | |
---|
| 90 | // special warty check |
---|
| 91 | if(toggle_item && section && g_strrstr(section, "universe")) { |
---|
| 92 | gchar *msg = _("You are adding the \"universe\" component.\n\n " |
---|
| 93 | "Packages in this component are not supported. " |
---|
| 94 | "Are you sure?"); |
---|
| 95 | if(!me->_userDialog->message(msg, RUserDialog::DialogWarning, |
---|
| 96 | RUserDialog::ButtonsOkCancel)) { |
---|
| 97 | gtk_tree_path_free(path); |
---|
| 98 | g_free(section); |
---|
| 99 | return; |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /* set new value */ |
---|
| 104 | gtk_list_store_set(GTK_LIST_STORE(model), &iter, |
---|
| 105 | STATUS_COLUMN, toggle_item, -1); |
---|
| 106 | |
---|
| 107 | me->_dirty = true; |
---|
| 108 | |
---|
| 109 | /* clean up */ |
---|
| 110 | g_free(section); |
---|
| 111 | gtk_tree_path_free(path); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | RGRepositoryEditor::RGRepositoryEditor(RGWindow *parent) |
---|
| 116 | : RGGladeWindow(parent, "repositories"), _dirty(false) |
---|
| 117 | { |
---|
| 118 | //cout << "RGRepositoryEditor::RGRepositoryEditor(RGWindow *parent)"<<endl; |
---|
| 119 | assert(_win); |
---|
| 120 | _userDialog = new RGUserDialog(_win); |
---|
| 121 | _applied = false; |
---|
| 122 | _lastIter = NULL; |
---|
| 123 | |
---|
| 124 | setTitle(_("Repositories")); |
---|
| 125 | gtk_window_set_modal(GTK_WINDOW(_win), TRUE); |
---|
| 126 | gtk_window_set_policy(GTK_WINDOW(_win), TRUE, TRUE, FALSE); |
---|
| 127 | |
---|
| 128 | // build gtktreeview |
---|
| 129 | _sourcesListStore = gtk_list_store_new(N_SOURCES_COLUMNS, |
---|
| 130 | G_TYPE_BOOLEAN, |
---|
| 131 | G_TYPE_STRING, |
---|
| 132 | G_TYPE_STRING, |
---|
| 133 | G_TYPE_STRING, |
---|
| 134 | G_TYPE_STRING, |
---|
| 135 | G_TYPE_STRING, |
---|
| 136 | G_TYPE_POINTER, GDK_TYPE_COLOR); |
---|
| 137 | |
---|
| 138 | _sourcesListView = glade_xml_get_widget(_gladeXML, "treeview_repositories"); |
---|
| 139 | gtk_tree_view_set_model(GTK_TREE_VIEW(_sourcesListView), |
---|
| 140 | GTK_TREE_MODEL(_sourcesListStore)); |
---|
| 141 | |
---|
| 142 | GtkCellRenderer *renderer; |
---|
| 143 | GtkTreeViewColumn *column; |
---|
| 144 | |
---|
| 145 | // status |
---|
| 146 | renderer = gtk_cell_renderer_toggle_new(); |
---|
| 147 | g_object_set_data(G_OBJECT(renderer), "me", this); |
---|
| 148 | column = gtk_tree_view_column_new_with_attributes(_("Enabled"), |
---|
| 149 | renderer, |
---|
| 150 | "active", STATUS_COLUMN, |
---|
| 151 | NULL); |
---|
| 152 | g_signal_connect(renderer, "toggled", G_CALLBACK(item_toggled), |
---|
| 153 | GTK_TREE_MODEL(_sourcesListStore)); |
---|
| 154 | gtk_tree_view_append_column(GTK_TREE_VIEW(_sourcesListView), column); |
---|
| 155 | |
---|
| 156 | // type |
---|
| 157 | renderer = gtk_cell_renderer_text_new(); |
---|
| 158 | column = gtk_tree_view_column_new_with_attributes(_("Type"), |
---|
| 159 | renderer, |
---|
| 160 | "text", TYPE_COLUMN, |
---|
| 161 | "foreground-gdk", |
---|
| 162 | DISABLED_COLOR_COLUMN, |
---|
| 163 | NULL); |
---|
| 164 | gtk_tree_view_append_column(GTK_TREE_VIEW(_sourcesListView), column); |
---|
| 165 | |
---|
| 166 | // vendor |
---|
| 167 | renderer = gtk_cell_renderer_text_new(); |
---|
| 168 | column = gtk_tree_view_column_new_with_attributes(_("Vendor"), |
---|
| 169 | renderer, |
---|
| 170 | "text", VENDOR_COLUMN, |
---|
| 171 | "foreground-gdk", |
---|
| 172 | DISABLED_COLOR_COLUMN, |
---|
| 173 | NULL); |
---|
| 174 | gtk_tree_view_append_column(GTK_TREE_VIEW(_sourcesListView), column); |
---|
| 175 | #ifndef HAVE_RPM |
---|
| 176 | gtk_tree_view_column_set_visible(column, FALSE); |
---|
| 177 | #endif |
---|
| 178 | |
---|
| 179 | // uri |
---|
| 180 | renderer = gtk_cell_renderer_text_new(); |
---|
| 181 | column = gtk_tree_view_column_new_with_attributes(_("URI"), |
---|
| 182 | renderer, |
---|
| 183 | "text", URI_COLUMN, |
---|
| 184 | "foreground-gdk", |
---|
| 185 | DISABLED_COLOR_COLUMN, |
---|
| 186 | NULL); |
---|
| 187 | gtk_tree_view_append_column(GTK_TREE_VIEW(_sourcesListView), column); |
---|
| 188 | |
---|
| 189 | // distribution |
---|
| 190 | renderer = gtk_cell_renderer_text_new(); |
---|
| 191 | column = gtk_tree_view_column_new_with_attributes(_("Distribution"), |
---|
| 192 | renderer, |
---|
| 193 | "text", |
---|
| 194 | DISTRIBUTION_COLUMN, |
---|
| 195 | "foreground-gdk", |
---|
| 196 | DISABLED_COLOR_COLUMN, |
---|
| 197 | NULL); |
---|
| 198 | gtk_tree_view_append_column(GTK_TREE_VIEW(_sourcesListView), column); |
---|
| 199 | |
---|
| 200 | // section(s) |
---|
| 201 | renderer = gtk_cell_renderer_text_new(); |
---|
| 202 | column = gtk_tree_view_column_new_with_attributes(_("Section(s)"), |
---|
| 203 | renderer, |
---|
| 204 | "text", SECTIONS_COLUMN, |
---|
| 205 | "foreground-gdk", |
---|
| 206 | DISABLED_COLOR_COLUMN, |
---|
| 207 | NULL); |
---|
| 208 | gtk_tree_view_append_column(GTK_TREE_VIEW(_sourcesListView), column); |
---|
| 209 | |
---|
| 210 | GtkTreeSelection *select; |
---|
| 211 | select = gtk_tree_view_get_selection(GTK_TREE_VIEW(_sourcesListView)); |
---|
| 212 | gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); |
---|
| 213 | g_signal_connect(G_OBJECT(select), "changed", |
---|
| 214 | G_CALLBACK(SelectionChanged), this); |
---|
| 215 | |
---|
| 216 | //_cbEnabled = glade_xml_get_widget(_gladeXML, "checkbutton_enabled"); |
---|
| 217 | |
---|
| 218 | _optType = glade_xml_get_widget(_gladeXML, "optionmenu_type"); |
---|
| 219 | _optTypeMenu = gtk_menu_new(); |
---|
| 220 | |
---|
| 221 | GtkWidget *item; |
---|
| 222 | #if HAVE_RPM |
---|
| 223 | item = gtk_menu_item_new_with_label("rpm"); |
---|
| 224 | gtk_menu_append(GTK_MENU(_optTypeMenu), item); |
---|
| 225 | gtk_widget_show(item); |
---|
| 226 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ITEM_TYPE_RPM); |
---|
| 227 | |
---|
| 228 | item = gtk_menu_item_new_with_label("rpm-src"); |
---|
| 229 | gtk_menu_append(GTK_MENU(_optTypeMenu), item); |
---|
| 230 | gtk_widget_show(item); |
---|
| 231 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ITEM_TYPE_RPMSRC); |
---|
| 232 | |
---|
| 233 | item = gtk_menu_item_new_with_label("rpm-dir"); |
---|
| 234 | gtk_menu_append(GTK_MENU(_optTypeMenu), item); |
---|
| 235 | gtk_widget_show(item); |
---|
| 236 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ITEM_TYPE_RPMDIR); |
---|
| 237 | |
---|
| 238 | item = gtk_menu_item_new_with_label("rpm-src-dir"); |
---|
| 239 | gtk_menu_append(GTK_MENU(_optTypeMenu), item); |
---|
| 240 | gtk_widget_show(item); |
---|
| 241 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ITEM_TYPE_RPMSRCDIR); |
---|
| 242 | |
---|
| 243 | item = gtk_menu_item_new_with_label("repomd"); |
---|
| 244 | gtk_menu_append(GTK_MENU(_optTypeMenu), item); |
---|
| 245 | gtk_widget_show(item); |
---|
| 246 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ITEM_TYPE_REPOMD); |
---|
| 247 | |
---|
| 248 | item = gtk_menu_item_new_with_label("repomd-src"); |
---|
| 249 | gtk_menu_append(GTK_MENU(_optTypeMenu), item); |
---|
| 250 | gtk_widget_show(item); |
---|
| 251 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ITEM_TYPE_REPOMDSRC); |
---|
| 252 | #else |
---|
| 253 | item = gtk_menu_item_new_with_label(_("Binary (deb)")); |
---|
| 254 | gtk_menu_append(GTK_MENU(_optTypeMenu), item); |
---|
| 255 | gtk_widget_show(item); |
---|
| 256 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ITEM_TYPE_DEB); |
---|
| 257 | |
---|
| 258 | item = gtk_menu_item_new_with_label(_("Source (deb-src)")); |
---|
| 259 | gtk_menu_append(GTK_MENU(_optTypeMenu), item); |
---|
| 260 | gtk_widget_show(item); |
---|
| 261 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ITEM_TYPE_DEBSRC); |
---|
| 262 | #endif |
---|
| 263 | gtk_option_menu_set_menu(GTK_OPTION_MENU(_optType), _optTypeMenu); |
---|
| 264 | |
---|
| 265 | _optVendor = glade_xml_get_widget(_gladeXML, "optionmenu_vendor"); |
---|
| 266 | _optVendorMenu = gtk_menu_new(); |
---|
| 267 | item = gtk_menu_item_new_with_label(_("(no vendor)")); |
---|
| 268 | gtk_menu_append(GTK_MENU(_optVendorMenu), item); |
---|
| 269 | gtk_widget_show(item); |
---|
| 270 | gtk_option_menu_set_menu(GTK_OPTION_MENU(_optVendor), _optVendorMenu); |
---|
| 271 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ""); |
---|
| 272 | |
---|
| 273 | #ifndef HAVE_RPM |
---|
| 274 | // debian can't use the vendors menu, so we hide it |
---|
| 275 | gtk_widget_hide(GTK_WIDGET(_optVendor)); |
---|
| 276 | GtkWidget *vendors = glade_xml_get_widget(_gladeXML,"button_edit_vendors"); |
---|
| 277 | assert(vendors); |
---|
| 278 | gtk_widget_hide(GTK_WIDGET(vendors)); |
---|
| 279 | #endif |
---|
| 280 | |
---|
| 281 | _entryURI = glade_xml_get_widget(_gladeXML, "entry_uri"); |
---|
| 282 | assert(_entryURI); |
---|
| 283 | _entryDist = glade_xml_get_widget(_gladeXML, "entry_distribution"); |
---|
| 284 | assert(_entryDist); |
---|
| 285 | _entrySect = glade_xml_get_widget(_gladeXML, "entry_sections"); |
---|
| 286 | assert(_entrySect); |
---|
| 287 | |
---|
| 288 | glade_xml_signal_connect_data(_gladeXML, |
---|
| 289 | "on_button_ok_clicked", |
---|
| 290 | G_CALLBACK(DoOK), this); |
---|
| 291 | |
---|
| 292 | glade_xml_signal_connect_data(_gladeXML, |
---|
| 293 | "on_button_cancel_clicked", |
---|
| 294 | G_CALLBACK(DoCancel), this); |
---|
| 295 | |
---|
| 296 | glade_xml_signal_connect_data(_gladeXML, |
---|
| 297 | "on_button_edit_vendors_clicked", |
---|
| 298 | G_CALLBACK(VendorsWindow), this); |
---|
| 299 | |
---|
| 300 | /* |
---|
| 301 | glade_xml_signal_connect_data(_gladeXML, |
---|
| 302 | "on_button_clear_clicked", |
---|
| 303 | G_CALLBACK(DoClear), |
---|
| 304 | this); |
---|
| 305 | */ |
---|
| 306 | |
---|
| 307 | glade_xml_signal_connect_data(_gladeXML, |
---|
| 308 | "on_button_add_clicked", |
---|
| 309 | G_CALLBACK(DoAdd), this); |
---|
| 310 | |
---|
| 311 | glade_xml_signal_connect_data(_gladeXML, |
---|
| 312 | "on_button_remove_clicked", |
---|
| 313 | G_CALLBACK(DoRemove), this); |
---|
| 314 | |
---|
| 315 | glade_xml_signal_connect_data(_gladeXML, |
---|
| 316 | "on_button_updown_clicked", |
---|
| 317 | G_CALLBACK(DoUpDown), this); |
---|
| 318 | |
---|
| 319 | GtkWidget *button = glade_xml_get_widget(_gladeXML, "button_up"); |
---|
| 320 | g_object_set_data(G_OBJECT(button), "up", GINT_TO_POINTER(1)); |
---|
| 321 | g_object_set_data(G_OBJECT(button), "down", GINT_TO_POINTER(0)); |
---|
| 322 | |
---|
| 323 | _upBut = glade_xml_get_widget(_gladeXML, "button_up"); |
---|
| 324 | assert(_upBut); |
---|
| 325 | gtk_widget_set_sensitive(_upBut, FALSE); |
---|
| 326 | |
---|
| 327 | _downBut = glade_xml_get_widget(_gladeXML, "button_down"); |
---|
| 328 | assert(_downBut); |
---|
| 329 | gtk_widget_set_sensitive(_downBut, FALSE); |
---|
| 330 | |
---|
| 331 | _deleteBut = glade_xml_get_widget(_gladeXML, "button_add"); |
---|
| 332 | assert(_deleteBut); |
---|
| 333 | gtk_widget_set_sensitive(_deleteBut, FALSE); |
---|
| 334 | |
---|
| 335 | _editTable = glade_xml_get_widget(_gladeXML, "table_edit"); |
---|
| 336 | assert(_editTable); |
---|
| 337 | gtk_widget_set_sensitive(_editTable, FALSE); |
---|
| 338 | |
---|
| 339 | gtk_window_resize(GTK_WINDOW(_win), 620, 400); |
---|
| 340 | skipTaskbar(true); |
---|
| 341 | show(); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | |
---|
| 345 | RGRepositoryEditor::~RGRepositoryEditor() |
---|
| 346 | { |
---|
| 347 | //gtk_widget_destroy(_win); |
---|
| 348 | delete _userDialog; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | |
---|
| 352 | bool RGRepositoryEditor::Run() |
---|
| 353 | { |
---|
| 354 | if (_lst.ReadSources() == false) { |
---|
| 355 | _userDialog-> |
---|
| 356 | warning(_("Ignoring invalid record(s) in sources.list file!")); |
---|
| 357 | //return false; |
---|
| 358 | } |
---|
| 359 | // keep a backup of the orginal list |
---|
| 360 | _savedList.ReadSources(); |
---|
| 361 | |
---|
| 362 | if (_lst.ReadVendors() == false) { |
---|
| 363 | _error->Error(_("Cannot read vendors.list file")); |
---|
| 364 | _userDialog->showErrors(); |
---|
| 365 | return false; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | GdkColormap *cmap = gdk_colormap_get_system(); |
---|
| 369 | _gray.red = _gray.green = _gray.blue = 0xAA00; |
---|
| 370 | gdk_color_alloc(cmap, &_gray); |
---|
| 371 | |
---|
| 372 | GtkTreeIter iter; |
---|
| 373 | for (SourcesListIter it = _lst.SourceRecords.begin(); |
---|
| 374 | it != _lst.SourceRecords.end(); it++) { |
---|
| 375 | if ((*it)->Type & SourcesList::Comment) |
---|
| 376 | continue; |
---|
| 377 | string Sections; |
---|
| 378 | for (unsigned int J = 0; J < (*it)->NumSections; J++) { |
---|
| 379 | Sections += (*it)->Sections[J]; |
---|
| 380 | Sections += " "; |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | gtk_list_store_append(_sourcesListStore, &iter); |
---|
| 384 | gtk_list_store_set(_sourcesListStore, &iter, |
---|
| 385 | STATUS_COLUMN, !((*it)->Type & |
---|
| 386 | SourcesList::Disabled), |
---|
| 387 | TYPE_COLUMN, utf8((*it)->GetType().c_str()), |
---|
| 388 | VENDOR_COLUMN, utf8((*it)->VendorID.c_str()), |
---|
| 389 | URI_COLUMN, utf8((*it)->URI.c_str()), |
---|
| 390 | DISTRIBUTION_COLUMN, utf8((*it)->Dist.c_str()), |
---|
| 391 | SECTIONS_COLUMN, utf8(Sections.c_str()), |
---|
| 392 | RECORD_COLUMN, (gpointer) (*it), |
---|
| 393 | DISABLED_COLOR_COLUMN, |
---|
| 394 | (*it)->Type & SourcesList::Disabled ? &_gray : NULL, |
---|
| 395 | -1); |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | |
---|
| 399 | UpdateVendorMenu(); |
---|
| 400 | |
---|
| 401 | gtk_main(); |
---|
| 402 | return _applied; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | void RGRepositoryEditor::UpdateVendorMenu() |
---|
| 406 | { |
---|
| 407 | gtk_option_menu_remove_menu(GTK_OPTION_MENU(_optVendor)); |
---|
| 408 | _optVendorMenu = gtk_menu_new(); |
---|
| 409 | GtkWidget *item = gtk_menu_item_new_with_label(_("(no vendor)")); |
---|
| 410 | gtk_menu_append(GTK_MENU(_optVendorMenu), item); |
---|
| 411 | gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer) ""); |
---|
| 412 | gtk_widget_show(item); |
---|
| 413 | for (VendorsListIter it = _lst.VendorRecords.begin(); |
---|
| 414 | it != _lst.VendorRecords.end(); it++) { |
---|
| 415 | item = gtk_menu_item_new_with_label((*it)->VendorID.c_str()); |
---|
| 416 | gtk_menu_append(GTK_MENU(_optVendorMenu), item); |
---|
| 417 | gtk_widget_show(item); |
---|
| 418 | gtk_object_set_data(GTK_OBJECT(item), "id", |
---|
| 419 | (gpointer) (*it)->VendorID.c_str()); |
---|
| 420 | } |
---|
| 421 | gtk_option_menu_set_menu(GTK_OPTION_MENU(_optVendor), _optVendorMenu); |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | int RGRepositoryEditor::VendorMenuIndex(string VendorID) |
---|
| 425 | { |
---|
| 426 | int index = 0; |
---|
| 427 | for (VendorsListIter it = _lst.VendorRecords.begin(); |
---|
| 428 | it != _lst.VendorRecords.end(); it++) { |
---|
| 429 | index += 1; |
---|
| 430 | if ((*it)->VendorID == VendorID) |
---|
| 431 | return index; |
---|
| 432 | } |
---|
| 433 | return 0; |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | void RGRepositoryEditor::DoClear(GtkWidget *, gpointer data) |
---|
| 437 | { |
---|
| 438 | RGRepositoryEditor *me = (RGRepositoryEditor *) data; |
---|
| 439 | //cout << "RGRepositoryEditor::DoClear(GtkWidget *, gpointer data)"<<endl; |
---|
| 440 | |
---|
| 441 | gtk_option_menu_set_history(GTK_OPTION_MENU(me->_optType), 0); |
---|
| 442 | gtk_option_menu_set_history(GTK_OPTION_MENU(me->_optVendor), 0); |
---|
| 443 | gtk_entry_set_text(GTK_ENTRY(me->_entryURI), ""); |
---|
| 444 | gtk_entry_set_text(GTK_ENTRY(me->_entryDist), ""); |
---|
| 445 | gtk_entry_set_text(GTK_ENTRY(me->_entrySect), ""); |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | void RGRepositoryEditor::DoAdd(GtkWidget *, gpointer data) |
---|
| 449 | { |
---|
| 450 | RGRepositoryEditor *me = (RGRepositoryEditor *) data; |
---|
| 451 | //cout << "RGRepositoryEditor::DoAdd(GtkWidget *, gpointer data)"<<endl; |
---|
| 452 | |
---|
| 453 | SourcesList::SourceRecord *rec = me->_lst.AddEmptySource(); |
---|
| 454 | |
---|
| 455 | GtkTreeIter iter; |
---|
| 456 | gtk_list_store_append(me->_sourcesListStore, &iter); |
---|
| 457 | gtk_list_store_set(me->_sourcesListStore, &iter, |
---|
| 458 | STATUS_COLUMN, 1, |
---|
| 459 | TYPE_COLUMN, "", |
---|
| 460 | VENDOR_COLUMN, "", |
---|
| 461 | URI_COLUMN, "", |
---|
| 462 | DISTRIBUTION_COLUMN, "", |
---|
| 463 | SECTIONS_COLUMN, "", |
---|
| 464 | RECORD_COLUMN, (gpointer) (rec), |
---|
| 465 | DISABLED_COLOR_COLUMN, NULL, -1); |
---|
| 466 | |
---|
| 467 | GtkTreeSelection *selection; |
---|
| 468 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(me->_sourcesListView)); |
---|
| 469 | gtk_tree_selection_unselect_all(selection); |
---|
| 470 | gtk_tree_selection_select_iter(selection, &iter); |
---|
| 471 | |
---|
| 472 | GtkTreePath *path; |
---|
| 473 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(me->_sourcesListStore), &iter); |
---|
| 474 | gtk_tree_view_set_cursor(GTK_TREE_VIEW(me->_sourcesListView), |
---|
| 475 | path, NULL, false); |
---|
| 476 | gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(me->_sourcesListView), path, |
---|
| 477 | NULL, TRUE, 0.0, 0.0); |
---|
| 478 | gtk_tree_path_free(path); |
---|
| 479 | |
---|
| 480 | me->_dirty=true; |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | void RGRepositoryEditor::doEdit() |
---|
| 484 | { |
---|
| 485 | //cout << "RGRepositoryEditor::doEdit()"<<endl; |
---|
| 486 | |
---|
| 487 | |
---|
| 488 | //GtkTreeSelection *selection; |
---|
| 489 | //selection = gtk_tree_view_get_selection(GTK_TREE_VIEW (_sourcesListView)); |
---|
| 490 | if (_lastIter == NULL) { |
---|
| 491 | //cout << "deadbeef"<<endl; |
---|
| 492 | return; |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | GtkTreeModel *model = GTK_TREE_MODEL(_sourcesListStore); |
---|
| 496 | //if (!gtk_tree_selection_get_selected (selection, &model, &iter)) |
---|
| 497 | //return; |
---|
| 498 | |
---|
| 499 | SourcesList::SourceRecord *rec; |
---|
| 500 | gtk_tree_model_get(model, _lastIter, RECORD_COLUMN, &rec, -1); |
---|
| 501 | |
---|
| 502 | rec->Type = 0; |
---|
| 503 | gboolean status; |
---|
| 504 | gtk_tree_model_get(GTK_TREE_MODEL(_sourcesListStore), _lastIter, |
---|
| 505 | STATUS_COLUMN, &status, -1); |
---|
| 506 | if (!status) |
---|
| 507 | rec->Type |= SourcesList::Disabled; |
---|
| 508 | |
---|
| 509 | GtkWidget *menuitem = gtk_menu_get_active(GTK_MENU(_optTypeMenu)); |
---|
| 510 | switch ((long)(gtk_object_get_data(GTK_OBJECT(menuitem), "id"))) { |
---|
| 511 | case ITEM_TYPE_DEB: |
---|
| 512 | rec->Type |= SourcesList::Deb; |
---|
| 513 | break; |
---|
| 514 | case ITEM_TYPE_DEBSRC: |
---|
| 515 | rec->Type |= SourcesList::DebSrc; |
---|
| 516 | break; |
---|
| 517 | case ITEM_TYPE_RPM: |
---|
| 518 | rec->Type |= SourcesList::Rpm; |
---|
| 519 | break; |
---|
| 520 | case ITEM_TYPE_RPMSRC: |
---|
| 521 | rec->Type |= SourcesList::RpmSrc; |
---|
| 522 | break; |
---|
| 523 | case ITEM_TYPE_RPMDIR: |
---|
| 524 | rec->Type |= SourcesList::RpmDir; |
---|
| 525 | break; |
---|
| 526 | case ITEM_TYPE_RPMSRCDIR: |
---|
| 527 | rec->Type |= SourcesList::RpmSrcDir; |
---|
| 528 | break; |
---|
| 529 | case ITEM_TYPE_REPOMD: |
---|
| 530 | rec->Type |= SourcesList::Repomd; |
---|
| 531 | break; |
---|
| 532 | case ITEM_TYPE_REPOMDSRC: |
---|
| 533 | rec->Type |= SourcesList::RepomdSrc; |
---|
| 534 | break; |
---|
| 535 | default: |
---|
| 536 | _userDialog->error(_("Unknown source type")); |
---|
| 537 | return; |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | menuitem = gtk_menu_get_active(GTK_MENU(_optVendorMenu)); |
---|
| 541 | rec->VendorID = (char *)gtk_object_get_data(GTK_OBJECT(menuitem), "id"); |
---|
| 542 | |
---|
| 543 | rec->URI = gtk_entry_get_text(GTK_ENTRY(_entryURI)); |
---|
| 544 | rec->Dist = gtk_entry_get_text(GTK_ENTRY(_entryDist)); |
---|
| 545 | |
---|
| 546 | delete[]rec->Sections; |
---|
| 547 | rec->NumSections = 0; |
---|
| 548 | |
---|
| 549 | const char *Section = gtk_entry_get_text(GTK_ENTRY(_entrySect)); |
---|
| 550 | if (Section != 0 && Section[0] != 0) |
---|
| 551 | rec->NumSections++; |
---|
| 552 | |
---|
| 553 | rec->Sections = new string[rec->NumSections]; |
---|
| 554 | rec->NumSections = 0; |
---|
| 555 | Section = gtk_entry_get_text(GTK_ENTRY(_entrySect)); |
---|
| 556 | |
---|
| 557 | if (Section != 0 && Section[0] != 0) |
---|
| 558 | rec->Sections[rec->NumSections++] = Section; |
---|
| 559 | |
---|
| 560 | string Sect; |
---|
| 561 | for (unsigned int I = 0; I < rec->NumSections; I++) { |
---|
| 562 | Sect += rec->Sections[I]; |
---|
| 563 | Sect += " "; |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | /* repaint screen */ |
---|
| 567 | gtk_list_store_set(_sourcesListStore, _lastIter, |
---|
| 568 | STATUS_COLUMN, !(rec->Type & |
---|
| 569 | SourcesList::Disabled), |
---|
| 570 | TYPE_COLUMN, utf8(rec->GetType().c_str()), |
---|
| 571 | VENDOR_COLUMN, utf8(rec->VendorID.c_str()), |
---|
| 572 | URI_COLUMN, utf8(rec->URI.c_str()), |
---|
| 573 | DISTRIBUTION_COLUMN, utf8(rec->Dist.c_str()), |
---|
| 574 | SECTIONS_COLUMN, utf8(Sect.c_str()), |
---|
| 575 | RECORD_COLUMN, (gpointer) (rec), |
---|
| 576 | DISABLED_COLOR_COLUMN, |
---|
| 577 | (rec->Type & SourcesList::Disabled ? &_gray : NULL), -1); |
---|
| 578 | |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | void RGRepositoryEditor::DoRemove(GtkWidget *, gpointer data) |
---|
| 582 | { |
---|
| 583 | RGRepositoryEditor *me = (RGRepositoryEditor *) data; |
---|
| 584 | //cout << "RGRepositoryEditor::DoRemove(GtkWidget *, gpointer data)"<<endl; |
---|
| 585 | |
---|
| 586 | GtkTreeSelection *selection; |
---|
| 587 | GtkTreeIter iter; |
---|
| 588 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(me->_sourcesListView)); |
---|
| 589 | |
---|
| 590 | if (gtk_tree_selection_get_selected(selection, (GtkTreeModel **) (&me->_sourcesListStore), &iter)) { |
---|
| 591 | SourcesList::SourceRecord *rec; |
---|
| 592 | gtk_tree_model_get(GTK_TREE_MODEL(me->_sourcesListStore), &iter, RECORD_COLUMN, &rec, -1); |
---|
| 593 | assert(rec); |
---|
| 594 | |
---|
| 595 | me->_lst.RemoveSource(rec); |
---|
| 596 | gtk_list_store_remove(me->_sourcesListStore, &iter); |
---|
| 597 | if (me->_lastIter != NULL) |
---|
| 598 | gtk_tree_iter_free(me->_lastIter); |
---|
| 599 | me->_lastIter = NULL; |
---|
| 600 | } |
---|
| 601 | me->_dirty=true; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | void RGRepositoryEditor::DoOK(GtkWidget *, gpointer data) |
---|
| 605 | { |
---|
| 606 | RGRepositoryEditor *me = (RGRepositoryEditor *) data; |
---|
| 607 | |
---|
| 608 | me->doEdit(); |
---|
| 609 | me->_lst.UpdateSources(); |
---|
| 610 | |
---|
| 611 | // check if we actually can parse the sources.list |
---|
| 612 | pkgSourceList List; |
---|
| 613 | if (!List.ReadMainList()) { |
---|
| 614 | me->_userDialog->showErrors(); |
---|
| 615 | me->_savedList.UpdateSources(); |
---|
| 616 | return; |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | gtk_main_quit(); |
---|
| 620 | me->_applied = me->_dirty; |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | void RGRepositoryEditor::DoCancel(GtkWidget *, gpointer data) |
---|
| 624 | { |
---|
| 625 | //RGRepositoryEditor *me = (RGRepositoryEditor *)data; |
---|
| 626 | gtk_main_quit(); |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | |
---|
| 630 | |
---|
| 631 | void RGRepositoryEditor::SelectionChanged(GtkTreeSelection *selection, |
---|
| 632 | gpointer data) |
---|
| 633 | { |
---|
| 634 | RGRepositoryEditor *me = (RGRepositoryEditor *) data; |
---|
| 635 | //cout << "RGRepositoryEditor::SelectionChanged()"<<endl; |
---|
| 636 | |
---|
| 637 | GtkTreeIter iter; |
---|
| 638 | GtkTreeModel *model; |
---|
| 639 | gtk_widget_set_sensitive(me->_editTable, TRUE); |
---|
| 640 | |
---|
| 641 | gtk_widget_set_sensitive(me->_upBut, TRUE); |
---|
| 642 | gtk_widget_set_sensitive(me->_downBut, TRUE); |
---|
| 643 | gtk_widget_set_sensitive(me->_deleteBut, TRUE); |
---|
| 644 | |
---|
| 645 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) { |
---|
| 646 | me->doEdit(); // save the old row |
---|
| 647 | if (me->_lastIter != NULL) |
---|
| 648 | gtk_tree_iter_free(me->_lastIter); |
---|
| 649 | me->_lastIter = gtk_tree_iter_copy(&iter); |
---|
| 650 | |
---|
| 651 | const SourcesList::SourceRecord *rec; |
---|
| 652 | gtk_tree_model_get(model, &iter, RECORD_COLUMN, &rec, -1); |
---|
| 653 | |
---|
| 654 | int id = ITEM_TYPE_DEB; |
---|
| 655 | if (rec->Type & SourcesList::DebSrc) |
---|
| 656 | id = ITEM_TYPE_DEBSRC; |
---|
| 657 | else if (rec->Type & SourcesList::Rpm) |
---|
| 658 | id = ITEM_TYPE_RPM; |
---|
| 659 | else if (rec->Type & SourcesList::RpmSrc) |
---|
| 660 | id = ITEM_TYPE_RPMSRC; |
---|
| 661 | else if (rec->Type & SourcesList::RpmDir) |
---|
| 662 | id = ITEM_TYPE_RPMDIR; |
---|
| 663 | else if (rec->Type & SourcesList::RpmSrcDir) |
---|
| 664 | id = ITEM_TYPE_RPMSRCDIR; |
---|
| 665 | else if (rec->Type & SourcesList::Repomd) |
---|
| 666 | id = ITEM_TYPE_REPOMD; |
---|
| 667 | else if (rec->Type & SourcesList::RepomdSrc) |
---|
| 668 | id = ITEM_TYPE_REPOMDSRC; |
---|
| 669 | gtk_option_menu_set_history(GTK_OPTION_MENU(me->_optType), id); |
---|
| 670 | |
---|
| 671 | gtk_option_menu_set_history(GTK_OPTION_MENU(me->_optVendor), |
---|
| 672 | me->VendorMenuIndex(rec->VendorID)); |
---|
| 673 | |
---|
| 674 | gtk_entry_set_text(GTK_ENTRY(me->_entryURI), utf8(rec->URI.c_str())); |
---|
| 675 | gtk_entry_set_text(GTK_ENTRY(me->_entryDist), utf8(rec->Dist.c_str())); |
---|
| 676 | gtk_entry_set_text(GTK_ENTRY(me->_entrySect), ""); |
---|
| 677 | |
---|
| 678 | for (unsigned int I = 0; I < rec->NumSections; I++) { |
---|
| 679 | gtk_entry_append_text(GTK_ENTRY(me->_entrySect), |
---|
| 680 | utf8(rec->Sections[I].c_str())); |
---|
| 681 | gtk_entry_append_text(GTK_ENTRY(me->_entrySect), " "); |
---|
| 682 | } |
---|
| 683 | } else { |
---|
| 684 | //cout << "no selection" << endl; |
---|
| 685 | gtk_widget_set_sensitive(me->_editTable, FALSE); |
---|
| 686 | |
---|
| 687 | gtk_widget_set_sensitive(me->_upBut, FALSE); |
---|
| 688 | gtk_widget_set_sensitive(me->_downBut, FALSE); |
---|
| 689 | gtk_widget_set_sensitive(me->_deleteBut, FALSE); |
---|
| 690 | } |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | void RGRepositoryEditor::VendorsWindow(GtkWidget *, void *data) |
---|
| 694 | { |
---|
| 695 | RGRepositoryEditor *me = (RGRepositoryEditor *) data; |
---|
| 696 | RGVendorsEditor w(me, me->_lst); |
---|
| 697 | w.Run(); |
---|
| 698 | GtkWidget *menuitem = gtk_menu_get_active(GTK_MENU(me->_optVendorMenu)); |
---|
| 699 | string VendorID = (char *)gtk_object_get_data(GTK_OBJECT(menuitem), "id"); |
---|
| 700 | me->UpdateVendorMenu(); |
---|
| 701 | gtk_option_menu_set_history(GTK_OPTION_MENU(me->_optVendor), |
---|
| 702 | me->VendorMenuIndex(VendorID)); |
---|
| 703 | } |
---|
| 704 | |
---|
| 705 | void RGRepositoryEditor::DoUpDown(GtkWidget *self, gpointer data) |
---|
| 706 | { |
---|
| 707 | RGRepositoryEditor *me = (RGRepositoryEditor *) data; |
---|
| 708 | //cout << "RGRepositoryEditor::DoUpDown(GtkWidget *, gpointer data)"<<endl; |
---|
| 709 | |
---|
| 710 | GtkTreeIter iter; |
---|
| 711 | GtkTreeIter iter2; |
---|
| 712 | |
---|
| 713 | GtkTreeSelection *selection; |
---|
| 714 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(me->_sourcesListView)); |
---|
| 715 | gtk_tree_selection_get_selected (selection, (GtkTreeModel **) (&me->_sourcesListStore), &iter); |
---|
| 716 | |
---|
| 717 | GtkTreePath *path; |
---|
| 718 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(me->_sourcesListStore), &iter); |
---|
| 719 | |
---|
| 720 | // check if it does up or down |
---|
| 721 | gboolean up = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(self), "up")); |
---|
| 722 | if(up) |
---|
| 723 | gtk_tree_path_prev( path ); |
---|
| 724 | else |
---|
| 725 | gtk_tree_path_next( path ); |
---|
| 726 | |
---|
| 727 | if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(me->_sourcesListStore), &iter2, path ) ) |
---|
| 728 | return; |
---|
| 729 | gtk_list_store_swap( me->_sourcesListStore, &iter, &iter2 ); |
---|
| 730 | gtk_tree_path_free(path); |
---|
| 731 | |
---|
| 732 | SourcesList::SourceRecord *rec; |
---|
| 733 | gtk_tree_model_get(GTK_TREE_MODEL(me->_sourcesListStore), &iter, |
---|
| 734 | RECORD_COLUMN, &rec, -1); |
---|
| 735 | assert(rec); |
---|
| 736 | SourcesList::SourceRecord *rec_p; |
---|
| 737 | gtk_tree_model_get(GTK_TREE_MODEL(me->_sourcesListStore), &iter2, |
---|
| 738 | RECORD_COLUMN, &rec_p, -1); |
---|
| 739 | assert(rec_p); |
---|
| 740 | |
---|
| 741 | // Insert rec before rec_p |
---|
| 742 | if(up) |
---|
| 743 | me->_lst.SwapSources(rec_p, rec); |
---|
| 744 | else |
---|
| 745 | me->_lst.SwapSources(rec, rec_p); |
---|
| 746 | } |
---|