Esempio n. 1
0
bool BooksDB::loadBooks(BookList &books) {
	AppLog(" BooksDB::loadBooks(BookList &books)");
	shared_ptr<DBDataReader> reader = myLoadBooks->executeReader();

	books.clear();
	std::map<int,shared_ptr<Book> > bookMap;

	while (reader->next()) {
		if (reader->type(0) != DBValue::DBINT || /* book_id */
				reader->type(4) != DBValue::DBINT) { /* file_id */
			return false;
		}
		const int bookId = reader->intValue(0);
		const int fileId = reader->intValue(4);
		const std::string fileName = getFileName(fileId);

		shared_ptr<Book> book = Book::createBook(
			ZLFile(fileName),
			bookId,
			reader->textValue(1, Book::AutoEncoding),
			reader->textValue(2, ZLLanguageUtil::OtherLanguageCode),
			reader->textValue(3, std::string())
		);
		books.push_back(book);
		bookMap[bookId] = book;
	}

	loadSeries(bookMap);
	AppLog("loadSeries(bookMap);");
	loadAuthors(bookMap);
	AppLog("loadAuthors(bookMap);");
	loadTags(bookMap);
	AppLog("loadTags(bookMap);");
	return true;
}
Esempio n. 2
0
shared_ptr<Book> BooksDB::loadBook(const std::string &fileName) {
	AppLog(" BooksDB::loadBook(const std::string &fileName)");
	if (!isInitialized()) {
		return 0;
	}

	myFindFileId->setFileName(fileName);
	if (!myFindFileId->run()) {
		return false;
	}
	((DBIntValue&)*myLoadBook->parameter("@file_id").value()) = myFindFileId->fileId();
	shared_ptr<DBDataReader> reader = myLoadBook->executeReader();

	if (reader.isNull() || !reader->next() ||
			reader->type(0) != DBValue::DBINT /* book_id */) {
		return 0;
	}
	const int bookId = reader->intValue(0);

	shared_ptr<Book> book = Book::createBook(
		ZLFile(fileName), bookId,
		reader->textValue(1, Book::AutoEncoding),
		reader->textValue(2, ZLLanguageUtil::OtherLanguageCode),
		reader->textValue(3, std::string())
	);

	loadSeries(*book);
	AppLog("loadSeries(*book);");
	loadAuthors(*book);
	AppLog("loadSeries(*book);");
	loadTags(*book);
	AppLog("loadSeries(*book);");

	return book;
}
Esempio n. 3
0
SelectAuthorsDialog::SelectAuthorsDialog( QWidget *parent, const ElementList &currentAuthors, RecipeDB *db )
		: KDialog(parent ),
		database(db)
{
	setCaption(i18nc("@title:window", "Authors" ));
	setButtons(KDialog::Ok | KDialog::Cancel);
	setDefaultButton(KDialog::Ok);
	setModal( true );
	KVBox *page = new KVBox( this );
	setMainWidget( page );
	//Design UI

	// Combo to Pick authors
	KHBox *topBox = new KHBox(page);
	topBox->setSpacing(6);

	authorsCombo = new KComboBox( true, topBox );
	authorsCombo->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
	authorsCombo->completionObject() ->setCompletionMode( KGlobalSettings::CompletionPopupAuto );
	authorsCombo->lineEdit() ->disconnect( authorsCombo ); //so hitting enter doesn't enter the item into the box

	connect( authorsCombo->lineEdit(), SIGNAL( returnPressed() ),
					 this, SLOT( addAuthor() ) );

	// Add/Remove buttons

	addAuthorButton = new KPushButton( topBox );
	addAuthorButton->setIcon( KIcon( "list-add" ) );

	removeAuthorButton = new KPushButton( topBox );
	removeAuthorButton->setIcon( KIcon( "list-remove" ) );

	// Author List

	authorListModel = new QStandardItemModel( 0, 2, this );

	authorListView = new QTreeView( page );
	authorListView->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
	authorListView->setAllColumnsShowFocus( true );
	authorListView->setRootIsDecorated( false );

	QStringList horizontalLabels;
	horizontalLabels << i18nc( "@title:column", "Id" ) << i18nc( "@title:column", "Author" );
	authorListModel->setHorizontalHeaderLabels( horizontalLabels );
		
	authorListProxyModel = new QSortFilterProxyModel(this);
	authorListProxyModel->setSourceModel(authorListModel);
	authorListProxyModel->setDynamicSortFilter( true );
	authorListView->setModel( authorListProxyModel );
	
	KConfigGroup config( KGlobal::config(), "Advanced" );
	if ( !config.readEntry( "ShowID", false ) ) {
		authorListView->hideColumn( 0 );
		authorListView->header()->hide();
	}

	// Load the list
	loadAuthors( currentAuthors );

	adjustSize();
	resize(450, height());

	// Connect signals & Slots
	connect ( addAuthorButton, SIGNAL( clicked() ), this, SLOT( addAuthor() ) );
	connect ( removeAuthorButton, SIGNAL( clicked() ), this, SLOT( removeAuthor() ) );

	authorsCombo->setEditText(QString());
	authorsCombo->lineEdit()->setFocus();
}