Fix Qt compilation on Windows. Check the user-supplied range syntax
authorGerald Combs <gerald@wireshark.org>
Tue, 9 Oct 2012 15:34:40 +0000 (15:34 -0000)
committerGerald Combs <gerald@wireshark.org>
Tue, 9 Oct 2012 15:34:40 +0000 (15:34 -0000)
and provide instant feedback in the Win32 file dialog similar to the Qt
code. Tango-ize some colors. Escape a backslash in QtShark.pro.

svn path=/trunk/; revision=45430

image/file_dlg_win32.rc
ui/qt/QtShark.pro
ui/qt/capture_file_dialog.cpp
ui/win32/file_dlg_win32.c

index 7236a8fab7ff871da7555576c0721f13aed687f3..ef399072ded615ae129215c35293bc19aca03705 100644 (file)
@@ -51,7 +51,7 @@ FONT 8, "MS Shell Dlg"
     CONTROL  "Marked packets", EWFD_MARKED_BTN, "Button", BS_AUTORADIOBUTTON,  78, 47, 67, 10
     CONTROL  "First to last marked", EWFD_FIRST_LAST_BTN, "Button",  BS_AUTORADIOBUTTON, 78, 59, 75, 10
     CONTROL  "Range:", EWFD_RANGE_BTN, "Button",  BS_AUTORADIOBUTTON, 78, 71, 35, 10
-    EDITTEXT EWFD_RANGE_EDIT, 117, 70, 105, 12, ES_AUTOHSCROLL
+    CONTROL  "", EWFD_RANGE_EDIT, RICHEDIT_CLASS, ES_AUTOHSCROLL, 117, 70, 105, 12, WS_EX_CLIENTEDGE
     CONTROL  "Remove Ignored packets", EWFD_REMOVE_IGN_CB, "Button",  BS_AUTOCHECKBOX | WS_TABSTOP, 78, 83, 100, 10
 
     LTEXT "0", EWFD_ALL_PKTS_CAP, 232, 24, 39, 8, SS_RIGHT
index 42301d4f97513350f3f184d3560d25994060d661..8d62aa1a15a5a772f7dd3f30651fb93137a42777 100644 (file)
@@ -325,7 +325,7 @@ RC_FILE = qtshark.rc
 !isEmpty(TRANSLATIONS) {
 
     isEmpty(QMAKE_LRELEASE) {
-        win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\lrelease.exe
+        win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\\lrelease.exe
         else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease
     }
 
index 53788301285990be048c6172b84ea6b953646d49..d6d17864a4269242fcb75ac04c6c7334270a5eb0 100644 (file)
@@ -158,7 +158,7 @@ check_savability_t CaptureFileDialog::checkSaveAsWithComments(QWidget *
 #if defined(Q_WS_WIN)
     if (!parent || !cf)
         return CANCELLED;
-    return win32_check_save_as_with_comments(parent->effectiveWinId(), cap_file_, file_type);
+    return win32_check_save_as_with_comments(parent->effectiveWinId(), cf, file_type);
 #else // Q_WS_WIN
     QMessageBox msg_dialog;
     int response;
@@ -402,11 +402,11 @@ check_savability_t CaptureFileDialog::saveAs(QString &file_name, bool must_suppo
     return CANCELLED;
 }
 
-check_savability_t CaptureFileDialog::exportSelectedPackets(QString &file_name) {
+check_savability_t CaptureFileDialog::exportSelectedPackets(QString &file_name, packet_range_t *range) {
     GString *fname = g_string_new(file_name.toUtf8().constData());
     gboolean wespf_status;
 
-    wespf_status = win32_export_specified_packets_file(parentWidget()->effectiveWinId(), fname, &file_type_, &compressed_, &range_);
+    wespf_status = win32_export_specified_packets_file(parentWidget()->effectiveWinId(), fname, &file_type_, &compressed_, range);
     file_name = fname->str;
 
     g_string_free(fname, TRUE);
@@ -651,13 +651,14 @@ int CaptureFileDialog::mergeType() {
 
     return 0;
 }
-#endif // Q_WS_WINDOWS
-
-// Slots
 
 void CaptureFileDialog::rangeValidityChanged(bool is_valid) {
     if (save_bt_) save_bt_->setEnabled(is_valid);
 }
+#endif // Q_WS_WINDOWS
+
+// Slots
+
 
 
 /* do a preview run on the currently selected capture file */
index a553bea00f1d8cf67b56f447b57b218fc0d85b41..7b6720b640575c9f7b83ea04bb8d6a5f09fdf111 100644 (file)
@@ -1340,10 +1340,10 @@ filter_tb_syntax_check(HWND hwnd, TCHAR *filter_text) {
         if (dfp != NULL)
             dfilter_free(dfp);
         /* Valid (light green) */
-        SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, 0x00afffaf);
+        SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, RGB(0xe4, 0xff, 0xc7)); /* tango_chameleon_1 */
     } else {
         /* Invalid (light red) */
-        SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, 0x00afafff);
+        SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, RGB(0xff, 0xcc, 0xcc)); /* tango_scarlet_red_1 */
     }
 
     if (strval) g_free(strval);
