Interface List: Hide button for only one interface
authorRoland Knall <rknall@gmail.com>
Sun, 2 Oct 2016 14:22:27 +0000 (16:22 +0200)
committerRoland Knall <rknall@gmail.com>
Sun, 2 Oct 2016 17:56:54 +0000 (17:56 +0000)
If only one interface type exists, the button row is being hidden.

Change-Id: Ieed9c363ab1ebc4bc15d0e09bceeb79a04d6e76e
Reviewed-on: https://code.wireshark.org/review/18017
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
ui/qt/interface_frame.cpp
ui/qt/interface_frame.ui

index 1fdd1c4dca40a118018c35c522572af7e8f0d172..d729eb7b767f87b78106249e52c956f87e8dd66f 100644 (file)
@@ -147,7 +147,7 @@ QAbstractButton * InterfaceFrame::createButton(QString text, QString prop, QVari
 
 void InterfaceFrame::interfaceListChanged()
 {
-    if (sourceModel->rowCount() == 0)
+    if ( sourceModel->rowCount() == 0 )
     {
         ui->interfaceTree->setHidden(true);
         ui->lblNoInterfaces->setHidden(false);
@@ -174,7 +174,9 @@ void InterfaceFrame::resetInterfaceButtons()
 {
     QAbstractButton * button = 0;
 
-    if ( ! global_capture_opts.all_ifaces )
+    ui->wdgTypeSelector->setVisible( proxyModel->typesDisplayed().count() > 1 );
+
+    if ( sourceModel->rowCount() == 0 )
         return;
 
     foreach (QWidget * w, ui->wdgButtons->findChildren<QWidget *>())
@@ -213,12 +215,12 @@ void InterfaceFrame::resetInterfaceButtons()
 
 void InterfaceFrame::updateSelectedInterfaces()
 {
-    if ( ! global_capture_opts.all_ifaces )
+    if ( sourceModel->rowCount() == 0 )
         return;
 
     QItemSelection mySelection;
 
-    for(unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++)
+    for( int idx = 0; idx < sourceModel->rowCount(); idx++ )
     {
         interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
 
@@ -244,7 +246,7 @@ void InterfaceFrame::interfaceTreeSelectionChanged(const QItemSelection & select
 {
     if (selected.count() == 0 && deselected.count() == 0)
         return;
-    if ( ! global_capture_opts.all_ifaces )
+    if ( sourceModel->rowCount() == 0 )
         return;
 
     QList<int> selectedIndices;
@@ -301,7 +303,7 @@ void InterfaceFrame::on_interfaceTree_doubleClicked(const QModelIndex &index)
 {
     QModelIndex realIndex = proxyModel->mapToSource(index);
 
-    if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) realIndex.row() )
+    if ( ! realIndex.isValid() )
         return;
 
 #ifdef HAVE_EXTCAP
@@ -332,7 +334,7 @@ void InterfaceFrame::on_interfaceTree_clicked(const QModelIndex &index)
     {
         QModelIndex realIndex = proxyModel->mapToSource(index);
 
-        if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) realIndex.row() )
+        if ( ! realIndex.isValid() )
             return;
 
         interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, realIndex.row());
@@ -358,12 +360,12 @@ void InterfaceFrame::on_interfaceTree_clicked(const QModelIndex &index)
 
 void InterfaceFrame::updateStatistics(void)
 {
-    if ( ! global_capture_opts.all_ifaces )
+    if ( sourceModel->rowCount() == 0 )
         return;
 
 #ifdef HAVE_LIBPCAP
 
-    for( unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++ )
+    for( int idx = 0; idx < proxyModel->rowCount(); idx++ )
     {
         QModelIndex selectIndex = proxyModel->mapFromSource(sourceModel->index(idx, 0));
 
index 0c9ec9210adc959386737e92241da71faf4db2a2..46d4135eb1d50e860f06bf1c8c3d284a95b51836 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>550</width>
+    <width>555</width>
     <height>350</height>
    </rect>
   </property>
     </widget>
    </item>
    <item>
-    <layout class="QHBoxLayout" name="horizontalLayout">
-     <item>
-      <widget class="QLabel" name="label">
-       <property name="text">
-        <string>Show Interfaces</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QWidget" name="wdgButtons" native="true"/>
-     </item>
-     <item>
-      <spacer name="horizontalSpacer">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeType">
-        <enum>QSizePolicy::MinimumExpanding</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-    </layout>
+    <widget class="QWidget" name="wdgTypeSelector" native="true">
+     <layout class="QHBoxLayout" name="horizontalLayout_2">
+      <property name="leftMargin">
+       <number>0</number>
+      </property>
+      <property name="topMargin">
+       <number>0</number>
+      </property>
+      <property name="rightMargin">
+       <number>0</number>
+      </property>
+      <property name="bottomMargin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Show Interfaces</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QWidget" name="wdgButtons" native="true"/>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::MinimumExpanding</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>429</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
    </item>
   </layout>
  </widget>