#include <SFTPAssist.h>
#include <FileChooser.h>
Fl_Window *window;
Fl_Group *radio_btns, *radio_btns2;
Fl_Radio_Round_Button *get_rbtn, *put_rbtn, *file_rbtn, *dir_rbtn;
Fl_Box *pc_label, *file_label, *to_label, *conn_label, *cmd_label;
Fl_Input *file_input, *to_input, *conn_input, *cmd_input;
Fl_Button *conn_btn, *cmd_btn, *clear_btn, *fileFcBtn, *toFcBtn;
Fl_Choice *choice;
FileChooser* chooser;
void conn_cb(Fl_Widget*, void*) {
string cmd_conn;
string pc;
int choice_num = choice -> value();
switch(choice_num){
case 0:{
pc = "aaa.local";
break;
}
case 1:{
pc = "bbb.local";
break;
}
case 2:{
pc = "ccc.local";
break;
}
}
string cmd_pwd = "pwd";
system(cmd_pwd.c_str());
cmd_conn = "sftp " + pc;
cout << "cmd_conn " << cmd_conn << endl;
conn_input -> value("");
conn_input -> value(cmd_conn.c_str());
string cmdConnCopy = "printf '" + cmd_conn + "' | pbcopy";
system(cmdConnCopy.c_str());
}
void cmd_cb(Fl_Widget*, void*) {
string cmd0;
string cmd1;
string cmd;
int onoff_put = put_rbtn->value();
int onoff_dir = dir_rbtn->value();
if (onoff_put == 1){
cmd0 = "put";
} else {
cmd0 = "get";
}
if (onoff_dir == 1){
cmd1 = "-r";
} else {
cmd1 = "";
}
const char* fileName = file_input -> value();
const char* toName = to_input -> value();
cmd = cmd0 + " " + cmd1 + " \"" + string(fileName) + "\" " + string(toName);
cout << "cmd " << cmd << endl;
cmd_input -> value("");
cmd_input -> value(cmd.c_str());
string cmdCopy = "printf '" + cmd + "' | pbcopy";
system(cmdCopy.c_str());
}
void clear_cb(Fl_Widget*, void*) {
file_input->value("");
to_input->value("");
conn_input->value("");
cmd_input->value("");
}
void FileChooserCB(Fl_Widget*, void*) {
int fc;
string appdir = "/Volumes/Macintosh HD/Users/xxxxx/";
int onoff_dir = dir_rbtn->value();
if (onoff_dir == 1){
fc = 4; // FileChooser::DIRECTORY
} else {
fc = 0; // FileChooser::SINGLE
}
int x_win = window->x_root();
int y_win = window->y_root();
cout<<"x_win "<< x_win <<" y_win "<< y_win <<endl;
chooser = new FileChooser(appdir.c_str(),
"*.*",
fc,
"File/Dir Chooser",490,380
);
chooser->resize(x_win+85,y_win+50,490,380);
chooser->set_modal();
chooser->Fl_Window::show();
while(chooser->Fl_Window::shown()){
Fl::wait();
}
}
int main(int argc, char **argv) {
Fl::set_font(FL_HELVETICA, "Osaka");
window = new Fl_Window(100,100,360,245,"SFTP Assist");
window->color(fl_rgb_color(147,184,129)); // やなぎぞめ
// file
pc_label = new Fl_Box(18,15,35,16,"PC");
window->add(pc_label);
pc_label->labelsize(14);
pc_label->labelcolor(fl_rgb_color(255,239,213));
pc_label->align(Fl_Align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT));
// PC選択項目
Fl_Menu_Item pc_type[4] = {
{"Mac mini Intel"},
{"WindowsPC"},
{"LinuxPC"}
};
// PC選択メニュー
choice = new Fl_Choice(55, 10, 220, 25, nullptr);
choice->menu(pc_type);
radio_btns = new Fl_Group(75,45,185,20,"");{
radio_btns->labelsize(12);
// put_rbtn
put_rbtn = new Fl_Radio_Round_Button(75,45,90,20,"PUT");
put_rbtn->labelcolor(fl_rgb_color(255,239,213));
put_rbtn->setonly();
// get_rbtn
get_rbtn = new Fl_Radio_Round_Button(170,45,90,20,"GET");
get_rbtn->labelcolor(fl_rgb_color(255,239,213));
}
radio_btns->end();
radio_btns2 = new Fl_Group(75,75,185,20,"");{
radio_btns2->labelsize(12);
// file_rbtn
file_rbtn = new Fl_Radio_Round_Button(75,75,90,20,"FILE");
file_rbtn->labelcolor(fl_rgb_color(255,239,213));
file_rbtn->setonly();
// dir_rbtn
dir_rbtn = new Fl_Radio_Round_Button(170,75,90,20,"DIR");
dir_rbtn->labelcolor(fl_rgb_color(255,239,213));
}
radio_btns2->end();
// FILE/DIR
file_label = new Fl_Box(18,112,52,13,"FILE/DIR");
file_label->labelcolor(fl_rgb_color(255,239,213));
file_label->labelsize(12);
file_label->align(Fl_Align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT));
file_input = new Fl_Input(75,105,165,25,"");
file_input->textsize(12);
// fileFcBtn
fileFcBtn = new Fl_Button(245,108,30,20,"...");
fileFcBtn->color(fl_rgb_color(112,128,144));
fileFcBtn->labelcolor(fl_rgb_color(255,239,213));
fileFcBtn->labelsize(14);
fileFcBtn->callback(FileChooserCB);
// TO
to_label = new Fl_Box(18,146,20,14,"TO");
to_label->labelcolor(fl_rgb_color(255,239,213));
to_label->labelsize(14);
to_label->align(Fl_Align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT));
to_input = new Fl_Input(75,140,165,25,"");
to_input->textsize(12);
// toFcBtn
toFcBtn = new Fl_Button(245,143,30,20,"...");
toFcBtn->color(fl_rgb_color(112,128,144));
toFcBtn->labelcolor(fl_rgb_color(255,239,213));
toFcBtn->labelsize(14);
toFcBtn->callback(FileChooserCB);
// CONN
conn_label = new Fl_Box(18,181,44,14,"CONN");
conn_label->labelcolor(fl_rgb_color(255,239,213));
conn_label->labelsize(14);
conn_label->align(Fl_Align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT));
conn_input = new Fl_Input(75,175,270,25,"");
conn_input->color(fl_rgb_color(187,200,230)); // あわふじいろ
conn_input->textsize(12);
// CMD
cmd_label = new Fl_Box(18,216,34,14,"CMD");
cmd_label->labelcolor(fl_rgb_color(255,239,213));
cmd_label->labelsize(14);
cmd_label->align(Fl_Align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT));
cmd_input = new Fl_Input(75,210,270,25,"");
cmd_input->color(fl_rgb_color(187,200,230));
cmd_input->textsize(12);
// CONN_BTN
conn_btn = new Fl_Button(295,10,50,40,"CONN");
conn_btn->color(fl_rgb_color(112,128,144));
conn_btn->labelcolor(fl_rgb_color(255,239,213));
conn_btn->labelsize(14);
conn_btn->callback(conn_cb);
// CMD_BTN
cmd_btn = new Fl_Button(295,60,50,40,"CMD");
cmd_btn->color(fl_rgb_color(112,128,144));
cmd_btn->labelcolor(fl_rgb_color(255,239,213));
cmd_btn->labelsize(14);
cmd_btn->callback(cmd_cb);
clear_btn = new Fl_Button(295,110,50,25,"CLR");
clear_btn->color(fl_rgb_color(112,128,144));
clear_btn->labelcolor(fl_rgb_color(255,239,213));
clear_btn->labelsize(14);
clear_btn->callback(clear_cb);
window->end();
window->show(argc, argv);
return Fl::run();
}