summaryrefslogtreecommitdiffstats
path: root/dialog.cpp
blob: 634c9b0bc1499d160dee463f955a27a70c0ed9e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <unistd.h>

#include <wx/msgdlg.h>

#include "dialog.h"
#include "creator_thread.h"

#ifdef __WINDOWS__
#include <windows.h>
#endif

Dialog::Dialog(wxWindow *parent)
	: DialogUI(parent)
{
	m_log = new wxLogTextCtrl(m_textctrl);
	wxLog::SetActiveTarget(m_log);
	RefreshDrives();
}

void Dialog::RefreshDrives(void)
{
#ifdef __WINDOWS__ 
//    SetErrorMode(SEM_NOOPENFILEERRORBOX);
	wchar_t drives[256], *pdrv = drives;
	memset(drives, 0, sizeof(drives));
	GetLogicalDriveStrings(sizeof(drives), drives);
	m_target->Clear();
	while(pdrv[0] != '\0') {
//        if (GetDriveType(pdrv) == DRIVE_REMOVABLE) {
	        m_target->Append(pdrv);
//        }
	    pdrv += lstrlen(pdrv) + 1;
	}
	
#else
	m_target->Clear();
	m_target->Append(wxT("/tmp/alpine"));
#endif
	if (!m_target->IsEmpty())
	    m_target->SetSelection(0);
}

void Dialog::OnRefreshDrives(wxCommandEvent &event)
{
	RefreshDrives();
	UpdateStartButton();
}

void Dialog::OnStartButton(wxCommandEvent &event)
{
	wxString isopath(m_iso_picker->GetPath());
	wxString target(m_target->GetString(m_target->GetSelection()));

	CreatorThread *thread = new CreatorThread(this, isopath, target);
	if (thread->Create() == wxTHREAD_NO_ERROR) {
		m_start_button->Disable();
		m_target->Disable();
		m_iso_picker->Disable();
		m_refresh_button->Disable();
		thread->Run();
	}
}

void Dialog::OnCancelButton(wxCommandEvent &event)
{
	Close();	
}

void Dialog::UpdateStartButton(void)
{
	if ((m_target->GetSelection() != wxNOT_FOUND)
	        && wxFileExists(m_iso_picker->GetPath())) {
	    m_start_button->Enable();
	} else {
	    m_start_button->Disable();
	}
}

void Dialog::OnIsoChange(wxFileDirPickerEvent &event)
{
	UpdateStartButton();
}

void Dialog::OnTargetChange(wxCommandEvent &event)
{
	UpdateStartButton();
}

void Dialog::SetProgress(size_t current, size_t total, const char *filename )
{
	if (m_gauge->GetRange() != total)
		m_gauge->SetRange(total);
	if (m_gauge->GetValue() != current)
		m_gauge->SetValue(current);
	if (filename != NULL) {
		wxString msg = wxString::FromAscii(filename);
		wxLogMessage(msg);
	}
}