Skip to content

Commit

Permalink
Merge pull request #620 from subutai-io/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
crioto authored Feb 15, 2018
2 parents f36c179 + f17a18d commit 0e5b41d
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 44 deletions.
1 change: 1 addition & 0 deletions commons/include/OsBranchConsts.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const QString& hub_billing_url();
const char ** ssdp_rh_search_target_arr();

const QString& default_p2p_path();
const QString& default_vagrant_path();
const QString& default_terminal();
const QString& default_x2goclient_path();
const QString& default_term_arg();
Expand Down
19 changes: 19 additions & 0 deletions commons/src/OsBranchConsts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,25 @@ default_p2p_path() {
}
////////////////////////////////////////////////////////////////////////////

template<class OS> const QString& default_vagrant_path_temp_internal();

#define default_vagrant_path_internal_def(OS_TYPE, STRING) \
template<> \
const QString& default_vagrant_path_temp_internal<Os2Type<OS_TYPE> >() { \
static QString res(STRING); \
return res; \
}

default_vagrant_path_internal_def(OS_LINUX, "/usr/bin/vagrant")
default_vagrant_path_internal_def(OS_WIN, "C:\\Vagrant\\Vagrant")
default_vagrant_path_internal_def(OS_MAC, "/usr/local/bin/vagrant")

const QString &
default_vagrant_path() {
return default_vagrant_path_temp_internal<Os2Type<CURRENT_OS> >();
}
////////////////////////////////////////////////////////////////////////////

template<class OS> const QString& default_terminal_temp_internal();

#define default_terminal_internal_def(OS_TYPE, STRING) \
Expand Down
54 changes: 45 additions & 9 deletions hub/forms/DlgSettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_common">
<attribute name="title">
Expand Down Expand Up @@ -340,13 +340,16 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="le_ssh_command"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="le_p2p_command"/>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="le_ssh_command"/>
<item row="4" column="1">
<widget class="QLineEdit" name="le_ssh_keygen_command"/>
</item>
<item row="8" column="0" colspan="3">
<item row="11" column="0" colspan="3">
<widget class="QGroupBox" name="gb_terminal_settings">
<property name="title">
<string>Terminal settings:</string>
Expand Down Expand Up @@ -411,9 +414,6 @@
</layout>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="le_ssh_keygen_command"/>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="btn_ssh_command">
<property name="text">
Expand Down Expand Up @@ -474,6 +474,32 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lbl_err_ssh_command">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="le_vagrant_command"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Vagrant command</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="lbl_err_x2goclient_command">
<property name="sizePolicy">
Expand All @@ -490,14 +516,17 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lbl_err_ssh_command">
<item row="10" column="1">
<widget class="QLabel" name="lbl_err_vagrant_command">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -506,6 +535,13 @@
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QPushButton" name="btn_vagrant_command">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
1 change: 1 addition & 0 deletions hub/include/DlgSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private slots:
void btn_logs_storage_released();
void btn_ssh_keys_storage_released();
void btn_refresh_rh_list_released();
void btn_vagrant_command_released();

