Skip to content

Commit

Permalink
Finishing up Launchpad support
Browse files Browse the repository at this point in the history
Fixing bugs
  • Loading branch information
Matt Barringer committed Mar 20, 2011
1 parent 6b590ae commit cecc020
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 93 deletions.
106 changes: 75 additions & 31 deletions MainWindow.cpp
Expand Up @@ -83,6 +83,7 @@ MainWindow::MainWindow(QWidget *parent) :
// mSyncRequests tracks how many sync requests have been made
// in order to know when to re-enable the widgets
mSyncRequests = 0;
mUploading = false;
QSettings settings("Entomologist");

// Resize the splitters, otherwise they'll be 50/50
Expand Down Expand Up @@ -197,6 +198,8 @@ MainWindow::MainWindow(QWidget *parent) :
setupDB();
toggleButtons();
loadTrackers();
if (settings.value("startup-sync", false).toBool() == true)
syncNextTracker();
}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -538,6 +541,11 @@ MainWindow::loadDetails(long long id)
mActiveStatus.remove(QRegExp("<[^>]*>"));
ui->statusCombo->setCurrentIndex(ui->statusCombo->findText(mActiveStatus));

QString bugDetailsLabel = QString("%1 #%2 - %3")
.arg(r.value(2).toString())
.arg(r.value(3).toString())
.arg(r.value(9).toString());
ui->bugDetailsLabel->setText(bugDetailsLabel);
if ((pActiveBackend->autoCacheComments() == "0") && (isOnline()))
{
mSyncRequests++;
Expand Down Expand Up @@ -727,6 +735,7 @@ void
MainWindow::setupTracker(Backend *newBug, QMap<QString, QString> info)
{
qDebug() << "Setup tracker";
bool autosync = false;
newBug->setId(info["id"]);
newBug->setName(info["name"]);
newBug->setUsername(info["username"]);
Expand All @@ -749,16 +758,17 @@ MainWindow::setupTracker(Backend *newBug, QMap<QString, QString> info)
info["auto_cache_comments"] = newBug->autoCacheComments();
int tracker = insertTracker(info);
newBug->setId(QString("%1").arg(tracker));
mSyncPosition = mBackendList.size() + 1;
autosync = true;
}


addTrackerToList(newBug);
addTrackerToList(newBug, autosync);
}

// Adds a tracker to the tracker list on the left
// side of the screen
void
MainWindow::addTrackerToList(Backend *newTracker)
MainWindow::addTrackerToList(Backend *newTracker, bool sync)
{
qDebug() << "Adding tracker to list";
QListWidgetItem *newItem = new QListWidgetItem(newTracker->name());
Expand All @@ -771,10 +781,11 @@ MainWindow::addTrackerToList(Backend *newTracker)
iconPath.append(QDir::separator()).append("entomologist");
iconPath.append(QDir::separator()).append(QString("%1.png").arg(newTracker->name()));
mBackendMap[newTracker->id()] = newTracker;

syncTracker(newTracker);
mBackendList.append(newTracker);
if(!QFile::exists(iconPath))
fetchIcon(newTracker->url(), iconPath);
if (sync)
syncTracker(newTracker);
}

// When the user clicks the sort header in the bug view, this
Expand Down Expand Up @@ -831,9 +842,17 @@ MainWindow::bugsUpdated()
mSyncRequests--;
if (mSyncRequests == 0)
{
filterTable();
stopAnimation();
notifyUser();
if (mSyncPosition == mBackendList.size())
{
filterTable();
mUploading = false;
stopAnimation();
notifyUser();
}
else
{
syncNextTracker();
}
}
}

Expand Down Expand Up @@ -924,7 +943,7 @@ MainWindow::fetchIcon(const QString &url,
{
QUrl u(url);
QString fetch = "http://" + u.host() + "/favicon.ico";
qDebug() << "Fetching " << fetch;
qDebug() << "fetchIcon: " << fetch;

QNetworkRequest req = QNetworkRequest(QUrl(fetch));
req.setAttribute(QNetworkRequest::User, QVariant(savePath));
Expand All @@ -946,13 +965,15 @@ MainWindow::iconDownloaded()

if (!redirect.toUrl().isEmpty() && !wasRedirected)
{
reply->deleteLater();
QNetworkRequest req = QNetworkRequest(redirect.toUrl());
req.setAttribute(QNetworkRequest::User, QVariant(savePath));
req.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User+1), QVariant(1));
QNetworkReply *rep = pManager->get(req);
connect(rep, SIGNAL(finished()),
this, SLOT(iconDownloaded()));
qDebug() << "Was redirected to " << redirect.toUrl();
reply->deleteLater();
QNetworkRequest req = QNetworkRequest(redirect.toUrl());
req.setAttribute(QNetworkRequest::User, QVariant(savePath));
req.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User+1), QVariant(1));
QNetworkReply *rep = pManager->get(req);
connect(rep, SIGNAL(finished()),
this, SLOT(iconDownloaded()));
return;
}

qDebug() << "Icon downloaded";
Expand Down Expand Up @@ -981,8 +1002,18 @@ MainWindow::iconDownloaded()

reader.setScaledSize(iconSize);
const QImage icon = reader.read();
icon.save(savePath, "PNG");
if (icon.format() == QImage::Format_Invalid)
fetchHTMLIcon(reply->url().toString(), savePath);
else
icon.save(savePath, "PNG");
}
else
{
qDebug() << "Invalid image";
fetchHTMLIcon(reply->url().toString(), savePath);
}

logoBuffer.close();
reply->close();
}

Expand Down Expand Up @@ -1165,11 +1196,24 @@ MainWindow::resync()
return;
}

