1 /* AbiCollab - Code to enable the modification of remote documents.
2  * Copyright (C) 2007 by Ryan Pavlik <abiryan@ryand.net>
3  * Copyright (C) 2006 by Marc Maurer <uwog@uwog.net>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301 USA.
19  */
20 
21 #include <windows.h>
22 #include "xap_App.h"
23 #include "ap_Win32App.h"
24 #include "xap_Win32App.h"
25 #include "xap_Frame.h"
26 #include "xap_Win32DialogHelper.h"
27 #include "ut_string_class.h"
28 #include <session/xp/AbiCollabSessionManager.h>
29 
30 #include "ap_Win32Dialog_CollaborationAddBuddy.h"
31 /*
32 enum
33 {
34 	DESC_COLUMN = 0,
35 	HANDLER_COLUMN
36 };
37 
38 static void s_ok_clicked(GtkWidget * wid, AP_Win32Dialog_CollaborationAddBuddy * dlg)
39 {
40 	dlg->event_Ok();
41 }
42 //*/
static_constructor(XAP_DialogFactory * pFactory,XAP_Dialog_Id id)43 XAP_Dialog * AP_Win32Dialog_CollaborationAddBuddy::static_constructor(XAP_DialogFactory * pFactory, XAP_Dialog_Id id)
44 {
45 	return static_cast<XAP_Dialog *>(new AP_Win32Dialog_CollaborationAddBuddy(pFactory, id));
46 }
47 pt2Constructor ap_Dialog_CollaborationAddBuddy_Constructor = &AP_Win32Dialog_CollaborationAddBuddy::static_constructor;
48 
49 
AP_Win32Dialog_CollaborationAddBuddy(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)50 AP_Win32Dialog_CollaborationAddBuddy::AP_Win32Dialog_CollaborationAddBuddy(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id)
51 	: AP_Dialog_CollaborationAddBuddy(pDlgFactory, id),
52 	m_hInstance(0),
53 	m_hOK(0),
54 	m_hCancel(0)
55 
56 {
57 	AbiCollabSessionManager * pSessionManager= AbiCollabSessionManager::getManager();
58 	if (pSessionManager)
59 	{
60 		m_hInstance=pSessionManager->getInstance();
61 	}
62 }
63 
64 
runModal(XAP_Frame * pFrame)65 void AP_Win32Dialog_CollaborationAddBuddy::runModal(XAP_Frame * pFrame)
66 {
67 	UT_return_if_fail(pFrame);
68 	// TODO: Implement!
69 	/*
70     // Build the dialog's window
71 	m_wWindowMain = _constructWindow();
72 	UT_return_if_fail(m_wWindowMain);
73 
74 	_populateWindowData();
75 
76 	switch ( abiRunModalDialog ( GTK_DIALOG(m_wWindowMain),
77 								 pFrame, this, GTK_RESPONSE_CANCEL, false ) )
78 	{
79 		case GTK_RESPONSE_CANCEL:
80 			m_answer = AP_Win32Dialog_CollaborationAddBuddy::a_CANCEL;
81 			break;
82 		case GTK_RESPONSE_OK:
83 			m_answer = AP_Win32Dialog_CollaborationAddBuddy::a_OK;
84 			break;
85 		default:
86 			m_answer = AP_Win32Dialog_CollaborationAddBuddy::a_CANCEL;
87 			break;
88 	}
89 
90 	abiDestroyWidget(m_wWindowMain);
91 	//*/
92 }
93 
94 /*****************************************************************/
95 
96 
97 /*
98 GtkWidget * AP_Win32Dialog_CollaborationAddBuddy::_constructWindow(void)
99 {
100 	GtkWidget* window;
101 	const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet();
102 
103 	// get the path where our UI file is located
104 	std::string ui_path = static_cast<XAP_UnixApp*>(XAP_App::getApp())->getAbiSuiteAppUIDir() + "/ap_Win32Dialog_CollaborationAddBuddy.xml";
105 	// load the dialog from the UI file
106 	GtkBuilder* builder = gtk_builder_new();
107 	gtk_builder_add_from_file(builder, ui_path.c_str(), NULL);
108 
109 	// Update our member variables with the important widgets that
110 	// might need to be queried or altered later
111 	window = GTK_WIDGET(gtk_builder_get_object(builder, "ap_Win32Dialog_CollaborationAddBuddy"));
112 	m_wOk = GTK_WIDGET(gtk_builder_get_object(builder, "btOK"));
113 	m_wName = GTK_WIDGET(gtk_builder_get_object(builder, "edName"));
114 	m_wAccount = GTK_WIDGET(gtk_builder_get_object(builder, "cbAccount"));
115 
116 	// set the dialog title
117 	// TODO
118 
119 	// localize the strings in our dialog, and set tags for some widgets
120 	// TODO
121 
122 	// connect our signals
123 	g_signal_connect(G_OBJECT(m_wOk),
124 							"clicked",
125 							G_CALLBACK(s_ok_clicked),
126 							static_cast<gpointer>(this));
127 
128 	return window;
129 }
130 
131 void AP_Win32Dialog_CollaborationAddBuddy::_populateWindowData()
132 {
133 	// populate the account combobox
134 	GtkListStore* store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
135 	GtkTreeIter iter;
136 	AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager();
137 
138 	for (UT_sint32 i = 0; i < pManager->getAccounts().size(); i++)
139 	{
140 		AccountHandler* pHandler = pManager->getAccounts().getNthItem(i);
141 		if (pHandler && pHandler->allowsManualBuddies())
142 		{
143 			gtk_list_store_append (store, &iter);
144 			gtk_list_store_set (store, &iter,
145 						DESC_COLUMN, pHandler->getDescription().utf8_str(),
146 						HANDLER_COLUMN, pHandler,
147 						-1);
148 		}
149 	}
150 	m_model = GTK_TREE_MODEL (store);
151 	gtk_combo_box_set_model(GTK_COMBO_BOX(m_wAccount), m_model);
152 
153 	// if we have at least one account, then make sure the first one is selected
154 	if (pManager->getAccounts().size() > 0)
155 	{
156 		gtk_combo_box_set_active(GTK_COMBO_BOX(m_wAccount), 0);
157 	}
158 	else
159 	{
160 		// nope, we don't have any account :'-(
161 		gtk_combo_box_set_active(GTK_COMBO_BOX(m_wAccount), -1);
162 	}
163 }
164 
165 void AP_Win32Dialog_CollaborationAddBuddy::event_Ok()
166 {
167 	GtkTreeIter iter;
168 	if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(m_wAccount), &iter))
169 	{
170 		gpointer handler = 0;
171 		gtk_tree_model_get(m_model, &iter, HANDLER_COLUMN, &handler, -1);
172 
173 		if (handler)
174 		{
175 			m_pAccount = reinterpret_cast<AccountHandler*>(handler);
176 			_setName(gtk_entry_get_text(GTK_ENTRY(m_wName)));
177 		}
178 		else
179 			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
180 	}
181 	else
182 		UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
183 }
184 //*/
185