/*************************************************************************** * ownermanwindow.cpp * * Wed Jul 20 22:21:52 2005 * Copyright 2005 User * Email ****************************************************************************/ #include "ownermanwindow.h" ownerManagerWindow::ownerManagerWindow() { wType = UE_MANAGEOWNERS; } ownerManagerWindow::~ownerManagerWindow() { } GtkWidget* ownerManagerWindow::createWindowContent() { GtkWidget *mainVBox; mainVBox = gtk_vbox_new(FALSE, 10); gtk_container_set_border_width(GTK_CONTAINER(mainVBox), 10); gtk_box_pack_start(GTK_BOX(mainVBox), createProtocolsList(), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(mainVBox), createButtonbar(), FALSE, TRUE, 0); setWindowSize(420, 260); setWindowTitle(tr("IcQnD Owner Manager")); IO_getGeneralSource()->addCallback((IMEventCallback)this->cb_eventCallback, this); return mainVBox; } GtkWidget* ownerManagerWindow::createProtocolsList() { GList *search; IMOwnerDaemon *currentOwner; GtkTreeIter iter; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkWidget *scrolled; // create the store protoStore = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); search = IO_getOwnerList(); while(search) { currentOwner = (IMOwnerDaemon*)search->data; gtk_list_store_append(protoStore, &iter); gtk_list_store_set(protoStore, &iter, 0, currentOwner->info->licqID, 1, currentOwner->protocol->name, 2, currentOwner, -1); search = search->next; } // create the view protoView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(protoStore)); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(protoView), TRUE); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(protoView), TRUE); g_signal_connect_swapped(gtk_tree_view_get_selection(GTK_TREE_VIEW(protoView)), "changed", G_CALLBACK(this->cb_protocolsListCursorChanged), this); g_signal_connect_swapped(protoView, "row-activated", G_CALLBACK(this->cb_modifyButtonClicked), this); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("User ID", renderer, "text", 0, NULL); gtk_tree_view_column_set_expand(column, TRUE); gtk_tree_view_append_column(GTK_TREE_VIEW(protoView), column); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("Protocol", renderer, "text", 1, NULL); gtk_tree_view_column_set_expand(column, TRUE); gtk_tree_view_append_column(GTK_TREE_VIEW(protoView), column); // create a scrolled window around the list scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(scrolled), protoView); return scrolled; } GtkWidget* ownerManagerWindow::createButtonbar() { GtkWidget *hbox, *closeButton; GtkSizeGroup *group; group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); addButton = u_createTextStockImageButton(tr("Add"), GTK_STOCK_ADD); g_signal_connect_swapped(addButton, "clicked", G_CALLBACK(this->cb_addButtonClicked), this); gtk_size_group_add_widget(group, addButton); removeButton = u_createTextStockImageButton(tr("Remove"), GTK_STOCK_REMOVE); g_signal_connect_swapped(removeButton, "clicked", G_CALLBACK(this->cb_removeButtonClicked), this); gtk_size_group_add_widget(group, removeButton); modifyButton = u_createTextStockImageButton(tr("Personal Info"), GTK_STOCK_PROPERTIES); g_signal_connect_swapped(modifyButton, "clicked", G_CALLBACK(this->cb_modifyButtonClicked), this); // gtk_size_group_add_widget(group, modifyButton); closeButton = gtk_button_new_from_stock(GTK_STOCK_CLOSE); g_signal_connect_swapped(closeButton, "clicked", G_CALLBACK(this->cb_closeButtonClicked), this); gtk_size_group_add_widget(group, closeButton); hbox = gtk_hbox_new(FALSE, 2); gtk_box_pack_start(GTK_BOX(hbox), addButton, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), removeButton, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), modifyButton, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(hbox), closeButton, FALSE, FALSE, 0); return hbox; } gboolean ownerManagerWindow::eventCallback(gint command, gint lastResult, gpointer info) { IMOwnerDaemon *newOwner; GtkTreeIter iter; GtkTreePath *path; switch(command) { case PC_NEWOWNER: newOwner = (IMOwnerDaemon*)info; gtk_list_store_append(protoStore, &iter); gtk_list_store_set(protoStore, &iter, 0, newOwner->info->licqID, 1, newOwner->protocol->name, 2, newOwner, -1); path = gtk_tree_model_get_path(GTK_TREE_MODEL(protoStore), &iter); gtk_tree_view_set_cursor(GTK_TREE_VIEW(protoView), path, NULL, FALSE); gtk_tree_path_free(path); break; case PC_REMOVEOWNER: if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(protoStore), &iter)) do { gtk_tree_model_get(GTK_TREE_MODEL(protoStore), &iter, 2, &newOwner, -1); if (newOwner == info) { gtk_list_store_remove(protoStore, &iter); cb_protocolsListCursorChanged(this); break; } } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(protoStore), &iter)); break; } return TRUE; } void ownerManagerWindow::destroyWindowContent() { IO_getGeneralSource()->removeCallback((IMEventCallback)this->cb_eventCallback); } void ownerManagerWindow::cb_protocolsListCursorChanged(ownerManagerWindow* self) { GtkTreePath *path; gtk_tree_view_get_cursor(GTK_TREE_VIEW(self->protoView), &path, NULL); if (!path) { gtk_widget_set_sensitive(self->removeButton, FALSE); gtk_widget_set_sensitive(self->modifyButton, FALSE); } else { gtk_widget_set_sensitive(self->removeButton, TRUE); gtk_widget_set_sensitive(self->modifyButton, TRUE); gtk_tree_path_free(path); } } void ownerManagerWindow::cb_addButtonClicked(ownerManagerWindow* self) { GList *pluginSearch; IMPluginDaemon *currentPlugin; // check whether it is possible to add new accounts pluginSearch = IO_getPluginsList(); while(pluginSearch) { currentPlugin = (IMPluginDaemon*)pluginSearch->data; if (currentPlugin->isLoaded && currentPlugin->isProtoPlugin && !currentPlugin->owners) break; pluginSearch = pluginSearch->next; } if (!pluginSearch) u_showAlertMessage(tr("No adding possible"), tr("Currently only one owner per loaded protocol is allowed, this will change in the future.\n\nAll of your loaded protocols already contain a user. Please check your loaded Plugins (Options->Plugins) or download new protocol plugins from www.licq.org. Sorry"), GTK_STOCK_DIALOG_WARNING); else IO_getGeneralSource()->startCallback(UE_UNDEFINED, EC_FROMMANAGER, UE_REGISTEROWNER, NULL); } void ownerManagerWindow::cb_removeButtonClicked(ownerManagerWindow* self) { GtkTreePath *path; GtkTreeIter iter; IMOwnerDaemon *owner; gchar *msg; gtk_tree_view_get_cursor(GTK_TREE_VIEW(self->protoView), &path, NULL); if (!path) return; gtk_tree_model_get_iter(GTK_TREE_MODEL(self->protoStore), &iter, path); gtk_tree_path_free(path); gtk_tree_model_get(GTK_TREE_MODEL(self->protoStore), &iter, 2, &owner, -1); msg = g_strdup_printf(tr("Do you really want to remove the account %s (%s) from Licq?\nAll contacts that this account contains will be removed with their history as well!"), owner->info->licqID, owner->protocol->name); if (u_showYesNoDialog(tr("Really remove?"), msg, GTK_STOCK_DIALOG_QUESTION, FALSE) == GTK_RESPONSE_YES) owner->protocol->removeOwner(owner); g_free(msg); } void ownerManagerWindow::cb_closeButtonClicked(ownerManagerWindow* self) { self->destroyWindow(); delete self; } void ownerManagerWindow::cb_modifyButtonClicked(ownerManagerWindow* self) { GtkTreePath *path; GtkTreeIter iter; IMOwnerDaemon *owner; gtk_tree_view_get_cursor(GTK_TREE_VIEW(self->protoView), &path, NULL); if (!path) return; gtk_tree_model_get_iter(GTK_TREE_MODEL(self->protoStore), &iter, path); gtk_tree_path_free(path); gtk_tree_model_get(GTK_TREE_MODEL(self->protoStore), &iter, 2, &owner, -1); owner->startCallback(EC_FROMMANAGER, UE_USERINFO, owner); }