Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
uroni committed Jun 29, 2016
2 parents 7590763 + 8ec04d0 commit acb07e3
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 4 deletions.
81 changes: 81 additions & 0 deletions CbtStatus.cpp
@@ -0,0 +1,81 @@
#include "CbtStatus.h"
#include <wx/process.h>

extern wxString res_path;
extern wxString ico_ext;
extern wxBitmapType ico_type;

CbtStatus::CbtStatus(wxWindow* parent)
: GUICbtStatus(parent), wxProcess(wxPROCESS_REDIRECT), first_val(true)
{
SetIcon(wxIcon(res_path + wxT("backup-ok.") + ico_ext, ico_type));

long pid = wxExecute(wxT("\"") + res_path + wxT("urbctctl.exe\" status all"), wxEXEC_ASYNC, this);
if (pid != 0)
{
Redirect();
CloseOutput();
}

Start(100);

m_textCtrl3->SetValue("Retrieving CBT status...");

Show(true);
}

CbtStatus::~CbtStatus()
{
Stop();
}

void CbtStatus::OnExitClick(wxCommandEvent & event)
{
Stop();
Close();
}

void CbtStatus::Notify(void)
{
if (first_val)
{
first_val = false;
m_textCtrl3->SetValue("");
}

addStream(GetInputStream());
addStream(GetErrorStream());

if ((GetErrorStream() == NULL || GetErrorStream()->Eof())
&& (GetInputStream()==NULL || GetInputStream()->Eof()) )
{
Stop();
}
}

void CbtStatus::OnTerminate(int pid, int status)
{
Notify();
Stop();
}

void CbtStatus::addStream(wxInputStream * input_stream)
{
if (input_stream == NULL)
{
return;
}

while (input_stream->CanRead())
{
char buffer[1024];
input_stream->Read(buffer, 1024);
size_t read = input_stream->LastRead();

if (read > 0)
{
wxString read_str = wxString::FromUTF8(buffer, read);
m_textCtrl3->AppendText(read_str);
}
}
}
22 changes: 22 additions & 0 deletions CbtStatus.h
@@ -0,0 +1,22 @@
#pragma once

#include "gui/GUI.h"
#include <wx/process.h>
#include <wx/timer.h>

class CbtStatus : public GUICbtStatus, wxTimer, wxProcess
{
public:
CbtStatus(wxWindow* parent);
~CbtStatus();
protected:
virtual void OnExitClick(wxCommandEvent& event);

virtual void Notify(void);

virtual void OnTerminate(int pid, int status);

void addStream(wxInputStream* input_stream);

bool first_val;
};
20 changes: 18 additions & 2 deletions Info.cpp
Expand Up @@ -18,6 +18,7 @@

#include "Info.h"
#include "stringtools.h"
#include "TrayIcon.h"

extern std::string g_lang;
extern std::string g_res_path;
Expand All @@ -41,8 +42,8 @@ Info::Info(wxWindow* parent) : GUIInfo(parent)
m_textCtrl14->SetValue(ConvertToUnicode(inf));
Show(true);

std::string n_version = getFile("version.txt");
std::string c_version = getFile("curr_version.txt");
std::string n_version = getFile(g_res_path+"version.txt");
std::string c_version = getFile(g_res_path+"curr_version.txt");
if (n_version.empty())n_version = "0";
if (c_version.empty())c_version = "0";

Expand All @@ -56,6 +57,16 @@ Info::Info(wxWindow* parent) : GUIInfo(parent)
Layout();
}

if (FileExists(g_res_path+"urbctctl.exe"))
{
wxButton* cbtStatusButton = new wxButton(this, wxID_ANY, _("Show CBT status"));
m_versionSizer->Add(cbtStatusButton);

cbtStatusButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(Info::OnShowCBTStatusClick), NULL, this);

Layout();
}

instance=this;
}

Expand All @@ -71,6 +82,11 @@ void Info::OnUpdateClick(wxCommandEvent & event)
update_urbackup();
}

void Info::OnShowCBTStatusClick(wxCommandEvent& event)
{
runCommand("cbt-status");
}

