void BtInstallModuleChooserDialog::showEvent(QShowEvent *event) {
    Q_UNUSED(event);

    if (m_shown) return;
    bookshelfWidget()->treeView()->expandAll();
    bookshelfWidget()->treeView()->header()->resizeSections(QHeaderView::ResizeToContents);
    m_shown = true;
}
BtInstallModuleChooserDialog::BtInstallModuleChooserDialog(const BtBookshelfTreeModel::Grouping &g,
                                                           QWidget *parent,
                                                           Qt::WindowFlags flags)
    : BtModuleChooserDialog(parent, flags), m_shown(false)
{
    resize(550, 340);

    // Read grouping order from settings or the default from argument:
    BtBookshelfTreeModel::Grouping groupingOrder(false);
    if (!groupingOrder.loadFrom(groupingOrderKey)) {
        groupingOrder = g;
    }

    BtInstallModuleChooserDialogModel *treeModel;
    treeModel = new BtInstallModuleChooserDialogModel(groupingOrder, this);
    connect(treeModel, SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
            this,      SLOT(slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping&)));

    m_bookshelfModel = new BtBookshelfModel(this);
    bookshelfWidget()->postFilterModel()->setShowShown(true);
    bookshelfWidget()->setTreeModel(treeModel);
    bookshelfWidget()->setSourceModel(m_bookshelfModel);
    bookshelfWidget()->showHideAction()->setVisible(false);
    bookshelfWidget()->showHideButton()->hide();
    bookshelfWidget()->treeView()->header()->show();

    retranslateUi();
}
BtSearchModuleChooserDialog::BtSearchModuleChooserDialog(QWidget *parent,
                                                         Qt::WindowFlags flags)
    : BtModuleChooserDialog(parent, flags)
{
    // Initialize the tree model:
    BtBookshelfTreeModel::Grouping grouping(groupingOrderKey);
    BtBookshelfTreeModel *treeModel = new BtBookshelfTreeModel(grouping, this);
    treeModel->setCheckable(true);
    BT_CONNECT(treeModel,
               SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
               this,
               SLOT(slotGroupingOrderChanged(
                            BtBookshelfTreeModel::Grouping const &)));

    // Initialize the bookshelf widget:
    bookshelfWidget()->showHideAction()->setVisible(false);
    bookshelfWidget()->showHideButton()->hide();
    bookshelfWidget()->setTreeModel(treeModel);
    bookshelfWidget()->setSourceModel(CSwordBackend::instance()->model());

    retranslateUi();
}