Beispiel #1
0
void *SoundPlugin::processEvent(Event *e)
{
    if (e->type() == EventContactOnline){
        Contact *contact = (Contact*)(e->param());
        SoundUserData *data = (SoundUserData*)(contact->getUserData(user_data_id));
        if (data && data->Alert && *data->Alert &&
                (!getDisableAlert() ||
                 (core &&
                  ((core->getManualStatus() == STATUS_ONLINE) ||
                   (core->getManualStatus() == STATUS_OFFLINE))))){
            Event eSound(EventPlaySound, data->Alert);
            eSound.process();
        }
        return NULL;
    }
    if (e->type() == EventMessageSent){
        Message *msg = (Message*)(e->param());
		const char *err = msg->getError();
		if (err && *err)
			return NULL;
        const char *sound = NULL;
		if (msg->type() == MessageFile){
			sound = getFileDone();
		}else if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){
            if ((msg->getFlags() & MESSAGE_MULTIPLY) && ((msg->getFlags() & MESSAGE_LAST) == 0))
                return NULL;
	        sound = getMessageSent();
		}
           if (sound && *sound &&
                    (!getDisableAlert() || (core && (core->getManualStatus() == STATUS_ONLINE)))){
                Event eSound(EventPlaySound, (void*)sound);
                eSound.process();
        }
        return NULL;
    }
    if (e->type() == EventMessageReceived){
        Message *msg = (Message*)(e->param());
        if (msg->type() == MessageStatus)
            return NULL;
        if (getDisableAlert() && core && (core->getManualStatus() != STATUS_ONLINE))
            return NULL;
        Contact *contact = getContacts()->contact(msg->contact());
        if (contact == NULL)
            return NULL;
        SoundUserData *data = (SoundUserData*)(contact->getUserData(user_data_id));
        string sound = messageSound(msg->type(), data);
        if (!sound.empty())
            playSound(sound.c_str());
        return NULL;
    }
    if (e->type() == EventPlaySound){
        char *name = (char*)(e->param());
        playSound(name);
        return e->param();
    }
    return NULL;
}
bool Upgrader::downloader(int targetfile)
{
    curlhandle.downloading = true;
    curlhandle.handle = curl_easy_init();
    curlhandle.success = false;

    std::string urlstring = geturl() + targetswitch(targetfile);
    const char *url = urlstring.c_str();

    bfs::path target = path(DATA) / "upgrade";
    // if user switches between upgrading client and bootstrapping blockchain, we don't want to pass around garbage
    if (bfs::exists(target)) {bfs::remove_all(target);} 
    
    if (!verifyPath(target, true)) {return false;}
    target /= targetswitch(targetfile);
    cancelDownload(false);
    if (bfs::exists(target))    {bfs::remove(target);}
    file = fopen(target.string().c_str(), "wb");
    fileInitialized=true;


    curl_easy_setopt(curlhandle.handle, CURLOPT_URL, url);
    curl_easy_setopt(curlhandle.handle, CURLOPT_WRITEFUNCTION, fwrite);
    curl_easy_setopt(curlhandle.handle, CURLOPT_WRITEDATA, file);
    curl_easy_setopt(curlhandle.handle, CURLOPT_WRITEDATA, file);
    //curl_easy_setopt(curlhandle.handle, CURLOPT_XFERINFOFUNCTION, cancelDownloader);
    curl_easy_setopt(curlhandle.handle, CURLOPT_NOPROGRESS, 0L);


    downloadThread = boost::thread(download, (void *)&curlhandle);

    printf("downloading file...\n");

    filesize = -1;
    filesizeRetrieved = false;

    while (curlhandle.downloading && !CANCEL_DOWNLOAD)
        {
            #ifdef WIN32
            Sleep(1000);
            #else
            usleep(1000*500);
            #endif
            #if defined(UPGRADERFLAG)
            int sz = getFileDone();
            printf("\r%i\tKB \t%i%%", sz/1024, getFilePerc(sz));
            fflush( stdout );
            #endif
        }

    curl_easy_cleanup(curlhandle.handle);
    fclose(file);
    fileInitialized=false;

    if(!curlhandle.success)
    {
        printf((CANCEL_DOWNLOAD)? "\ndownload interrupted\n" : "\ndownload failed\n");
        if (bfs::exists(target))    bfs::remove(target);
        cancelDownload(false);
        return false;
    }
    else
    {
        printf("\nfile downloaded successfully\n");
        return true;
    }
}
Beispiel #3
0
void *SoundPlugin::processEvent(Event *e)
{
    if (e->type() == EventSoundChanged){
        Command cmd;
        cmd->id    = CmdSoundDisable;
        SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id));
        if (!data->Disable.bValue)
            cmd->flags |= COMMAND_CHECKED;
        m_bChanged = true;
        Event e(EventCommandChecked, cmd);
        e.process();
        m_bChanged = false;
        return NULL;
    }
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == CmdSoundDisable){
            cmd->flags &= ~COMMAND_CHECKED;
            SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id));
            if (!data->Disable.bValue)
                cmd->flags |= COMMAND_CHECKED;
            return e->param();
        }
        return NULL;
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (!m_bChanged && (cmd->id == CmdSoundDisable)){
            SoundUserData *data = (SoundUserData*)(getContacts()->getUserData(user_data_id));
            data->Disable.bValue = !data->Disable.bValue;
            Event eChanged(EventSoundChanged);
            eChanged.process();
            return e->param();
        }
        return NULL;
    }
    if (e->type() == EventContactOnline){
        Contact *contact = (Contact*)(e->param());
        SoundUserData *data = (SoundUserData*)(contact->getUserData(user_data_id));
        if (data && data->Alert.ptr && *data->Alert.ptr && !data->Disable.bValue){
            Event eSound(EventPlaySound, data->Alert.ptr);
            eSound.process();
        }
        return NULL;
    }
    if (e->type() == EventMessageSent){
        Message *msg = (Message*)(e->param());
        const char *err = msg->getError();
        if (err && *err)
            return NULL;
        const char *sound = NULL;
        if (msg->type() == MessageFile){
            sound = getFileDone();
        }else if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){
            if ((msg->getFlags() & MESSAGE_MULTIPLY) && ((msg->getFlags() & MESSAGE_LAST) == 0))
                return NULL;
            sound = getMessageSent();
        }
        if (sound && *sound){
            Event eSound(EventPlaySound, (void*)sound);
            eSound.process();
        }
        return NULL;
    }
    if (e->type() == EventMessageReceived){
        Message *msg = (Message*)(e->param());
        if (msg->type() == MessageStatus)
            return NULL;
        if (msg->getFlags() & MESSAGE_LIST)
            return NULL;
        Contact *contact = getContacts()->contact(msg->contact());
        SoundUserData *data;
        if (contact){
            data = (SoundUserData*)(contact->getUserData(user_data_id));
        }else{
            data = (SoundUserData*)(getContacts()->getUserData(user_data_id));
        }
        bool bEnable = !data->Disable.bValue;
        if (bEnable && data->NoSoundIfActive.bValue){
            Event e(EventActiveContact);
            if ((unsigned)(e.process()) == contact->id())
                bEnable = false;
        }
        if (bEnable){
            string sound = messageSound(msg->baseType(), data);
            if (!sound.empty())
                playSound(sound.c_str());
        }
        return NULL;
    }
    if (e->type() == EventPlaySound){
        char *name = (char*)(e->param());
        playSound(name);
        return e->param();
    }
    return NULL;
}