@@ -1826,7 +1826,8 @@ range_update_dynamics(HWND dlg_hwnd, packet_range_t *range) {
     TCHAR    static_val[STATIC_LABEL_CHARS];
     gint     selected_num;
     guint32  ignored_cnt = 0, displayed_ignored_cnt = 0;
-    guint32       displayed_cnt;
+    guint32  displayed_cnt;
+    gboolean range_valid = TRUE;
 
     cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_DISPLAYED_BTN);
     if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
@@ -1920,23 +1921,51 @@ range_update_dynamics(HWND dlg_hwnd, packet_range_t *range) {
     SetWindowText(cur_ctrl, static_val);
 
     /* RANGE_SELECT_USER */
-    cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_CAP);
-    EnableWindow(cur_ctrl, !filtered_active);
-    if (range->remove_ignored) {
-        StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt - range->ignored_user_range_cnt);
-    } else {
-        StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt);
-    }
-    SetWindowText(cur_ctrl, static_val);
+    switch (packet_range_check(range)) {
+        case CVT_NO_ERROR:
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
+            SendMessage(cur_ctrl, EM_SETBKGNDCOLOR, (WPARAM) 1, COLOR_WINDOW);
+
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_CAP);
+            EnableWindow(cur_ctrl, !filtered_active);
+            if (range->remove_ignored) {
+                StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt - range->ignored_user_range_cnt);
+            } else {
+                StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt);
+            }
+            SetWindowText(cur_ctrl, static_val);
+        
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP);
+            EnableWindow(cur_ctrl, filtered_active);
+            if (range->remove_ignored) {
+                StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_user_range_cnt - range->displayed_ignored_user_range_cnt);
+            } else {
+                StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_user_range_cnt);
+            }
+            SetWindowText(cur_ctrl, static_val);
+            break;
+        case CVT_SYNTAX_ERROR:
+            if (range->process == range_process_user_range) range_valid = FALSE;
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
+            SendMessage(cur_ctrl, EM_SETBKGNDCOLOR, 0, RGB(0xff, 0xcc, 0xcc));
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_CAP);
+            SetWindowText(cur_ctrl, _T("Bad range"));
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP);
+            SetWindowText(cur_ctrl, _T("-"));
+            break;
+        case CVT_NUMBER_TOO_BIG:
+            if (range->process == range_process_user_range) range_valid = FALSE;
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
+            SendMessage(cur_ctrl, EM_SETBKGNDCOLOR, 0, RGB(0xff, 0xcc, 0xcc));
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_CAP);
+            SetWindowText(cur_ctrl, _T("Too large"));
+            cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP);
+            SetWindowText(cur_ctrl, _T("-"));
+           break;
 
-    cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP);
-    EnableWindow(cur_ctrl, filtered_active);
-    if (range->remove_ignored) {
-        StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_user_range_cnt - range->displayed_ignored_user_range_cnt);
-    } else {
-        StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_user_range_cnt);
+        default:
+            g_assert_not_reached();
     }
-    SetWindowText(cur_ctrl, static_val);
 
     /* RANGE_REMOVE_IGNORED_PACKETS */
     switch(range->process) {
@@ -1976,6 +2005,9 @@ range_update_dynamics(HWND dlg_hwnd, packet_range_t *range) {
     EnableWindow(cur_ctrl, displayed_ignored_cnt && filtered_active);
     StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), displayed_ignored_cnt);
     SetWindowText(cur_ctrl, static_val);
+
+    cur_ctrl = GetDlgItem(GetParent(dlg_hwnd), IDOK);
+    EnableWindow(cur_ctrl, range_valid);
 }
 
 static void
@@ -1989,6 +2021,12 @@ range_handle_wm_initdialog(HWND dlg_hwnd, packet_range_t *range) {
         cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_CAPTURED_BTN);
     SendMessage(cur_ctrl, BM_SETCHECK, TRUE, 0);
 
+    /* Retain the filter text, and fill it in. */
+    if(range->user_range != NULL) {
+        cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
+        SetWindowText(cur_ctrl, utf_8to16(range_convert_range(range->user_range)));
+    }
+
     /* dynamic values in the range frame */
     range_update_dynamics(dlg_hwnd, range);
 
@@ -2068,7 +2106,7 @@ range_handle_wm_command(HWND dlg_hwnd, HWND ctrl, WPARAM w_param, packet_range_t
             cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_BTN);
             SendMessage(cur_ctrl, BM_CLICK, 0, 0);
             break;
-        case (EN_CHANGE << 16) | EWFD_RANGE_EDIT:
+        case (EN_UPDATE << 16) | EWFD_RANGE_EDIT:
             SendMessage(ctrl, WM_GETTEXT, (WPARAM) RANGE_TEXT_MAX, (LPARAM) range_text);
             packet_range_convert_str(range, utf_16to8(range_text));
             range_update_dynamics(dlg_hwnd, range);