void refresh_rh_list_timer_timeout();
void lstv_resource_hosts_double_clicked(QModelIndex ix0);
Expand Down
4 changes: 4 additions & 0 deletions hub/include/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CSettingsManager : public QObject {
static const QString SM_SSH_PATH;
static const QString SM_SSH_USER;
static const QString SM_LOCALE;
static const QString SM_VAGRANT_PATH;

static const QString SM_RH_USER;
static const QString SM_RH_PASS;
Expand Down Expand Up @@ -75,6 +76,7 @@ class CSettingsManager : public QObject {

uint32_t m_refresh_time_sec;
QString m_p2p_path;
QString m_vagrant_path;

uint32_t m_notification_delay_sec;

Expand Down Expand Up @@ -180,6 +182,7 @@ class CSettingsManager : public QObject {
uint16_t plugin_port() const { return m_plugin_port; }
const QString& ssh_path() const { return m_ssh_path; }
const QString& ssh_user() const { return m_ssh_user; }
const QString& vagrant_path() const { return m_vagrant_path; }

const QString& rh_user(const QString &id);
const QString& rh_pass(const QString &id);
Expand Down Expand Up @@ -251,6 +254,7 @@ class CSettingsManager : public QObject {
void set_rh_management_freq(int fr);
void set_locale(int fr);
void set_p2p_path(QString fr);
void set_vagrant_path(QString fr);
void set_x2goclient_path(QString fr);
void set_rh_pass(const QString &id, const QString &pass);
void set_rh_user(const QString &id, const QString &user);
Expand Down
19 changes: 18 additions & 1 deletion hub/src/DlgSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ DlgSettings::DlgSettings(QWidget* parent)
ui->sb_refresh_timeout->setValue(
CSettingsManager::Instance().refresh_time_sec());
ui->le_p2p_command->setText(CSettingsManager::Instance().p2p_path());
ui->le_vagrant_command->setText(CSettingsManager::Instance().vagrant_path());
ui->sb_notification_delay->setMinimum(
CSettingsManager::NOTIFICATION_DELAY_MIN);
ui->sb_notification_delay->setMaximum(
Expand All @@ -94,6 +95,7 @@ DlgSettings::DlgSettings(QWidget* parent)
ui->lbl_err_ssh_keys_storage->hide();
ui->lbl_err_ssh_user->hide();
ui->lbl_err_p2p_command->hide();
ui->lbl_err_x2goclient_command->hide();
ui->lbl_err_ssh_command->hide();
ui->lbl_err_ssh_keygen_command->hide();
ui->lbl_err_terminal_arg->hide();
Expand Down Expand Up @@ -176,6 +178,8 @@ DlgSettings::DlgSettings(QWidget* parent)
&DlgSettings::btn_p2p_file_dialog_released);
connect(ui->btn_ssh_command, &QPushButton::released, this,
&DlgSettings::btn_ssh_command_released);
connect(ui->btn_vagrant_command, &QPushButton::released, this,
&DlgSettings::btn_vagrant_command_released);
connect(ui->btn_x2goclient_command, &QPushButton::released, this,
&DlgSettings::btn_x2goclient_command_released);
connect(ui->btn_ssh_keygen_command, &QPushButton::released, this,
Expand Down Expand Up @@ -268,7 +272,7 @@ void DlgSettings::btn_ok_released() {
tr("Can't launch application");

QLineEdit* le[] = {ui->le_logs_storage, ui->le_ssh_keys_storage,
ui->le_p2p_command, ui->le_ssh_command};
ui->le_p2p_command, ui->le_ssh_command, ui->le_vagrant_command};
QStringList lst_home =
QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString home_folder = lst_home.empty() ? "~" : lst_home[0];
Expand Down Expand Up @@ -298,6 +302,10 @@ void DlgSettings::btn_ok_released() {
{ui->le_p2p_command, ui->lbl_err_p2p_command, can_launch_application, 1,
can_launch_application_msg},

{ui->le_vagrant_command, ui->lbl_err_vagrant_command, is_le_empty_validate, 1, empty_validator_msg},
{ui->le_vagrant_command, ui->lbl_err_vagrant_command, can_launch_application, 1,
can_launch_application_msg},

{ui->le_ssh_command, ui->lbl_err_ssh_command, is_le_empty_validate, 1, empty_validator_msg},
{ui->le_ssh_command, ui->lbl_err_ssh_command, can_launch_application, 1,
can_launch_application_msg},
Expand Down Expand Up @@ -376,6 +384,7 @@ void DlgSettings::btn_ok_released() {
CSettingsManager::Instance().set_ssh_keys_storage(
ui->le_ssh_keys_storage->text());
CSettingsManager::Instance().set_p2p_path(ui->le_p2p_command->text());
CSettingsManager::Instance().set_vagrant_path(ui->le_vagrant_command->text());
CSettingsManager::Instance().set_x2goclient_path(ui->le_x2goclient_command->text());

CSettingsManager::Instance().set_ssh_path(ui->le_ssh_command->text());
Expand Down Expand Up @@ -444,6 +453,14 @@ void DlgSettings::btn_p2p_file_dialog_released() {
}
////////////////////////////////////////////////////////////////////////////

void DlgSettings::btn_vagrant_command_released() {
QString fn = QFileDialog::getOpenFileName(this, tr("Vagrant command"));
if (fn == "") return;
ui->le_vagrant_command->setText(fn);
qDebug() << "Selected vagrant path";
}
////////////////////////////////////////////////////////////////////////////

void DlgSettings::btn_ssh_command_released() {
QString fn = QFileDialog::getOpenFileName(this, tr("Ssh command"));
if (fn == "") return;
Expand Down
8 changes: 4 additions & 4 deletions hub/src/HubController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,15 @@ void CHubController::desktop_to_container_from_hub(const QString &env_id, const
env = res.first;
cont = res.second;
if (env == NULL) {
emit ssh_to_container_from_hub_finished(*env, *cont, SDLE_ENV_NOT_FOUND, additional_data);
emit desktop_to_container_from_hub_finished(*env, *cont, SDLE_ENV_NOT_FOUND, additional_data);
}
else
if (cont == NULL) {
emit ssh_to_container_from_hub_finished(*env, *cont, SDLE_CONT_NOT_FOUND, additional_data);
emit desktop_to_container_from_hub_finished(*env, *cont, SDLE_CONT_NOT_FOUND, additional_data);
}
else {
ssh_desktop_launch_error_t res = ssh_to_container(*env, *cont);
emit ssh_to_container_from_hub_finished(*env, *cont, res, additional_data);
ssh_desktop_launch_error_t res = desktop_to_container(*env, *cont);
emit desktop_to_container_from_hub_finished(*env, *cont, res, additional_data);
}
}

Expand Down
15 changes: 12 additions & 3 deletions hub/src/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const QString CSettingsManager::SM_REMEMBER_ME("Remember_Me");
const QString CSettingsManager::SM_REFRESH_TIME("Refresh_Time_Sec");
const QString CSettingsManager::SM_P2P_PATH("P2P_Path");
const QString CSettingsManager::SM_X2GOCLIENT_PATH("X2GOCLIENT_Path");
const QString CSettingsManager::SM_VAGRANT_PATH("VAGRANT_Path");

const QString CSettingsManager::SM_NOTIFICATION_DELAY_SEC("Notification_Delay_Sec");
const QString CSettingsManager::SM_PLUGIN_PORT("Plugin_Port");
Expand Down Expand Up @@ -165,6 +166,7 @@ CSettingsManager::CSettingsManager()
m_remember_me(false),
m_refresh_time_sec(DEFAULT_REFRESH_TIMEOUT_SEC),
m_p2p_path(default_p2p_path()),
m_vagrant_path(default_vagrant_path()),
m_notification_delay_sec(7),
m_plugin_port(9998),
m_ssh_path(ssh_cmd_path()),
Expand Down Expand Up @@ -221,6 +223,7 @@ CSettingsManager::CSettingsManager()
// str
{(void*)&m_login, SM_LOGIN, qvar_to_str},
{(void*)&m_p2p_path, SM_P2P_PATH, qvar_to_str},
{(void*)&m_vagrant_path, SM_VAGRANT_PATH, qvar_to_str},
{(void*)&m_x2goclient, SM_X2GOCLIENT_PATH, qvar_to_str},
{(void*)&m_ssh_path, SM_SSH_PATH, qvar_to_str},
{(void*)&m_ssh_user, SM_SSH_USER, qvar_to_str},
Expand Down Expand Up @@ -291,14 +294,15 @@ CSettingsManager::CSettingsManager()

// which using
QString* cmd_which[] = {&m_ssh_keygen_cmd, &m_ssh_path,
&m_p2p_path, &m_x2goclient, nullptr};
&m_p2p_path, &m_x2goclient, &m_vagrant_path, nullptr};
static const QString default_values[] = {ssh_keygen_cmd_path(), ssh_cmd_path(),
default_p2p_path(), default_x2goclient_path()};
default_p2p_path(), default_x2goclient_path(), default_vagrant_path()};
static const QString commands_name[] =
{"ssh-keygen",
"ssh",
"p2p",
"x2goclient"};
"x2goclient",
"vagrant"};


QString tmp;
Expand Down Expand Up @@ -543,6 +547,11 @@ void CSettingsManager::set_p2p_path(QString p2p_path) {
m_settings.setValue(SM_P2P_PATH, m_p2p_path);
}

void CSettingsManager::set_vagrant_path(QString vagrant_path) {
QString sl = QFile::symLinkTarget(vagrant_path);
m_vagrant_path = sl == "" ? vagrant_path : sl;
m_settings.setValue(SM_VAGRANT_PATH, m_vagrant_path);
}
void CSettingsManager::set_x2goclient_path(QString x2goclient_path) {
QString sl = QFile::symLinkTarget(x2goclient_path);
m_x2goclient = sl == "" ? x2goclient_path : sl;
Expand Down
42 changes: 16 additions & 26 deletions hub/src/TrayControlWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ void TrayControlWindow::launch_Hub() {
void TrayControlWindow::launch_p2p(){
qDebug()
<<"p2p button is pressed";
int rse_err;
switch (p2p_current_status) {
case P2PStatus_checker::P2P_FAIL :
CNotificationObserver::Error(QObject::tr("Can't launch P2P daemon. "
Expand Down Expand Up @@ -565,8 +564,7 @@ void TrayControlWindow::environments_updated_sl(int rr) {
static std::vector<QString> lst_checked_unhealthy_env;
m_hub_menu->clear();

std::vector<QString> lst_unhealthy_envs;
std::vector<QString> lst_unhealthy_env_statuses;
std::map<QString, std::vector<QString> > tbl_envs;

if (CHubController::Instance().lst_environments().empty()) {
QAction* empty_action = new QAction("Empty", this);
Expand All @@ -588,9 +586,8 @@ void TrayControlWindow::environments_updated_sl(int rr) {

if (!env->healthy()) {
if (iter_found == lst_checked_unhealthy_env.end()) {
lst_unhealthy_envs.push_back(env_name);
lst_unhealthy_env_statuses.push_back(env->status());
lst_checked_unhealthy_env.push_back(env->id());
tbl_envs[env->status()].push_back(env_name);
qCritical(
"Environment %s, %s is unhealthy. Reason : %s",
env_name.toStdString().c_str(), env->id().toStdString().c_str(),
Expand All @@ -615,28 +612,21 @@ void TrayControlWindow::environments_updated_sl(int rr) {
});
} // for auto env in environments list

if (lst_unhealthy_envs.empty()) return;

QString str_unhealthy_envs = "";
QString str_statuses = "";
for (size_t i = 0; i < lst_unhealthy_envs.size() - 1; ++i) {
str_unhealthy_envs += lst_unhealthy_envs[i] + ", ";
str_statuses += lst_unhealthy_env_statuses[i] + ", ";
for (std::map<QString, std::vector<QString> >::iterator it = tbl_envs.begin(); it != tbl_envs.end(); it++){
if(!it->second.empty()){
QString str_env_names = "";
for (size_t i=0; i < it->second.size()-1; i++)
str_env_names += it->second[i] + ", ";
str_env_names += it->second[it->second.size()-1];
QString str_notifications =
tr("Environment%1 %2 %3 %4")
.arg(it->second.size() > 1 ? "s" : "")
.arg(str_env_names)
.arg(it->second.size() > 1 ? "are" : "is")
.arg(it->first);
CNotificationObserver::Instance()->Info(str_notifications, DlgNotification::N_NO_ACTION);
}
}

str_unhealthy_envs += lst_unhealthy_envs[lst_unhealthy_envs.size() - 1];
str_statuses += lst_unhealthy_env_statuses[lst_unhealthy_envs.size() - 1];
qDebug()
<< QString("Unhealthy Environments: %1 with statuses: %2").arg(str_unhealthy_envs, str_statuses);

QString str_notification =
tr("Environment%1 %2 %3 %4")
.arg(lst_unhealthy_envs.size() > 1 ? "s" : "")
.arg(str_unhealthy_envs)
.arg(lst_unhealthy_envs.size() > 1 ? "are" : "is")
.arg(str_statuses);

CNotificationObserver::Instance()->Info(str_notification, DlgNotification::N_NO_ACTION);
}

////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 0e5b41d

Please sign in to comment.