src/wscout_gui_main_window.hxx

00001 /*
00002  * WScout - Lightweight PCAP visualizer.
00003  * Copyright (C) 2007, 2008  Universite Pierre et Marie Curie - Paris 6
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018  * MA  02110-1301  USA
00019  *
00020  * Author: Thomas Claveirole <thomas.claveirole@lip6.fr>
00021  */
00022 
00023 #ifndef WSCOUT_GUI_MAIN_WINDOW_HXX_
00024 # define WSCOUT_GUI_MAIN_WINDOW_HXX_
00025 
00026 # include <QtCore/QDir>
00027 # include <QtCore/QFileInfo>
00028 # include <QtGui/QApplication>
00029 
00030 # include "wscout_gui_main_window.hh"
00031 
00032 namespace wscout
00033 {
00034 
00035   namespace gui
00036   {
00037 
00038     inline
00039     MainWindow::NewProgressDialog::NewProgressDialog(QProgressDialog**  d,
00040                                                      QMainWindow*       w):
00041       d_ (d),
00042       w_ (w)
00043     {
00044     }
00045 
00046     inline
00047     void
00048     MainWindow::NewProgressDialog::operator () (std::streampos min,
00049                                                 std::streampos max)
00050     {
00051       QProgressDialog*& d = *d_;
00052 
00053       d = new QProgressDialog (tr("Building Index...<br />"
00054                                   "<b>Total size:</b> %1 MiB")
00055                                .arg(max / (1 << 20)),
00056                                tr("&Cancel"),
00057                                min >> 16,
00058                                max >> 16,
00059                                w_);
00060       d->setWindowTitle(tr("Building index..."));
00061       d->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
00062     }
00063 
00064     inline
00065     MainWindow::
00066     UpdateProgressDialog::UpdateProgressDialog(QProgressDialog** d): d_ (d)
00067     {
00068     }
00069 
00070     inline
00071     const std::string*
00072     MainWindow::UpdateProgressDialog::operator () (std::streampos cur)
00073     {
00074       const static std::string  interrupt_message ("User interruption");
00075       QProgressDialog&          dialog  = **d_;
00076 
00077       dialog.setValue(cur >> 16);
00078       qApp->processEvents();
00079       return dialog.wasCanceled() ? &interrupt_message : 0;
00080     }
00081 
00082     inline
00083     void
00084     MainWindow::addTrace(Trace* t)
00085     {
00086       assert(t);
00087       assert(not t->parent());
00088       assert(t->trace());
00089 
00090       const QString     traceName = t->trace()->file_name().c_str();
00091 
00092       connect(t, SIGNAL(positionChanged(int)), SLOT(updatePosition(int)));
00093       connect(t, SIGNAL(positionChanged(int)), t, SLOT(setFocus()));
00094 
00095       connect(t, SIGNAL(packetLeftClicked(int)), SLOT(updateHexDock(int)));
00096       connect(t, SIGNAL(packetDoubleLeftClicked(int)), SLOT(showHexDock(int)));
00097 
00098       tabs_.setCurrentIndex(tabs_.addTab(t, QFileInfo (traceName).fileName()));
00099       if (tabs_.count() == 1)
00100         updateTrace();
00101     }
00102 
00103     inline
00104     Trace*
00105     MainWindow::trace()
00106     {
00107       QWidget* const    w = tabs_.currentWidget();
00108       Trace* const      t = dynamic_cast<Trace*> (w);
00109 
00110       assert(not w or t);
00111       return t;
00112     }
00113 
00114     inline
00115     const Trace*
00116     MainWindow::trace() const
00117     {
00118       const QWidget* const      w = tabs_.currentWidget();
00119       const Trace* const        t = dynamic_cast<const Trace*> (w);
00120 
00121       assert(not w or t);
00122       return t;
00123     }
00124 
00125     inline
00126     QString
00127     MainWindow::openDirectoryHint() const
00128     {
00129       const Trace* const t = trace();
00130 
00131       return t ?
00132         QFileInfo (t->trace()->file_name().c_str()).absolutePath():
00133         QDir::currentPath();
00134     }
00135 
00136     inline
00137     MainWindow*
00138     MainWindow::setupNewWindow(MainWindow* w, bool show)
00139     {
00140       w->setAttribute(Qt::WA_DeleteOnClose);
00141       if (show)
00142         w->show();
00143       return w;
00144     }
00145 
00146   } // End of namespace gui.
00147 
00148 } // End of namespace wscout.
00149 
00150 #endif // ! WSCOUT_GUI_MAIN_WINDOW_HXX_

Generated on Wed Jan 30 19:02:27 2008 for WScout by  doxygen 1.5.4