PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Problem with serialize and unserialize on DND (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Problem with serialize and unserialize on DND
#164
wim stockman (User)
Fresh Boarder
Posts: 19
graphgraph
User Offline Click here to see the profile of this user
Problem with serialize and unserialize on DND 5 Months, 4 Weeks ago Karma: 0  
Hello ,

I have a strange problem when I serialze my titel of my Thumbnail in a GtkIconview they are in Latin1 codepage
and then unserialize it in my drop function there is nothing in my data and this only happens if there are some typical french accents like é or ç in the words:
Here is my code I use to serialize:
$selection = $widget->get_selected_items();
if (count($selection)==0) return; // return if there's no selection
foreach($selection as $el)
{

$iter_filter = $this->_modelfilter->get_iter($el[0]);
$titel = $this->_modelfilter->get_value($iter_filter,0);
$filepath = $this->_modelfilter->get_value($iter_filter,2);
$path = $el[0];
$elements_to_send[]=array($titel,$filepath);


}

$data->set_text(serialize($elements_to_send));
}

and in the on_drop function when I do
$data = unserialize($data->data);
there is nothing in the $data variable if I used some specialchars.
I already tried with htmlspecialchars and then htmlspecialchars_decode but it stays the same.

Somebody know;
$elements_to_send[]=array($titel,$filepath);


}

$data->set_text(serialize($elements_to_send));
}

and in the on_drop function when I do
$data = unserialize($data->data);
there is nothing in the $data variable if I used some specialchars.
I already tried with htmlspecialchars and then htmlspecialchars_decode but it stays the same.

Somebody knows how to prevent this ?
 
  The administrator has disabled public write access.
#165
kksou (Admin)
Admin
Posts: 323
graph
User Online Now Click here to see the profile of this user
Re:Problem with serialize and unserialize on DND 5 Months, 4 Weeks ago Karma: 8  
Hi Wim,

Please refer to Jake's comments why the problem occurs. He also presented a solution there.

Alternatively, I've presented another solution in the following article:
Sample Code 475: How to drag and drop between 2 GtkTreeViews - Part 7 - another method of passing along complex drag info

Regards,
/kksou
 
  The administrator has disabled public write access.
#167
wim stockman (User)
Fresh Boarder
Posts: 19
graphgraph
User Offline Click here to see the profile of this user
Re:Problem with serialize and unserialize on DND 5 Months, 4 Weeks ago Karma: 0  
Hello ,

Thanks for the solution
offcourse the solution of kksou I already thought of also
but this I find not such a good object oriented way.
And the solution of Jake just doesn't work.
for the set_text
can't we get a function where we can add a pointer in the data to an array or something.
I searched to now what the context variable is and what is inside maybe there is a solution?

thanks for all your great work.

Wim Stockman
 
  The administrator has disabled public write access.
#168
kksou (Admin)
Admin
Posts: 323
graph
User Online Now Click here to see the profile of this user
Re:Problem with serialize and unserialize on DND 5 Months, 4 Weeks ago Karma: 8  
Hi Wim,

Not everyone has learned OOP. That's why about 99% of the codes found on this website are using plain, non-OOP php.

You can easily change this into OOP fashion.

There are many way of doing this. Here are two solutions - one using OOP at the application level, and the other using OOP at the widget level:

Sample Code 476: How to drag and drop between 2 GtkTreeViews - Part 8 - another method of passing along complex drag info - OOP ver 1

Sample Code 477: How to drag and drop between 2 GtkTreeViews - Part 9 - another method of passing along complex drag info - OOP ver 2

If you look at either solution, we're using $data->data more or less like a pointer to your array of drag information...

Regards,
/kksou
 
  The administrator has disabled public write access.
#172
wim stockman (User)
Fresh Boarder
Posts: 19
graphgraph
User Offline Click here to see the profile of this user
Re:Problem with serialize and unserialize on DND 5 Months, 4 Weeks ago Karma: 0  
Hello ,

I found a solution. Thanks to Jake and Kksou.
instead of using the serialize function. I use the implode function to create my string out of an array with is delimited by \x10 char.

Now the dnd works fine. But I have another issue with characters before the drop I have this as titel:
"Yves Rhayé" and after the drop I have "Yves Rhay\u00e9"
problem something with the character set but what.
Thanks for all the great support
 
  The administrator has disabled public write access.
#177
wim stockman (User)
Fresh Boarder
Posts: 19
graphgraph
User Offline Click here to see the profile of this user
Re:Problem with serialize and unserialize on DND 5 Months, 3 Weeks ago Karma: 0  
I think I know where the problem is.
Does the gtkselectiodata->Set_Text function convert the string into uris format ?
and how can I convert it back then ?
thank you.
 
  The administrator has disabled public write access.
#178
wim stockman (User)
Fresh Boarder
Posts: 19
graphgraph
User Offline Click here to see the profile of this user
Re:Problem with serialize and unserialize on DND 5 Months, 3 Weeks ago Karma: 0  
Hello I was on the good way finally found the solution.
you have to use the urlencode($your_string) and everything works fine.
You don't even need to uncode it. The get_text() does this for you.
Finally we can go the hole OOP way.

Thanks for all the support
 
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Copyright © 2006-2008. kksou.com. All Rights Reserved