Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

LoadProgress Class Reference

#include <LoadProgress.h>

List of all members.

Public Methods

 LoadProgress ()
int run_load (const string &subdir_, const string &prefix_, const string &proj_path_, vector< string > &file_list_)
void on_cancel_clicked ()
void dump (void) const

Private Methods

int init (const string &subdir_, const string &prefix_, const string &proj_path_)
bool process_file (void)

Private Attributes

Gtk::Dialog * m_dialog
Gtk::Label * Message
Gtk::ProgressBar * Progress
DIR * m_dp
int m_max_val
vector< string > m_file_list
string m_dir
string m_prefix
uint m_entries
uint m_count


Constructor & Destructor Documentation

LoadProgress::LoadProgress  
 

Definition at line 37 of file LoadProgress.cpp.

References m_dialog, Message, on_cancel_clicked, and Progress.

00038     : m_dialog (NULL), Message (NULL), Progress (NULL),
00039       m_dp (0), m_max_val (0), m_entries (0), m_count (0)
00040 {  
00041     trace ("LoadProgress::LoadProgress");
00042 
00043     m_dialog = this;
00044     Gtk::Button* cancel_button = m_dialog->add_button(Gtk::Stock::CANCEL, 0);
00045 
00046     Gtk::Label *InfoLabel = 
00047         manage(new class Gtk::Label("Processing File :"));   
00048     Message = manage(new class Gtk::Label());
00049 
00050     Gtk::HBox *hbox1 = manage(new class Gtk::HBox(false, 0));
00051     Progress = manage(new class Gtk::ProgressBar());
00052 
00053     Gtk::VBox *vbox1 = manage(new class Gtk::VBox(false, 4));
00054 //    cancel_button->set_flags(GTK_CAN_FOCUS);
00055     InfoLabel->set_alignment(0.5, 0.5);
00056     InfoLabel->set_padding(0, 0);
00057     InfoLabel->set_justify(Gtk::JUSTIFY_LEFT);
00058     Message->set_alignment(0.5, 0.5);
00059     Message->set_padding(0, 0);
00060     hbox1->pack_start(*InfoLabel, false, false, 6);
00061     hbox1->pack_start(*Message, false, false, 0);
00062     Progress->set_size_request (235, 23);
00063     vbox1->pack_start(*hbox1, false, false, 0);
00064     vbox1->pack_start(*Progress, false, false, 0);
00065     m_dialog->get_vbox()->set_spacing(8);
00066     m_dialog->get_vbox()->pack_start(*vbox1);
00067 //    m_dialog->set_policy(false, false, false);
00068 
00069     Gtk::HButtonBox *dialog_action_area1 = m_dialog->get_action_area ();
00070     dialog_action_area1->set_spacing(8); 
00071     InfoLabel->show();
00072     Message->show();
00073     hbox1->show();
00074     Progress->show();
00075     vbox1->show();
00076     m_dialog->show();
00077     cancel_button->signal_clicked ().connect(
00078         SigC::slot(*(static_cast<class LoadProgress*>(this)), 
00079                    &LoadProgress::on_cancel_clicked));
00080 }


Member Function Documentation

void LoadProgress::dump void    const
 

Definition at line 238 of file LoadProgress.cpp.

References m_count, m_dir, m_entries, and m_prefix.

Referenced by init.

00239 {
00240     trace("LoadProgress::dump");
00241 
00242     DL((TRACE,"m_dir     : \"%s\"\n", m_dir.c_str ()));
00243     DL((TRACE,"m_prefix  : \"%s\"\n", m_prefix.c_str ()));
00244     DL((TRACE,"m_entries : %d\n",     m_entries));
00245     DL((TRACE,"m_count   : %d\n",     m_count));
00246 
00247 }

int LoadProgress::init const string &    subdir_,
const string &    prefix_,
const string &    proj_path_
[private]
 

Definition at line 88 of file LoadProgress.cpp.

References dump, m_dir, m_dp, m_entries, m_prefix, and process_file.

Referenced by run_load.

00089 {
00090     trace ("LoadProgress::init");
00091 
00092     string name;        // absolute file name
00093     m_dir = proj_path_ + "/" + subdir_;
00094     m_prefix = prefix_;
00095 
00096     if ((m_dp = opendir (m_dir.c_str ())) == NULL) {
00097         string msg ("Can't open directory\n\"");
00098         msg += m_dir + string ("\"");
00099         Gtk::MessageDialog emsg (msg, MESSAGE_ERROR);
00100         emsg.run ();
00101         return -1;
00102     }
00108     struct dirent* dirp = 0;
00109     while ((dirp = readdir (m_dp)) != NULL) {
00110         m_entries++;
00111     }
00112     rewinddir (m_dp);
00113     
00114     /* Setup idle work callback */
00115     Glib::signal_idle ().connect ((slot (*this, &LoadProgress::process_file)));
00116     dump ();
00117     return 0;
00118 }

void LoadProgress::on_cancel_clicked   [inline]
 

Definition at line 72 of file LoadProgress.h.

Referenced by LoadProgress.

00073 {    
00074     trace ("LoadProgress::on_cancel_clicked");
00075 }

bool LoadProgress::process_file void    [private]
 

We have to know how many files are there in the directory we have to process in order to meaningfully update the progress bar.

Definition at line 127 of file LoadProgress.cpp.

References m_count, m_dir, m_dp, m_entries, m_file_list, m_max_val, m_prefix, max2, Message, and Progress.

Referenced by init.

