Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gtk-3.0\gtk\gtk.h>
- #include <windows.h>
- #include "bu.h"
- #include "folder.h"
- #include <string>
- enum
- {
- LIST_ITEM = 0, N_COLUMNS
- };
- typedef struct t_WINDOWSCBSD
- {
- GtkWidget *window, *sourceEntry;
- } WINDOWSCBSD;
- GtkWidget *list;
- static void browseFile(GtkWidget *button, gpointer data)
- {
- WINDOWSCBSD *myData = (struct t_WINDOWSCBSD *)data;
- std::string path;
- GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
- GtkWidget *dialog = gtk_file_chooser_dialog_new("Open File", GTK_WINDOW(myData->window), action, "_Cancel", GTK_RESPONSE_CANCEL, "_Open", GTK_RESPONSE_ACCEPT, NULL);
- gint res = gtk_dialog_run(GTK_DIALOG(dialog));
- if(res == GTK_RESPONSE_ACCEPT)
- {
- char *filename;
- GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
- filename = gtk_file_chooser_get_filename(chooser);
- path = filename;
- gtk_entry_set_text(GTK_ENTRY(myData->sourceEntry), path.c_str());
- g_free(filename);
- }
- gtk_widget_destroy(dialog);
- }
- void appendItem(GtkWidget *widget, gpointer entry)
- {
- GtkListStore *store;
- GtkTreeIter iter;
- const gchar *str = gtk_entry_get_text(GTK_ENTRY(entry));
- store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, LIST_ITEM, str, -1);
- gtk_entry_set_text(GTK_ENTRY(entry), "");
- }
- void removeItem(GtkWidget *widget, gpointer selection)
- {
- GtkListStore *store;
- GtkTreeModel *model;
- GtkTreeIter iter;
- store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
- model = gtk_tree_view_get_model(GTK_TREE_VIEW(list));
- if(gtk_tree_model_get_iter_first(model, &iter) == FALSE)
- {
- return;
- }
- if(gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter))
- {
- gtk_list_store_remove(store, &iter);
- }
- }
- void removeAllItem(GtkWidget *widget, gpointer selection)
- {
- GtkListStore *store;
- GtkTreeModel *model;
- GtkTreeIter iter;
- store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
- model = gtk_tree_view_get_model(GTK_TREE_VIEW(list));
- if(gtk_tree_model_get_iter_first(model, &iter) == FALSE)
- {
- return;
- }
- gtk_list_store_clear(store);
- }
- void initlist(GtkWidget *list)
- {
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
- GtkListStore *store;
- renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes("List Item", renderer, "text", LIST_ITEM, NULL);
- gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
- store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING);
- gtk_tree_view_set_model(GTK_TREE_VIEW(list), GTK_TREE_MODEL(store));
- g_object_unref(store);
- }
- int main(int argc, char *argv[])
- {
- WINDOWSCBSD data;
- GtkWidget *window, *sw, *grid, *label, *sourceEntry, *browse, *buttonBrowse, *add, *buttonLabelAdd, *remove, *buttonLabelRemove, *removeAll, *buttonLabelRemoveAll, *img;
- GtkTreeSelection *selection;
- GdkPixbuf *iconTitle, *iconButton;
- GtkImage *imgButton=NULL;
- gtk_init(&argc, &argv);
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window), "Backup");
- gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
- gtk_container_set_border_width(GTK_CONTAINER (window), 10);
- gtk_widget_set_size_request(window, 500, 260);
- gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
- iconTitle = gdk_pixbuf_new_from_inline(-1, icon_1, false, NULL);
- gtk_window_set_icon(GTK_WINDOW(window), iconTitle);
- data.window = window;
- g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
- grid = gtk_grid_new();
- gtk_grid_set_row_spacing(GTK_GRID(grid), 7);
- gtk_container_add(GTK_CONTAINER(window), grid);//window
- list = gtk_tree_view_new();
- gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE);
- gtk_widget_set_size_request(list, 485, 150);
- initlist(list);
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
- gtk_grid_attach(GTK_GRID(grid), list, 0, 0, 6, 1);
- label = gtk_label_new(NULL);
- gtk_label_set_markup(GTK_LABEL(label), "<b>Select source : </b>");
- gtk_widget_set_halign(label, GTK_ALIGN_START);
- gtk_grid_attach(GTK_GRID(grid), label, 0, 1, 1, 1);
- sourceEntry = gtk_entry_new();
- gtk_widget_set_size_request(sourceEntry, 75, 18);
- gtk_grid_attach_next_to(GTK_GRID(grid), sourceEntry, label, GTK_POS_RIGHT, 4, 1);
- data.sourceEntry = sourceEntry;
- browse = gtk_button_new_with_label(NULL);
- gtk_widget_set_size_request(browse, 32, 32);
- iconButton = gdk_pixbuf_new_from_inline(-1, icon_2, false, NULL);
- img = gtk_image_new_from_pixbuf(iconButton);
- gtk_button_set_image(GTK_BUTTON(browse), img);
- gtk_button_set_relief(GTK_BUTTON(browse), GTK_RELIEF_NONE);
- gtk_widget_set_tooltip_text(browse, "Select source directory");
- gtk_grid_attach_next_to(GTK_GRID(grid), browse, sourceEntry, GTK_POS_RIGHT, 1, 1);
- g_signal_connect(G_OBJECT(browse), "clicked", G_CALLBACK(browseFile), &data);
- add = gtk_button_new_with_label((gchar *)"Add");
- buttonLabelAdd = gtk_bin_get_child(GTK_BIN(add));
- gtk_label_set_markup(GTK_LABEL(buttonLabelAdd), "<b>Add</b>");
- gtk_widget_set_halign(add, GTK_ALIGN_END);
- gtk_grid_attach(GTK_GRID(grid), add, 1, 2, 1, 1);
- g_signal_connect(G_OBJECT(add), "clicked", G_CALLBACK(appendItem), sourceEntry);
- remove = gtk_button_new_with_label((gchar *)"Remove");
- buttonLabelRemove = gtk_bin_get_child(GTK_BIN(remove));
- gtk_label_set_markup(GTK_LABEL(buttonLabelRemove), "<b>Remove</b>");
- gtk_grid_attach_next_to(GTK_GRID(grid), remove, add, GTK_POS_RIGHT, 1, 1);
- g_signal_connect(G_OBJECT(remove), "clicked", G_CALLBACK(removeItem), selection);
- removeAll = gtk_button_new_with_label((gchar *)"Remove All");
- buttonLabelRemoveAll = gtk_bin_get_child(GTK_BIN(removeAll));
- gtk_label_set_markup(GTK_LABEL(buttonLabelRemoveAll), "<b>Remove All</b>");
- gtk_grid_attach_next_to(GTK_GRID(grid), removeAll, remove, GTK_POS_RIGHT, 1, 1);
- g_signal_connect(G_OBJECT(removeAll), "clicked", G_CALLBACK(removeAllItem), selection);
- gtk_widget_grab_focus(sourceEntry);
- gtk_widget_show_all(window);
- gtk_main();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement