void BasicmLearningEditor::addNewItem(const QString &title, const QString &description) {
  int marked_item = m_ui->m_listItems->currentRow();
  BasicmLearningItem new_item;
  QListWidgetItem *new_item_view = new QListWidgetItem();

  new_item.setTitle(title);
  new_item.setDescription(description);

  new_item_view->setText(new_item.title());
  new_item_view->setData(Qt::UserRole, QVariant::fromValue(new_item));

  if (m_ui->m_listItems->count() == 0) {
    // We are adding first item.
    setEditorsEnabled(true);

    m_ui->m_btnItemRemove->setEnabled(true);

    m_ui->m_listItems->insertItem(0, new_item_view);
    m_ui->m_listItems->setCurrentRow(0);
  }
  else {
    m_ui->m_listItems->insertItem(marked_item + 1, new_item_view);
    m_ui->m_listItems->setCurrentRow(marked_item + 1);
  }

  updateItemCount();
}
void DownloadManager::updateRow()
{
    DownloadItem *item = qobject_cast<DownloadItem*>(sender());
    int row = m_downloads.indexOf(item);
    if (-1 == row)
        return;
    if (!m_iconProvider)
        m_iconProvider = new QFileIconProvider();
    QIcon icon = m_iconProvider->icon(item->m_output.fileName());
    if (icon.isNull())
        icon = style()->standardIcon(QStyle::SP_FileIcon);
    item->fileIcon->setPixmap(icon.pixmap(48, 48));
    downloadsView->setRowHeight(row, item->minimumSizeHint().height());

    bool remove = false;
    QWebSettings *globalSettings = QWebSettings::globalSettings();
    if (!item->downloading()
        && globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled))
    {
        remove = true;
        item->m_must_be_deleted = false;
    }

    if (item->downloadedSuccessfully()
        && removePolicy() == DownloadManager::SuccessFullDownload) {
        remove = true;
    }
    if (remove || item->m_to_delete)
        m_model->removeRow(row);

    cleanupButton->setEnabled(m_downloads.count() - activeDownloads() > 0);
    openButton->setEnabled(m_downloads.count() > 0);
    updateItemCount();
}
BasicmLearningEditor::BasicmLearningEditor(TemplateCore *core, QWidget *parent)
  : TemplateEditor(core, parent), m_ui(new Ui::BasicmLearningEditor) {
  m_ui->setupUi(this);

  // Set validators.
  QRegExpValidator *author_validator = new QRegExpValidator(this);
  QRegExpValidator *title_validator = new QRegExpValidator(this);

  author_validator->setRegExp(QRegExp(".{,50}"));
  title_validator->setRegExp(QRegExp(".{,100}"));

  m_ui->m_txtAuthor->lineEdit()->setValidator(author_validator);
  m_ui->m_txtName->lineEdit()->setValidator(title_validator);

  // Set tab order.
  QList<QWidget*> tab_order_widgets;
  tab_order_widgets << m_ui->m_txtTitle->lineEdit() << m_ui->m_txtDescription <<
                       m_ui->m_txtAuthor->lineEdit() << m_ui->m_txtName->lineEdit() <<
                       m_ui->m_listItems << m_ui->m_btnItemAdd << m_ui->m_btnItemRemove <<
                       m_ui->m_btnItemUp << m_ui->m_btnItemDown;

  for (int i = 1; i < tab_order_widgets.size(); i++) {
    setTabOrder(tab_order_widgets.at(i - 1), tab_order_widgets.at(i));
  }


  m_ui->m_txtTitle->lineEdit()->setPlaceholderText(tr("Title of the item"));
  m_ui->m_txtNumberOfItems->lineEdit()->setEnabled(false);
  m_ui->m_txtAuthor->lineEdit()->setPlaceholderText(tr("Author of this collection"));
  m_ui->m_txtName->lineEdit()->setPlaceholderText(tr("Name of this collection"));

  IconFactory *factory = IconFactory::instance();

  m_ui->m_btnItemAdd->setIcon(factory->fromTheme("item-add"));
  m_ui->m_btnItemRemove->setIcon(factory->fromTheme("item-remove"));
  m_ui->m_btnItemUp->setIcon(factory->fromTheme("move-up"));
  m_ui->m_btnItemDown->setIcon(factory->fromTheme("move-down"));

  connect(m_ui->m_txtTitle->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(checkTitle(QString)));
  connect(m_ui->m_btnItemAdd, SIGNAL(clicked()), this, SLOT(addNewItem()));
  connect(m_ui->m_btnItemRemove, SIGNAL(clicked()), this, SLOT(removeSelectedItem()));
  connect(m_ui->m_txtDescription, SIGNAL(textChanged()), this, SLOT(saveItem()));
  connect(m_ui->m_txtTitle->lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(saveItem()));
  connect(m_ui->m_listItems, SIGNAL(currentRowChanged(int)), this, SLOT(displayItem(int)));
  connect(m_ui->m_btnItemUp, SIGNAL(clicked()), this, SLOT(moveItemUp()));
  connect(m_ui->m_btnItemDown, SIGNAL(clicked()), this, SLOT(moveItemDown()));
  connect(m_ui->m_txtAuthor->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onAuthorChanged(QString)));
  connect(m_ui->m_txtName->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onNameChanged(QString)));

  checkTitle(m_ui->m_txtTitle->lineEdit()->text());
  checkAuthor();
  checkName();
  setEditorsEnabled(false);
  updateItemCount();
}
void DownloadManager::cleanup()
{
    if (m_downloads.isEmpty())
        return;
    m_model->removeRows(0, m_downloads.count());
    updateItemCount();
    if (m_downloads.isEmpty() && m_iconProvider) {
        delete m_iconProvider;
        m_iconProvider = 0;
    }
    m_autoSaver->changeOccurred();
}
void DownloadManager::cleanup_list()
{
    if (m_downloads.isEmpty())
        return;
    m_model->removeRows(0, m_downloads.count());
    updateItemCount();
    if (m_downloads.isEmpty() && m_iconProvider) {
        delete m_iconProvider;
        m_iconProvider = 0;
    }
    save();
}
Beispiel #6
0
void DownloadManager::addItem(DownloadItem *item)
{
    connect(item, SIGNAL(statusChanged()), this, SLOT(updateRow()));
    int row = m_downloads.count();
    m_model->beginInsertRows(QModelIndex(), row, row);
    m_downloads.append(item);
    m_model->endInsertRows();
    updateItemCount();
    downloadsView->setIndexWidget(m_model->index(row, 0), item);
    QIcon icon = style()->standardIcon(QStyle::SP_FileIcon);
    item->fileIcon->setPixmap(icon.pixmap(48, 48));
    downloadsView->setRowHeight(row, item->sizeHint().height());
    updateRow(item); //incase download finishes before the constructor returns
}
void DownloadManager::addItem(DownloadWidget *widget)
{
    connect(widget, SIGNAL(statusChanged()), this, SLOT(updateRow()));
    int row = m_downloads.count();
    m_model->beginInsertRows(QModelIndex(), row, row);
    m_downloads.append(widget);
    m_model->endInsertRows();
    updateItemCount();
    if (row == 0)
        show();
    downloadsView->setIndexWidget(m_model->index(row, 0), widget);
    QIcon icon = style()->standardIcon(QStyle::SP_FileIcon);
    widget->fileIcon->setPixmap(icon.pixmap(48, 48));
    downloadsView->setRowHeight(row, widget->sizeHint().height());
}
void WBDownloadManager::cleanup()
{
    if (mDownloads.isEmpty())
        return;

    mModel->removeRows(0, mDownloads.count());
    updateItemCount();

    if (mDownloads.isEmpty() && mIconProvider)
    {
        delete mIconProvider;
        mIconProvider = 0;
    }

    mAutoSaver->changeOccurred();
}
void DownloadManager::cleanup_full()
{
    QSettings settings;
    settings.beginGroup(QLatin1String("downloadmanager"));
    bool full_cleanup = settings.value(QLatin1String("full_cleanup"), true).toBool();
    bool first_ask = settings.value(QLatin1String("first_ask"), true).toBool();

    if (first_ask)
    {
        int ret = QMessageBox::question(this, tr("Confirmation"),
                           tr("<b>Do you want to remove downloads history and downloads themselves?</b><br><br>"
                           "Click <b>Yes</b> to clean up downloads and history<br>"
                           "Click <b>No</b> to clean up history but keep downloaded files<br>"
                           "Click <b>Cancel</b> to cancel clean up procedure<br><br>"
                           "Your choice will be stored to settings, and used in future cleanups."
                           ),
                           QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
                           QMessageBox::Yes);
        if (ret == QMessageBox::Cancel)
            return;

        full_cleanup = (ret == QMessageBox::Yes);
        settings.setValue(QLatin1String("full_cleanup"), full_cleanup);
        settings.setValue(QLatin1String("first_ask"), false);
    }
    
    settings.endGroup();

    foreach(DownloadItem *item, m_downloads)
    {
        item->m_must_be_deleted = (full_cleanup);
    }

    if (m_downloads.isEmpty())
        return;

    m_model->removeRows(0, m_downloads.count());
    updateItemCount();
    if (m_downloads.isEmpty() && m_iconProvider) {
        delete m_iconProvider;
        m_iconProvider = 0;
    }
    save();
}
void WBDownloadManager::addItem(WBDownloadItem *item)
{
    connect(item, SIGNAL(statusChanged()), this, SLOT(updateRow()));
    int row = mDownloads.count();
    mModel->beginInsertRows(QModelIndex(), row, row);
    mDownloads.append(item);
    mModel->endInsertRows();
    updateItemCount();

    if (!mIsLoading)
        show();

    downloadsView->setIndexWidget(mModel->index(row, 0), item);

    if (!mIconProvider)
        mIconProvider = new QFileIconProvider();
    QIcon icon = mIconProvider->icon(item->m_output.fileName());
    if (icon.isNull())
        icon = style()->standardIcon(QStyle::SP_FileIcon);
    item->fileIcon->setPixmap(icon.pixmap(48, 48));
    downloadsView->setRowHeight(row, item->sizeHint().height());
}