00128 {
00129     trace ("LoadProgress::process_file");
00130 
00131     struct dirent* dirp = 0;
00132     string name;
00133     string wavinfo_args;
00134     string::size_type idx;
00135     
00136  skip:
00137     if (m_dp == NULL || (dirp = readdir (m_dp)) == NULL) {
00138         /*
00139          * We are at the end of the list; 
00140          * cancel dialog and idle work callback
00141          */
00142         closedir (m_dp);
00143         m_dp = NULL;
00144         sort (m_file_list.begin (), m_file_list.end ());
00145         // cause_close ();
00146         response (Gtk::RESPONSE_NONE);
00147         return false;
00148     }
00149     m_count++;
00150     name = dirp->d_name;
00151 
00155     if (name == "." || name == ".." ||
00156         name.find ("_pause.wav") != std::string::npos)
00157     {
00158         DL((TRACE,"Skiping \"%s\"\n", name.c_str ()));
00159         goto skip;          
00160     }
00161     wavinfo_args = "--silent " + m_dir + "/" + name;
00162 
00163     DL((TRACE,"Processing file \"%s\"\n", name.c_str ()));
00164     Message->set_text (name.c_str ());
00165     DL((TRACE,"Progress: %d / %d : %5.2f\n", m_count, m_entries,
00166         gfloat (m_count) / m_entries));
00167 
00168     Progress->set_fraction (gfloat (m_count) / m_entries);
00169 
00170     DL((TRACE,"Call fork_exec(wavinfo, \"%s\")\n",
00171         wavinfo_args.c_str ()));
00172 
00173     if (Fork::fork_exec ("wavinfo", wavinfo_args, true) != 0) {
00174         DL((APP,"Not a WAV file! Skipping \"%s\"\n", name.c_str ()));
00175         goto skip;
00176     }
00177 
00178     /* File name is of the format: [prefix][number].wav.
00179        For example, ru25_04.wav : prefix = "ru25_", number = 4,
00180        extension = ".wav".
00181        Remove prefix and extension, adjust maximun seen number and
00182        add number to the file list.
00183     */
00184     DL((APP,"Parsing file name \"%s\"\n", name.c_str ()));
00185     DL((APP,"Removing prefix \"%s\"\n", m_prefix.c_str ()));
00186 
00187     if ((idx = name.find (m_prefix)) == 0) {         // remove [prefix]
00188         DL((APP,"Prefix found in position = %d\n",idx));
00189 
00190         name.replace (0, m_prefix.size (), "");
00191         idx = name.find ('.');                      // remove '.wav' portion
00192         if (idx != string::npos) {
00193             DL((APP,"Found '.' in pos = %d\n", idx));
00194             if (name.substr (idx) != ".wav") {
00195                 DL((APP,"Extension \"%s\" != \".wav\"\n", 
00196                     name.substr(idx).c_str ()));
00197                 DL((APP,"Skipping file\n"));
00198                 goto skip;
00199             }
00200             DL((APP,"Removing extension; name = \"%s\"\n", name.c_str ()));
00201             name.replace (idx, name.size (), "");
00202         }
00203         DL((APP,"And the number is: %d\n", atoi (name.c_str ())));
00204         m_max_val = max2 (m_max_val, atoi (name.c_str ()));
00205         DL((APP,"New max_val = %d\n", m_max_val));
00206         m_file_list.push_back (name);
00207         DL((APP,"Added \"%s\" to the file list\n", name.c_str ()));
00208     }
00209     else {
00210         DL((APP, "Prefix is not found!\n"));
00211     }
00212     return true;        // continue processing
00213 }

int LoadProgress::run_load const string &    subdir_,
const string &    prefix_,
const string &    proj_path_,
vector< string > &    file_list_
 

Skip '.', '..', and pause files

Definition at line 220 of file LoadProgress.cpp.

References init, m_file_list, and m_max_val.

Referenced by MainWindow::read_dir.

00224 {
00225     trace ("LoadProgress::run");
00226 
00227     if (init (subdir_, prefix_, proj_path_) == -1) {
00228         return -1;
00229     }
00230 
00231     run ();
00232     file_list_ = m_file_list;   // copy the result
00233     return m_max_val;
00234 }


Member Data Documentation

uint LoadProgress::m_count [private]
 

Definition at line 67 of file LoadProgress.h.

Referenced by dump, and process_file.

Gtk::Dialog* LoadProgress::m_dialog [private]
 

Definition at line 55 of file LoadProgress.h.

Referenced by LoadProgress.

string LoadProgress::m_dir [private]
 

Definition at line 64 of file LoadProgress.h.

Referenced by dump, init, and process_file.

DIR* LoadProgress::m_dp [private]
 

Definition at line 60 of file LoadProgress.h.

Referenced by init, and process_file.

uint LoadProgress::m_entries [private]
 

Definition at line 66 of file LoadProgress.h.

Referenced by dump, init, and process_file.

vector<string> LoadProgress::m_file_list [private]
 

Definition at line 62 of file LoadProgress.h.

Referenced by process_file, and run_load.

int LoadProgress::m_max_val [private]
 

Definition at line 61 of file LoadProgress.h.

Referenced by process_file, and run_load.

string LoadProgress::m_prefix [private]
 

Definition at line 65 of file LoadProgress.h.

Referenced by dump, init, and process_file.

Gtk::Label* LoadProgress::Message [private]
 

Definition at line 56 of file LoadProgress.h.

Referenced by LoadProgress, and process_file.

Gtk::ProgressBar* LoadProgress::Progress [private]
 

Definition at line 57 of file LoadProgress.h.

Referenced by LoadProgress, and process_file.


The documentation for this class was generated from the following files:
Generated on Tue Feb 11 23:05:32 2003 for gwavmerger by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002