// --- void DragonWindGame::initialize () { QGAMES::ArcadeGame::initialize (); // Sets the icon of the game... mainScreen () -> setIcon (formBuilder () -> form (__DRAGONWINDICON__)); // Add to the world its different world... // Initially none of them is active! addWorld (__DRAGONSELECTIONWORLD); addWorld (__DRAGONTRAININGWORLD); // Add to the game its different states... addState (new DragonWindPauseState (this), std::string (__DRAGONSTATEPAUSENAME)); addState (new DragonWindInitialState (this), std::string (__DRAGONSTATEINITIALNAME)); addState (new DragonWindIntroductionState (this), std::string (__DRAGONSTATEINTRODUCTIONNAME)); addState (new DragonWindSelectionState (this), std::string (__DRAGONSTATESELECTONNAME)); addState (new DragonWindInstructionsState (this), std::string (__DRAGONSTATEINSTRUCTIONSNAME)); addState (new DragonWindTrainingState (this), std::string (__DRAGONSTATETRAININGNAME)); addState (new DragonWindCountingDownState (this), std::string (__DRAGONSTATECOUNTDOWNNAME)); addState (new DragonWindPlayingState (this), std::string (__DRAGONSTATEPLAYINGNAME)); addState (new DragonWindEndState (this), std::string (__DRAGONSTATEENDNAME)); addState (new DragonWindWinState (this), std::string (__DRAGONSTATEWINNAME)); // Add to the game its different artists // Their visibility will depend on the world and scene the main players are in addArtist (_DRAGONNINJAARTIST); // The main character of the game... addArtist (_DRAGONNINJAARTISTB); // The other main character of the game...this last one is only used during presentations! // The initial state... setState (std::string (__DRAGONSTATEINTRODUCTIONNAME)); }
QTreeWidgetItem *CollectionTreeWidget::addAlbum(QString artist, QString album, unsigned int albumId) { // Find id in database if we don't have it if (albumId == 0) { QSqlTableModel *model = service->collectionModel(); // SQLite used two single quotes to escape a single quote! :) QString filter = "artist = '" + QString(artist).replace("'","''") + "' AND " "album = '" + QString(album).replace("'","''") + "'"; model->setFilter(filter); model->select(); while (model->canFetchMore()) model->fetchMore(); int total = model->rowCount(); if (total > 0) { albumId = model->record(0).value(model->fieldIndex("id_album")).toInt(); } else { qDebug("ERROR: no album found! -- " + model->filter().toUtf8()); return NULL; } } // Looks for the artist QTreeWidgetItem *newAlbumNode; // The node with the album, whether it exists or not QTreeWidgetItem *artistItem; artistItem = addArtist(artist); // Look for album for (int i = 0; i < artistItem->childCount(); i++) { if (artistItem->child(i)->text(0) == album) { newAlbumNode = artistItem->child(i); return newAlbumNode; } } // Create our new album node and add it if it was not found newAlbumNode = new CollectionTreeWidgetItem(LevelAlbum, albumId, (QTreeWidget*)0); newAlbumNode->setText(0, album); newAlbumNode->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); // Set icon newAlbumNode->setIcon(0, IconFactory::fromTheme("media-cdrom")); artistItem->addChild(newAlbumNode); artistItem->sortChildren(0, Qt::AscendingOrder); return newAlbumNode; }
ArtistForm::ArtistForm(const QString &name, QWidget *parent) : QDialog(parent) { model = new QSqlTableModel(this); model->setTable("artist"); model->setSort(Artist_Name, Qt::AscendingOrder); model->setHeaderData(Artist_Name, Qt::Horizontal, tr("Name")); model->setHeaderData(Artist_Country, Qt::Horizontal, tr("Country")); model->select(); connect(model, SIGNAL(beforeInsert(QSqlRecord &)), this, SLOT(beforeInsertArtist(QSqlRecord &))); tableView = new QTableView; tableView->setModel(model); tableView->setColumnHidden(Artist_Id, true); tableView->setSelectionBehavior(QAbstractItemView::SelectRows); tableView->resizeColumnsToContents(); for (int row = 0; row < model->rowCount(); ++row) { QSqlRecord record = model->record(row); if (record.value(Artist_Name).toString() == name) { tableView->selectRow(row); break; } } addButton = new QPushButton(tr("&Add")); deleteButton = new QPushButton(tr("&Delete")); closeButton = new QPushButton(tr("Close")); connect(addButton, SIGNAL(clicked()), this, SLOT(addArtist())); connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteArtist())); connect(closeButton, SIGNAL(clicked()), this, SLOT(accept())); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addWidget(addButton); buttonLayout->addWidget(deleteButton); buttonLayout->addStretch(); buttonLayout->addWidget(closeButton); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(tableView); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); setWindowTitle(tr("Edit Artists")); }
//Update an artist void ArtistIndex::updateArtist(std::string old_artist, std::string new_artist, int old_pos) { int holdLocation = 0; //If new artist does not currently exist... if(!matchArtist(new_artist, holdLocation)) { addArtist(new_artist, old_pos); } // end if else { //Copy positions to new location Node * newNode = head->next; //Find new Node while(newNode != NULL) { if(newNode->artist == new_artist) { break; } // end if newNode = newNode->next; } // end while //Update count newNode->up->pos = newNode->up->pos + 1; //Find empty up in newNode Node * newUp = newNode->up; while(newUp->up != NULL) { newUp = newUp->up; } // end while //Add New Up Node * p = new Node("~",old_pos); p->down = newUp->down; p->up = newUp; newUp->down->up=p; newUp->down=p; } // end else //Delete Old Up deleteArtist(old_artist, old_pos); } // end updateArtist
/// @brief Constructor CollectionTreeWidget::CollectionTreeWidget() { setColumnCount(1); header()->hide(); // hide headers setDragEnabled(true); setAcceptDrops(true); setSelectionMode(QAbstractItemView::ExtendedSelection); service = new CollectionService(); // Add songs that currently exist on database QSqlTableModel *artistModel = service->artistModel(); artistModel->select(); // TODO: verify if we can put fetchmore() inside the for loop. // TODO: put this task in background... URGENT while (artistModel->canFetchMore()) artistModel->fetchMore(); int total = artistModel->rowCount(); for (int i = 0; i < total; i++) { QString artist = artistModel->record(i).value(artistModel->fieldIndex("name")).toString(); unsigned int id = artistModel->record(i).value(artistModel->fieldIndex("id")).toInt(); addArtist(artist, id); } delete artistModel; /* * TODO: modify the slots in order to add only the artist, not the music. * The album and song must be shown only if the node is already expanded. */ connect(service, SIGNAL(songAdded(Music*)), this, SLOT(addMusic(Music*))); connect(service, SIGNAL(songRemoved(unsigned int)), this, SLOT(removeMusic(uint))); connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(doubleClickAt(QModelIndex))); connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(showChildrenOf(QModelIndex))); /* * We shall emit those signals to show or hide the widget that will * give the feedback that the collection is being scanned. */ connect(service, SIGNAL(scanning()), this, SIGNAL(scanning())); connect(service, SIGNAL(listUpdated()), this, SIGNAL(listUpdated())); // Start service to find new songs and remove the inexistent ones service->start(QThread::LowestPriority); }
/* * Function: printArtistComment * Parameters: funcName stuct * Returns: (void) * * This function checks if the current user is a librarian or not * so it knows whether the user has permission to add a new artist. * If they don't have permission they will recieve a message stating * they are not privleged to add new artists. The function will then * check that the cgi form was a success and then will add the new artist * by communicating with the database. */ static void doAddArtist(void) { Boolean needAddForm = TRUE; int result = 0; /* Temporary Struct to store form data */ artistNode_t *formdata = NULL; /* Array to store errors */ int *errors = NULL; Boolean isAdding = FALSE; /* Check privileges of current user */ if (isUserLibrarian(_currUserLogon) == FALSE) { fprintf(cgiOut, "You are not privileged to add new Artists\n"); return; } fprintf(cgiOut, "<div class=\"head1\">Adding New Artist</div>\n"); /* if adding field is set */ result = cgiFormIntegerBounded("adding", &isAdding, FALSE, TRUE, FALSE); if (result != cgiFormSuccess) { /* Some sort of failure */ isAdding = FALSE; } /* Malloc space for form data */ formdata = malloc(sizeof(artistNode_t)); if (formdata == NULL) { isAdding = FALSE; } else { Boolean formOK = FALSE; formdata->name = NULL; /* Malloc space for error code of each field */ errors = malloc(sizeof(int) * 1); if (errors == NULL) { free(formdata); isAdding = FALSE; } else { /* Set errors to E_NOERROR */ int i = 0; for (i = 0; i < 1; i++) { errors[i] = E_NOERROR; } } /* The curr data is ready for processing */ formOK = processAddForm(errors, formdata); if (isAdding == TRUE && formOK == TRUE) { int newArtistid = -1; /* All form data is good */ /* Add artist to database */ newArtistid = addArtist(formdata->name); if (newArtistid > 0) { /* User added ok */ needAddForm = FALSE; fprintf(cgiOut, "Adding successful<br />\n"); fprintf(cgiOut, "<a href=\"./?page=artist&artistid=%d&hash=%d\">[View Artist]</a><br />\n", newArtistid, _currUserLogon); fprintf(cgiOut, "<a href=\"./?page=album&func=add&artistid=%d&hash=%d\">[Add Album by this Artist]</a><br />\n", newArtistid, _currUserLogon); fprintf(cgiOut, "<a href=\"./?page=artist&func=add&hash=%d\">[Add Another Artist]</a>", _currUserLogon); } else { /* Artist adding error */ fprintf(cgiOut, "DB Save Error<br />\n"); } } } if (needAddForm == TRUE) { /* Need to print form */ printAddForm(isAdding, errors, formdata); } /* Free the memory */ if (errors != NULL) { free(errors); } if (formdata != NULL) { if (formdata->name != NULL) { free(formdata->name); } free(formdata); } }
//Read in artists void ArtistIndex::readSecondary() { std::ifstream input("artist_index.txt"); std::string line; getline (input,line); size = atoi(line.c_str()); if (input.is_open()) { //Set position to 1 long position = 1; //delimiter is a space std::string delimiter = " "; //size of string size_t pos = 0; //Line in file as a string std::string line; //string of part std::string part; //Number of keys in line int numOfKeys = 0; //Artist Name std::string artist_name = ""; while(!input.eof() && position != (int)(size+1)) { //Read in a line from the sequential file getline (input,line); //Defaults pos = 0; part = ""; numOfKeys = 0; //Get Number of keys if ((pos = line.find(delimiter)) != std::string::npos) { part = line.substr(0, pos); line.erase(0, pos + delimiter.length()); numOfKeys = atoi(part.c_str()); } //Get artist name if ((pos = line.find(delimiter)) != std::string::npos) { part = line.substr(0, pos); artist_name = part; line.erase(0, pos + delimiter.length()); --size; } //Set pos to keys in line for(int i = 0; i < numOfKeys; ++i) { if((pos = line.find(delimiter)) != std::string::npos) { part = line.substr(0, pos); addArtist(artist_name, atoi(part.c_str())); line.erase(0, pos + delimiter.length()); } } // end for position++; } // End eof while input.close(); } // end if } // end readSecondary