From 53342f94c969443d6877b2b0bbfe35f4d7fb2d23 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 22 Nov 2012 23:41:11 -0500 Subject: [PATCH] Factor out report name generation as a utility function. --- .../gui/team_window/TeamWindow.cpp | 17 ++++---------- .../debugger/user_interface/util/UiUtils.cpp | 22 +++++++++++++++++++ .../debugger/user_interface/util/UiUtils.h | 4 ++++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp index 1c50a88ef0..869d9ff523 100644 --- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -44,6 +43,7 @@ #include "StackTraceView.h" #include "Tracing.h" #include "TypeComponentPath.h" +#include "UiUtils.h" #include "UserInterface.h" #include "Variable.h" #include "WatchPromptWindow.h" @@ -221,21 +221,12 @@ TeamWindow::MessageReceived(BMessage* message) case MSG_CHOOSE_DEBUG_REPORT_LOCATION: { try { - BPath teamPath(fTeam->Name()); - BDateTime currentTime; - currentTime.SetTime_t(time(NULL)); - BString filename; - filename.SetToFormat("%s-%" B_PRId32 "-debug-%02" - B_PRId32 "-%02" B_PRId32 "-%02" B_PRId32 "-%02" - B_PRId32 "-%02" B_PRId32 "-%02" B_PRId32 ".report", - teamPath.Leaf(), fTeam->ID(), currentTime.Date().Day(), - currentTime.Date().Month(), currentTime.Date().Year(), - currentTime.Time().Hour(), currentTime.Time().Minute(), - currentTime.Time().Second()); + char filename[B_FILE_NAME_LENGTH]; + UiUtils::ReportNameForTeam(fTeam, filename, sizeof(filename)); BMessenger msgr(this); fFilePanel = new BFilePanel(B_SAVE_PANEL, &msgr, NULL, 0, false, new BMessage(MSG_GENERATE_DEBUG_REPORT)); - fFilePanel->SetSaveText(filename.String()); + fFilePanel->SetSaveText(filename); fFilePanel->Show(); } catch (...) { delete fFilePanel; diff --git a/src/apps/debugger/user_interface/util/UiUtils.cpp b/src/apps/debugger/user_interface/util/UiUtils.cpp index 539e069926..72aa28120c 100644 --- a/src/apps/debugger/user_interface/util/UiUtils.cpp +++ b/src/apps/debugger/user_interface/util/UiUtils.cpp @@ -1,5 +1,6 @@ /* * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2012, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -8,11 +9,14 @@ #include +#include +#include #include #include "FunctionInstance.h" #include "Image.h" #include "StackFrame.h" +#include "Team.h" #include "Thread.h" @@ -134,3 +138,21 @@ UiUtils::ImageTypeToString(image_type type, char* buffer, size_t bufferSize) return buffer; } + + +/*static*/ const char* +UiUtils::ReportNameForTeam(::Team* team, char* buffer, size_t bufferSize) +{ + BPath teamPath(team->Name()); + BDateTime currentTime; + currentTime.SetTime_t(time(NULL)); + snprintf(buffer, bufferSize, "%s-%" B_PRId32 "-debug-%02" B_PRId32 "-%02" + B_PRId32 "-%02" B_PRId32 "-%02" B_PRId32 "-%02" B_PRId32 "-%02" + B_PRId32 ".report", teamPath.Leaf(), team->ID(), + currentTime.Date().Day(), currentTime.Date().Month(), + currentTime.Date().Year(), currentTime.Time().Hour(), + currentTime.Time().Minute(), currentTime.Time().Second()); + + return buffer; + +} diff --git a/src/apps/debugger/user_interface/util/UiUtils.h b/src/apps/debugger/user_interface/util/UiUtils.h index 4415754e35..81ed46df90 100644 --- a/src/apps/debugger/user_interface/util/UiUtils.h +++ b/src/apps/debugger/user_interface/util/UiUtils.h @@ -12,6 +12,7 @@ class BVariant; class StackFrame; +class Team; class UiUtils { @@ -25,6 +26,9 @@ public: char* buffer, size_t bufferSize); static const char* ImageTypeToString(image_type type, char* buffer, size_t bufferSize); + + static const char* ReportNameForTeam(::Team* team, + char* buffer, size_t bufferSize); };