Skip to content

Commit

Permalink
Alert when quitting while building/burning
Browse files Browse the repository at this point in the history
This addresses part of #24.
Now we pop up an alert if anything's currently building/burning/blanking.
However, since I don't know how savely abort a system()ed cdrecord or
mkisofs command, even when doing the "Quit anyway", those commands will
still run in the background.
  • Loading branch information
Humdinger committed Oct 6, 2017
1 parent 8c2953e commit f50b3b6
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 32 deletions.
66 changes: 64 additions & 2 deletions Source/BurnWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ CompilationDataView* fCompilationDataView;
CompilationAudioView* fCompilationAudioView;
CompilationImageView* fCompilationImageView;
CompilationDVDView* fCompilationDVDView;
CompilationCDRWView* fCompilationCDRWView;
CompilationCloneView* fCompilationCloneView;

#pragma mark --Constructor/Destructor--

Expand Down Expand Up @@ -70,6 +72,19 @@ BurnWindow::BurnWindow(BRect frame, const char* title)
bool
BurnWindow::QuitRequested()
{
BString text = _ActionInprogress();

if (text != "") {
text << B_TRANSLATE("\nDo you want to quit BurnItNow anyway (this "
"won't stop the action currently in progress...");
BAlert* alert = new BAlert("stopquit", text.String(),
B_TRANSLATE("Quit anyway"), B_TRANSLATE("Cancel"));

int32 button = alert->Go();
if (button)
return false;
}

if (fCacheQuitItem->IsMarked())
_ClearCache();

Expand Down Expand Up @@ -339,13 +354,15 @@ BurnWindow::_CreateTabView()
fCompilationAudioView = new CompilationAudioView(*this);
fCompilationImageView = new CompilationImageView(*this);
fCompilationDVDView = new CompilationDVDView(*this);
fCompilationCDRWView = new CompilationCDRWView(*this);
fCompilationCloneView = new CompilationCloneView(*this);

tabView->AddTab(fCompilationDataView);
tabView->AddTab(fCompilationAudioView);
tabView->AddTab(fCompilationImageView);
tabView->AddTab(fCompilationDVDView);
tabView->AddTab(new CompilationCDRWView(*this));
tabView->AddTab(new CompilationCloneView(*this));
tabView->AddTab(fCompilationCDRWView);
tabView->AddTab(fCompilationCloneView);

return tabView;
}
Expand Down Expand Up @@ -583,6 +600,51 @@ BurnWindow::_UpdateSpeedSlider(BMessage* message)
}


#pragma mark -- Private Methods --

BString
BurnWindow::_ActionInprogress()
{
BString text = "";

int32 dataProgress = fCompilationDataView->InProgress();
int32 audioProgress = fCompilationAudioView->InProgress();
int32 imageProgress = fCompilationImageView->InProgress();
int32 dvdProgress = fCompilationDVDView->InProgress();
int32 cdrwProgress = fCompilationCDRWView->InProgress();
int32 cloneProgress = fCompilationCloneView->InProgress();

if ((dataProgress == NONE)
&& (audioProgress == NONE)
&& (imageProgress == NONE)
&& (dvdProgress == NONE)
&& (cloneProgress == NONE))
return text;

text = B_TRANSLATE("BurnItNow is currently busy.\n\n");

if ((dataProgress == BUILDING)
|| (dvdProgress == BUILDING)
|| (cloneProgress == BUILDING))
text << B_TRANSLATE("The building of an image is currently in "
"progress.\n");

if ((dataProgress == BURNING)
|| (audioProgress == BURNING)
|| (imageProgress == BURNING)
|| (dvdProgress == BURNING)
|| (cloneProgress == BURNING))
text << B_TRANSLATE("The burning of a disc is currently in "
"progress.\n");

if (cdrwProgress == BLANKING)
text << B_TRANSLATE("The blanking of a disc is currently in "
"progress.\n");

return text;
}


#pragma mark -- Public Methods --