Info* Info::getInstance()
{
return instance;
Expand Down
1 change: 1 addition & 0 deletions Info.h
Expand Up @@ -28,6 +28,7 @@ class Info : public GUIInfo
protected:
void OnOKClick( wxCommandEvent& event );
void OnUpdateClick(wxCommandEvent& event);
void OnShowCBTStatusClick(wxCommandEvent& event);

virtual void OnClose();

Expand Down
2 changes: 2 additions & 0 deletions UrBackupClientGUI.vcxproj
Expand Up @@ -207,6 +207,7 @@
</ManifestResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="CbtStatus.cpp" />
<ClCompile Include="ConfigPath.cpp" />
<ClCompile Include="Connector.cpp" />
<ClCompile Include="escape.cpp" />
Expand All @@ -228,6 +229,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="capa_bits.h" />
<ClInclude Include="CbtStatus.h" />
<ClInclude Include="ConfigPath.h" />
<ClInclude Include="Connector.h" />
<ClInclude Include="escape.h" />
Expand Down
6 changes: 6 additions & 0 deletions UrBackupClientGUI.vcxproj.filters
Expand Up @@ -75,6 +75,9 @@
<ClCompile Include="gui\GUISetupWizard.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="CbtStatus.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ConfigPath.h">
Expand Down Expand Up @@ -134,6 +137,9 @@
<ClInclude Include="gui\GUISetupWizard.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="CbtStatus.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="icon1.ico">
Expand Down
38 changes: 37 additions & 1 deletion gui/GUI.cpp
Expand Up @@ -906,4 +906,40 @@ void GUIStatus::OnCloseInt(wxCloseEvent& event)
{
event.Skip();
OnClose();
}
}

GUICbtStatus::GUICbtStatus(wxWindow * parent, wxWindowID id, const wxString & title, const wxPoint & pos, const wxSize & size, long style)
: wxDialog(parent, id, title, pos, size, style)
{
this->SetSizeHints(wxDefaultSize, wxDefaultSize);

wxBoxSizer* bSizer9;
bSizer9 = new wxBoxSizer(wxVERTICAL);

m_textCtrl3 = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP);
bSizer9->Add(m_textCtrl3, 15, wxALL | wxEXPAND, 5);

wxBoxSizer* bSizer10;
bSizer10 = new wxBoxSizer(wxHORIZONTAL);


bSizer10->Add(0, 0, 1, wxEXPAND, 5);

m_button5 = new wxButton(this, wxID_ANY, _("Exit"), wxDefaultPosition, wxDefaultSize, 0);
bSizer10->Add(m_button5, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);

bSizer9->Add(bSizer10, 1, wxEXPAND | wxALIGN_RIGHT, 5);

this->SetSizer(bSizer9);
this->Layout();

this->Centre(wxBOTH);

// Connect Events
m_button5->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(GUICbtStatus::OnExitClick), NULL, this);
}

GUICbtStatus::~GUICbtStatus()
{
m_button5->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(GUICbtStatus::OnExitClick), NULL, this);
}
22 changes: 22 additions & 0 deletions gui/GUI.h
Expand Up @@ -295,4 +295,26 @@ class GUIStatus : public wxDialog

};

///////////////////////////////////////////////////////////////////////////////
/// Class GUICbtStatus
///////////////////////////////////////////////////////////////////////////////
class GUICbtStatus : public wxDialog
{
private:

protected:
wxTextCtrl* m_textCtrl3;

wxButton* m_button5;

// Virtual event handlers, overide them in your derived class
virtual void OnExitClick(wxCommandEvent& event) { event.Skip(); }

public:

GUICbtStatus(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("CBT status"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500, 222), long style = wxDEFAULT_DIALOG_STYLE);
virtual ~GUICbtStatus();

};

#endif //__GUI_H__
2 changes: 1 addition & 1 deletion info.txt
Expand Up @@ -22,4 +22,4 @@ osiengine group (Farsi)
buzzertnl, Decay (Dutch)
Ales Hermann (Czech)

See license.txt for the licences of the libraries used and of UrBackup (AGPL v3+).
See license.txt for the licences of the libraries used and of UrBackup (AGPL v3+). The source code is available at https://github.com/uroni/urbackup_backend (backend) and https://github.com/uroni/urbackup_frontend_wx (tray icon).
9 changes: 9 additions & 0 deletions main.cpp
Expand Up @@ -25,6 +25,7 @@
#include "Logs.h"
#include "TranslationHelper.h"
#include "Status.h"
#include "CbtStatus.h"
#include <iostream>
#include <limits>
#include <wx/stdpaths.h>
Expand Down Expand Up @@ -477,6 +478,14 @@ bool MyApp::OnInit()
Connector::restoreOk(wxString(argv[2])=="true", process_id);
wxExit();
}
else if (cmd == wxT("cbt-status"))
{
CbtStatus *s = new CbtStatus(NULL);
SetTopWindow(s);
s->ShowModal();
s->Destroy();
wxExit();
}
#ifdef __APPLE__
else if (cmd == wxT("uninstall"))
{
Expand Down

0 comments on commit acb07e3

Please sign in to comment.