2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "groups.hh"
|
2009-05-18 18:01:50 +00:00
|
|
|
#include "instances.hh"
|
2009-01-28 20:55:45 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
Groups::Groups( QWidget * parent,
|
|
|
|
vector< sptr< Dictionary::Class > > const & dicts_,
|
2009-05-18 18:01:50 +00:00
|
|
|
Config::Groups const & groups_,
|
|
|
|
Config::Group const & order ): QWidget( parent ),
|
2009-01-28 20:55:45 +00:00
|
|
|
dicts( dicts_ ), groups( groups_ )
|
|
|
|
{
|
|
|
|
ui.setupUi( this );
|
|
|
|
|
|
|
|
// Populate the dictionaries' list
|
|
|
|
|
|
|
|
ui.dictionaries->setAsSource();
|
2009-05-18 18:01:50 +00:00
|
|
|
ui.dictionaries->populate( Instances::Group( order, dicts ).dictionaries,
|
|
|
|
dicts );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
// Populate groups' widget
|
|
|
|
|
|
|
|
ui.groups->populate( groups, dicts );
|
|
|
|
|
|
|
|
connect( ui.addGroup, SIGNAL( clicked() ),
|
|
|
|
this, SLOT( addNew() ) );
|
|
|
|
connect( ui.renameGroup, SIGNAL( clicked() ),
|
|
|
|
this, SLOT( renameCurrent() ) );
|
|
|
|
connect( ui.removeGroup, SIGNAL( clicked() ),
|
|
|
|
this, SLOT( removeCurrent() ) );
|
2009-04-29 23:32:42 +00:00
|
|
|
connect( ui.removeAllGroups, SIGNAL( clicked() ),
|
|
|
|
this, SLOT( removeAll() ) );
|
2009-05-02 17:12:52 +00:00
|
|
|
connect( ui.addDictsToGroup, SIGNAL( clicked() ),
|
|
|
|
this, SLOT( addToGroup() ) );
|
2009-07-31 11:40:54 +00:00
|
|
|
connect( ui.dictionaries, SIGNAL( doubleClicked(const QModelIndex &) ),
|
|
|
|
this, SLOT( addToGroup() ) );
|
2009-05-02 17:12:52 +00:00
|
|
|
connect( ui.removeDictsFromGroup, SIGNAL( clicked() ),
|
|
|
|
this, SLOT( removeFromGroup() ) );
|
2010-09-16 18:50:31 +00:00
|
|
|
connect( ui.autoGroups, SIGNAL( clicked() ),
|
|
|
|
this, SLOT( addAutoGroups() ) );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
countChanged();
|
|
|
|
}
|
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
void Groups::editGroup( unsigned id )
|
|
|
|
{
|
|
|
|
for( unsigned x = 0; x < groups.size(); ++x )
|
|
|
|
{
|
|
|
|
if ( groups[ x ].id == id )
|
|
|
|
{
|
|
|
|
ui.groups->setCurrentIndex( x );
|
|
|
|
ui.groups->currentWidget()->setFocus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 18:01:50 +00:00
|
|
|
void Groups::updateDictionaryOrder( Config::Group const & order )
|
|
|
|
{
|
|
|
|
// Make sure it differs from what we have
|
|
|
|
|
|
|
|
Instances::Group newOrder( order, dicts );
|
|
|
|
|
|
|
|
if ( ui.dictionaries->getCurrentDictionaries() != newOrder.dictionaries )
|
|
|
|
{
|
|
|
|
// Repopulate
|
|
|
|
ui.dictionaries->populate( Instances::Group( order, dicts ).dictionaries,
|
|
|
|
dicts );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
Config::Groups Groups::getGroups() const
|
|
|
|
{
|
|
|
|
return ui.groups->makeGroups();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Groups::countChanged()
|
|
|
|
{
|
|
|
|
bool en = ui.groups->count();
|
|
|
|
|
|
|
|
ui.renameGroup->setEnabled( en );
|
|
|
|
ui.removeGroup->setEnabled( en );
|
2009-04-29 23:32:42 +00:00
|
|
|
ui.removeAllGroups->setEnabled( en );
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Groups::addNew()
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
|
|
|
|
QString name = QInputDialog::getText( this, tr( "Add group" ),
|
|
|
|
tr("Give a name for the new group:"), QLineEdit::Normal,
|
|
|
|
"", &ok );
|
|
|
|
|
|
|
|
if ( ok )
|
|
|
|
{
|
|
|
|
ui.groups->addNewGroup( name );
|
|
|
|
countChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-16 18:50:31 +00:00
|
|
|
void Groups::addAutoGroups()
|
|
|
|
{
|
|
|
|
ui.groups->addAutoGroups();
|
|
|
|
countChanged();
|
|
|
|
}
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void Groups::renameCurrent()
|
|
|
|
{
|
|
|
|
int current = ui.groups->currentIndex();
|
|
|
|
|
|
|
|
if ( current < 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
|
|
|
|
QString name = QInputDialog::getText( this, tr("Rename group"),
|
|
|
|
tr("Give a new name for the group:"), QLineEdit::Normal,
|
2009-04-10 21:37:16 +00:00
|
|
|
ui.groups->getCurrentGroupName(), &ok );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
if ( ok )
|
|
|
|
ui.groups->renameCurrentGroup( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Groups::removeCurrent()
|
|
|
|
{
|
|
|
|
int current = ui.groups->currentIndex();
|
|
|
|
|
|
|
|
if ( current >= 0 && QMessageBox::question( this, tr( "Remove group" ),
|
2009-04-10 21:37:16 +00:00
|
|
|
tr( "Are you sure you want to remove the group <b>%1</b>?" ).arg( ui.groups->getCurrentGroupName() ),
|
2009-01-28 20:55:45 +00:00
|
|
|
QMessageBox::Yes, QMessageBox::Cancel ) == QMessageBox::Yes )
|
|
|
|
{
|
|
|
|
ui.groups->removeCurrentGroup();
|
|
|
|
countChanged();
|
|
|
|
}
|
|
|
|
}
|
2009-04-29 23:32:42 +00:00
|
|
|
|
|
|
|
void Groups::removeAll()
|
|
|
|
{
|
|
|
|
int current = ui.groups->currentIndex();
|
|
|
|
|
|
|
|
if ( current >= 0 && QMessageBox::question( this, tr( "Remove all groups" ),
|
|
|
|
tr( "Are you sure you want to remove all the groups?" ),
|
|
|
|
QMessageBox::Yes, QMessageBox::Cancel ) == QMessageBox::Yes )
|
|
|
|
{
|
|
|
|
ui.groups->removeAllGroups();
|
|
|
|
countChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-02 17:12:52 +00:00
|
|
|
void Groups::addToGroup()
|
|
|
|
{
|
|
|
|
int current = ui.groups->currentIndex();
|
|
|
|
|
|
|
|
if ( current >= 0 )
|
|
|
|
{
|
|
|
|
ui.groups->getCurrentModel()->addSelectedUniqueFromModel( ui.dictionaries->selectionModel() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Groups::removeFromGroup()
|
|
|
|
{
|
|
|
|
int current = ui.groups->currentIndex();
|
|
|
|
|
|
|
|
if ( current >= 0 )
|
|
|
|
{
|
|
|
|
ui.groups->getCurrentModel()->removeSelectedRows( ui.groups->getCurrentSelectionModel() );
|
|
|
|
}
|
|
|
|
}
|