Skip to content

Commit

Permalink
New GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
hessionb committed Apr 19, 2012
1 parent 11b2275 commit 42d5515
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 15 deletions.
3 changes: 3 additions & 0 deletions etc/classcatcher.log
@@ -0,0 +1,3 @@
CRN: 92111 - 6
CRN: 99999 - None
CRN: 98888 - None
7 changes: 7 additions & 0 deletions etc/cookie.txt
@@ -0,0 +1,7 @@
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file! Do not edit.

.vt.edu TRUE / TRUE NATIVE_LOGIN TRUE
.vt.edu TRUE / TRUE SESSID QUlVVlQzMTIwNjAxODU=
banweb.banner.vt.edu FALSE /ssb/prod TRUE TESTID set
46 changes: 46 additions & 0 deletions headers/error.h
@@ -0,0 +1,46 @@
/***
* Brian Hession, Erik Wenkel, James Miller
*
* Error window
*
* Error window that pops up when something
* bad happens.
*
*/

#ifndef ERROR_H
#define ERROR_H

#include <gtkmm/window.h>
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <gtkmm/button.h>
#include <glibmm/ustring.h>


class Error : public Gtk::Window {

public:
Error();
virtual ~Error();

void setfields( Gtk::Window* w );
void setlabel( Glib::ustring s );

protected:
// Signal handlers
void on_close();

// Formatting
Gtk::VBox m_VBox;

// Widgets
Gtk::Label errorlabel;
Gtk::Button close_button;

// Parent
Gtk::Window* parent;
};

#endif

4 changes: 4 additions & 0 deletions headers/gui.h
Expand Up @@ -20,6 +20,7 @@
#include "credentials.h"
#include "options.h"
#include "popup.h"
#include "error.h"


// Create class GUI extending Gtk::Window
Expand Down Expand Up @@ -66,6 +67,9 @@ class GUI : public Gtk::Window {

// Test
Popup popup;

// Error
Error error;
};

#endif
8 changes: 5 additions & 3 deletions headers/popup.h
Expand Up @@ -22,6 +22,7 @@
#include <glibmm/ustring.h>

#include "tree.h"
#include "error.h"


class Popup : public Gtk::Window {
Expand All @@ -30,12 +31,13 @@ class Popup : public Gtk::Window {
Popup();
virtual ~Popup();

void set_values( Gtk::Window* parent, Tree* t );
void set_values( Gtk::Window* parent, Tree* t, Error* e );

protected:
// Signal handlers
void on_apply();
void on_close();
void on_error();

// Entry model
class ModelColumns : public Gtk::TreeModel::ColumnRecord {
Expand All @@ -46,8 +48,7 @@ class Popup : public Gtk::Window {
}

Gtk::TreeModelColumn<Glib::ustring> m_col_name;
};
ModelColumns m_columns;
} m_columns;

// For entry completion
typedef std::map<int, Glib::ustring> type_actions_map;
Expand All @@ -70,6 +71,7 @@ class Popup : public Gtk::Window {
// Pointers to Parent widgets
Gtk::Window* parent;
Tree* classlist;
Error* error;
};

#endif
Expand Down
53 changes: 53 additions & 0 deletions src/error.cpp
@@ -0,0 +1,53 @@
/***
* Brian Hession, Erik Wenkel, James Miller
*
* Error popup implementation
*
*/

#include "error.h"

Error::Error()
:
// Initializing
errorlabel( "Error: " ),
close_button( "_Close", true )
{
// Window properties
set_title( "Error Message" );
set_size_request( 200, 5 );
set_resizable( false );
set_border_width( 5 );
set_keep_above( true );
set_decorated( false );

m_VBox.pack_start( errorlabel, Gtk::PACK_SHRINK );
m_VBox.pack_start( close_button, Gtk::PACK_SHRINK );

add( m_VBox );

// Add signal
close_button.signal_clicked().connect( sigc::mem_fun( *this,
&Error::on_close ) );

show_all_children();
}

Error::~Error() {}

void Error::setfields( Gtk::Window* w ) {

parent = w;
}

void Error::setlabel( Glib::ustring s ) {

errorlabel.set_text( s );
}

void Error::on_close() {

parent->set_sensitive( true );
hide();
}

4 changes: 2 additions & 2 deletions src/gui.cpp
Expand Up @@ -82,10 +82,10 @@ void GUI::deleteclass() {
void GUI::popupwindow() {

// Make window popup
popup.set_values( this, &classtree );
popup.set_values( this, &classtree, &error );
int x, y;
get_position( x, y );
popup.move( x + 15, y + 15 );
popup.move( x + 15, y + 50 );
set_sensitive( false );
popup.show();
}
Expand Down
26 changes: 21 additions & 5 deletions src/popup.cpp
Expand Up @@ -30,6 +30,7 @@ Popup::Popup()
set_resizable( false );
set_border_width( 5 );
set_keep_above( true );
set_decorated( false );

// Term combo
term_combo.set_id_column( 0 );
Expand Down Expand Up @@ -359,10 +360,24 @@ Popup::Popup()
Popup::~Popup() {}

// set_tree
void Popup::set_values( Gtk::Window* g, Tree* t ) {
void Popup::set_values( Gtk::Window* g, Tree* t, Error* e ) {

parent = g;
classlist = t;
error = e;
}

// Error
void Popup::on_error() {

error->setfields( this );
set_sensitive( false );

int x, y;
get_position( x, y );
error->move( x + 30, y + 60 );

error->show();
}

bool isvalid( Glib::ustring s, unsigned int len ) {
Expand All @@ -387,10 +402,11 @@ void Popup::on_apply() {
course.subj = subj_entry.get_text();
course.crse = crse_entry.get_text();

if(isvalid(course.crn,5))
std::cout << "good" << std::endl;
if(isvalid(course.crse,4))
std::cout << "good" << std::endl;
if(!isvalid(course.crn,5) || !isvalid(course.crse, 4)) {
error->setlabel( "Invalid Field" );
on_error();
return;
}

// Reset Fields
crn_entry.delete_text( 0, -1 );
Expand Down
10 changes: 5 additions & 5 deletions src/tree.cpp
Expand Up @@ -29,7 +29,7 @@ Tree::~Tree() {}
void Tree::loadfromfile() {

// Read from text file
std::ifstream coursefile( "include/.courses" );
std::ifstream coursefile( "etc/.courses" );
if( coursefile.is_open() ) {
while( true ) {
Tree::Course c;
Expand Down Expand Up @@ -75,8 +75,8 @@ void Tree::deleteclass() {
if( *iter ) {

Glib::ustring str = (*iter)[m_Columns.m_col_crn];
std::ifstream coursefile( "include/.courses" );
std::ofstream tempfile( "include/.courses.tmp" );
std::ifstream coursefile( "etc/.courses" );
std::ofstream tempfile( "etc/.courses.tmp" );
if( coursefile.is_open() && tempfile.is_open() ) {
while( true ) {
char buf[10], line[256];
Expand All @@ -89,8 +89,8 @@ void Tree::deleteclass() {
}
coursefile.close();
tempfile.close();
std::remove( "include/.courses" ); // Remove and rename file
std::rename( "include/.courses.tmp", "include/.courses" );
std::remove( "etc/.courses" ); // Remove and rename file
std::rename( "etc/.courses.tmp", "etc/.courses" );
}
m_refTreeModel->erase( iter ); // Erase from tree
}
Expand Down

0 comments on commit 42d5515

Please sign in to comment.