Changeset View
Changeset View
Standalone View
Standalone View
src/browsers/BrowserMessageArea.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
70 | { | 70 | { | ||
71 | // The purpose of this emit is to make the operation thread safe. If this | 71 | // The purpose of this emit is to make the operation thread safe. If this | ||
72 | // method is called from a non-GUI thread, the "emit" relays it over the | 72 | // method is called from a non-GUI thread, the "emit" relays it over the | ||
73 | // event loop to the GUI thread, so that we can safely create widgets. | 73 | // event loop to the GUI thread, so that we can safely create widgets. | ||
74 | emit signalLongMessage( text, type ); | 74 | emit signalLongMessage( text, type ); | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | void | 77 | void | ||
78 | BrowserMessageArea::newProgressOperation( KJob *job, const QString &text, QObject *obj, | 78 | BrowserMessageArea::newProgressOperationImpl( KJob *job, const QString &text, QObject *context, | ||
79 | const char *slot, Qt::ConnectionType type ) | 79 | const std::function<void ()> &function, Qt::ConnectionType type ) | ||
80 | { | 80 | { | ||
81 | KJobProgressBar *newBar = new KJobProgressBar( 0, job ); | 81 | KJobProgressBar *newBar = new KJobProgressBar( 0, job ); | ||
82 | newBar->setDescription( text ); | 82 | newBar->setDescription( text ); | ||
83 | connect( job, &KJob::destroyed, m_progressBar, | 83 | connect( job, &KJob::destroyed, m_progressBar, | ||
84 | &CompoundProgressBar::endProgressOperation ); | 84 | &CompoundProgressBar::endProgressOperation ); | ||
85 | newBar->setAbortSlot( obj, slot, type ); | 85 | newBar->setAbortSlot( context, function, type ); | ||
86 | m_progressBar->addProgressBar( newBar, job ); | 86 | m_progressBar->addProgressBar( newBar, job ); | ||
87 | m_progressBar->show(); | 87 | m_progressBar->show(); | ||
88 | 88 | | |||
89 | m_busy = true; | 89 | m_busy = true; | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | void | 92 | void | ||
93 | BrowserMessageArea::newProgressOperation( QNetworkReply *reply, const QString &text, QObject *obj, | 93 | BrowserMessageArea::newProgressOperationImpl( QNetworkReply *reply, const QString &text, QObject *obj, | ||
94 | const char *slot, Qt::ConnectionType type ) | 94 | const std::function<void ()> &function, Qt::ConnectionType type ) | ||
95 | { | 95 | { | ||
96 | NetworkProgressBar *newBar = new NetworkProgressBar( 0, reply ); | 96 | NetworkProgressBar *newBar = new NetworkProgressBar( 0, reply ); | ||
97 | newBar->setDescription( text ); | 97 | newBar->setDescription( text ); | ||
98 | newBar->setAbortSlot( reply, &QNetworkReply::deleteLater ); | 98 | newBar->setAbortSlot( reply, &QNetworkReply::deleteLater ); | ||
99 | connect( reply, &QNetworkReply::destroyed, m_progressBar, | 99 | connect( reply, &QNetworkReply::destroyed, m_progressBar, | ||
100 | &CompoundProgressBar::endProgressOperation ); | 100 | &CompoundProgressBar::endProgressOperation ); | ||
101 | newBar->setAbortSlot( obj, slot, type ); | 101 | newBar->setAbortSlot( obj, function, type ); | ||
102 | m_progressBar->addProgressBar( newBar, reply ); | 102 | m_progressBar->addProgressBar( newBar, reply ); | ||
103 | m_progressBar->show(); | 103 | m_progressBar->show(); | ||
104 | 104 | | |||
105 | m_busy = true; | 105 | m_busy = true; | ||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | void | 108 | void | ||
109 | BrowserMessageArea::newProgressOperation( QObject *sender, const QString &text, int maximum, | 109 | BrowserMessageArea::newProgressOperationImpl( QObject *sender, const QMetaMethod &increment, const QMetaMethod &end, const QString &text, | ||
110 | QObject *obj, const char *slot, Qt::ConnectionType type ) | 110 | int maximum, QObject *obj, const std::function<void ()> &function, Qt::ConnectionType type ) | ||
111 | { | 111 | { | ||
112 | ProgressBar *newBar = new ProgressBar( 0 ); | 112 | ProgressBar *newBar = new ProgressBar( 0 ); | ||
113 | newBar->setDescription( text ); | 113 | newBar->setDescription( text ); | ||
114 | newBar->setMaximum( maximum ); | 114 | newBar->setMaximum( maximum ); | ||
115 | connect( sender, &QObject::destroyed, m_progressBar, | 115 | connect( sender, &QObject::destroyed, m_progressBar, | ||
116 | &CompoundProgressBar::endProgressOperation, Qt::QueuedConnection ); | 116 | &CompoundProgressBar::endProgressOperation, Qt::QueuedConnection ); | ||
117 | connect( sender, SIGNAL(endProgressOperation(QObject*)), m_progressBar, | 117 | int endIndex = m_progressBar->staticMetaObject.indexOfMethod( SLOT(endProgressOperation(QObject*)) ); | ||
118 | SLOT(endProgressOperation(QObject*)), Qt::QueuedConnection ); | 118 | auto endSlot = m_progressBar->staticMetaObject.method( endIndex ); | ||
119 | connect( sender, SIGNAL(incrementProgress()), m_progressBar, | 119 | connect( sender, end, m_progressBar, | ||
120 | SLOT(slotIncrementProgress()), Qt::QueuedConnection ); | 120 | endSlot, Qt::QueuedConnection ); | ||
121 | int incrementIndex = m_progressBar->staticMetaObject.indexOfMethod( SLOT(slotIncrementProgress()) ); | ||||
122 | auto incrementSlot = m_progressBar->staticMetaObject.method( incrementIndex ); | ||||
123 | connect( sender, increment, m_progressBar, | ||||
124 | incrementSlot, Qt::QueuedConnection ); | ||||
125 | if( sender->staticMetaObject.indexOfSignal( SIGNAL(totalSteps(int)) ) != -1 ) | ||||
121 | connect( sender, SIGNAL(totalSteps(int)), newBar, SLOT(slotTotalSteps(int)) ); | 126 | connect( sender, SIGNAL(totalSteps(int)), newBar, SLOT(slotTotalSteps(int)) ); | ||
122 | newBar->setAbortSlot( obj, slot, type ); | 127 | newBar->setAbortSlot( obj, function, type ); | ||
123 | m_progressBar->addProgressBar( newBar, sender ); | 128 | m_progressBar->addProgressBar( newBar, sender ); | ||
124 | m_progressBar->show(); | 129 | m_progressBar->show(); | ||
125 | 130 | | |||
126 | m_busy = true; | 131 | m_busy = true; | ||
127 | } | 132 | } | ||
128 | 133 | | |||
129 | void | 134 | void | ||
130 | BrowserMessageArea::hideProgress() //SLOT | 135 | BrowserMessageArea::hideProgress() //SLOT | ||
Show All 17 Lines | 145 | { | |||
148 | else | 153 | else | ||
149 | { | 154 | { | ||
150 | m_messageLabel->hide(); | 155 | m_messageLabel->hide(); | ||
151 | m_busy = false; | 156 | m_busy = false; | ||
152 | } | 157 | } | ||
153 | } | 158 | } | ||
154 | 159 | | |||
155 | void | 160 | void | ||
156 | BrowserMessageArea::hideLongMessage() | | |||
157 | { | | |||
158 | sender()->deleteLater(); | | |||
159 | } | | |||
160 | | ||||
161 | void | | |||
162 | BrowserMessageArea::slotLongMessage( const QString &text, MessageType type ) | 161 | BrowserMessageArea::slotLongMessage( const QString &text, MessageType type ) | ||
163 | { | 162 | { | ||
164 | LongMessageWidget *message = new LongMessageWidget( this, text, type ); | 163 | Q_UNUSED(type) | ||
165 | connect( message, &LongMessageWidget::closed, this, &BrowserMessageArea::hideLongMessage ); | 164 | | ||
165 | LongMessageWidget *message = new LongMessageWidget( text ); | ||||
166 | connect( message, &LongMessageWidget::closed, message, &QObject::deleteLater ); | ||||
166 | } | 167 | } |