Fixed some network manager bug, refactoring of feed model.
This commit is contained in:
parent
f131be94b9
commit
39666e7bae
8 changed files with 27 additions and 28 deletions
|
@ -16,12 +16,12 @@
|
|||
|
||||
Added:
|
||||
<ul>
|
||||
<li></li>
|
||||
<li style="color: red;">Brand new "service plugin system" - HIGHLY EXPERIMENTAL and REWRITTEN from scratch. Some UI features (for example drag-drop) are temporarily unavailable. Expect bugs and misunderstandings now!</li>
|
||||
</ul>
|
||||
|
||||
Fixed:
|
||||
<ul>
|
||||
<li></li>
|
||||
<li>When removing download item from download manager via DELETE key, then "Cleanup" button is correctly disabled.</li>
|
||||
</ul>
|
||||
|
||||
<hr/>
|
||||
|
|
|
@ -231,30 +231,22 @@ bool FeedsModel::removeItem(const QModelIndex &index) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void FeedsModel::assignNodeToNewParent(RootItem *item, RootItem *new_parent) {
|
||||
QModelIndex parent_index = indexForItem(new_parent);
|
||||
int new_index_of_item = new_parent->childCount();
|
||||
|
||||
// TODO: sloučit do funkce reassignNodeToNewParent.
|
||||
|
||||
beginInsertRows(parent_index, new_index_of_item, new_index_of_item);
|
||||
new_parent->appendChild(item);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void FeedsModel::reassignNodeToNewParent(RootItem *original_node, RootItem *new_parent) {
|
||||
RootItem *original_parent = original_node->parent();
|
||||
|
||||
if (original_parent != new_parent) {
|
||||
// User edited item and set it new parent item,
|
||||
// se we need to move the item in the model too.
|
||||
int original_index_of_item = original_parent->childItems().indexOf(original_node);
|
||||
int new_index_of_item = new_parent->childCount();
|
||||
if (original_parent != NULL) {
|
||||
int original_index_of_item = original_parent->childItems().indexOf(original_node);
|
||||
|
||||
// Remove the original item from the model...
|
||||
beginRemoveRows(indexForItem(original_parent), original_index_of_item, original_index_of_item);
|
||||
original_parent->removeChild(original_node);
|
||||
endRemoveRows();
|
||||
if (original_index_of_item >= 0) {
|
||||
// Remove the original item from the model...
|
||||
beginRemoveRows(indexForItem(original_parent), original_index_of_item, original_index_of_item);
|
||||
original_parent->removeChild(original_node);
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
|
||||
int new_index_of_item = new_parent->childCount();
|
||||
|
||||
// ... and insert it under the new parent.
|
||||
beginInsertRows(indexForItem(new_parent), new_index_of_item, new_index_of_item);
|
||||
|
|
|
@ -63,9 +63,6 @@ class FeedsModel : public QAbstractItemModel {
|
|||
// NOTE: Also deletes item from memory.
|
||||
bool removeItem(const QModelIndex &index);
|
||||
|
||||
// Assigns item to the new parent.
|
||||
void assignNodeToNewParent(RootItem *item, RootItem *new_parent);
|
||||
|
||||
// Checks if new parent node is different from one used by original node.
|
||||
// If it is, then it reassigns original_node to new parent.
|
||||
void reassignNodeToNewParent(RootItem *original_node, RootItem *new_parent);
|
||||
|
|
|
@ -559,6 +559,10 @@ QNetworkAccessManager *DownloadManager::networkManager() const {
|
|||
return m_networkManager;
|
||||
}
|
||||
|
||||
int DownloadManager::totalDownloads() const {
|
||||
return m_downloads.size();
|
||||
}
|
||||
|
||||
void DownloadManager::itemFinished() {
|
||||
emit downloadFinished();
|
||||
}
|
||||
|
@ -789,6 +793,11 @@ bool DownloadModel::removeRows(int row, int count, const QModelIndex &parent) {
|
|||
}
|
||||
|
||||
m_downloadManager->m_autoSaver->changeOccurred();
|
||||
|
||||
if (m_downloadManager->totalDownloads() == 0) {
|
||||
m_downloadManager->m_ui->m_btnCleanup->setEnabled(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
1
src/network-web/downloadmanager.h
Normal file → Executable file
1
src/network-web/downloadmanager.h
Normal file → Executable file
|
@ -111,6 +111,7 @@ class DownloadManager : public TabContent {
|
|||
WebBrowser *webBrowser();
|
||||
QNetworkAccessManager *networkManager() const;
|
||||
|
||||
int totalDownloads() const;
|
||||
int activeDownloads() const;
|
||||
int downloadProgress() const;
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ void FormStandardCategoryDetails::apply() {
|
|||
if (m_editableCategory == NULL) {
|
||||
// Add the category.
|
||||
if (new_category->addItself(parent)) {
|
||||
m_serviceRoot->feedsModel()->assignNodeToNewParent(new_category, parent);
|
||||
m_serviceRoot->feedsModel()->reassignNodeToNewParent(new_category, parent);
|
||||
accept();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -242,7 +242,7 @@ void FormStandardFeedDetails::apply() {
|
|||
if (m_editableFeed == NULL) {
|
||||
// Add the feed.
|
||||
if (new_feed->addItself(parent)) {
|
||||
m_serviceRoot->feedsModel()->assignNodeToNewParent(new_feed, parent);
|
||||
m_serviceRoot->feedsModel()->reassignNodeToNewParent(new_feed, parent);
|
||||
accept();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -256,7 +256,7 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model,
|
|||
new_category->clearChildren();
|
||||
|
||||
if (new_category->addItself(target_parent)) {
|
||||
m_feedsModel->assignNodeToNewParent(new_category, target_parent);
|
||||
m_feedsModel->reassignNodeToNewParent(new_category, target_parent);
|
||||
|
||||
// Process all children of this category.
|
||||
original_parents.push(new_category);
|
||||
|
@ -290,7 +290,7 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model,
|
|||
|
||||
// Append this feed and end this iteration.
|
||||
if (new_feed->addItself(target_parent)) {
|
||||
m_feedsModel->assignNodeToNewParent(new_feed, target_parent);
|
||||
m_feedsModel->reassignNodeToNewParent(new_feed, target_parent);
|
||||
}
|
||||
else {
|
||||
delete new_feed;
|
||||
|
|
Loading…
Add table
Reference in a new issue