/*************************************************************************** * idactionwindow.cpp * * Mon Jun 27 00:30:00 2005 * Copyright 2005 User * Email ****************************************************************************/ #include "idactionwindow.h" IDActionWindow::IDActionWindow(userEventType eType, IDActionCallback cb, gpointer cbdata, gchar* introText, gchar* titleText, gboolean cvisible, gchar* toggleText, gboolean toggleBtnToggled, gchar* btnText, gchar* logoImg) { wType = eType; callBack = cb; callBackData = cbdata; introText? intro = g_strdup_printf("%s", introText): intro = NULL; toggleText? toggleButtonText = g_strdup(toggleText): toggleButtonText = NULL; commentVisible = cvisible; toggleButtonToggled = toggleBtnToggled; title = g_strdup(titleText); btnText? buttonText = g_strdup(btnText): btnText = NULL; if (logoImg) logoImageName = g_strdup_printf("%sicqnd/%s", SHARE_DIR, logoImg); else logoImageName = NULL; } IDActionWindow::~IDActionWindow() { if (intro) g_free(intro); if (toggleButtonText) g_free(toggleButtonText); if (buttonText) g_free(buttonText); if (logoImageName) g_free(logoImageName); } GtkWidget* IDActionWindow::createWindowContent() { GtkWidget *label1, *label2, *img1, *hbox1, *vbox1, *vbox2, *vbox3, *notebook, *table1, *cBox; gchar *fstr; // create the intro text and load the image label1 = gtk_label_new(intro); gtk_widget_set_size_request(label1, 250, -1); gtk_label_set_use_markup(GTK_LABEL(label1), TRUE); gtk_label_set_line_wrap(GTK_LABEL(label1), TRUE); gtk_misc_set_alignment(GTK_MISC(label1), 0.0f, 0.5f); hbox1 = gtk_hbox_new(FALSE, 10); if (logoImageName) { img1 = gtk_image_new_from_file(logoImageName); gtk_box_pack_start(GTK_BOX(hbox1), img1, FALSE, FALSE, 0); } gtk_box_pack_start(GTK_BOX(hbox1), label1, FALSE, TRUE, 0); // create the id entry and the proto box label1 = gtk_label_new(tr("User ID:")); gtk_misc_set_alignment(GTK_MISC(label1), 0.0f, 0.5f); idEdit = gtk_entry_new(); label2 = gtk_label_new(tr("Protocol:")); table1 = gtk_table_new(toggleButtonText? 3: 2, 2, FALSE); gtk_table_set_row_spacings(GTK_TABLE(table1), 2); gtk_table_set_col_spacings(GTK_TABLE(table1), 2); gtk_table_attach(GTK_TABLE(table1), label1, 0, 1, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); gtk_table_attach_defaults(GTK_TABLE(table1), idEdit, 1, 2, 0, 1); gtk_table_attach(GTK_TABLE(table1), label2, 0, 1, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0); gtk_table_attach_defaults(GTK_TABLE(table1), createProtoList(), 1, 2, 1, 2); // create the toggle box if (toggleButtonText) { toggleButton = gtk_check_button_new_with_mnemonic(toggleButtonText); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggleButton), toggleButtonToggled); gtk_table_set_row_spacing(GTK_TABLE(table1), 2, 7); gtk_table_attach_defaults(GTK_TABLE(table1), toggleButton, 1, 2, 2, 3); } // pack everything into a vbox vbox2 = gtk_vbox_new(FALSE, 15); gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5); gtk_box_pack_start(GTK_BOX(vbox2), hbox1, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox2), table1, FALSE, TRUE, 0); if (commentVisible) { // create the comment box and label label1 = gtk_label_new(""); fstr = g_strdup_printf("%s", tr("Please enter a short comment or a description here")); gtk_label_set_markup(GTK_LABEL(label1), fstr); g_free(fstr); gtk_label_set_line_wrap(GTK_LABEL(label1), TRUE); gtk_misc_set_alignment(GTK_MISC(label1), 0.0f, 0.0f); cBox = u_createTextView(&commentBox); vbox1 = gtk_vbox_new(FALSE, 2); gtk_box_pack_start(GTK_BOX(vbox1), label1, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox1), cBox, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox2), vbox1, TRUE, TRUE, 0); } // add a "notebook" around it notebook = gtk_notebook_new(); gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, NULL); // create a big vbox vbox3 = gtk_vbox_new(FALSE, 10); gtk_container_set_border_width(GTK_CONTAINER(vbox3), 10); gtk_box_pack_start(GTK_BOX(vbox3), notebook, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox3), createButtonbar(), FALSE, TRUE, 0); if (!commentVisible) setWindowSize(300, 230); else setWindowSize(300, 400); return vbox3; /* GtkWidget *vbox, *introLabel, *commentLabel, *label, *table, *cBox, *alignment; GList *owners; GtkCellRenderer *renderer; GtkListStore *protoStore; GtkTreeIter iter; introLabel = gtk_label_new(intro); gtk_label_set_use_markup(GTK_LABEL(introLabel), TRUE); gtk_label_set_line_wrap(GTK_LABEL(introLabel), TRUE); gtk_misc_set_alignment(GTK_MISC(introLabel), 0.0f, 0.5f); table = gtk_table_new(2, 2, FALSE); // create id row label = gtk_label_new(tr("User ID:")); gtk_widget_set_size_request(label, 110, -1); \ gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f); idEdit = gtk_entry_new(); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0); gtk_table_attach_defaults(GTK_TABLE(table), idEdit, 1, 2, 0, 1); // create protocol list label = gtk_label_new(tr("Protocol:")); gtk_widget_set_size_request(label, 110, -1); \ gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0); gtk_table_attach_defaults(GTK_TABLE(table), idProtocolList, 1, 2, 1, 2); // create the toggle button if (toggleButtonText) { toggleButton = gtk_check_button_new_with_mnemonic(toggleButtonText); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggleButton), toggleButtonToggled); } if (commentVisible) { // create the comment box and label commentLabel = gtk_label_new(""); gtk_label_set_markup(GTK_LABEL(commentLabel), tr("Please enter a short comment or a description here")); gtk_label_set_line_wrap(GTK_LABEL(commentLabel), TRUE); gtk_misc_set_alignment(GTK_MISC(commentLabel), 0.0f, 0.0f); alignment = gtk_alignment_new(0.0f, 0.0f, 1.0f, 1.0f); gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 5, 0, 0, 0); gtk_container_add(GTK_CONTAINER(alignment), commentLabel); cBox = u_createTextView(&commentBox); } // create the main vbox vbox = gtk_vbox_new(FALSE, 2); gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); gtk_box_pack_start(GTK_BOX(vbox), introLabel, FALSE, TRUE, 1); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, TRUE, 1); if (toggleButtonText) gtk_box_pack_start(GTK_BOX(vbox), toggleButton, FALSE, TRUE, 0); if (commentVisible) { gtk_box_pack_start(GTK_BOX(vbox), alignment, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), cBox, TRUE, TRUE, 0); } gtk_box_pack_start(GTK_BOX(vbox), createButtonbar(), FALSE, TRUE, 0); return vbox; */ } void IDActionWindow::destroyWindowContent() { } GtkWidget* IDActionWindow::createProtoList() { GList *owners; GtkCellRenderer *renderer; GtkListStore *protoStore; GtkTreeIter iter; protoStore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT); idProtocolList = gtk_combo_box_new_with_model(GTK_TREE_MODEL(protoStore)); g_object_unref(protoStore); renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(idProtocolList), renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(idProtocolList), renderer, "text", 0, NULL); // idProtocolList = gtk_combo_box_new_text(); owners = IO_getOwnerList(); if (g_list_length(owners)<=1) gtk_widget_set_sensitive(idProtocolList, FALSE); while(owners) { gtk_list_store_append(protoStore, &iter); gtk_list_store_set(protoStore, &iter, 0, ((IMOwnerDaemon*)owners->data)->protocol->name, 1, ((IMOwnerDaemon*)owners->data)->info->pluginID, -1); owners = owners->next; } gtk_combo_box_set_active(GTK_COMBO_BOX(idProtocolList), 0); return idProtocolList; } GtkWidget* IDActionWindow::createButtonbar() { GtkWidget *hbox, *okayButton, *cancelButton; okayButton = u_createTextStockImageButton(buttonText? buttonText: (gchar*)tr("_Send"), GTK_STOCK_OK); g_signal_connect_swapped(okayButton, "clicked", G_CALLBACK(this->cb_sendButtonClicked), this); cancelButton = gtk_button_new_from_stock(GTK_STOCK_CANCEL); g_signal_connect_swapped(cancelButton, "clicked", G_CALLBACK(this->cb_cancelButtonClicked), this); hbox = gtk_hbox_new(FALSE, 2); gtk_box_pack_end(GTK_BOX(hbox), cancelButton, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(hbox), okayButton, FALSE, FALSE, 0); return hbox; } void IDActionWindow::closeWindow() { if (callBack) callBack(wType, REQUEST_CLOSED, NULL, 0, NULL, FALSE, callBackData); basicWindow::closeWindow(); } void IDActionWindow::cb_sendButtonClicked(IDActionWindow* self) { GtkTreeIter iter; GtkTextIter startIter, endIter; guint ppid; gchar *comment; gboolean toggled; gtk_combo_box_get_active_iter(GTK_COMBO_BOX(self->idProtocolList), &iter); gtk_tree_model_get(GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(self->idProtocolList))), &iter, 1, &ppid, -1); if (self->commentVisible) { gtk_text_buffer_get_bounds(gtk_text_view_get_buffer(GTK_TEXT_VIEW(self->commentBox)), &startIter, &endIter); comment = gtk_text_buffer_get_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(self->commentBox)), &startIter, &endIter, FALSE); } else comment = NULL; self->toggleButtonText? toggled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->toggleButton)): toggled = FALSE; if (self->callBack) self->callBack(self->wType, REQUEST_ACCEPTED, (gchar*)gtk_entry_get_text(GTK_ENTRY(self->idEdit)), ppid, comment, toggled, self->callBackData); if (comment) g_free(comment); self->destroyWindow(); delete self; } void IDActionWindow::cb_cancelButtonClicked(IDActionWindow* self) { if (self->callBack) self->callBack(self->wType, REQUEST_CLOSED, NULL, 0, NULL, FALSE, self->callBackData); self->destroyWindow(); delete self; }