add parameter dcerpc_info to PIDL_dissect_ipv?address()
[wireshark-wip.git] / ui / qt / progress_bar.cpp
blob8b1a1883b3b42d54c4d90aac5fe8e9ca86461f25
1 /* progress_bar.cpp
3 * $Id$
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "config.h"
26 #include "progress_bar.h"
28 #include "wireshark_application.h"
30 #include <QGraphicsOpacityEffect>
31 #include <QPropertyAnimation>
33 // XXX We should probably call ITaskbarList3::SetProgressState and
34 // ::SetProgressState on Windows and add an NSProgressIndicator to the
35 // dock icon on OS X.
37 static progdlg_t *
38 common_create_progress_dlg(bool animate, const gpointer top_level_window,
39 gboolean terminate_is_stop, gboolean *stop_flag,
40 int value)
42 ProgressBar *pb;
43 QWidget *main_window;
45 if (!top_level_window) {
46 return NULL;
49 main_window = qobject_cast<QWidget *>((QObject *)top_level_window);
51 if (!main_window) {
52 return NULL;
55 pb = main_window->findChild<ProgressBar *>();
57 if (!pb) {
58 return NULL;
60 return pb->show(animate, terminate_is_stop, stop_flag, value);
63 progdlg_t *
64 create_progress_dlg(const gpointer top_level_window, const gchar *task_title, const gchar *item_title,
65 gboolean terminate_is_stop, gboolean *stop_flag,
66 const GTimeVal *start_time, gfloat progress)
68 Q_UNUSED(task_title);
69 Q_UNUSED(item_title);
70 Q_UNUSED(start_time);
72 return common_create_progress_dlg(false, top_level_window, terminate_is_stop, stop_flag, progress * 100);
75 progdlg_t *
76 delayed_create_progress_dlg(const gpointer top_level_window, const gchar *task_title, const gchar *item_title,
77 gboolean terminate_is_stop, gboolean *stop_flag,
78 const GTimeVal *start_time, gfloat progress)
80 Q_UNUSED(task_title);
81 Q_UNUSED(item_title);
82 Q_UNUSED(start_time);
84 return common_create_progress_dlg(true, top_level_window, terminate_is_stop, stop_flag, progress * 100);
88 * Update the progress information of the progress bar box.
90 void
91 update_progress_dlg(progdlg_t *dlg, gfloat percentage, const gchar *status)
93 Q_UNUSED(status);
95 dlg->progress_bar->setValue(percentage * 100);
98 * Flush out the update and process any input events.
100 WiresharkApplication::processEvents();
104 * Destroy the progress bar.
106 void
107 destroy_progress_dlg(progdlg_t *dlg)
109 dlg->progress_bar->hide();
112 // XXX - Add a "stop what you're doing this instant" button.
113 // XXX - We need to show the task and item titles. Maybe as a tooltip or popped
114 // into our sibling status message?
115 ProgressBar::ProgressBar(QWidget *parent) :
116 QProgressBar(parent), terminate_is_stop_(false), stop_flag_(NULL)
118 progress_dialog_.progress_bar = this;
119 progress_dialog_.top_level_window = window();
121 //#ifdef Q_OS_MAC
122 // // https://bugreports.qt-project.org/browse/QTBUG-11569
123 // setAttribute(Qt::WA_MacSmallSize, true);
124 //#endif
125 setTextVisible(false);
126 setStyleSheet(QString(
127 "ProgressBar {"
128 " max-width: 20em;"
129 " min-height: 0.8em;"
130 " max-height: 1em;"
131 " border-bottom: 0;"
132 " background: transparent;"
133 "}"));
135 hide();
138 progdlg_t * ProgressBar::show(bool animate, bool terminate_is_stop, gboolean *stop_flag, int value) {
140 terminate_is_stop_ = terminate_is_stop;
141 stop_flag_ = stop_flag;
143 setValue(value);
145 #if !defined(Q_OS_MAC) || QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
146 if (animate) {
147 QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(this);
148 this->setGraphicsEffect(effect);
150 QPropertyAnimation *animation = new QPropertyAnimation(effect, "opacity");
152 animation->setDuration(750);
153 animation->setStartValue(0.1);
154 animation->setEndValue(1.0);
155 animation->setEasingCurve(QEasingCurve::InOutQuad);
156 animation->start();
158 #else
159 Q_UNUSED(animate);
160 #endif
162 QProgressBar::show();
163 return &progress_dialog_;
167 * Editor modelines
169 * Local Variables:
170 * c-basic-offset: 4
171 * tab-width: 8
172 * indent-tabs-mode: nil
173 * End:
175 * ex: set shiftwidth=4 tabstop=8 expandtab:
176 * :indentSize=4:tabSize=8:noTabs=true: