Example #1
0
int MusicPlayer::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: updateTime((*reinterpret_cast< qint64(*)>(_a[1]))); break;
        case 1: playOrpause(); break;
        case 2: openFile(); break;
        case 3: setMod(); break;
        case 4: previousSong(); break;
        case 5: nextSong(); break;
        case 6: whatiLike(); break;
        case 7: showLrc(); break;
        case 8: setPlayer(); break;
        case 9: showPlayList(); break;
        case 10: metaStateChanged((*reinterpret_cast< Phonon::State(*)>(_a[1])),(*reinterpret_cast< Phonon::State(*)>(_a[2]))); break;
        case 11: tableWidgetClicked((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 12: aboutToFinish(); break;
        case 13: clearSources(); break;
        case 14: saveAndQuit(); break;
        case 15: trayIconActivated((*reinterpret_cast< QSystemTrayIcon::ActivationReason(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 16;
    }
    return _id;
}
Example #2
0
/** Kontrola procesu */
void errorpid(pid_t pid) {

    fprintf(stderr, "%s", ecode[EFORK]);

    kill(pid, SIGTERM);
    int errnum;
    errnum = clearSources();
    if (errnum != EOK) {
        fprintf(stderr, "%s", ecode[errnum]);
    }
    killProces(0);
    exit(2);
}
Example #3
0
void SoundManager::setup(WSound *sound)
{
  for (unsigned i = 0; i < sound->media_.size(); ++i) {
    const WSound::Source& m = sound->media_[i];
    if (getSource(m.encoding) != m.link) {      
      clearSources();
      for (unsigned j = 0; j < sound->media_.size(); ++j) {
	const WSound::Source& m2 = sound->media_[j];
	addSource(m2.encoding, m2.link);
      }
      break;
    }
  }
}
// 初始化播放器
void MyWidget::initPlayer()
{
    // 设置主界面标题、图标和大小
    setWindowTitle(tr("MyPlayer音乐播放器"));
    setWindowIcon(QIcon(":/images/icon.png"));
    setMinimumSize(320, 160);
    setMaximumSize(320, 160);

    // 创建媒体图
    mediaObject = new Phonon::MediaObject(this);
    Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(mediaObject, audioOutput);

    // 关联媒体对象的tick()信号来更新播放时间的显示
    connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(updateTime(qint64)));

    // 创建顶部标签,用于显示一些信息
    topLabel = new QLabel(tr("<a href = \" http://www.yafeilinux.com \"> www.yafeilinux.com </a>"));
    topLabel->setTextFormat(Qt::RichText);
    topLabel->setOpenExternalLinks(true);
    topLabel->setAlignment(Qt::AlignCenter);

    // 创建控制播放进度的滑块
    Phonon::SeekSlider *seekSlider = new Phonon::SeekSlider(mediaObject, this);

    // 创建包含播放列表图标、显示时间标签和桌面歌词图标的工具栏
    QToolBar *widgetBar = new QToolBar(this);
    // 显示播放时间的标签
    timeLabel = new QLabel(tr("00:00 / 00:00"), this);
    timeLabel->setToolTip(tr("当前时间 / 总时间"));
    timeLabel->setAlignment(Qt::AlignCenter);
    timeLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    // 创建图标,用于控制是否显示播放列表
    QAction *PLAction = new QAction(tr("PL"), this);
    PLAction->setShortcut(QKeySequence("F4"));
    PLAction->setToolTip(tr("播放列表(F4)"));
    connect(PLAction, SIGNAL(triggered()), this, SLOT(setPlaylistShown()));
    // 创建图标,用于控制是否显示桌面歌词
    QAction *LRCAction = new QAction(tr("LRC"), this);
    LRCAction->setShortcut(QKeySequence("F2"));
    LRCAction->setToolTip(tr("桌面歌词(F2)"));
    connect(LRCAction, SIGNAL(triggered()), this, SLOT(setLrcShown()));
    // 添加到工具栏
    widgetBar->addAction(PLAction);
    widgetBar->addSeparator();
    widgetBar->addWidget(timeLabel);
    widgetBar->addSeparator();
    widgetBar->addAction(LRCAction);

    // 创建播放控制动作工具栏
    QToolBar *toolBar = new QToolBar(this);
    // 播放动作
    playAction = new QAction(this);
    playAction->setIcon(QIcon(":/images/play.png"));
    playAction->setText(tr("播放(F5)"));
    playAction->setShortcut(QKeySequence(tr("F5")));
    connect(playAction, SIGNAL(triggered()), this, SLOT(setPaused()));
    // 停止动作
    stopAction = new QAction(this);
    stopAction->setIcon(QIcon(":/images/stop.png"));
    stopAction->setText(tr("停止(F6)"));
    stopAction->setShortcut(QKeySequence(tr("F6")));
    connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop()));
    // 跳转到上一首动作
    skipBackwardAction = new QAction(this);
    skipBackwardAction->setIcon(QIcon(":/images/skipBackward.png"));
    skipBackwardAction->setText(tr("上一首(Ctrl+Left)"));
    skipBackwardAction->setShortcut(QKeySequence(tr("Ctrl+Left")));
    connect(skipBackwardAction, SIGNAL(triggered()), this, SLOT(skipBackward()));
    // 跳转到下一首动作
    skipForwardAction = new QAction(this);
    skipForwardAction->setIcon(QIcon(":/images/skipForward.png"));
    skipForwardAction->setText(tr("下一首(Ctrl+Right)"));
    skipForwardAction->setShortcut(QKeySequence(tr("Ctrl+Right")));
    connect(skipForwardAction, SIGNAL(triggered()), this, SLOT(skipForward()));
    // 打开文件动作
    QAction *openAction = new QAction(this);
    openAction->setIcon(QIcon(":/images/open.png"));
    openAction->setText(tr("播放文件(Ctrl+O)"));
    openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
    connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
    // 音量控制部件
    Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider(audioOutput, this);
    volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
    // 添加到工具栏
    toolBar->addAction(playAction);
    toolBar->addSeparator();
    toolBar->addAction(stopAction);
    toolBar->addSeparator();
    toolBar->addAction(skipBackwardAction);
    toolBar->addSeparator();
    toolBar->addAction(skipForwardAction);
    toolBar->addSeparator();
    toolBar->addWidget(volumeSlider);
    toolBar->addSeparator();
    toolBar->addAction(openAction);

    // 创建主界面布局管理器
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(topLabel);
    mainLayout->addWidget(seekSlider);
    mainLayout->addWidget(widgetBar);
    mainLayout->addWidget(toolBar);
    setLayout(mainLayout);

    // 在3-2中添加的代码
    connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
            this, SLOT(stateChanged(Phonon::State, Phonon::State)));

    // 以下是在3-3中添加的代码

    // 创建播放列表
    playlist = new MyPlaylist(this);
    connect(playlist, SIGNAL(cellClicked(int, int)), this, SLOT(tableClicked(int)));
    connect(playlist, SIGNAL(playlistClean()), this, SLOT(clearSources()));

    // 创建用来解析媒体的信息的元信息解析器
    metaInformationResolver = new Phonon::MediaObject(this);
    // 需要与AudioOutput连接后才能使用metaInformationResolver来获取歌曲的总时间
    Phonon::AudioOutput *metaInformationAudioOutput =
            new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(metaInformationResolver, metaInformationAudioOutput);
    connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
            this, SLOT(metaStateChanged(Phonon::State, Phonon::State)));

    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
            this, SLOT(sourceChanged(Phonon::MediaSource)));
    connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));

    // 初始化动作图标的状态
    playAction->setEnabled(false);
    stopAction->setEnabled(false);
    skipBackwardAction->setEnabled(false);
    skipForwardAction->setEnabled(false);
    topLabel->setFocus();

}
Example #5
0
SourceManager::~SourceManager()
{
    clearSources();
}
Example #6
0
int main (int argc, char **argv){
    int errnum;

    // alokovani pameti
    errnum = allocMem();
    if (errnum != EOK) {
        fprintf(stderr, "%s", ecode[errnum]);
        return 2;
    }

    // overeni parametru
    errnum = getParameters(argc, argv);
    if (errnum != EOK) {
        fprintf(stderr, "%s", ecode[errnum]);
        return 1;
    }

    //generovani nahodnych cisel
    srand(time(NULL));

    semafors->waiting = sem_open("/bayer05_waiting", O_CREAT, S_IRUSR|S_IWUSR, 1);
    semafors->boarding_Serf = sem_open("/bayer05_boarding_Serf", O_CREAT, S_IRUSR|S_IWUSR, 0);
    semafors->boarding_Hacker = sem_open("/bayer05_boarding_Hacker", O_CREAT, S_IRUSR|S_IWUSR, 0);
    semafors->member = sem_open("/bayer05_member", O_CREAT, S_IRUSR|S_IWUSR, 0);
    semafors->landing = sem_open("/bayer05_landing", O_CREAT, S_IRUSR|S_IWUSR, 0);
    semafors->finish = sem_open("/bayer05_finish", O_CREAT, S_IRUSR|S_IWUSR, 0);
    semafors->boating = sem_open("/bayer05_boating", O_CREAT, S_IRUSR|S_IWUSR, 0);
    semafors->checkready = sem_open("/bayer05_checkready", O_CREAT, S_IRUSR|S_IWUSR, 1);

    // overeni korektnosti vytvareni semaforu
    if(semafors->waiting == SEM_FAILED
    || semafors->boarding_Serf == SEM_FAILED
    || semafors->boarding_Hacker == SEM_FAILED
    || semafors->member == SEM_FAILED
    || semafors->landing == SEM_FAILED
    || semafors->finish == SEM_FAILED
    || semafors->boating == SEM_FAILED
    || semafors->checkready == SEM_FAILED)
    {
        fprintf(stderr, "%s", ecode[ESEMAPHORE]);

        errnum = clearSources();
        if (errnum != EOK) {
            fprintf(stderr, "%s", ecode[errnum]);
            return 2;
        }
        return 2;
    }

    fileopen();
    semafors->pocet = 1;
    semafors->molo_Hackers = 0;
    semafors->molo_Serfs = 0;
    semafors->dec = 4;
    semafors->end = 0;

    pid_t pid, pid2, pid3;

    pid = fork();
    if (pid == 0)
    {
        for ( int i = 0 ; i < semafors->members; i++)
        {
            if (semafors->serfSleep != 0)
            {
                usleep(rand()%(semafors->serfSleep)*1000);
            }
            pid2 = fork();
            if (pid2 == 0)
            {
                SerfProc(i+1);

                exit(0);
            }
            else if (pid2 < 0)
            {
                errorpid(pid2);
            }
        }
        for ( int i = 0 ; i < semafors->members; i++)
        {
            wait(NULL);
        }
        exit(0);
    }
    else if (pid < 0)
    {
        errorpid(pid);
    }
    else
    {
        pid = fork();
        if(pid == 0)
        {
            for( int i = 0 ; i < semafors->members; i++)
            {
                if (semafors->hackerSleep != 0)
                {
                    usleep(rand()%(semafors->hackerSleep)*1000);
                }
                pid3 = fork();
                if (pid3 == 0)
                {
                    HackerProc(i+1);

                    exit(0);
                }
                else if (pid3 < 0)
                {
                    errorpid(pid3);
                }
            }
            for ( int i = 0 ; i < semafors->members; i++)
            {
                wait(NULL);
            }
            exit(0);
        }
        else if (pid < 0)
        {
            errorpid(pid);
        }
        else
        {
            signal(SIGTERM, killProces);
            signal(SIGINT, killProces);

            wait(NULL);
            wait(NULL);
           // exit(0);
        }
    }

    errnum = clearSources();
    if (errnum != EOK) {
        fprintf(stderr, "%s", ecode[errnum]);
        return 2;
    }

    return 0;
}
Example #7
0
/** Zabije proces */
void killProces() {
    // ukonceni
    clearSources();
    kill(getpid(), SIGTERM);
    exit(2);
}