Ticket #3787: poorman.diff

File poorman.diff, 68.2 KB (added by tokyo6pm, 15 years ago)

layout manager support and coding style cleanup

  • src/apps/poorman/PoorManSiteView.h

     
    1414#include <CheckBox.h>
    1515
    1616
    17 class PoorManSiteView: public BView
    18 {
     17class PoorManSiteView: public BView {
    1918public:
    20                 PoorManSiteView(BRect, const char *name);
    21         void    SetSendDirValue(bool state) {if (state) sendDir->SetValue(B_CONTROL_ON);
    22                                                 else sendDir->SetValue(B_CONTROL_OFF); }
    23         bool    SendDirValue()  { return (sendDir->Value() == B_CONTROL_ON) ? true : false; }
    24 const   char *  IndexFileName() { return indexFileName->Text(); }
    25         void    SetIndexFileName(const char * name) { indexFileName->SetText(name); }
    26 const   char *  WebDir()        { return webDir->Text(); }
    27         void    SetWebDir(const char * dir) { webDir->SetText(dir); }
     19                            PoorManSiteView(const char *name);
     20
     21            void            SetSendDirValue(bool state)
     22                                { if (state) fSendDir->SetValue(B_CONTROL_ON);
     23                                    else fSendDir->SetValue(B_CONTROL_OFF); }
     24            bool            SendDirValue()
     25                                { return (fSendDir->Value() == B_CONTROL_ON)
     26                                    ? true : false; }
     27            const char*     IndexFileName()
     28                                { return fIndexFileName->Text(); }
     29            void            SetIndexFileName(const char* name)
     30                                { fIndexFileName->SetText(name); }
     31            const char*     WebDir()
     32                                { return fWebDir->Text(); }
     33            void            SetWebDir(const char* dir)
     34                                { fWebDir->SetText(dir); }
     35
    2836private:
    2937        // Site Tab
    3038            // Web Site Location
    31             BTextControl    *   webDir;
    32             BTextControl    *   indexFileName;
    33             BButton         *   selectWebDir;
     39            BTextControl*   fWebDir;
     40            BTextControl*   fIndexFileName;
     41            BButton*        fSelectWebDir;
    3442           
    3543            // Web Site Options
    36             BCheckBox       *   sendDir;
     44            BCheckBox*      fSendDir;
    3745           
    3846};
    3947
  • src/apps/poorman/PoorManAdvancedView.h

     
    1313#include "StatusSlider.h"
    1414
    1515
    16 class PoorManAdvancedView: public BView
    17 {
     16class PoorManAdvancedView: public BView {
    1817public:
    19                 PoorManAdvancedView(BRect, const char *name);
    20         int32   MaxSimultaneousConnections() { return maxConnections->Value(); }
    21         void    SetMaxSimutaneousConnections(int32 num);
     18                            PoorManAdvancedView(const char *name);
     19
     20            int32           MaxSimultaneousConnections()
     21                                { return fMaxConnections->Value(); }
     22            void            SetMaxSimutaneousConnections(int32 num);
    2223private:
    23         // Advanced Tab
     24            // Advanced Tab
    2425            // Connections Options
    25             StatusSlider    *   maxConnections;
     26            StatusSlider*   fMaxConnections;
    2627};
    2728
    2829#endif
  • src/apps/poorman/PoorManWindow.cpp

     
    1616#include <Directory.h>
    1717#include <File.h>
    1818#include <FindDirectory.h>
     19#include <GroupLayoutBuilder.h>
    1920#include <Menu.h>
    2021#include <MenuBar.h>
    2122#include <MenuItem.h>
     
    3435#include "constants.h"
    3536
    3637PoorManWindow::PoorManWindow(BRect frame)
    37     : BWindow(frame, STR_APP_NAME, B_TITLED_WINDOW, 0),
    38     status(false), hits(0), prefWindow(NULL), fLogFile(NULL), fServer(NULL)
     38    :
     39    BWindow(frame, STR_APP_NAME, B_TITLED_WINDOW, 0),
     40    fStatus(false),
     41    fHits(0),
     42    fPrefWindow(NULL),
     43    fLogFile(NULL),
     44    fServer(NULL)
    3945{
    4046    //preferences init
    41     web_directory.SetTo(STR_DEFAULT_WEB_DIRECTORY);
    42     index_file_name.SetTo("index.html");
    43     dir_list_flag = false;
     47    fWebDirectory.SetTo(STR_DEFAULT_WEB_DIRECTORY);
     48    fIndexFileName.SetTo("index.html");
     49    fDirListFlag = false;
    4450   
    45     log_console_flag = true;
    46     log_file_flag = false;
    47     log_path.SetTo("");
     51    fLogConsoleFlag = true;
     52    fLogFileFlag = false;
     53    fLogPath.SetTo("");
    4854   
    49     max_connections = (int16)32;
     55    fMaxConnections = (int16)32;
    5056   
    51     is_zoomed = true;
    52     last_width = 318.0f;
    53     last_height = 320.0f;
    54     this->frame = frame;
    55     setwindow_frame.Set(112.0f, 60.0f, 492.0f, 340.0f);
     57    fIsZoomed = true;
     58    fLastWidth = 318.0f;
     59    fLastHeight = 320.0f;
     60    this->fFrame = frame;
     61    fSetwindowFrame.Set(112.0f, 60.0f, 492.0f, 340.0f);
    5662   
    5763    // PoorMan Window
    5864    SetSizeLimits(318, 1600, 53, 1200);
     
    6167    //SetZoomLimits(1024, 768);
    6268   
    6369    //frame.Set(30.0f, 30.0f, 355.0f, 185.0f);
    64     frame.OffsetTo(B_ORIGIN);
    65     frame = Bounds();
    66     frame.top += 19.0;
    6770   
    68     mainView = new PoorManView(frame, STR_APP_NAME);
    69     mainView->SetViewColor(216,216,216,255);
    70    
    71     mainView->SetFont(be_bold_font);
    72     mainView->SetFontSize(12);
    73     AddChild(mainView);
    74    
    75     // BBox tests
    76     BRect br;
    77     br = mainView->Bounds();
    78     br.top = 1.0;
     71    SetLayout(new BGroupLayout(B_VERTICAL));
    7972
    80     BBox * bb = new BBox(br, "Background", B_FOLLOW_ALL_SIDES,
    81         B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE);
    82     bb->SetHighColor(WHITE);
    83     bb->SetLowColor(GRAY);
    84     bb->SetBorder(B_PLAIN_BORDER);
    85     mainView->AddChild(bb);
    86 
    8773    // -----------------------------------------------------------------
    8874    // Three Labels
    8975   
    9076    // Status String
    91     BRect statusRect;
    92     statusRect = Bounds();
    93     statusRect.left += 5;
    94     statusRect.top  += 3;
    95     statusRect.bottom = statusRect.top + 15;
    96     statusRect.right = statusRect.left + 100;   // make the width wide enough for the string to display
    97        
    98     statusView = new BStringView(statusRect, "Status View", "Status: Stopped");
    99     bb->AddChild(statusView);
     77    fStatusView = new BStringView("Status View", "Status: Stopped");
    10078   
    10179    // Directory String
    102     BRect dirRect;
    103     dirRect = Bounds();
    104     dirRect.top = statusRect.bottom - 1;
    105     dirRect.bottom = dirRect.top + 15;
    106     dirRect.left = statusRect.left;
    107     dirRect.right -= 5;
     80    fDirView = new BStringView("Dir View", "Directory: (none)");
    10881   
    109     dirView = new BStringView(dirRect, "Dir View", "Directory: (none)", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
    110     bb->AddChild(dirView);
    111    
    11282    // Hits String
    113     BRect hitsRect;
    114     hitsRect = bb->Bounds();
    115     hitsRect.InsetBy(5.0f, 5.0f);
    116     hitsRect.top = statusRect.top;
    117     hitsRect.bottom = statusRect.bottom;
    118     hitsRect.left = statusRect.right + 20;
     83    fHitsView = new BStringView("Hit View", "Hits: 0");
    11984   
    120     hitsView = new BStringView(hitsRect, "Hit View", "Hits: 0", B_FOLLOW_RIGHT | B_FOLLOW_TOP);
    121     hitsView->SetAlignment(B_ALIGN_RIGHT);
    122     bb->AddChild(hitsView);
    12385
    12486    // -----------------------------------------------------------------
    12587    // Logging View
    12688   
    127     // logRect
    128     BRect logRect = bb->Bounds();//(5.0, 36.0, 306.0, 131.0);
    129     logRect.InsetBy(5, 5);
    130     logRect.top = 36.0f;
    131     logRect.right -= B_V_SCROLL_BAR_WIDTH;
    132    
    133     // textRect
    134     BRect textRect; //(1.0, 1.0, 175.0, 75.0);
    135     textRect = logRect;
    136     textRect.top = 0.0;
    137     textRect.left = 2.0;
    138     textRect.right = logRect.right - logRect.left - 2.0;
    139     textRect.bottom = logRect.bottom - logRect.top;
     89    fLoggingView = new BTextView(STR_TXT_VIEW, B_WILL_DRAW );
    14090
    141     fLogViewFont = new BFont(be_plain_font);
    142     fLogViewFont->SetSize(11.0);
    143 
    144     loggingView = new BTextView(logRect, STR_TXT_VIEW, textRect,
    145          fLogViewFont, NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW );
    146 
    147     loggingView->MakeEditable(false);   // user cannot change the text
    148     loggingView->MakeSelectable(true);
    149     loggingView->SetViewColor(WHITE);
    150     loggingView->SetStylable(true);
     91    fLoggingView->MakeEditable(false);  // user cannot change the text
     92    fLoggingView->MakeSelectable(true);
     93    fLoggingView->SetViewColor(WHITE);
     94    fLoggingView->SetStylable(true);
    15195       
    15296    // create the scroll view
    153     scrollView = new BScrollView("Scroll View", loggingView, B_FOLLOW_ALL_SIDES,
     97    fScrollView = new BScrollView("Scroll View", fLoggingView,
    15498                    B_WILL_DRAW | B_FRAME_EVENTS,
    15599                    // Make sure articles on border do not occur when resizing
    156100                    false, true);
    157     bb->AddChild(scrollView);
    158     loggingView->MakeFocus(true);
     101    fLoggingView->MakeFocus(true);
    159102
    160103
    161104    // -----------------------------------------------------------------
    162105    // menu bar
    163     BRect menuRect;
    164     menuRect = Bounds();
    165     menuRect.bottom = 18.0f;
     106    fFileMenuBar = new BMenuBar("File Menu Bar");
    166107   
    167     FileMenuBar = new BMenuBar(menuRect, "File Menu Bar");
    168    
    169108    // menus
    170     FileMenu = BuildFileMenu();
    171     if (FileMenu)
    172         FileMenuBar->AddItem(FileMenu);
     109    fFileMenu = BuildfFileMenu();
     110    if (fFileMenu)
     111        fFileMenuBar->AddItem(fFileMenu);
    173112           
    174     EditMenu = BuildEditMenu();
    175     if (EditMenu)
    176         FileMenuBar->AddItem(EditMenu);
     113    fEditMenu = BuildEditMenu();
     114    if (fEditMenu)
     115        fFileMenuBar->AddItem(fEditMenu);
    177116       
    178     ControlsMenu = BuildControlsMenu();
    179     if (ControlsMenu)
    180         FileMenuBar->AddItem(ControlsMenu);
     117    fControlsMenu = BuildControlsMenu();
     118    if (fControlsMenu)
     119        fFileMenuBar->AddItem(fControlsMenu);
    181120   
    182121    // File Panels
    183     BWindow * change_title;
     122    BWindow* change_title;
    184123   
    185     saveConsoleFilePanel = new BFilePanel(
    186                         B_SAVE_PANEL,
    187                         new BMessenger(this),
    188                         NULL,
    189                         B_FILE_NODE,
    190                         false,
    191                         new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE)
    192                         );
    193     change_title = saveConsoleFilePanel->Window();
     124    fSaveConsoleFilePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this),
     125                        NULL, B_FILE_NODE, false,
     126                        new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE));
     127    change_title = fSaveConsoleFilePanel->Window();
    194128    change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE);
    195129   
    196     saveConsoleSelectionFilePanel = new BFilePanel(
    197                         B_SAVE_PANEL,
    198                         new BMessenger(this),
    199                         NULL,
    200                         B_FILE_NODE,
    201                         false,
    202                         new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION)
    203                         );
    204     change_title = saveConsoleSelectionFilePanel->Window();
     130    fSaveConsoleSelectionFilePanel = new BFilePanel(B_SAVE_PANEL,
     131                        new BMessenger(this), NULL, B_FILE_NODE, false,
     132                        new BMessage(MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION));
     133    change_title = fSaveConsoleSelectionFilePanel->Window();
    205134    change_title->SetTitle(STR_FILEPANEL_SAVE_CONSOLE_SELECTION);
    206135   
     136    AddChild(BGroupLayoutBuilder(B_VERTICAL)
     137        .Add(fFileMenuBar)
     138        .Add(BGroupLayoutBuilder(B_VERTICAL, 5)
     139            .Add(BGroupLayoutBuilder(B_HORIZONTAL)
     140                .Add(fStatusView)
     141                .AddGlue()
     142                .Add(fHitsView))
     143            .Add(BGroupLayoutBuilder(B_HORIZONTAL)
     144                .Add(fDirView)
     145                .AddGlue())
     146            .Add(fScrollView)
     147        .SetInsets(10, 10, 10, 10)));
    207148   
    208     AddChild(FileMenuBar);
    209    
    210149    pthread_rwlock_init(&fLogFileLock, NULL);
    211150}
    212151
     152
    213153PoorManWindow::~PoorManWindow()
    214154{
    215155    delete fServer;
    216     delete fLogViewFont;
    217156    delete fLogFile;
    218157    pthread_rwlock_destroy(&fLogFileLock);
    219158}
    220159
     160
    221161void
    222162PoorManWindow::MessageReceived(BMessage* message)
    223163{
    224164    switch (message->what) {
    225     case MSG_MENU_FILE_SAVE_AS:
    226         saveConsoleFilePanel->Show();
    227         break;
    228     case MSG_FILE_PANEL_SAVE_CONSOLE:
    229         printf("FilePanel: Save Console\n");
    230         SaveConsole(message, false);
    231         break;
    232     case MSG_MENU_FILE_SAVE_SELECTION:
    233         saveConsoleSelectionFilePanel->Show();
    234         break;
    235     case MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION:
    236         printf("FilePanel: Save Console Selection\n");
    237         SaveConsole(message, true);
    238         break;
    239     case MSG_MENU_EDIT_PREF:
    240         prefWindow = new PoorManPreferencesWindow(
    241             setwindow_frame,
    242             STR_WIN_NAME_PREF
    243         );
    244         break;
    245     case MSG_MENU_CTRL_RUN:
    246         if(status)
    247             StopServer();
    248         else
    249             StartServer();
    250         break;
    251     case MSG_MENU_CTRL_CLEAR_HIT:
    252         SetHits(0);
    253         //UpdateHitsLabel();
    254         break;
    255     case MSG_MENU_CTRL_CLEAR_CONSOLE:
    256         loggingView->SelectAll();
    257         loggingView->Delete();
    258         break;
    259     case MSG_MENU_CTRL_CLEAR_LOG:
    260         FILE * f;
    261         f = fopen(log_path.String(), "w");
    262         fclose(f);
    263         break;
    264     case MSG_LOG:
    265     {
    266         if(!log_console_flag && !log_file_flag)
    267         break;
     165        case MSG_MENU_FILE_SAVE_AS:
     166            fSaveConsoleFilePanel->Show();
     167            break;
     168
     169        case MSG_FILE_PANEL_SAVE_CONSOLE:
     170            printf("FilePanel: Save Console\n");
     171            SaveConsole(message, false);
     172            break;
     173
     174        case MSG_MENU_FILE_SAVE_SELECTION:
     175            fSaveConsoleSelectionFilePanel->Show();
     176            break;
     177
     178        case MSG_FILE_PANEL_SAVE_CONSOLE_SELECTION:
     179            printf("FilePanel: Save Console Selection\n");
     180            SaveConsole(message, true);
     181            break;
     182
     183        case MSG_MENU_EDIT_PREF:
     184            fPrefWindow = new PoorManPreferencesWindow(fSetwindowFrame,
     185                STR_WIN_NAME_PREF);
     186            break;
     187
     188        case MSG_MENU_CTRL_RUN:
     189            if(fStatus)
     190                StopServer();
     191            else
     192                StartServer();
     193            break;
     194
     195        case MSG_MENU_CTRL_CLEAR_HIT:
     196            SetHits(0);
     197            //UpdateHitsLabel();
     198            break;
     199
     200        case MSG_MENU_CTRL_CLEAR_CONSOLE:
     201            fLoggingView->SelectAll();
     202            fLoggingView->Delete();
     203            break;
     204
     205        case MSG_MENU_CTRL_CLEAR_LOG:
     206            FILE * f;
     207            f = fopen(fLogPath.String(), "w");
     208            fclose(f);
     209            break;
     210
     211        case MSG_LOG:
     212        {
     213            if (!fLogConsoleFlag && !fLogFileFlag)
     214                break;
    268215   
    269         time_t time;
    270         in_addr_t address;
    271         rgb_color color;
    272         const void* pointer;
    273         ssize_t size;
    274         const char* msg;
    275         BString line;
     216            time_t time;
     217            in_addr_t address;
     218            rgb_color color;
     219            const void* pointer;
     220            ssize_t size;
     221            const char* msg;
     222            BString line;
    276223       
    277         if(message->FindString("cstring", &msg) != B_OK)
    278             break;
    279         if(message->FindData("time_t", B_TIME_TYPE, &pointer, &size) != B_OK)
    280             time = -1;
    281         else
    282             time = *static_cast<const time_t*>(pointer);
    283         if(message->FindData("in_addr_t", B_ANY_TYPE, &pointer, &size) != B_OK)
    284             address = INADDR_NONE;
    285         else
    286             address = *static_cast<const in_addr_t*>(pointer);
    287         if(message->FindData("rgb_color", B_RGB_COLOR_TYPE, &pointer, &size) != B_OK)
    288             color = BLACK;
    289         else
    290             color = *static_cast<const rgb_color*>(pointer);
     224            if (message->FindString("cstring", &msg) != B_OK)
     225                break;
     226           
     227            if (message->FindData("time_t", B_TIME_TYPE, &pointer, &size) != B_OK)
     228                time = -1;
     229            else
     230                time = *static_cast<const time_t*>(pointer);
     231           
     232            if (message->FindData("in_addr_t", B_ANY_TYPE, &pointer, &size) != B_OK)
     233                address = INADDR_NONE;
     234            else
     235                address = *static_cast<const in_addr_t*>(pointer);
     236           
     237            if (message->FindData("rgb_color", B_RGB_COLOR_TYPE, &pointer, &size) != B_OK)
     238                color = BLACK;
     239            else
     240                color = *static_cast<const rgb_color*>(pointer);
    291241       
    292         if(time != -1){
    293             char timeString[26];
    294             if(ctime_r(&time, timeString) != NULL){
    295                 timeString[24] = '\0';
    296                 line << '[' << timeString << "]: ";
     242            if (time != -1) {
     243                char timeString[26];
     244                if (ctime_r(&time, timeString) != NULL) {
     245                    timeString[24] = '\0';
     246                    line << '[' << timeString << "]: ";
     247                }
    297248            }
    298         }
    299249       
    300         if(address != INADDR_NONE){
    301             char addr[INET_ADDRSTRLEN];
    302             struct in_addr sin_addr;
    303             sin_addr.s_addr = address;
    304             if(inet_ntop(AF_INET, &sin_addr, addr, sizeof(addr)) != NULL){
    305                 addr[strlen(addr)] = '\0';
    306                 line << '(' << addr << ") ";
     250            if(address != INADDR_NONE){
     251                char addr[INET_ADDRSTRLEN];
     252                struct in_addr sin_addr;
     253                sin_addr.s_addr = address;
     254                if (inet_ntop(AF_INET, &sin_addr, addr, sizeof(addr)) != NULL) {
     255                    addr[strlen(addr)] = '\0';
     256                    line << '(' << addr << ") ";
     257                }
    307258            }
    308         }
    309259       
    310         line << msg;
     260            line << msg;
     261
     262            text_run run;
     263            text_run_array runs;
    311264       
    312         text_run run;
    313         text_run_array runs;
     265            run.offset = 0;
     266            run.font = be_plain_font;
     267            run.color = color;
    314268       
    315         run.offset = 0;
    316         run.font = *fLogViewFont;
    317         run.color = color;
     269            runs.count = 1;
     270            runs.runs[0] = run;
    318271       
    319         runs.count = 1;
    320         runs.runs[0] = run;
     272            if (Lock()) {
     273                if(fLogConsoleFlag) {
     274                    fLoggingView->Insert(fLoggingView->TextLength(),
     275                        line.String(), line.Length(), &runs);
     276                    fLoggingView->ScrollToOffset(fLoggingView->TextLength());
     277                }
    321278       
    322         if(Lock()){
    323             if(log_console_flag){
    324                 loggingView->Insert(loggingView->TextLength(),
    325                     line.String(), line.Length(), &runs);
    326                 loggingView->ScrollToOffset(loggingView->TextLength());
    327             }
    328        
    329             if(log_file_flag){
    330                 if(pthread_rwlock_rdlock(&fLogFileLock) == 0){
    331                     fLogFile->Write(line.String(), line.Length());
    332                     pthread_rwlock_unlock(&fLogFileLock);
     279                if (fLogFileFlag) {
     280                    if (pthread_rwlock_rdlock(&fLogFileLock) == 0) {
     281                        fLogFile->Write(line.String(), line.Length());
     282                        pthread_rwlock_unlock(&fLogFileLock);
     283                    }
    333284                }
    334             }
    335285           
    336             Unlock();
     286                Unlock();
     287            }
     288       
     289            break;
    337290        }
    338291       
    339         break;
     292        default:
     293            BWindow::MessageReceived(message);
     294            break;
    340295    }
    341     default:
    342         BWindow::MessageReceived(message);
    343         break;
    344     }
    345296}
    346297
    347298void
    348299PoorManWindow::FrameMoved(BPoint origin)
    349300{
    350     frame.left = origin.x;
    351     frame.top = origin.y;
     301    fFrame.left = origin.x;
     302    fFrame.top = origin.y;
    352303}
    353304
    354305void
    355306PoorManWindow::FrameResized(float width, float height)
    356307{
    357     if (is_zoomed)
    358     {
    359         last_width  = width;
    360         last_height = height;
     308    if (fIsZoomed) {
     309        fLastWidth  = width;
     310        fLastHeight = height;
    361311    }
    362312}
    363313
    364314bool
    365315PoorManWindow::QuitRequested()
    366316{
    367     if(status){
     317    if (fStatus) {
    368318        time_t now = time(NULL);
    369319        char line[] = "[Thu Jan  1 00:00:00 1970]: Shutting down.\n";
    370320       
     
    372322        line[25] = ']';
    373323        line[26] = ' ';
    374324       
    375         if(log_console_flag){
    376                 loggingView->Insert(loggingView->TextLength(),
    377                     line, strlen(line));
    378                 loggingView->ScrollToOffset(loggingView->TextLength());
     325        if (fLogConsoleFlag) {
     326            fLoggingView->Insert(fLoggingView->TextLength(),
     327                line, strlen(line));
     328                fLoggingView->ScrollToOffset(fLoggingView->TextLength());
    379329        }
    380330       
    381         if(log_file_flag){
    382             if(pthread_rwlock_rdlock(&fLogFileLock) == 0){
    383                     fLogFile->Write(line, strlen(line));
    384                     pthread_rwlock_unlock(&fLogFileLock);
     331        if (fLogFileFlag) {
     332            if (pthread_rwlock_rdlock(&fLogFileLock) == 0) {
     333                fLogFile->Write(line, strlen(line));
     334                pthread_rwlock_unlock(&fLogFileLock);
    385335            }
    386336        }
    387337       
    388338        fServer->Stop();
    389         status = false;
     339        fStatus = false;
    390340        UpdateStatusLabelAndMenuItem();
    391341    }
    392342   
     
    398348void
    399349PoorManWindow::Zoom(BPoint origin, float width, float height)
    400350{
    401     if (is_zoomed)
    402     {   // Change to the Minimal size
    403         is_zoomed = false;
     351    if (fIsZoomed) {
     352        // Change to the Minimal size
     353        fIsZoomed = false;
    404354        ResizeTo(318, 53);
     355    } else {
     356        // Change to the Zoomed size
     357        fIsZoomed = true;
     358        ResizeTo(fLastWidth, fLastHeight);
    405359    }
    406     else
    407     {   // Change to the Zoomed size
    408         is_zoomed = true;
    409         ResizeTo(last_width, last_height);
    410     }
    411360}
    412361
    413362void
    414363PoorManWindow::SetHits(uint32 num)
    415364{
    416     hits = num;
     365    fHits = num;
    417366    UpdateHitsLabel();
    418367}
    419368
    420369// Private: Methods ------------------------------------------
    421370
    422 BMenu *
    423 PoorManWindow::BuildFileMenu() const
     371BMenu*
     372PoorManWindow::BuildfFileMenu() const
    424373{
    425     BMenu * ptrFileMenu = new BMenu(STR_MNU_FILE);
     374    BMenu* ptrfFileMenu = new BMenu(STR_MNU_FILE);
    426375
    427     ptrFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_AS,
     376    ptrfFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_AS,
    428377        new BMessage(MSG_MENU_FILE_SAVE_AS), CMD_FILE_SAVE_AS));
    429378       
    430     ptrFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_SELECTION,
     379    ptrfFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_SAVE_SELECTION,
    431380        new BMessage(MSG_MENU_FILE_SAVE_SELECTION)));
    432381       
    433     ptrFileMenu->AddSeparatorItem();
     382    ptrfFileMenu->AddSeparatorItem();
    434383   
    435384    // about box
    436     BMenuItem * AboutItem = new BMenuItem(STR_MNU_FILE_ABOUT,
     385    BMenuItem* AboutItem = new BMenuItem(STR_MNU_FILE_ABOUT,
    437386        new BMessage(B_ABOUT_REQUESTED));
    438387    AboutItem->SetTarget(NULL, be_app);
    439     ptrFileMenu->AddItem(AboutItem);
     388    ptrfFileMenu->AddItem(AboutItem);
    440389
    441     ptrFileMenu->AddSeparatorItem();
     390    ptrfFileMenu->AddSeparatorItem();
    442391   
    443392
    444     ptrFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_QUIT,
     393    ptrfFileMenu->AddItem(new BMenuItem(STR_MNU_FILE_QUIT,
    445394        new BMessage(B_QUIT_REQUESTED), CMD_FILE_QUIT));
    446395       
    447     return ptrFileMenu;
     396    return ptrfFileMenu;
    448397}
    449398
    450 BMenu *
     399BMenu*
    451400PoorManWindow::BuildEditMenu() const
    452401{
    453     BMenu * ptrEditMenu = new BMenu(STR_MNU_EDIT);
     402    BMenu* ptrEditMenu = new BMenu(STR_MNU_EDIT);
    454403   
    455     BMenuItem * CopyMenuItem = new BMenuItem(STR_MNU_EDIT_COPY,
     404    BMenuItem* CopyMenuItem = new BMenuItem(STR_MNU_EDIT_COPY,
    456405        new BMessage(B_COPY), CMD_EDIT_COPY);
    457406
    458407    ptrEditMenu->AddItem(CopyMenuItem);
    459     CopyMenuItem->SetTarget(loggingView, NULL);
     408    CopyMenuItem->SetTarget(fLoggingView, NULL);
    460409   
    461410    ptrEditMenu->AddSeparatorItem();
    462411
    463     BMenuItem * SelectAllMenuItem = new BMenuItem(STR_MNU_EDIT_SELECT_ALL,
     412    BMenuItem* SelectAllMenuItem = new BMenuItem(STR_MNU_EDIT_SELECT_ALL,
    464413    new BMessage(B_SELECT_ALL), CMD_EDIT_SELECT_ALL);
    465414   
    466415    ptrEditMenu->AddItem(SelectAllMenuItem);
    467     SelectAllMenuItem->SetTarget(loggingView, NULL);
     416    SelectAllMenuItem->SetTarget(fLoggingView, NULL);
    468417   
    469418    ptrEditMenu->AddSeparatorItem();
    470419   
    471     BMenuItem * PrefMenuItem = new BMenuItem(STR_MNU_EDIT_PREF,
     420    BMenuItem* PrefMenuItem = new BMenuItem(STR_MNU_EDIT_PREF,
    472421        new BMessage(MSG_MENU_EDIT_PREF));
    473422    ptrEditMenu->AddItem(PrefMenuItem);
    474423   
    475424    return ptrEditMenu;
    476425}
    477426
    478 BMenu *
     427BMenu*
    479428PoorManWindow::BuildControlsMenu() const
    480429{
    481     BMenu * ptrControlMenu = new BMenu(STR_MNU_CTRL);
     430    BMenu* ptrControlMenu = new BMenu(STR_MNU_CTRL);
    482431   
    483     BMenuItem * RunServerMenuItem = new BMenuItem(STR_MNU_CTRL_RUN_SERVER,
     432    BMenuItem* RunServerMenuItem = new BMenuItem(STR_MNU_CTRL_RUN_SERVER,
    484433        new BMessage(MSG_MENU_CTRL_RUN));
    485434    RunServerMenuItem->SetMarked(false);
    486435    ptrControlMenu->AddItem(RunServerMenuItem);
    487436   
    488     BMenuItem * ClearHitCounterMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_HIT_COUNTER,
     437    BMenuItem* ClearHitCounterMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_HIT_COUNTER,
    489438        new BMessage(MSG_MENU_CTRL_CLEAR_HIT));
    490439    ptrControlMenu->AddItem(ClearHitCounterMenuItem);
    491440
    492441    ptrControlMenu->AddSeparatorItem();
    493442
    494     BMenuItem * ClearConsoleLogMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_CONSOLE,
     443    BMenuItem* ClearConsoleLogMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_CONSOLE,
    495444        new BMessage(MSG_MENU_CTRL_CLEAR_CONSOLE));
    496445    ptrControlMenu->AddItem(ClearConsoleLogMenuItem);
    497446
    498     BMenuItem * ClearLogFileMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_LOG_FILE,
     447    BMenuItem* ClearLogfFileMenuItem = new BMenuItem(STR_MNU_CTRL_CLEAR_LOG_FILE,
    499448        new BMessage(MSG_MENU_CTRL_CLEAR_LOG));
    500     ptrControlMenu->AddItem(ClearLogFileMenuItem);
     449    ptrControlMenu->AddItem(ClearLogfFileMenuItem);
    501450   
    502451    return ptrControlMenu;
    503452}
    504453
    505454void
    506 PoorManWindow::SetDirLabel(const char * name)
     455PoorManWindow::SetDirLabel(const char* name)
    507456{
    508457    BString dirPath("Directory: ");
    509458    dirPath.Append(name);
    510459   
    511     if (Lock())
    512     {
    513         dirView->SetText(dirPath.String());
     460    if (Lock()) {
     461        fDirView->SetText(dirPath.String());
    514462        Unlock();
    515463    }
    516464}
     
    518466void
    519467PoorManWindow::UpdateStatusLabelAndMenuItem()
    520468{
    521     if (Lock())
    522     {
    523         if (status)
    524             statusView->SetText("Status: Running");
     469    if (Lock()) {
     470        if (fStatus)
     471            fStatusView->SetText("Status: Running");
    525472        else
    526             statusView->SetText("Status: Stopped");
    527         ControlsMenu->FindItem(STR_MNU_CTRL_RUN_SERVER)->SetMarked(status);
     473            fStatusView->SetText("Status: Stopped");
     474        fControlsMenu->FindItem(STR_MNU_CTRL_RUN_SERVER)->SetMarked(fStatus);
    528475        Unlock();
    529476    }
    530477}
     
    532479void
    533480PoorManWindow::UpdateHitsLabel()
    534481{
    535     if (Lock())
    536     {
    537         sprintf(hitsLabel, "Hits: %lu", GetHits());
    538         hitsView->SetText(hitsLabel);
     482    if (Lock()) {
     483        sprintf(fHitsLabel, "Hits: %lu", GetHits());
     484        fHitsView->SetText(fHitsLabel);
    539485       
    540486        Unlock();
    541487    }
    542488}
    543489
    544490status_t
    545 PoorManWindow::SaveConsole(BMessage * message, bool selection)
     491PoorManWindow::SaveConsole(BMessage* message, bool selection)
    546492{
    547493    entry_ref   ref;
    548     const char  * name;
     494    const char* name;
    549495    BPath       path;
    550496    BEntry      entry;
    551497    status_t    err = B_OK;
    552     FILE        *f;
     498    FILE*       f;
    553499   
    554     if ((err = message->FindRef("directory", &ref)) != B_OK)
     500    err = message->FindRef("directory", &ref);
     501    if (err != B_OK)
    555502        return err;
    556    
    557     if ((err = message->FindString("name", &name)) != B_OK)
     503       
     504    err = message->FindString("name", &name);
     505    if (err != B_OK)
    558506        return err;
    559    
    560     if ((err = entry.SetTo(&ref)) != B_OK)
     507       
     508    err = entry.SetTo(&ref);
     509    if (err != B_OK)
    561510        return err;
    562511   
    563512    entry.GetPath(&path);
     
    566515    if (!(f = fopen(path.Path(), "w")))
    567516        return B_ERROR;
    568517   
    569     if (!selection)
    570     {
     518    if (!selection) {
    571519        // write the data to the file
    572         err = fwrite(loggingView->Text(), 1, loggingView->TextLength(), f);
     520        err = fwrite(fLoggingView->Text(), 1, fLoggingView->TextLength(), f);
    573521    } else {
    574522        // find the selected text and write it to a file
    575523        int32 start = 0, end = 0;
    576         loggingView->GetSelection(&start, &end);
     524        fLoggingView->GetSelection(&start, &end);
    577525       
    578526        BString buffer;
    579         char * buffData = buffer.LockBuffer(end - start + 1);
     527        char* buffData = buffer.LockBuffer(end - start + 1);
    580528        // copy the selected text from the TextView to the buffer   
    581         loggingView->GetText(start, end - start, buffData);
     529        fLoggingView->GetText(start, end - start, buffData);
    582530        buffer.UnlockBuffer(end - start + 1);
    583531       
    584532        err = fwrite(buffer.String(), 1, end - start + 1, f);
    585533    }
     534   
    586535    fclose(f);
    587536   
    588537    return err;
     
    599548    int32 buttonIndex = dirAlert->Go();
    600549
    601550    switch (buttonIndex){
    602     case 0:
    603         serverAlert->Go();
    604         SetWebDir("");
    605         break;
    606     case 1:
    607         prefWindow = new PoorManPreferencesWindow(
    608                 setwindow_frame,
    609                 STR_WIN_NAME_PREF
    610         );
    611         serverAlert->Go();
    612         prefWindow->ShowWebDirFilePanel();
    613         break;
    614     case 2:
    615         if(create_directory(STR_DEFAULT_WEB_DIRECTORY, 0755) != B_OK){
     551        case 0:
    616552            serverAlert->Go();
    617553            SetWebDir("");
    618554            break;
    619         }
    620         BAlert* dirCreatedAlert =
    621             new BAlert("Dir Created",STR_DIR_CREATED,"OK");
    622         dirCreatedAlert->Go();
    623         SetWebDir(STR_DEFAULT_WEB_DIRECTORY);
    624         break;
     555
     556        case 1:
     557            fPrefWindow = new PoorManPreferencesWindow(fSetwindowFrame,
     558                STR_WIN_NAME_PREF);
     559            serverAlert->Go();
     560            fPrefWindow->ShowWebDirFilePanel();
     561            break;
     562
     563        case 2:
     564            if (create_directory(STR_DEFAULT_WEB_DIRECTORY, 0755) != B_OK) {
     565                serverAlert->Go();
     566                SetWebDir("");
     567                break;
     568            }
     569            BAlert* dirCreatedAlert = new BAlert("Dir Created",
     570                STR_DIR_CREATED,"OK");
     571            dirCreatedAlert->Go();
     572            SetWebDir(STR_DEFAULT_WEB_DIRECTORY);
     573            break;
    625574    }
    626575}
    627576
     
    632581    BFile f;
    633582    BMessage m;
    634583   
    635     if(find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)
     584    if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)
    636585        return B_ERROR;
    637586    p.Append(STR_SETTINGS_FILE_NAME);
    638587   
    639588    f.SetTo(p.Path(), B_READ_ONLY);
    640     if(f.InitCheck()!=B_OK)
     589    if (f.InitCheck()!= B_OK)
    641590        return B_ERROR;
    642591   
    643     if(m.Unflatten(&f)!=B_OK)
     592    if (m.Unflatten(&f)!= B_OK)
    644593        return B_ERROR;
    645594   
    646     if(MSG_PREF_FILE != m.what)
     595    if (MSG_PREF_FILE != m.what)
    647596        return B_ERROR;
    648597   
    649598    //site tab
    650     if(m.FindString("web_directory", &web_directory) != B_OK)
    651         web_directory.SetTo(STR_DEFAULT_WEB_DIRECTORY);
    652     if(m.FindString("index_file_name", &index_file_name) != B_OK)
    653         index_file_name.SetTo("index.html");
    654     if(m.FindBool("dir_list_flag", &dir_list_flag) != B_OK)
    655         dir_list_flag = false;
     599    if (m.FindString("web_directory", &fWebDirectory) != B_OK)
     600        fWebDirectory.SetTo(STR_DEFAULT_WEB_DIRECTORY);
     601    if (m.FindString("index_file_name", &fIndexFileName) != B_OK)
     602        fIndexFileName.SetTo("index.html");
     603    if (m.FindBool("dir_list_flag", &fDirListFlag) != B_OK)
     604        fDirListFlag = false;
    656605   
    657606    //logging tab
    658     if(m.FindBool("log_console_flag", &log_console_flag) != B_OK)
    659         log_console_flag = true;
    660     if(m.FindBool("log_file_flag", &log_file_flag) != B_OK)
    661         log_file_flag = false;
    662     if(m.FindString("log_path", &log_path) != B_OK)
    663         log_path.SetTo("");
     607    if (m.FindBool("log_console_flag", &fLogConsoleFlag) != B_OK)
     608        fLogConsoleFlag = true;
     609    if (m.FindBool("log_file_flag", &fLogFileFlag) != B_OK)
     610        fLogFileFlag = false;
     611    if (m.FindString("log_path", &fLogPath) != B_OK)
     612        fLogPath.SetTo("");
    664613   
    665614    //advance tab
    666     if(m.FindInt16("max_connections", &max_connections) != B_OK)
    667         max_connections = (int16)32;
     615    if(m.FindInt16("max_connections", &fMaxConnections) != B_OK)
     616        fMaxConnections = (int16)32;
    668617   
    669618    //windows' position and size
    670     if(m.FindRect("frame", &frame) != B_OK)
    671         frame.Set(82.0f, 30.0f, 400.0f, 350.0f);
    672     if(m.FindRect("setwindow_frame", &setwindow_frame) != B_OK)
    673         setwindow_frame.Set(112.0f, 60.0f, 492.0f, 340.0f);
    674     if(m.FindBool("is_zoomed", &is_zoomed) != B_OK)
    675         is_zoomed = true;
    676     if(m.FindFloat("last_width", &last_width) != B_OK)
    677         last_width = 318.0f;
    678     if(m.FindFloat("last_height", &last_height) != B_OK)
    679         last_height = 320.0f;
     619    if(m.FindRect("frame", &fFrame) != B_OK)
     620        fFrame.Set(82.0f, 30.0f, 400.0f, 350.0f);
     621    if(m.FindRect("setwindow_frame", &fSetwindowFrame) != B_OK)
     622        fSetwindowFrame.Set(112.0f, 60.0f, 492.0f, 340.0f);
     623    if(m.FindBool("is_zoomed", &fIsZoomed) != B_OK)
     624        fIsZoomed = true;
     625    if(m.FindFloat("last_width", &fLastWidth) != B_OK)
     626        fLastWidth = 318.0f;
     627    if(m.FindFloat("last_height", &fLastHeight) != B_OK)
     628        fLastHeight = 320.0f;
    680629   
    681     is_zoomed?ResizeTo(last_width, last_height):ResizeTo(318, 53);
    682     MoveTo(frame.left, frame.top);
     630    fIsZoomed ? ResizeTo(fLastWidth, fLastHeight) : ResizeTo(318, 53);
     631    MoveTo(fFrame.left, fFrame.top);
    683632   
    684     fLogFile = new BFile(log_path.String(), B_CREATE_FILE|B_WRITE_ONLY|B_OPEN_AT_END);
     633    fLogFile = new BFile(fLogPath.String(),
     634        B_CREATE_FILE|B_WRITE_ONLY | B_OPEN_AT_END);
    685635    if(fLogFile->InitCheck() != B_OK){
    686         log_file_flag = false;
     636        fLogFileFlag = false;
    687637        //log it to console, "log to file unavailable."
    688638        return B_OK;
    689639    }
    690640   
    691     SetDirLabel(web_directory.String());
     641    SetDirLabel(fWebDirectory.String());
    692642   
    693643    return B_OK;
    694644}
     
    701651    BMessage m(MSG_PREF_FILE);
    702652       
    703653    //site tab
    704     m.AddString("web_directory", web_directory);
    705     m.AddString("index_file_name", index_file_name);
    706     m.AddBool("dir_list_flag", dir_list_flag);
     654    m.AddString("web_directory", fWebDirectory);
     655    m.AddString("index_file_name", fIndexFileName);
     656    m.AddBool("dir_list_flag", fDirListFlag);
    707657   
    708658    //logging tab
    709     m.AddBool("log_console_flag", log_console_flag);
    710     m.AddBool("log_file_flag", log_file_flag);
    711     m.AddString("log_path", log_path);
     659    m.AddBool("log_console_flag", fLogConsoleFlag);
     660    m.AddBool("log_file_flag", fLogFileFlag);
     661    m.AddString("log_path", fLogPath);
    712662   
    713663    //advance tab
    714     m.AddInt16("max_connections", max_connections);
     664    m.AddInt16("max_connections", fMaxConnections);
    715665   
    716666    //windows' position and size
    717     m.AddRect("frame", frame);
    718     m.AddRect("setwindow_frame", setwindow_frame);
    719     m.AddBool("is_zoomed", is_zoomed);
    720     m.AddFloat("last_width", last_width);
    721     m.AddFloat("last_height", last_height);
     667    m.AddRect("frame", fFrame);
     668    m.AddRect("setwindow_frame", fSetwindowFrame);
     669    m.AddBool("is_zoomed", fIsZoomed);
     670    m.AddFloat("last_width", fLastWidth);
     671    m.AddFloat("last_height", fLastHeight);
    722672       
    723     if(find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)
     673    if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)
    724674        return B_ERROR;
    725675    p.Append(STR_SETTINGS_FILE_NAME);
    726676   
    727677    f.SetTo(p.Path(), B_WRITE_ONLY| B_ERASE_FILE| B_CREATE_FILE);
    728     if(f.InitCheck()!=B_OK)
     678    if (f.InitCheck()!= B_OK)
    729679        return B_ERROR;
    730680   
    731     if(m.Flatten(&f)!=B_OK)
     681    if(m.Flatten(&f)!= B_OK)
    732682        return B_ERROR;
    733683
    734684    return B_OK;
     
    737687status_t
    738688PoorManWindow::StartServer()
    739689{
    740     if(NULL == fServer)
    741         fServer = new PoorManServer(
    742             web_directory.String(),
    743             max_connections,
    744             dir_list_flag,
    745             index_file_name.String()
    746         );
     690    if(fServer == NULL)
     691        fServer = new PoorManServer(fWebDirectory.String(), fMaxConnections,
     692            fDirListFlag, fIndexFileName.String());
    747693   
    748694    poorman_log("Starting up... ");
    749     if(fServer->Run() != B_OK){
     695    if (fServer->Run() != B_OK) {
    750696        return B_ERROR;
    751697    }
    752698   
    753     status = true;
     699    fStatus = true;
    754700    UpdateStatusLabelAndMenuItem();
    755701    poorman_log("done.\n", false, INADDR_NONE, GREEN);
    756702   
     
    760706status_t
    761707PoorManWindow::StopServer()
    762708{
    763     if(NULL == fServer)
     709    if(fServer == NULL)
    764710        return B_ERROR;
    765711   
    766712    poorman_log("Shutting down.\n");
    767713    fServer->Stop();
    768     status = false;
     714    fStatus = false;
    769715    UpdateStatusLabelAndMenuItem();
    770716    return B_OK;
    771717}
     
    773719void
    774720PoorManWindow::SetLogPath(const char* str)
    775721{
    776     if(log_path == str)
     722    if (fLogPath == str)
    777723        return;
    778724   
    779     BFile* temp = new BFile(str, B_CREATE_FILE|B_WRITE_ONLY|B_OPEN_AT_END);
     725    BFile* temp = new BFile(str, B_CREATE_FILE | B_WRITE_ONLY | B_OPEN_AT_END);
    780726   
    781     if(temp->InitCheck() != B_OK){
     727    if (temp->InitCheck() != B_OK) {
    782728        delete temp;
    783729        return;
    784730    }
    785731   
    786     if(pthread_rwlock_wrlock(&fLogFileLock) == 0){
     732    if (pthread_rwlock_wrlock(&fLogFileLock) == 0) {
    787733        delete fLogFile;
    788734        fLogFile = temp;
    789735        pthread_rwlock_unlock(&fLogFileLock);
     
    792738        return;
    793739    }
    794740   
    795     log_path.SetTo(str);
     741    fLogPath.SetTo(str);
    796742}
  • src/apps/poorman/PoorManView.cpp

     
    1010#endif
    1111
    1212PoorManView::PoorManView(BRect rect, char *name)
    13     : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW )
     13    :
     14    BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
    1415{
    1516}
    1617
  • src/apps/poorman/PoorManWindow.h

     
    3333class PoorManWindow: public BWindow
    3434{
    3535public:
    36                     PoorManWindow(BRect frame);
    37 virtual             ~PoorManWindow();
    38 virtual void        MessageReceived(BMessage * message);
     36                            PoorManWindow(BRect frame);
     37    virtual                 ~PoorManWindow();
     38    virtual void            MessageReceived(BMessage* message);
    3939
    40 virtual void        FrameMoved(BPoint origin);
    41 virtual void        FrameResized(float width, float height);
    42 virtual bool        QuitRequested();
    43 virtual void        Zoom(BPoint origin, float width, float height);
     40    virtual void            FrameMoved(BPoint origin);
     41    virtual void            FrameResized(float width, float height);
     42    virtual bool            QuitRequested();
     43    virtual void            Zoom(BPoint origin, float width, float height);
    4444
    4545    // -------------------------------------------
    4646    // Public PoorMan Window Methods
    47         void        SetDirLabel(const char * name);
    48         void        SetHits(uint32 num);
    49         uint32      GetHits() { return hits; }
    50         status_t    SaveConsole(BMessage * message, bool);
     47            void            SetDirLabel(const char* name);
     48            void            SetHits(uint32 num);
     49            uint32          GetHits() { return fHits; }
     50            status_t        SaveConsole(BMessage* message, bool);
    5151       
    52         status_t    SaveSettings();
    53         status_t    ReadSettings();
    54         void        DefaultSettings();
     52            status_t        SaveSettings();
     53            status_t        ReadSettings();
     54            void            DefaultSettings();
    5555       
    56         status_t    StartServer();
    57         status_t    StopServer();
     56            status_t        StartServer();
     57            status_t        StopServer();
    5858       
    59         PoorManServer* GetServer()const{return fServer;}
     59            PoorManServer*  GetServer() const { return fServer;}
    6060    // ------------------------------------------- 
    6161    // Preferences and Settings
    6262        // Site Tab     
    63         bool         DirListFlag()                { return dir_list_flag; }
    64         void         SetDirListFlag(bool flag)    { dir_list_flag = flag; }
    65         const char * IndexFileName()              { return index_file_name.String(); }
    66         void         SetIndexFileName(const char * str) { index_file_name.SetTo(str); }
    67         const char * WebDir()                     { return web_directory.String(); }
    68         void         SetWebDir(const char * str)  { web_directory.SetTo(str); }
     63            bool            DirListFlag()
     64                                { return fDirListFlag; }
     65            void            SetDirListFlag(bool flag)
     66                                { fDirListFlag = flag; }
     67            const char*     IndexFileName()
     68                                { return fIndexFileName.String(); }
     69            void            SetIndexFileName(const char* str)
     70                                { fIndexFileName.SetTo(str); }
     71            const char*     WebDir()
     72                                { return fWebDirectory.String(); }
     73            void            SetWebDir(const char* str)
     74                                { fWebDirectory.SetTo(str); }
    6975        // Logging Tab
    70         bool         LogConsoleFlag()             { return log_console_flag; }
    71         void         SetLogConsoleFlag(bool flag) { log_console_flag = flag; }
    72         bool         LogFileFlag()                { return log_file_flag; }
    73         void         SetLogFileFlag(bool flag)    { log_file_flag = flag; }
    74         const char * LogPath()                    { return log_path.String(); }
    75         void         SetLogPath(const char * str);
     76            bool            LogConsoleFlag()
     77                                { return fLogConsoleFlag; }
     78            void            SetLogConsoleFlag(bool flag)
     79                                { fLogConsoleFlag = flag; }
     80            bool            LogFileFlag()
     81                                { return fLogFileFlag; }
     82            void            SetLogFileFlag(bool flag)
     83                                { fLogFileFlag = flag; }
     84            const char*     LogPath()
     85                                { return fLogPath.String(); }
     86            void            SetLogPath(const char* str);
    7687        // Advanced Tab
    77         int16        MaxConnections()             { return max_connections; }
    78         void         SetMaxConnections(int16 num) { max_connections = num;  }
     88            int16           MaxConnections()
     89                                { return fMaxConnections; }
     90            void            SetMaxConnections(int16 num)
     91                                { fMaxConnections = num;  }
    7992
    80 
    8193private:
    8294    // -------------------------------------------
    8395    // PoorMan Window Methods
    84         void        UpdateStatusLabelAndMenuItem();
    85         void        UpdateHitsLabel();
     96            void            UpdateStatusLabelAndMenuItem();
     97            void            UpdateHitsLabel();
    8698   
    8799private:
    88100    // -------------------------------------------
    89     // PoorMan Window
    90     PoorManView     * mainView;
    91    
    92     // -------------------------------------------
    93101    // Build Menu Methods
    94     BMenu *     BuildFileMenu() const;
    95     BMenu *     BuildEditMenu() const;
    96     BMenu *     BuildControlsMenu() const;
     102            BMenu*          BuildfFileMenu() const;
     103            BMenu*          BuildEditMenu() const;
     104            BMenu*          BuildControlsMenu() const;
    97105   
    98106    // --------------------------------------------
    99107    // MenuBar & Menu items
    100     BMenuBar *  FileMenuBar;
    101     BMenu    *  FileMenu;
    102     BMenu    *  EditMenu;
    103     BMenu    *  ControlsMenu;
     108            BMenuBar*       fFileMenuBar;
     109            BMenu*          fFileMenu;
     110            BMenu*          fEditMenu;
     111            BMenu*          fControlsMenu;
    104112   
    105113    // --------------------------------------------
    106114    // Status, Hits, Directory
    107     BStringView *   statusView;
    108     BStringView *   hitsView;
    109     BStringView *   dirView;
     115            BStringView*    fStatusView;
     116            BStringView*    fHitsView;
     117            BStringView*    fDirView;
    110118   
    111     bool            status;
    112     uint32          hits;
    113     char            hitsLabel[25];
     119            bool            fStatus;
     120            uint32          fHits;
     121            char            fHitsLabel[25];
    114122   
    115123    // --------------------------------------------
    116124    // Logging View
    117     BScrollView *   scrollView;
    118     BTextView   *   loggingView;
     125            BScrollView*    fScrollView;
     126            BTextView*      fLoggingView;
    119127    // use asctime() for format of [Date/Time]:
    120128   
    121129
    122130    // -------------------------------------------
    123131    // PoorMan Preference Window
    124     PoorManPreferencesWindow * prefWindow;
     132            PoorManPreferencesWindow * fPrefWindow;
    125133   
    126134    // site tab
    127     BString         web_directory;
    128     BString         index_file_name;
    129     bool            dir_list_flag;
     135            BString         fWebDirectory;
     136            BString         fIndexFileName;
     137            bool            fDirListFlag;
    130138
    131139    // logging tab
    132     bool            log_console_flag;
    133     bool            log_file_flag;
    134     BString         log_path;
     140            bool            fLogConsoleFlag;
     141            bool            fLogFileFlag;
     142            BString         fLogPath;
    135143   
    136144    // advanced tab
    137     int16           max_connections;
     145            int16           fMaxConnections;
    138146       
    139     bool            is_zoomed;
    140     float           last_width;
    141     float           last_height;
    142     BRect           frame;
    143     BRect           setwindow_frame;
     147            bool            fIsZoomed;
     148            float           fLastWidth;
     149            float           fLastHeight;
     150            BRect           fFrame;
     151            BRect           fSetwindowFrame;
    144152   
    145153    // File Panels
    146     BFilePanel  *   saveConsoleFilePanel;
    147     BFilePanel  *   saveConsoleSelectionFilePanel;
     154            BFilePanel*     fSaveConsoleFilePanel;
     155            BFilePanel*     fSaveConsoleSelectionFilePanel;
    148156
    149     BFile* fLogFile;
    150     BFont* fLogViewFont;
     157            BFile*          fLogFile;
    151158   
    152     PoorManServer* fServer;
     159            PoorManServer*  fServer;
    153160   
    154     pthread_rwlock_t fLogFileLock;
     161            pthread_rwlock_t fLogFileLock;
    155162};
    156163
    157164#endif
  • src/apps/poorman/PoorManView.h

     
    1212#include <View.h>
    1313#endif
    1414
    15 class PoorManView: public BView
    16 {
     15class PoorManView: public BView {
    1716public:
    18                 PoorManView(BRect, char *name);
    19 virtual void    AttachedToWindow();
     17                            PoorManView(BRect, char *name);
     18
     19    virtual void            AttachedToWindow();
    2020};
    2121
    2222#endif
  • src/apps/poorman/PoorManLoggingView.cpp

     
    66 */
    77 
    88#include <Box.h>
     9#include <GroupLayoutBuilder.h>
    910
    1011#include "constants.h"
    1112#include "PoorManWindow.h"
    1213#include "PoorManApplication.h"
    1314#include "PoorManLoggingView.h"
    1415
    15 PoorManLoggingView::PoorManLoggingView(BRect rect, const char *name)
    16     : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
     16PoorManLoggingView::PoorManLoggingView(const char* name)
     17    :
     18    BView(name, B_WILL_DRAW, NULL)
    1719{
    18     PoorManWindow   *   win;
    19     win = ((PoorManApplication *)be_app)->GetPoorManWindow();
     20    PoorManWindow* win;
     21    win = ((PoorManApplication*)be_app)->GetPoorManWindow();
    2022   
    21     SetViewColor(BACKGROUND_COLOR);
     23    SetLayout(new BGroupLayout(B_VERTICAL));
    2224   
    2325    // Console Logging BBox
    24     BRect consoleLoggingRect;
    25     consoleLoggingRect = rect;
    26     consoleLoggingRect.top -= 5.0;
    27     consoleLoggingRect.left -= 5.0;
    28     consoleLoggingRect.right -= 7.0;
    29     consoleLoggingRect.bottom -= 118.0;
    30    
    31     BBox * consoleLogging = new BBox(consoleLoggingRect, "Console Logging");
     26    BBox* consoleLogging = new BBox("Console Logging");
    3227    consoleLogging->SetLabel(STR_BBX_CONSOLE_LOGGING);
    33     AddChild(consoleLogging);
    34 
    3528   
    3629    // File Logging BBox
    37     BRect fileLoggingRect;
    38     fileLoggingRect = consoleLoggingRect;
    39     fileLoggingRect.top = consoleLoggingRect.bottom + 10.0;
    40     fileLoggingRect.bottom = fileLoggingRect.top + 100.0;
    41 
    42     BBox * fileLogging = new BBox(fileLoggingRect, "File Logging");
     30    BBox* fileLogging = new BBox("File Logging");
    4331    fileLogging->SetLabel(STR_BBX_FILE_LOGGING);
    44     AddChild(fileLogging);
    4532   
    46     float left = 10.0;
    47     float top = 20.0;
    48     float box_size = 13.0;
    49     BRect tempRect(left, top, consoleLoggingRect.Width() - 5.0, top + box_size);
    50    
    5133    // Console Logging
    52     logConsole = new BCheckBox(tempRect, "Log To Console", STR_CBX_LOG_CONSOLE, new BMessage(MSG_PREF_LOG_CBX_CONSOLE));
     34    fLogConsole = new BCheckBox("Log To Console", STR_CBX_LOG_CONSOLE,
     35        new BMessage(MSG_PREF_LOG_CBX_CONSOLE));
    5336    // set the checkbox to the value the program has
    5437    SetLogConsoleValue(win->LogConsoleFlag());
    55     consoleLogging->AddChild(logConsole);
    5638   
    5739    // File Logging
    58     logFile = new BCheckBox(tempRect, "Log To File", STR_CBX_LOG_FILE, new BMessage(MSG_PREF_LOG_CBX_FILE));
     40    fLogFile = new BCheckBox("Log To File", STR_CBX_LOG_FILE,
     41        new BMessage(MSG_PREF_LOG_CBX_FILE));
    5942    // set the checkbox to the value the program has
    6043    SetLogFileValue(win->LogFileFlag());
    61     fileLogging->AddChild(logFile);
    6244   
    6345    // File Name
    64     tempRect.top = tempRect.bottom + 10.0;
    65     tempRect.bottom = tempRect.top + box_size;
    66     tempRect.right -= 5.0;
    67    
    68     logFileName = new BTextControl(tempRect, "File Name", STR_TXT_LOG_FILE_NAME, NULL, NULL);
    69     logFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
    70     logFileName->SetDivider(73.0);
     46    fLogFileName = new BTextControl("File Name", STR_TXT_LOG_FILE_NAME,
     47        NULL, NULL);
    7148    SetLogFileName(win->LogPath());
    72     fileLogging->AddChild(logFileName);
    7349   
    7450    // Create Log File
    75     BRect createLogFileRect;
    76     createLogFileRect.top = tempRect.bottom + 13.0;
    77     createLogFileRect.right = tempRect.right + 2.0;
    78     createLogFileRect.left = createLogFileRect.right - 87.0;
    79     createLogFileRect.bottom = createLogFileRect.top + 19.0;
    80    
    81     createLogFile = new BButton(createLogFileRect, "Create Log File", STR_BTN_CREATE_LOG_FILE, new BMessage(MSG_PREF_LOG_BTN_CREATE_FILE));
    82     fileLogging->AddChild(createLogFile);
     51    fCreateLogFile = new BButton("Create Log File", STR_BTN_CREATE_LOG_FILE,
     52        new BMessage(MSG_PREF_LOG_BTN_CREATE_FILE));
    8353
     54    consoleLogging->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     55        .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
     56            .Add(fLogConsole)
     57            .AddGlue())
     58        .SetInsets(5, 5, 5, 5));
     59       
     60    fileLogging->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     61        .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
     62            .Add(fLogFile)
     63            .AddGlue())
     64        .Add(fLogFileName)
     65        .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
     66            .AddGlue()
     67            .Add(fCreateLogFile))
     68        .SetInsets(5, 5, 5, 5));
     69   
     70    AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     71        .Add(consoleLogging)
     72        .Add(fileLogging)
     73        .SetInsets(5, 5, 5, 5));
    8474}
  • src/apps/poorman/PoorManLoggingView.h

     
    1414#include <CheckBox.h>
    1515
    1616
    17 class PoorManLoggingView: public BView
    18 {
     17class PoorManLoggingView: public BView {
    1918public:
    20                 PoorManLoggingView(BRect, const char *name);
     19                            PoorManLoggingView(const char* name);
    2120               
    22         void    SetLogConsoleValue(bool state) {if (state) logConsole->SetValue(B_CONTROL_ON);
    23                                                 else logConsole->SetValue(B_CONTROL_OFF); }
    24         bool    LogConsoleValue() { return (logConsole->Value() == B_CONTROL_ON) ? true : false; }
    25         void    SetLogFileValue(bool state) {if (state) logFile->SetValue(B_CONTROL_ON);
    26                                                 else logFile->SetValue(B_CONTROL_OFF); }
    27         bool    LogFileValue() { return (logFile->Value() == B_CONTROL_ON) ? true : false; }
    28 const   char *  LogFileName() { return logFileName->Text(); }
    29         void    SetLogFileName(const char * log) { logFileName->SetText(log); }
     21            void            SetLogConsoleValue(bool state)
     22                                { if (state)
     23                                    fLogConsole->SetValue(B_CONTROL_ON);
     24                                    else fLogConsole->SetValue(B_CONTROL_OFF); }
     25            bool            LogConsoleValue()
     26                                { return (fLogConsole->Value() == B_CONTROL_ON)
     27                                    ? true : false; }
     28            void            SetLogFileValue(bool state)
     29                                { if (state) fLogFile->SetValue(B_CONTROL_ON);
     30                                    else fLogFile->SetValue(B_CONTROL_OFF); }
     31            bool            LogFileValue()
     32                                { return (fLogFile->Value() == B_CONTROL_ON)
     33                                    ? true : false; }
     34            const char*     LogFileName()
     35                                { return fLogFileName->Text(); }
     36            void            SetLogFileName(const char* log)
     37                                { fLogFileName->SetText(log); }
     38
    3039private:
    31         // Logging Tab
    32 
     40            // Logging Tab
    3341            // Console Logging
    34             BCheckBox       *   logConsole;
     42            BCheckBox*      fLogConsole;
    3543            // File Logging
    36             BCheckBox       *   logFile;
    37             BTextControl    *   logFileName;
    38             BButton         *   createLogFile;
     44            BCheckBox*      fLogFile;
     45            BTextControl*   fLogFileName;
     46            BButton *       fCreateLogFile;
    3947};
    4048
    4149#endif
  • src/apps/poorman/PoorManPreferencesWindow.cpp

     
    99#include <Box.h>
    1010#include <Directory.h>
    1111#include <Debug.h>
     12#include <GroupLayoutBuilder.h>
     13#include <GroupView.h>
     14#include <SpaceLayoutItem.h>
    1215
    1316#include "constants.h"
    1417#include "PoorManWindow.h"
     
    1619#include "PoorManPreferencesWindow.h"
    1720#include "PoorManServer.h"
    1821
    19 PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char * name)
    20     : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
    21     webDirFilePanel(NULL),
    22     logFilePanel(NULL)
     22PoorManPreferencesWindow::PoorManPreferencesWindow(BRect frame, char* name)
     23    :
     24    BWindow(frame, name, B_TITLED_WINDOW,
     25        B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS),
     26    fWebDirFilePanel(NULL),
     27    fLogFilePanel(NULL)
    2328{
     29    SetLayout(new BGroupLayout(B_VERTICAL));
    2430
    25     frame = Bounds();
     31    fCancelButton = new BButton("Cancel Button", "Cancel",
     32        new BMessage(MSG_PREF_BTN_CANCEL));
     33    fDoneButton = new BButton("Done Button", "Done",
     34        new BMessage(MSG_PREF_BTN_DONE));
    2635
    27     prefView = new PoorManView(frame, STR_WIN_NAME_PREF);
    28     //prefView->SetViewColor(216,216,216,255);
    29     prefView->SetViewColor(BACKGROUND_COLOR);
    30     AddChild(prefView);
     36    fPrefTabView = new BTabView("Pref Tab View");
    3137
    32 
    33 
    34     // Button View
    35     BRect buttonRect;
    36     buttonRect = Bounds();
    37     buttonRect.top = buttonRect.bottom - 30;
    38 
    39     buttonView = new PoorManView(buttonRect, "Button View");
    40     buttonView->SetViewColor(BACKGROUND_COLOR);
    41     prefView->AddChild(buttonView);
    42 
    43     // Buttons
    44     float buttonTop = 0.0f;
    45     float buttonWidth = 52.0f;
    46     float buttonHeight = 26.0f;
    47     float buttonLeft = 265.0f;
    48 
    49     BRect button1;
    50     button1 = buttonView->Bounds();
    51     button1.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight);
    52     cancelButton = new BButton(button1, "Cancel Button", "Cancel", new BMessage(MSG_PREF_BTN_CANCEL));
    53 
    54     buttonLeft = 325.0f;
    55     BRect button2;
    56     button2 = buttonView->Bounds();
    57     button2.Set(buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight);
    58     doneButton = new BButton(button2, "Done Button", "Done", new BMessage(MSG_PREF_BTN_DONE));
    59 
    60     buttonView->AddChild(cancelButton);
    61     buttonView->AddChild(doneButton);
    62 
    63 
    64 
    65     // Create tabs
    66     BRect r;
    67     r = Bounds();
    68     //r.InsetBy(5, 5);
    69     r.top    += 8.0;
    70     r.bottom -= 38.0;
    71 
    72     prefTabView = new BTabView(r, "Pref Tab View");
    73     prefTabView->SetViewColor(BACKGROUND_COLOR);
    74 
    75     r = prefTabView->Bounds();
    76     r.InsetBy(5, 5);
    77     r.bottom -= prefTabView->TabHeight();
    78 
    7938    // Site Tab
    80     siteTab = new BTab();
    81     siteView = new PoorManSiteView(r, "Site View");
    82     prefTabView->AddTab(siteView, siteTab);
    83     siteTab->SetLabel(STR_TAB_SITE);
     39    fSiteTab = new BTab();
     40    fSiteView = new PoorManSiteView("Site View");
     41    fPrefTabView->AddTab(fSiteView, fSiteTab);
     42    fSiteTab->SetLabel(STR_TAB_SITE);
    8443
    8544    // Logging Tab
    86     loggingTab = new BTab();
    87     loggingView = new PoorManLoggingView(r, "Logging View");
    88     prefTabView->AddTab(loggingView, loggingTab);
    89     loggingTab->SetLabel(STR_TAB_LOGGING);
     45    fLoggingTab = new BTab();
     46    fLoggingView = new PoorManLoggingView("Logging View");
     47    fPrefTabView->AddTab(fLoggingView, fLoggingTab);
     48    fLoggingTab->SetLabel(STR_TAB_LOGGING);
    9049
    9150    // Advanced Tab
    92     advancedTab = new BTab();
    93     advancedView = new PoorManAdvancedView(r, "Advanced View");
    94     prefTabView->AddTab(advancedView, advancedTab);
    95     advancedTab->SetLabel(STR_TAB_ADVANCED);
     51    fAdvancedTab = new BTab();
     52    fAdvancedView = new PoorManAdvancedView("Advanced View");
     53    fPrefTabView->AddTab(fAdvancedView, fAdvancedTab);
     54    fAdvancedTab->SetLabel(STR_TAB_ADVANCED);
    9655
    97     prefView->AddChild(prefTabView);
    98 
    9956    // FilePanels
    10057    BWindow * change_title;
    10158
    10259    BMessenger messenger(this);
    10360    BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR);
    104     webDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL,
     61    fWebDirFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL,
    10562        B_DIRECTORY_NODE, false, &message, NULL, true);
    10663
    107     webDirFilePanel->SetPanelDirectory(new BDirectory("/boot/home/public_html"));
    108     webDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select");
    109     change_title = webDirFilePanel->Window();
     64    fWebDirFilePanel->SetPanelDirectory(
     65        new BDirectory("/boot/home/public_html"));
     66    fWebDirFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select");
     67    change_title = fWebDirFilePanel->Window();
    11068    change_title->SetTitle(STR_FILEPANEL_SELECT_WEB_DIR);
    11169
    11270    message.what = MSG_FILE_PANEL_CREATE_LOG_FILE;
    113     logFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL,
     71    fLogFilePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL,
    11472        B_FILE_NODE, false, &message);
    115     logFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create");
    116     change_title = logFilePanel->Window();
     73    fLogFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, "Create");
     74    change_title = fLogFilePanel->Window();
    11775    change_title->SetTitle(STR_FILEPANEL_CREATE_LOG_FILE);
     76   
     77    AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     78        .Add(fPrefTabView)
     79        .Add(BGroupLayoutBuilder(B_HORIZONTAL)
     80            .AddGlue()
     81            .Add(fCancelButton)
     82            .Add(fDoneButton))
     83        .SetInsets(5, 5, 5, 5));
    11884
    11985    Show();
    120 
    12186}
    12287
    12388PoorManPreferencesWindow::~PoorManPreferencesWindow()
    12489{
    125     delete logFilePanel;
    126     delete webDirFilePanel;
     90    delete fLogFilePanel;
     91    delete fWebDirFilePanel;
    12792}
    12893
    12994void
    13095PoorManPreferencesWindow::MessageReceived(BMessage* message)
    13196{
    13297    switch (message->what) {
    133     case MSG_PREF_BTN_DONE:
    134             PoorManWindow       *   win;
     98        case MSG_PREF_BTN_DONE:
     99            PoorManWindow* win;
    135100            PoorManServer* server;
    136             win = ((PoorManApplication *)be_app)->GetPoorManWindow();
     101            win = ((PoorManApplication*)be_app)->GetPoorManWindow();
    137102            server = win->GetServer();
    138103
    139             PRINT(("Pref Window: sendDir CheckBox: %d\n", siteView->SendDirValue()));
    140             server->SetListDir(siteView->SendDirValue());
    141             win->SetDirListFlag(siteView->SendDirValue());
    142             PRINT(("Pref Window: indexFileName TextControl: %s\n", siteView->IndexFileName()));
    143             if(server->SetIndexName(siteView->IndexFileName()) == B_OK)
    144                 win->SetIndexFileName(siteView->IndexFileName());
    145             PRINT(("Pref Window: webDir: %s\n", siteView->WebDir()));
    146             if(server->SetWebDir(siteView->WebDir()) == B_OK){
    147                 win->SetWebDir(siteView->WebDir());
    148                 win->SetDirLabel(siteView->WebDir());
     104            PRINT(("Pref Window: sendDir CheckBox: %d\n",
     105                siteView->SendDirValue()));
     106            server->SetListDir(fSiteView->SendDirValue());
     107            win->SetDirListFlag(fSiteView->SendDirValue());
     108           
     109            PRINT(("Pref Window: indexFileName TextControl: %s\n",
     110                fSiteView->IndexFileName()));
     111            if(server->SetIndexName(fSiteView->IndexFileName()) == B_OK)
     112                win->SetIndexFileName(fSiteView->IndexFileName());
     113           
     114            PRINT(("Pref Window: webDir: %s\n", fSiteView->WebDir()));
     115            if(server->SetWebDir(fSiteView->WebDir()) == B_OK){
     116                win->SetWebDir(fSiteView->WebDir());
     117                win->SetDirLabel(fSiteView->WebDir());
    149118            }
    150119
    151             PRINT(("Pref Window: logConsole CheckBox: %d\n", loggingView->LogConsoleValue()));
    152             win->SetLogConsoleFlag(loggingView->LogConsoleValue());
    153             PRINT(("Pref Window: logFile CheckBox: %d\n", loggingView->LogFileValue()));
    154             win->SetLogFileFlag(loggingView->LogFileValue());
    155             PRINT(("Pref Window: logFileName: %s\n", loggingView->LogFileName()));
    156             win->SetLogPath(loggingView->LogFileName());
     120            PRINT(("Pref Window: logConsole CheckBox: %d\n",
     121                fLoggingView->LogConsoleValue()));
     122            win->SetLogConsoleFlag(fLoggingView->LogConsoleValue());
     123           
     124            PRINT(("Pref Window: logFile CheckBox: %d\n",
     125                fLoggingView->LogFileValue()));
     126            win->SetLogFileFlag(fLoggingView->LogFileValue());
     127           
     128            PRINT(("Pref Window: logFileName: %s\n",
     129                fLoggingView->LogFileName()));
     130            win->SetLogPath(fLoggingView->LogFileName());
    157131
    158             PRINT(("Pref Window: MaxConnections Slider: %ld\n", advancedView->MaxSimultaneousConnections()));
    159             server->SetMaxConns(advancedView->MaxSimultaneousConnections());
    160             win->SetMaxConnections((int16)advancedView->MaxSimultaneousConnections());
     132            PRINT(("Pref Window: MaxConnections Slider: %ld\n",
     133                fAdvancedView->MaxSimultaneousConnections()));
     134            server->SetMaxConns(fAdvancedView->MaxSimultaneousConnections());
     135            win->SetMaxConnections(
     136                (int16)fAdvancedView->MaxSimultaneousConnections());
    161137
    162 
    163138            if (Lock())
    164139                Quit();
    165         break;
    166     case MSG_PREF_BTN_CANCEL:
     140            break;
     141
     142        case MSG_PREF_BTN_CANCEL:
    167143            if (Lock())
    168144                Quit();
    169         break;
    170     case MSG_PREF_SITE_BTN_SELECT:
     145            break;
     146
     147        case MSG_PREF_SITE_BTN_SELECT:
    171148            // Select the Web Directory, root directory to look in.
    172             if (!webDirFilePanel->IsShowing())
    173                 webDirFilePanel->Show();
    174         break;
    175     case MSG_FILE_PANEL_SELECT_WEB_DIR:
     149            if (!fWebDirFilePanel->IsShowing())
     150                fWebDirFilePanel->Show();
     151            break;
     152
     153        case MSG_FILE_PANEL_SELECT_WEB_DIR:
    176154            // handle the open BMessage from the Select Web Directory File Panel
    177155            PRINT(("Select Web Directory:\n"));
    178156            SelectWebDir(message);
    179         break;
    180     case MSG_PREF_LOG_BTN_CREATE_FILE:
     157            break;
     158
     159        case MSG_PREF_LOG_BTN_CREATE_FILE:
    181160            // Create the Log File
    182             logFilePanel->Show();
    183         break;
    184     case MSG_FILE_PANEL_CREATE_LOG_FILE:
     161            fLogFilePanel->Show();
     162            break;
     163
     164        case MSG_FILE_PANEL_CREATE_LOG_FILE:
    185165            // handle the save BMessage from the Create Log File Panel
    186166            PRINT(("Create Log File:\n"));
    187167            CreateLogFile(message);
    188         break;
    189     case MSG_PREF_ADV_SLD_MAX_CONNECTION:
    190             max_connections = advancedView->MaxSimultaneousConnections();
    191             PRINT(("Max Connections: %ld\n", max_connections));
    192         break;
     168            break;
    193169
    194     default:
    195         BWindow::MessageReceived(message);
    196         break;
     170        case MSG_PREF_ADV_SLD_MAX_CONNECTION:
     171            fMaxConnections = fAdvancedView->MaxSimultaneousConnections();
     172            PRINT(("Max Connections: %ld\n", fMaxConnections));
     173            break;
     174
     175        default:
     176            BWindow::MessageReceived(message);
     177            break;
    197178    }
    198179}
    199180
    200181void
    201 PoorManPreferencesWindow::SelectWebDir(BMessage * message)
     182PoorManPreferencesWindow::SelectWebDir(BMessage* message)
    202183{
    203184    entry_ref   ref;
    204     const char  * name;
     185    const char* name;
    205186    BPath       path;
    206187    BEntry      entry;
    207188    status_t    err = B_OK;
     
    218199    entry.GetPath(&path);
    219200
    220201    PRINT(("DIR: %s\n", path.Path()));
    221     siteView->SetWebDir(path.Path());
     202    fSiteView->SetWebDir(path.Path());
    222203   
    223204    bool temp;
    224     if(message->FindBool("Default Dialog", &temp) == B_OK){
    225         PoorManWindow* win = ((PoorManApplication *)be_app)->GetPoorManWindow();
    226         if(win->GetServer()->SetWebDir(siteView->WebDir()) == B_OK){
    227             win->SetWebDir(siteView->WebDir());
    228             win->SetDirLabel(siteView->WebDir());
     205    if (message->FindBool("Default Dialog", &temp) == B_OK) {
     206        PoorManWindow* win =
     207            ((PoorManApplication *)be_app)->GetPoorManWindow();
     208       
     209        if (win->GetServer()->SetWebDir(fSiteView->WebDir()) == B_OK) {
     210            win->SetWebDir(fSiteView->WebDir());
     211            win->SetDirLabel(fSiteView->WebDir());
    229212        }
     213       
    230214        win->StartServer();
     215       
    231216        if(Lock())
    232217            Quit();
    233218    }
    234219}
    235220
    236221void
    237 PoorManPreferencesWindow::CreateLogFile(BMessage * message)
     222PoorManPreferencesWindow::CreateLogFile(BMessage* message)
    238223{
    239224    entry_ref   ref;
    240     const char  * name;
     225    const char* name;
    241226    BPath       path;
    242227    BEntry      entry;
    243228    status_t    err = B_OK;
     
    255240    path.Append(name);
    256241    PRINT(("Log File: %s\n", path.Path()));
    257242
    258     if (err == B_OK)
    259     {
    260         loggingView->SetLogFileName(path.Path());
    261         loggingView->SetLogFileValue(true);
     243    if (err == B_OK) {
     244        fLoggingView->SetLogFileName(path.Path());
     245        fLoggingView->SetLogFileValue(true);
    262246    }
    263247
    264248    // mark the checkbox
     
    271255    BMessage message(MSG_FILE_PANEL_SELECT_WEB_DIR);
    272256    message.AddBool("Default Dialog", true);
    273257   
    274     webDirFilePanel->SetMessage(&message);
    275     if(!webDirFilePanel->IsShowing())
    276         webDirFilePanel->Show();
     258    fWebDirFilePanel->SetMessage(&message);
     259    if(!fWebDirFilePanel->IsShowing())
     260        fWebDirFilePanel->Show();
    277261}
  • src/apps/poorman/StatusSlider.cpp

     
    1111#include <stdio.h>
    1212
    1313
    14 StatusSlider::StatusSlider   (BRect frame,
    15                 const char *name,
    16                 const char *label,
    17                 char *statusPrefix,
    18                 BMessage *message,
    19                 int32 minValue,
    20                 int32 maxValue)
    21            
    22             :   BSlider(frame,
    23                         name,
    24                         label,
    25                         message,
    26                         minValue,
    27                         maxValue
    28                         ),
    29                 StatusPrefix(statusPrefix)
     14StatusSlider::StatusSlider(const char* name, const char* label,
     15    char* statusPrefix, BMessage* message, int32 minValue, int32 maxValue)
     16    :
     17    BSlider(name, label, message, minValue, maxValue, B_HORIZONTAL),
     18    fStatusPrefix(statusPrefix)
    3019{
    31     temp = str;
     20    fTemp = fStr;
    3221}
    33                
     22
     23           
    3424char*
    3525StatusSlider::UpdateText() const
    3626{
    37    
    38     sprintf(temp, "%ld %s", Value(), StatusPrefix);
    39    
    40     return temp;
     27    sprintf(fTemp, "%ld %s", Value(), fStatusPrefix);
     28
     29    return fTemp;
    4130}
  • src/apps/poorman/PoorManPreferencesWindow.h

     
    2222#include "PoorManAdvancedView.h"
    2323
    2424
     25class PoorManPreferencesWindow: public BWindow {
     26public:
     27                            PoorManPreferencesWindow(BRect frame, char* name);
     28                            ~PoorManPreferencesWindow();
    2529
     30    virtual void            MessageReceived(BMessage* message);
    2631
    27 class PoorManPreferencesWindow: public BWindow
    28 {
     32            void            ShowWebDirFilePanel();
     33            void            SelectWebDir(BMessage* message);
     34            void            CreateLogFile(BMessage* message);
     35
    2936private:
     37            PoorManView*    fPrefView;
     38            PoorManView*    fButtonView;
    3039
    31                 PoorManView *   prefView;
    32                 PoorManView *   buttonView;
     40            // ------------------------------------------------
     41            // Tabs
     42            BTabView*       fPrefTabView;
     43            BTab*           fSiteTab;
     44            BTab*           fLoggingTab;
     45            BTab*           fAdvancedTab;
     46            // Tab Views
     47            PoorManSiteView*        fSiteView;
     48            PoorManLoggingView*     fLoggingView;
     49            PoorManAdvancedView*    fAdvancedView;
    3350
    34                 // ------------------------------------------------
    35                 // Tabs
    36                 BTabView    *   prefTabView;
    37                 BTab        *   siteTab;
    38                 BTab        *   loggingTab;
    39                 BTab        *   advancedTab;
    40                 // Tab Views
    41                 PoorManSiteView     *   siteView;
    42                 PoorManLoggingView  *   loggingView;
    43                 PoorManAdvancedView *   advancedView;
     51            // ------------------------------------------------
     52            // Buttons
     53            BButton*        fCancelButton;
     54            BButton*        fDoneButton;
    4455
    45                 // ------------------------------------------------
    46                 // Buttons
    47                 BButton     *   cancelButton;
    48                 BButton     *   doneButton;
     56            // ------------------------------------------------
     57            // FilePanels
     58            BFilePanel*     fWebDirFilePanel;
     59            BFilePanel*     fLogFilePanel;
    4960
    50                 // ------------------------------------------------
    51                 // FilePanels
    52                 BFilePanel  *   webDirFilePanel;
    53                 BFilePanel  *   logFilePanel;
    5461
    55 
    5662                // ------------------------------------------------
    57                 // temporary preference variables used to save and
    58                 // set the application to
    59                 // site tab
    60                 char        web_directory[B_FILE_NAME_LENGTH];
    61                 char        index_file_name[64];
    62                 bool        send_dir;
    63                 // logging tab
    64                 bool        log_to_console;
    65                 bool        log_to_file;
    66                 char        log_file_name[B_FILE_NAME_LENGTH];
    67                 // advanced tab
    68                 int32       max_connections;
    69 public:
    70                 PoorManPreferencesWindow(BRect frame, char * name);
    71                 ~PoorManPreferencesWindow();
    72 
    73 virtual void    MessageReceived(BMessage * message);
    74 
    75         void    ShowWebDirFilePanel();
    76         void    SelectWebDir(BMessage * message);
    77         void    CreateLogFile(BMessage * message);
     63            // temporary preference variables used to save and
     64            // set the application to
     65            // site tab
     66            char            fWebDirectory[B_FILE_NAME_LENGTH];
     67            char            fIndexFileName[64];
     68            bool            fSendDir;
     69            // logging tab
     70            bool            flogToConsole;
     71            bool            fLogToFile;
     72            char            fLogFileName[B_FILE_NAME_LENGTH];
     73            // advanced tab
     74            int32           fMaxConnections;
    7875};
    7976
    8077#endif
  • src/apps/poorman/PoorManSiteView.cpp

     
    66 */
    77 
    88#include <Box.h>
     9#include <GroupLayoutBuilder.h>
    910
    1011#include "constants.h"
    1112#include "PoorManSiteView.h"
    1213#include "PoorManWindow.h"
    1314#include "PoorManApplication.h"
    1415
    15 PoorManSiteView::PoorManSiteView(BRect rect, const char *name)
    16     : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
     16PoorManSiteView::PoorManSiteView(const char* name)
     17    :
     18    BView(name, B_WILL_DRAW, NULL)
    1719{
    18     PoorManWindow   *   win;
     20    PoorManWindow* win;
    1921    win = ((PoorManApplication *)be_app)->GetPoorManWindow();
    2022
    21     SetViewColor(BACKGROUND_COLOR);
     23    SetLayout(new BGroupLayout(B_VERTICAL));
    2224
    2325    // Web Site Location BBox
    24     BRect webLocationRect;
    25     webLocationRect = rect;
    26     webLocationRect.top -= 5.0;
    27     webLocationRect.left -= 5.0;
    28     webLocationRect.right -= 7.0;
    29     webLocationRect.bottom -= 98.0;
    30 
    31     BBox * webSiteLocation = new BBox(webLocationRect, "Web Location");
     26    BBox* webSiteLocation = new BBox("Web Location");
    3227    webSiteLocation->SetLabel(STR_BBX_LOCATION);
    33     AddChild(webSiteLocation);
    3428   
    3529    // Web Site Options BBox
    36     BRect webOptionsRect;
    37     webOptionsRect = webLocationRect;
    38     webOptionsRect.top = webOptionsRect.bottom + 10.0;
    39     webOptionsRect.bottom = webOptionsRect.top + 80.0;
    40 
    41     BBox * webSiteOptions = new BBox(webOptionsRect, "Web Options");
     30    BBox* webSiteOptions = new BBox("Web Options");
    4231    webSiteOptions->SetLabel(STR_BBX_OPTIONS);
    43     AddChild(webSiteOptions);
    4432
    4533    // Send Directory List if No Index
    46     float left = 10.0;
    47     float top = 20.0;
    48     float box_size = 13.0;
    49     BRect sendDirRect(left, top, webOptionsRect.Width() - 5.0, top + box_size);
    50     sendDir = new BCheckBox(sendDirRect, "Send Dir", STR_CBX_DIR_LIST_LABEL, new BMessage(MSG_PREF_SITE_CBX_INDEX));
     34    fSendDir = new BCheckBox("Send Dir", STR_CBX_DIR_LIST_LABEL,
     35        new BMessage(MSG_PREF_SITE_CBX_INDEX));
    5136    // set the checkbox to the value the program has
    5237    SetSendDirValue(win->DirListFlag());
    53     webSiteOptions->AddChild(sendDir);
    5438
    55 
    56     // Finish the Web Site Location Section
    57     BRect webSiteLocationRect;
    58     webSiteLocationRect = webLocationRect;
    59     webSiteLocationRect.InsetBy(10.0, 7.0);
    60     webSiteLocationRect.top += 13.0;
    61     webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0;
    62    
    6339    // Web Directory Text Control
    64     webDir = new BTextControl(webSiteLocationRect, "Web Dir", STR_TXT_DIRECTORY, NULL, NULL);
    65     webDir->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
    66     webDir->SetDivider(80.0);
     40    fWebDir = new BTextControl("Web Dir", STR_TXT_DIRECTORY, NULL);
    6741    SetWebDir(win->WebDir());
    68     webSiteLocation->AddChild(webDir);
    6942   
    7043    // Select Web Directory Button
    71     BRect selectWebDirRect;
    72     selectWebDirRect.top = webSiteLocationRect.bottom + 5.0;
    73     selectWebDirRect.right = webSiteLocationRect.right + 2.0;
    74     selectWebDirRect.left = selectWebDirRect.right - 123.0;
    75     selectWebDirRect.bottom = selectWebDirRect.top + 19.0;
     44    fSelectWebDir = new BButton("Select Web Dir", STR_BTN_DIRECTORY,
     45        new BMessage(MSG_PREF_SITE_BTN_SELECT));
    7646   
    77     selectWebDir = new BButton(selectWebDirRect, "Select Web Dir", STR_BTN_DIRECTORY, new BMessage(MSG_PREF_SITE_BTN_SELECT));
    78     webSiteLocation->AddChild(selectWebDir);
    79    
    8047    // Index File Name Text Control
    81     //webDirRect.InsetBy(10.0, 7.0);
    82     webSiteLocationRect.top += 63.0;
    83     webSiteLocationRect.bottom = webSiteLocationRect.top + 19.0;
    84    
    85     indexFileName = new BTextControl(webSiteLocationRect, "Index File Name", STR_TXT_INDEX, NULL, NULL);
    86     indexFileName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
    87     indexFileName->SetDivider(80.0);
     48    fIndexFileName = new BTextControl("Index File Name", STR_TXT_INDEX, NULL);
    8849    SetIndexFileName(win->IndexFileName());
    89     webSiteLocation->AddChild(indexFileName);
    9050   
     51    webSiteOptions->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     52        .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
     53            .Add(fSendDir)
     54            .AddGlue())
     55        .SetInsets(5, 5, 5, 5));
     56       
     57    webSiteLocation->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     58        .Add(fWebDir)
     59        .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
     60            .AddGlue()
     61            .Add(fSelectWebDir))
     62        .Add(fIndexFileName)
     63        .SetInsets(5, 5, 5, 5));
     64   
     65    AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     66        .Add(webSiteLocation)
     67        .Add(webSiteOptions)
     68        .SetInsets(5, 5, 5, 5));
    9169}
  • src/apps/poorman/StatusSlider.h

     
    1313#include <Slider.h>
    1414
    1515
    16 class StatusSlider: public BSlider
    17 {
     16class StatusSlider: public BSlider {
    1817public:
    19         StatusSlider(BRect frame,
    20                     const char *name,
    21                     const char *label,
    22                     char *statusPrefix,
    23                     BMessage *message,
    24                     int32 minValue,
    25                     int32 maxValue);
    26 virtual char*   UpdateText() const;
     18                            StatusSlider(const char* name,
     19                                const char* label,
     20                                char* statusPrefix,
     21                                BMessage* message,
     22                                int32 minValue,
     23                                int32 maxValue);
     24
     25    virtual char*           UpdateText() const;
     26
    2727private:
    28     char *  StatusPrefix;
    29     char *  temp;
    30     char    str[128];
     28            char*           fStatusPrefix;
     29            char*           fTemp;
     30            char            fStr[128];
    3131};
    3232
    3333#endif
  • src/apps/poorman/PoorManAdvancedView.cpp

     
    66 */
    77
    88#include <Box.h>
    9  
     9#include <GroupLayoutBuilder.h>
     10
    1011#include "constants.h"
    1112#include "PoorManAdvancedView.h"
    1213#include "PoorManWindow.h"
    1314#include "PoorManApplication.h"
    1415
    15 PoorManAdvancedView::PoorManAdvancedView(BRect rect, const char *name)
    16     : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
     16
     17PoorManAdvancedView::PoorManAdvancedView(const char* name)
     18    :
     19    BView(name, B_WILL_DRAW, NULL)
    1720{
    18     PoorManWindow   *   win;
    19     win = ((PoorManApplication *)be_app)->GetPoorManWindow();
     21    PoorManWindow* win;
     22    win = ((PoorManApplication*)be_app)->GetPoorManWindow();
    2023   
    21     SetViewColor(BACKGROUND_COLOR);
     24    SetLayout(new BGroupLayout(B_VERTICAL));
    2225   
    23     // Console Logging BBox
    24     BRect maxRect;
    25     maxRect = rect;
    26     maxRect.top -= 5.0;
    27     maxRect.left -= 5.0;
    28     maxRect.right -= 7.0;
    29     maxRect.bottom -= 118.0;
    30    
    31     BBox * connectionOptions = new BBox(maxRect, "Connection Options");
     26    BBox* connectionOptions = new BBox("Connection Options");
    3227    connectionOptions->SetLabel(STR_BBX_CONNECTION);
    33     AddChild(connectionOptions);
    3428   
    35     BRect sliderRect;
    36     sliderRect = connectionOptions->Bounds();
    37     sliderRect.InsetBy(10.0f, 10.0f);
    38     sliderRect.top += 10;
    39     sliderRect.bottom = sliderRect.top + 50.0;
     29    fMaxConnections = new StatusSlider("Max Slider", STR_SLD_LABEL,
     30        STR_SLD_STATUS_LABEL,
     31        new BMessage(MSG_PREF_ADV_SLD_MAX_CONNECTION), 1, 200);
    4032   
    41     maxConnections = new StatusSlider(sliderRect, "Max Slider", STR_SLD_LABEL,
    42         STR_SLD_STATUS_LABEL, new BMessage(MSG_PREF_ADV_SLD_MAX_CONNECTION), 1, 200);
    43    
    4433    // labels below the slider 1 and 200
    45     maxConnections->SetLimitLabels("1", "200");
     34    fMaxConnections->SetLimitLabels("1", "200");
    4635    SetMaxSimutaneousConnections(win->MaxConnections());
    47     connectionOptions->AddChild(maxConnections);
     36   
     37    connectionOptions->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     38        .Add(fMaxConnections)
     39        .SetInsets(5, 5, 5, 5));
     40       
     41    AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     42        .Add(connectionOptions)
     43        .AddGlue()
     44        .SetInsets(5, 5, 5, 5));
    4845}
    4946
    5047void
    5148PoorManAdvancedView::SetMaxSimutaneousConnections(int32 num)
    5249{
    5350    if (num <= 0 || num > 200)
    54         maxConnections->SetValue(32);
     51        fMaxConnections->SetValue(32);
    5552    else   
    56         maxConnections->SetValue(num);
     53        fMaxConnections->SetValue(num);
    5754}