xref: /haiku/src/tools/translation/inspector/ActiveTranslatorsWindow.cpp (revision d1360823ff122e2862b640e20481fd273a9d5dbe)
1*d1360823SMatthew Wilber /*****************************************************************************/
2*d1360823SMatthew Wilber // ActiveTranslatorsWindow
3*d1360823SMatthew Wilber // Written by Michael Wilber, OBOS Translation Kit Team
4*d1360823SMatthew Wilber //
5*d1360823SMatthew Wilber // ActiveTranslatorsWindow.cpp
6*d1360823SMatthew Wilber //
7*d1360823SMatthew Wilber // BWindow class for displaying information about the currently open
8*d1360823SMatthew Wilber // document
9*d1360823SMatthew Wilber //
10*d1360823SMatthew Wilber //
11*d1360823SMatthew Wilber // Copyright (c) 2003 OpenBeOS Project
12*d1360823SMatthew Wilber //
13*d1360823SMatthew Wilber // Permission is hereby granted, free of charge, to any person obtaining a
14*d1360823SMatthew Wilber // copy of this software and associated documentation files (the "Software"),
15*d1360823SMatthew Wilber // to deal in the Software without restriction, including without limitation
16*d1360823SMatthew Wilber // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17*d1360823SMatthew Wilber // and/or sell copies of the Software, and to permit persons to whom the
18*d1360823SMatthew Wilber // Software is furnished to do so, subject to the following conditions:
19*d1360823SMatthew Wilber //
20*d1360823SMatthew Wilber // The above copyright notice and this permission notice shall be included
21*d1360823SMatthew Wilber // in all copies or substantial portions of the Software.
22*d1360823SMatthew Wilber //
23*d1360823SMatthew Wilber // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24*d1360823SMatthew Wilber // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25*d1360823SMatthew Wilber // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26*d1360823SMatthew Wilber // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27*d1360823SMatthew Wilber // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28*d1360823SMatthew Wilber // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29*d1360823SMatthew Wilber // DEALINGS IN THE SOFTWARE.
30*d1360823SMatthew Wilber /*****************************************************************************/
31*d1360823SMatthew Wilber 
32*d1360823SMatthew Wilber #include "Constants.h"
33*d1360823SMatthew Wilber #include "ActiveTranslatorsWindow.h"
34*d1360823SMatthew Wilber #include <Application.h>
35*d1360823SMatthew Wilber #include <ScrollView.h>
36*d1360823SMatthew Wilber #include <Message.h>
37*d1360823SMatthew Wilber #include <String.h>
38*d1360823SMatthew Wilber #include <stdlib.h>
39*d1360823SMatthew Wilber #include <string.h>
40*d1360823SMatthew Wilber #include <dirent.h>
41*d1360823SMatthew Wilber #include <unistd.h>
42*d1360823SMatthew Wilber #include <sys/stat.h>
43*d1360823SMatthew Wilber 
44*d1360823SMatthew Wilber ActiveTranslatorsWindow::ActiveTranslatorsWindow(BRect rect, const char *name)
45*d1360823SMatthew Wilber 	: BWindow(rect, name, B_FLOATING_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
46*d1360823SMatthew Wilber {
47*d1360823SMatthew Wilber 	BRect rctframe = Bounds();
48*d1360823SMatthew Wilber 	rctframe.InsetBy(5, 5);
49*d1360823SMatthew Wilber 	rctframe.right -= B_V_SCROLL_BAR_WIDTH;
50*d1360823SMatthew Wilber 
51*d1360823SMatthew Wilber 	fplist = new BOutlineListView(rctframe, "translators_list",
52*d1360823SMatthew Wilber 		B_MULTIPLE_SELECTION_LIST);
53*d1360823SMatthew Wilber 
54*d1360823SMatthew Wilber 	fplist->AddItem(fpuserItem = new BStringItem("User Translators"));
55*d1360823SMatthew Wilber 	fplist->AddItem(fpsystemItem = new BStringItem("System Translators"));
56*d1360823SMatthew Wilber 	AddTranslatorsToList("/boot/home/config/add-ons/Translators", fpuserItem);
57*d1360823SMatthew Wilber 	AddTranslatorsToList("/system/add-ons/Translators", fpsystemItem);
58*d1360823SMatthew Wilber 
59*d1360823SMatthew Wilber 	AddChild(new BScrollView("scroll_list", fplist, B_FOLLOW_LEFT | B_FOLLOW_TOP,
60*d1360823SMatthew Wilber 		0, false, true));
61*d1360823SMatthew Wilber 
62*d1360823SMatthew Wilber 	SetSizeLimits(100, 10000, 100, 10000);
63*d1360823SMatthew Wilber 
64*d1360823SMatthew Wilber 	Show();
65*d1360823SMatthew Wilber }
66*d1360823SMatthew Wilber 
67*d1360823SMatthew Wilber void
68*d1360823SMatthew Wilber ActiveTranslatorsWindow::AddTranslatorsToList(const char *path,
69*d1360823SMatthew Wilber 	BStringItem *pparent)
70*d1360823SMatthew Wilber {
71*d1360823SMatthew Wilber 	DIR *dir = opendir(path);
72*d1360823SMatthew Wilber 	if (!dir) {
73*d1360823SMatthew Wilber 		return;
74*d1360823SMatthew Wilber 	}
75*d1360823SMatthew Wilber 	struct dirent *dent;
76*d1360823SMatthew Wilber 	struct stat stbuf;
77*d1360823SMatthew Wilber 	char cwd[PATH_MAX] = "";
78*d1360823SMatthew Wilber 	while (NULL != (dent = readdir(dir))) {
79*d1360823SMatthew Wilber 		strcpy(cwd, path);
80*d1360823SMatthew Wilber 		strcat(cwd, "/");
81*d1360823SMatthew Wilber 		strcat(cwd, dent->d_name);
82*d1360823SMatthew Wilber 		status_t err = stat(cwd, &stbuf);
83*d1360823SMatthew Wilber 
84*d1360823SMatthew Wilber 		if (!err && S_ISREG(stbuf.st_mode) &&
85*d1360823SMatthew Wilber 			strcmp(dent->d_name, ".") && strcmp(dent->d_name, ".."))
86*d1360823SMatthew Wilber 			fplist->AddUnder(new BStringItem(dent->d_name), pparent);
87*d1360823SMatthew Wilber 	}
88*d1360823SMatthew Wilber 	closedir(dir);
89*d1360823SMatthew Wilber }
90*d1360823SMatthew Wilber 
91*d1360823SMatthew Wilber ActiveTranslatorsWindow::~ActiveTranslatorsWindow()
92*d1360823SMatthew Wilber {
93*d1360823SMatthew Wilber }
94*d1360823SMatthew Wilber 
95*d1360823SMatthew Wilber void
96*d1360823SMatthew Wilber ActiveTranslatorsWindow::FrameResized(float width, float height)
97*d1360823SMatthew Wilber {
98*d1360823SMatthew Wilber }
99*d1360823SMatthew Wilber 
100*d1360823SMatthew Wilber void
101*d1360823SMatthew Wilber ActiveTranslatorsWindow::MessageReceived(BMessage *pmsg)
102*d1360823SMatthew Wilber {
103*d1360823SMatthew Wilber 	switch (pmsg->what) {
104*d1360823SMatthew Wilber 		default:
105*d1360823SMatthew Wilber 			BWindow::MessageReceived(pmsg);
106*d1360823SMatthew Wilber 			break;
107*d1360823SMatthew Wilber 	}
108*d1360823SMatthew Wilber }
109*d1360823SMatthew Wilber 
110*d1360823SMatthew Wilber void
111*d1360823SMatthew Wilber ActiveTranslatorsWindow::Quit()
112*d1360823SMatthew Wilber {
113*d1360823SMatthew Wilber 	// tell the app to forget about this window
114*d1360823SMatthew Wilber 	be_app->PostMessage(M_ACTIVE_TRANSLATORS_WINDOW_QUIT);
115*d1360823SMatthew Wilber 	BWindow::Quit();
116*d1360823SMatthew Wilber }
117