From: <ane...@us...> - 2014-01-06 00:56:20
|
Revision: 948 http://sourceforge.net/p/vision/code/948 Author: anevilyak Date: 2014-01-06 00:56:17 +0000 (Mon, 06 Jan 2014) Log Message: ----------- Applied patch by GCI student "Freeman". Resolves Feature Request #5. Thanks! Modified Paths: -------------- branches/0.9.7/src/PrefLog.cpp branches/0.9.7/src/PrefLog.h branches/0.9.7/src/VisionMessages.h branches/0.9.7/src/VisionStrings.h branches/0.9.7/src/VisionStrings.h.en Modified: branches/0.9.7/src/PrefLog.cpp =================================================================== --- branches/0.9.7/src/PrefLog.cpp 2013-10-20 19:02:54 UTC (rev 947) +++ branches/0.9.7/src/PrefLog.cpp 2014-01-06 00:56:17 UTC (rev 948) @@ -26,7 +26,11 @@ #include "VTextControl.h" #include <Alert.h> +#include <Button.h> #include <CheckBox.h> +#include <Directory.h> +#include <FindDirectory.h> +#include <Entry.h> #include <Path.h> #include <ctype.h> @@ -58,6 +62,15 @@ checkboxRect.top += fLogStampFormat->Bounds().Height() * 1.2; BMessage msg (M_PREFLOG_CHECKBOX_CHANGED); + fClearLogs = new BButton(BRect(0,0,0,0), "Clear Logs", S_PREFLOG_DELETE_LOGS, + new BMessage(M_PREFLOG_DELETE_LOGS)); + fClearLogs->ResizeToPreferred(); + fClearLogs->MoveTo(fLogBaseDir->Bounds().Width() + 200, + fLogBaseDir->Frame().bottom + be_plain_font->Size()); + if (_CheckIfEmpty()) + fClearLogs->SetEnabled(false); + AddChild(fClearLogs); + checkboxRect.top += be_plain_font->Size(); checkboxRect.bottom = checkboxRect.top; msg.AddString ("setting", "timestamp"); @@ -111,6 +124,7 @@ fLogBaseDir->ResizeTo (Bounds().Width() - 15, fLogBaseDir->Bounds().Height()); fLogStampFormat->SetTarget (this); fLogStampFormat->ResizeTo (Bounds().Width() / 2.0, fLogStampFormat->Bounds().Height()); + fClearLogs->SetTarget (this); fTimeStamp->SetTarget (this); fTimeStamp->MoveTo (be_plain_font->StringWidth ("S"), fLogStampFormat->Frame().bottom + fLogStampFormat->Bounds().Height()); fLogEnabled->SetTarget (this); @@ -177,9 +191,53 @@ vision_app->SetString ("timestamp_format", 0, fLogStampFormat->Text()); } break; - + + case M_PREFLOG_DELETE_LOGS: + { + BString path(vision_app->GetString ("logBaseDir")); + BEntry entry(path.String()); + _DeleteLogs(&entry); + fClearLogs->SetEnabled(false); + } + break; + default: BView::MessageReceived (msg); break; } } + + +void +LogPrefsView::_DeleteLogs(BEntry* dir_entry) +{ + BEntry entry; + BDirectory dir(dir_entry); + dir.Rewind(); + while (dir.GetNextEntry(&entry) == B_OK) + { + if (entry.IsDirectory()) + _DeleteLogs(&entry); + else + entry.Remove(); + } +} + + +bool +LogPrefsView::_CheckIfEmpty() +{ + BString path(vision_app->GetString ("logBaseDir")); + BDirectory dir(path.String()); + BEntry entry; + while (dir.GetNextEntry(&entry) == B_OK) + { + if (entry.IsDirectory()) { + BDirectory directory(&entry); + if (directory.CountEntries() > 0) + return false; + } else + return false; + } + return true; +} Modified: branches/0.9.7/src/PrefLog.h =================================================================== --- branches/0.9.7/src/PrefLog.h 2013-10-20 19:02:54 UTC (rev 947) +++ branches/0.9.7/src/PrefLog.h 2014-01-06 00:56:17 UTC (rev 948) @@ -28,6 +28,8 @@ class BMenuField; class BCheckBox; class BBox; +class BButton; +class BEntry; class LogPrefsView : public BView { @@ -46,6 +48,10 @@ BCheckBox *fLogEnabled, *fLogFileTimestamp, *fTimeStamp; + BButton *fClearLogs; + private: + void _DeleteLogs(BEntry* dir_entry); + bool _CheckIfEmpty(); }; #endif // _PREFLOG_H Modified: branches/0.9.7/src/VisionMessages.h =================================================================== --- branches/0.9.7/src/VisionMessages.h 2013-10-20 19:02:54 UTC (rev 947) +++ branches/0.9.7/src/VisionMessages.h 2014-01-06 00:56:17 UTC (rev 948) @@ -232,6 +232,7 @@ const uint32 M_PREFLOG_LOGPATH_CHANGED = 0x2315; const uint32 M_PREFLOG_TS_FORMAT_CHANGED = 0x2316; const uint32 M_DCC_PRIVATE_CHANGED = 0x2317; +const uint32 M_PREFLOG_DELETE_LOGS = 0x2318; // misc Modified: branches/0.9.7/src/VisionStrings.h =================================================================== --- branches/0.9.7/src/VisionStrings.h 2013-10-20 19:02:54 UTC (rev 947) +++ branches/0.9.7/src/VisionStrings.h 2014-01-06 00:56:17 UTC (rev 948) @@ -369,6 +369,7 @@ #define S_PREFLOG_ALERT_TITLE "Error" #define S_PREFLOG_ALERT_TEXT "The log path you have entered is invalid." #define S_PREFLOG_ALERT_BUTTON "OK" +#define S_PREFLOG_DELETE_LOGS "Delete Log Files" // main prefs view Modified: branches/0.9.7/src/VisionStrings.h.en =================================================================== --- branches/0.9.7/src/VisionStrings.h.en 2013-10-20 19:02:54 UTC (rev 947) +++ branches/0.9.7/src/VisionStrings.h.en 2014-01-06 00:56:17 UTC (rev 948) @@ -362,7 +362,7 @@ #define S_PREFLOG_ALERT_TITLE "Error" #define S_PREFLOG_ALERT_TEXT "The log path you have entered is invalid." #define S_PREFLOG_ALERT_BUTTON "OK" - +#define S_PREFLOG_DELETE_LOGS "Delete Log Files" // main prefs view #define S_PREFGEN_APP_ITEM "Application" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |