src/partDownloader.cc

changeset 855
e16f1587ef44
parent 852
cbd89b33f70d
child 861
83426c5fa732
equal deleted inserted replaced
854:403affd33c6e 855:e16f1587ef44
69 69
70 // ============================================================================= 70 // =============================================================================
71 // 71 //
72 PartDownloader::PartDownloader (QWidget* parent) : QDialog (parent) 72 PartDownloader::PartDownloader (QWidget* parent) : QDialog (parent)
73 { 73 {
74 setInterface (new Ui_DownloadFrom); 74 setForm (new Ui_DownloadFrom);
75 interface()->setupUi (this); 75 form()->setupUi (this);
76 interface()->fname->setFocus(); 76 form()->fname->setFocus();
77 interface()->progress->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch); 77
78 #ifdef USE_QT5
79 form()->progress->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch);
80 #else
81 form()->progress->horizontalHeader()->setResizeMode (PartLabelColumn, QHeaderView::Stretch);
82 #endif
78 83
79 setDownloadButton (new QPushButton (tr ("Download"))); 84 setDownloadButton (new QPushButton (tr ("Download")));
80 interface()->buttonBox->addButton (downloadButton(), QDialogButtonBox::ActionRole); 85 form()->buttonBox->addButton (downloadButton(), QDialogButtonBox::ActionRole);
81 getButton (Abort)->setEnabled (false); 86 getButton (Abort)->setEnabled (false);
82 87
83 connect (interface()->source, SIGNAL (currentIndexChanged (int)), 88 connect (form()->source, SIGNAL (currentIndexChanged (int)),
84 this, SLOT (sourceChanged (int))); 89 this, SLOT (sourceChanged (int)));
85 connect (interface()->buttonBox, SIGNAL (clicked (QAbstractButton*)), 90 connect (form()->buttonBox, SIGNAL (clicked (QAbstractButton*)),
86 this, SLOT (buttonClicked (QAbstractButton*))); 91 this, SLOT (buttonClicked (QAbstractButton*)));
87 } 92 }
88 93
89 // ============================================================================= 94 // =============================================================================
90 // 95 //
91 PartDownloader::~PartDownloader() 96 PartDownloader::~PartDownloader()
92 { 97 {
93 delete interface(); 98 delete form();
94 } 99 }
95 100
96 // ============================================================================= 101 // =============================================================================
97 // 102 //
98 QString PartDownloader::getURL() 103 QString PartDownloader::getURL()
101 QString dest; 106 QString dest;
102 107
103 switch (src) 108 switch (src)
104 { 109 {
105 case PartsTracker: 110 case PartsTracker:
106 dest = interface()->fname->text(); 111 dest = form()->fname->text();
107 modifyDestination (dest); 112 modifyDestination (dest);
108 interface()->fname->setText (dest); 113 form()->fname->setText (dest);
109 return g_unofficialLibraryURL + dest; 114 return g_unofficialLibraryURL + dest;
110 115
111 case CustomURL: 116 case CustomURL:
112 return interface()->fname->text(); 117 return form()->fname->text();
113 } 118 }
114 119
115 // Shouldn't happen 120 // Shouldn't happen
116 return ""; 121 return "";
117 } 122 }
181 186
182 // ============================================================================= 187 // =============================================================================
183 // 188 //
184 PartDownloader::Source PartDownloader::getSource() const 189 PartDownloader::Source PartDownloader::getSource() const
185 { 190 {
186 return (Source) interface()->source->currentIndex(); 191 return (Source) form()->source->currentIndex();
187 } 192 }
188 193
189 // ============================================================================= 194 // =============================================================================
190 // 195 //
191 void PartDownloader::sourceChanged (int i) 196 void PartDownloader::sourceChanged (int i)
192 { 197 {
193 if (i == CustomURL) 198 if (i == CustomURL)
194 interface()->fileNameLabel->setText (tr ("URL:")); 199 form()->fileNameLabel->setText (tr ("URL:"));
195 else 200 else
196 interface()->fileNameLabel->setText (tr ("File name:")); 201 form()->fileNameLabel->setText (tr ("File name:"));
197 } 202 }
198 203
199 // ============================================================================= 204 // =============================================================================
200 // 205 //
201 void PartDownloader::buttonClicked (QAbstractButton* btn) 206 void PartDownloader::buttonClicked (QAbstractButton* btn)
211 for (PartDownloadRequest* req : requests()) 216 for (PartDownloadRequest* req : requests())
212 req->abort(); 217 req->abort();
213 } 218 }
214 elif (btn == getButton (Download)) 219 elif (btn == getButton (Download))
215 { 220 {
216 QString dest = interface()->fname->text(); 221 QString dest = form()->fname->text();
217 setPrimaryFile (LDDocumentPtr()); 222 setPrimaryFile (LDDocumentPtr());
218 setAborted (false); 223 setAborted (false);
219 224
220 if (getSource() == CustomURL) 225 if (getSource() == CustomURL)
221 dest = basename (getURL()); 226 dest = basename (getURL());
228 if (not confirm (tr ("Overwrite?"), overwritemsg)) 233 if (not confirm (tr ("Overwrite?"), overwritemsg))
229 return; 234 return;
230 } 235 }
231 236
232 downloadButton()->setEnabled (false); 237 downloadButton()->setEnabled (false);
233 interface()->progress->setEnabled (true); 238 form()->progress->setEnabled (true);
234 interface()->fname->setEnabled (false); 239 form()->fname->setEnabled (false);
235 interface()->source->setEnabled (false); 240 form()->source->setEnabled (false);
236 downloadFile (dest, getURL(), true); 241 downloadFile (dest, getURL(), true);
237 getButton (Close)->setEnabled (false); 242 getButton (Close)->setEnabled (false);
238 getButton (Abort)->setEnabled (true); 243 getButton (Abort)->setEnabled (true);
239 getButton (Download)->setEnabled (false); 244 getButton (Download)->setEnabled (false);
240 } 245 }
242 247
243 // ============================================================================= 248 // =============================================================================
244 // 249 //
245 void PartDownloader::downloadFile (QString dest, QString url, bool primary) 250 void PartDownloader::downloadFile (QString dest, QString url, bool primary)
246 { 251 {
247 const int row = interface()->progress->rowCount(); 252 const int row = form()->progress->rowCount();
248 253
249 // Don't download files repeadetly. 254 // Don't download files repeadetly.
250 if (filesToDownload().indexOf (dest) != -1) 255 if (filesToDownload().indexOf (dest) != -1)
251 return; 256 return;
252 257
253 modifyDestination (dest); 258 modifyDestination (dest);
254 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this); 259 PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this);
255 m_filesToDownload << dest; 260 m_filesToDownload << dest;
256 m_requests << req; 261 m_requests << req;
257 interface()->progress->insertRow (row); 262 form()->progress->insertRow (row);
258 req->setTableRow (row); 263 req->setTableRow (row);
259 req->updateToTable(); 264 req->updateToTable();
260 } 265 }
261 266
262 // ============================================================================= 267 // =============================================================================
310 { 315 {
311 case Download: 316 case Download:
312 return downloadButton(); 317 return downloadButton();
313 318
314 case Abort: 319 case Abort:
315 return qobject_cast<QPushButton*> (interface()->buttonBox->button (QDialogButtonBox::Abort)); 320 return qobject_cast<QPushButton*> (form()->buttonBox->button (QDialogButtonBox::Abort));
316 321
317 case Close: 322 case Close:
318 return qobject_cast<QPushButton*> (interface()->buttonBox->button (QDialogButtonBox::Close)); 323 return qobject_cast<QPushButton*> (form()->buttonBox->button (QDialogButtonBox::Close));
319 } 324 }
320 325
321 return null; 326 return null;
322 } 327 }
323 328
363 // 368 //
364 void PartDownloadRequest::updateToTable() 369 void PartDownloadRequest::updateToTable()
365 { 370 {
366 int const labelcol = PartDownloader::PartLabelColumn; 371 int const labelcol = PartDownloader::PartLabelColumn;
367 int const progcol = PartDownloader::ProgressColumn; 372 int const progcol = PartDownloader::ProgressColumn;
368 QTableWidget* table = prompt()->interface()->progress; 373 QTableWidget* table = prompt()->form()->progress;
369 QProgressBar* prog; 374 QProgressBar* prog;
370 375
371 switch (state()) 376 switch (state())
372 { 377 {
373 case DLRQ_Requesting: 378 case DLRQ_Requesting:

mercurial