QMapIterator<QString, Backend *> i(mBackendMap);
while (i.hasNext())
mSyncPosition = 0;
syncNextTracker();
}

void
MainWindow::syncNextTracker()
{
Backend *b = mBackendList.at(mSyncPosition);
ui->syncingLabel->setText(QString("Syncing %1...").arg(b->name()));
mSyncPosition++;
if (mUploading)
{
i.next();
syncTracker(i.value());
mSyncRequests++;
b->uploadAll();
}
else
{
syncTracker(b);
}
}

Expand Down Expand Up @@ -1202,15 +1246,10 @@ MainWindow::upload()
if (reallyUpload)
{
startAnimation();
QMapIterator<QString, Backend *> i(mBackendMap);
while (i.hasNext())
{
i.next();
mSyncRequests++;
i.value()->uploadAll();
}
mUploading = true;
mSyncPosition = 0;
syncNextTracker();
}

}

// Build up a changelog for the changelog dialog box
Expand Down Expand Up @@ -1642,6 +1681,7 @@ MainWindow::customContextMenuRequested(const QPoint &pos)
QMenu contextMenu(tr("Context menu"), this);
QAction *editAction = contextMenu.addAction(tr("Edit"));
QAction *deleteAction = contextMenu.addAction(tr("Delete"));
QAction *resyncAction = contextMenu.addAction(tr("Resync"));
QAction *a = contextMenu.exec(QCursor::pos());
Backend *b = mBackendMap[id];

Expand All @@ -1666,6 +1706,11 @@ MainWindow::customContextMenuRequested(const QPoint &pos)
deleteTracker(id);
}
}
else if (a == resyncAction)
{
mSyncPosition = mBackendList.size();
syncTracker(b);
}
// Reset any list selection
ui->trackerList->setCurrentItem(NULL);
}
Expand Down Expand Up @@ -1720,9 +1765,8 @@ void
MainWindow::searchTriggered()
{
QString searchText = ui->searchEdit->text();
if (searchText.isEmpty()) return;

QStringList query;

// Summary
query << QString("(bugs.summary LIKE \'\%%1\%\')").arg(searchText);
// Comment
Expand Down
6 changes: 5 additions & 1 deletion MainWindow.h
Expand Up @@ -109,7 +109,7 @@ public slots:
void loadTrackers();
void loadComments();
void addTracker(QMap<QString, QString> info);
void addTrackerToList(Backend *newTracker);
void addTrackerToList(Backend *newTracker, bool sync = false);
void fetchIcon(const QString &url, const QString &savePath);
void fetchHTMLIcon(const QString &url, const QString &savePath);
bool isOnline();
Expand All @@ -123,9 +123,13 @@ public slots:
int insertTracker(QMap<QString, QString> tracker);
QString getChangelog();
QString autodetectTracker(const QString &url);
void syncNextTracker();

int mSyncRequests;
int mSyncPosition;
bool mUploading;
QMap<QString, Backend*> mBackendMap;
QList<Backend *> mBackendList;
QString mDbPath;
Backend *pActiveBackend;
QString mActiveBugId, mActivePriority, mActiveStatus, mActiveSeverity;
Expand Down
41 changes: 36 additions & 5 deletions MainWindow.ui
Expand Up @@ -207,8 +207,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>623</width>
<height>207</height>
<width>633</width>
<height>198</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down Expand Up @@ -313,11 +313,42 @@
<rect>
<x>0</x>
<y>0</y>
<width>603</width>
<height>165</height>
<width>609</width>
<height>163</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="bugDetailsLabel">
<property name="font">
<font>
<pointsize>15</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
Expand Down Expand Up @@ -418,7 +449,7 @@
<x>0</x>
<y>0</y>
<width>641</width>
<height>28</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuShow">
Expand Down
3 changes: 3 additions & 0 deletions Preferences.cpp
Expand Up @@ -35,6 +35,7 @@ Preferences::Preferences(QWidget *parent) :
ui->autoUpdateSpinBox->setValue(settings.value("update-interval", "2").toInt());
ui->autoUpdateCheckBox->setChecked(settings.value("update-automatically", false).toBool());
ui->confirmationCheckBox->setChecked(settings.value("no-upload-confirmation", "false").toBool());
ui->startupSyncCheckbox->setChecked(settings.value("startup-sync", false).toBool());
if (!ui->autoUpdateCheckBox->isChecked())
ui->autoUpdateSpinBox->setEnabled(false);

Expand Down Expand Up @@ -68,6 +69,8 @@ Preferences::accepted()
settings.setValue("update-interval", ui->autoUpdateSpinBox->value());
settings.setValue("update-automatically", ui->autoUpdateCheckBox->isChecked());
settings.setValue("no-upload-confirmation", ui->confirmationCheckBox->isChecked());
settings.setValue("startup-sync", ui->startupSyncCheckbox->isChecked());

close();
}

Expand Down
9 changes: 8 additions & 1 deletion Preferences.ui
Expand Up @@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>90</height>
<height>132</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -73,6 +73,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="startupSyncCheckbox">
<property name="text">
<string>Sync trackers on startup</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down
2 changes: 2 additions & 0 deletions SqlWriter.cpp
Expand Up @@ -122,13 +122,15 @@ SqlWriter::insertBugs(QList<QMap<QString, QString> > bugList)

if (!error)
{
qDebug() << "Emitting bugsFinished";
mDatabase.commit();
emit bugsFinished(idList);
}
else
{
mDatabase.rollback();
}

}

void
Expand Down

0 comments on commit cecc020

Please sign in to comment.