コード例 #1
0
Display* DisplayGroup::takeDisplay( Display* child )
{
    Display* result = NULL;
    int num_displays = displays_.size();
    for( int i = 0; i < num_displays; i++ )
    {
        if( displays_.at( i ) == child )
        {
            if( model_ )
            {
                model_->beginRemove( this, Display::numChildren() + i, 1 );
            }
//      printf("  displaygroup3 displays_.takeAt( %d )\n", i );
            result = displays_.takeAt( i );
            Q_EMIT displayRemoved( result );
            result->setParent( NULL );
            result->setModel( NULL );
            child_indexes_valid_ = false;
            if( model_ )
            {
                model_->endRemove();
            }
            Q_EMIT childListChanged( this );
            break;
        }
    }
    return result;
}
コード例 #2
0
void DisplayGroup::removeAllDisplays()
{
    int num_non_display_children = Display::numChildren();

    if( model_ )
    {
        model_->beginRemove( this, num_non_display_children, displays_.size() );
    }
    for( int i = displays_.size() - 1; i >= 0; i-- )
    {
//    printf("  displaygroup2 displays_.takeAt( %d )\n", i );
        Display* child = displays_.takeAt( i );
        Q_EMIT displayRemoved( child );
        child->setParent( NULL ); // prevent child destructor from calling getParent()->takeChild().
        delete child;
    }
    if( model_ )
    {
        model_->endRemove();
    }
    Q_EMIT childListChanged( this );
}
コード例 #3
0
Property* DisplayGroup::takeChildAt( int index )
{
    if( index < Display::numChildren() )
    {
        return Display::takeChildAt( index );
    }
    int disp_index = index - Display::numChildren();
    if( model_ )
    {
        model_->beginRemove( this, index, 1 );
    }
//  printf("  displaygroup5 displays_.takeAt( %d ) ( index = %d )\n", disp_index, index );
    Display* child = displays_.takeAt( disp_index );
    Q_EMIT displayRemoved( child );
    child->setModel( NULL );
    child->setParent( NULL );
    child_indexes_valid_ = false;
    if( model_ )
    {
        model_->endRemove();
    }
    Q_EMIT childListChanged( this );
    return child;
}
コード例 #4
0
ファイル: ShareEdit.cpp プロジェクト: epoupon/fileshelter
void
ShareEdit::refresh(void)
{
	if (!wApp->internalPathMatches("/share-edit"))
		return;

	clear();

	std::string editUUID = wApp->internalPathNextPart("/share-edit/");

	Wt::Dbo::Transaction transaction(FsApp->getDboSession());

	Database::Share::pointer share = Database::Share::getByEditUUID(FsApp->getDboSession(), editUUID);
	if (!share || !boost::filesystem::exists(share->getPath()))
	{
		FS_LOG(UI, ERROR) << "Edit UUID '" << editUUID << "' not found";
		displayNotFound();
		return;
	}

	FS_LOG(UI, INFO) << "[" << share->getDownloadUUID() << "] Editing share from " << wApp->environment().clientAddress();

	Wt::WTemplate *t = addNew<Wt::WTemplate>(tr("template-share-edit"));
	t->addFunction("tr", &Wt::WTemplate::Functions::tr);

	if (!share->getDesc().empty())
	{
		t->setCondition("if-desc", true);
		t->bindString("file-desc", Wt::WString::fromUTF8(share->getDesc()));
	}
	t->bindString("file-name", Wt::WString::fromUTF8(share->getFileName()));
	t->bindString("file-size", sizeToString(share->getFileSize()));
	t->bindString("expiry-date-time", share->getExpiryTime().toString() + " UTC");

	auto hits = std::to_string(share->getHits());
	if (share->getMaxHits() > 0)
		hits += " / " + std::to_string(share->getMaxHits());
	t->bindString("hits", hits);

	t->bindWidget("download-link", createShareDownloadAnchor(share));

	Wt::WPushButton* deleteBtn = t->bindNew<Wt::WPushButton>("delete-btn", tr("msg-delete"));

	deleteBtn->clicked().connect([=] ()
	{
		auto messageBox = deleteBtn->addChild(std::make_unique<Wt::WMessageBox>(tr("msg-share-delete"),
			tr("msg-confirm-action"),
			 Wt::Icon::Question,
			 Wt::StandardButton::Yes | Wt::StandardButton::No));

		messageBox->setModal(true);

		messageBox->buttonClicked().connect([=] (Wt::StandardButton btn)
		{
			if (btn == Wt::StandardButton::Yes)
			{
				Wt::Dbo::Transaction transaction(FsApp->getDboSession());

				Database::Share::pointer share = Database::Share::getByEditUUID(FsApp->getDboSession(), editUUID);

				if (share)
				{
					FS_LOG(UI, INFO) << "[" << share->getDownloadUUID() << "] Deleting share from " << wApp->environment().clientAddress();
					share.modify()->destroy();
					share.remove();
				}

				displayRemoved();
			}
			deleteBtn->removeChild(messageBox);
		});

		messageBox->show();
	});

}