6 Copyright (c) 1991-2001, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
37 #include <Directory.h>
38 #include <FindDirectory.h>
44 #include <TextControl.h>
46 #include <VolumeRoster.h>
53 #include "MailWindow.h"
57 #define STATUS_TEXT "Status:"
58 #define STATUS_FIELD_H 10
59 #define STATUS_FIELD_V 8
60 #define STATUS_FIELD_WIDTH (STATUS_WIDTH - STATUS_FIELD_H)
61 #define STATUS_FIELD_HEIGHT 16
63 #define BUTTON_WIDTH 70
64 #define BUTTON_HEIGHT 20
66 #define S_OK_BUTTON_X1 (STATUS_WIDTH - BUTTON_WIDTH - 6)
67 #define S_OK_BUTTON_Y1 (STATUS_HEIGHT - (BUTTON_HEIGHT + 10))
68 #define S_OK_BUTTON_X2 (S_OK_BUTTON_X1 + BUTTON_WIDTH)
69 #define S_OK_BUTTON_Y2 (S_OK_BUTTON_Y1 + BUTTON_HEIGHT)
70 #define S_OK_BUTTON_TEXT "OK"
72 #define S_CANCEL_BUTTON_X1 (S_OK_BUTTON_X1 - (BUTTON_WIDTH + 10))
73 #define S_CANCEL_BUTTON_Y1 S_OK_BUTTON_Y1
74 #define S_CANCEL_BUTTON_X2 (S_CANCEL_BUTTON_X1 + BUTTON_WIDTH)
75 #define S_CANCEL_BUTTON_Y2 S_OK_BUTTON_Y2
76 #define S_CANCEL_BUTTON_TEXT "Cancel"
78 enum status_messages
{
85 TStatusWindow::TStatusWindow(BRect rect
, BMessenger target
, const char* status
)
86 : BWindow(rect
, "", B_MODAL_WINDOW
, B_NOT_RESIZABLE
),
89 BView
* view
= new BView(Bounds(), "", B_FOLLOW_ALL
, B_WILL_DRAW
);
90 view
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
93 BRect
r(STATUS_FIELD_H
, STATUS_FIELD_V
,
94 STATUS_FIELD_WIDTH
, STATUS_FIELD_V
+ STATUS_FIELD_HEIGHT
);
96 fStatus
= new BTextControl(r
, "", STATUS_TEXT
, status
, new BMessage(STATUS
));
97 view
->AddChild(fStatus
);
99 fStatus
->SetDivider(fStatus
->StringWidth(STATUS_TEXT
) + 6);
100 fStatus
->BTextControl::MakeFocus(true);
102 r
.Set(S_OK_BUTTON_X1
, S_OK_BUTTON_Y1
, S_OK_BUTTON_X2
, S_OK_BUTTON_Y2
);
103 BButton
*button
= new BButton(r
, "", S_OK_BUTTON_TEXT
, new BMessage(OK
));
104 view
->AddChild(button
);
105 button
->MakeDefault(true);
107 r
.Set(S_CANCEL_BUTTON_X1
, S_CANCEL_BUTTON_Y1
, S_CANCEL_BUTTON_X2
, S_CANCEL_BUTTON_Y2
);
108 button
= new BButton(r
, "", S_CANCEL_BUTTON_TEXT
, new BMessage(CANCEL
));
109 view
->AddChild(button
);
115 TStatusWindow::~TStatusWindow()
121 TStatusWindow::MessageReceived(BMessage
* msg
)
129 if (!_Exists(fStatus
->Text())) {
139 find_directory(B_USER_SETTINGS_DIRECTORY
, &path
, true);
140 dir
.SetTo(path
.Path());
141 if (dir
.FindEntry("Mail", &entry
) == B_NO_ERROR
)
144 dir
.CreateDirectory("Mail", &dir
);
145 if (dir
.InitCheck() != B_NO_ERROR
)
147 if (dir
.FindEntry("status", &entry
) == B_NO_ERROR
)
150 dir
.CreateDirectory("status", &dir
);
151 if (dir
.InitCheck() == B_NO_ERROR
) {
152 char name
[B_FILE_NAME_LENGTH
];
153 char newName
[B_FILE_NAME_LENGTH
];
155 sprintf(name
, "%s", fStatus
->Text());
156 if (strlen(name
) > B_FILE_NAME_LENGTH
- 10)
157 name
[B_FILE_NAME_LENGTH
- 10] = 0;
158 for (loop
= 0; loop
< strlen(name
); loop
++) {
159 if (name
[loop
] == '/')
162 strcpy(newName
, name
);
164 if ((result
= dir
.CreateFile(newName
, &file
, true)) == B_NO_ERROR
)
166 if (result
!= EEXIST
)
168 sprintf(newName
, "%s_%" B_PRId32
, name
, index
++);
170 dir
.FindEntry(newName
, &entry
);
171 node
= new BNodeInfo(&file
);
172 node
->SetType("text/plain");
174 file
.Write(fStatus
->Text(), strlen(fStatus
->Text()) + 1);
175 file
.SetSize(file
.Position());
176 file
.WriteAttr(INDEX_STATUS
, B_STRING_TYPE
, 0, fStatus
->Text(),
177 strlen(fStatus
->Text()) + 1);
182 BMessage
close(M_CLOSE_CUSTOM
);
183 close
.AddString("status", fStatus
->Text());
184 fTarget
.SendMessage(&close
);
196 TStatusWindow::_Exists(const char* status
)
199 BVolumeRoster().GetBootVolume(&volume
);
202 query
.SetVolume(&volume
);
203 query
.PushAttr(INDEX_STATUS
);
204 query
.PushString(status
);
209 if (query
.GetNextEntry(&entry
) == B_NO_ERROR
)