void
Expand Down
2 changes: 2 additions & 0 deletions Source/BurnWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class BurnWindow : public BWindow {
void _OpenHelp();
void _UpdateSpeedSlider(BMessage* message);

BString _ActionInprogress();

BTabView* fTabView;

BMenu* fSessionMenu;
Expand Down
9 changes: 9 additions & 0 deletions Source/CompilationAudioView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ CompilationAudioView::_BurnerParserOutput(BMessage* message)
"Burning complete. Burn another disc?",
"Status notification"));
fBurnButton->SetEnabled(true);
step = NONE;
}
}

Expand Down Expand Up @@ -325,4 +326,12 @@ CompilationAudioView::BurnDisc()
fBurnerThread->AddArgument(track);
}
fBurnerThread->Run();
step = BURNING;
}


int32
CompilationAudioView::InProgress()
{
return step;
}
2 changes: 2 additions & 0 deletions Source/CompilationAudioView.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CompilationAudioView : public BView {

void BurnDisc();
BSplitView* fAudioSplitView;
int32 InProgress();

private:
void _BurnerParserOutput(BMessage* message);
Expand All @@ -51,6 +52,7 @@ class CompilationAudioView : public BView {

AudioListView* fTrackList;
SizeView* fSizeView;
int step;
};


Expand Down
13 changes: 12 additions & 1 deletion Source/CompilationCDRWView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CompilationCDRWView::CompilationCDRWView(BurnWindow& parent)
fBlankerThread(NULL)
{
windowParent = &parent;
step = NONE;

SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

Expand Down Expand Up @@ -179,6 +180,7 @@ CompilationCDRWView::_Blank()

fBlankerThread->AddArgument(device);
fBlankerThread->Run();
step = BLANKING;
}


Expand All @@ -193,7 +195,16 @@ CompilationCDRWView::_BlankerParserOutput(BMessage* message)
fBlankerInfoTextView->ScrollBy(0.0, 50.0);
}
int32 code = -1;
if (message->FindInt32("thread_exit", &code) == B_OK)
if (message->FindInt32("thread_exit", &code) == B_OK) {
fBlankerInfoBox->SetLabel(B_TRANSLATE_COMMENT("Blanking complete",
"Status notification"));
step = NONE;
}
}


