maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Prevent double press? [SOLVED] (https://talk.maemo.org/showthread.php?t=62968)

Berserk 2010-09-26 13:45

Prevent double press? [SOLVED]
 
There's only one bug that keeps me from promoting Wallpaeper to Extras-testing, which is the following:

It's possible to open multiple windows after pressing a button more than once.

How can I make sure a button can only be pressed once? (or how can I make sure only one window is opened?)
I've tried: (after button press)
- Disable button before creating a new Manager window (but that seemed to go simultaneously, so the button was disabled just before or after the new window shows)
- Disable the button, if(disabled) - open window (same as above, strange..)
- A boolean that decides whether to open it or not (false if button pressed)
- disconnect() after button press
- if a Manager window is made, don't make it again (didn't work..)

None of these worked :(
It doesn't crash with multiple windows, there are just multiple windows without a parent window

So can anyone help me with either:
- Preventing double button press
- Setting QListWidget icons faster

Many thanks in advance!

Tetsuo6995 2010-09-27 08:31

Re: Prevent double press?
 
Can you be more accurate on what language your coding ?

I'am a beginner but i found handy to use Hildon's StackableWindow.
Makes you sure you won't have multiple windows opened at the same time...

Hope i'am not completely wrong !

Berserk 2010-09-27 08:40

Re: Prevent double press?
 
I'm using C++ in the Nokia Qt SDK ;)

I also use .setAttribute(Qt::WA_Maemo5StackedWindow);
with the right parent window, of course.

When I press the button once, it stacks perfectly, however when I press it multiple times, it opens multiple windows, which then don't have a parent window, and are shown as separate windows.

The window takes some time to load, that's why it can be pressed more than once.

Diph 2010-09-27 14:57

Re: Prevent double press?
 
Set a windowIsVisible etc. flag before QWidget::show() is called. Then unset the flag when QWidget is hidden (maybe you have to reimplement hideEvent()).

E: Maybe it is easier to help if you show your code...

What do you mean by setting QListWidget icons faster?

Berserk 2010-09-27 16:28

Re: Prevent double press?
 
Thanks for that visible-flag tip ;) I will try something with that, not that I know a lot about flags, but I'll figure it out.


This is how it adds new items to the QListWidget:
- Put all .desktop files from /home/user/MyDocs/.images/ in a QStringList
- Open all of them
--- Check if it contains "Type=Background Image", if it does, next step:
--- Take filename, X-File1=, X-File2=, X-File3=, X-File4=, Name= from the file and put it in a second QStringList, [0] to [5]
--- Then add values from that second QStringList (the "clean" one) to the QListWidget, like this:
Code:

itemList.append(new QListWidgetItem(QIcon(imageSetList[i][1]), QFileInfo(imageSetList[i][0]).fileName(), ui->fileList));
That all goes blazingly fast, except for the QIcon, taken from the X-File1= value.
(A previous version didn't have the icons, it was LOTS faster..)







This is the slot that creates/shows the new window:
Code:

void wallPaeper::manBtnClicked() {
    manWin = new wpManager(this);
    manWin->setAttribute(Qt::WA_Maemo5StackedWindow);
    manWin->setAttribute(Qt::WA_DeleteOnClose);
    manWin->show();
}

By the way, it seems to open multiple windows simultaneously. So I can't do an existing-check in between, because every window is building at the same time as it seems :(

Berserk 2010-09-27 16:56

Re: Prevent double press?
 
The updateList() function, that does the above with the QStringLists, is in the constructor of wpManager (the new window). Hence the loading time,

I've just gotten an idea, which didn't work before, but I thought of a new way to do it..

I'll remove updateList() from the contructor, make a connect() function that checks if the window is visible, and updates the list when it is.
I'll make sure the slot prevents an infinite loop, since it stays visible for a while.

So it will load the list after the window opens. This will greatly improve the loading time (before it shows), making double button pressing less likely.

Berserk 2010-09-27 18:59

Re: Prevent double press?
 
It's solved :D it's probably not the prettiest solution, but I'm not taking my code to the catwalk ;)

It sets openManWin on true in the constructor, after the button press it's set on false, and after the window closes, it's true again.

Here's the code:
Code:

void wallPaeper::manBtnClicked() {
    if(openManWin == true) {
        openManWin = false;
        manWin = new wpManager(this);
        manWin->setAttribute(Qt::WA_Maemo5StackedWindow);
        manWin->setAttribute(Qt::WA_DeleteOnClose);
        connect(manWin, SIGNAL(destroyed()),
                this, SLOT(openManWinTrue()));
        manWin->show();
    }
}
void wallPaeper::openManWinTrue() {
    openManWin = true;
}



All times are GMT. The time now is 08:17.

vBulletin® Version 3.8.8