commit
6a6bfe1856
48 changed files with 2890 additions and 0 deletions
@ -0,0 +1,57 @@ |
|||
cmake_minimum_required(VERSION 3.0.2-1) |
|||
|
|||
project(simple-netaid) |
|||
|
|||
message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") |
|||
|
|||
set(CMAKE_CXX_COMPILER_INIT g++) |
|||
set_source_files_properties(gtk/*.cpp PROPERTIES LANGUAGE CXX_STANDARD11 ) |
|||
|
|||
set(CMAKE_INSTALL_PREFIX /usr) |
|||
|
|||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/ModulesCMake") |
|||
|
|||
include(GNUInstallDirs) |
|||
# set arch-specific include dir |
|||
set(CMAKE_INSTALL_INCLUDEDIR "include/${CMAKE_LIBRARY_ARCHITECTURE}") |
|||
set(CMAKE_INSTALL_LIBDIR "usr/lib/${DEB_HOST_MULTIARCH}") |
|||
|
|||
set(CMAKE_CXX_FLAGS "-Wall -g -o -lm -liw -Wc++0x-compat -pthread -std=gnu++11" ) |
|||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -o -lm -liw -Wc++0x-compat -pthread -std=gnu++11" ) |
|||
|
|||
find_package(PkgConfig REQUIRED) |
|||
pkg_check_modules(GLIBMM REQUIRED glibmm-2.4) |
|||
pkg_check_modules(GTKMM REQUIRED gtkmm-2.4) |
|||
|
|||
list(APPEND DIR_LIST include ${GTKMM_INCLUDE_DIRS}) |
|||
|
|||
include_directories(${DIR_LIST}) |
|||
|
|||
add_subdirectory (gtk) |
|||
|
|||
link_directories(${LINK_LIST}) |
|||
|
|||
# Add other flags to the compiler |
|||
add_definitions(${CFLAG_LIST}) |
|||
|
|||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/../) |
|||
set(CMAKE_BUILD_TYPE debug) |
|||
|
|||
add_executable(${PROJECT_NAME} main.cpp) |
|||
add_executable("${PROJECT_NAME}-suid" suid.cpp) |
|||
|
|||
target_link_libraries(${PROJECT_NAME} netaid-gtk ${GLIBMM_LIBRARIES} ${GTKMM_LIBRARIES} netaid) |
|||
target_link_libraries("${PROJECT_NAME}-suid" netaid netaid-gtk ${GLIBMM_LIBRARIES} ${GTKMM_LIBRARIES}) |
|||
|
|||
add_custom_command( |
|||
OUTPUT suid_binary |
|||
POST_BUILD |
|||
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR} sudo chown root:root "${PROJECT_NAME}-suid" |
|||
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR} sudo chmod u+s "${PROJECT_NAME}-suid" |
|||
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR} rm -f "suid" |
|||
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR} mv "${PROJECT_NAME}-suid" "suid" |
|||
DEPENDS "${PROJECT_NAME}-suid" |
|||
COMMENT "Giving suid permissions to the server...\n" |
|||
) |
|||
|
|||
add_custom_target(suid ALL DEPENDS suid_binary) |
@ -0,0 +1,7 @@ |
|||
# simple-netaid-gtk |
|||
|
|||
Gtk interface for simple-netaid. |
|||
|
|||
<p align="center"> |
|||
<img src="screenshots/screenshot_3.png"> |
|||
</p> |
@ -0,0 +1,7 @@ |
|||
# headers: |
|||
FILE(GLOB_RECURSE HEADER_GTK_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h") |
|||
|
|||
# sources: |
|||
FILE(GLOB_RECURSE NETAID_GTK_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") |
|||
|
|||
add_library(netaid-gtk STATIC ${NETAID_GTK_SOURCES}) |
@ -0,0 +1,206 @@ |
|||
/*
|
|||
* active_wifis.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#include <iostream> |
|||
|
|||
#include "active_wifis.h" |
|||
#include "window_main.h" |
|||
#include "args.h" |
|||
#include "svr.h" |
|||
#include "cli.h" |
|||
#include "pipe_file.h" |
|||
|
|||
// Constructor
|
|||
ActiveWifis::ActiveWifis(WindowMain *caller, const Args& args) |
|||
{ |
|||
client=args.CLIENT; |
|||
wireless_device=args.WIRELESS_DEVICE; |
|||
|
|||
get_selection()->set_mode( Gtk::SELECTION_SINGLE ); |
|||
set_hover_selection( true ); |
|||
set_sensitive( true ); |
|||
|
|||
m_refTreeModel = Gtk::ListStore::create( m_Columns ); |
|||
set_model( m_refTreeModel ); |
|||
|
|||
append_column( " ESSID" , m_Columns.essid ); |
|||
append_column( " ADDRESS " , m_Columns.address ); |
|||
cell = Gtk::manage( new Gtk::CellRendererProgress ); |
|||
cols_count = append_column( " QUALITY ", *cell ); |
|||
|
|||
signal_button_press_event().connect |
|||
( |
|||
sigc::mem_fun(*this, &ActiveWifis::on_button_press_event), |
|||
false |
|||
); |
|||
|
|||
show_all_children(); |
|||
|
|||
get_active_wifis(); |
|||
|
|||
////////// passwd_dialog = new PasswdDialog( caller, args );
|
|||
} |
|||
|
|||
// Destructor
|
|||
ActiveWifis::~ActiveWifis() |
|||
{ |
|||
|
|||
} |
|||
|
|||
void ActiveWifis::get_active_wifis() |
|||
{ |
|||
std::unique_ptr<PipeFile> fp( new PipeFile() ); |
|||
std::string cmd = client + wireless_device; |
|||
wifis.erase(wifis.begin(), wifis.end()); |
|||
wifis = fp->get_output( cmd.c_str() ); |
|||
for(unsigned i=0; i<wifis.size(); i++) std::cout << "_" << wifis[i] << std::endl; |
|||
|
|||
std::vector<std::string> essid; |
|||
std::vector<std::string> address; |
|||
std::vector<int> quality; |
|||
|
|||
unsigned i=0, j=0; |
|||
|
|||
while(i<wifis.size()) { |
|||
switch(j) { |
|||
case 0: address.push_back(wifis[i]); |
|||
i++; j++; |
|||
break; |
|||
|
|||
case 1: essid.push_back(wifis[i]); |
|||
i++; j++; |
|||
break; |
|||
|
|||
case 2: { |
|||
std::vector<std::string> v; |
|||
size_t found = wifis[i].find("/"); |
|||
v.push_back(wifis[i].substr(0, found)); |
|||
v.push_back(wifis[i].substr(found+1, wifis[i].size())); |
|||
quality.push_back(std::stoi(v[0])*100/std::stoi(v[1])); |
|||
i++; j=0; |
|||
} |
|||
|
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} // while
|
|||
|
|||
for(i=0; i<quality.size(); i++) |
|||
for(j=0; j<quality.size()-1; j++) |
|||
if(quality[j]<quality[j+1]) { |
|||
|
|||
std::string temp_essid=essid[j]; |
|||
essid[j]=essid[j+1]; |
|||
essid[j+1]=temp_essid; |
|||
|
|||
std::string temp_address=address[j]; |
|||
address[j]=address[j+1]; |
|||
address[j+1]=temp_address; |
|||
|
|||
int temp_quality=quality[j]; |
|||
quality[j]=quality[j+1]; |
|||
quality[j+1]=temp_quality; |
|||
} |
|||
|
|||
for(i=0; i<essid.size(); i++) { |
|||
row = *(m_refTreeModel->append()); |
|||
row[m_Columns.essid] = essid[i]; |
|||
row[m_Columns.address] = address[i]; |
|||
row[m_Columns.strength] = quality[i]; |
|||
pColumn = get_column(cols_count - 1); |
|||
pColumn->add_attribute(cell->property_value(), m_Columns.strength); |
|||
} |
|||
|
|||
essid.erase(essid.begin(), essid.end()); |
|||
address.erase(address.begin(), address.end()); |
|||
quality.erase(quality.begin(), quality.end()); |
|||
|
|||
this->show_all_children(); |
|||
} |
|||
|
|||
// Signal Handler (single click)
|
|||
bool ActiveWifis::on_button_press_event(GdkEventButton* event) |
|||
{ |
|||
bool return_value = false; |
|||
|
|||
//Call base class, to allow normal handling,
|
|||
//such as allowing the row to be selected by the right-click:
|
|||
return_value = TreeView::on_button_press_event(event); |
|||
|
|||
//Then do our custom stuff:
|
|||
if( (event->type == GDK_BUTTON_PRESS) && (event->button == 1) ) |
|||
{ |
|||
Glib::RefPtr<Gtk::TreeView::Selection> refTreeSelection = get_selection(); |
|||
if(refTreeSelection) |
|||
{ |
|||
Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); |
|||
if(iter) |
|||
{ |
|||
/*
|
|||
this->passwd_dialog->addr = (*iter)[ m_Columns.essid ]; |
|||
size_t len= this->passwd_dialog->addr.length(); |
|||
|
|||
set_hover_selection( false ); |
|||
|
|||
// Only in Gtkmm3:
|
|||
//set_activate_on_single_click( false );
|
|||
|
|||
passwd_dialog->signal_response().connect |
|||
( |
|||
sigc::mem_fun(*this, &ActiveWifis::on_about_dialog_response) |
|||
); |
|||
|
|||
passwd_dialog->clear_entry_box(); |
|||
passwd_dialog->show(); |
|||
|
|||
//Bring it to the front, in case it was already shown:
|
|||
passwd_dialog->present(); |
|||
* */ |
|||
} |
|||
} |
|||
} |
|||
|
|||
return return_value; |
|||
} |
|||
|
|||
void ActiveWifis::on_about_dialog_response(int response_id) |
|||
{ |
|||
set_hover_selection( true ); |
|||
|
|||
std::cout |
|||
<< response_id |
|||
<< ", close=" << Gtk::RESPONSE_CLOSE |
|||
<< ", cancel=" << Gtk::RESPONSE_CANCEL |
|||
<< ", delete_event=" << Gtk::RESPONSE_DELETE_EVENT |
|||
<< std::endl; |
|||
|
|||
if((response_id == Gtk::RESPONSE_CLOSE) || (response_id == Gtk::RESPONSE_CANCEL)) |
|||
m_refTreeModel->clear(); |
|||
} |
|||
|
|||
void ActiveWifis::fill_treeview(WindowMain *caller) |
|||
{ |
|||
if(caller->get_shall_fill_treeview()) { |
|||
m_refTreeModel->clear(); |
|||
get_active_wifis(); |
|||
} |
|||
} |
@ -0,0 +1,96 @@ |
|||
/*
|
|||
* active_wifis.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid-gtk is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#ifndef __ACTIVE_WIFIS_H__ |
|||
#define __ACTIVE_WIFIS_H__ |
|||
|
|||
#include <gtkmm.h> |
|||
#include <thread> |
|||
#include <mutex> |
|||
#include <vector> |
|||
|
|||
class WindowMain; |
|||
class Args; |
|||
|
|||
class ActiveWifis : public Gtk::TreeView |
|||
{ |
|||
public: |
|||
ActiveWifis(WindowMain*, const Args&); |
|||
virtual ~ActiveWifis(); |
|||
|
|||
virtual void fill_treeview(WindowMain*); |
|||
|
|||
protected: |
|||
|
|||
class ColModel : public Gtk::TreeModel::ColumnRecord |
|||
{ |
|||
public: |
|||
ColModel() |
|||
{ |
|||
//add(icon);
|
|||
add(essid); |
|||
//add(installed);
|
|||
add(address); |
|||
add(strength); |
|||
}; |
|||
|
|||
// Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > icon;
|
|||
Gtk::TreeModelColumn<std::string> essid; |
|||
// Gtk::TreeModelColumn<bool> installed;
|
|||
Gtk::TreeModelColumn<std::string> address; |
|||
Gtk::TreeModelColumn<int> strength; |
|||
}; |
|||
|
|||
std::string client, wireless_device; |
|||
ColModel m_Columns; |
|||
|
|||
std::vector<std::string> wifis; |
|||
|
|||
virtual void get_active_wifis(); |
|||
|
|||
// Signal Handlers
|
|||
|
|||
/*
|
|||
* This is for the single click event, since |
|||
* set_activate_on_single_click( true ) is not available in gtkmm 2.4 |
|||
* */ |
|||
virtual bool on_button_press_event(GdkEventButton*) override; |
|||
|
|||
void on_about_dialog_response(int response_id); |
|||
|
|||
// Friend fuctions:
|
|||
friend void on_statusicon_activated(GtkWidget*, gpointer); |
|||
|
|||
private: |
|||
GdkEventAny* any_event; |
|||
std::string addr; |
|||
std::string backend_path; |
|||
guint cols_count; |
|||
Glib::RefPtr<Gtk::ListStore> m_refTreeModel; |
|||
Gtk::TreeModel::Row row; |
|||
Gtk::TreeViewColumn* pColumn; |
|||
Gtk::CellRendererProgress* cell; |
|||
|
|||
|
|||
}; |
|||
|
|||
#endif // __ACTIVE_WIFIS_H__
|
|||
|
@ -0,0 +1,148 @@ |
|||
/*
|
|||
* args.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#include <iostream> |
|||
|
|||
#include "args.h" |
|||
#include "svr.h" |
|||
|
|||
extern "C" { |
|||
|
|||
#include <simple-netaid/sbuf.h> |
|||
#include <simple-netaid/interfaces.h> |
|||
|
|||
} |
|||
|
|||
Args::Args(int argc, char **argv) |
|||
{ |
|||
for(int i=0; i<argc; i++) |
|||
argvs.push_back(std::string(argv[i])); |
|||
|
|||
get_pid(); |
|||
ARGS_FILE_DESCRIPTOR = "/tmp/snet_suid_args_" + PID + ".socket"; |
|||
ACTIVE_WIFIS_OUTPUT = "/tmp/snet_active-wifis_" + PID + ".socket"; |
|||
|
|||
get_current_path(); |
|||
get_devices(); |
|||
set_bin_path(); |
|||
get_pixmaps(); |
|||
} |
|||
|
|||
Args::~Args() |
|||
{ |
|||
Glib::RefPtr<Gio::File> ref_path = Gio::File::create_for_path(ACTIVE_WIFIS_OUTPUT.c_str()); |
|||
if(ref_path->query_exists()) { |
|||
std::unique_ptr<Svr> svr( new Svr(ARGS_FILE_DESCRIPTOR) ); |
|||
svr->dispatch( { "4" } ); |
|||
std::string cmd = CLIENT; |
|||
system(cmd.c_str()); |
|||
} |
|||
|
|||
ref_path = Gio::File::create_for_path(ARGS_FILE_DESCRIPTOR.c_str()); |
|||
if(ref_path->query_exists()) { |
|||
try { |
|||
std::remove(ARGS_FILE_DESCRIPTOR.c_str()); |
|||
} |
|||
catch( const std::exception& e ) { |
|||
throw std::runtime_error("Error deleting args file descriptor.\n"); |
|||
} |
|||
}; |
|||
} |
|||
|
|||
void Args::get_pid() |
|||
{ |
|||
pid_t pid = getpid(); |
|||
std::string str; |
|||
|
|||
char *mypid = NULL; |
|||
if (asprintf(&mypid, "%jd", (intmax_t) pid) != -1) { |
|||
str = std::string(mypid); |
|||
free(mypid); // cleanup when done.
|
|||
} |
|||
|
|||
PID = str; |
|||
} |
|||
|
|||
void Args::get_current_path() |
|||
{ |
|||
char current_working_dir[1024] = {0}; |
|||
getcwd(current_working_dir, 1024); |
|||
CURRENT_PATH = std::string(current_working_dir); |
|||
std::cout << "Current path is " << CURRENT_PATH << std::endl; |
|||
} |
|||
|
|||
void Args::get_devices() |
|||
{ |
|||
struct sbuf wired_interface; |
|||
struct sbuf wireless_interface; |
|||
sbuf_init(&wired_interface); |
|||
sbuf_init(&wireless_interface); |
|||
get_interfaces(&wired_interface, &wireless_interface); |
|||
WIRED_DEVICE = std::string(wired_interface.buf); |
|||
WIRELESS_DEVICE = std::string(wireless_interface.buf); |
|||
free(wired_interface.buf); |
|||
free(wireless_interface.buf); |
|||
} |
|||
|
|||
void Args::set_bin_path() |
|||
{ |
|||
Glib::RefPtr<Gio::File> ref_path_A = Gio::File::create_for_path( (CURRENT_PATH + "/suid").c_str() ); |
|||
Glib::RefPtr<Gio::File> ref_path_B = Gio::File::create_for_path( "/usr/lib/simple-netaid/bin/suid" ); |
|||
Glib::RefPtr<Gio::File> ref_path_C = Gio::File::create_for_path( "/usr/local/lib/simple-netaid/bin/suid" ); |
|||
|
|||
std::string path; |
|||
|
|||
if ( ref_path_A->query_exists() ) |
|||
path = CURRENT_PATH + "/"; |
|||
|
|||
else if ( ref_path_B->query_exists() ) |
|||
path = "/usr/lib/simple-netaid/bin/ "; |
|||
|
|||
else if ( ref_path_C->query_exists() ) |
|||
path = "/usr/local/lib/simple-netaid/bin/ "; |
|||
|
|||
else std::cerr << " The suid executable doesn't exist! " << std::endl; |
|||
|
|||
CLIENT = path + "suid "; |
|||
} |
|||
|
|||
void Args::get_pixmaps() |
|||
{ |
|||
Glib::RefPtr<Gio::File> ref_path_A = Gio::File::create_for_path((CURRENT_PATH + "/pixmaps/SimpleNetaid.png").c_str()); |
|||
Glib::RefPtr<Gio::File> ref_path_B = Gio::File::create_for_path("/usr/share/pixmaps/SimpleNetaid.png"); |
|||
|
|||
std::string path; |
|||
|
|||
if ( ref_path_A->query_exists() ) |
|||
path = CURRENT_PATH + "/pixmaps/"; |
|||
|
|||
else if ( ref_path_B->query_exists() ) |
|||
path = "/usr/share/pixmaps/"; |
|||
|
|||
else std::cerr << " Icon's path doesn't exist! " << std::endl; |
|||
|
|||
APP_ICON = path + "SimpleNetaid.png"; |
|||
CONNECTED_ICON = path + "connected.png"; |
|||
DISCONNECTED_ICON = path + "disconnected.png"; |
|||
WIRED_ICON = path + "wired.png"; |
|||
WIRELESS_ICON = path + "wireless.png"; |
|||
VIEW_REFRESH_ICON = path + "view-refresh.png"; |
|||
} |
@ -0,0 +1,56 @@ |
|||
/*
|
|||
* args.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#ifndef __ARGS_H__ |
|||
#define __ARGS_H__ |
|||
|
|||
#include <gtkmm.h> |
|||
|
|||
class Args |
|||
{ |
|||
public: |
|||
Args(int, char**); |
|||
virtual ~Args(); |
|||
|
|||
virtual void get_pid(); |
|||
virtual void get_current_path(); |
|||
virtual void get_devices(); |
|||
virtual void set_bin_path(); |
|||
virtual void get_pixmaps(); |
|||
|
|||
std::vector<std::string> argvs; |
|||
|
|||
std::string PID, |
|||
CURRENT_PATH, |
|||
ARGS_FILE_DESCRIPTOR, |
|||
ACTIVE_WIFIS_OUTPUT, |
|||
WIRED_DEVICE, |
|||
WIRELESS_DEVICE, |
|||
APP_ICON, |
|||
CONNECTED_ICON, |
|||
DISCONNECTED_ICON, |
|||
WIRED_ICON, |
|||
WIRELESS_ICON, |
|||
VIEW_REFRESH_ICON, |
|||
CLIENT; |
|||
}; |
|||
|
|||
#endif // __ARGS_H__
|
@ -0,0 +1,40 @@ |
|||
/*
|
|||
* buttonbox.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#include "buttonbox.h" |
|||
|
|||
myButtonBox::myButtonBox(bool horizontal, int spacing, Gtk::ButtonBoxStyle layout) |
|||
{ |
|||
if (horizontal) |
|||
bbox = new Gtk::HButtonBox; |
|||
else |
|||
bbox = new Gtk::VButtonBox; |
|||
|
|||
bbox->set_border_width(5); |
|||
|
|||
add(*bbox); |
|||
bbox->set_layout(layout); |
|||
bbox->set_spacing(spacing); |
|||
} |
|||
|
|||
myButtonBox::~myButtonBox() |
|||
{ |
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
/*
|
|||
* buttonbox.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#ifndef __BUTTONBOX_H__ |
|||
#define __BUTTONBOX_H__ |
|||
|
|||
#include <gtkmm.h> |
|||
|
|||
class myButtonBox : public Gtk::Alignment |
|||
{ |
|||
public: |
|||
myButtonBox(bool horizontal, int spacing, Gtk::ButtonBoxStyle layout); |
|||
virtual ~myButtonBox(); |
|||
|
|||
// Child widgets:
|
|||
Gtk::ButtonBox *bbox; |
|||
}; |
|||
|
|||
#endif //__BUTTONBOX_H__
|
@ -0,0 +1,84 @@ |
|||
/*
|
|||
* cli.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#include <thread> |
|||
#include <iostream> |
|||
#include "cli.h" |
|||
|
|||
Cli::Cli(std::string fileDescriptor) |
|||
{ |
|||
puntSockServer = (struct sockaddr*) &dirUNIXServer; |
|||
longServer = sizeof(dirUNIXServer); |
|||
|
|||
// Create a bidirectional UNIX socket:
|
|||
dfClient = socket ( AF_UNIX, SOCK_STREAM, PROTOCOL ); |
|||
dirUNIXServer.sun_family = AF_UNIX; /* domain type */ |
|||
strcpy(dirUNIXServer.sun_path, fileDescriptor.c_str()); /* name of the server */ |
|||
|
|||
int n=0; |
|||
while(1) { |
|||
int result = connect(dfClient, puntSockServer, longServer); |
|||
if(result == -1 && n<10) { |
|||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); /* retry */ |
|||
n++; |
|||
} else break; |
|||
} |
|||
|
|||
std::vector<std::string>::iterator iter; |
|||
iter = messages.begin(); |
|||
while(readMessage()) iter++; |
|||
} |
|||
|
|||
Cli::~Cli() |
|||
{ |
|||
close(dfClient); /* close the socket */ |
|||
} |
|||
|
|||
int Cli::readMessage() |
|||
{ |
|||
char *buffer, *cad; |
|||
|
|||
buffer = (char*)malloc(1); |
|||
buffer[0] = '\0'; |
|||
|
|||
cad = (char*)malloc(1); |
|||
cad[0] = '\0'; |
|||
|
|||
int n, buffer_size = 1, len = 0; |
|||
|
|||
do { |
|||
n = read (dfClient, cad, 1); |
|||
|
|||
if (buffer_size <= len + 1) { |
|||
buffer_size = buffer_size * 2 + 16; |
|||
buffer = (char*)realloc(buffer, buffer_size); |
|||
} |
|||
|
|||
buffer[len++] = *cad; |
|||
buffer[len] = 0; |
|||
|
|||
} while (n > 0 && *cad++); |
|||
|
|||
if(n > 0) messages.push_back(buffer); |
|||
|
|||
free(buffer); |
|||
|
|||
return (n > 0); |
|||
} |
@ -0,0 +1,51 @@ |
|||
/*
|
|||
* cli.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#ifndef __CLI_H__ |
|||
#define __CLI_H__ |
|||
|
|||
#include <iostream> |
|||
#include <vector> |
|||
#include <unistd.h> |
|||
#include <signal.h> |
|||
#include <sys/types.h> |
|||
#include <sys/socket.h> |
|||
#include <sys/un.h> /* for UNIX sockets */ |
|||
|
|||
#define PROTOCOL 0 /* protocol by default */ |
|||
|
|||
class Cli |
|||
{ |
|||
public: |
|||
Cli(std::string); |
|||
virtual ~Cli(); |
|||
|
|||
std::vector<std::string> messages; |
|||
|
|||
private: |
|||
int longServer, dfClient; |
|||
struct sockaddr_un dirUNIXServer; |
|||
struct sockaddr* puntSockServer; |
|||
|
|||
int readMessage(); |
|||
}; |
|||
|
|||
|
|||
#endif // __CLI_H__
|
@ -0,0 +1,87 @@ |
|||
/*
|
|||
* icon_factory.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#include <iostream> |
|||
|
|||
#include "icon_factory.h" |
|||
|
|||
IconFactory::IconFactory() |
|||
{ |
|||
std::string REFRESH_STOCK_ICON = "pixmaps/refresh.png"; |
|||
std::string WIRED_STOCK_ICON = "pixmaps/wired.png"; |
|||
std::string WIRELESS_STOCK_ICON = "pixmaps/wireless.png"; |
|||
|
|||
Glib::RefPtr<Gtk::IconFactory> factory = Gtk::IconFactory::create(); |
|||
|
|||
add_stock_icon(factory, REFRESH_STOCK_ICON, "refresh", "Refresh"); |
|||
add_stock_icon(factory, WIRED_STOCK_ICON, "wired connection", "Wired connection"); |
|||
add_stock_icon(factory, WIRELESS_STOCK_ICON, "wireless", "Wireless connection"); |
|||
|
|||
factory->add_default(); //Add factory to list of factories.
|
|||
|
|||
this->REFRESH_STOCK_ICON = Gtk::StockID("refresh"); |
|||
this->WIRED_STOCK_ICON = Gtk::StockID("wired connection"); |
|||
this->WIRELESS_STOCK_ICON = Gtk::StockID("wireless"); |
|||
} |
|||
|
|||
IconFactory::~IconFactory() |
|||
{ |
|||
|
|||
} |
|||
|
|||
void IconFactory::add_stock_icon( const Glib::RefPtr<Gtk::IconFactory> &factory, |
|||
const std::string& filepath, |
|||
const std::string& id, |
|||
const std::string& label ) |
|||
{ |
|||
Gtk::IconSource source; |
|||
|
|||
try |
|||
{ |
|||
//This throws an exception if the file is not found:
|
|||
//source.set_pixbuf(Gdk::Pixbuf::create_from_file(filepath));
|
|||
const Glib::RefPtr<Gdk::Pixbuf>& pixbuf = Gdk::Pixbuf::create_from_file(filepath.c_str()); |
|||
source.set_pixbuf(pixbuf); |
|||
} |
|||
catch(const Glib::Exception& ex) |
|||
{ |
|||
std::cout << ex.what() << std::endl; |
|||
} |
|||
|
|||
source.set_size(Gtk::ICON_SIZE_SMALL_TOOLBAR); |
|||
source.set_size_wildcarded(); //Icon may be scaled.
|
|||
|
|||
#if GTK_MAJOR_VERSION == 2 |
|||
|
|||
Gtk::IconSet icon_set; |
|||
icon_set.add_source(source); //More than one source per set is allowed.
|
|||
|
|||
#elif GTK_MAJOR_VERSION == 3 |
|||
|
|||
Glib::RefPtr<Gtk::IconSet> icon_set = Gtk::IconSet::create(); |
|||
icon_set->add_source(source); //More than one source per set is allowed.
|
|||
|
|||
#endif |
|||
|
|||
const Gtk::StockID stock_id(id); |
|||
factory->add(stock_id, icon_set); |
|||
Gtk::Stock::add(Gtk::StockItem(stock_id, label)); |
|||
} |
@ -0,0 +1,45 @@ |
|||
/*
|
|||
* icon_factory.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#ifndef __ICON_FACTORY_H__ |
|||
#define __ICON_FACTORY_H__ |
|||
|
|||
#include <gtkmm.h> |
|||
|
|||
class IconFactory |
|||
{ |
|||
public: |
|||
IconFactory(); |
|||
virtual ~IconFactory(); |
|||
|
|||
protected: |
|||
Gtk::StockID REFRESH_STOCK_ICON; |
|||
Gtk::StockID WIRED_STOCK_ICON; |
|||
Gtk::StockID WIRELESS_STOCK_ICON; |
|||
|
|||
private: |
|||
virtual void add_stock_icon( const Glib::RefPtr<Gtk::IconFactory>&, |
|||
const std::string&, |
|||
const std::string&, |
|||
const std::string& ); |
|||
}; |
|||
|
|||
#endif // __ICON_FACTORY_H__
|
@ -0,0 +1,84 @@ |
|||
/*
|
|||
* menubar.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#include <iostream> |
|||
|
|||
#include "menubar.h" |
|||
#include "window_main.h" |
|||
|
|||
myMenuBar::myMenuBar(WindowMain *caller) |
|||
{ |
|||
item = Gtk::manage(new Gtk::ImageMenuItem("Menu", true)); |
|||
append(*item); |
|||
m_Submenu = Gtk::manage(new Gtk::Menu()); |
|||
item->set_submenu(*m_Submenu); |
|||
|
|||
m_WiredConnectionItem = Gtk::manage(new Gtk::ImageMenuItem(myMenuBar::WIRED_STOCK_ICON)); |
|||
m_Submenu->append(*m_WiredConnectionItem); |
|||
m_WiredConnectionItem->signal_activate().connect ( |
|||
sigc::mem_fun(*this, &myMenuBar::on_action_connect) |
|||
); |
|||
|
|||
m_DisconnectItem = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::DISCONNECT)); |
|||
m_Submenu->append(*m_DisconnectItem); |
|||
m_DisconnectItem->signal_activate().connect ( |
|||
sigc::mem_fun(*this, &myMenuBar::on_action_disconnect) |
|||
); |
|||
|
|||
m_QuitItem = Gtk::manage( new Gtk::ImageMenuItem(Gtk::Stock::QUIT)); |
|||
m_Submenu->append(*m_QuitItem); |
|||
m_QuitItem->signal_activate().connect ( |
|||
sigc::mem_fun(*caller, &WindowMain::hide) |
|||
); |
|||
|
|||
// Define the items of the second Menu:
|
|||
item = Gtk::manage(new Gtk::ImageMenuItem("Help", true)); |
|||
append(*item); |
|||
m_Submenu = Gtk::manage(new Gtk::Menu()); |
|||
item->set_submenu(*m_Submenu); |
|||
|
|||
m_AboutItem = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::ABOUT)); |
|||
m_Submenu->append(*m_AboutItem); |
|||
|
|||
m_AboutItem->signal_activate().connect ( |
|||
sigc::mem_fun(*this, &myMenuBar::on_action_about) |
|||
); |
|||
} |
|||
|
|||
myMenuBar::~myMenuBar() |
|||
{ |
|||
|
|||
} |
|||
|
|||
void myMenuBar::on_action_connect() |
|||
{ |
|||
std::cout << "\nExecuting on_action_connect..." << std::endl; |
|||
} |
|||
|
|||
void myMenuBar::on_action_disconnect() |
|||
{ |
|||
std::cout << "\nExecuting on_action_disconnect..." << std::endl; |
|||
} |
|||
|
|||
void myMenuBar::on_action_about() |
|||
{ |
|||
std::cout << "\nExecuting on_action_about..." << std::endl; |
|||
} |
@ -0,0 +1,47 @@ |
|||
/*
|
|||
* menubar.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#ifndef __MENUBAR_H__ |
|||
#define __MENUBAR_H__ |
|||
|
|||
#include <gtkmm.h> |
|||
#include "icon_factory.h" |
|||
|
|||
// Forward declarations:
|
|||
class WindowMain; |
|||
|
|||
class myMenuBar : public Gtk::MenuBar , public IconFactory |
|||
{ |
|||
public: |
|||
myMenuBar(WindowMain*); |
|||
virtual ~myMenuBar(); |
|||
|
|||
protected: |
|||
Gtk::Menu *m_Submenu; |
|||
Gtk::ImageMenuItem *item, *m_WiredConnectionItem, *m_DisconnectItem, *m_QuitItem, *m_AboutItem; |
|||
Gtk::SeparatorMenuItem *hline; |
|||
|
|||
virtual void on_action_connect(); |
|||
virtual void on_action_disconnect(); |
|||
virtual void on_action_about(); |
|||
}; |
|||
|
|||
#endif // __MENUBAR_H__
|
@ -0,0 +1,110 @@ |
|||
/*
|
|||
* notebook.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid-gtk is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#include "notebook.h" |
|||
#include "window_main.h" |
|||
#include "args.h" |
|||
#include "buttonbox.h" |
|||
#include "active_wifis.h" |
|||
|
|||
// Constructor
|
|||
myNotebook::myNotebook(WindowMain *caller, const Args& args) |
|||
: |
|||
m_Label1(" Active Wifis "), |
|||
m_Label2(" Installed Wifis ") |
|||
{ |
|||
set_scrollable(true); |
|||
|
|||
m_Align1.set_padding(0, 0, 0, 0); |
|||
m_Align2.set_padding(0, 0, 0, 0); |
|||
|
|||
m_Align1.add(m_ScrolledWindow1); |
|||
m_VBox1.add(m_ScrolledWindow1); |
|||
|
|||
m_Align2.add (m_HBox); |
|||
m_HBox.add (m_ScrolledWindow2); |
|||
|
|||
m_ScrolledWindow1.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); |
|||
m_ScrolledWindow2.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); |
|||
|
|||
append_page(m_Align1, m_Label1); |
|||
append_page(m_Align2, m_Label2); |
|||
|
|||
m_ActiveWifis = new ActiveWifis(caller, args); |
|||
m_ScrolledWindow1.add(*m_ActiveWifis); |
|||
|
|||
m_HBox.pack_start(m_VBox2, Gtk::PACK_SHRINK); |
|||
|
|||
m_VBox2.set_border_width(10); |
|||
|
|||
m_ButtonBox = new myButtonBox(false, 10, Gtk::BUTTONBOX_START); |
|||
m_VBox2.pack_start(*m_ButtonBox, true, true, 5); |
|||
|
|||
m_ButtonConnect = Gtk::manage( new Gtk::Button( Gtk::Stock::CONNECT ) ); |
|||
m_ButtonBox->bbox->add(*m_ButtonConnect); |
|||
|
|||
m_ButtonRemove = Gtk::manage( new Gtk::Button( Gtk::Stock::REMOVE ) ); |
|||
m_ButtonBox->bbox->add(*m_ButtonRemove); |
|||
|
|||
m_ButtonConnect->signal_clicked().connect ( |
|||
sigc::bind< WindowMain*, const Args&> |
|||
( |
|||
sigc::mem_fun( *this, &myNotebook::on_button_connect ), |
|||
caller, |
|||
args |
|||
) |
|||
); |
|||
|
|||
m_ButtonRemove->signal_clicked().connect ( |
|||
sigc::bind< WindowMain*, const Args&> |
|||
( |
|||
sigc::mem_fun( *this, &myNotebook::on_button_remove ), |
|||
caller, |
|||
args |
|||
) |
|||
); |
|||
|
|||
m_ButtonConnect->set_can_focus(false); |
|||
m_ButtonRemove->set_can_focus(false); |
|||
|
|||
show_all_children(); |
|||
} |
|||
|
|||
// Destructor (virtual)
|
|||
myNotebook::~myNotebook() |
|||
{ |
|||
//if(m_ButtonBox) delete m_ButtonBox;
|
|||
//if(m_ActiveWifis) delete m_ActiveWifis;
|
|||
} |
|||
|
|||
void myNotebook::on_button_connect(WindowMain* caller, const Args& args) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void myNotebook::on_button_remove(WindowMain* caller, const Args& args) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void myNotebook::fill_treeview(WindowMain *caller) |
|||
{ |
|||
m_ActiveWifis->fill_treeview(caller); |
|||
} |
@ -0,0 +1,65 @@ |
|||
/*
|
|||
* notebook.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid-gtk is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#ifndef __NOTEBOOK_H__ |
|||
#define __NOTEBOOK_H__ |
|||
|
|||
#include <gtkmm.h> |
|||
|
|||
// Forward declarations:
|
|||
class WindowMain; |
|||
class Args; |
|||
class myButtonBox; |
|||
class ActiveWifis; |
|||
|
|||
class myNotebook : public Gtk::Notebook |
|||
{ |
|||
public: |
|||
myNotebook(WindowMain*, const Args&); |
|||
virtual ~myNotebook(); |
|||
|
|||
void fill_treeview(WindowMain*); |
|||
|
|||
protected: |
|||
std::string selected_addr; |
|||
ActiveWifis *m_ActiveWifis; |
|||
|
|||
// Child Widgets:
|
|||
Gtk::HBox m_HBox; |
|||
Gtk::VBox m_VBox1, m_VBox2; |
|||
|
|||
Gtk::ScrolledWindow m_ScrolledWindow1, |
|||
m_ScrolledWindow2; |
|||
|
|||
myButtonBox *m_ButtonBox; |
|||
|
|||
Gtk::Label m_Label1, m_Label2; |
|||
Gtk::Alignment m_Align1, m_Align2; |
|||
Gtk::Button *m_ButtonConnect, *m_ButtonRemove; |
|||
|
|||
// Signal handlers:
|
|||
virtual void on_button_connect(WindowMain*, const Args&); |
|||
virtual void on_button_remove(WindowMain*, const Args&); |
|||
|
|||
// Friend functions:
|
|||
friend void on_statusicon_activated(GtkWidget*, gpointer); |
|||
}; |
|||
|
|||
#endif // __NOTEBOOK_H__
|
@ -0,0 +1,67 @@ |
|||
/*
|
|||
* pipe_file.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#include "pipe_file.h" |
|||
#include <iostream> |
|||
#include <stdexcept> |
|||
|
|||
PipeFile::PipeFile() |
|||
{ |
|||
|
|||
} |
|||
|
|||
PipeFile::~PipeFile() |
|||
{ |
|||
|
|||
} |
|||
|
|||
std::vector<std::string> PipeFile::get_output(std::string cmd) |
|||
{ |
|||
std::vector<std::string> buffer; |
|||
|
|||
try { |
|||
|
|||
char ch; |
|||
struct sbuf s; |
|||
sbuf_init(&s); |
|||
|
|||
FILE *fpipe = (FILE*)popen(cmd.c_str(), "r"); |
|||
|
|||
while ((ch = fgetc(fpipe)) != EOF) { |
|||
if(ch != '\n') sbuf_addch(&s, ch); |
|||
else { |
|||
buffer.push_back(std::string(s.buf)); |
|||
sbuf_init(&s); |
|||
} |
|||
} |
|||
|
|||
pclose(fpipe); |
|||
free(s.buf); |
|||
|
|||
} catch(std::exception const& e){ |
|||
|
|||
throw std::runtime_error("Sorry there was an error opening the file\n"); |
|||
}; |
|||
|
|||
// std::vector<std::string>::iterator iter = buffer.begin();
|
|||
// for(; iter != buffer.end(); iter++) std::cout << *iter << std::endl;
|
|||
|
|||
return buffer; |
|||
} |
@ -0,0 +1,42 @@ |
|||
/*
|
|||
* pipe_file.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#ifndef __PIPE_FILE_H__ |
|||
#define __PIPE_FILE_H__ |
|||
|
|||
#include <string> |
|||
#include <vector> |
|||
|
|||
extern "C" { |
|||
|
|||
#include <simple-netaid/sbuf.h> |
|||
} |
|||
|
|||
class PipeFile |
|||
{ |
|||
public: |
|||
PipeFile(); |
|||
virtual ~PipeFile(); |
|||
|
|||
std::vector<std::string> get_output(std::string); |
|||
}; |
|||
|
|||
#endif // __PIPE_FILE_H__
|
@ -0,0 +1,74 @@ |
|||
/*
|
|||
* popup.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#include <gtkmm.h> |
|||
#include <iostream> |
|||
|
|||
#include "popup.h" |
|||
#include "window_main.h" |
|||
#include "args.h" |
|||
|
|||
myPopup::myPopup(WindowMain *caller, const Args& args) |
|||
{ |
|||
m_Menu = new Gtk::Menu(); |
|||
|
|||
checkItem = Gtk::manage(new Gtk::CheckMenuItem("Automatically connect", true)); |
|||
m_Menu->append(*checkItem); |
|||
|
|||
item = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::PREFERENCES)); |
|||
m_Menu->append(*item); |
|||
|
|||
item = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::INFO)); |
|||
m_Menu->append(*item); |
|||
|
|||
item = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::HELP)); |
|||
m_Menu->append(*item); |
|||
|
|||
hline = Gtk::manage(new Gtk::SeparatorMenuItem()); |
|||
m_Menu->append(*hline); |
|||
|
|||
item = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::QUIT)); |
|||
m_Menu->append(*item); |
|||
item->signal_activate().connect ( |
|||
sigc::bind<WindowMain*> |
|||
( |
|||
sigc::mem_fun(*this, &myPopup::on_action_quit), |
|||
caller |
|||
) |
|||
); |
|||
|
|||
m_Menu->show_all_children(); |
|||
} |
|||
|
|||
myPopup::~myPopup() |
|||
{ |
|||
if(m_Menu) delete m_Menu; |
|||
} |
|||
|
|||
void myPopup::on_action_quit(WindowMain *caller) |
|||
{ |
|||
delete caller; |
|||
} |
|||
|
|||
void myPopup::show_popup_menu(guint button, guint32 activate_time) |
|||
{ |
|||
if(m_Menu) |
|||
m_Menu->popup(button, activate_time); |
|||
} |
@ -0,0 +1,60 @@ |
|||
/*
|
|||
* popup.h |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
|
|||
#ifndef __POPUP_H__ |
|||
#define __POPUP_H__ |
|||
|
|||
#include <gtkmm.h> |
|||
|
|||
// Forward declarations:
|
|||
class WindowMain; |
|||
class Args; |
|||
|
|||
class myPopup : public Gtk::Window |
|||
{ |
|||
public: |
|||
myPopup(WindowMain*, const Args&); |
|||
virtual ~myPopup(); |
|||
|
|||
protected: |
|||
//Child widgets:
|
|||
Gtk::Menu *m_Menu; |
|||
Gtk::ImageMenuItem *item; |
|||
Gtk::SeparatorMenuItem *hline; |
|||
Gtk::CheckMenuItem *checkItem; |
|||
|
|||
Gtk::EventBox *m_EventBox; |
|||
GdkEventButton *gdkEvent; |
|||
|
|||
// Glib:
|
|||
Glib::RefPtr<Gtk::UIManager> m_refUIManager; |
|||
Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup; |
|||
Glib::RefPtr<Gtk::Action> m_refActionQuit; |
|||
|
|||
// Signal handlers:
|
|||
virtual void on_action_quit(WindowMain*); |
|||
virtual void show_popup_menu(guint, guint32); |
|||
|
|||
// Friend class:
|
|||
friend class myStatusIcon; |
|||
}; |
|||
|
|||
#endif // __POPUP_H__
|
@ -0,0 +1,78 @@ |
|||
/*
|
|||
* statusbar.cpp |
|||
* Copyright (C) Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org> |
|||
* |
|||
* simple-netaid is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* simple-netaid-gtk is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||
* See the GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* See the COPYING file. * |
|||
*/ |
|||
|
|||
#include "statusbar.h" |
|||