int32
CompilationCDRWView::InProgress()
{
return step;
}
2 changes: 2 additions & 0 deletions Source/CompilationCDRWView.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CompilationCDRWView : public BView {

virtual void MessageReceived(BMessage* message);
virtual void AttachedToWindow();
int32 InProgress();

private:
void _Blank();
Expand All @@ -36,6 +37,7 @@ class CompilationCDRWView : public BView {
BurnWindow* windowParent;
BSeparatorView* fBlankerInfoBox;
BMenu* fBlankModeMenu;
int32 step;
};


Expand Down
24 changes: 16 additions & 8 deletions Source/CompilationCloneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ CompilationCloneView::_CreateImage()

status_t ret = path.Append(kCacheFileClone);
if (ret == B_OK) {
step = 1;
step = BUILDING;

BString file = "f=";
file.Append(path.Path());
Expand Down Expand Up @@ -195,7 +195,7 @@ CompilationCloneView::_BurnImage()

status_t ret = path.Append(kCacheFileClone);
if (ret == B_OK) {
step = 2;
step = BURNING;

fClonerInfoTextView->SetText(NULL);
fClonerInfoBox->SetLabel(B_TRANSLATE_COMMENT(
Expand Down Expand Up @@ -238,12 +238,13 @@ CompilationCloneView::_ClonerOutput(BMessage* message)
fClonerInfoTextView->ScrollBy(0.0, 50.0);
}
int32 code = -1;
if ((message->FindInt32("thread_exit", &code) == B_OK) && (step == 1)) {
if ((message->FindInt32("thread_exit", &code) == B_OK)
&& (step == BUILDING)) {
BString result(fClonerInfoTextView->Text());

// Last output line always (except error) contains speed statistics
if (result.FindFirst(" kB/sec.") != B_ERROR) {
step = 0;
step = NONE;

fClonerInfoBox->SetLabel(B_TRANSLATE_COMMENT(
"Insert a blank disc and burn the image",
Expand All @@ -258,7 +259,7 @@ CompilationCloneView::_ClonerOutput(BMessage* message)
->AddArgument(device)
->Run();
} else {
step = 0;
step = NONE;
fClonerInfoBox->SetLabel(B_TRANSLATE_COMMENT(
"Failed to create image", "Status notification"));
return;
Expand All @@ -267,16 +268,16 @@ CompilationCloneView::_ClonerOutput(BMessage* message)
fImageButton->SetEnabled(true);
fBurnButton->SetEnabled(true);

step = 0;
step = NONE;

} else if ((message->FindInt32("thread_exit", &code) == B_OK)
&& (step == 2)) {
&& (step == BURNING)) {
fClonerInfoBox->SetLabel(B_TRANSLATE_COMMENT(
"Burning complete. Burn another disc?", "Status notification"));
fImageButton->SetEnabled(true);
fBurnButton->SetEnabled(true);

step = 0;
step = NONE;
}
}

Expand All @@ -303,3 +304,10 @@ CompilationCloneView::_UpdateSizeBar()
fSizeView->UpdateSizeDisplay(fileSize / 1024, DATA, CD_OR_DVD);
// size in KiB
}


int32
CompilationCloneView::InProgress()
{
return step;
}
1 change: 1 addition & 0 deletions Source/CompilationCloneView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CompilationCloneView : public BView {

virtual void MessageReceived(BMessage* message);
virtual void AttachedToWindow();
int32 InProgress();

private:
void _CreateImage();
Expand Down
22 changes: 15 additions & 7 deletions Source/CompilationDVDView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CompilationDVDView::CompilationDVDView(BurnWindow& parent)
fImagePath(new BPath())
{
windowParent = &parent;
step = 0;
step = NONE;

SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

Expand Down Expand Up @@ -272,7 +272,8 @@ CompilationDVDView::_BurnerOutput(BMessage* message)
fBurnerInfoTextView->ScrollBy(0.0, 50.0);
}
int32 code = -1;
if ((message->FindInt32("thread_exit", &code) == B_OK) && (step == 1)) {
if ((message->FindInt32("thread_exit", &code) == B_OK)
&& (step == BUILDING)) {
BString infoText(fBurnerInfoTextView->Text());
// mkisofs has same errors for dvd-video and dvd-hybrid, but
// no error checking for dvd-audio, apparently
Expand All @@ -288,17 +289,17 @@ CompilationDVDView::_BurnerOutput(BMessage* message)
fImageButton->SetEnabled(false);
fBurnButton->SetEnabled(true);
}
step = 0;
step = NONE;

} else if ((message->FindInt32("thread_exit", &code) == B_OK)
&& (step == 2)) {
&& (step == BURNING)) {
fBurnerInfoBox->SetLabel(B_TRANSLATE_COMMENT(
"Burning complete. Burn another disc?", "Status notification"));
fDVDButton->SetEnabled(true);
fImageButton->SetEnabled(false);
fBurnButton->SetEnabled(true);

step = 0;
step = NONE;
}
}

Expand Down Expand Up @@ -350,7 +351,7 @@ CompilationDVDView::BuildISO()

status_t ret = fImagePath->Append(kCacheFileDVD);
if (ret == B_OK) {
step = 1; // flag we're building ISO
step = BUILDING; // flag we're building ISO

fBurnerThread->AddArgument("mkisofs")
->AddArgument("-V")
Expand Down Expand Up @@ -378,7 +379,7 @@ CompilationDVDView::BurnDisc()
if (fBurnerThread != NULL)
delete fBurnerThread;

step = 2; // flag we're burning
step = BURNING; // flag we're burning

fBurnerInfoTextView->SetText(NULL);
fBurnerInfoBox->SetLabel(B_TRANSLATE_COMMENT(
Expand Down Expand Up @@ -410,3 +411,10 @@ CompilationDVDView::BurnDisc()
->AddArgument(fImagePath->Path())
->Run();
}


int32
CompilationDVDView::InProgress()
{
return step;
}
1 change: 1 addition & 0 deletions Source/CompilationDVDView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CompilationDVDView : public BView {

void BuildISO();
void BurnDisc();
int32 InProgress();

private:
void _ChooseDirectory();
Expand Down
Loading

0 comments on commit f50b3b6

Please sign in to comment.