Ejemplo n.º 1
0
void activity_table::get_activity_records( string source, string &result ){

		string count_sql = "SELECT count(1) "
			" FROM activity ";

		if(!source.empty())
			count_sql.append("WHERE activity_type = ").append(source);

		query count_query(*conn, count_sql);
		auto count_res = count_query.emit_result();
		if( count_res->get_int(0) == 0)
			return;
		

		string sql = "SELECT activity_id, activity_name, activity_type, activity_status, "
			" activity_priority, who_preside, when_created, note "
			" FROM activity ";

			
		if(!source.empty())
			sql.append("WHERE activity_type = ").append(source);

		query q(*conn, sql);
		LOG("sql", sql);
		auto res = q.emit_result();

		stringstream ss;

		//XXX should check count in case it is 0. there is a bug form sqlite count doesn't work

		bool first = true;
		ss << "{ \"activity\":[ ";
		do{
			if(first)
				first = false;
			else{
				ss << ", ";
			}

			ss << "{" ;
			ss << "\"activity_id\"" << ":" << "\"" << res->get_string(0) << "\"" << ",";
			ss << "\"activity_name\"" << ":" << "\"" << res->get_string(1) << "\"" << ",";
			ss << "\"activity_type\"" << ":" << "\"" << res->get_string(2) << "\"" << ",";
			ss << "\"activity_status\"" << ":" << "\"" << res->get_string(3) << "\"" << ",";
			ss << "\"activity_priority\"" << ":" << "\"" << res->get_string(4) << "\"" << ",";
			ss << "\"who_preside\"" << ":" << "\"" << res->get_string(5) << "\"" << ",";
			ss << "\"when_created\"" << ":" << "\"" << res->get_string(6) << "\"" << ",";
			ss << "\"note\"" << ":" << "\"" << res->get_string(7) << "\"" ;
			ss << "}";
		} while(res->next_row());

		ss << " ] }";
		result = ss.str();
}
Ejemplo n.º 2
0
/// checks we have some tracks available
static bool checkMusicAvailable(void)
{
    MSqlQuery count_query(MSqlQuery::InitCon());
    bool foundMusic = false;
    if (count_query.exec("SELECT COUNT(*) FROM music_songs;"))
    {
        if(count_query.next() &&
            0 != count_query.value(0).toInt())
        {
            foundMusic = true;
        }
    }

    if (!foundMusic)
    {
        ShowOkPopup(qApp->translate("(MythMusicMain)",
                                    "No music has been found.\n"
                                    "Please select 'Scan For New Music' "
                                    "to perform a scan for music."));
    }

    return foundMusic;
}
Ejemplo n.º 3
0
void contact_table::get_contact_list(std::map<string, string> &contacts){
	auto count_sql = "SELECT count(1) FROM contact";

	query count_query(*conn, count_sql);
	auto count_res = count_query.emit_result();
	auto rows = count_res->get_int(0);

	if(rows == 0)
		return;

	string sql = "SELECT contact_id, first_name, last_name, contact_from.description "
		"FROM contact INNER JOIN contact_from ON contact.contact_from = contact_from.contact_from";
	
	query q(*conn, sql);

	LOG("sql", sql);
	auto res = q.emit_result();

	do{
		string contact_item = res->get_string(1) + " " + res->get_string(2) +": " + res->get_string(3);
		contacts[res->get_string(0)] = contact_item;
	} while(res->next_row());
}
Ejemplo n.º 4
0
static void loadMusic()
{
    // only do this once
    if (gMusicData->initialized)
        return;

    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
    QString message = QObject::tr("Loading Music. Please wait ...");

    MythUIBusyDialog *busy = new MythUIBusyDialog(message, popupStack,
                                                  "musicscanbusydialog");
    if (busy->Create())
        popupStack->AddScreen(busy, false);
    else
        busy = NULL;

    srand(time(NULL));

    CheckFreeDBServerFile();

    MSqlQuery count_query(MSqlQuery::InitCon());

    bool musicdata_exists = false;
    if (count_query.exec("SELECT COUNT(*) FROM music_songs;"))
    {
        if(count_query.next() &&
            0 != count_query.value(0).toInt())
        {
            musicdata_exists = true;
        }
    }

    //  Load all available info about songs (once!)
    QString startdir = gCoreContext->GetSetting("MusicLocation");
    startdir = QDir::cleanPath(startdir);
    if (!startdir.endsWith("/"))
        startdir += "/";

    Metadata::SetStartdir(startdir);

    Decoder::SetLocationFormatUseTags();

    // Only search music files if a directory was specified & there
    // is no data in the database yet (first run).  Otherwise, user
    // can choose "Setup" option from the menu to force it.
    if (!startdir.isEmpty() && !musicdata_exists)
    {
        FileScanner *fscan = new FileScanner();
        fscan->SearchDir(startdir);
        delete fscan;
    }

    QString paths = gCoreContext->GetSetting("TreeLevels");

    // Set the various track formatting modes
    Metadata::setArtistAndTrackFormats();

    AllMusic *all_music = new AllMusic(paths, startdir);

    //  Load all playlists into RAM (once!)
    PlaylistContainer *all_playlists = new PlaylistContainer(
            all_music, gCoreContext->GetHostName());

    gMusicData->paths = paths;
    gMusicData->startdir = startdir;
    gMusicData->all_playlists = all_playlists;
    gMusicData->all_music = all_music;
    gMusicData->initialized = true;

    while (!gMusicData->all_playlists->doneLoading() || !gMusicData->all_music->doneLoading())
    {
        qApp->processEvents();
        usleep(50000);
    }
    gMusicData->all_playlists->postLoad();

    gPlayer->constructPlaylist();

    if (busy)
        busy->Close();

}