]> code.citadel.org Git - citadel.git/blob - daphne/selectuser.cpp
warning fixes on sparc-sun-solaris2.8 with gcc 3.0.4, mostly for *printf
[citadel.git] / daphne / selectuser.cpp
1 // ============================================================================
2 // declarations
3 // ============================================================================
4
5 #include "includes.hpp"
6
7 // ----------------------------------------------------------------------------
8 // private classes
9 // ----------------------------------------------------------------------------
10
11
12
13 class ReturnedUser : public wxTreeItemData {
14 public:
15         ReturnedUser(wxString);
16         wxString emailaddr;
17 };
18
19 ReturnedUser::ReturnedUser(wxString e) {
20         emailaddr = e;
21 }
22
23
24
25 // ----------------------------------------------------------------------------
26 // constants
27 // ----------------------------------------------------------------------------
28
29 // IDs for the controls and the menu commands
30 enum
31 {
32         BUTTON_SENDCMD,
33         BUTTON_CLOSE,
34         THE_TREE
35 };
36
37
38 // ----------------------------------------------------------------------------
39 // event tables and other macros for wxWindows
40 // ----------------------------------------------------------------------------
41
42 BEGIN_EVENT_TABLE(      SelectUser, wxPanel)
43         EVT_BUTTON(     BUTTON_SENDCMD,         SelectUser::OnButtonPressed)
44         EVT_BUTTON(     BUTTON_CLOSE,           SelectUser::OnButtonPressed)
45 END_EVENT_TABLE()
46
47 //BEGIN_EVENT_TABLE(thisclassname, wxTreeCtrl)
48 //      EVT_TREE_ITEM_ACTIVATED(THE_TREE, SelectUser::OnTreeClick)
49 //END_EVENT_TABLE()
50
51 // ============================================================================
52 // implementation
53 // ============================================================================
54
55
56 // ----------------------------------------------------------------------------
57 // the application class
58 // ----------------------------------------------------------------------------
59
60 // frame constructor
61 SelectUser::SelectUser(CitClient *sock, wxWindow *the_parent,
62                 wxString caption,
63                 wxString rootlabel,
64                 unsigned int flags,
65                 wxTextCtrl *PlaceToPutTheSelection)
66        : wxPanel(the_parent, -1) {
67
68         citsock = sock;
69         target_textctrl = PlaceToPutTheSelection;
70
71         TheTree = new wxTreeCtrl(
72                 this,
73                 THE_TREE,
74                 wxDefaultPosition, wxDefaultSize,
75                 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER
76                 );
77
78         wxStaticText *caption_ctrl = new wxStaticText(this, -1, caption);
79         wxLayoutConstraints *c0 = new wxLayoutConstraints;
80         c0->left.SameAs(this, wxLeft, 5);
81         c0->top.SameAs(this, wxTop, 5);
82         c0->width.AsIs();
83         c0->height.AsIs();
84         caption_ctrl->SetConstraints(c0);
85
86         wxButton *select_button = new wxButton(
87                 this,
88                 BUTTON_SENDCMD,
89                 " Select "
90                 );
91
92         wxButton *cancel_button = new wxButton(
93                 this,
94                 BUTTON_CLOSE,
95                 " Cancel "
96                 );
97
98         wxLayoutConstraints *c5 = new wxLayoutConstraints;
99         c5->left.SameAs(this, wxLeft, 5);
100         c5->bottom.SameAs(this, wxBottom, 5);
101         c5->width.AsIs();
102         c5->height.AsIs();
103         select_button->SetConstraints(c5);
104
105         wxLayoutConstraints *c6 = new wxLayoutConstraints;
106         c6->right.SameAs(this, wxRight, 5);
107         c6->bottom.SameAs(this, wxBottom, 5);
108         c6->width.AsIs();
109         c6->height.AsIs();
110         cancel_button->SetConstraints(c6);
111
112         wxLayoutConstraints *c1 = new wxLayoutConstraints;
113         c1->top.Below(caption_ctrl, 5);
114         c1->bottom.Above(select_button, -5);
115         c1->left.SameAs(this, wxLeft, 5);
116         c1->right.SameAs(this, wxRight, 5);
117         TheTree->SetConstraints(c1);
118
119         SetAutoLayout(TRUE);
120         Show(TRUE);
121         Layout();
122         wxYield();
123
124         // Load up the tree with some STUFF
125         TheTree->AddRoot(
126                 rootlabel,
127                 -1,             // FIX put an image here
128                 -1,             // FIX same image
129                 NULL            // No data here, it's only a heading
130                 );
131
132         // Add local users to the tree (this is probably always going to be
133         // desired, so there's no need for a flag)
134         AddLocalUsers(TheTree, citsock);
135 }
136
137
138
139 void SelectUser::OnButtonPressed(wxCommandEvent& whichbutton) {
140
141         if (whichbutton.GetId()==BUTTON_CLOSE) {
142                 delete this;
143         }
144         else if (whichbutton.GetId()==BUTTON_SENDCMD) {
145                 ReturnedUser *u = (ReturnedUser *)
146                         TheTree->GetItemData(TheTree->GetSelection());
147                 if ( (u != NULL) && (target_textctrl != NULL) ) {
148                         target_textctrl->SetValue(u->emailaddr);
149                         delete this;
150                 }
151         }
152 }
153
154
155 void SelectUser::AddLocalUsers(wxTreeCtrl *tree, CitClient *cit) {
156         wxString sendcmd;
157         wxString recvcmd;
158         wxString xferbuf;
159         wxStringTokenizer *ul;
160         wxString buf, username;
161
162         sendcmd = "LIST";
163         if (citsock->serv_trans(sendcmd, recvcmd, xferbuf) != 1) return;
164
165         wxTreeItemId localusers = tree->AppendItem(
166                 tree->GetRootItem(),
167                 cit->HumanNode,
168                 -1,     // FIX put an image here
169                 -1,     // FIX and here
170                 NULL    // No data here either.  It's a heading.
171                 );
172
173         ul = new wxStringTokenizer(xferbuf, "\n", FALSE);
174         while (ul->HasMoreTokens()) {
175                 buf = ul->NextToken();
176                 extract(username, buf, 0);
177                 tree->AppendItem(
178                         localusers,
179                         username,
180                         -1,             // FIX img
181                         -1,             // FIX img
182                         new ReturnedUser(username)
183                         );
184         }
185
186         // FIX ... this has to be made case insensitive
187         tree->SortChildren(localusers);
188 }
189
190