# HG changeset patch # User Dremov Kirill (Nokia-D-MSW/Tampere) # Date 1270099834 -10800 # Node ID cfcbf08528c455d3ad8084ea2740ba3c9d63175f Revision: 201013 diff -r 000000000000 -r cfcbf08528c4 group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/group/bld.inf Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published by +* the Free Software Foundation, version 2.1 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this program. If not, +* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". +* +* Description: Build information file for Qt Extensions configuration +* +*/ + +#include + +PRJ_PLATFORMS +TOOLS2 + +PRJ_EXPORTS +qtextensionsconfig.xml /epoc32/tools/makefile_templates/qt/qtextensionsconfig.xml +qtextensionsconfig.flm /epoc32/tools/makefile_templates/qt/qtextensionsconfig.flm +qtextensionsconfig.mk /epoc32/tools/makefile_templates/qt/qtextensionsconfig.mk +qtextensionsconfig.meta /epoc32/tools/makefile_templates/qt/qtextensionsconfig.meta + +../qtmobility/features/mobility.prf /epoc32/tools/qt/mkspecs/features/mobility.prf + +//For UDA image +../qtmobility/confml/qtmobility.confml CONFML_EXPORT_PATH(qtmobility.confml,uda_content) +../qtmobility/implml/qtmobility_copy.implml CRML_EXPORT_PATH(qtmobility_copy.implml,uda_content) +../qtmobility/data/qtmobility.sisx CRML_EXPORT_PATH(../content/sis/,uda_content) +../qtmobility/data/qtmobility_stub.sis /epoc32/data/z/system/install/qtmobility_stub.sis + +PRJ_MMPFILES + + +PRJ_TESTMMPFILES + + +PRJ_EXTENSIONS +START EXTENSION qt/qtextensionsconfig +OPTION MODULES bearer +OPTION TESTS -tests +OPTION EXAMPLES -examples +OPTION DOCS -no-docs +END + diff -r 000000000000 -r cfcbf08528c4 group/cmaker/config/export.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/group/cmaker/config/export.mk Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,37 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, version 2.1 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, +# see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". +# +# Description: makefile_templates, actual build configuration export makefile +# + +MAKEFILE = /sf/mw/qtextensions/group/cmaker/config/export.mk + + +$(call push,MAKEFILE_STACK,$(MAKEFILE)) + + +TEMPLATEMAKEFILES = /sf/mw/qtextensions/group/qtextensionsconfig.meta /epoc32/tools/makefile_templates/qt/ + + +template_makefiles :: template_makefiles_config + + +$(call addfiles, $(TEMPLATEMAKEFILES), template_makefiles_config) + + +$(call popout,MAKEFILE_STACK) + diff -r 000000000000 -r cfcbf08528c4 group/cmaker/makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/group/cmaker/makefile Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,27 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, version 2.1 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, +# see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". +# +# Description: exporting of *.meta file via cmaker +# + +MAKEFILE = /sf/mw/qtextensions/group/cmaker/makefile + +# Place the first target as the default target which is executed from this level + +export_template_files :: template_makefiles + +include include_template.mk diff -r 000000000000 -r cfcbf08528c4 group/qtextensionsconfig.flm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/group/qtextensionsconfig.flm Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,38 @@ +# /**************************************************************************** +# ** +# ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +# ** Contact: +# ** +# ****************************************************************************/ + +# FLM to configure QtMobility. + +QT_ROOT := $(EPOCROOT)/epoc32/tools/qt/ +QTMOBILITY_ROOT := $(subst group,,$(subst \,/,$(EXTENSION_ROOT)qtmobility/)) + +# Determine which platform we are building on +ifeq ($(OSTYPE),unix) +DOTBAT := +else +DOTBAT := .bat +endif + +define QtExtensionsConfiguration +QTMOBILITY: + $(call startrule,qtextensionsconf) \ + echo Configuring QtMobility && \ + echo EPOCROOT $(EPOCROOT) && \ + echo QT_ROOT $(QT_ROOT) && \ + echo QTMOBILITY_ROOT $(QTMOBILITY_ROOT) && \ + echo DOTBAT $(DOTBAT) && \ + echo MODULES $(MODULES) && \ + echo TESTS $(TESTS) && \ + echo EXAMPLES $(EXAMPLES) && \ + echo DOCS $(DOCS) && \ + cd $(QTMOBILITY_ROOT) && \ + $(QTMOBILITY_ROOT)configure$(DOTBAT) -qt $(QT_ROOT) -prefix $(QTMOBILITY_ROOT) -modules "$(MODULES)" $(TESTS) $(EXAMPLES) $(DOCS) \ + $(call endrule,qtextensionsconf) +endef + +ALL:: QTMOBILITY +$(eval $(call QtExtensionsConfiguration)) diff -r 000000000000 -r cfcbf08528c4 group/qtextensionsconfig.meta --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/group/qtextensionsconfig.meta Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,8 @@ +# Meta information for Python Py2exe +# +# Copyright (c) 2007 Symbian Software Ltd. All rights reserved. +# + +platform tools2 +makefile gnumake +techstream qt diff -r 000000000000 -r cfcbf08528c4 group/qtextensionsconfig.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/group/qtextensionsconfig.mk Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,75 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, version 2.1 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, +# see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". +# +# Description: +# + +# All paths used in this file end with the path delimiter '/' + +include $(EPOCROOT)epoc32/tools/shell/$(notdir $(basename $(SHELL))).mk + +EPOC_ROOT := $(subst \,/,$(EPOCROOT)) +QT_ROOT := $(EPOC_ROOT)epoc32/tools/qt/ +QTMOBILITY_ROOT := $(subst group,,$(subst \,/,$(EXTENSION_ROOT)qtmobility/)) + +# Determine which platform we are building on +ifeq ($(OSTYPE),unix) +DOTBAT := +else +QTMOBILITY_ROOT:= $(subst /,\,$(QTMOBILITY_ROOT)) +QT_ROOT:= $(subst /,\,$(QT_ROOT)) +DOTBAT := .bat +endif + +QTMOBILITY: + echo Configuring QtMobility + echo EPOCROOT $(EPOCROOT) + echo EPOC_ROOT $(EPOC_ROOT) + echo EXTENSION_ROOT $(EXTENSION_ROOT) + echo QT_ROOT $(QT_ROOT) + echo QTMOBILITY_ROOT $(QTMOBILITY_ROOT) + echo DOTBAT $(DOTBAT) + echo MODULES $(MODULES) + echo TESTS $(TESTS) + echo TESTS $(TESTS) + echo DOCS $(DOCS) + cd $(QTMOBILITY_ROOT) && $(QTMOBILITY_ROOT)configure$(DOTBAT) -qt $(QT_ROOT) -prefix $(QTMOBILITY_ROOT) -modules "$(MODULES)" $(TESTS) $(EXAMPLES) $(DOCS) + +do_nothing: + +MAKMAKE : do_nothing + +BLD : QTMOBILITY + +FINAL : do_nothing + +CLEAN : do_nothing + +RELEASABLES : do_nothing + +SAVESPACE : BLD + +FREEZE : do_nothing + +LIB : do_nothing + +CLEANLIB : do_nothing + +RESOURCE : do_nothing + + + diff -r 000000000000 -r cfcbf08528c4 group/qtextensionsconfig.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/group/qtextensionsconfig.xml Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 layers.sysdef.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/layers.sysdef.xml Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,27 @@ + + +]> + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtextensions.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtextensions.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,22 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, version 2.1 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, +# see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". +# +# Description: +# + +TEMPLATE = subdirs +SUBDIRS = qtmobility diff -r 000000000000 -r cfcbf08528c4 qtmobility/INSTALL.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/INSTALL.txt Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,1 @@ +Please refer to installation.html under doc/html. diff -r 000000000000 -r cfcbf08528c4 qtmobility/LGPL_EXCEPTION.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/LGPL_EXCEPTION.txt Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,22 @@ +Nokia Qt LGPL Exception version 1.1 + +As an additional permission to the GNU Lesser General Public License version +2.1, the object code form of a "work that uses the Library" may incorporate +material from a header file that is part of the Library. You may distribute +such object code under terms of your choice, provided that: + (i) the header files of the Library have not been modified; and + (ii) the incorporated material is limited to numerical parameters, data + structure layouts, accessors, macros, inline functions and + templates; and + (iii) you comply with the terms of Section 6 of the GNU Lesser General + Public License version 2.1. + +Moreover, you may apply this exception to a modified version of the Library, +provided that such modification does not involve copying material from the +Library into the modified Library's header files unless such material is +limited to (i) numerical parameters; (ii) data structure layouts; +(iii) accessors; and (iv) small macros, templates and inline functions of +five lines or less in length. + +Furthermore, you are not required to apply this additional permission to a +modified version of the Library. diff -r 000000000000 -r cfcbf08528c4 qtmobility/LICENSE.LGPL --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/LICENSE.LGPL Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/LICENSE.PREVIEW.COMMERCIAL --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/LICENSE.PREVIEW.COMMERCIAL Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,629 @@ +TECHNOLOGY PREVIEW LICENSE AGREEMENT + +For individuals and/or legal entities resident in the Americas (North +America, Central America and South America), the applicable licensing +terms are specified under the heading "Technology Preview License +Agreement: The Americas". + +For individuals and/or legal entities not resident in The Americas, the +applicable licensing terms are specified under the heading "Technology +Preview License Agreement: Rest of the World". + + +TECHNOLOGY PREVIEW LICENSE AGREEMENT: The Americas +Agreement version 2.4 + +This Technology Preview License Agreement ("Agreement") is a legal +agreement between Nokia Inc. ("Nokia"), with its registered office at +102 Corporate Park Drive, White Plains, N.Y., U.S.A. 10604 and you (either an +individual or a legal entity) ("Licensee") for the Licensed Software (as +defined below). + +1. DEFINITIONS + +"Affiliate" of a Party shall mean an entity (i) which is directly or +indirectly controlling such Party; (ii) which is under the same direct +or indirect ownership or control as such Party; or (iii) which is +directly or indirectly owned or controlled by such Party. For these +purposes, an entity shall be treated as being controlled by another if +that other entity has fifty percent (50 %) or more of the votes in such +entity, is able to direct its affairs and/or to control the composition +of its board of directors or equivalent body. + +"Applications" shall mean Licensee's software products created using the +Licensed Software which may include portions of the Licensed Software. + +"Term" shall mean the period of time six (6) months from the later of +(a) the Effective Date; or (b) the date the Licensed Software was +initially delivered to Licensee by Nokia. If no specific Effective Date +is set forth in the Agreement, the Effective Date shall be deemed to be +the date the Licensed Software was initially delivered to Licensee. + +"Licensed Software" shall mean the computer software, "online" or +electronic documentation, associated media and printed materials, +including the source code, example programs and the documentation +delivered by Nokia to Licensee in conjunction with this Agreement. + +"Party" or "Parties" shall mean Licensee and/or Nokia. + + +2. OWNERSHIP + +The Licensed Software is protected by copyright laws and international +copyright treaties, as well as other intellectual property laws and +treaties. The Licensed Software is licensed, not sold. + +If Licensee provides any findings, proposals, suggestions or other +feedback ("Feedback") to Nokia regarding the Licensed Software, Nokia +shall own all right, title and interest including the intellectual +property rights in and to such Feedback, excluding however any existing +patent rights of Licensee. To the extent Licensee owns or controls any +patents for such Feedback Licensee hereby grants to Nokia and its +Affiliates, a worldwide, perpetual, non-transferable, sublicensable, +royalty-free license to (i) use, copy and modify Feedback and to create +derivative works thereof, (ii) to make (and have made), use, import, +sell, offer for sale, lease, dispose, offer for disposal or otherwise +exploit any products or services of Nokia containing Feedback,, and +(iii) sublicense all the foregoing rights to third party licensees and +customers of Nokia and/or its Affiliates. + + +3. VALIDITY OF THE AGREEMENT + +By installing, copying, or otherwise using the Licensed Software, +Licensee agrees to be bound by the terms of this Agreement. If Licensee +does not agree to the terms of this Agreement, Licensee may not install, +copy, or otherwise use the Licensed Software. Upon Licensee's acceptance +of the terms and conditions of this Agreement, Nokia grants Licensee the +right to use the Licensed Software in the manner provided below. + + +4. LICENSES + +4.1. Using and Copying + +Nokia grants to Licensee a non-exclusive, non-transferable, time-limited +license to use and copy the Licensed Software for sole purpose of +designing, developing and testing Applications, and evaluating and the +Licensed Software during the Term. + +Licensee may install copies of the Licensed Software on an unlimited +number of computers provided that (a) if an individual, only such +individual; or (b) if a legal entity only its employees; use the +Licensed Software for the authorized purposes. + +4.2 No Distribution or Modifications + +Licensee may not disclose, modify, sell, market, commercialise, +distribute, loan, rent, lease, or license the Licensed Software or any +copy of it or use the Licensed Software for any purpose that is not +expressly granted in this Section 4. Licensee may not alter or remove +any details of ownership, copyright, trademark or other property right +connected with the Licensed Software. Licensee may not distribute any +software statically or dynamically linked with the Licensed Software. + +4.3 No Technical Support + +Nokia has no obligation to furnish Licensee with any technical support +whatsoever. Any such support is subject to separate agreement between +the Parties. + + +5. PRE-RELEASE CODE +The Licensed Software contains pre-release code that is not at the level +of performance and compatibility of a final, generally available, +product offering. The Licensed Software may not operate correctly and +may be substantially modified prior to the first commercial product +release, if any. Nokia is not obligated to make this or any later +version of the Licensed Software commercially available. The License +Software is "Not for Commercial Use" and may only be used for the +purposes described in Section 4. The Licensed Software may not be used +in a live operating environment where it may be relied upon to perform +in the same manner as a commercially released product or with data that +has not been sufficiently backed up. + +6. THIRD PARTY SOFTWARE + +The Licensed Software may provide links to third party libraries or code +(collectively "Third Party Software") to implement various functions. +Third Party Software does not comprise part of the Licensed Software. In +some cases, access to Third Party Software may be included along with +the Licensed Software delivery as a convenience for development and +testing only. Such source code and libraries may be listed in the +".../src/3rdparty" source tree delivered with the Licensed Software or +documented in the Licensed Software where the Third Party Software is +used, as may be amended from time to time, do not comprise the Licensed +Software. Licensee acknowledges (1) that some part of Third Party +Software may require additional licensing of copyright and patents from +the owners of such, and (2) that distribution of any of the Licensed +Software referencing any portion of a Third Party Software may require +appropriate licensing from such third parties. + + +7. LIMITED WARRANTY AND WARRANTY DISCLAIMER + +The Licensed Software is licensed to Licensee "as is". To the maximum +extent permitted by applicable law, Nokia on behalf of itself and its +suppliers, disclaims all warranties and conditions, either express or +implied, including, but not limited to, implied warranties of +merchantability, fitness for a particular purpose, title and +non-infringement with regard to the Licensed Software. + + +8. LIMITATION OF LIABILITY + +If, Nokia's warranty disclaimer notwithstanding, Nokia is held liable to +Licensee, whether in contract, tort or any other legal theory, based on +the Licensed Software, Nokia's entire liability to Licensee and +Licensee's exclusive remedy shall be, at Nokia's option, either (A) +return of the price Licensee paid for the Licensed Software, or (B) +repair or replacement of the Licensed Software, provided Licensee +returns to Nokia all copies of the Licensed Software as originally +delivered to Licensee. Nokia shall not under any circumstances be liable +to Licensee based on failure of the Licensed Software if the failure +resulted from accident, abuse or misapplication, nor shall Nokia under +any circumstances be liable for special damages, punitive or exemplary +damages, damages for loss of profits or interruption of business or for +loss or corruption of data. Any award of damages from Nokia to Licensee +shall not exceed the total amount Licensee has paid to Nokia in +connection with this Agreement. + + +9. CONFIDENTIALITY + +Each party acknowledges that during the Term of this Agreement it shall +have access to information about the other party's business, business +methods, business plans, customers, business relations, technology, and +other information, including the terms of this Agreement, that is +confidential and of great value to the other party, and the value of +which would be significantly reduced if disclosed to third parties (the +"Confidential Information"). Accordingly, when a party (the "Receiving +Party") receives Confidential Information from another party (the +"Disclosing Party"), the Receiving Party shall, and shall obligate its +employees and agents and employees and agents of its Affiliates to: (i) +maintain the Confidential Information in strict confidence; (ii) not +disclose the Confidential Information to a third party without the +Disclosing Party's prior written approval; and (iii) not, directly or +indirectly, use the Confidential Information for any purpose other than +for exercising its rights and fulfilling its responsibilities pursuant +to this Agreement. Each party shall take reasonable measures to protect +the Confidential Information of the other party, which measures shall +not be less than the measures taken by such party to protect its own +confidential and proprietary information. + +"Confidential Information" shall not include information that (a) is or +becomes generally known to the public through no act or omission of the +Receiving Party; (b) was in the Receiving Party's lawful possession +prior to the disclosure hereunder and was not subject to limitations on +disclosure or use; (c) is developed by the Receiving Party without +access to the Confidential Information of the Disclosing Party or by +persons who have not had access to the Confidential Information of the +Disclosing Party as proven by the written records of the Receiving +Party; (d) is lawfully disclosed to the Receiving Party without +restrictions, by a third party not under an obligation of +confidentiality; or (e) the Receiving Party is legally compelled to +disclose the information, in which case the Receiving Party shall assert +the privileged and confidential nature of the information and cooperate +fully with the Disclosing Party to protect against and prevent +disclosure of any Confidential Information and to limit the scope of +disclosure and the dissemination of disclosed Confidential Information +by all legally available means. + +The obligations of the Receiving Party under this Section shall continue +during the Initial Term and for a period of five (5) years after +expiration or termination of this Agreement. To the extent that the +terms of the Non-Disclosure Agreement between Nokia and Licensee +conflict with the terms of this Section 9, this Section 9 shall be +controlling over the terms of the Non-Disclosure Agreement. + + +10. GENERAL PROVISIONS + +10.1 No Assignment + +Licensee shall not be entitled to assign or transfer all or any of its +rights, benefits and obligations under this Agreement without the prior +written consent of Nokia, which shall not be unreasonably withheld. + +10.2 Termination + +Nokia may terminate the Agreement at any time immediately upon written +notice by Nokia to Licensee if Licensee breaches this Agreement. + +Upon termination of this Agreement, Licensee shall return to Nokia all +copies of Licensed Software that were supplied by Nokia. All other +copies of Licensed Software in the possession or control of Licensee +must be erased or destroyed. An officer of Licensee must promptly +deliver to Nokia a written confirmation that this has occurred. + +10.3 Surviving Sections + +Any terms and conditions that by their nature or otherwise reasonably +should survive a cancellation or termination of this Agreement shall +also be deemed to survive. Such terms and conditions include, but are +not limited to the following Sections: 2, 5, 6, 7, 8, 9, 10.2, 10.3, 10.4, +10.5, 10.6, 10.7, and 10.8 of this Agreement. + +10.4 Entire Agreement + +This Agreement constitutes the complete agreement between the parties +and supersedes all prior or contemporaneous discussions, +representations, and proposals, written or oral, with respect to the +subject matters discussed herein, with the exception of the +non-disclosure agreement executed by the parties in connection with this +Agreement ("Non-Disclosure Agreement"), if any, shall be subject to +Section 9. No modification of this Agreement shall be effective unless +contained in a writing executed by an authorized representative of each +party. No term or condition contained in Licensee's purchase order shall +apply unless expressly accepted by Nokia in writing. If any provision of +the Agreement is found void or unenforceable, the remainder shall remain +valid and enforceable according to its terms. If any remedy provided is +determined to have failed for its essential purpose, all limitations of +liability and exclusions of damages set forth in this Agreement shall +remain in effect. + +10.5 Export Control + +Licensee acknowledges that the Licensed Software may be subject to +export control restrictions of various countries. Licensee shall fully +comply with all applicable export license restrictions and requirements +as well as with all laws and regulations relating to the importation of +the Licensed Software and shall procure all necessary governmental +authorizations, including without limitation, all necessary licenses, +approvals, permissions or consents, where necessary for the +re-exportation of the Licensed Software., + +10.6 Governing Law and Legal Venue + +This Agreement shall be governed by and construed in accordance with the +federal laws of the United States of America and the internal laws of +the State of New York without given effect to any choice of law rule +that would result in the application of the laws of any other +jurisdiction. The United Nations Convention on Contracts for the +International Sale of Goods (CISG) shall not apply. Each Party (a) +hereby irrevocably submits itself to and consents to the jurisdiction of +the United States District Court for the Southern District of New York +(or if such court lacks jurisdiction, the state courts of the State of +New York) for the purposes of any action, claim, suit or proceeding +between the Parties in connection with any controversy, claim, or +dispute arising out of or relating to this Agreement; and (b) hereby +waives, and agrees not to assert by way of motion, as a defense or +otherwise, in any such action, claim, suit or proceeding, any claim that +is not personally subject to the jurisdiction of such court(s), that the +action, claim, suit or proceeding is brought in an inconvenient forum or +that the venue of the action, claim, suit or proceeding is improper. +Notwithstanding the foregoing, nothing in this Section 9.6 is intended +to, or shall be deemed to, constitute a submission or consent to, or +selection of, jurisdiction, forum or venue for any action for patent +infringement, whether or not such action relates to this Agreement. + +10.7 No Implied License + +There are no implied licenses or other implied rights granted under this +Agreement, and all rights, save for those expressly granted hereunder, +shall remain with Nokia and its licensors. In addition, no licenses or +immunities are granted to the combination of the Licensed Software with +any other software or hardware not delivered by Nokia under this +Agreement. + +10.8 Government End Users + +A "U.S. Government End User" shall mean any agency or entity of the +government of the United States. The following shall apply if Licensee +is a U.S. Government End User. The Licensed Software is a "commercial +item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), +consisting of "commercial computer software" and "commercial computer +software documentation," as such terms are used in 48 C.F.R. 12.212 +(Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 +through 227.7202-4 (June 1995), all U.S. Government End Users acquire +the Licensed Software with only those rights set forth herein. The +Licensed Software (including related documentation) is provided to U.S. +Government End Users: (a) only as a commercial end item; and (b) only +pursuant to this Agreement. + + + + + +TECHNOLOGY PREVIEW LICENSE AGREEMENT: Rest of the World +Agreement version 2.4 + +This Technology Preview License Agreement ("Agreement") is a legal +agreement between Nokia Corporation ("Nokia"), with its registered +office at Keilalahdentie 4, 02150 Espoo, Finland and you (either an +individual or a legal entity) ("Licensee") for the Licensed Software (as +defined below). + +1. DEFINITIONS + +"Affiliate" of a Party shall mean an entity (i) which is directly or +indirectly controlling such Party; (ii) which is under the same direct +or indirect ownership or control as such Party; or (iii) which is +directly or indirectly owned or controlled by such Party. For these +purposes, an entity shall be treated as being controlled by another if +that other entity has fifty percent (50 %) or more of the votes in such +entity, is able to direct its affairs and/or to control the composition +of its board of directors or equivalent body. + +"Applications" shall mean Licensee's software products created using the +Licensed Software which may include portions of the Licensed Software. + +"Term" shall mean the period of time six (6) months from the later of +(a) the Effective Date; or (b) the date the Licensed Software was +initially delivered to Licensee by Nokia. If no specific Effective Date +is set forth in the Agreement, the Effective Date shall be deemed to be +the date the Licensed Software was initially delivered to Licensee. + +"Licensed Software" shall mean the computer software, "online" or +electronic documentation, associated media and printed materials, +including the source code, example programs and the documentation +delivered by Nokia to Licensee in conjunction with this Agreement. + +"Party" or "Parties" shall mean Licensee and/or Nokia. + + +2. OWNERSHIP + +The Licensed Software is protected by copyright laws and international +copyright treaties, as well as other intellectual property laws and +treaties. The Licensed Software is licensed, not sold. + +If Licensee provides any findings, proposals, suggestions or other +feedback ("Feedback") to Nokia regarding the Licensed Software, Nokia +shall own all right, title and interest including the intellectual +property rights in and to such Feedback, excluding however any existing +patent rights of Licensee. To the extent Licensee owns or controls any +patents for such Feedback Licensee hereby grants to Nokia and its +Affiliates, a worldwide, perpetual, non-transferable, sublicensable, +royalty-free license to (i) use, copy and modify Feedback and to create +derivative works thereof, (ii) to make (and have made), use, import, +sell, offer for sale, lease, dispose, offer for disposal or otherwise +exploit any products or services of Nokia containing Feedback,, and +(iii) sublicense all the foregoing rights to third party licensees and +customers of Nokia and/or its Affiliates. + +3. VALIDITY OF THE AGREEMENT + +By installing, copying, or otherwise using the Licensed Software, +Licensee agrees to be bound by the terms of this Agreement. If Licensee +does not agree to the terms of this Agreement, Licensee may not install, +copy, or otherwise use the Licensed Software. Upon Licensee's acceptance +of the terms and conditions of this Agreement, Nokia grants Licensee the +right to use the Licensed Software in the manner provided below. + + +4. LICENSES + +4.1. Using and Copying + +Nokia grants to Licensee a non-exclusive, non-transferable, time-limited +license to use and copy the Licensed Software for sole purpose of +designing, developing and testing Applications, and evaluating and the +Licensed Software during the Term. + +Licensee may install copies of the Licensed Software on an unlimited +number of computers provided that (a) if an individual, only such +individual; or (b) if a legal entity only its employees; use the +Licensed Software for the authorized purposes. + +4.2 No Distribution or Modifications + +Licensee may not disclose, modify, sell, market, commercialise, +distribute, loan, rent, lease, or license the Licensed Software or any +copy of it or use the Licensed Software for any purpose that is not +expressly granted in this Section 4. Licensee may not alter or remove +any details of ownership, copyright, trademark or other property right +connected with the Licensed Software. Licensee may not distribute any +software statically or dynamically linked with the Licensed Software. + +4.3 No Technical Support + +Nokia has no obligation to furnish Licensee with any technical support +whatsoever. Any such support is subject to separate agreement between +the Parties. + + +5. PRE-RELEASE CODE + +The Licensed Software contains pre-release code that is not at the level +of performance and compatibility of a final, generally available, +product offering. The Licensed Software may not operate correctly and +may be substantially modified prior to the first commercial product +release, if any. Nokia is not obligated to make this or any later +version of the Licensed Software commercially available. The License +Software is "Not for Commercial Use" and may only be used for the +purposes described in Section 4. The Licensed Software may not be used +in a live operating environment where it may be relied upon to perform +in the same manner as a commercially released product or with data that +has not been sufficiently backed up. + +6. THIRD PARTY SOFTWARE + +The Licensed Software may provide links to third party libraries or code +(collectively "Third Party Software") to implement various functions. +Third Party Software does not comprise part of the Licensed Software. In +some cases, access to Third Party Software may be included along with +the Licensed Software delivery as a convenience for development and +testing only. Such source code and libraries may be listed in the +".../src/3rdparty" source tree delivered with the Licensed Software or +documented in the Licensed Software where the Third Party Software is +used, as may be amended from time to time, do not comprise the Licensed +Software. Licensee acknowledges (1) that some part of Third Party +Software may require additional licensing of copyright and patents from +the owners of such, and (2) that distribution of any of the Licensed +Software referencing any portion of a Third Party Software may require +appropriate licensing from such third parties. + + +7. LIMITED WARRANTY AND WARRANTY DISCLAIMER + +The Licensed Software is licensed to Licensee "as is". To the maximum +extent permitted by applicable law, Nokia on behalf of itself and its +suppliers, disclaims all warranties and conditions, either express or +implied, including, but not limited to, implied warranties of +merchantability, fitness for a particular purpose, title and +non-infringement with regard to the Licensed Software. + + +8. LIMITATION OF LIABILITY + +If, Nokia's warranty disclaimer notwithstanding, Nokia is held liable to +Licensee, whether in contract, tort or any other legal theory, based on +the Licensed Software, Nokia's entire liability to Licensee and +Licensee's exclusive remedy shall be, at Nokia's option, either (A) +return of the price Licensee paid for the Licensed Software, or (B) +repair or replacement of the Licensed Software, provided Licensee +returns to Nokia all copies of the Licensed Software as originally +delivered to Licensee. Nokia shall not under any circumstances be liable +to Licensee based on failure of the Licensed Software if the failure +resulted from accident, abuse or misapplication, nor shall Nokia under +any circumstances be liable for special damages, punitive or exemplary +damages, damages for loss of profits or interruption of business or for +loss or corruption of data. Any award of damages from Nokia to Licensee +shall not exceed the total amount Licensee has paid to Nokia in +connection with this Agreement. + + +9. CONFIDENTIALITY + +Each party acknowledges that during the Term of this Agreement it shall +have access to information about the other party's business, business +methods, business plans, customers, business relations, technology, and +other information, including the terms of this Agreement, that is +confidential and of great value to the other party, and the value of +which would be significantly reduced if disclosed to third parties (the +"Confidential Information"). Accordingly, when a party (the "Receiving +Party") receives Confidential Information from another party (the +"Disclosing Party"), the Receiving Party shall, and shall obligate its +employees and agents and employees and agents of its Affiliates to: (i) +maintain the Confidential Information in strict confidence; (ii) not +disclose the Confidential Information to a third party without the +Disclosing Party's prior written approval; and (iii) not, directly or +indirectly, use the Confidential Information for any purpose other than +for exercising its rights and fulfilling its responsibilities pursuant +to this Agreement. Each party shall take reasonable measures to protect +the Confidential Information of the other party, which measures shall +not be less than the measures taken by such party to protect its own +confidential and proprietary information. + +"Confidential Information" shall not include information that (a) is or +becomes generally known to the public through no act or omission of the +Receiving Party; (b) was in the Receiving Party's lawful possession +prior to the disclosure hereunder and was not subject to limitations on +disclosure or use; (c) is developed by the Receiving Party without +access to the Confidential Information of the Disclosing Party or by +persons who have not had access to the Confidential Information of the +Disclosing Party as proven by the written records of the Receiving +Party; (d) is lawfully disclosed to the Receiving Party without +restrictions, by a third party not under an obligation of +confidentiality; or (e) the Receiving Party is legally compelled to +disclose the information, in which case the Receiving Party shall assert +the privileged and confidential nature of the information and cooperate +fully with the Disclosing Party to protect against and prevent +disclosure of any Confidential Information and to limit the scope of +disclosure and the dissemination of disclosed Confidential Information +by all legally available means. + +The obligations of the Receiving Party under this Section shall continue +during the Initial Term and for a period of five (5) years after +expiration or termination of this Agreement. To the extent that the +terms of the Non-Disclosure Agreement between Nokia and Licensee +conflict with the terms of this Section 9, this Section 9 shall be +controlling over the terms of the Non-Disclosure Agreement. + + +10. GENERAL PROVISIONS + +10.1 No Assignment + +Licensee shall not be entitled to assign or transfer all or any of its +rights, benefits and obligations under this Agreement without the prior +written consent of Nokia, which shall not be unreasonably withheld. + +10.2 Termination + +Nokia may terminate the Agreement at any time immediately upon written +notice by Nokia to Licensee if Licensee breaches this Agreement. + +Upon termination of this Agreement, Licensee shall return to Nokia all +copies of Licensed Software that were supplied by Nokia. All other +copies of Licensed Software in the possession or control of Licensee +must be erased or destroyed. An officer of Licensee must promptly +deliver to Nokia a written confirmation that this has occurred. + +10.3 Surviving Sections + +Any terms and conditions that by their nature or otherwise reasonably +should survive a cancellation or termination of this Agreement shall +also be deemed to survive. Such terms and conditions include, but are +not limited to the following Sections: 2, 5, 6, 7, 8, 9, 10.2, 10.3, 10.4, +10.5, 10.6, 10.7, and 10.8 of this Agreement. + +10.4 Entire Agreement + +This Agreement constitutes the complete agreement between the parties +and supersedes all prior or contemporaneous discussions, +representations, and proposals, written or oral, with respect to the +subject matters discussed herein, with the exception of the +non-disclosure agreement executed by the parties in connection with this +Agreement ("Non-Disclosure Agreement"), if any, shall be subject to +Section 9. No modification of this Agreement shall be effective unless +contained in a writing executed by an authorized representative of each +party. No term or condition contained in Licensee's purchase order shall +apply unless expressly accepted by Nokia in writing. If any provision of +the Agreement is found void or unenforceable, the remainder shall remain +valid and enforceable according to its terms. If any remedy provided is +determined to have failed for its essential purpose, all limitations of +liability and exclusions of damages set forth in this Agreement shall +remain in effect. + +10.5 Export Control + +Licensee acknowledges that the Licensed Software may be subject to +export control restrictions of various countries. Licensee shall fully +comply with all applicable export license restrictions and requirements +as well as with all laws and regulations relating to the importation of +the Licensed Software and shall procure all necessary governmental +authorizations, including without limitation, all necessary licenses, +approvals, permissions or consents, where necessary for the +re-exportation of the Licensed Software., + +10.6 Governing Law and Legal Venue + +This Agreement shall be construed and interpreted in accordance with the +laws of Finland, excluding its choice of law provisions. Any disputes +arising out of or relating to this Agreement shall be resolved in +arbitration under the Rules of Arbitration of the Chamber of Commerce of +Helsinki, Finland. The arbitration tribunal shall consist of one (1), or +if either Party so requires, of three (3), arbitrators. The award shall +be final and binding and enforceable in any court of competent +jurisdiction. The arbitration shall be held in Helsinki, Finland and the +process shall be conducted in the English language. + +10.7 No Implied License + +There are no implied licenses or other implied rights granted under this +Agreement, and all rights, save for those expressly granted hereunder, +shall remain with Nokia and its licensors. In addition, no licenses or +immunities are granted to the combination of the Licensed Software with +any other software or hardware not delivered by Nokia under this +Agreement. + +10.8 Government End Users + +A "U.S. Government End User" shall mean any agency or entity of the +government of the United States. The following shall apply if Licensee +is a U.S. Government End User. The Licensed Software is a "commercial +item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), +consisting of "commercial computer software" and "commercial computer +software documentation," as such terms are used in 48 C.F.R. 12.212 +(Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 +through 227.7202-4 (June 1995), all U.S. Government End Users acquire +the Licensed Software with only those rights set forth herein. The +Licensed Software (including related documentation) is provided to U.S. +Government End Users: (a) only as a commercial end item; and (b) only +pursuant to this Agreement. + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/bin/purge.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/bin/purge.sh Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,46 @@ +#!/bin/bash +############################################################################# +## +## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +## All rights reserved. +## Contact: Nokia Corporation (qt-info@nokia.com) +## +## This file is part of the Qt Mobility Components. +## +## $QT_BEGIN_LICENSE:LGPL$ +## No Commercial Usage +## This file contains pre-release code and may not be distributed. +## You may use this file in accordance with the terms and conditions +## contained in the Technology Preview License Agreement accompanying +## this package. +## +## GNU Lesser General Public License Usage +## Alternatively, this file may be used under the terms of the GNU Lesser +## General Public License version 2.1 as published by the Free Software +## Foundation and appearing in the file LICENSE.LGPL included in the +## packaging of this file. Please review the following information to +## ensure the GNU Lesser General Public License version 2.1 requirements +## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +## +## In addition, as a special exception, Nokia gives you certain additional +## rights. These rights are described in the Nokia Qt LGPL Exception +## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +## +## If you have questions regarding the use of this file, please contact +## Nokia at qt-info@nokia.com. +## +## +## +## +## +## +## +## +## $QT_END_LICENSE$ +## +############################################################################# + +make clean +rm -f config.pri +find . -name "Makefile*" |xargs rm +rm -rf build include install bin/examples lib diff -r 000000000000 -r cfcbf08528c4 qtmobility/bin/rununittests.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/bin/rununittests.bat Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,55 @@ +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +:: All rights reserved. +:: Contact: Nokia Corporation (qt-info@nokia.com) +:: +:: This file is part of the Qt Mobility Components. +:: +:: $QT_BEGIN_LICENSE:LGPL$ +:: No Commercial Usage +:: This file contains pre-release code and may not be distributed. +:: You may use this file in accordance with the terms and conditions +:: contained in the Technology Preview License Agreement accompanying +:: this package. +:: +:: GNU Lesser General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU Lesser +:: General Public License version 2.1 as published by the Free Software +:: Foundation and appearing in the file LICENSE.LGPL included in the +:: packaging of this file. Please review the following information to +:: ensure the GNU Lesser General Public License version 2.1 requirements +:: will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +:: +:: In addition, as a special exception, Nokia gives you certain additional +:: rights. These rights are described in the Nokia Qt LGPL Exception +:: version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +:: +:: If you have questions regarding the use of this file, please contact +:: Nokia at qt-info@nokia.com. +:: +:: +:: +:: +:: +:: +:: +:: +:: $QT_END_LICENSE$ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +set SAVED_PWD="%CD%" +set BATCH_PATH=%~dp0 + +set PATH=%BATCH_PATH%..\lib;%PATH% + +cd %BATCH_PATH%..\build\tests\bin + +::BearerManagement +tst_qnetworkconfiguration.exe +tst_qnetworkconfigurationmanager.exe +tst_qnetworksession.exe + +cd %SAVED_PWD% + diff -r 000000000000 -r cfcbf08528c4 qtmobility/bin/rununittests.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/bin/rununittests.sh Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,64 @@ +#!/bin/bash +############################################################################# +## +## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +## All rights reserved. +## Contact: Nokia Corporation (qt-info@nokia.com) +## +## This file is part of the Qt Mobility Components. +## +## $QT_BEGIN_LICENSE:LGPL$ +## No Commercial Usage +## This file contains pre-release code and may not be distributed. +## You may use this file in accordance with the terms and conditions +## contained in the Technology Preview License Agreement accompanying +## this package. +## +## GNU Lesser General Public License Usage +## Alternatively, this file may be used under the terms of the GNU Lesser +## General Public License version 2.1 as published by the Free Software +## Foundation and appearing in the file LICENSE.LGPL included in the +## packaging of this file. Please review the following information to +## ensure the GNU Lesser General Public License version 2.1 requirements +## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +## +## In addition, as a special exception, Nokia gives you certain additional +## rights. These rights are described in the Nokia Qt LGPL Exception +## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +## +## If you have questions regarding the use of this file, please contact +## Nokia at qt-info@nokia.com. +## +## +## +## +## +## +## +## +## $QT_END_LICENSE$ +## +############################################################################# + +#convenient script to execute all unit tests + +shell=`readlink -f "$0"`; +shell_path=`dirname $shell`; + +SAVED_PWD=$PWD; +if [ ! -d "$shell_path/../build/tests/bin" ]; then + echo -e 'Unit tests have not been built.' + echo -e 'Please run configure with the -tests switch.' + exit +fi +cd $shell_path/../build/tests/bin + +#LD_LIBRARY_PATH=$shell_path/../lib:$LD_LIBRARY_PATH + +#BearerManagement +./tst_qnetworkconfiguration +./tst_qnetworkconfigurationmanager +./tst_qnetworksession + +cd $SAVED_PWD + diff -r 000000000000 -r cfcbf08528c4 qtmobility/bin/syncheaders --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/bin/syncheaders Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,110 @@ +#!/usr/bin/perl +############################################################################# +## +## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +## All rights reserved. +## Contact: Nokia Corporation (qt-info@nokia.com) +## +## This file is part of the Qt Mobility Components. +## +## $QT_BEGIN_LICENSE:LGPL$ +## No Commercial Usage +## This file contains pre-release code and may not be distributed. +## You may use this file in accordance with the terms and conditions +## contained in the Technology Preview License Agreement accompanying +## this package. +## +## GNU Lesser General Public License Usage +## Alternatively, this file may be used under the terms of the GNU Lesser +## General Public License version 2.1 as published by the Free Software +## Foundation and appearing in the file LICENSE.LGPL included in the +## packaging of this file. Please review the following information to +## ensure the GNU Lesser General Public License version 2.1 requirements +## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +## +## In addition, as a special exception, Nokia gives you certain additional +## rights. These rights are described in the Nokia Qt LGPL Exception +## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +## +## If you have questions regarding the use of this file, please contact +## Nokia at qt-info@nokia.com. +## +## +## +## +## +## +## +## +## $QT_END_LICENSE$ +## +############################################################################# + +use strict; +use warnings; + +use File::Basename; +use File::stat; +use File::Path; + +my $allow_non_exported = 1; +if ( @ARGV && $ARGV[0] eq "-needs-export" ) { + shift(@ARGV); + $allow_non_exported = 0; +} + +my $outdir = shift(@ARGV) or usage(); +mkpath($outdir); + +my $indir = shift(@ARGV) or usage(); +processFile($indir); + +exit 0; + +sub usage +{ + print "Usage: syncheaders [-needs-export] outdir indir\n"; + print " Processes all public header files \n"; + exit 2; +} + +sub processFile +{ + my ( $read_dir ) = @_; + my @allFiles; + my $filename; + + opendir( THISDIR, $read_dir) or die "Can't read $read_dir"; + #process all header files + @allFiles = grep /\.h/, readdir THISDIR; + #don't include private headers + @allFiles = grep !/_p\.h/, @allFiles; + + for $filename (@allFiles) { + open INPUT, "$indir/$filename" or die "Can't read $filename"; + + my $src_s = stat("$indir/$filename"); + my $now = $src_s->mtime; + + while () { + if ( /^\s*class\s+.*_EXPORT\s+([^\s:]+)/ || + ($allow_non_exported && /^\s*class\s+([^\s:<]+)/ && index($_, ";") == -1) || + /syncqtopia\s+header\s+([^\s:]+)/ ) + { + # Skip preprocessor-related items + next if ( $1 =~ /#/ ); + + my $outfile = "$outdir/$1"; + + print "Create header $outfile\n"; + + #system("install", "-m", "0644", $filename, $outfile); + open OUT, ">$outfile" or die "Can't write $outfile"; + print OUT "#include \"".basename($filename)."\"\n"; + close OUT; + } + } + close INPUT; + } +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/bin/syncheaders.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/bin/syncheaders.bat Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,40 @@ +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +:: All rights reserved. +:: Contact: Nokia Corporation (qt-info@nokia.com) +:: +:: This file is part of the Qt Mobility Components. +:: +:: $QT_BEGIN_LICENSE:LGPL$ +:: No Commercial Usage +:: This file contains pre-release code and may not be distributed. +:: You may use this file in accordance with the terms and conditions +:: contained in the Technology Preview License Agreement accompanying +:: this package. +:: +:: GNU Lesser General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU Lesser +:: General Public License version 2.1 as published by the Free Software +:: Foundation and appearing in the file LICENSE.LGPL included in the +:: packaging of this file. Please review the following information to +:: ensure the GNU Lesser General Public License version 2.1 requirements +:: will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +:: +:: In addition, as a special exception, Nokia gives you certain additional +:: rights. These rights are described in the Nokia Qt LGPL Exception +:: version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +:: +:: If you have questions regarding the use of this file, please contact +:: Nokia at qt-info@nokia.com. +:: +:: +:: +:: +:: +:: +:: +:: +:: $QT_END_LICENSE$ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: diff -r 000000000000 -r cfcbf08528c4 qtmobility/common.pri --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/common.pri Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,175 @@ +###################################################################### +# +# Mobility API project - common QMake settings +# +###################################################################### + + +CONFIG(debug, debug|release) { + WAS_IN_DEBUG=debug +} else { + WAS_IN_DEBUG=release +} + +include(staticconfig.pri) + +mac { + contains(QT_CONFIG, qt_framework):contains(TEMPLATE, lib) { + #MacOSX always builds debug and release libs when using mac framework + CONFIG+=$$WAS_IN_DEBUG + CONFIG += debug_and_release build_all + } else { + !contains(QT_CONFIG,debug)|!contains(QT_CONFIG,release) { + CONFIG -= debug_and_release debug release + contains(QT_CONFIG,debug): CONFIG+=debug + contains(QT_CONFIG,release): CONFIG+=release + } + } +} + +#In Windows we want to build libraries in debug and release mode if the user +#didn't select a version - if Qt is build in debug_and_release +#this avoids problems for third party as qmake build debug by default +#If mobility selected debug_and_release but Qt only supports +#one version but not the other we slently disable the impossible combination +win32:contains(CONFIG_WIN32,build_all) { + contains(QT_CONFIG,debug):contains(QT_CONFIG,release) { + contains(TEMPLATE,.*lib):!plugin { + CONFIG += $$WAS_IN_DEBUG + CONFIG += debug_and_release build_all + } + } else { + CONFIG -= debug_and_release debug release + contains(QT_CONFIG,debug): CONFIG+=debug + contains(QT_CONFIG,release): CONFIG+=release + } +} + +# Helper function. This should move to a .prf file +defineReplace(mobilityDeployFilename) { + unset(MOBILITY_DEPLOY_NAME) + MOBILITY_DEPLOY_NAME = $$1 + CONFIG(debug, debug|release): { + mac:RET = $$member(MOBILITY_DEPLOY_NAME, 0)_debug + else:win32:RET = $$member(MOBILITY_DEPLOY_NAME, 0)d + } + isEmpty(RET):RET = $$MOBILITY_DEPLOY_NAME + return($$RET) +} + +# Make sure this goes everywhere we need it +symbian: load(data_caging_paths) + + +# Figure out the root of where stuff should go (this could be done via configure) +OUTPUT_DIR = $$QT_MOBILITY_BUILD_TREE +SOURCE_DIR = $$PWD + +CONFIG(debug, debug|release) { + SUBDIRPART=Debug +} else { + SUBDIRPART=Release +} + +contains(QT_CONFIG, reduce_exports):CONFIG+=hide_symbols + +#export more symbols if we build the unit tests +#contains(build_unit_tests, yes):DEFINES+=QTM_BUILD_UNITTESTS + +#test whether we have a unit test +!testcase { + OBJECTS_DIR = $$OUTPUT_DIR/build/$$SUBDIRPART/$$TARGET + !plugin { + contains(TEMPLATE,.*lib) { + DESTDIR = $$OUTPUT_DIR/lib + symbian:defFilePath=../s60installs + } else { + DESTDIR = $$OUTPUT_DIR/bin + } + } else { + testplugin:DESTDIR = $$OUTPUT_DIR/build/tests/bin/plugins/$$PLUGIN_TYPE + !testplugin:DESTDIR = $$OUTPUT_DIR/plugins/$$PLUGIN_TYPE + } + + MOC_DIR = $$OUTPUT_DIR/build/$$SUBDIRPART/$$TARGET/moc + RCC_DIR = $$OUTPUT_DIR/build/$$SUBDIRPART/$$TARGET/rcc + UI_DIR = $$OUTPUT_DIR/build/$$SUBDIRPART/$$TARGET/ui + QMAKE_RPATHDIR += $$QT_MOBILITY_LIB +} else { + # Unit test code (no plugins! test plugins are just normal plugins installed elsewhere) + QT *= testlib + CONFIG += console + CONFIG -= app_bundle + OBJECTS_DIR = $$OUTPUT_DIR/build/tests/$$SUBDIRPART/$$TARGET + DESTDIR = $$OUTPUT_DIR/build/tests/bin + MOC_DIR = $$OUTPUT_DIR/build/tests/$$SUBDIRPART/$$TARGET/moc + RCC_DIR = $$OUTPUT_DIR/build/tests/$$SUBDIRPART/$$TARGET/rcc + UI_DIR = $$OUTPUT_DIR/build/tests/$$SUBDIRPART/$$TARGET/ui + QMAKE_RPATHDIR += $$OUTPUT_DIR/lib +} + +# On Symbian, we are freezing libraryies only +#symbian:!isEmpty(defFilePath) { +# MMP_RULES += "EXPORTUNFROZEN" +#} + +contains(TEMPLATE,.*lib):DEFINES += QT_SHARED + +maemo6 { + DEFINES+= Q_WS_MAEMO_6 + contains(TEMPLATE,.*app.*): QMAKE_LIB_FLAGS+= -Wl,-rpath-link $$[QT_INSTALL_LIBS] + QMAKE_LIB_FLAGS+= -Wl,-rpath-link $$[QT_INSTALL_LIBS] + QMAKE_RPATHDIR += $$[QT_INSTALL_LIBS] +} +maemo5 { + DEFINES+= Q_WS_MAEMO_5 +} +maemo* { + LIBS += -L/opt/qt4-maemo5/lib + QMAKE_LFLAGS += -Wl,-rpath,/opt/qt4-maemo5/lib +} + +wince* { + ### Bearer Management + BEARERLIB.sources = $$OUTPUT_DIR/lib/$$mobilityDeployFilename(QtBearer).dll + BEARERLIB.path = . + DEPLOYMENT += BEARERLIB + + ### Contacts + # Main library + CONTACTS_DEPLOYMENT.sources = $$OUTPUT_DIR/lib/$$mobilityDeployFilename(QtContacts).dll + CONTACTS_DEPLOYMENT.path = /Windows + + # Plugins + CONTACTS_PLUGINS_DEPLOYMENT.sources = $$OUTPUT_DIR/plugins/contacts/*.dll + CONTACTS_PLUGINS_DEPLOYMENT.path = plugins/contacts + DEPLOYMENT += CONTACTS_DEPLOYMENT CONTACTS_PLUGINS_DEPLOYMENT + + ### Service Framework + SFW_DEPLOYMENT.sources = $$OUTPUT_DIR/lib/$$mobilityDeployFilename(QtServiceFramework).dll + SFW_DEPLOYMENT.path = . + DEPLOYMENT += SFW_DEPLOYMENT + + ### Location + LOCATION.sources = $$OUTPUT_DIR/lib/$$mobilityDeployFilename(QtLocation).dll + LOCATION.path = . + DEPLOYMENT += LOCATION +} + +symbian { + #For some reason the default include path doesn't include MOC_DIR on symbian + INCLUDEPATH += $$MOC_DIR +} + +# Add the output dirs to the link path too +mac:contains(QT_CONFIG,qt_framework) { + #add framework option + ##contains(TEMPLATE, app)|contains(CONFIG,plugin):LIBS+=-F$$OUTPUT_DIR/lib + LIBS+=-F$$OUTPUT_DIR/lib +} +LIBS += -L$$OUTPUT_DIR/lib + + +DEPENDPATH += . $$SOURCE_DIR +INCLUDEPATH += $$SOURCE_DIR/src/global + diff -r 000000000000 -r cfcbf08528c4 qtmobility/configure --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/configure Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,446 @@ +#!/bin/sh +############################################################################# +## +## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +## All rights reserved. +## Contact: Nokia Corporation (qt-info@nokia.com) +## +## This file is part of the Qt Mobility Components. +## +## $QT_BEGIN_LICENSE:LGPL$ +## No Commercial Usage +## This file contains pre-release code and may not be distributed. +## You may use this file in accordance with the terms and conditions +## contained in the Technology Preview License Agreement accompanying +## this package. +## +## GNU Lesser General Public License Usage +## Alternatively, this file may be used under the terms of the GNU Lesser +## General Public License version 2.1 as published by the Free Software +## Foundation and appearing in the file LICENSE.LGPL included in the +## packaging of this file. Please review the following information to +## ensure the GNU Lesser General Public License version 2.1 requirements +## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +## +## In addition, as a special exception, Nokia gives you certain additional +## rights. These rights are described in the Nokia Qt LGPL Exception +## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +## +## If you have questions regarding the use of this file, please contact +## Nokia at qt-info@nokia.com. +## +## +## +## +## +## +## +## +## $QT_END_LICENSE$ +## +############################################################################# + +# the current directory (shadow build dir) +shadowpath=`/bin/pwd` +# the name of this script +relconf=`basename $0` +# the directory of this script is the "source tree" +relpath=`dirname $0` +relpath=`(cd "$relpath"; /bin/pwd)` + +CONFIG_IN="$shadowpath/config.in" +QT_MOBILITY_PREFIX=$shadowpath/install +QT_MOBILITY_INCLUDE= +QT_MOBILITY_LIB= +QT_MOBILITY_BIN= +BUILD_UNITTESTS= +BUILD_EXAMPLES= +BUILD_DOCS=yes +RELEASEMODE= +BUILD_SILENT= +LINUX_TARGET= +QMAKE_CACHE="$shadowpath/.qmake.cache" +LIB_PATH="lib" +BIN_PATH="bin" +MAC_SDK= +MOBILITY_MODULES="bearer location contacts multimedia publishsubscribe versit messaging systeminfo serviceframework sensors" +MOBILITY_MODULES_UNPARSED= + +usage() +{ + echo "Usage: configure [-prefix ] [headerdir ] [libdir ]" + echo " [-bindir ] [-tests] [-examples] [-no-docs]" + echo " [-debug] [-release] [-silent] [-modules ]" + echo + echo "Options:" + echo + echo "-prefix ..... This will install everything relative to " + echo " (default prefix: $shadowpath/install)" + echo "-headerdir .. Header files will be installed to " + echo " (default prefix: PREFIX/include)" + echo "-libdir ..... Libraries will be installed to " + echo " (default PREFIX/lib)" + echo "-bindir ..... Executables will be installed to " + echo " (default PREFIX/bin)" + echo "-debug ............ Build with debugging symbols" + echo "-release .......... Build without debugging symbols" + echo "-silent ........... Reduces build output" + echo "-tests ............ Build unit tests (not build by default)" + echo " Note, this adds test symbols to all libraries" + echo " and should not be used for release builds." + echo "-examples ......... Build example applications" + echo "-no-docs .......... Do not build documentation (build by default)" + echo "-modules ... Restrict list of modules to build (default all supported)" + echo " Choose from: bearer contacts location publishsubscribe" + echo " messaging multimedia systeminfo serviceframework versit" + echo " sensors" + echo " Modules should be separated by a space and surrounded" + echo " by double quotation. If a" + echo " selected module depends on other modules dependencies" + echo " will automatically be enabled." + echo "-maemo6 ........... Build Qt Mobility for Maemo6 (Harmattan)." + echo "-maemo5 ........... Build Qt Mobility for Maemo5 (Freemantle)." + echo "-sdk ..........Build using Apple provided SDK ." + echo " example: -sdk /Developer/SDKs/MacOSX10.6.sdk" + echo + + rm -f "$CONFIG_IN" + exit 1 +} + +rm -rf "$QMAKE_CACHE" +CONFIG_LOG="$shadowpath/config.log" +rm -rf "$CONFIG_LOG" + +while [ "$#" -gt 0 ]; do + case "$1" in + -h|-help|--help) + usage + ;; + -headerdir) + QT_MOBILITY_INCLUDE="$2" + shift + ;; + -libdir) + QT_MOBILITY_LIB="$2" + shift + ;; + --prefix|-prefix) + QT_MOBILITY_PREFIX="$2" + shift + ;; + -bindir) + QT_MOBILITY_BIN="$2" + shift + ;; + -tests) + BUILD_UNITTESTS="yes" + ;; + -examples) + BUILD_EXAMPLES="yes" + ;; + -no-docs) + BUILD_DOCS= + ;; + -debug) + RELEASEMODE=debug + ;; + -release) + RELEASEMODE=release + ;; + -silent) + BUILD_SILENT=yes + ;; + -maemo5) + LINUX_TARGET=maemo5 + ;; + -maemo6) + LINUX_TARGET=maemo6 + ;; + -sdk) + MAC_SDK="$2" + shift + ;; + -modules) + MOBILITY_MODULES_UNPARSED=$2 + #reset default selection + MOBILITY_MODULES= + for m in $MOBILITY_MODULES_UNPARSED; do + case "$m" in + bearer|contacts|location|messaging|multimedia|publishsubscribe|serviceframework|systeminfo|versit|sensors) + MOBILITY_MODULES="$MOBILITY_MODULES $m"; + ;; + *) + echo "Unknown module: $m" + echo + usage + ;; + + esac + done + if [ -z "$MOBILITY_MODULES" ]; then + echo "List of selected modules is empty." + echo + usage + fi + shift + ;; + *) + echo "Unknown option: $1" + usage + ;; + esac + shift +done + +findframeworks() +{ +# figure out if Qt was built with frameworks +# if so, install in the correct place. +# and fix rpath + echo "contains(QT_CONFIG,qt_framework):message(1)" > 1.pro + SOMETHING=`qmake 1.pro 2>&1` + if [ "$SOMETHING" = "Project MESSAGE: 1" ]; then + LIB_PATH="Library/Frameworks" + BIN_PATH="Applications" + fi + rm 1.pro +} + +findframeworks + +if [ -n "$BUILD_SILENT" ]; then + echo "CONFIG += silent" > "$CONFIG_IN" +fi + +if [ -z "$RELEASEMODE" ]; then + RELEASEMODE="debug" +fi +echo "CONFIG += $RELEASEMODE" >> "$CONFIG_IN" + +#do we build for Maemo? +if [ -n "$LINUX_TARGET" ]; then + if [ "$LINUX_TARGET" = "maemo5" ]; then + echo "CONFIG+=maemo5" >> "$CONFIG_IN" + elif [ "$LINUX_TARGET" = "maemo6" ]; then + echo "CONFIG+=maemo6" >> "$CONFIG_IN" + fi +fi + +#process PREFIX +if [ -d "$QT_MOBILITY_PREFIX" ]; then + QT_MOBILITY_PREFIX=`(cd "$QT_MOBILITY_PREFIX"; /bin/pwd)` +else + mkdir -p "$QT_MOBILITY_PREFIX" + absPath=`(cd "$QT_MOBILITY_PREFIX"; /bin/pwd)` + rm -rf "$QT_MOBILITY_PREFIX" + QT_MOBILITY_PREFIX="$absPath" +fi +echo "QT_MOBILITY_PREFIX = $QT_MOBILITY_PREFIX" >> "$CONFIG_IN" + +#process include path +if [ -z "$QT_MOBILITY_INCLUDE" ]; then + QT_MOBILITY_INCLUDE="$QT_MOBILITY_PREFIX/include" +elif [ -d "$QT_MOBILITY_INCLUDE" ]; then + QT_MOBILITY_INCLUDE=`(cd "$QT_MOBILITY_INCLUDE"; /bin/pwd)` +else + mkdir -p "$QT_MOBILITY_INCLUDE" + absPath=`(cd "$QT_MOBILITY_INCLUDE"; /bin/pwd)` + rm -rf "$QT_MOBILITY_INCLUDE" + QT_MOBILITY_INCLUDE="$absPath" +fi +echo "QT_MOBILITY_INCLUDE = $QT_MOBILITY_INCLUDE" >> "$CONFIG_IN" + + +#process library path +if [ -z "$QT_MOBILITY_LIB" ]; then + QT_MOBILITY_LIB="$QT_MOBILITY_PREFIX/$LIB_PATH" +elif [ -d "$QT_MOBILITY_LIB" ]; then + QT_MOBILITY_LIB=`(cd "$QT_MOBILITY_LIB"; /bin/pwd)` +else + mkdir -p "$QT_MOBILITY_LIB" + absPath=`(cd "$QT_MOBILITY_LIB"; /bin/pwd)` + rm -rf "$QT_MOBILITY_LIB" + QT_MOBILITY_LIB="$absPath" +fi +echo "QT_MOBILITY_LIB = $QT_MOBILITY_LIB" >> "$CONFIG_IN" + +#process binary path +if [ -z "$QT_MOBILITY_BIN" ]; then + QT_MOBILITY_BIN="$QT_MOBILITY_PREFIX/$BIN_PATH" +elif [ -d "$QT_MOBILITY_BIN" ]; then + QT_MOBILITY_BIN=`(cd "$QT_MOBILITY_BIN"; /bin/pwd)` +else + mkdir -p "$QT_MOBILITY_BIN" + absPath=`(cd "$QT_MOBILITY_BIN"; /bin/pwd)` + rm -rf "$QT_MOBILITY_BIN" + QT_MOBILITY_BIN="$absPath" +fi +echo "QT_MOBILITY_BIN = $QT_MOBILITY_BIN" >> "$CONFIG_IN" + +echo "QT_MOBILITY_SOURCE_TREE = $relpath" >> "$QMAKE_CACHE" +echo "QT_MOBILITY_BUILD_TREE = $shadowpath" >> "$QMAKE_CACHE" + +if [ -n "$MAC_SDK" ]; then + QMAKE_MAC_SDK="$MAC_SDK" + echo "QMAKE_MAC_SDK = $QMAKE_MAC_SDK" >> "$CONFIG_IN" +fi + +if [ -z "$BUILD_UNITTESTS" ]; then + echo "build_unit_tests = no" >> "$CONFIG_IN" +else + echo "build_unit_tests = yes" >> "$CONFIG_IN" +fi + +if [ -z "$BUILD_EXAMPLES" ]; then + echo "build_examples = no" >> "$CONFIG_IN" +else + echo "build_examples = yes" >> "$CONFIG_IN" +fi + +if [ -z "$BUILD_DOCS" ]; then + echo "build_docs = no" >> "$CONFIG_IN" +else + echo "build_docs = yes" >> "$CONFIG_IN" +fi + +echo "Configuring Qt Mobility" +echo + +WHICH="$relpath/config.tests/tools/which.test" + +printf "Checking available Qt" +if ! "$WHICH" qmake 2>/dev/null 1>&2; then + printf " ... Not found\n\n" >&2 + echo >&2 "Cannot find 'qmake' in your PATH."; + echo >&2 "Aborting." +else + printf " ... " + qmake -query QT_VERSION +fi + +# find out which make we want to use +MAKE= +for m in make gmake; do + if "$WHICH" $m >/dev/null 2>&1; then + MAKE=`$WHICH $m` + break + fi +done +if [ -z "$MAKE" ]; then + echo >&2 "Cannot find 'make' or 'gmake' in your PATH"; + echo >&2 "Aborting." +fi + +compileTest() +{ + printf "Checking $1" + CURRENT_PWD=`pwd` + + if [ "$shadowpath" = "$relpath" ]; then + #doing source tree build + cd "$relpath/config.tests/$2" + rm -rf ./$2 + else + #using shadow build + rm -rf config.tests/$2 + mkdir -p config.tests/$2 + cd config.tests/$2 + fi + + qmake "$relpath/config.tests/$2/$2.pro" >> "$CONFIG_LOG" + printf " ." + "$MAKE" clean >> "$CONFIG_LOG" + printf "." + "$MAKE" >> "$CONFIG_LOG" 2>&1 + printf ". " + if ./$2 >> "$CONFIG_LOG" 2>&1; then + echo "OK" + echo "$2_enabled = yes" >> "$CONFIG_IN" + else + echo "Not Found" + echo "$2_enabled = no" >> "$CONFIG_IN" + fi + cd "$CURRENT_PWD" +} + +#compile tests +compileTest QMF qmf +compileTest NetworkManager networkmanager +compileTest "CoreWLAN (MacOS 10.6)" corewlan + +# Now module selection +# using 'expr match ....' should help a bit +#if [ -n "$MOBILITY_MODULES_UNPARSED" ]; then + # In theory we should do some sanity checking here. +# MOBILITY_MODULES="$MOBILITY_MODULES_UNPARSED" +#fi + +# It's a lot easier to make qmake do the dependency checking... +echo "mobility_modules = $MOBILITY_MODULES" >> "$CONFIG_IN" +echo "contains(mobility_modules,versit): mobility_modules *= contacts" >> "$CONFIG_IN" + +# Ideally we'd skip generating headers for modules that are not enabled +echo "Generating Mobility Headers..." +#remove old headers +rm -rf $shadowpath/include +mkdir $shadowpath/include +for module in $MOBILITY_MODULES; do + case "$module" in + bearer) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/bearer + ;; + publishsubscribe) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/publishsubscribe + ;; + location) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/location + ;; + serviceframework) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/serviceframework + ;; + systeminfo) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/systeminfo + ;; + contacts) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/contacts + $relpath/bin/syncheaders $shadowpath/include $relpath/src/contacts/details + $relpath/bin/syncheaders $shadowpath/include $relpath/src/contacts/requests + $relpath/bin/syncheaders $shadowpath/include $relpath/src/contacts/filters + ;; + multimedia) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/multimedia + $relpath/bin/syncheaders $shadowpath/include $relpath/src/multimedia/experimental + ;; + messaging) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/messaging + ;; + versit) + #versit implies contacts + $relpath/bin/syncheaders $shadowpath/include $relpath/src/versit + $relpath/bin/syncheaders $shadowpath/include $relpath/src/contacts + $relpath/bin/syncheaders $shadowpath/include $relpath/src/contacts/details + $relpath/bin/syncheaders $shadowpath/include $relpath/src/contacts/requests + $relpath/bin/syncheaders $shadowpath/include $relpath/src/contacts/filters + ;; + sensors) + $relpath/bin/syncheaders $shadowpath/include $relpath/src/sensors + ;; + *) + echo "Cannot generate headers for $module" + ;; + esac +done + +mv "$CONFIG_IN" config.pri +mkdir -p "$shadowpath/features" +cp -f "$relpath/features/strict_flags.prf" "$shadowpath/features" + +echo "Running qmake..." +if qmake -recursive "$relpath/qtmobility.pro"; then + echo "" + echo "configure has finished. You may run make or gmake to build the project now." +else + echo "" + echo "configure failed." +fi diff -r 000000000000 -r cfcbf08528c4 qtmobility/configure.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/configure.bat Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,561 @@ +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +:: All rights reserved. +:: Contact: Nokia Corporation (qt-info@nokia.com) +:: +:: This file is part of the Qt Mobility Components. +:: +:: $QT_BEGIN_LICENSE:LGPL$ +:: No Commercial Usage +:: This file contains pre-release code and may not be distributed. +:: You may use this file in accordance with the terms and conditions +:: contained in the Technology Preview License Agreement accompanying +:: this package. +:: +:: GNU Lesser General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU Lesser +:: General Public License version 2.1 as published by the Free Software +:: Foundation and appearing in the file LICENSE.LGPL included in the +:: packaging of this file. Please review the following information to +:: ensure the GNU Lesser General Public License version 2.1 requirements +:: will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +:: +:: In addition, as a special exception, Nokia gives you certain additional +:: rights. These rights are described in the Nokia Qt LGPL Exception +:: version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +:: +:: If you have questions regarding the use of this file, please contact +:: Nokia at qt-info@nokia.com. +:: +:: +:: +:: +:: +:: +:: +:: +:: $QT_END_LICENSE$ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +@echo off + +set QT_MOBILITY_PREFIX= C:\QtMobility +set BUILD_PATH=%CD% +set SOURCE_PATH= %~dp0 +cd /D %SOURCE_PATH% +set SOURCE_PATH=%CD% +cd /D %BUILD_PATH% + +set PROJECT_CONFIG= %BUILD_PATH%\config.in +set PROJECT_LOG= %BUILD_PATH%\config.log +set RELEASEMODE=release +set WIN32_RELEASEMODE=debug_and_release build_all +set QT_MOBILITY_LIB= +set BUILD_UNITTESTS=no +set BUILD_EXAMPLES=no +set BUILD_DOCS=yes +set MOBILITY_MODULES=bearer location contacts multimedia publishsubscribe versit messaging systeminfo serviceframework sensors +set MOBILITY_MODULES_UNPARSED= +set VC_TEMPLATE_OPTION= +set QT_PATH= +set QMAKE_CACHE=%BUILD_PATH%\.qmake.cache + +if exist "%QMAKE_CACHE%" del %QMAKE_CACHE% +if exist "%PROJECT_LOG%" del %PROJECT_LOG% +if exist "%PROJECT_CONFIG%" del %PROJECT_CONFIG% + +set MOD_SOURCE_PATH=%SOURCE_PATH:\=/% +set MOD_BUILD_PATH=%BUILD_PATH:\=/% +echo QT_MOBILITY_SOURCE_TREE = $${EPOCROOT}%MOD_SOURCE_PATH:~3% +REM echo QT_MOBILITY_SOURCE_TREE = $${EPOCROOT}%MOD_SOURCE_PATH:~3% > %QMAKE_CACHE% +echo QT_MOBILITY_BUILD_TREE = $${EPOCROOT}%MOD_BUILD_PATH:~3% +REM echo QT_MOBILITY_BUILD_TREE = $${EPOCROOT}%MOD_BUILD_PATH:~3% >> %QMAKE_CACHE% +set QMAKE_CACHE= + +:cmdline_parsing +if "%1" == "" goto startProcessing +if "%1" == "-debug" goto debugTag +if "%1" == "-release" goto releaseTag +if "%1" == "-silent" goto silentTag +if "%1" == "-prefix" goto prefixTag +if "%1" == "-libdir" goto libTag +if "%1" == "-bindir" goto binTag +if "%1" == "-headerdir" goto headerTag +if "%1" == "-tests" goto testTag +if "%1" == "-examples" goto exampleTag +if "%1" == "-qt" goto qtTag +if "%1" == "-vc" goto vcTag +if "%1" == "-no-docs" goto nodocsTag +if "%1" == "-modules" goto modulesTag +if "%1" == "/?" goto usage +if "%1" == "-h" goto usage +if "%1" == "-help" goto usage +if "%1" == "--help" goto usage + + +echo Unknown option: "%1" +goto usage + +:usage +echo Usage: configure.bat [-prefix (dir)] [headerdir (dir)] [libdir (dir)] + echo [-bindir (dir)] [-tests] [-examples] + echo [-debug] [-release] [-silent] + echo. + echo Options: + echo. + echo -prefix (dir) ..... This will install everything relative to dir + echo (default prefix: C:\QtMobility) + echo -headerdir (dir) .. Header files will be installed to dir + echo (default prefix: PREFIX/include) + echo -libdir (dir) ..... Libraries will be installed to dir + echo (default PREFIX/lib) + echo -bindir (dir) ..... Executables will be installed to dir + echo (default PREFIX/bin) + echo -debug ............ Build with debugging symbols + echo -release .......... Build without debugging symbols + echo -silent ........... Reduces build output + echo -tests ............ Build unit tests (not build by default) + echo Note, this adds test symbols to all libraries + echo and should not be used for release builds. + echo -examples ......... Build example applications + echo -no-docs .......... Do not build documentation (build by default) + echo -modules ^ ... Build only the specified modules (default all) + echo Choose from: bearer contacts location publishsubscribe + echo messaging multimedia systeminfo serviceframework versit + echo Modules should be separated by a space and surrounded + echo by double quotation. If a + echo selected module depends on other modules dependencies + echo will automatically be enabled. + echo -vc ............... Generate Visual Studio make files + + +if exist "%PROJECT_CONFIG%" del %PROJECT_CONFIG% +goto exitTag + +:qtTag +shift +set QT_PATH=%1\ +shift +goto cmdline_parsing + +:debugTag +if "%RELEASEMODE%" == "release" set RELEASEMODE=debug +set WIN32_RELEASEMODE= +shift +goto cmdline_parsing + +:releaseTag +if "%RELEASEMODE%" == "debug" set RELEASEMODE=release +set WIN32_RELEASEMODE= +shift +goto cmdline_parsing + +:silentTag +echo CONFIG += silent > %PROJECT_CONFIG% +shift +goto cmdline_parsing + +:prefixTag +shift +set QT_MOBILITY_PREFIX=%1 +shift +goto cmdline_parsing + +:libTag +shift +echo QT_MOBILITY_LIB = %1 >> %PROJECT_CONFIG% +shift +goto cmdline_parsing + +:binTag +shift +echo QT_MOBILITY_BIN = %1 >> %PROJECT_CONFIG% +shift +goto cmdline_parsing + +:headerTag +shift +echo QT_MOBILITY_INCLUDE = %1 >> %PROJECT_CONFIG% +shift +goto cmdline_parsing + +:testTag +set BUILD_UNITTESTS=yes +shift +goto cmdline_parsing + +:exampleTag +set BUILD_EXAMPLES=yes +shift +goto cmdline_parsing + +:vcTag +shift +set VC_TEMPLATE_OPTION=-tp vc +goto cmdline_parsing + +:nodocsTag +set BUILD_DOCS=no +shift +goto cmdline_parsing + +:modulesTag +shift +:: %1 can have leading/trailing quotes, so we can't use if "%1" == "" +if xx%1xx == xxxx ( + echo. >&2 + echo >&2The -modules option requires a list of modules. + echo. >&2 + goto usage +) + +:: Remove leading/trailing quotes, if we have them +set MOBILITY_MODULES_UNPARSED=xxx%1xxx +set MOBILITY_MODULES_UNPARSED=%MOBILITY_MODULES_UNPARSED:"xxx=% +set MOBILITY_MODULES_UNPARSED=%MOBILITY_MODULES_UNPARSED:xxx"=% +set MOBILITY_MODULES_UNPARSED=%MOBILITY_MODULES_UNPARSED:xxx=% + +REM reset default modules as we expect a modules list +set MOBILITY_MODULES= + +echo Checking selected modules: +:modulesTag2 + +for /f "tokens=1,*" %%a in ("%MOBILITY_MODULES_UNPARSED%") do ( + set FIRST=%%a + set REMAINING=%%b +) + +: What we want is a switch as we need to check module name and only want to +: distinguish between false and correct module names being passed +if %FIRST% == bearer ( + echo Bearer Management selected +) else if %FIRST% == contacts ( + echo Contacts selected +) else if %FIRST% == location ( + echo Location selected +) else if %FIRST% == messaging ( + echo Messaging selected +) else if %FIRST% == multimedia ( + echo Multimedia selected +) else if %FIRST% == publishsubscribe ( + echo PublishSubscribe selected +) else if %FIRST% == systeminfo ( + echo Systeminfo selected +) else if %FIRST% == serviceframework ( + echo ServiceFramework selected +) else if %FIRST% == versit ( + echo Versit selected ^(implies Contacts^) +) else if %FIRST% == sensors ( + echo Sensors selected +) else ( + echo Unknown module %FIRST% + goto errorTag +) + +set MOBILITY_MODULES=%MOBILITY_MODULES% %FIRST% +if "%REMAINING%" == "" ( + shift +) else ( + set MOBILITY_MODULES_UNPARSED=%REMAINING% + goto modulesTag2 +) + +SET REMAINING= +SET FIRST= +goto cmdline_parsing + +:startProcessing + +echo CONFIG += %RELEASEMODE% >> %PROJECT_CONFIG% +echo CONFIG_WIN32 += %WIN32_RELEASEMODE% %RELEASEMODE% >> %PROJECT_CONFIG% +set RELEASEMODE= +set WIN32_RELEASEMODE= + +set CURRENTDIR=%CD% +echo %CURRENTDIR% +if exist %QT_MOBILITY_PREFIX% goto prefixExists +mkdir %QT_MOBILITY_PREFIX% +if errorlevel 1 goto invalidPrefix +cd /D %QT_MOBILITY_PREFIX% +set QT_MOBILITY_PREFIX=%CD% +cd /D %CURRENTDIR% +rd /S /Q %QT_MOBILITY_PREFIX% +goto endprefixProcessing + +:invalidPrefix +echo "%QT_MOBILITY_PREFIX%" is not a valid directory path. +goto :exitTag + +:prefixExists +set MOD_QT_MOBILITY_PREFIX=%QT_MOBILITY_PREFIX:/=\% +cd /D %MOD_QT_MOBILITY_PREFIX% +set QT_MOBILITY_PREFIX=%CD% +cd /D %CURRENTDIR% + +:endprefixProcessing +echo QT_MOBILITY_SOURCE_TREE = $${EPOCROOT}%MOD_SOURCE_PATH:~3% > %PROJECT_CONFIG% +echo QT_MOBILITY_BUILD_TREE = $${EPOCROOT}%MOD_BUILD_PATH:~3% >> %PROJECT_CONFIG% +set MOD_QT_MOBILITY_PREFIX=%QT_MOBILITY_PREFIX:\=/% +echo QT_MOBILITY_PREFIX = $${EPOCROOT}%MOD_QT_MOBILITY_PREFIX:~3% +echo QT_MOBILITY_PREFIX = $${EPOCROOT}%MOD_QT_MOBILITY_PREFIX:~3% >> %PROJECT_CONFIG% + +echo build_unit_tests = %BUILD_UNITTESTS% >> %PROJECT_CONFIG% +set BUILD_UNITTESTS= + +echo build_examples = %BUILD_EXAMPLES% >> %PROJECT_CONFIG% +set BUILD_EXAMPLES= + +echo build_docs = %BUILD_DOCS% >> %PROJECT_CONFIG% +set BUILD_DOCS= + +echo qmf_enabled = no >> %PROJECT_CONFIG% + +echo isEmpty($$QT_MOBILITY_INCLUDE):QT_MOBILITY_INCLUDE=$$QT_MOBILITY_PREFIX/include >> %PROJECT_CONFIG% +echo isEmpty($$QT_MOBILITY_LIB):QT_MOBILITY_LIB=$$QT_MOBILITY_PREFIX/lib >> %PROJECT_CONFIG% +echo isEmpty($$QT_MOBILITY_BIN):QT_MOBILITY_BIN=$$QT_MOBILITY_PREFIX/bin >> %PROJECT_CONFIG% + +echo mobility_modules = %MOBILITY_MODULES% >> %PROJECT_CONFIG% +REM no Sysinfo support on Maemo yet +echo maemo5^|maemo6:mobility_modules -= systeminfo >> %PROJECT_CONFIG% +echo contains(mobility_modules,versit): mobility_modules *= contacts >> %PROJECT_CONFIG% + +REM echo Checking available Qt +REM call %QT_PATH%qmake -v >> %PROJECT_LOG% 2>&1 +REM if errorlevel 1 goto qmakeNotFound +goto qmakeFound +:qmakeNotFound +echo ... Not found >> %PROJECT_LOG% 2>&1 +if "%QT_PATH%" == "" ( + echo >&2Cannot find 'qmake' in your PATH. + echo >&2Your PATH is: %PATH% +) else ( + echo >&2Cannot find 'qmake' in %QT_PATH%. +) +echo >&2Aborting. +goto errorTag + +:qmakeFound +REM call %QT_PATH%qmake -query QT_VERSION + +goto checkMake + +:makeTest +setlocal + set CURRENT_PWD=%CD% + + if %BUILD_PATH% == %SOURCE_PATH% ( + cd %SOURCE_PATH%\config.tests\make + if exist make del make + ) else ( + rmdir /S /Q config.tests\make + mkdir config.tests\make + cd config.tests\make + ) + + for /f "tokens=3" %%i in ('call %QT_PATH%qmake %SOURCE_PATH%\config.tests\make\make.pro 2^>^&1 1^>NUL') do set BUILDSYSTEM=%%i + + if %BUILDSYSTEM% == symbian-abld ( + call make -h >> %PROJECT_LOG% 2>&1 + if not errorlevel 1 ( + echo ... Symbian abld make found. + set MAKE=make + ) + ) else if %BUILDSYSTEM% == symbian-sbsv2 ( + call make -h >> %PROJECT_LOG% 2>&1 + if not errorlevel 1 ( + echo ... Symbian sbsv2 make found. + set MAKE=make + ) + ) else if %BUILDSYSTEM% == win32-nmake ( + call nmake /? >> %PROJECT_LOG% 2>&1 + if not errorlevel 1 ( + echo ... nmake found. + set MAKE=nmake + ) + ) else if %BUILDSYSTEM% == win32-mingw ( + call mingw32-make -v >> %PROJECT_LOG% 2>&1 + if not errorlevel 1 ( + echo ... mingw32-make found. + set MAKE=mingw32-make + ) + ) else ( + echo ... Unknown target environment %BUILDSYSTEM%. + ) + call cd %CURRENT_PWD% +call endlocal&set %1=%MAKE%&set %2=%BUILDSYSTEM%&goto :EOF + +:checkMake +REM echo Checking make +REM call :makeTest MOBILITY_MAKE MOBILITY_BUILDSYSTEM +REM if not "%MOBILITY_MAKE%" == "" goto compileTests +goto compileTests + +echo >&2Cannot find 'nmake', 'mingw32-make' or 'make' in your PATH +echo >&2Aborting. +goto errorTag + +:compileTest +setlocal + echo Checking %1 + set CURRENT_PWD=%CD% + + if %BUILD_PATH% == %SOURCE_PATH% ( + cd %SOURCE_PATH%\config.tests\%2 + if exist %2 del %2 + ) else ( + rmdir /S /Q config.tests\%2 + mkdir config.tests\%2 + cd config.tests\%2 + ) + + call %QT_PATH%qmake %SOURCE_PATH%\config.tests\%2\%2.pro >> %PROJECT_LOG% 2>&1 + call %MOBILITY_MAKE% clean >> %PROJECT_LOG% 2>&1 + call %MOBILITY_MAKE% >> %PROJECT_LOG% 2>&1 + + set FAILED=0 + if %MOBILITY_BUILDSYSTEM% == symbian-sbsv2 ( + for /f "tokens=2" %%i in ('%MOBILITY_MAKE% SBS^="@sbs --check"') do set FAILED=1 + ) else if %MOBILITY_BUILDSYSTEM% == symbian-abld ( + for /f "tokens=2" %%i in ('%MOBILITY_MAKE% ABLD^="@ABLD.BAT -c" 2^>^&1') do if not %%i == bldfiles set FAILED=1 + ) else if errorlevel 1 ( + set FAILED=1 + ) + + if %FAILED% == 0 ( + echo ... OK + echo %2_enabled = yes >> %PROJECT_CONFIG% + ) else ( + echo ... Not Found + echo %2_enabled = no >> %PROJECT_CONFIG% + ) + + cd %CURRENT_PWD% +endlocal&goto :EOF + +:compileTests + +echo. +echo Start of compile tests +REM compile tests go here. +REM call :compileTest LBT lbt +echo lbt_enabled = yes >> %PROJECT_CONFIG% +REM call :compileTest SNAP snap +echo snap_enabled = yes >> %PROJECT_CONFIG% +REM call :compileTest SymbianContactSIM symbiancntsim +echo symbiancntsim_enabled = yes >> %PROJECT_CONFIG% +echo End of compile tests +echo. +echo. + +REM we could skip generating headers if a module is not enabled +if not exist "%BUILD_PATH%\features" mkdir %BUILD_PATH%\features +copy %SOURCE_PATH%\features\strict_flags.prf %BUILD_PATH%\features +echo Generating Mobility Headers... +if exist "%BUILD_PATH%\include" rd /s /q %BUILD_PATH%\include +mkdir %BUILD_PATH%\include +perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\global + +set MODULES_TEMP=%MOBILITY_MODULES% + +:generateHeaders + +for /f "tokens=1,*" %%a in ("%MODULES_TEMP%") do ( + set FIRST=%%a + set REMAINING=%%b +) + +if %FIRST% == bearer ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\bearer +) else if %FIRST% == contacts ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\contacts + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\contacts\requests + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\contacts\filters + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\contacts\details +) else if %FIRST% == location ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\location +) else if %FIRST% == messaging ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\messaging +) else if %FIRST% == multimedia ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\multimedia + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\multimedia\experimental +) else if %FIRST% == publishsubscribe ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\publishsubscribe +) else if %FIRST% == systeminfo ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\systeminfo +) else if %FIRST% == serviceframework ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\serviceframework +) else if %FIRST% == versit ( + REM versit implies contacts + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\versit + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\contacts + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\contacts\requests + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\contacts\filters + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\contacts\details +) else if %FIRST% == sensors ( + perl -S %SOURCE_PATH%\bin\syncheaders %BUILD_PATH%\include %SOURCE_PATH%\src\sensors +) + +if "%REMAINING%" == "" ( + shift +) else ( + set MODULES_TEMP=%REMAINING% + goto generateHeaders +) + +SET REMAINING= +SET FIRST= +SET MODULES_TEMP= + +if exist config.pri del config.pri +ren %PROJECT_CONFIG% config.pri + +echo. +REM echo Running qmake... +REM call %QT_PATH%qmake -recursive %VC_TEMPLATE_OPTION% %SOURCE_PATH%\qtmobility.pro +REM if errorlevel 1 goto qmakeRecError +REM echo. +echo configure has finished. +REM You may run %MOBILITY_MAKE% to build the project now. +goto exitTag + +:qmakeRecError +echo. +echo configure failed. +goto errorTag + +:errorTag +set BUILD_PATH= +set CURRENTDIR= +set MOBILITY_MAKE= +set MOBILITY_BUILDSYSTEM= +set PROJECT_CONFIG= +set PROJECT_LOG= +set QT_MOBILITY_PREFIX= +set QT_PATH= +set SOURCE_PATH= +set MOBILITY_MODULES= +set MOBILITY_MODULES_UNPARSED= +SET REMAINING= +SET FIRST= +SET MODULES_TEMP= +exit /b 1 + +:exitTag +set BUILD_PATH= +set CURRENTDIR= +set MOBILITY_MAKE= +set MOBILITY_BUILDSYSTEM= +set PROJECT_CONFIG= +set PROJECT_LOG= +set QT_MOBILITY_PREFIX= +set QT_PATH= +set SOURCE_PATH= +set MOBILITY_MODULES= +set MOBILITY_MODULES_UNPARSED= +SET REMAINING= +SET FIRST= +SET MODULES_TEMP= +exit /b 0 diff -r 000000000000 -r cfcbf08528c4 qtmobility/confml/qtmobility.confml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/confml/qtmobility.confml Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,16 @@ + + + + QtMobility settings + + To enable QtMobility usage + + + + + true + + + \ No newline at end of file diff -r 000000000000 -r cfcbf08528c4 qtmobility/data/qtmobility.pkg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/data/qtmobility.pkg Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,22 @@ + +; Language +&EN + +; SIS header: name, uid, version +#{"QtMobility"},(0x2002AC89),1,0,0,TYPE=SA,RU + +; Localised Vendor name +%{"Nokia"} + +; Unique Vendor name +:"Nokia" + +; Manual PKG pre-rules from PRO files +; Default HW/platform dependencies +[0x101F7961],0,0,0,{"S60ProductID"} +[0x102032BE],0,0,0,{"S60ProductID"} +[0x102752AE],0,0,0,{"S60ProductID"} +[0x1028315F],0,0,0,{"S60ProductID"} + +; DEPLOYMENT +"/epoc32/release/armv5/urel/QtBearer.dll" - "!:\sys\bin\QtBearer.dll" diff -r 000000000000 -r cfcbf08528c4 qtmobility/data/qtmobility.sisx Binary file qtmobility/data/qtmobility.sisx has changed diff -r 000000000000 -r cfcbf08528c4 qtmobility/data/qtmobility_stub.pkg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/data/qtmobility_stub.pkg Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,12 @@ + +; Language +&EN + +; SIS header: name, uid, version +#{"QtMobility"},(0x2002AC89),1,0,0,TYPE=SA + +; Localised Vendor name +%{"Nokia"} + +; Unique Vendor name +:"Nokia" diff -r 000000000000 -r cfcbf08528c4 qtmobility/data/qtmobility_stub.sis Binary file qtmobility/data/qtmobility_stub.sis has changed diff -r 000000000000 -r cfcbf08528c4 qtmobility/data/qtmobilityexampleapps.pkg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/data/qtmobilityexampleapps.pkg Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,23 @@ +; Language +&EN + +; SIS header: name, uid, version +#{"QtMobilityExamples"},(0xE001E61D),1,0,0,TYPE=SA + +; Localised Vendor name +%{"Nokia, Qt"} + +; Unique Vendor name +:"Nokia, Qt" + +"/epoc32/release/armv5/urel/bearercloud.exe" - "!:\sys\bin\bearercloud.exe" +"/epoc32/data/z/resource/apps/bearercloud.rsc" - "!:\resource\apps\bearercloud.rsc" +"/epoc32/data/z/private/10003a3f/import/apps/bearercloud_reg.rsc" - "!:\private\10003a3f\import\apps\bearercloud_reg.rsc" + +"/epoc32/release/armv5/urel/bearermonitor.exe" - "!:\sys\bin\bearermonitor.exe" +"/epoc32/data/z/resource/apps/bearermonitor.rsc" - "!:\resource\apps\bearermonitor.rsc" +"/epoc32/data/z/private/10003a3f/import/apps/bearermonitor_reg.rsc" - "!:\private\10003a3f\import\apps\bearermonitor_reg.rsc" + +"/epoc32/release/armv5/urel/BearerEx.exe" - "!:\sys\bin\BearerEx.exe" +"/epoc32/data/z/resource/apps/BearerEx.rsc" - "!:\resource\apps\BearerEx.rsc" +"/epoc32/data/z/private/10003a3f/import/apps/BearerEx_reg.rsc" - "!:\private\10003a3f\import\apps\BearerEx_reg.rsc" diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/bearercloud.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/bearercloud.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "bearercloud.h" +#include "cloud.h" + +#include +#include +#include +#include + +#include + +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +//! [0] +BearerCloud::BearerCloud(QObject *parent) +: QGraphicsScene(parent), timerId(0) +{ + setSceneRect(-300, -300, 600, 600); + + qsrand(QDateTime::currentDateTime().toTime_t()); + + offset[QNetworkConfiguration::Active] = 2 * M_PI * qrand() / RAND_MAX; + offset[QNetworkConfiguration::Discovered] = offset[QNetworkConfiguration::Active] + M_PI / 6; + offset[QNetworkConfiguration::Defined] = offset[QNetworkConfiguration::Discovered] - M_PI / 6; + offset[QNetworkConfiguration::Undefined] = offset[QNetworkConfiguration::Undefined] + M_PI / 6; + + thisDevice = new QGraphicsTextItem(QHostInfo::localHostName()); + thisDevice->setData(0, QLatin1String("This Device")); + thisDevice->setPos(thisDevice->boundingRect().width() / -2, + thisDevice->boundingRect().height() / -2); + addItem(thisDevice); + + qreal radius = Cloud::getRadiusForState(QNetworkConfiguration::Active); + QGraphicsEllipseItem *orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::green)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Discovered); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::blue)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Defined); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::darkGray)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Undefined); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::lightGray)); + addItem(orbit); + + connect(&manager, SIGNAL(configurationAdded(QNetworkConfiguration)), + this, SLOT(configurationAdded(QNetworkConfiguration))); + connect(&manager, SIGNAL(configurationRemoved(QNetworkConfiguration)), + this, SLOT(configurationRemoved(QNetworkConfiguration))); + connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); + + QTimer::singleShot(0, this, SLOT(updateConfigurations())); +} +//! [0] + +BearerCloud::~BearerCloud() +{ +} + +void BearerCloud::cloudMoved() +{ + if (!timerId) + timerId = startTimer(1000 / 25); +} + +void BearerCloud::timerEvent(QTimerEvent *) +{ + QList clouds; + foreach (QGraphicsItem *item, items()) { + if (Cloud *cloud = qgraphicsitem_cast(item)) + clouds << cloud; + } + + foreach (Cloud *cloud, clouds) + cloud->calculateForces(); + + bool cloudsMoved = false; + foreach (Cloud *cloud, clouds) + cloudsMoved |= cloud->advance(); + + if (!cloudsMoved) { + killTimer(timerId); + timerId = 0; + } +} + +//! [2] +void BearerCloud::configurationAdded(const QNetworkConfiguration &config) +{ + const QNetworkConfiguration::StateFlags state = config.state(); + + configStates.insert(state, config.identifier()); + + const qreal radius = Cloud::getRadiusForState(state); + const int count = configStates.count(state); + const qreal angle = 2 * M_PI / count; + + Cloud *item = new Cloud(config); + configurations.insert(config.identifier(), item); + + item->setPos(radius * cos((count-1) * angle + offset[state]), + radius * sin((count-1) * angle + offset[state])); + + addItem(item); + + cloudMoved(); +} +//! [2] + +//! [3] +void BearerCloud::configurationRemoved(const QNetworkConfiguration &config) +{ + foreach (const QNetworkConfiguration::StateFlags &state, configStates.uniqueKeys()) + configStates.remove(state, config.identifier()); + + Cloud *item = configurations.take(config.identifier()); + + item->setFinalScale(0.0); + item->setDeleteAfterAnimation(true); + + cloudMoved(); +} +//! [3] + +//! [4] +void BearerCloud::configurationChanged(const QNetworkConfiguration &config) +{ + foreach (const QNetworkConfiguration::StateFlags &state, configStates.uniqueKeys()) + configStates.remove(state, config.identifier()); + + configStates.insert(config.state(), config.identifier()); + + cloudMoved(); +} +//! [4] + +//! [1] +void BearerCloud::updateConfigurations() +{ + QList allConfigurations = manager.allConfigurations(); + + while (!allConfigurations.isEmpty()) + configurationAdded(allConfigurations.takeFirst()); + + cloudMoved(); +} +//! [1] + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/bearercloud.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/bearercloud.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include +#include + +QTM_USE_NAMESPACE + +class Cloud; + +class BearerCloud : public QGraphicsScene +{ + Q_OBJECT + +public: + BearerCloud(QObject *parent = 0); + ~BearerCloud(); + + void cloudMoved(); + + void timerEvent(QTimerEvent *event); + +private Q_SLOTS: + void configurationAdded(const QNetworkConfiguration &config); + void configurationRemoved(const QNetworkConfiguration &config); + void configurationChanged(const QNetworkConfiguration &config); + void updateConfigurations(); + +private: + QNetworkConfigurationManager manager; + + QGraphicsTextItem *thisDevice; + QHash configurations; + + QMap offset; + QMultiMap configStates; + + int timerId; +}; + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/bearercloud.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/bearercloud.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,23 @@ +HEADERS = bearercloud.h \ + cloud.h + +SOURCES = main.cpp \ + bearercloud.cpp \ + cloud.cpp + +RESOURCES = icons.qrc + +TARGET = bearercloud + +QT = core gui network svg + +INCLUDEPATH += ../../src/bearer + +include(../examples.pri) + +CONFIG += mobility +MOBILITY = bearer + +CONFIG += console + +symbian:TARGET.CAPABILITY = NetworkServices ReadUserData diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/cloud.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/cloud.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,361 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "cloud.h" +#include "bearercloud.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +static QMap svgCache; + +//! [0] +Cloud::Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent) +: QGraphicsItem(parent), configuration(config), deleteAfterAnimation(false) +{ + session = new QNetworkSession(configuration, this); + connect(session, SIGNAL(newConfigurationActivated()), + this, SLOT(newConfigurationActivated())); + connect(session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + setFlag(ItemIsMovable); +#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)) + setFlag(ItemSendsGeometryChanges); +#endif + setZValue(1); + + icon = new QGraphicsSvgItem(this); + text = new QGraphicsTextItem(this); + + currentScale = 0; + finalScale = 1; + setTransform(QTransform::fromScale(currentScale, currentScale), false); + setOpacity(0); + + newConfigurationActivated(); +} +//! [0] + +Cloud::~Cloud() +{ +} + +void Cloud::setFinalScale(qreal factor) +{ + finalScale = factor; +} + +void Cloud::setDeleteAfterAnimation(bool deleteAfter) +{ + deleteAfterAnimation = deleteAfter; +} + +void Cloud::calculateForces() +{ + if (!scene() || scene()->mouseGrabberItem() == this) { + newPos = pos(); + return; + } + + // sum up all the forces push this item away + qreal xvel = 0; + qreal yvel = 0; + QLineF orbitForce; + foreach (QGraphicsItem *item, scene()->items()) { + // other clouds + Cloud *cloud = qgraphicsitem_cast(item); + if (!cloud && item->data(0) != QLatin1String("This Device")) + continue; + + qreal factor = 1.0; + + QLineF line(cloud ? item->mapToScene(0, 0) : QPointF(0, 0), mapToScene(0, 0)); + if (item->data(0) == QLatin1String("This Device")) + orbitForce = line; + + if (cloud) + factor = cloud->currentScale; + + qreal dx = line.dx(); + qreal dy = line.dy(); + double l = 2.0 * (dx * dx + dy * dy); + if (l > 0) { + xvel += factor * dx * 200.0 / l; + yvel += factor * dy * 200.0 / l; + } + } + + // tendency to stay at a fixed orbit + qreal orbit = getRadiusForState(configuration.state()); + qreal distance = orbitForce.length(); + + QLineF unit = orbitForce.unitVector(); + + orbitForce.setLength(xvel * unit.dx() + yvel * unit.dy()); + + qreal w = 2 - exp(-pow(distance-orbit, 2)/(2 * 50)); + + if (distance < orbit) { + xvel += orbitForce.dx() * w; + yvel += orbitForce.dy() * w; + } else { + xvel -= orbitForce.dx() * w; + yvel -= orbitForce.dy() * w; + } + + if (qAbs(xvel) < 0.1 && qAbs(yvel) < 0.1) + xvel = yvel = 0; + + QRectF sceneRect = scene()->sceneRect(); + newPos = pos() + QPointF(xvel, yvel); + newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10)); + newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10)); +} + +bool Cloud::advance() +{ + static const qreal scaleDelta = 0.01; + + bool animated = false; + + if (currentScale < finalScale) { + animated = true; + currentScale = qMin(currentScale + scaleDelta, finalScale); + setTransform(QTransform::fromScale(currentScale, currentScale), false); + } else if (currentScale > finalScale) { + animated = true; + currentScale = qMax(currentScale - scaleDelta, finalScale); + setTransform(QTransform::fromScale(currentScale, currentScale), false); + } + + if (newPos != pos()) { + setPos(newPos); + animated = true; + } + + if (opacity() != finalOpacity) { + animated = true; + if (qAbs(finalScale - currentScale) > 0.0) { + // use scale as reference + setOpacity(opacity() + scaleDelta * (finalOpacity - opacity()) / + qAbs(finalScale - currentScale)); + } else { + setOpacity(finalOpacity); + } + } + + if (!animated && deleteAfterAnimation) + deleteLater(); + + return animated; +} + +QRectF Cloud::boundingRect() const +{ + return childrenBoundingRect(); +} + +void Cloud::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) +{ +} + +//! [4] +QVariant Cloud::itemChange(GraphicsItemChange change, const QVariant &value) +{ + switch (change) { + case ItemPositionHasChanged: + if (BearerCloud *bearercloud = qobject_cast(scene())) + bearercloud->cloudMoved(); + default: + ; + }; + + return QGraphicsItem::itemChange(change, value); +} +//! [4] + +//! [3] +void Cloud::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + if (session->isOpen()) + session->close(); + else + session->open(); + + event->accept(); + } +} +//! [3] + +//! [2] +void Cloud::stateChanged(QNetworkSession::State state) +{ + if (configuration.name().isEmpty()) + finalOpacity = qreal(0.1); + else if (session->state() == QNetworkSession::NotAvailable) + finalOpacity = 0.5; + else + finalOpacity = 1.0; + + QString tooltip; + + if (configuration.name().isEmpty()) + tooltip += tr("HIDDEN NETWORK
"); + else + tooltip += tr("%1
").arg(configuration.name()); + + const QNetworkInterface interface = session->interface(); + if (interface.isValid()) + tooltip += tr("
Interface: %1").arg(interface.humanReadableName()); + tooltip += tr("
Id: %1").arg(configuration.identifier()); + + const QString bearerName = configuration.bearerName(); + if (!bearerName.isEmpty()) + tooltip += tr("
Bearer: %1").arg(bearerName); + + QString s = tr("
State: %1 (%2)"); + switch (state) { + case QNetworkSession::Invalid: + s = s.arg(tr("Invalid")); + break; + case QNetworkSession::NotAvailable: + s = s.arg(tr("Not Available")); + break; + case QNetworkSession::Connecting: + s = s.arg(tr("Connecting")); + break; + case QNetworkSession::Connected: + s = s.arg(tr("Connected")); + break; + case QNetworkSession::Closing: + s = s.arg(tr("Closing")); + break; + case QNetworkSession::Disconnected: + s = s.arg(tr("Disconnected")); + break; + case QNetworkSession::Roaming: + s = s.arg(tr("Roaming")); + break; + default: + s = s.arg(tr("Unknown")); + } + + if (session->isOpen()) + s = s.arg(tr("Open")); + else + s = s.arg(tr("Closed")); + + tooltip += s; + + tooltip += tr("

Active time: %1 seconds").arg(session->activeTime()); + tooltip += tr("
Received data: %1 bytes").arg(session->bytesReceived()); + tooltip += tr("
Sent data: %1 bytes").arg(session->bytesWritten()); + + setToolTip(tooltip); +} +//! [2] + +//! [1] +void Cloud::newConfigurationActivated() +{ + const QString bearerName = configuration.bearerName(); + if (!svgCache.contains(bearerName)) { + if (bearerName == QLatin1String("WLAN")) + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":wlan.svg"))); + else if (bearerName == QLatin1String("Ethernet")) + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":lan.svg"))); + else + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":unknown.svg"))); + } + + icon->setSharedRenderer(svgCache[bearerName]); + + if (configuration.name().isEmpty()) { + text->setPlainText(tr("HIDDEN NETWORK")); + } else { + if (configuration.type() == QNetworkConfiguration::ServiceNetwork) + text->setHtml("" + configuration.name() + ""); + else + text->setPlainText(configuration.name()); + } + + const qreal height = icon->boundingRect().height() + text->boundingRect().height(); + + icon->setPos(icon->boundingRect().width() / -2, height / -2); + + text->setPos(text->boundingRect().width() / -2, + height / 2 - text->boundingRect().height()); + + stateChanged(session->state()); +} +//! [1] + +qreal Cloud::getRadiusForState(QNetworkConfiguration::StateFlags state) +{ + switch (state) { + case QNetworkConfiguration::Active: + return 100; + break; + case QNetworkConfiguration::Discovered: + return 150; + break; + case QNetworkConfiguration::Defined: + return 200; + break; + case QNetworkConfiguration::Undefined: + return 250; + break; + default: + return 300; + } +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/cloud.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/cloud.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +QTM_USE_NAMESPACE + +QT_BEGIN_NAMESPACE +class QGraphicsTextItem; +class QGraphicsSvgItem; +QT_END_NAMESPACE + +class Cloud : public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + +public: + Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent = 0); + ~Cloud(); + + enum { Type = UserType + 1 }; + int type() const { return Type; } + + void setFinalScale(qreal factor); + void setDeleteAfterAnimation(bool deleteAfter); + + void calculateForces(); + + bool advance(); + QRectF boundingRect() const; + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + static qreal getRadiusForState(QNetworkConfiguration::StateFlags state); + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + +private Q_SLOTS: + void stateChanged(QNetworkSession::State state); + void newConfigurationActivated(); + +private: + QNetworkConfiguration configuration; + QNetworkSession *session; + + QGraphicsTextItem *text; + QGraphicsSvgItem *icon; + + qreal finalOpacity; + qreal finalScale; + qreal currentScale; + + QPointF newPos; + + bool deleteAfterAnimation; +}; + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/icons.qrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/icons.qrc Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,7 @@ + + + wlan.svg + lan.svg + unknown.svg + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/lan.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/lan.svg Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,76 @@ + + + + + + + + + + + image/svg+xml + + + + + + LAN + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/main.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "bearercloud.h" + +#include +#include + +class CloudView : public QGraphicsView +{ + Q_OBJECT + +public: + CloudView(QGraphicsScene *scene); + ~CloudView() { } + +protected: + void resizeEvent(QResizeEvent *) { + fitInView(sceneRect(), Qt::KeepAspectRatio); + } +#ifdef Q_OS_WINCE + void hideEvent(QHideEvent *) { + qApp->quit(); + } +#endif +}; + +CloudView::CloudView(QGraphicsScene *scene) +: QGraphicsView(scene) +{ + setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | + QPainter::SmoothPixmapTransform); +#if defined (Q_OS_SYMBIAN) || defined (Q_OS_WINCE) + setWindowState(Qt::WindowMaximized); +#endif +} + +#include "main.moc" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + BearerCloud bearerCloud; + + CloudView view(&bearerCloud); + view.show(); + + return app.exec(); +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/unknown.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/unknown.svg Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,76 @@ + + + + + + + + + + + image/svg+xml + + + + + + NET + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearercloud/wlan.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearercloud/wlan.svg Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,151 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/bearermonitor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/bearermonitor.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,395 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "bearermonitor.h" +#include "sessionwidget.h" + +#include + +#ifdef Q_OS_WIN +#include +#undef interface + +#ifndef NS_NLA +#define NS_NLA 15 +#endif +#endif + +BearerMonitor::BearerMonitor(QWidget *parent) +: QWidget(parent) +{ + setupUi(this); + delete tabWidget->currentWidget(); + sessionGroup->hide(); +#if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) + setWindowState(Qt::WindowMaximized); +#endif + updateConfigurations(); + + onlineStateChanged(!manager.allConfigurations(QNetworkConfiguration::Active).isEmpty()); + + QNetworkConfiguration defaultConfiguration = manager.defaultConfiguration(); + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == defaultConfiguration.identifier()) { + treeWidget->setCurrentItem(item); + showConfigurationFor(item); + break; + } + } + + connect(&manager, SIGNAL(configurationAdded(const QNetworkConfiguration&)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + connect(&manager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), + this, SLOT(configurationRemoved(const QNetworkConfiguration&))); + connect(&manager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), + this, SLOT(configurationChanged(const QNetworkConfiguration))); + connect(&manager, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations())); + connect(&manager, SIGNAL(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool))); + +#ifdef Q_OS_WIN + connect(registerButton, SIGNAL(clicked()), this, SLOT(registerNetwork())); + connect(unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterNetwork())); +#else + nlaGroup->hide(); +#endif + + connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), + this, SLOT(createSessionFor(QTreeWidgetItem*))); + + connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), + this, SLOT(showConfigurationFor(QTreeWidgetItem*))); + + connect(newSessionButton, SIGNAL(clicked()), + this, SLOT(createNewSession())); + connect(deleteSessionButton, SIGNAL(clicked()), + this, SLOT(deleteSession())); + + connect(scanButton, SIGNAL(clicked()), + this, SLOT(performScan())); +} + +BearerMonitor::~BearerMonitor() +{ +} + +static void updateItem(QTreeWidgetItem *item, const QNetworkConfiguration &config) +{ + item->setText(0, config.name()); + item->setData(0, Qt::UserRole, config.identifier()); + + QFont font = item->font(1); + font.setBold((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active); + item->setFont(0, font); +} + +void BearerMonitor::configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent) +{ + QTreeWidgetItem *item = new QTreeWidgetItem; + updateItem(item, config); + + if (parent) + parent->addChild(item); + else + treeWidget->addTopLevelItem(item); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &child, config.children()) + configurationAdded(child, item); + } +} + +void BearerMonitor::configurationRemoved(const QNetworkConfiguration &config) +{ + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == config.identifier()) { + delete item; + break; + } + } +} + +void BearerMonitor::configurationChanged(const QNetworkConfiguration &config) +{ + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == config.identifier()) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + + if (item == treeWidget->currentItem()) + showConfigurationFor(item); + + break; + } + } +} + +void BearerMonitor::updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap) +{ + QMap itemMap; + for (int i = 0; i < parent->childCount(); ++i) { + QTreeWidgetItem *item = parent->child(i); + itemMap.insert(item->data(0, Qt::UserRole).toString(), item); + } + + QList allConfigurations = snap.children(); + + while (!allConfigurations.isEmpty()) { + QNetworkConfiguration config = allConfigurations.takeFirst(); + + QTreeWidgetItem *item = itemMap.take(config.identifier()); + if (item) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + } else { + configurationAdded(config, parent); + } + } + + foreach (const QString &id, itemMap.keys()) + delete itemMap.value(id); + + itemMap.clear(); +} + +void BearerMonitor::updateConfigurations() +{ + progressBar->hide(); + scanButton->show(); + + QList items = treeWidget->findItems(QLatin1String("*"), Qt::MatchWildcard); + QMap itemMap; + while (!items.isEmpty()) { + QTreeWidgetItem *item = items.takeFirst(); + itemMap.insert(item->data(0, Qt::UserRole).toString(), item); + } + + QList allConfigurations = manager.allConfigurations(); + + while (!allConfigurations.isEmpty()) { + QNetworkConfiguration config = allConfigurations.takeFirst(); + + QTreeWidgetItem *item = itemMap.take(config.identifier()); + if (item) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + } else { + configurationAdded(config); + } + } + + foreach (const QString &id, itemMap.keys()) + delete itemMap.value(id); +} + +void BearerMonitor::onlineStateChanged(bool isOnline) +{ + if (isOnline) + onlineState->setText(tr("Online")); + else + onlineState->setText(tr("Offline")); +} + +#ifdef Q_OS_WIN +void BearerMonitor::registerNetwork() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + QNetworkConfiguration configuration = + manager.configurationFromIdentifier(item->data(0, Qt::UserRole).toString()); + + const QString name = configuration.name(); + + qDebug() << "Registering" << name << "with system"; + + WSAQUERYSET networkInfo; + memset(&networkInfo, 0, sizeof(networkInfo)); + networkInfo.dwSize = sizeof(networkInfo); + networkInfo.lpszServiceInstanceName = (LPWSTR)name.utf16(); + networkInfo.dwNameSpace = NS_NLA; + + if (WSASetService(&networkInfo, RNRSERVICE_REGISTER, 0) == SOCKET_ERROR) + qDebug() << "WSASetService(RNRSERVICE_REGISTER) returned" << WSAGetLastError(); +} + +void BearerMonitor::unregisterNetwork() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + QNetworkConfiguration configuration = + manager.configurationFromIdentifier(item->data(0, Qt::UserRole).toString()); + + const QString name = configuration.name(); + + qDebug() << "Unregistering" << name << "with system"; + + WSAQUERYSET networkInfo; + memset(&networkInfo, 0, sizeof(networkInfo)); + networkInfo.dwSize = sizeof(networkInfo); + networkInfo.lpszServiceInstanceName = (LPWSTR)name.utf16(); + networkInfo.dwNameSpace = NS_NLA; + + if (WSASetService(&networkInfo, RNRSERVICE_DELETE, 0) == SOCKET_ERROR) + qDebug() << "WSASetService(RNRSERVICE_DELETE) returned" << WSAGetLastError(); +} +#endif + +void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item) +{ + QString identifier; + + if (item) + identifier = item->data(0, Qt::UserRole).toString(); + + QNetworkConfiguration conf = manager.configurationFromIdentifier(identifier); + + switch (conf.state()) { + case QNetworkConfiguration::Active: + configurationState->setText(tr("Active")); + break; + case QNetworkConfiguration::Discovered: + configurationState->setText(tr("Discovered")); + break; + case QNetworkConfiguration::Defined: + configurationState->setText(tr("Defined")); + break; + case QNetworkConfiguration::Undefined: + configurationState->setText(tr("Undefined")); + break; + default: + configurationState->setText(QString()); + } + + switch (conf.type()) { + case QNetworkConfiguration::InternetAccessPoint: + configurationType->setText(tr("Internet Access Point")); + break; + case QNetworkConfiguration::ServiceNetwork: + configurationType->setText(tr("Service Network")); + break; + case QNetworkConfiguration::UserChoice: + configurationType->setText(tr("User Choice")); + break; + case QNetworkConfiguration::Invalid: + configurationType->setText(tr("Invalid")); + break; + default: + configurationType->setText(QString()); + } + + switch (conf.purpose()) { + case QNetworkConfiguration::UnknownPurpose: + configurationPurpose->setText(tr("Unknown")); + break; + case QNetworkConfiguration::PublicPurpose: + configurationPurpose->setText(tr("Public")); + break; + case QNetworkConfiguration::PrivatePurpose: + configurationPurpose->setText(tr("Private")); + break; + case QNetworkConfiguration::ServiceSpecificPurpose: + configurationPurpose->setText(tr("Service Specific")); + break; + default: + configurationPurpose->setText(QString()); + } + + configurationIdentifier->setText(conf.identifier()); + + configurationRoaming->setText(conf.isRoamingAvailable() ? tr("Available") : tr("Not available")); + + configurationChildren->setText(QString::number(conf.children().count())); + + configurationName->setText(conf.name()); +} + +void BearerMonitor::createSessionFor(QTreeWidgetItem *item) +{ + const QString identifier = item->data(0, Qt::UserRole).toString(); + + QNetworkConfiguration conf = manager.configurationFromIdentifier(identifier); + + SessionWidget *session = new SessionWidget(conf); + + tabWidget->addTab(session, conf.name()); + + sessionGroup->show(); + + sessionWidgets.append(session); +} + +void BearerMonitor::createNewSession() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + createSessionFor(item); +} + +void BearerMonitor::deleteSession() +{ + SessionWidget *session = qobject_cast(tabWidget->currentWidget()); + if (session) { + sessionWidgets.removeAll(session); + + delete session; + + if (tabWidget->count() == 0) + sessionGroup->hide(); + } +} + +void BearerMonitor::performScan() +{ + scanButton->hide(); + progressBar->show(); + manager.updateConfigurations(); +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/bearermonitor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/bearermonitor.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BEARERMONITOR_H +#define BEARERMONITOR_H + +#include +#include +#if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) +#include "ui_bearermonitor_240_320.h" +#else +#include "ui_bearermonitor_640_480.h" +#endif + +QTM_USE_NAMESPACE + +class SessionWidget; + +class BearerMonitor : public QWidget, public Ui_BearerMonitor +{ + Q_OBJECT + +public: + BearerMonitor(QWidget *parent = 0); + ~BearerMonitor(); + +private slots: + void configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent = 0); + void configurationRemoved(const QNetworkConfiguration &config); + void configurationChanged(const QNetworkConfiguration &config); + void updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap); + void updateConfigurations(); + + void onlineStateChanged(bool isOnline); + +#ifdef Q_OS_WIN + void registerNetwork(); + void unregisterNetwork(); +#endif + + void showConfigurationFor(QTreeWidgetItem *item); + + void createSessionFor(QTreeWidgetItem *item); + void createNewSession(); + void deleteSession(); + + void performScan(); + +private: + QNetworkConfigurationManager manager; + QList sessionWidgets; +}; + +#endif //BEARERMONITOR_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/bearermonitor.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/bearermonitor.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,28 @@ +HEADERS = sessionwidget.h \ + bearermonitor.h + +SOURCES = main.cpp \ + bearermonitor.cpp \ + sessionwidget.cpp + +FORMS = bearermonitor_240_320.ui \ + bearermonitor_640_480.ui \ + sessionwidget.ui + +TARGET = bearermonitor + +QT = core gui network + +INCLUDEPATH += ../../src/bearer + +include(../examples.pri) + +CONFIG += mobility +MOBILITY = bearer + +win32:!wince*:LIBS += -lWs2_32 +wince*:LIBS += -lWs2 + +CONFIG += console + +symbian:TARGET.CAPABILITY = NetworkServices ReadUserData diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/bearermonitor_240_320.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/bearermonitor_240_320.ui Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,420 @@ + + + BearerMonitor + + + + 0 + 0 + 240 + 320 + + + + Form + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + true + + + + + 0 + -274 + 206 + 576 + + + + + + + System State + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + Online State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + Configurations + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + + + Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Type: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Purpose: + + + + + + + + 0 + 0 + + + + Unknown + + + + + + + + + + + Identifier: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Roaming: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Children: + + + + + + + + 0 + 0 + + + + + + + + + + + + + Network Location Awareness + + + + + + Register + + + + + + + Unregister + + + + + + + + + + New Session + + + + + + + Delete Session + + + + + + + Scan + + + + + + + 0 + + + -1 + + + false + + + false + + + %p% + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOff + + + false + + + + 1 + + + + + + + + + + + + + Sessions + + + true + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 0 + + + + Session 1 + + + + + + + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/bearermonitor_640_480.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/bearermonitor_640_480.ui Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,386 @@ + + + BearerMonitor + + + + 0 + 0 + 640 + 515 + + + + Form + + + + + + System State + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + Online State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + Configurations + + + true + + + + 0 + + + 0 + + + 0 + + + + + false + + + + 1 + + + + + + + + + + + + Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Type: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Purpose: + + + + + + + + 0 + 0 + + + + Unknown + + + + + + + + + + + Identifier: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Roaming: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Children: + + + + + + + + 0 + 0 + + + + + + + + + + + + + Network Location Awareness + + + + + + Register + + + + + + + Unregister + + + + + + + + + + New Session + + + + + + + Delete Session + + + + + + + Scan + + + + + + + 0 + + + -1 + + + false + + + false + + + %p% + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Sessions + + + true + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 0 + + + + Session 1 + + + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/main.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "bearermonitor.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + BearerMonitor monitor; + monitor.show(); + + return app.exec(); +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/sessionwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/sessionwidget.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sessionwidget.h" +#include "qnetworkconfigmanager.h" + +SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent) +: QWidget(parent) +{ + setupUi(this); + + session = new QNetworkSession(config, this); + + connect(session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(updateSession())); + connect(session, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(updateSession())); + + updateSession(); + + sessionId->setText(QString("0x%1").arg(qulonglong(session), 8, 16, QChar('0'))); + + configuration->setText(session->configuration().name()); + + connect(openSessionButton, SIGNAL(clicked()), + this, SLOT(openSession())); + connect(openSyncSessionButton, SIGNAL(clicked()), + this, SLOT(openSyncSession())); + connect(closeSessionButton, SIGNAL(clicked()), + this, SLOT(closeSession())); + connect(stopSessionButton, SIGNAL(clicked()), + this, SLOT(stopSession())); +} + +SessionWidget::~SessionWidget() +{ + delete session; +} + +void SessionWidget::updateSession() +{ + updateSessionState(session->state()); + updateSessionError(session->error()); + + if (session->configuration().type() == QNetworkConfiguration::InternetAccessPoint) + bearer->setText(session->configuration().bearerName()); + else { + QNetworkConfigurationManager mgr; + QNetworkConfiguration c = mgr.configurationFromIdentifier(session->sessionProperty("ActiveConfiguration").toString()); + bearer->setText(c.bearerName()); + } + + interfaceName->setText(session->interface().humanReadableName()); + interfaceGuid->setText(session->interface().name()); +} + +void SessionWidget::openSession() +{ + session->open(); + updateSession(); +} + +void SessionWidget::openSyncSession() +{ + session->open(); + session->waitForOpened(); + updateSession(); +} + +void SessionWidget::closeSession() +{ + session->close(); + updateSession(); +} + +void SessionWidget::stopSession() +{ + session->stop(); + updateSession(); +} + +void SessionWidget::updateSessionState(QNetworkSession::State state) +{ + QString s = tr("%1 (%2)"); + + switch (state) { + case QNetworkSession::Invalid: + s = s.arg(tr("Invalid")); + break; + case QNetworkSession::NotAvailable: + s = s.arg(tr("Not Available")); + break; + case QNetworkSession::Connecting: + s = s.arg(tr("Connecting")); + break; + case QNetworkSession::Connected: + s = s.arg(tr("Connected")); + break; + case QNetworkSession::Closing: + s = s.arg(tr("Closing")); + break; + case QNetworkSession::Disconnected: + s = s.arg(tr("Disconnected")); + break; + case QNetworkSession::Roaming: + s = s.arg(tr("Roaming")); + break; + default: + s = s.arg(tr("Unknown")); + } + + if (session->isOpen()) + s = s.arg(tr("Open")); + else + s = s.arg(tr("Closed")); + + sessionState->setText(s); +} + +void SessionWidget::updateSessionError(QNetworkSession::SessionError error) +{ + lastError->setText(QString::number(error)); + errorString->setText(session->errorString()); +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/sessionwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/sessionwidget.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SESSIONWIDGET_H +#define SESSIONWIDGET_H + +#include "ui_sessionwidget.h" + +#include + +QTM_USE_NAMESPACE + +class SessionWidget : public QWidget, public Ui_SessionWidget +{ + Q_OBJECT + +public: + SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0); + ~SessionWidget(); + +private: + void updateSessionState(QNetworkSession::State state); + void updateSessionError(QNetworkSession::SessionError error); + +private Q_SLOTS: + void openSession(); + void openSyncSession(); + void closeSession(); + void stopSession(); + void updateSession(); + +private: + QNetworkSession *session; +}; + +#endif + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/bearermonitor/sessionwidget.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/bearermonitor/sessionwidget.ui Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,259 @@ + + + SessionWidget + + + + 0 + 0 + 340 + 286 + + + + Form + + + + + + + + + + Session ID: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + 0 + 0 + + + + Session State: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Configuration: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Bearer: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Interface Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Interface GUID: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Last Error: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Error String + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Open + + + + + + + Blocking Open + + + + + + + + + + + Close + + + + + + + Stop + + + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/examples.pri --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/examples.pri Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,49 @@ +include(../staticconfig.pri) + +!contains(build_examples, yes):error(Please use the -examples configure switch to enable building of examples) + +win32:contains(CONFIG_WIN32,build_all):Win32DebugAndRelease=yes +mac | contains(Win32DebugAndRelease,yes) { + #due to different debug/release library names we have to comply with + #whatever Qt does + !contains(QT_CONFIG,debug)|!contains(QT_CONFIG,release) { + CONFIG -= debug_and_release debug release + contains(QT_CONFIG,debug): CONFIG+=debug + contains(QT_CONFIG,release): CONFIG+=release + } +} + +CONFIG(debug, debug|release) { + SUBDIRPART=Debug +} else { + SUBDIRPART=Release +} + +OUTPUT_DIR = $$QT_MOBILITY_BUILD_TREE +DESTDIR = $$OUTPUT_DIR/bin/examples +MOC_DIR = $$OUTPUT_DIR/build/$$SUBDIRPART/$$TARGET/moc +RCC_DIR = $$OUTPUT_DIR/build/$$SUBDIRPART/$$TARGET/rcc +UI_DIR = $$OUTPUT_DIR/build/$$SUBDIRPART/$$TARGET/ui +OBJECTS_DIR = $$OUTPUT_DIR/build/$$SUBDIRPART/$$TARGET +mac:LIBS+= -F$$OUTPUT_DIR/lib +LIBS+= -L$$OUTPUT_DIR/lib +QMAKE_RPATHDIR+=$$OUTPUT_DIR/lib +INCLUDEPATH+= $$QT_MOBILITY_SOURCE_TREE/src/global + +maemo6 { + DEFINES+= Q_WS_MAEMO_6 + DEFINES+= QTM_EXAMPLES_SMALL_SCREEN + DEFINES+= QTM_EXAMPLES_PREFER_LANDSCAPE +} +maemo5 { + DEFINES+= Q_WS_MAEMO_5 + DEFINES+= QTM_EXAMPLES_SMALL_SCREEN + DEFINES+= QTM_EXAMPLES_PREFER_LANDSCAPE +} +symbian { + DEFINES+= QTM_EXAMPLES_SMALL_SCREEN +} +maemo* { + LIBS += -L/opt/qt4-maemo5/lib + QMAKE_LFLAGS += -Wl,-rpath,/opt/qt4-maemo5/lib +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/examples.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/examples.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,10 @@ +include(../staticconfig.pri) + +TEMPLATE = subdirs + +#BearerManagement examples +contains(mobility_modules,bearer) { + SUBDIRS += bearermonitor bearercloud +} +#BLD_INF_RULES.prj_exports += "./rom/qtmobilityexamples.iby $$CUSTOMER_VARIANT_APP_LAYER_IBY_EXPORT_PATH(qtmobilityexamples.iby)" + diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/rom/qtmobilityexamples.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/rom/qtmobilityexamples.iby Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published by +* the Free Software Foundation, version 2.1 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this program. If not, +* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". +* +* Description: +* +*/ + +#ifndef __QT_MOBILITYEXAMPLES_IBY__ +#define __QT_MOBILITYEXAMPLES_IBY__ + +#include + +#define UPGRADABLE_APP_REG_RSC(NAME) data=DATAZ_\PRIVATE\10003A3F\IMPORT\APPS\ ## NAME ## _reg.rsc Private\10003a3f\import\apps\ ## NAME ## _reg.rsc + +S60_APP_EXE(bearercloud) +S60_APP_RESOURCE(bearercloud) +UPGRADABLE_APP_REG_RSC(bearercloud) + +S60_APP_EXE(bearermonitor) +S60_APP_RESOURCE(bearermonitor) +UPGRADABLE_APP_REG_RSC(bearermonitor) + +#endif //__QT_MOBILITYEXAMPLES_IBY__ diff -r 000000000000 -r cfcbf08528c4 qtmobility/examples/s60installs/s60installs.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/examples/s60installs/s60installs.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,43 @@ +!symbian:error(This example is for Symbian packaging purposes only.) + +TEMPLATE = app +TARGET = S60Examples + +include(../../staticconfig.pri) + +TEMPLATE = subdirs + +load(data_caging_paths) + +#BearerManagement examples +contains(mobility_modules, bearer) { + SUBDIRS += ../bearermonitor \ + ../../tests/bearerex + executables.sources += \ + bearermonitor.exe \ + BearerEx.exe + + reg_resource.sources += \ + $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/bearermonitor_reg.rsc \ + $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/BearerEx_reg.rsc + resource.sources += \ + $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/bearermonitor.rsc \ + $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/BearerEx.rsc +} + +executables.path = /sys/bin +reg_resource.path = $$REG_RESOURCE_IMPORT_DIR +resource.path = $$APP_RESOURCE_DIR + +DEPLOYMENT += executables \ + pluginstubs \ + reg_resource \ + resource + +mifs.sources = \ + $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/0xA000C611.mif +mifs.path = $$APP_RESOURCE_DIR + + +# ensure that dependency to QtMobility sis package is added +CONFIG+=mobility diff -r 000000000000 -r cfcbf08528c4 qtmobility/features/deploy.pri --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/features/deploy.pri Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,38 @@ +headers.files = $$PUBLIC_HEADERS +headers.path = $$QT_MOBILITY_INCLUDE + +contains(TEMPLATE,.*lib) { + target.path=$$QT_MOBILITY_LIB + TARGET = $$qtLibraryTarget($${TARGET}) + + symbian { + middleware { path=$$MW_LAYER_PUBLIC_EXPORT_PATH("") } + app { path=$$APP_LAYER_PUBLIC_EXPORT_PATH("") } + + exportPath=$$EPOCROOT"."$$dirname(path) + nativePath=$$replace(exportPath, /,\) + exists($$nativePath) { + } else { + system($$QMAKE_MKDIR $$nativePath) + } + + for(header, headers.files) { + middleware { BLD_INF_RULES.prj_exports += "$$header $$MW_LAYER_PUBLIC_EXPORT_PATH($$basename(header))"} + app { BLD_INF_RULES.prj_exports += "$$header $$APP_LAYER_PUBLIC_EXPORT_PATH($$basename(header))"} + } + + } + +} else { + contains(TEMPLATE,.*app):target.path=$$QT_MOBILITY_BIN +} + +INSTALLS+=target headers + +mac:contains(QT_CONFIG,qt_framework) { + CONFIG += lib_bundle absolute_library_soname + FRAMEWORK_HEADERS.version = Versions + FRAMEWORK_HEADERS.files = $${PUBLIC_HEADERS} + FRAMEWORK_HEADERS.path = Headers + QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/features/mobility.prf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/features/mobility.prf Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,71 @@ +MOBILITY_PREFIX=$${EPOCROOT}sf/mw/qtextensions/qtmobility +MOBILITY_INCLUDE=$${EPOCROOT}sf/mw/qtextensions/qtmobility/include +MOBILITY_LIB=$${EPOCROOT}sf/mw/qtextensions/qtmobility/lib + +!symbian { + INCLUDEPATH += $${MOBILITY_INCLUDE} +} else { + load(data_caging_paths) + contains(MOBILITY, contacts|versit) { + INCLUDEPATH+=$$APP_LAYER_SYSTEMINCLUDE + } + + contains(MOBILITY,bearer|location|publishsubscribe|systeminfo|multimedia|messaging|serviceframework) { + INCLUDEPATH+=$$MW_LAYER_SYSTEMINCLUDE + } +} +mac: LIBS += -F$${MOBILITY_LIB} +LIBS+= -L$${MOBILITY_LIB} + +contains(MOBILITY, bearer) { + qtAddLibrary(QtBearer) +} + +contains(MOBILITY, publishsubscribe) { + qtAddLibrary(QtPublishSubscribe) +} + +contains(MOBILITY, location) { + qtAddLibrary(QtLocation) +} + +contains(MOBILITY, serviceframework) { + qtAddLibrary(QtServiceFramework) +} + +contains(MOBILITY, systeminfo) { + #QSystemInfo header requires QNetworkInterface + QT += network + qtAddLibrary(QtSystemInfo) +} + +contains(MOBILITY, multimedia) { + qtAddLibrary(QtMedia) +} + +contains(MOBILITY, contacts) { + qtAddLibrary(QtContacts) +} + +contains(MOBILITY, messaging) { + qtAddLibrary(QtMessaging) +} + +contains(MOBILITY, versit) { + qtAddLibrary(QtVersit) +} + +contains(MOBILITY, sensors) { + qtAddLibrary(QtSensors) +} + +# Add dependency to QtMobility package to all projects besides QtMobility package itself. +# Mobility libs have UID3 0x2002AC89 +# self-signed Mobility libs have UID3 0xE002AC89 +symbian:contains(CONFIG, mobility):!contains(TARGET.UID3, 0x2002AC89):!contains(TARGET.UID3, 0xE002AC89) { + mobility_default_deployment.pkg_prerules += \ + "; Default dependency to QtMobility libraries" \ + "(0x2002AC89), 1, 0, 0, {\"QtMobility\"}" + DEPLOYMENT += mobility_default_deployment +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/features/mobility.prf.template --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/features/mobility.prf.template Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,68 @@ + +!symbian { + INCLUDEPATH += $${MOBILITY_INCLUDE} +} else { + load(data_caging_paths) + contains(MOBILITY, contacts|versit) { + INCLUDEPATH+=$$APP_LAYER_SYSTEMINCLUDE + } + + contains(MOBILITY,bearer|location|publishsubscribe|systeminfo|multimedia|messaging|serviceframework) { + INCLUDEPATH+=$$MW_LAYER_SYSTEMINCLUDE + } +} +mac: LIBS += -F$${MOBILITY_LIB} +LIBS+= -L$${MOBILITY_LIB} + +contains(MOBILITY, bearer) { + qtAddLibrary(QtBearer) +} + +contains(MOBILITY, publishsubscribe) { + qtAddLibrary(QtPublishSubscribe) +} + +contains(MOBILITY, location) { + qtAddLibrary(QtLocation) +} + +contains(MOBILITY, serviceframework) { + qtAddLibrary(QtServiceFramework) +} + +contains(MOBILITY, systeminfo) { + #QSystemInfo header requires QNetworkInterface + QT += network + qtAddLibrary(QtSystemInfo) +} + +contains(MOBILITY, multimedia) { + qtAddLibrary(QtMedia) +} + +contains(MOBILITY, contacts) { + qtAddLibrary(QtContacts) +} + +contains(MOBILITY, messaging) { + qtAddLibrary(QtMessaging) +} + +contains(MOBILITY, versit) { + qtAddLibrary(QtVersit) +} + +contains(MOBILITY, sensors) { + qtAddLibrary(QtSensors) +} + +# Add dependency to QtMobility package to all projects besides QtMobility package itself. +# Mobility libs have UID3 0x2002AC89 +# self-signed Mobility libs have UID3 0xE002AC89 +symbian:contains(CONFIG, mobility):!contains(TARGET.UID3, 0x2002AC89):!contains(TARGET.UID3, 0xE002AC89) { + mobility_default_deployment.pkg_prerules += \ + "; Default dependency to QtMobility libraries" \ + "(0x2002AC89), 1, 0, 0, {\"QtMobility\"}" + DEPLOYMENT += mobility_default_deployment +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/features/strict_flags.prf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/features/strict_flags.prf Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,38 @@ +# This functionality is opt-in via the STRICT environment variable +# export STRICT=1 on Unix +# set STRICT=1 on Windows +STRICT=$$(STRICT) +equals(STRICT,1) { + win32 { + QMAKE_CXXFLAGS+=-WX + } else { + QMAKE_CXXFLAGS+=-Werror + QMAKE_CXXFLAGS+=-Wall + # There are legitimate cases that conflict with this warning (QSensorFilter::filter) + #QMAKE_CXXFLAGS+=-Woverloaded-virtual + # This breaks in QML headers + #QMAKE_CXXFLAGS+=-Wold-style-cast + # This breaks in QML headers + #QMAKE_CXXFLAGS+=-pedantic + QMAKE_CXXFLAGS+=-ansi + QMAKE_CXXFLAGS+=-Wno-long-long + # This breaks in Qt headers + #QMAKE_CXXFLAGS+=-Wshadow + # This breaks everywhere + #QMAKE_CXXFLAGS+=-Wunreachable-code + QMAKE_CXXFLAGS+=-Wundef + QMAKE_CXXFLAGS+=-Wformat-nonliteral + QMAKE_CXXFLAGS+=-Wformat-security + QMAKE_CXXFLAGS+=-Wcast-align + QMAKE_CXXFLAGS+=-Wchar-subscripts + # This breaks in Qt headers + #QMAKE_CXXFLAGS+=-Wfloat-equal + QMAKE_LFLAGS+=-Wl,-no-undefined + } + + contains(TEMPLATE,lib) { + DEFINES += QT_NO_CAST_FROM_ASCII + CONFIG += no_keywords + } +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/implml/qtmobility_copy.implml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/implml/qtmobility_copy.implml Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,10 @@ + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/qtmobility.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/qtmobility.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,83 @@ + +#This is a temporary workaround for internal Symbian builds +#QT_MAJOR_VERSION et al are not set +symbian { + isEmpty(QT_MAJOR_VERSION) { + exists($${EPOCROOT}epoc32/data/z/system/install/Series60v5.2.sis) { + QT_MAJOR_VERSION=4; + QT_MINOR_VERSION=6; + QT_PATCH_VERSION=0; + } + } +} + +# config.pri specifies the configure options +include(staticconfig.pri) +!include($$QT_MOBILITY_BUILD_TREE/config.pri) { + error("Please run configure script"); + #also fails if .qmake.cache was not generated which may + #happen if we are trying to shadow build w/o running configure +} + + +#don't build QtMobility if chosen config mismatches Qt's config +win32:!contains(CONFIG_WIN32,build_all) { + contains(QT_CONFIG,debug):!contains(QT_CONFIG,release):contains(CONFIG_WIN32,release) { + # Qt only build in debug mode + error(QtMobility cannot be build in release mode if Qt is build in debug mode only) + } + !contains(QT_CONFIG,debug):contains(QT_CONFIG,release):contains(CONFIG_WIN32,debug) { + # Qt only build in release mode + error(QtMobility cannot be build in debug mode if Qt is build in release mode only) + } +} + +#lessThan(QT_MAJOR_VERSION, 4) { +# error(Qt Mobility requires Qt 4.6 or higher. Qt $${QT_VERSION} was found.); +#} + +#contains(QT_MAJOR_VERSION, 4):lessThan(QT_MINOR_VERSION, 6) { +# error(Qt Mobility requires Qt 4.6 or higher. Qt $${QT_VERSION} was found.); +#} + + +#generate prf file for Qt integration +#PRF_OUTPUT=$${QT_MOBILITY_BUILD_TREE}/features/mobility.prf + +#system(echo MOBILITY_PREFIX=$${QT_MOBILITY_PREFIX} > $$PRF_OUTPUT) +#system(echo MOBILITY_INCLUDE=$${QT_MOBILITY_INCLUDE} >> $$PRF_OUTPUT) +#system(echo MOBILITY_LIB=$${QT_MOBILITY_LIB} >> $$PRF_OUTPUT) + +#MOD_QT_MOBILITY_SOURCE_TREE=$$replace(QT_MOBILITY_SOURCE_TREE, /, \\) +#unix:!symbian:system(cat $${QT_MOBILITY_SOURCE_TREE}/features/mobility.prf.template >> $$PRF_OUTPUT) +#win32:system(type $${QT_MOBILITY_SOURCE_TREE}\features\mobility.prf.template >> $$PRF_OUTPUT) +#symbian:system(type $${MOD_QT_MOBILITY_SOURCE_TREE}\features\mobility.prf.template >> $$PRF_OUTPUT) + +#MOD_QT_MOBILITY_BUILD_TREE=$$replace(QT_MOBILITY_BUILD_TREE, /, \\) +#INSTALL_DATA=$$[QT_INSTALL_DATA] +#MOD_QT_INSTALL_DATA=$$replace(INSTALL_DATA, /, \\) +#symbian does not generate make install rule. we have to copy prf manually +#symbian:system(copy $${MOD_QT_MOBILITY_BUILD_TREE}\features\mobility.prf $${MOD_QT_INSTALL_DATA}\mkspecs\features) + +# install feature file +#feature.path = $$[QT_INSTALL_DATA]/mkspecs/features +#feature.files = $$QT_MOBILITY_BUILD_TREE/features/mobility.prf +#INSTALLS += feature + +TEMPLATE = subdirs +CONFIG+=ordered + +SUBDIRS += src + +#contains(build_unit_tests, yes):SUBDIRS+=tests +#contains(build_examples, yes):SUBDIRS+=examples + +# install Qt style headers +qtmheaders.path = $${QT_MOBILITY_INCLUDE} +qtmheaders.files = $${QT_MOBILITY_BUILD_TREE}/include/* + +INSTALLS += qtmheaders + +symbian { +#BLD_INF_RULES.prj_exports += "./rom/qtmobility.iby $$CORE_MW_LAYER_IBY_EXPORT_PATH(qtmobility.iby)" +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/rom/qtmobility.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/rom/qtmobility.iby Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published by +* the Free Software Foundation, version 2.1 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this program. If not, +* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". +* +* Description: +* +*/ + +#ifndef __QT_MOBILITY_IBY__ +#define __QT_MOBILITY_IBY__ + +#include + +#ifdef FF_QT_BEARER_MANAGEMENT +file=ABI_DIR\BUILD_DIR\qtbearer.dll SHARED_LIB_DIR\qtbearer.dll PAGED +data=ZSYSTEM\install\qtmobility_stub.sis \system\install\qtmobility_stub.sis +#endif // FF_QT_BEARER_MANAGEMENT + +#endif // __QT_MOBILITY_IBY__ diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/bearer.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/bearer.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,155 @@ +# Qt bearer management library +TEMPLATE = lib +TARGET = QtBearer + +QT += network +include (../../common.pri) + +DEFINES += QT_BUILD_BEARER_LIB QT_MAKEDLL + +#DEFINES += BEARER_MANAGEMENT_DEBUG + +PUBLIC_HEADERS += qnetworkconfiguration.h \ + qnetworksession.h \ + qnetworkconfigmanager.h + +HEADERS += $$PUBLIC_HEADERS +SOURCES += qnetworksession.cpp \ + qnetworkconfigmanager.cpp \ + qnetworkconfiguration.cpp + +symbian: { + contains(snap_enabled, yes) { + message("Building with SNAP support") + DEFINES += SNAP_FUNCTIONALITY_AVAILABLE=1 + LIBS += -lcmmanager + } else { + message("Building without SNAP support") + LIBS += -lapengine + } + + INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE + + HEADERS += qnetworkconfigmanager_s60_p.h \ + qnetworkconfiguration_s60_p.h \ + qnetworksession_s60_p.h + SOURCES += qnetworkconfigmanager_s60_p.cpp \ + qnetworkconfiguration_s60_p.cpp \ + qnetworksession_s60_p.cpp + + LIBS += -lcommdb \ + -lapsettingshandlerui \ + -lconnmon \ + -lcentralrepository \ + -lesock \ + -linsock \ + -lecom \ + -lefsrv \ + -lnetmeta + + TARGET.CAPABILITY = ALL -TCB + TARGET.UID3 = 0x2002AC81 + + QtBearerManagement.sources = QtBearer.dll + QtBearerManagement.path = /sys/bin + DEPLOYMENT += QtBearerManagement +} else { + maemo6 { + CONFIG += link_pkgconfig + + exists(../debug) { + message("Enabling debug messages.") + DEFINES += BEARER_MANAGEMENT_DEBUG + } + + HEADERS += qnetworksession_maemo_p.h \ + qnetworkconfigmanager_maemo_p.h \ + qnetworkconfiguration_maemo_p.h + + SOURCES += qnetworkconfigmanager_maemo.cpp \ + qnetworksession_maemo.cpp + + documentation.path = $$QT_MOBILITY_PREFIX/doc + documentation.files = doc/html + + PKGCONFIG += glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet + + CONFIG += create_pc create_prl + QMAKE_PKGCONFIG_REQUIRES = glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet + pkgconfig.path = $$QT_MOBILITY_LIB/pkgconfig + pkgconfig.files = QtBearer.pc + + INSTALLS += pkgconfig documentation + + } else { + + DEFINES += BEARER_ENGINE + + HEADERS += qnetworkconfigmanager_p.h \ + qnetworkconfiguration_p.h \ + qnetworksession_p.h \ + qnetworksessionengine_p.h \ + qgenericengine_p.h + + SOURCES += qnetworkconfigmanager_p.cpp \ + qnetworksession_p.cpp \ + qnetworksessionengine.cpp \ + qgenericengine.cpp + + unix:!mac:contains(networkmanager_enabled, yes) { + contains(QT_CONFIG,dbus) { + DEFINES += BACKEND_NM + QT += dbus + + HEADERS += qnmdbushelper_p.h \ + qnetworkmanagerservice_p.h \ + qnmwifiengine_unix_p.h + + SOURCES += qnmdbushelper.cpp \ + qnetworkmanagerservice_p.cpp \ + qnmwifiengine_unix.cpp + } else { + message("NetworkManager backend requires Qt DBus support") + } + } + + win32: { + HEADERS += qnlaengine_win_p.h \ + qnetworksessionengine_win_p.h + + !wince*:HEADERS += qnativewifiengine_win_p.h + + SOURCES += qnlaengine_win.cpp + + !wince*:SOURCES += qnativewifiengine_win.cpp + + !wince*:LIBS += -lWs2_32 + wince*:LIBS += -lWs2 + } + } + macx: { + HEADERS += qcorewlanengine_mac_p.h + SOURCES+= qcorewlanengine_mac.mm + LIBS += -framework Foundation -framework SystemConfiguration + + contains(corewlan_enabled, yes) { + isEmpty(QMAKE_MAC_SDK) { + SDK6="yes" + } else { + contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { + SDK6="yes" + } + } + + !isEmpty(SDK6) { + LIBS += -framework CoreWLAN + DEFINES += MAC_SDK_10_6 + } + } + + + } +} + +CONFIG += middleware +include(../../features/deploy.pri) diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qcorewlanengine_mac.mm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qcorewlanengine_mac.mm Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,551 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qcorewlanengine_mac_p.h" +#include "qnetworkconfiguration_p.h" + +#include +#include +#include +#include + +#include + +#if defined(MAC_SDK_10_6) //not much functionality without this +#include +#include +#include +#include +#endif + +#include +#include +#include + +#include +QMap networkInterfaces; + +#ifdef MAC_SDK_10_6 +@interface QNSListener : NSObject +{ + NSNotificationCenter *center; + CWInterface * currentInterface; +} +- (void)notificationHandler:(NSNotification *)notification; +- (void)remove; +@end + +@implementation QNSListener +- (id) init +{ + [super init]; + center = [NSNotificationCenter defaultCenter]; + currentInterface = [CWInterface interface]; + [center addObserver:self selector:@selector(notificationHandler:) name:kCWLinkDidChangeNotification object:nil]; + [center addObserver:self selector:@selector(notificationHandler:) name:kCWPowerDidChangeNotification object:nil]; + + return self; +} + +-(void)dealloc +{ + [center release]; + [currentInterface release]; + [super dealloc]; +} + +-(void)remove +{ + [center removeObserver:self]; +} + +- (void)notificationHandler:(NSNotification *)notification +{ + QTM_NAMESPACE::QCoreWlanEngine::instance()->requestUpdate(); +} +@end +#endif + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) + +inline QString cfstringRefToQstring(CFStringRef cfStringRef) { + QString retVal; + CFIndex maxLength = 2 * CFStringGetLength(cfStringRef) + 1/*zero term*/; // max UTF8 + char *cstring = new char[maxLength]; + if (CFStringGetCString(CFStringRef(cfStringRef), cstring, maxLength, kCFStringEncodingUTF8)) { + retVal = QString::fromUtf8(cstring); + } + delete[] cstring; + return retVal; +} + +inline CFStringRef qstringToCFStringRef(const QString &string) +{ + return CFStringCreateWithCharacters(0, reinterpret_cast(string.unicode()), + string.length()); +} + +inline NSString *qstringToNSString(const QString &qstr) +{ return [reinterpret_cast(qstringToCFStringRef(qstr)) autorelease]; } + +inline QString nsstringToQString(const NSString *nsstr) +{ return cfstringRefToQstring(reinterpret_cast(nsstr)); } + +inline QStringList nsarrayToQStringList(void *nsarray) +{ + QStringList result; + NSArray *array = static_cast(nsarray); + for (NSUInteger i=0; i<[array count]; ++i) + result << nsstringToQString([array objectAtIndex:i]); + return result; +} + +static QString qGetInterfaceType(const QString &interfaceString) +{ + return networkInterfaces.value(interfaceString, QLatin1String("Unknown")); +} + +void networkChangeCallback(SCDynamicStoreRef/* store*/, CFArrayRef changedKeys, void *info) +{ + for ( long i = 0; i < CFArrayGetCount(changedKeys); i++) { + + CFStringRef changed = (CFStringRef)CFArrayGetValueAtIndex(changedKeys, i); + if( cfstringRefToQstring(changed).contains("/Network/Global/IPv4")) { + QCoreWlanEngine* wlanEngine = static_cast(info); + wlanEngine->requestUpdate(); + } + } + return; +} + +QCoreWlanEngine::QCoreWlanEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + getAllScInterfaces(); + startNetworkChangeLoop(); +#ifdef MAC_SDK_10_6 + QNSListener *listener; + listener = [[QNSListener alloc] init]; +#endif + requestUpdate(); +} + +QCoreWlanEngine::~QCoreWlanEngine() +{ + QNetworkConfigurationPrivate* cpPriv = 0; + foundConfigurations.clear(); + while(!foundConfigurations.isEmpty()) { + cpPriv = foundConfigurations.takeFirst(); + delete cpPriv; + } +} + +QList QCoreWlanEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + foundConfigurations.clear(); + + uint identifier; + QMapIterator i(networkInterfaces); + QNetworkConfigurationPrivate* cpPriv = 0; + while (i.hasNext()) { + i.next(); + if (i.value() == "WLAN") { + QList fetchedConfigurations = scanForSsids(i.key()); + for (int i = 0; i < fetchedConfigurations.count(); ++i) { + + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate(); + cpPriv = fetchedConfigurations.at(i); + config->name = cpPriv->name; + config->isValid = cpPriv->isValid; + config->id = cpPriv->id; + + config->state = cpPriv->state; + config->type = cpPriv->type; + config->roamingSupported = cpPriv->roamingSupported; + config->purpose = cpPriv->purpose; + config->internet = cpPriv->internet; + config->serviceInterface = cpPriv->serviceInterface; + config->bearer = cpPriv->bearer; + + identifier = config->name.toUInt(); + configurationInterface[identifier] = config->serviceInterface.name(); + foundConfigurations.append(config); + delete cpPriv; + } + } + + QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate(); + const QString humanReadableName = interface.humanReadableName(); + cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; + cpPriv->isValid = true; + + if (interface.index()) + identifier = interface.index(); + else + identifier = qHash(interface.hardwareAddress()); + + cpPriv->id = QString::number(identifier); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Undefined; + + if (interface.flags() & QNetworkInterface::IsRunning) { + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->internet = true; + } + if ( !interface.addressEntries().isEmpty()) { + cpPriv->state |= QNetworkConfiguration::Active; + cpPriv->internet = true; + } + configurationInterface[identifier] = interface.name(); + cpPriv->bearer = interface.name().isEmpty()? QLatin1String("Unknown") : qGetInterfaceType(interface.name()); + foundConfigurations.append(cpPriv); + } + + pollTimer.start(); + return foundConfigurations; +} + +QString QCoreWlanEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QCoreWlanEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +void QCoreWlanEngine::connectToId(const QString &id) +{ + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QString interfaceString = getInterfaceFromId(id); + + if(networkInterfaces.value(interfaceString) == "WLAN") { +#if defined(MAC_SDK_10_6) + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; + CWConfiguration *userConfig = [ wifiInterface configuration]; + + NSSet *remNets = [userConfig rememberedNetworks]; //CWWirelessProfile + + NSEnumerator *enumerator = [remNets objectEnumerator]; + CWWirelessProfile *wProfile; + NSUInteger index=0; + + NSDictionary *parametersDict; + NSArray* apArray; + + CW8021XProfile *user8021XProfile; + NSError *err; + NSMutableDictionary *params; + + while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile + + if(id == nsstringToQString([wProfile ssid])) { + user8021XProfile = nil; + user8021XProfile = [ wProfile user8021XProfile]; + + err = nil; + params = [NSMutableDictionary dictionaryWithCapacity:0]; + + if(user8021XProfile) { + [params setValue: user8021XProfile forKey:kCWAssocKey8021XProfile]; + } else { + [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; + } + + parametersDict = nil; + apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; + + if(!err) { + + for(uint row=0; row < [apArray count]; row++ ) { + CWNetwork *apNetwork = [apArray objectAtIndex:row]; + if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { + + bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; + + if(!result) { + emit connectionError(id, ConnectError); + } else { + [autoreleasepool release]; + return; + } + } + } + } + } + index++; + } + + emit connectionError(id, InterfaceLookupError); +#endif + } else { + // not wifi + } + emit connectionError(id, OperationNotSupported); + [autoreleasepool release]; +} + +void QCoreWlanEngine::disconnectFromId(const QString &id) +{ + QString interfaceString = getInterfaceFromId(id); + if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now +#if defined(MAC_SDK_10_6) + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; + [wifiInterface disassociate]; + if([[wifiInterface interfaceState]intValue] != kCWInterfaceStateInactive) { + emit connectionError(id, DisconnectionError); + } + [autoreleasepool release]; + return; +#endif + } else { + + } + emit connectionError(id, OperationNotSupported); +} + +void QCoreWlanEngine::requestUpdate() +{ + getAllScInterfaces(); + emit configurationsChanged(); +} + +QCoreWlanEngine *QCoreWlanEngine::instance() +{ + return coreWlanEngine(); +} + +QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) +{ + QList foundConfigs; +#if defined(MAC_SDK_10_6) + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)]; + if([currentInterface power]) { + NSError *err = nil; + NSDictionary *parametersDict = nil; + NSArray* apArray = [currentInterface scanForNetworksWithParameters:parametersDict error:&err]; + + CWNetwork *apNetwork; + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { + NSAutoreleasePool *looppool = [[NSAutoreleasePool alloc] init]; + + apNetwork = [apArray objectAtIndex:row]; + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QString networkSsid = nsstringToQString([apNetwork ssid]); + cpPriv->name = networkSsid; + cpPriv->isValid = true; + cpPriv->id = networkSsid; + cpPriv->internet = true; + cpPriv->bearer = QLatin1String("WLAN"); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(interfaceName); + + if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { + QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); + if( cpPriv->name == interfaceSsidString) { + cpPriv->state |= QNetworkConfiguration::Active; + } + } + if(!cpPriv->state) { + if(isKnownSsid(cpPriv->serviceInterface.name(), networkSsid)) { + cpPriv->state = QNetworkConfiguration::Discovered; + } else { + cpPriv->state = QNetworkConfiguration::Defined; + } + } + if(!cpPriv->state) { + cpPriv->state = QNetworkConfiguration::Undefined; + } + if([[apNetwork securityMode ] intValue]== kCWSecurityModeOpen) + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + else + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + foundConfigs.append(cpPriv); + [looppool release]; + } + } + } + [autoreleasepool drain]; +#else + Q_UNUSED(interfaceName); +#endif + return foundConfigs; +} + +bool QCoreWlanEngine::isWifiReady(const QString &wifiDeviceName) +{ +#if defined(MAC_SDK_10_6) + CWInterface *defaultInterface = [CWInterface interfaceWithName: qstringToNSString(wifiDeviceName)]; + if([defaultInterface power]) + return true; +#else + Q_UNUSED(wifiDeviceName); +#endif + return false; +} + +bool QCoreWlanEngine::isKnownSsid(const QString &interfaceName, const QString &ssid) +{ +#if defined(MAC_SDK_10_6) + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceName)]; + CWConfiguration *userConfig = [wifiInterface configuration]; + NSSet *remNets = [userConfig rememberedNetworks]; + for (CWWirelessProfile *wProfile in remNets) { + if(ssid == nsstringToQString([wProfile ssid])) + return true; + } +#else + Q_UNUSED(interfaceName); + Q_UNUSED(ssid); +#endif + return false; +} + +bool QCoreWlanEngine::getAllScInterfaces() +{ + networkInterfaces.clear(); + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + CFArrayRef interfaces = SCNetworkInterfaceCopyAll(); + if (interfaces != NULL) { + CFIndex interfaceCount; + CFIndex interfaceIndex; + interfaceCount = CFArrayGetCount(interfaces); + for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { + NSAutoreleasePool *looppool = [[NSAutoreleasePool alloc] init]; + + CFStringRef bsdName; + CFTypeRef thisInterface = CFArrayGetValueAtIndex(interfaces, interfaceIndex); + bsdName = SCNetworkInterfaceGetBSDName((SCNetworkInterfaceRef)thisInterface); + QString interfaceName = cfstringRefToQstring(bsdName); + QString typeStr; + CFStringRef type = SCNetworkInterfaceGetInterfaceType((SCNetworkInterfaceRef)thisInterface); + if ( CFEqual(type, kSCNetworkInterfaceTypeIEEE80211)) { + typeStr = "WLAN"; +// } else if (CFEqual(type, kSCNetworkInterfaceTypeBluetooth)) { +// typeStr = "Bluetooth"; + } else if(CFEqual(type, kSCNetworkInterfaceTypeEthernet)) { + typeStr = "Ethernet"; + } else if(CFEqual(type, kSCNetworkInterfaceTypeFireWire)) { + typeStr = "Ethernet"; //ok a bit fudged + } + if(!networkInterfaces.contains(interfaceName) && !typeStr.isEmpty()) { + networkInterfaces.insert(interfaceName,typeStr); + } + [looppool release]; + } + } + CFRelease(interfaces); + + [autoreleasepool drain]; + return true; +} + +void QCoreWlanEngine::startNetworkChangeLoop() +{ + storeSession = NULL; + + SCDynamicStoreContext dynStoreContext = { 0, this/*(void *)storeSession*/, NULL, NULL, NULL }; + storeSession = SCDynamicStoreCreate(NULL, + CFSTR("networkChangeCallback"), + networkChangeCallback, + &dynStoreContext); + if (!storeSession ) { + qWarning() << "could not open dynamic store: error:" << SCErrorString(SCError()); + return; + } + + CFMutableArrayRef notificationKeys; + notificationKeys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + CFMutableArrayRef patternsArray; + patternsArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + + CFStringRef storeKey; + storeKey = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, + kSCDynamicStoreDomainState, + kSCEntNetIPv4); + CFArrayAppendValue(notificationKeys, storeKey); + CFRelease(storeKey); + + storeKey = SCDynamicStoreKeyCreateNetworkServiceEntity(NULL, + kSCDynamicStoreDomainState, + kSCCompAnyRegex, + kSCEntNetIPv4); + CFArrayAppendValue(patternsArray, storeKey); + CFRelease(storeKey); + + if (!SCDynamicStoreSetNotificationKeys(storeSession , notificationKeys, patternsArray)) { + qWarning() << "register notification error:"<< SCErrorString(SCError()); + CFRelease(storeSession ); + CFRelease(notificationKeys); + CFRelease(patternsArray); + return; + } + CFRelease(notificationKeys); + CFRelease(patternsArray); + + runloopSource = SCDynamicStoreCreateRunLoopSource(NULL, storeSession , 0); + if (!runloopSource) { + qWarning() << "runloop source error:"<< SCErrorString(SCError()); + CFRelease(storeSession ); + return; + } + + CFRunLoopAddSource(CFRunLoopGetCurrent(), runloopSource, kCFRunLoopDefaultMode); + return; +} + + +#include "moc_qcorewlanengine_mac_p.cpp" + +QTM_END_NAMESPACE + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qcorewlanengine_mac_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qcorewlanengine_mac_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCOREWLANENGINE_P_H +#define QCOREWLANENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworksessionengine_p.h" +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QCoreWlanEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QCoreWlanEngine(QObject *parent = 0); + ~QCoreWlanEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QCoreWlanEngine *instance(); + static bool getAllScInterfaces(); + +private: + bool isWifiReady(const QString &dev); + QMap configurationInterface; + QTimer pollTimer; + QList scanForSsids(const QString &interfaceName); + + bool isKnownSsid(const QString &interfaceName, const QString &ssid); + QList foundConfigurations; + + SCDynamicStoreRef storeSession; + CFRunLoopSourceRef runloopSource; + + void startNetworkChangeLoop(); + +}; + +QTM_END_NAMESPACE + +#endif + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qgenericengine.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qgenericengine.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgenericengine_p.h" +#include "qnetworkconfiguration_p.h" + +#include +#include +#include +#include + +#include + +#ifdef Q_OS_WIN +#include "qnetworksessionengine_win_p.h" +#endif + +#ifdef Q_OS_LINUX +#include +#include +#include +#include +#endif + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QGenericEngine, genericEngine) + +static QString qGetInterfaceType(const QString &interface) +{ +#ifdef Q_OS_WIN32 + unsigned long oid; + DWORD bytesWritten; + + NDIS_MEDIUM medium; + NDIS_PHYSICAL_MEDIUM physicalMedium; + + HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, + FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (handle == INVALID_HANDLE_VALUE) + return QLatin1String("Unknown"); + + oid = OID_GEN_MEDIA_SUPPORTED; + bytesWritten = 0; + bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &medium, sizeof(medium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + return QLatin1String("Unknown"); + } + + oid = OID_GEN_PHYSICAL_MEDIUM; + bytesWritten = 0; + result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + + if (medium == NdisMedium802_3) + return QLatin1String("Ethernet"); + else + return QLatin1String("Unknown"); + } + + CloseHandle(handle); + + if (medium == NdisMedium802_3) { + switch (physicalMedium) { + case NdisPhysicalMediumWirelessLan: + return QLatin1String("WLAN"); + case NdisPhysicalMediumBluetooth: + return QLatin1String("Bluetooth"); + case NdisPhysicalMediumWiMax: + return QLatin1String("WiMAX"); + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Physical Medium" << physicalMedium; +#endif + return QLatin1String("Ethernet"); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << medium << physicalMedium; +#endif +#elif defined(Q_OS_LINUX) + int sock = socket(AF_INET, SOCK_DGRAM, 0); + + ifreq request; + strncpy(request.ifr_name, interface.toLocal8Bit().data(), sizeof(request.ifr_name)); + int result = ioctl(sock, SIOCGIFHWADDR, &request); + close(sock); + + if (result >= 0 && request.ifr_hwaddr.sa_family == ARPHRD_ETHER) + return QLatin1String("Ethernet"); +#else + Q_UNUSED(interface); +#endif + + return QLatin1String("Unknown"); +} + +QGenericEngine::QGenericEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QGenericEngine::~QGenericEngine() +{ +} + +QList QGenericEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + + QList foundConfigurations; + + // Immediately after connecting with a wireless access point + // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a + // second time results in a non-empty list. If we loose interfaces we will end up removing + // network configurations which will break current sessions. + QList interfaces = QNetworkInterface::allInterfaces(); + if (interfaces.isEmpty()) + interfaces = QNetworkInterface::allInterfaces(); + + // create configuration for each interface + while (!interfaces.isEmpty()) { + QNetworkInterface interface = interfaces.takeFirst(); + + if (!interface.isValid()) + continue; + + // ignore loopback interface + if (interface.flags() & QNetworkInterface::IsLoopBack) + continue; + + // ignore WLAN interface handled in seperate engine + if (qGetInterfaceType(interface.name()) == "WLAN") + continue; + + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString humanReadableName = interface.humanReadableName(); + cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; + cpPriv->isValid = true; + + uint identifier; + if (interface.index()) + identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index())); + else + identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress()); + + cpPriv->id = QString::number(identifier); + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + if (interface.name().isEmpty()) + cpPriv->bearer = QLatin1String("Unknown"); + else + cpPriv->bearer = qGetInterfaceType(interface.name()); + + if (interface.flags() & QNetworkInterface::IsUp) + cpPriv->state |= QNetworkConfiguration::Active; + + configurationInterface[identifier] = interface.name(); + + foundConfigurations.append(cpPriv); + } + + pollTimer.start(); + + return foundConfigurations; +} + +QString QGenericEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QGenericEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +/*QString QGenericEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QLatin1String("Unknown"); + + return qGetInterfaceType(interface); +}*/ + +void QGenericEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::requestUpdate() +{ + emit configurationsChanged(); +} + +QGenericEngine *QGenericEngine::instance() +{ + return genericEngine(); +} + +#include "moc_qgenericengine_p.cpp" +QTM_END_NAMESPACE + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qgenericengine_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qgenericengine_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGENERICENGINE_P_H +#define QGENERICENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworksessionengine_p.h" + +#include +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QGenericEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QGenericEngine(QObject *parent = 0); + ~QGenericEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + //QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QGenericEngine *instance(); + +private: + QMap configurationInterface; + QTimer pollTimer; +}; + +QTM_END_NAMESPACE + +#endif + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnativewifiengine_win.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnativewifiengine_win.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,729 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnativewifiengine_win_p.h" +#include "qnetworkconfiguration_p.h" + +#include +#include +#include +#include + +#include + +#include +#undef interface + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) + +#define WLAN_MAX_NAME_LENGTH 256 +#define WLAN_MAX_PHY_TYPE_NUMBER 8 +#define WLAN_NOTIFICATION_SOURCE_ALL 0x0000ffff +#define WLAN_AVAILABLE_NETWORK_CONNECTED 1 +#define WLAN_AVAILABLE_NETWORK_HAS_PROFILE 2 +#define DOT11_SSID_MAX_LENGTH 32 + +struct WLAN_NOTIFICATION_DATA { + DWORD NotificationSource; + DWORD NotificationCode; + GUID InterfaceGuid; + DWORD dwDataSize; + PVOID pData; +}; + +enum WLAN_INTERFACE_STATE { + wlan_interface_state_not_ready = 0, + wlan_interface_state_connected, + wlan_interface_state_ad_hoc_network_formed, + wlan_interface_state_disconnecting, + wlan_interface_state_disconnected, + wlan_interface_state_associating, + wlan_interface_state_discovering, + wlan_interface_state_authenticating +}; + +struct WLAN_INTERFACE_INFO { + GUID InterfaceGuid; + WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH]; + WLAN_INTERFACE_STATE isState; +}; + +struct WLAN_INTERFACE_INFO_LIST { + DWORD dwNumberOfItems; + DWORD dwIndex; + WLAN_INTERFACE_INFO InterfaceInfo[1]; +}; + +struct DOT11_SSID { + ULONG uSSIDLength; + UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]; +}; + +struct NDIS_OBJECT_HEADER { + UCHAR Type; + UCHAR Revision; + USHORT Size; +}; + +typedef UCHAR DOT11_MAC_ADDRESS[6]; +struct DOT11_BSSID_LIST { + NDIS_OBJECT_HEADER Header; + ULONG uNumberOfEntries; + ULONG uTotalNumOfEntries; + DOT11_MAC_ADDRESS BSSIDs[1]; +}; + +enum DOT11_BSS_TYPE { + dot11_BSS_type_infrastructure = 1, + dot11_BSS_type_independent = 2, + dot11_BSS_type_any = 3 +}; + +enum DOT11_PHY_TYPE { + dot11_phy_type_unknown = 0, + dot11_phy_type_any = dot11_phy_type_unknown, + dot11_phy_type_fhss = 1, + dot11_phy_type_dsss = 2, + dot11_phy_type_irbaseband = 3, + dot11_phy_type_ofdm = 4, + dot11_phy_type_hrdsss = 5, + dot11_phy_type_erp = 6, + dot11_phy_type_ht = 7, + dot11_phy_type_IHV_start = 0x80000000, + dot11_phy_type_IHV_end = 0xffffffff +}; + +enum DOT11_AUTH_ALGORITHM { + DOT11_AUTH_ALGO_80211_OPEN = 1, + DOT11_AUTH_ALGO_80211_SHARED_KEY = 2, + DOT11_AUTH_ALGO_WPA = 3, + DOT11_AUTH_ALGO_WPA_PSK = 4, + DOT11_AUTH_ALGO_WPA_NONE = 5, + DOT11_AUTH_ALGO_RSNA = 6, + DOT11_AUTH_ALGO_RSNA_PSK = 7, + DOT11_AUTH_ALGO_IHV_START = 0x80000000, + DOT11_AUTH_ALGO_IHV_END = 0xffffffff +}; + +enum DOT11_CIPHER_ALGORITHM { + DOT11_CIPHER_ALGO_NONE = 0x00, + DOT11_CIPHER_ALGO_WEP40 = 0x01, + DOT11_CIPHER_ALGO_TKIP = 0x02, + DOT11_CIPHER_ALGO_CCMP = 0x04, + DOT11_CIPHER_ALGO_WEP104 = 0x05, + DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100, + DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100, + DOT11_CIPHER_ALGO_WEP = 0x101, + DOT11_CIPHER_ALGO_IHV_START = 0x80000000, + DOT11_CIPHER_ALGO_IHV_END = 0xffffffff +}; + +struct WLAN_AVAILABLE_NETWORK { + WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; + DOT11_SSID dot11Ssid; + DOT11_BSS_TYPE dot11BssType; + ULONG uNumberOfBssids; + BOOL bNetworkConnectable; + DWORD wlanNotConnectableReason; + ULONG uNumberOfPhyTypes; + DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER]; + BOOL bMorePhyTypes; + ULONG wlanSignalQuality; + BOOL bSecurityEnabled; + DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm; + DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm; + DWORD dwFlags; + DWORD dwReserved; +}; + +struct WLAN_AVAILABLE_NETWORK_LIST { + DWORD dwNumberOfItems; + DWORD dwIndex; + WLAN_AVAILABLE_NETWORK Network[1]; +}; + +enum WLAN_INTF_OPCODE { + wlan_intf_opcode_autoconf_start = 0x000000000, + wlan_intf_opcode_autoconf_enabled, + wlan_intf_opcode_background_scan_enabled, + wlan_intf_opcode_media_streaming_mode, + wlan_intf_opcode_radio_state, + wlan_intf_opcode_bss_type, + wlan_intf_opcode_interface_state, + wlan_intf_opcode_current_connection, + wlan_intf_opcode_channel_number, + wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs, + wlan_intf_opcode_supported_adhoc_auth_cipher_pairs, + wlan_intf_opcode_supported_country_or_region_string_list, + wlan_intf_opcode_current_operation_mode, + wlan_intf_opcode_supported_safe_mode, + wlan_intf_opcode_certified_safe_mode, + wlan_intf_opcode_autoconf_end = 0x0fffffff, + wlan_intf_opcode_msm_start = 0x10000100, + wlan_intf_opcode_statistics, + wlan_intf_opcode_rssi, + wlan_intf_opcode_msm_end = 0x1fffffff, + wlan_intf_opcode_security_start = 0x20010000, + wlan_intf_opcode_security_end = 0x2fffffff, + wlan_intf_opcode_ihv_start = 0x30000000, + wlan_intf_opcode_ihv_end = 0x3fffffff +}; + +enum WLAN_OPCODE_VALUE_TYPE { + wlan_opcode_value_type_query_only = 0, + wlan_opcode_value_type_set_by_group_policy, + wlan_opcode_value_type_set_by_user, + wlan_opcode_value_type_invalid +}; + +enum WLAN_CONNECTION_MODE { + wlan_connection_mode_profile = 0, + wlan_connection_mode_temporary_profile, + wlan_connection_mode_discovery_secure, + wlan_connection_mode_discovery_unsecure, + wlan_connection_mode_auto, + wlan_connection_mode_invalid +}; + +struct WLAN_CONNECTION_PARAMETERS { + WLAN_CONNECTION_MODE wlanConnectionMode; + LPCWSTR strProfile; + DOT11_SSID *pDot11Ssid; + DOT11_BSSID_LIST *pDesiredBssidList; + DOT11_BSS_TYPE dot11BssType; + DWORD dwFlags; +}; + +struct WLAN_RAW_DATA { + DWORD dwDataSize; + BYTE DataBlob[1]; +}; + +enum WLAN_NOTIFICATION_ACM { + wlan_notification_acm_start = 0, + wlan_notification_acm_autoconf_enabled, + wlan_notification_acm_autoconf_disabled, + wlan_notification_acm_background_scan_enabled, + wlan_notification_acm_background_scan_disabled, + wlan_notification_acm_bss_type_change, + wlan_notification_acm_power_setting_change, + wlan_notification_acm_scan_complete, + wlan_notification_acm_scan_fail, + wlan_notification_acm_connection_start, + wlan_notification_acm_connection_complete, + wlan_notification_acm_connection_attempt_fail, + wlan_notification_acm_filter_list_change, + wlan_notification_acm_interface_arrival, + wlan_notification_acm_interface_removal, + wlan_notification_acm_profile_change, + wlan_notification_acm_profile_name_change, + wlan_notification_acm_profiles_exhausted, + wlan_notification_acm_network_not_available, + wlan_notification_acm_network_available, + wlan_notification_acm_disconnecting, + wlan_notification_acm_disconnected, + wlan_notification_acm_adhoc_network_state_change, + wlan_notification_acm_end +}; + +struct WLAN_ASSOCIATION_ATTRIBUTES { + DOT11_SSID dot11Ssid; + DOT11_BSS_TYPE dot11BssType; + DOT11_MAC_ADDRESS dot11Bssid; + DOT11_PHY_TYPE dot11PhyType; + ULONG uDot11PhyIndex; + ULONG wlanSignalQuality; + ULONG ulRxRate; + ULONG ulTxRate; +}; + +struct WLAN_SECURITY_ATTRIBUTES { + BOOL bSecurityEnabled; + BOOL bOneXEnabled; + DOT11_AUTH_ALGORITHM dot11AuthAlgorithm; + DOT11_CIPHER_ALGORITHM dot11CipherAlgorithm; +}; + +struct WLAN_CONNECTION_ATTRIBUTES { + WLAN_INTERFACE_STATE isState; + WLAN_CONNECTION_MODE wlanConnectionMode; + WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; + WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes; + WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes; +}; + +typedef void (WINAPI *WLAN_NOTIFICATION_CALLBACK)(WLAN_NOTIFICATION_DATA *, PVOID); + +typedef DWORD (WINAPI *WlanOpenHandleProto) + (DWORD dwClientVersion, PVOID pReserved, PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle); +typedef DWORD (WINAPI *WlanRegisterNotificationProto) + (HANDLE hClientHandle, DWORD dwNotifSource, BOOL bIgnoreDuplicate, + WLAN_NOTIFICATION_CALLBACK funcCallback, PVOID pCallbackContext, + PVOID pReserved, PDWORD pdwPrevNotifSource); +typedef DWORD (WINAPI *WlanEnumInterfacesProto) + (HANDLE hClientHandle, PVOID pReserved, WLAN_INTERFACE_INFO_LIST **ppInterfaceList); +typedef DWORD (WINAPI *WlanGetAvailableNetworkListProto) + (HANDLE hClientHandle, const GUID* pInterfaceGuid, DWORD dwFlags, PVOID pReserved, + WLAN_AVAILABLE_NETWORK_LIST **ppAvailableNetworkList); +typedef DWORD (WINAPI *WlanQueryInterfaceProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, WLAN_INTF_OPCODE OpCode, PVOID pReserved, + PDWORD pdwDataSize, PVOID *ppData, WLAN_OPCODE_VALUE_TYPE *pWlanOpcodeValueType); +typedef DWORD (WINAPI *WlanConnectProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, + const WLAN_CONNECTION_PARAMETERS *pConnectionParameters, PVOID pReserved); +typedef DWORD (WINAPI *WlanDisconnectProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, PVOID pReserved); +typedef DWORD (WINAPI *WlanScanProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, const DOT11_SSID *pDot11Ssid, + const WLAN_RAW_DATA *pIeData, PVOID pReserved); +typedef VOID (WINAPI *WlanFreeMemoryProto)(PVOID pMemory); +typedef DWORD (WINAPI *WlanCloseHandleProto)(HANDLE hClientHandle, PVOID pReserved); + +static WlanOpenHandleProto local_WlanOpenHandle = 0; +static WlanRegisterNotificationProto local_WlanRegisterNotification = 0; +static WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; +static WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList = 0; +static WlanQueryInterfaceProto local_WlanQueryInterface = 0; +static WlanConnectProto local_WlanConnect = 0; +static WlanDisconnectProto local_WlanDisconnect = 0; +static WlanScanProto local_WlanScan = 0; +static WlanFreeMemoryProto local_WlanFreeMemory = 0; +static WlanCloseHandleProto local_WlanCloseHandle = 0; + +static void resolveLibrary() +{ + static volatile bool triedResolve = false; + + if (!triedResolve) { +#ifndef QT_NO_THREAD + QMutexLocker locker(QMutexPool::globalInstanceGet(&local_WlanOpenHandle)); +#endif + + if (!triedResolve) { + local_WlanOpenHandle = (WlanOpenHandleProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanOpenHandle"); + local_WlanRegisterNotification = (WlanRegisterNotificationProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanRegisterNotification"); + local_WlanEnumInterfaces = (WlanEnumInterfacesProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanEnumInterfaces"); + local_WlanGetAvailableNetworkList = (WlanGetAvailableNetworkListProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanGetAvailableNetworkList"); + local_WlanQueryInterface = (WlanQueryInterfaceProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanQueryInterface"); + local_WlanConnect = (WlanConnectProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanConnect"); + local_WlanDisconnect = (WlanDisconnectProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanDisconnect"); + local_WlanScan = (WlanScanProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanScan"); + local_WlanFreeMemory = (WlanFreeMemoryProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanFreeMemory"); + local_WlanCloseHandle = (WlanCloseHandleProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanCloseHandle"); + + triedResolve = true; + } + } +} + +void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) +{ + Q_UNUSED(d); + + switch (data->NotificationCode) { + case wlan_notification_acm_connection_complete: + case wlan_notification_acm_disconnected: + d->emitConfigurationsChanged(); + break; + default: + qDebug() << "wlan unknown notification"; + } +} + +QNativeWifiEngine::QNativeWifiEngine(QObject *parent) +: QNetworkSessionEngine(parent), handle(0) +{ + DWORD clientVersion; + + DWORD result = local_WlanOpenHandle(1, 0, &clientVersion, &handle); + if (result != ERROR_SUCCESS) { + if (result != ERROR_SERVICE_NOT_ACTIVE) + qWarning("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result); + + return; + } + + result = local_WlanRegisterNotification(handle, WLAN_NOTIFICATION_SOURCE_ALL, true, + WLAN_NOTIFICATION_CALLBACK(qNotificationCallback), + this, 0, 0); + if (result != ERROR_SUCCESS) + qWarning("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result); + + // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. + // We need to poll for changes in available wireless networks. + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QNativeWifiEngine::~QNativeWifiEngine() +{ + local_WlanCloseHandle(handle, 0); +} + +QList QNativeWifiEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = false; + + QList foundConfigurations; + + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return foundConfigurations; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + QStringList seenNetworks; + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + QString networkName; + + if (network.strProfileName[0] != 0) { + networkName = QString::fromWCharArray(network.strProfileName); + } else { + networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), + network.dot11Ssid.uSSIDLength); + } + + // don't add duplicate networks + if (seenNetworks.contains(networkName)) + continue; + else + seenNetworks.append(networkName); + + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + + cpPriv->isValid = true; + + cpPriv->name = networkName; + cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); + + if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) + cpPriv->state = QNetworkConfiguration::Undefined; + + if (network.strProfileName[0] != 0) { + if (network.bNetworkConnectable) { + if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) + cpPriv->state = QNetworkConfiguration::Active; + else + cpPriv->state = QNetworkConfiguration::Discovered; + } else { + cpPriv->state = QNetworkConfiguration::Defined; + } + } + + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->bearer = QLatin1String("WLAN"); + + + foundConfigurations.append(cpPriv); + } + + local_WlanFreeMemory(networkList); + } + + local_WlanFreeMemory(interfaceList); + + if (ok) + *ok = true; + + pollTimer.start(); + + return foundConfigurations; +} + +QString QNativeWifiEngine::getInterfaceFromId(const QString &id) +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return QString(); + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + DWORD dataSize; + WLAN_CONNECTION_ATTRIBUTES *connectionAttributes; + result = local_WlanQueryInterface(handle, &interface.InterfaceGuid, + wlan_intf_opcode_current_connection, 0, &dataSize, + reinterpret_cast(&connectionAttributes), 0); + if (result != ERROR_SUCCESS) { + if (result != ERROR_INVALID_STATE) + qWarning("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result); + + continue; + } + + if (qHash(QLatin1String("WLAN:") + + QString::fromWCharArray(connectionAttributes->strProfileName)) == id.toUInt()) { + QString guid("{%1-%2-%3-%4%5-%6%7%8%9%10%11}"); + + guid = guid.arg(interface.InterfaceGuid.Data1, 8, 16, QChar('0')); + guid = guid.arg(interface.InterfaceGuid.Data2, 4, 16, QChar('0')); + guid = guid.arg(interface.InterfaceGuid.Data3, 4, 16, QChar('0')); + for (int i = 0; i < 8; ++i) + guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); + + local_WlanFreeMemory(connectionAttributes); + + return guid.toUpper(); + } + + local_WlanFreeMemory(connectionAttributes); + local_WlanFreeMemory(interfaceList); + } + + return QString(); +} + +bool QNativeWifiEngine::hasIdentifier(const QString &id) +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return false; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + QString networkName; + + if (network.strProfileName[0] != 0) { + networkName = QString::fromWCharArray(network.strProfileName); + } else { + networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), + network.dot11Ssid.uSSIDLength); + } + + if (qHash(QLatin1String("WLAN:") + networkName) == id.toUInt()) { + local_WlanFreeMemory(networkList); + local_WlanFreeMemory(interfaceList); + return true; + } + } + + local_WlanFreeMemory(networkList); + } + + local_WlanFreeMemory(interfaceList); + + return false; +} + +/*QString QNativeWifiEngine::bearerName(const QString &) +{ + return QLatin1String("WLAN"); +}*/ + +void QNativeWifiEngine::connectToId(const QString &id) +{ + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, InterfaceLookupError); + return; + } + + QString profile; + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + profile = QString::fromWCharArray(network.strProfileName); + + if (qHash(QLatin1String("WLAN:") + profile) == id.toUInt()) + break; + else + profile.clear(); + } + + local_WlanFreeMemory(networkList); + + if (!profile.isEmpty()) { + WLAN_CONNECTION_PARAMETERS parameters; + parameters.wlanConnectionMode = wlan_connection_mode_profile; + parameters.strProfile = reinterpret_cast(profile.utf16()); + parameters.pDot11Ssid = 0; + parameters.pDesiredBssidList = 0; + parameters.dot11BssType = dot11_BSS_type_any; + parameters.dwFlags = 0; + + DWORD result = local_WlanConnect(handle, &interface.InterfaceGuid, ¶meters, 0); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, ConnectError); + break; + } + + break; + } + } + + local_WlanFreeMemory(interfaceList); + + if (profile.isEmpty()) + emit connectionError(id, InterfaceLookupError); +} + +void QNativeWifiEngine::disconnectFromId(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) { + emit connectionError(id, InterfaceLookupError); + return; + } + + QStringList split = interface.mid(1, interface.length() - 2).split('-'); + + GUID guid; + guid.Data1 = split.at(0).toUInt(0, 16); + guid.Data2 = split.at(1).toUShort(0, 16); + guid.Data3 = split.at(2).toUShort(0, 16); + guid.Data4[0] = split.at(3).left(2).toUShort(0, 16); + guid.Data4[1] = split.at(3).right(2).toUShort(0, 16); + for (int i = 0; i < 6; ++i) + guid.Data4[i + 2] = split.at(4).mid(i*2, 2).toUShort(0, 16); + + DWORD result = local_WlanDisconnect(handle, &guid, 0); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, DisconnectionError); + return; + } +} + +void QNativeWifiEngine::requestUpdate() +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + result = local_WlanScan(handle, &interfaceList->InterfaceInfo[i].InterfaceGuid, 0, 0, 0); + if (result != ERROR_SUCCESS) + qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); + } +} + +QNativeWifiEngine *QNativeWifiEngine::instance() +{ + resolveLibrary(); + + // native wifi dll not available + if (!local_WlanOpenHandle) + return 0; + + QNativeWifiEngine *engine = nativeWifiEngine(); + + // could not initialise subsystem + if (engine && engine->handle == 0) + return 0; + + return engine; +} + +#include "moc_qnativewifiengine_win_p.cpp" + +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnativewifiengine_win_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnativewifiengine_win_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNATIVEWIFIENGINE_P_H +#define QNATIVEWIFIENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworksessionengine_p.h" + +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNativeWifiEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNativeWifiEngine(QObject *parent = 0); + ~QNativeWifiEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + //QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + inline void emitConfigurationsChanged() { emit configurationsChanged(); } + + static QNativeWifiEngine *instance(); + +private: + QTimer pollTimer; + + Qt::HANDLE handle; +}; + +QTM_END_NAMESPACE + +#endif diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfigmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfigmanager.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,340 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworkconfigmanager.h" + +#ifdef Q_OS_SYMBIAN +#include "qnetworkconfigmanager_s60_p.h" +#elif Q_WS_MAEMO_6 +#include "qnetworkconfigmanager_maemo_p.h" +#else +#include "qnetworkconfigmanager_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); + +/*! + \class QNetworkConfigurationManager + + \brief The QNetworkConfigurationManager class manages the network configurations provided + by the system. + + \inmodule QtNetwork + \ingroup bearer + + QNetworkConfigurationManager provides access to the network configurations known to the system and + enables applications to detect the system capabilities (with regards to network sessions) at runtime. + + A QNetworkConfiguration abstracts a set of configuration options describing how a + network interface has to be configured to connect to a particular target network. + QNetworkConfigurationManager maintains and updates the global list of + QNetworkConfigurations. Applications can access and filter this list via + allConfigurations(). If a new configuration is added or an existing one is removed or changed + the configurationAdded(), configurationRemoved() and configurationChanged() signals are emitted + respectively. + + The defaultConfiguration() can be used when intending to immediately create a new + network session without caring about the particular configuration. It returns + a \l QNetworkConfiguration::Discovered configuration. If there are not any + discovered ones an invalid configuration is returned. + + Some configuration updates may require some time to perform updates. A WLAN scan is + such an example. Unless the platform performs internal updates it may be required to + manually trigger configuration updates via QNetworkConfigurationManager::updateConfigurations(). + The completion of the update process is indicted by emitting the updateCompleted() + signal. The update process ensures that every existing QNetworkConfiguration instance + is updated. There is no need to ask for a renewed configuration list via allConfigurations(). + + \sa QNetworkConfiguration +*/ + +/*! + \fn void QNetworkConfigurationManager::configurationAdded(const QNetworkConfiguration& config) + + This signal is emitted whenever a new network configuration is added to the system. The new + configuration is specified by \a config. +*/ + +/*! + \fn void QNetworkConfigurationManager::configurationRemoved(const QNetworkConfiguration& configuration) + + This signal is emitted when a configuration is about to be removed from the system. The removed + \a configuration is invalid but retains name and identifier. +*/ + +/*! + \fn void QNetworkConfigurationManager::updateCompleted() + + This signal is emitted when the configuration update has been completed. Such an update can + be initiated via \l updateConfigurations(). +*/ + +/*! \fn void QNetworkConfigurationManager::configurationChanged(const QNetworkConfiguration& config) + + This signal is emitted when the \l {QNetworkConfiguration::state()}{state} of \a config changes. +*/ + +/*! + \fn void QNetworkConfigurationManager::onlineStateChanged(bool isOnline) + + This signal is emitted when the device changes from online to offline mode or vice versa. + \a isOnline represents the new state of the device. + + The state is considered to be online for as long as + \l{allConfigurations()}{allConfigurations}(QNetworkConfiguration::Active) returns a list with + at least one entry. +*/ + +/*! + \enum QNetworkConfigurationManager::Capability + + Specifies the system capabilities of the bearer API. The possible values are: + + \value CanStartAndStopInterfaces Network sessions and their underlying access points can be + started and stopped. If this flag is not set QNetworkSession + can only monitor but not influence the state of access points. + On some platforms this feature may require elevated user + permissions. This option is platform specific and may not + always be available. + \value DirectConnectionRouting Network sessions and their sockets can be bound to a + particular network interface. Any packet that passes through + the socket goes to the specified network interface and thus + disregards standard routing table entries. This may be useful + when two interfaces can reach overlapping IP ranges or an + application has specific needs in regards to target networks. + This option is platform specific and may not always be + available. + \value SystemSessionSupport If this flag is set the underlying platform ensures that a + network interface is not shut down until the last network + session has been \l{QNetworkSession::close()}{closed()}. This + works across multiple processes. If the platform session + support is missing this API can only ensure the above behavior + for network sessions within the same process. + In general mobile platforms (such as Symbian/S60) have such + support whereas most desktop platform lack this capability. + \value ApplicationLevelRoaming The system gives applications control over the systems roaming + behavior. Applications can initiate roaming (in case the + current link is not suitable) and are consulted if the system + has identified a more suitable access point. + \value ForcedRoaming The system disconnects an existing access point and reconnects + via a more suitable one. The application does not have any + control over this process and has to reconnect its active + sockets. + \value DataStatistics If this flag is set QNetworkSession can provide statistics + about transmitted and received data. +*/ + +/*! + Constructs a QNetworkConfigurationManager with the given \a parent. +*/ +QNetworkConfigurationManager::QNetworkConfigurationManager( QObject* parent ) + : QObject(parent) +{ + QNetworkConfigurationManagerPrivate* priv = connManager(); + connect(priv, SIGNAL(configurationAdded(QNetworkConfiguration)), + this, SIGNAL(configurationAdded(QNetworkConfiguration))); + connect(priv, SIGNAL(configurationRemoved(QNetworkConfiguration)), + this, SIGNAL(configurationRemoved(QNetworkConfiguration))); + connect(priv, SIGNAL(configurationUpdateComplete()), + this, SIGNAL(updateCompleted())); + connect(priv, SIGNAL(onlineStateChanged(bool)), + this, SIGNAL(onlineStateChanged(bool))); + connect(priv, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SIGNAL(configurationChanged(QNetworkConfiguration))); +} + +/*! + Frees the resources associated with the QNetworkConfigurationManager object. +*/ +QNetworkConfigurationManager::~QNetworkConfigurationManager() +{ +} + + +/*! + Returns the default configuration to be used. This function always returns a discovered + configuration; otherwise an invalid configuration. + + In some cases it may be required to call updateConfigurations() and wait for the + updateCompleted() signal before calling this function. + + \sa allConfigurations() +*/ +QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const +{ + return connManager()->defaultConfiguration(); +} + +/*! + Returns the list of configurations which comply with the given \a filter. + + By default this function returns all (defined and undefined) configurations. + + A wireless network with a particular SSID may only be accessible in a + certain area despite the fact that the system has a valid configuration + for it. Therefore the filter flag may be used to limit the list to + discovered and possibly connected configurations only. + + If \a filter is set to zero this function returns all possible configurations. + + Note that this function returns the states for all configurations as they are known at + the time of this function call. If for instance a configuration of type WLAN is defined + the system may have to perform a WLAN scan in order to determine whether it is + actually available. To obtain the most accurate state updateConfigurations() should + be used to update each configuration's state. Note that such an update may require + some time. It's completion is signalled by updateCompleted(). In the absence of a + configuration update this function returns the best estimate at the time of the call. + Therefore, if WLAN configurations are of interest, it is recommended that + updateConfigurations() is called once after QNetworkConfigurationManager + instantiation (WLAN scans are too time consuming to perform in constructor). + After this the data is kept automatically up-to-date as the system reports + any changes. +*/ +QList QNetworkConfigurationManager::allConfigurations(QNetworkConfiguration::StateFlags filter) const +{ + QList result; + QNetworkConfigurationManagerPrivate* conPriv = connManager(); + QList cpsIdents = conPriv->accessPointConfigurations.keys(); + + //find all InternetAccessPoints + foreach( QString ii, cpsIdents) { + QExplicitlySharedDataPointer p = + conPriv->accessPointConfigurations.value(ii); + if ( (p->state & filter) == filter ) { + QNetworkConfiguration pt; + pt.d = conPriv->accessPointConfigurations.value(ii); + result << pt; + } + } + + //find all service networks + cpsIdents = conPriv->snapConfigurations.keys(); + foreach( QString ii, cpsIdents) { + QExplicitlySharedDataPointer p = + conPriv->snapConfigurations.value(ii); + if ( (p->state & filter) == filter ) { + QNetworkConfiguration pt; + pt.d = conPriv->snapConfigurations.value(ii); + result << pt; + } + } + + return result; +} + +/*! + Returns the QNetworkConfiguration for \a identifier; otherwise returns an + invalid QNetworkConfiguration. + + \sa QNetworkConfiguration::identifier() +*/ +QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier(const QString& identifier) const +{ + QNetworkConfigurationManagerPrivate* conPriv = connManager(); + QNetworkConfiguration item; + if (conPriv->accessPointConfigurations.contains(identifier)) + item.d = conPriv->accessPointConfigurations.value(identifier); + else if (conPriv->snapConfigurations.contains(identifier)) + item.d = conPriv->snapConfigurations.value(identifier); + else if (conPriv->userChoiceConfigurations.contains(identifier)) + item.d = conPriv->userChoiceConfigurations.value(identifier); + return item; + +} + +/*! + Returns true if the system is considered to be connected to another device via an active + network interface; otherwise returns false. + + This is equivalent to the following code snippet: + + \code + QNetworkConfigurationManager mgr; + QList activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active) + if (activeConfigs.count() > 0) + Q_ASSERT(mgr.isOnline()) + else + Q_ASSERT(!mgr.isOnline()) + \endcode + + \sa onlineStateChanged() +*/ +bool QNetworkConfigurationManager::isOnline() const +{ + QNetworkConfigurationManagerPrivate* conPriv = connManager(); + Q_UNUSED(conPriv); + QList activeConfigs = allConfigurations(QNetworkConfiguration::Active); + return activeConfigs.count() > 0; +} + +/*! + Returns the capabilities supported by the current platform. +*/ +QNetworkConfigurationManager::Capabilities QNetworkConfigurationManager::capabilities() const +{ + return connManager()->capFlags; +} + +/*! + Initiates an update of all configurations. This may be used to initiate WLAN scans or other + time consuming updates which may be required to obtain the correct state for configurations. + + This call is asynchronous. On completion of this update the updateCompleted() signal is + emitted. If new configurations are discovered or old ones were removed or changed the update + process may trigger the emission of one or multiple configurationAdded(), + configurationRemoved() and configurationChanged() signals. + + If a configuration state changes as a result of this update all existing QNetworkConfiguration + instances are updated automatically. + + \sa allConfigurations() +*/ +void QNetworkConfigurationManager::updateConfigurations() +{ + connManager()->performAsyncConfigurationUpdate(); +} + +#include "moc_qnetworkconfigmanager.cpp" + +QTM_END_NAMESPACE + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfigmanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfigmanager.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCONFIGURATIONMANAGER_H +#define QNETWORKCONFIGURATIONMANAGER_H + +#include "qmobilityglobal.h" + +#include +#include "qnetworkconfiguration.h" + +QT_BEGIN_HEADER + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationManagerPrivate; +class Q_BEARER_EXPORT QNetworkConfigurationManager : public QObject +{ + Q_OBJECT + +public: + + enum Capability { + CanStartAndStopInterfaces = 0x00000001, + DirectConnectionRouting = 0x00000002, + SystemSessionSupport = 0x00000004, + ApplicationLevelRoaming = 0x00000008, + ForcedRoaming = 0x00000010, + DataStatistics = 0x00000020 + }; + + Q_DECLARE_FLAGS(Capabilities, Capability) + + QNetworkConfigurationManager( QObject* parent = 0 ); + virtual ~QNetworkConfigurationManager(); + + + QNetworkConfigurationManager::Capabilities capabilities() const; + + QNetworkConfiguration defaultConfiguration() const; + QList allConfigurations(QNetworkConfiguration::StateFlags flags = 0) const; + QNetworkConfiguration configurationFromIdentifier(const QString& identifier) const; + void updateConfigurations(); + + bool isOnline() const; + +Q_SIGNALS: + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void configurationChanged(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); + void updateCompleted(); + +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkConfigurationManager::Capabilities) + +QTM_END_NAMESPACE + +QT_END_HEADER + +#endif //QNETWORKCONFIGURATIONMANAGER_H + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfigmanager_maemo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfigmanager_maemo.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,715 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "qnetworkconfigmanager_maemo_p.h" + +#include +#include + +#include +#include +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +/* The IapAddTimer is a helper class that makes sure we update + * the configuration only after all db additions to certain + * iap are finished (after a certain timeout) + */ +class _IapAddTimer : public QObject +{ + Q_OBJECT + +public: + _IapAddTimer() {} + ~_IapAddTimer() + { + if (timer.isActive()) { + QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.stop(); + } + } + + void add(QString& iap_id, QNetworkConfigurationManagerPrivate *d); + + QString iap_id; + QTimer timer; + QNetworkConfigurationManagerPrivate *d; + +public Q_SLOTS: + void timeout(); +}; + + +void _IapAddTimer::add(QString& id, QNetworkConfigurationManagerPrivate *d_ptr) +{ + iap_id = id; + d = d_ptr; + + if (timer.isActive()) { + QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.stop(); + } + timer.setSingleShot(true); + QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.start(1500); +} + + +void _IapAddTimer::timeout() +{ + d->addConfiguration(iap_id); +} + + +class IapAddTimer { + QHash timers; + +public: + IapAddTimer() {} + ~IapAddTimer() {} + + void add(QString& iap_id, QNetworkConfigurationManagerPrivate *d); + void del(QString& iap_id); + void removeAll(); +}; + + +void IapAddTimer::removeAll() +{ + QHashIterator i(timers); + while (i.hasNext()) { + i.next(); + _IapAddTimer *t = i.value(); + delete t; + } + timers.clear(); +} + + +void IapAddTimer::add(QString& iap_id, QNetworkConfigurationManagerPrivate *d) +{ + if (timers.contains(iap_id)) { + _IapAddTimer *iap = timers.value(iap_id); + iap->add(iap_id, d); + } else { + _IapAddTimer *iap = new _IapAddTimer; + iap->add(iap_id, d); + timers.insert(iap_id, iap); + } +} + +void IapAddTimer::del(QString& iap_id) +{ + if (timers.contains(iap_id)) { + _IapAddTimer *iap = timers.take(iap_id); + delete iap; + } +} + + +class IapMonitor : public Maemo::IAPMonitor +{ +public: + IapMonitor() : first_call(true) { } + + void setup(QNetworkConfigurationManagerPrivate *d); + void cleanup(); + +protected: + void iapAdded(const QString &iapId); + void iapRemoved(const QString &iapId); + +private: + bool first_call; + + QNetworkConfigurationManagerPrivate *d; + IapAddTimer timers; +}; + +Q_GLOBAL_STATIC(IapMonitor, iapMonitor); + + +void IapMonitor::setup(QNetworkConfigurationManagerPrivate *d_ptr) +{ + if (first_call) { + d = d_ptr; + first_call = false; + } +} + + +void IapMonitor::cleanup() +{ + if (!first_call) { + timers.removeAll(); + first_call = true; + } +} + + +void IapMonitor::iapAdded(const QString &iap_id) +{ + /* We cannot know when the IAP is fully added to db, so a timer is + * installed instead. When the timer expires we hope that IAP is added ok. + */ + QString id = iap_id; + timers.add(id, d); +} + + +void IapMonitor::iapRemoved(const QString &iap_id) +{ + QString id = iap_id; + d->deleteConfiguration(id); +} + + + +void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() +{ + capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + capFlags |= QNetworkConfigurationManager::DataStatistics; + capFlags |= QNetworkConfigurationManager::ForcedRoaming; +} + + +static inline QString network_attrs_to_security(uint network_attrs) +{ + uint cap = 0; + nwattr2cap(network_attrs, &cap); /* from libicd-network-wlan-dev.h */ + if (cap & WLANCOND_OPEN) + return "NONE"; + else if (cap & WLANCOND_WEP) + return "WEP"; + else if (cap & WLANCOND_WPA_PSK) + return "WPA_PSK"; + else if (cap & WLANCOND_WPA_EAP) + return "WPA_EAP"; + return ""; +} + + +struct SSIDInfo { + QString iap_id; + QString wlan_security; +}; + + +void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivate *ptr) +{ + QNetworkConfiguration item; + item.d = ptr; + emit configurationChanged(item); +} + +void QNetworkConfigurationManagerPrivate::deleteConfiguration(QString& iap_id) +{ + /* Called when IAPs are deleted in db, in this case we do not scan + * or read all the IAPs from db because it might take too much power + * (multiple applications would need to scan and read all IAPs from db) + */ + if (accessPointConfigurations.contains(iap_id)) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(iap_id); + if (priv.data()) { + priv->isValid = false; +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "was removed from storage."; +#endif + + QNetworkConfiguration item; + item.d = priv; + emit configurationRemoved(item); + configChanged(priv.data(), false); + } else + qWarning("Configuration not found for IAP %s", iap_id.toAscii().data()); + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, already missing from the known list", iap_id.toAscii().data()); +#endif + } +} + + +uint32_t QNetworkConfigurationManagerPrivate::getNetworkAttrs(bool is_iap_id, + QString& iap_id, + QString& iap_type, + QString security_method) +{ + guint network_attr = 0; + dbus_uint32_t cap = 0; + + if (iap_type == "WLAN_INFRA") + cap |= WLANCOND_INFRA; + else if (iap_type == "WLAN_ADHOC") + cap |= WLANCOND_ADHOC; + + if (security_method.isEmpty() && (cap & (WLANCOND_INFRA | WLANCOND_ADHOC))) { + Maemo::IAPConf saved_ap(iap_id); + security_method = saved_ap.value("wlan_security").toString(); + } + + if (!security_method.isEmpty()) { + if (security_method == "WEP") + cap |= WLANCOND_WEP; + else if (security_method == "WPA_PSK") + cap |= WLANCOND_WPA_PSK; + else if (security_method == "WPA_EAP") + cap |= WLANCOND_WPA_EAP; + else if (security_method == "NONE") + cap |= WLANCOND_OPEN; + + if (cap & (WLANCOND_WPA_PSK | WLANCOND_WPA_EAP)) { + Maemo::IAPConf saved_iap(iap_id); + bool wpa2_only = saved_iap.value("EAP_wpa2_only_mode").toBool(); + if (wpa2_only) { + cap |= WLANCOND_WPA2; + } + } + } + + cap2nwattr(cap, &network_attr); + if (is_iap_id) + network_attr |= ICD_NW_ATTR_IAPNAME; + + return (uint32_t)network_attr; +} + + +void QNetworkConfigurationManagerPrivate::addConfiguration(QString& iap_id) +{ + if (!accessPointConfigurations.contains(iap_id)) { + Maemo::IAPConf saved_iap(iap_id); + QString iap_type = saved_iap.value("type").toString(); + if (!iap_type.isEmpty()) { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = saved_iap.value("name").toString(); + if (cpPriv->name.isEmpty()) + cpPriv->name = iap_id; + cpPriv->isValid = true; + cpPriv->id = iap_id; + cpPriv->iap_type = iap_type; + cpPriv->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString()); + cpPriv->service_id = saved_iap.value("service_id").toString(); + cpPriv->service_type = saved_iap.value("service_type").toString(); + if (iap_type.startsWith("WLAN")) { + QByteArray ssid = saved_iap.value("wlan_ssid").toByteArray(); + if (ssid.isEmpty()) { + qWarning() << "Cannot get ssid for" << iap_id; + } + } + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Defined; + + QExplicitlySharedDataPointer ptr(cpPriv); + accessPointConfigurations.insert(iap_id, ptr); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, name: %s, added to known list", iap_id.toAscii().data(), cpPriv->name.toAscii().data()); +#endif + + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + configChanged(ptr.data(), true); + } else { + qWarning("IAP %s does not have \"type\" field defined, skipping this IAP.", iap_id.toAscii().data()); + } + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "already in db."; +#endif + + /* Check if the data in db changed and update configuration accordingly + */ + QExplicitlySharedDataPointer ptr = accessPointConfigurations.take(iap_id); + if (ptr.data()) { + Maemo::IAPConf changed_iap(iap_id); + QString iap_type = changed_iap.value("type").toString(); + bool update_needed = false; /* if IAP type or ssid changed, we need to change the state */ + + ptr->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString()); + ptr->service_id = changed_iap.value("service_id").toString(); + ptr->service_type = changed_iap.value("service_type").toString(); + + if (!iap_type.isEmpty()) { + ptr->name = changed_iap.value("name").toString(); + if (ptr->name.isEmpty()) + ptr->name = iap_id; + ptr->isValid = true; + if (ptr->iap_type != iap_type) { + ptr->iap_type = iap_type; + update_needed = true; + } + if (iap_type.startsWith("WLAN")) { + QByteArray ssid = changed_iap.value("wlan_ssid").toByteArray(); + if (ssid.isEmpty()) { + qWarning() << "Cannot get ssid for" << iap_id; + } + if (ptr->network_id != ssid) { + ptr->network_id = ssid; + update_needed = true; + } + } + } + accessPointConfigurations.insert(iap_id, ptr); + if (update_needed) { + ptr->type = QNetworkConfiguration::InternetAccessPoint; + if (ptr->state != QNetworkConfiguration::Defined) { + ptr->state = QNetworkConfiguration::Defined; + configurationChanged(ptr.data()); + } + } + } else { + qWarning("Cannot find IAP %s from current configuration although it should be there.", iap_id.toAscii().data()); + } + } +} + + +void QNetworkConfigurationManagerPrivate::updateConfigurations() +{ + /* Contains known network id (like ssid) from storage */ + QMultiHash knownConfigs; + + /* All the scanned access points */ + QList scanned; + + /* Turn on IAP monitoring */ + iapMonitor()->setup(this); + + if (firstUpdate) { + /* We create a default configuration which is a pseudo config */ + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = "UserChoice"; + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->isValid = true; + cpPriv->id = OSSO_IAP_ANY; + cpPriv->type = QNetworkConfiguration::UserChoice; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + QExplicitlySharedDataPointer ptr(cpPriv); + userChoiceConfigurations.insert(cpPriv->id, ptr); + } + + /* We return currently configured IAPs in the first run and do the WLAN + * scan in subsequent runs. + */ + QList all_iaps; + Maemo::IAPConf::getAll(all_iaps); + + foreach (QString iap_id, all_iaps) { + QByteArray ssid; + + Maemo::IAPConf saved_ap(iap_id); + bool is_temporary = saved_ap.value("temporary").toBool(); + if (is_temporary) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "is temporary, skipping it."; +#endif + continue; + } + + QString iap_type = saved_ap.value("type").toString(); + if (iap_type.startsWith("WLAN")) { + ssid = saved_ap.value("wlan_ssid").toByteArray(); + if (ssid.isEmpty()) { + qWarning() << "Cannot get ssid for" << iap_id; + continue; + } + + QString security_method = saved_ap.value("wlan_security").toString(); + SSIDInfo *info = new SSIDInfo; + info->iap_id = iap_id; + info->wlan_security = security_method; + knownConfigs.insert(ssid, info); + } else if (iap_type.isEmpty()) { + qWarning() << "IAP" << iap_id << "network type is not set! Skipping it"; + continue; + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "network type is" << iap_type; +#endif + ssid.clear(); + } + + if (!accessPointConfigurations.contains(iap_id)) { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = saved_ap.value("name").toString(); + if (cpPriv->name.isEmpty()) { + if (!ssid.isEmpty() && ssid.size() > 0) + cpPriv->name = ssid.data(); + else + cpPriv->name = iap_id; + } + cpPriv->isValid = true; + cpPriv->id = iap_id; + cpPriv->network_id = ssid; + cpPriv->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString()); + cpPriv->iap_type = iap_type; + cpPriv->service_id = saved_ap.value("service_id").toString(); + cpPriv->service_type = saved_ap.value("service_type").toString(); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->manager = this; + + QExplicitlySharedDataPointer ptr(cpPriv); + accessPointConfigurations.insert(iap_id, ptr); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, name: %s, ssid: %s, added to known list", iap_id.toAscii().data(), cpPriv->name.toAscii().data(), !ssid.isEmpty() ? ssid.data() : "-"); +#endif + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, ssid: %s, already exists in the known list", iap_id.toAscii().data(), !ssid.isEmpty() ? ssid.data() : "-"); +#endif + } + } + + if (!firstUpdate) { + QStringList scannedNetworkTypes; + QStringList networkTypesToScan; + QString error; + Maemo::Icd icd(ICD_SHORT_SCAN_TIMEOUT); + + scannedNetworkTypes = icd.scan(ICD_SCAN_REQUEST_ACTIVE, + networkTypesToScan, + scanned, + error); + if (!error.isEmpty()) { + qWarning() << "Network scanning failed" << error; + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + if (!scanned.isEmpty()) + qDebug() << "Scan returned" << scanned.size() << "networks"; + else + qDebug() << "Scan returned nothing."; +#endif + } + } + + + /* This is skipped in the first update as scanned size is zero */ + if (!scanned.isEmpty()) + for (int i=0; i priv = accessPointConfigurations.take(iapid); + if (priv.data()) { + priv->state = QNetworkConfiguration::Discovered; /* Defined is set automagically */ + priv->network_attrs = ap.scan.network_attrs; + priv->service_id = ap.scan.service_id; + priv->service_type = ap.scan.service_type; + priv->service_attrs = ap.scan.service_attrs; + + configurationChanged(priv.data()); + accessPointConfigurations.insert(iapid, priv); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, ssid: %s, discovered", iapid.toAscii().data(), priv->network_id.data()); +#endif + + if (!ap.scan.network_type.startsWith("WLAN")) + continue; // not a wlan AP + + /* Remove scanned AP from known configurations so that we can + * emit configurationRemoved signal later + */ + QList known_iaps = knownConfigs.values(priv->network_id); + rescan_list: + if (!known_iaps.isEmpty()) { + for (int k=0; kiap_id << "security" << iap->wlan_security << "scan" << network_attrs_to_security(ap.scan.network_attrs); +#endif + + if (iap->wlan_security == + network_attrs_to_security(ap.scan.network_attrs)) { + /* Remove IAP from the list */ + knownConfigs.remove(priv->network_id, iap); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Removed IAP" << iap->iap_id << "from unknown config"; +#endif + known_iaps.removeAt(k); + delete iap; + goto rescan_list; + } + } + } + } else { + qWarning() << "IAP" << iapid << "is missing in configuration."; + } + + } else { + /* Non saved access point data */ + QByteArray scanned_ssid = ap.scan.network_id; + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QString hrs = scanned_ssid.data(); + + cpPriv->name = ap.network_name.isEmpty() ? hrs : ap.network_name; + cpPriv->isValid = true; + cpPriv->id = scanned_ssid.data(); // Note: id is now ssid, it should be set to IAP id if the IAP is saved + cpPriv->network_id = scanned_ssid; + cpPriv->iap_type = ap.scan.network_type; + cpPriv->network_attrs = ap.scan.network_attrs; + cpPriv->service_id = ap.scan.service_id; + cpPriv->service_type = ap.scan.service_type; + cpPriv->service_attrs = ap.scan.service_attrs; + cpPriv->manager = this; + + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Undefined; + + QExplicitlySharedDataPointer ptr(cpPriv); + accessPointConfigurations.insert(cpPriv->id, ptr); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP with network id" << cpPriv->id << "was found in the scan."; +#endif + + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + } + + + /* Remove non existing iaps since last update */ + if (!firstUpdate) { + QHashIterator i(knownConfigs); + while (i.hasNext()) { + i.next(); + SSIDInfo *iap = i.value(); + QString iap_id = iap->iap_id; + //qDebug() << i.key() << ": " << iap_id; + + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(iap_id); + if (priv.data()) { + priv->isValid = false; +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "was removed as it was not found in scan."; +#endif + + QNetworkConfiguration item; + item.d = priv; + emit configurationRemoved(item); + configChanged(priv.data(), false); + + //if we would have SNAP support we would have to remove the references + //from existing ServiceNetworks to the removed access point configuration + } + } + } + + + QMutableHashIterator i(knownConfigs); + while (i.hasNext()) { + i.next(); + SSIDInfo *iap = i.value(); + delete iap; + i.remove(); + } + + if (!firstUpdate) + emit configurationUpdateComplete(); + + if (firstUpdate) + firstUpdate = false; +} + + +QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() +{ + /* Here we just return [ANY] request to icd and let the icd decide which + * IAP to connect. + */ + QNetworkConfiguration item; + if (userChoiceConfigurations.contains(OSSO_IAP_ANY)) + item.d = userChoiceConfigurations.value(OSSO_IAP_ANY); + return item; +} + + +void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() +{ + QTimer::singleShot(0, this, SLOT(updateConfigurations())); +} + + +void QNetworkConfigurationManagerPrivate::cleanup() +{ + iapMonitor()->cleanup(); +} + + +void QNetworkConfigurationManagerPrivate::configChanged(QNetworkConfigurationPrivate *ptr, bool added) +{ + if (added) { + if (ptr && ptr->state == QNetworkConfiguration::Active) { + onlineConfigurations++; + if (!firstUpdate && onlineConfigurations == 1) + emit onlineStateChanged(true); + } + } else { + if (ptr && ptr->state == QNetworkConfiguration::Active) { + onlineConfigurations--; + if (!firstUpdate && onlineConfigurations == 0) + emit onlineStateChanged(false); + if (onlineConfigurations < 0) + onlineConfigurations = 0; + } + } +} + + +#include "qnetworkconfigmanager_maemo.moc" +#include "moc_qnetworkconfigmanager_maemo_p.cpp" + +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfigmanager_maemo_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfigmanager_maemo_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCONFIGURATIONMANAGERPRIVATE_H +#define QNETWORKCONFIGURATIONMANAGERPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +#include "qnetworkconfigmanager.h" +#include "qnetworkconfiguration_maemo_p.h" +#include "qnetworksession_maemo_p.h" + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNetworkConfigurationManagerPrivate : public QObject +{ + Q_OBJECT +public: + QNetworkConfigurationManagerPrivate() + : QObject(0), capFlags(0), firstUpdate(true), onlineConfigurations(0) + { + registerPlatformCapabilities(); + updateConfigurations(); + } + + virtual ~QNetworkConfigurationManagerPrivate() + { + QList configIdents = snapConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = accessPointConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = userChoiceConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = userChoiceConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + cleanup(); + } + + QNetworkConfiguration defaultConfiguration(); + + QNetworkConfigurationManager::Capabilities capFlags; + void registerPlatformCapabilities(); + + void performAsyncConfigurationUpdate(); + + //this table contains an up to date list of all configs at any time. + //it must be updated if configurations change, are added/removed or + //the members of ServiceNetworks change + QHash > accessPointConfigurations; + QHash > snapConfigurations; + QHash > userChoiceConfigurations; + bool firstUpdate; + int onlineConfigurations; + friend class IapMonitor; + void cleanup(); + void deleteConfiguration(QString &iap_id); + void addConfiguration(QString &iap_id); + void configurationChanged(QNetworkConfigurationPrivate *ptr); + uint32_t getNetworkAttrs(bool is_iap_id, QString& iap_id, + QString& iap_type, QString security_method); + void configChanged(QNetworkConfigurationPrivate *ptr, bool added); + friend class QNetworkSessionPrivate; + +public slots: + void updateConfigurations(); + +Q_SIGNALS: + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void configurationUpdateComplete(); + void configurationChanged(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfigmanager_p.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfigmanager_p.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,453 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworkconfigmanager_p.h" +#include "qgenericengine_p.h" + +#ifdef Q_OS_WIN +#include "qnlaengine_win_p.h" +#endif +#ifdef Q_OS_WIN32 +#include "qnativewifiengine_win_p.h" +#endif +#if defined(BACKEND_NM) +#include "qnmwifiengine_unix_p.h" +#endif +#ifdef Q_OS_DARWIN +#include "qcorewlanengine_mac_p.h" +#endif + +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() +{ + capFlags = QNetworkConfigurationManager::ForcedRoaming; +} + +void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivate *cpPriv, QNetworkSessionEngine *engine) +{ + QExplicitlySharedDataPointer ptr(new QNetworkConfigurationPrivate); + + ptr.data()->isValid = cpPriv->isValid; + ptr.data()->name = cpPriv->name; + ptr.data()->id = cpPriv->id; + ptr.data()->state = cpPriv->state; + ptr.data()->type = cpPriv->type; + ptr.data()->roamingSupported = cpPriv->roamingSupported; + ptr.data()->purpose = cpPriv->purpose; + ptr.data()->internet = cpPriv->internet; + ptr.data()->bearer = cpPriv->bearer; + + accessPointConfigurations.insert(cpPriv->id, ptr); + configurationEngine.insert(cpPriv->id, engine); + + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + + if (ptr.data()->state == QNetworkConfiguration::Active) { + ++onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 1) + emit onlineStateChanged(true); + } +} + +void QNetworkConfigurationManagerPrivate::configurationRemoved(const QString &id) +{ + if (!accessPointConfigurations.contains(id)) + return; + + QExplicitlySharedDataPointer ptr = + accessPointConfigurations.take(id); + + configurationEngine.remove(id); + + ptr.data()->isValid = false; + + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationRemoved(item); + } + + if (ptr.data()->state == QNetworkConfiguration::Active) { + --onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 0) + emit onlineStateChanged(false); + } +} + +void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivate *cpPriv) +{ + if (!accessPointConfigurations.contains(cpPriv->id)) + return; + + QExplicitlySharedDataPointer ptr = + accessPointConfigurations.value(cpPriv->id); + + if (ptr.data()->isValid != cpPriv->isValid || + ptr.data()->name != cpPriv->name || + ptr.data()->id != cpPriv->id || + ptr.data()->state != cpPriv->state || + ptr.data()->type != cpPriv->type || + ptr.data()->roamingSupported != cpPriv->roamingSupported || + ptr.data()->purpose != cpPriv->purpose || + ptr.data()->bearer != cpPriv->bearer || + ptr.data()->internet != cpPriv->internet) { + + const QNetworkConfiguration::StateFlags oldState = ptr.data()->state; + + ptr.data()->isValid = cpPriv->isValid; + ptr.data()->name = cpPriv->name; + ptr.data()->id = cpPriv->id; + ptr.data()->state = cpPriv->state; + ptr.data()->type = cpPriv->type; + ptr.data()->roamingSupported = cpPriv->roamingSupported; + ptr.data()->purpose = cpPriv->purpose; + ptr.data()->internet = cpPriv->internet; + ptr.data()->bearer = cpPriv->bearer; + + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationChanged(item); + } + + if (ptr.data()->state == QNetworkConfiguration::Active && oldState != ptr.data()->state) { + // configuration went online + ++onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 1) + emit onlineStateChanged(true); + } else if (ptr.data()->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) { + // configuration went offline + --onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 0) + emit onlineStateChanged(false); + } + } +} + +void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() +{ + if (!snapConfigurations.contains(QLatin1String("Internet Service Network"))) { + QNetworkConfigurationPrivate *serviceNetwork = new QNetworkConfigurationPrivate; + serviceNetwork->name = tr("Internet"); + serviceNetwork->isValid = true; + serviceNetwork->id = QLatin1String("Internet Service Network"); + serviceNetwork->state = QNetworkConfiguration::Defined; + serviceNetwork->type = QNetworkConfiguration::ServiceNetwork; + + QExplicitlySharedDataPointer ptr(serviceNetwork); + + snapConfigurations.insert(serviceNetwork->id, ptr); + + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + } + + QExplicitlySharedDataPointer ptr = + snapConfigurations.value(QLatin1String("Internet Service Network")); + + QList > serviceNetworkMembers; + + QHash >::const_iterator i = + accessPointConfigurations.constBegin(); + + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined; + while (i != accessPointConfigurations.constEnd()) { + QExplicitlySharedDataPointer child = i.value(); + + if (child.data()->internet && ((child.data()->state & QNetworkConfiguration::Defined) + == QNetworkConfiguration::Defined)) { + serviceNetworkMembers.append(child); + + state |= child.data()->state; + } + + ++i; + } + + + if (ptr.data()->state != state || ptr.data()->serviceNetworkMembers != serviceNetworkMembers) { + ptr.data()->state = state; + ptr.data()->serviceNetworkMembers = serviceNetworkMembers; + + QNetworkConfiguration item; + item.d = ptr; + emit configurationChanged(item); + } +} + +void QNetworkConfigurationManagerPrivate::updateConfigurations() +{ + if (firstUpdate) { + updateState = NotUpdating; + onlineConfigurations = 0; + +#if defined (Q_OS_DARWIN) + coreWifi = QCoreWlanEngine::instance(); + if (coreWifi) { + connect(coreWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } +#else +#if defined(BACKEND_NM) + nmWifi = QNmWifiEngine::instance(); + if (nmWifi) { + connect(nmWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } else { +#endif + generic = QGenericEngine::instance(); + if (generic) { + connect(generic, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } +#if defined(BACKEND_NM) + } +#endif +#endif + +#ifdef Q_OS_WIN + nla = QNlaEngine::instance(); + if (nla) { + connect(nla, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } +#endif + +#ifdef Q_OS_WIN32 + nativeWifi = QNativeWifiEngine::instance(); + if (nativeWifi) { + connect(nativeWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + + capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + } +#endif + } + + QNetworkSessionEngine *engine = qobject_cast(sender()); + if (updateState & Updating && engine) { +#if defined (Q_OS_DARWIN) + if (engine == coreWifi) + updateState &= ~CoreWifiUpdating; +#else +#if defined(BACKEND_NM) + if (engine == nmWifi) + updateState &= ~NmUpdating; + else if (engine == generic) + updateState &= ~GenericUpdating; +#else + if (engine == generic) + updateState &= ~GenericUpdating; +#endif +#endif + +#ifdef Q_OS_WIN + else if (engine == nla) + updateState &= ~NlaUpdating; +#ifdef Q_OS_WIN32 + else if (engine == nativeWifi) + updateState &= ~NativeWifiUpdating; +#endif +#endif + } + QList engines; + if (firstUpdate) { +#if defined (Q_OS_DARWIN) + if (coreWifi) + engines << coreWifi; +#else +#if defined(BACKEND_NM) + if (nmWifi) + engines << nmWifi; + else if (generic) + engines << generic; +#else + if (generic) + engines << generic; +#endif +#endif + +#ifdef Q_OS_WIN + if (nla) + engines << nla; +#ifdef Q_OS_WIN32 + if (nativeWifi) + engines << nativeWifi; +#endif +#endif + } else if (engine) { + engines << engine; + } + + while (!engines.isEmpty()) { + engine = engines.takeFirst(); + + bool ok; + QList foundConfigurations = engine->getConfigurations(&ok); + + // Find removed configurations. + QList removedIdentifiers = configurationEngine.keys(); + for (int i = 0; i < foundConfigurations.count(); ++i) + removedIdentifiers.removeOne(foundConfigurations.at(i)->id); + + // Update or add configurations. + while (!foundConfigurations.isEmpty()) { + QNetworkConfigurationPrivate *cpPriv = foundConfigurations.takeFirst(); + + if (accessPointConfigurations.contains(cpPriv->id)) + configurationChanged(cpPriv); + else + configurationAdded(cpPriv, engine); + + delete cpPriv; + } + + // Remove configurations. + while (!removedIdentifiers.isEmpty()) { + const QString id = removedIdentifiers.takeFirst(); + + if (configurationEngine.value(id) == engine) + configurationRemoved(id); + } + } + + updateInternetServiceConfiguration(); + + if (updateState == Updating) { + updateState = NotUpdating; + emit configurationUpdateComplete(); + } + + if (firstUpdate) + firstUpdate = false; +} + +/*! + Returns the first active configuration found, if one exists; otherwise returns the first + discovered configuration found, if one exists; otherwise returns an empty configuration. + + \internal +*/ +QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() +{ + QExplicitlySharedDataPointer firstActive; + QExplicitlySharedDataPointer firstDiscovered; + + QHash >::const_iterator i = + accessPointConfigurations.constBegin(); + while (i != accessPointConfigurations.constEnd()) { + QNetworkConfigurationPrivate *priv = i.value().data(); + + if (!firstActive && priv->isValid && + (priv->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) + firstActive = i.value(); + if (!firstDiscovered && priv->isValid && + (priv->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) + firstDiscovered = i.value(); + + ++i; + } + + QNetworkConfiguration item; + + if (firstActive) + item.d = firstActive; + else if (firstDiscovered) + item.d = firstDiscovered; + + return item; +} + +void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() +{ + updateState = Updating; +#if defined (Q_OS_DARWIN) + if (coreWifi) { + updateState |= CoreWifiUpdating; + coreWifi->requestUpdate(); + } +#else +#if defined(BACKEND_NM) + if (nmWifi) { + updateState |= NmUpdating; + nmWifi->requestUpdate(); + } else if (generic) { + updateState |= GenericUpdating; + generic->requestUpdate(); + } +#else + if (generic) { + updateState |= GenericUpdating; + generic->requestUpdate(); + } +#endif +#endif +#ifdef Q_OS_WIN + if (nla) { + updateState |= NlaUpdating; + nla->requestUpdate(); + } +#endif + +#ifdef Q_OS_WIN32 + if (nativeWifi) { + updateState |= NativeWifiUpdating; + nativeWifi->requestUpdate(); + } +#endif +} + +#include "moc_qnetworkconfigmanager_p.cpp" + +QTM_END_NAMESPACE + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfigmanager_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfigmanager_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCONFIGURATIONMANAGERPRIVATE_H +#define QNETWORKCONFIGURATIONMANAGERPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworkconfigmanager.h" +#include "qnetworkconfiguration_p.h" + +#include +#include + +QTM_BEGIN_NAMESPACE + +#ifdef BEARER_ENGINE +class QNetworkSessionEngine; +class QGenericEngine; +class QNlaEngine; +class QNativeWifiEngine; +class QNmWifiEngine; +class QCoreWlanEngine; +#endif + + +class QNetworkConfigurationManagerPrivate : public QObject +{ + Q_OBJECT +public: + QNetworkConfigurationManagerPrivate() + : QObject(0), capFlags(0), firstUpdate(true) + { + registerPlatformCapabilities(); + updateConfigurations(); + } + + virtual ~QNetworkConfigurationManagerPrivate() + { + QList configIdents = snapConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = accessPointConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + } + + QNetworkConfiguration defaultConfiguration(); + + QNetworkConfigurationManager::Capabilities capFlags; + void registerPlatformCapabilities(); + + void performAsyncConfigurationUpdate(); + + //this table contains an up to date list of all configs at any time. + //it must be updated if configurations change, are added/removed or + //the members of ServiceNetworks change + QHash > accessPointConfigurations; + QHash > snapConfigurations; + QHash > userChoiceConfigurations; +#ifdef BEARER_ENGINE + QHash configurationEngine; +#endif + bool firstUpdate; + +public slots: + void updateConfigurations(); + +Q_SIGNALS: + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void configurationUpdateComplete(); + void configurationChanged(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); + +private: +#ifdef BEARER_ENGINE + void updateInternetServiceConfiguration(); + + void abort(); +#endif + +#ifdef BEARER_ENGINE + QGenericEngine *generic; +#ifdef Q_OS_WIN + QNlaEngine *nla; +#ifndef Q_OS_WINCE + QNativeWifiEngine *nativeWifi; +#endif +#endif +#ifdef BACKEND_NM + QNmWifiEngine *nmWifi; +#endif +#ifdef Q_OS_DARWIN + QCoreWlanEngine *coreWifi; +#endif + + uint onlineConfigurations; + + enum EngineUpdate { + NotUpdating = 0x00, + Updating = 0x01, + GenericUpdating = 0x02, + NlaUpdating = 0x04, + NativeWifiUpdating = 0x08, + NmUpdating = 0x20, + CoreWifiUpdating = 0x40, + }; + Q_DECLARE_FLAGS(EngineUpdateState, EngineUpdate) + + EngineUpdateState updateState; +#endif + +private Q_SLOTS: +#ifdef BEARER_ENGINE + void configurationAdded(QNetworkConfigurationPrivate *cpPriv, QNetworkSessionEngine *engine); + void configurationRemoved(const QString &id); + void configurationChanged(QNetworkConfigurationPrivate *cpPriv); +#endif +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfigmanager_s60_p.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfigmanager_s60_p.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,994 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworkconfigmanager_s60_p.h" + +#include +#include +#include + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include + #include + #include + #include + #include + #include +#else + #include + #include + #include +#endif + +QTM_BEGIN_NAMESPACE + +static const int KValueThatWillBeAddedToSNAPId = 1000; +static const int KUserChoiceIAPId = 0; + +QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() + : QObject(0), CActive(CActive::EPriorityIdle), capFlags(0), iFirstUpdate(true), iInitOk(true) +{ + CActiveScheduler::Add(this); + + registerPlatformCapabilities(); + TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP)); + if (error != KErrNone) { + iInitOk = false; + return; + } + + TRAP_IGNORE(iConnectionMonitor.ConnectL()); + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + TRAP(error, iCmManager.OpenL()); + if (error != KErrNone) { + iInitOk = false; + return; + } +#endif + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = "UserChoice"; + cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(KUserChoiceIAPId)); + cpPriv->numericId = KUserChoiceIAPId; + cpPriv->connectionId = 0; + cpPriv->type = QNetworkConfiguration::UserChoice; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + QExplicitlySharedDataPointer ptr(cpPriv); + userChoiceConfigurations.insert(cpPriv->id, ptr); + + updateConfigurations(); + updateStatesToSnaps(); + + updateAvailableAccessPoints(); // On first time updates synchronously (without WLAN scans) + + // Start monitoring IAP and/or SNAP changes in Symbian CommsDB + startCommsDatabaseNotifications(); + iFirstUpdate = false; +} + +QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() +{ + Cancel(); + + QList configIdents = snapConfigurations.keys(); + foreach(QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = accessPointConfigurations.keys(); + foreach(QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = userChoiceConfigurations.keys(); + foreach(QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = userChoiceConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + priv->manager = 0; + } + + iConnectionMonitor.CancelNotifications(); + iConnectionMonitor.Close(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iCmManager.Close(); +#endif + + delete ipAccessPointsAvailabilityScanner; + + // CCommsDatabase destructor uses cleanup stack. Since QNetworkConfigurationManager + // is a global static, but the time we are here, E32Main() has been exited already and + // the thread's default cleanup stack has been deleted. Without this line, a + // 'E32USER-CBase 69' -panic will occur. + CTrapCleanup* cleanup = CTrapCleanup::New(); + delete ipCommsDB; + delete cleanup; +} + + +void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() +{ + capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + capFlags |= QNetworkConfigurationManager::DirectConnectionRouting; + capFlags |= QNetworkConfigurationManager::SystemSessionSupport; +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + capFlags |= QNetworkConfigurationManager::ApplicationLevelRoaming; + capFlags |= QNetworkConfigurationManager::ForcedRoaming; +#endif + capFlags |= QNetworkConfigurationManager::DataStatistics; +} + +void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() +{ + if (!iInitOk || iUpdateGoingOn) { + return; + } + iUpdateGoingOn = true; + + stopCommsDatabaseNotifications(); + updateConfigurations(); // Synchronous call + updateAvailableAccessPoints(); // Asynchronous call +} + +void QNetworkConfigurationManagerPrivate::updateConfigurations() +{ + if (!iInitOk) { + return; + } + + TRAP_IGNORE(updateConfigurationsL()); +} + +void QNetworkConfigurationManagerPrivate::updateConfigurationsL() +{ + QList knownConfigs = accessPointConfigurations.keys(); + QList knownSnapConfigs = snapConfigurations.keys(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + // S60 version is >= Series60 3rd Edition Feature Pack 2 + TInt error = KErrNone; + + // Loop through all IAPs + RArray connectionMethods; // IAPs + CleanupClosePushL(connectionMethods); + iCmManager.ConnectionMethodL(connectionMethods); + for(int i = 0; i < connectionMethods.Count(); i++) { + RCmConnectionMethod connectionMethod = iCmManager.ConnectionMethodL(connectionMethods[i]); + CleanupClosePushL(connectionMethod); + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString ident = QString::number(qHash(iapId)); + if (accessPointConfigurations.contains(ident)) { + knownConfigs.removeOne(ident); + } else { + QNetworkConfigurationPrivate* cpPriv = NULL; + TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); + if (error == KErrNone) { + QExplicitlySharedDataPointer ptr(cpPriv); + accessPointConfigurations.insert(cpPriv->id, ptr); + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + } + } + CleanupStack::PopAndDestroy(&connectionMethod); + } + CleanupStack::PopAndDestroy(&connectionMethods); + + // Loop through all SNAPs + RArray destinations; + CleanupClosePushL(destinations); + iCmManager.AllDestinationsL(destinations); + for(int i = 0; i < destinations.Count(); i++) { + RCmDestination destination; + destination = iCmManager.DestinationL(destinations[i]); + CleanupClosePushL(destination); + QString ident = QString::number(qHash(destination.Id()+KValueThatWillBeAddedToSNAPId)); //TODO: Check if it's ok to add 1000 SNAP Id to prevent SNAP ids overlapping IAP ids + if (snapConfigurations.contains(ident)) { + knownSnapConfigs.removeOne(ident); + } else { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + CleanupStack::PushL(cpPriv); + + HBufC *pName = destination.NameLC(); + cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->numericId = destination.Id(); + cpPriv->connectionId = 0; + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->type = QNetworkConfiguration::ServiceNetwork; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + + QExplicitlySharedDataPointer ptr(cpPriv); + snapConfigurations.insert(ident, ptr); + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + + CleanupStack::Pop(cpPriv); + } + QExplicitlySharedDataPointer privSNAP = snapConfigurations.value(ident); + + for (int j=0; j < destination.ConnectionMethodCount(); j++) { + RCmConnectionMethod connectionMethod = destination.ConnectionMethodL(j); + CleanupClosePushL(connectionMethod); + + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString iface = QString::number(qHash(iapId)); + // Check that IAP can be found from accessPointConfigurations list + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data() == 0) { + QNetworkConfigurationPrivate* cpPriv = NULL; + TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); + if (error == KErrNone) { + QExplicitlySharedDataPointer ptr(cpPriv); + ptr.data()->serviceNetworkPtr = privSNAP; + accessPointConfigurations.insert(cpPriv->id, ptr); + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + privSNAP->serviceNetworkMembers.append(ptr); + } + } else { + knownConfigs.removeOne(iface); + // Check that IAP can be found from related SNAP's configuration list + bool iapFound = false; + for (int i=0; iserviceNetworkMembers.count(); i++) { + if (privSNAP->serviceNetworkMembers[i]->numericId == iapId) { + iapFound = true; + break; + } + } + if (!iapFound) { + priv.data()->serviceNetworkPtr = privSNAP; + privSNAP->serviceNetworkMembers.append(priv); + } + } + + CleanupStack::PopAndDestroy(&connectionMethod); + } + + if (privSNAP->serviceNetworkMembers.count() > 1) { + // Roaming is supported only if SNAP contains more than one IAP + privSNAP->roamingSupported = true; + } + + CleanupStack::PopAndDestroy(&destination); + } + CleanupStack::PopAndDestroy(&destinations); + +#else + // S60 version is < Series60 3rd Edition Feature Pack 2 + CCommsDbTableView* pDbTView = ipCommsDB->OpenTableLC(TPtrC(IAP)); + + // Loop through all IAPs + TUint32 apId = 0; + TInt retVal = pDbTView->GotoFirstRecord(); + while (retVal == KErrNone) { + pDbTView->ReadUintL(TPtrC(COMMDB_ID), apId); + QString ident = QString::number(qHash(apId)); + if (accessPointConfigurations.contains(ident)) { + knownConfigs.removeOne(ident); + } else { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + if (readNetworkConfigurationValuesFromCommsDb(apId, cpPriv)) { + QExplicitlySharedDataPointer ptr(cpPriv); + accessPointConfigurations.insert(ident, ptr); + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + } else { + delete cpPriv; + } + } + retVal = pDbTView->GotoNextRecord(); + } + CleanupStack::PopAndDestroy(pDbTView); +#endif + updateActiveAccessPoints(); + + foreach (QString oldIface, knownConfigs) { + //remove non existing IAP + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = priv; + emit configurationRemoved(item); + } + // Remove non existing IAP from SNAPs + QList snapConfigIdents = snapConfigurations.keys(); + foreach (QString iface, snapConfigIdents) { + QExplicitlySharedDataPointer priv2 = snapConfigurations.value(iface); + // => Check if one of the IAPs of the SNAP is active + for (int i=0; iserviceNetworkMembers.count(); i++) { + if (priv2->serviceNetworkMembers[i]->numericId == priv->numericId) { + priv2->serviceNetworkMembers.removeAt(i); + break; + } + } + } + } + foreach (QString oldIface, knownSnapConfigs) { + //remove non existing SNAPs + QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = priv; + emit configurationRemoved(item); + } + } +} + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +QNetworkConfigurationPrivate* QNetworkConfigurationManagerPrivate::configFromConnectionMethodL( + RCmConnectionMethod& connectionMethod) +{ + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + CleanupStack::PushL(cpPriv); + + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString ident = QString::number(qHash(iapId)); + + HBufC *pName = connectionMethod.GetStringAttributeL(CMManager::ECmName); + CleanupStack::PushL(pName); + cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + + TUint32 bearerId = connectionMethod.GetIntAttributeL(CMManager::ECmCommsDBBearerType); + switch (bearerId) { + case KCommDbBearerCSD: + cpPriv->bearer = QNetworkConfigurationPrivate::Bearer2G; + break; + case KCommDbBearerWcdma: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerWCDMA; + break; + case KCommDbBearerLAN: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerEthernet; + break; + case KCommDbBearerVirtual: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; + break; + case KCommDbBearerPAN: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; + break; + case KCommDbBearerWLAN: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerWLAN; + break; + default: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; + break; + } + + TInt error = KErrNone; + TUint32 bearerType = connectionMethod.GetIntAttributeL(CMManager::ECmBearerType); + switch (bearerType) { + case KUidPacketDataBearerType: + // "Packet data" Bearer => Mapping is done using "Access point name" + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EPacketDataAPName)); + break; + case KUidWlanBearerType: + // "Wireless LAN" Bearer => Mapping is done using "WLAN network name" = SSID + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EWlanSSID)); + break; + } + if (!pName) { + // "Data call" Bearer or "High Speed (GSM)" Bearer => Mapping is done using "Dial-up number" + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EDialDefaultTelNum)); + } + + if (error == KErrNone && pName) { + CleanupStack::PushL(pName); + cpPriv->mappingName = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + } + + cpPriv->state = QNetworkConfiguration::Defined; + TBool isConnected = connectionMethod.GetBoolAttributeL(CMManager::ECmConnected); + if (isConnected) { + cpPriv->state = QNetworkConfiguration::Active; + } + + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->numericId = iapId; + cpPriv->connectionId = 0; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + + CleanupStack::Pop(cpPriv); + return cpPriv; +} +#else +bool QNetworkConfigurationManagerPrivate::readNetworkConfigurationValuesFromCommsDb( + TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration) +{ + TRAPD(error, readNetworkConfigurationValuesFromCommsDbL(aApId,apNetworkConfiguration)); + if (error != KErrNone) { + return false; + } + return true; +} + +void QNetworkConfigurationManagerPrivate::readNetworkConfigurationValuesFromCommsDbL( + TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration) +{ + CApDataHandler* pDataHandler = CApDataHandler::NewLC(*ipCommsDB); + CApAccessPointItem* pAPItem = CApAccessPointItem::NewLC(); + TBuf name; + + CApUtils* pApUtils = CApUtils::NewLC(*ipCommsDB); + TUint32 apId = pApUtils->WapIdFromIapIdL(aApId); + + pDataHandler->AccessPointDataL(apId,*pAPItem); + pAPItem->ReadTextL(EApIapName, name); + if (name.Compare(_L("Easy WLAN")) == 0) { + // "Easy WLAN" won't be accepted to the Configurations list + User::Leave(KErrNotFound); + } + + QString ident = QString::number(qHash(aApId)); + + apNetworkConfiguration->name = QString::fromUtf16(name.Ptr(),name.Length()); + apNetworkConfiguration->isValid = true; + apNetworkConfiguration->id = ident; + apNetworkConfiguration->numericId = aApId; + apNetworkConfiguration->connectionId = 0; + apNetworkConfiguration->state = (QNetworkConfiguration::Defined); + apNetworkConfiguration->type = QNetworkConfiguration::InternetAccessPoint; + apNetworkConfiguration->purpose = QNetworkConfiguration::UnknownPurpose; + apNetworkConfiguration->roamingSupported = false; + switch (pAPItem->BearerTypeL()) { + case EApBearerTypeCSD: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::Bearer2G; + break; + case EApBearerTypeGPRS: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::Bearer2G; + break; + case EApBearerTypeHSCSD: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerHSPA; + break; + case EApBearerTypeCDMA: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerCDMA2000; + break; + case EApBearerTypeWLAN: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerWLAN; + break; + case EApBearerTypeLAN: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerEthernet; + break; + case EApBearerTypeLANModem: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerEthernet; + break; + default: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerUnknown; + break; + } + apNetworkConfiguration->manager = this; + + CleanupStack::PopAndDestroy(pApUtils); + CleanupStack::PopAndDestroy(pAPItem); + CleanupStack::PopAndDestroy(pDataHandler); +} +#endif + +QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() +{ + QNetworkConfiguration config; + + if (iInitOk) { + stopCommsDatabaseNotifications(); + TRAP_IGNORE(config = defaultConfigurationL()); + startCommsDatabaseNotifications(); + } + + return config; +} + +QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfigurationL() +{ + QNetworkConfiguration item; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + // Check Default Connection (SNAP or IAP) + TCmDefConnValue defaultConnectionValue; + iCmManager.ReadDefConnL(defaultConnectionValue); + if (defaultConnectionValue.iType == ECmDefConnDestination) { + QString iface = QString::number(qHash(defaultConnectionValue.iId+KValueThatWillBeAddedToSNAPId)); + QExplicitlySharedDataPointer priv = snapConfigurations.value(iface); + if (priv.data() != 0) { + item.d = priv; + } + } else if (defaultConnectionValue.iType == ECmDefConnConnectionMethod) { + QString iface = QString::number(qHash(defaultConnectionValue.iId)); + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data() != 0) { + item.d = priv; + } + } +#endif + + if (!item.isValid()) { + QString iface = QString::number(qHash(KUserChoiceIAPId)); + QExplicitlySharedDataPointer priv = userChoiceConfigurations.value(iface); + if (priv.data() != 0) { + item.d = priv; + } + } + + return item; +} + +void QNetworkConfigurationManagerPrivate::updateActiveAccessPoints() +{ + bool online = false; + QList inactiveConfigs = accessPointConfigurations.keys(); + + TRequestStatus status; + TUint connectionCount; + iConnectionMonitor.GetConnectionCount(connectionCount, status); + User::WaitForRequest(status); + + // Go through all connections and set state of related IAPs to Active + TUint connectionId; + TUint subConnectionCount; + TUint apId; + if (status.Int() == KErrNone) { + for (TUint i = 1; i <= connectionCount; i++) { + iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + QString ident = QString::number(qHash(apId)); + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); + if (priv.data()) { + online = true; + inactiveConfigs.removeOne(ident); + priv.data()->connectionId = connectionId; + // Configuration is Active + changeConfigurationStateTo(priv, QNetworkConfiguration::Active); + } + } + } + + // Make sure that state of rest of the IAPs won't be Active + foreach (QString iface, inactiveConfigs) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data()) { + // Configuration is either Defined or Discovered + changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Discovered); + } + } + + if (iOnline != online) { + iOnline = online; + emit this->onlineStateChanged(iOnline); + } +} + +void QNetworkConfigurationManagerPrivate::updateAvailableAccessPoints() +{ + if (!ipAccessPointsAvailabilityScanner) { + ipAccessPointsAvailabilityScanner = new AccessPointsAvailabilityScanner(*this, iConnectionMonitor); + } + if (ipAccessPointsAvailabilityScanner) { + // Scanning may take a while because WLAN scanning will be done (if device supports WLAN). + ipAccessPointsAvailabilityScanner->StartScanning(); + } +} + +void QNetworkConfigurationManagerPrivate::accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo) +{ + iUpdateGoingOn = false; + if (scanSuccessful) { + QList unavailableConfigs = accessPointConfigurations.keys(); + + // Set state of returned IAPs to Discovered + // if state is not already Active + for(TUint i=0; i priv = accessPointConfigurations.value(ident); + if (priv.data()) { + unavailableConfigs.removeOne(ident); + if (priv.data()->state < QNetworkConfiguration::Active) { + // Configuration is either Discovered or Active + changeConfigurationStateAtMinTo(priv, QNetworkConfiguration::Discovered); + } + } + } + + // Make sure that state of rest of the IAPs won't be Discovered or Active + foreach (QString iface, unavailableConfigs) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data()) { + // Configuration is Defined + changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Defined); + } + } + } + + updateStatesToSnaps(); + + if (!iFirstUpdate) { + startCommsDatabaseNotifications(); + emit this->configurationUpdateComplete(); + } +} + +void QNetworkConfigurationManagerPrivate::updateStatesToSnaps() +{ + // Go through SNAPs and set correct state to SNAPs + QList snapConfigIdents = snapConfigurations.keys(); + foreach (QString iface, snapConfigIdents) { + bool discovered = false; + bool active = false; + QExplicitlySharedDataPointer priv = snapConfigurations.value(iface); + // => Check if one of the IAPs of the SNAP is discovered or active + // => If one of IAPs is active, also SNAP is active + // => If one of IAPs is discovered but none of the IAPs is active, SNAP is discovered + for (int i=0; iserviceNetworkMembers.count(); i++) { + QExplicitlySharedDataPointer priv2 = priv->serviceNetworkMembers[i]; + if ((priv->serviceNetworkMembers[i]->state & QNetworkConfiguration::Active) + == QNetworkConfiguration::Active) { + active = true; + break; + } else if ((priv->serviceNetworkMembers[i]->state & QNetworkConfiguration::Discovered) + == QNetworkConfiguration::Discovered) { + discovered = true; + } + } + if (active) { + changeConfigurationStateTo(priv, QNetworkConfiguration::Active); + } else if (discovered) { + changeConfigurationStateTo(priv, QNetworkConfiguration::Discovered); + } else { + changeConfigurationStateTo(priv, QNetworkConfiguration::Defined); + } + } +} + +bool QNetworkConfigurationManagerPrivate::changeConfigurationStateTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState) +{ + if (newState != sharedData.data()->state) { + sharedData.data()->state = newState; + QNetworkConfiguration item; + item.d = sharedData; + if (!iFirstUpdate) { + emit configurationChanged(item); + } + return true; + } + return false; +} + +/* changeConfigurationStateAtMinTo function does not overwrite possible better + * state (e.g. Discovered state does not overwrite Active state) but + * makes sure that state is at minimum given state. +*/ +bool QNetworkConfigurationManagerPrivate::changeConfigurationStateAtMinTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState) +{ + if ((newState | sharedData.data()->state) != sharedData.data()->state) { + sharedData.data()->state = (sharedData.data()->state | newState); + QNetworkConfiguration item; + item.d = sharedData; + if (!iFirstUpdate) { + emit configurationChanged(item); + } + return true; + } + return false; +} + +/* changeConfigurationStateAtMaxTo function overwrites possible better + * state (e.g. Discovered state overwrites Active state) and + * makes sure that state is at maximum given state (e.g. Discovered state + * does not overwrite Defined state). +*/ +bool QNetworkConfigurationManagerPrivate::changeConfigurationStateAtMaxTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState) +{ + if ((newState & sharedData.data()->state) != sharedData.data()->state) { + sharedData.data()->state = (newState & sharedData.data()->state); + QNetworkConfiguration item; + item.d = sharedData; + if (!iFirstUpdate) { + emit configurationChanged(item); + } + return true; + } + return false; +} + +void QNetworkConfigurationManagerPrivate::startCommsDatabaseNotifications() +{ + if (!iWaitingCommsDatabaseNotifications) { + iWaitingCommsDatabaseNotifications = ETrue; + if (!IsActive()) { + SetActive(); + // Start waiting for new notification + ipCommsDB->RequestNotification(iStatus); + } + } +} + +void QNetworkConfigurationManagerPrivate::stopCommsDatabaseNotifications() +{ + if (iWaitingCommsDatabaseNotifications) { + iWaitingCommsDatabaseNotifications = EFalse; + if (!IsActive()) { + SetActive(); + // Make sure that notifier recorded events will not be returned + // as soon as the client issues the next RequestNotification() request. + ipCommsDB->RequestNotification(iStatus); + ipCommsDB->CancelRequestNotification(); + } else { + ipCommsDB->CancelRequestNotification(); + } + } +} + +void QNetworkConfigurationManagerPrivate::RunL() +{ + if (iStatus != KErrCancel) { + RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); + switch (event) { +// case RDbNotifier::EUnlock: /** All read locks have been removed. */ + case RDbNotifier::ECommit: /** A transaction has been committed. */ + case RDbNotifier::ERollback: /** A transaction has been rolled back */ + case RDbNotifier::ERecover: /** The database has been recovered */ + // Note that if further database events occur while a client is handling + // a request completion, the notifier records the most significant database + // event and this is signalled as soon as the client issues the next + // RequestNotification() request. + // => Stop recording notifications + stopCommsDatabaseNotifications(); + TRAPD(error, updateConfigurationsL()); + if (error == KErrNone) { + updateStatesToSnaps(); + } + iWaitingCommsDatabaseNotifications = true; + break; + default: + // Do nothing + break; + } + } + + if (iWaitingCommsDatabaseNotifications) { + if (!IsActive()) { + SetActive(); + // Start waiting for new notification + ipCommsDB->RequestNotification(iStatus); + } + } +} + +void QNetworkConfigurationManagerPrivate::DoCancel() +{ + ipCommsDB->CancelRequestNotification(); +} + + +void QNetworkConfigurationManagerPrivate::EventL(const CConnMonEventBase& aEvent) +{ + switch (aEvent.EventType()) { + case EConnMonCreateConnection: + { + CConnMonCreateConnection* realEvent; + realEvent = (CConnMonCreateConnection*) &aEvent; + TUint subConnectionCount = 0; + TUint apId; + TUint connectionId = realEvent->ConnectionId(); + TRequestStatus status; + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + QString ident = QString::number(qHash(apId)); + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); + if (priv.data()) { + priv.data()->connectionId = connectionId; + // Configuration is Active + if (changeConfigurationStateTo(priv, QNetworkConfiguration::Active)) { + updateStatesToSnaps(); + } + if (!iOnline) { + iOnline = true; + emit this->onlineStateChanged(iOnline); + } + } + } + break; + + case EConnMonDeleteConnection: + { + CConnMonDeleteConnection* realEvent; + realEvent = (CConnMonDeleteConnection*) &aEvent; + TUint connectionId = realEvent->ConnectionId(); + QExplicitlySharedDataPointer priv = dataByConnectionId(connectionId); + if (priv.data()) { + priv.data()->connectionId = 0; + // Configuration is either Defined or Discovered + if (changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Discovered)) { + updateStatesToSnaps(); + } + } + + bool online = false; + QList iapConfigs = accessPointConfigurations.keys(); + foreach (QString iface, iapConfigs) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data()->state == QNetworkConfiguration::Active) { + online = true; + break; + } + } + if (iOnline != online) { + iOnline = online; + emit this->onlineStateChanged(iOnline); + } + } + break; + + case EConnMonIapAvailabilityChange: + { + CConnMonIapAvailabilityChange* realEvent; + realEvent = (CConnMonIapAvailabilityChange*) &aEvent; + TConnMonIapInfo iaps = realEvent->IapAvailability(); + QList unDiscoveredConfigs = accessPointConfigurations.keys(); + for ( TUint i = 0; i < iaps.Count(); i++ ) { + QString ident = QString::number(qHash(iaps.iIap[i].iIapId)); + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); + if (priv.data()) { + // Configuration is either Discovered or Active + changeConfigurationStateAtMinTo(priv, QNetworkConfiguration::Discovered); + unDiscoveredConfigs.removeOne(ident); + } + } + foreach (QString iface, unDiscoveredConfigs) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data()) { + // Configuration is Defined + changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Defined); + } + } + } + break; + + default: + // For unrecognized events + break; + } +} + +QExplicitlySharedDataPointer QNetworkConfigurationManagerPrivate::dataByConnectionId(TUint aConnectionId) +{ + QNetworkConfiguration item; + + QHash >::const_iterator i = + accessPointConfigurations.constBegin(); + while (i != accessPointConfigurations.constEnd()) { + QExplicitlySharedDataPointer priv = i.value(); + if (priv.data()->connectionId == aConnectionId) { + return priv; + } + ++i; + } + + return QExplicitlySharedDataPointer(); +} + +AccessPointsAvailabilityScanner::AccessPointsAvailabilityScanner(QNetworkConfigurationManagerPrivate& owner, + RConnectionMonitor& connectionMonitor) + : CActive(CActive::EPriorityStandard), iOwner(owner), iConnectionMonitor(connectionMonitor) +{ + CActiveScheduler::Add(this); +} + +AccessPointsAvailabilityScanner::~AccessPointsAvailabilityScanner() +{ + Cancel(); +} + +void AccessPointsAvailabilityScanner::DoCancel() +{ + iConnectionMonitor.CancelAsyncRequest(EConnMonGetPckgAttribute); +} + +void AccessPointsAvailabilityScanner::StartScanning() +{ + if (iOwner.iFirstUpdate) { + // On first update (the mgr is being instantiated) update only those bearers who + // don't need time-consuming scans (WLAN). + // Note: EBearerIdWCDMA covers also GPRS bearer + iConnectionMonitor.GetPckgAttribute(EBearerIdWCDMA, 0, KIapAvailability, iIapBuf, iStatus); + User::WaitForRequest(iStatus); + if (iStatus.Int() == KErrNone) { + iOwner.accessPointScanningReady(true,iIapBuf()); + } + } else { + iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus); + if (!IsActive()) { + SetActive(); + } + } +} + +void AccessPointsAvailabilityScanner::RunL() +{ + if (iStatus.Int() != KErrNone) { + iIapBuf().iCount = 0; + iOwner.accessPointScanningReady(false,iIapBuf()); + } else { + iOwner.accessPointScanningReady(true,iIapBuf()); + } +} +#include "moc_qnetworkconfigmanager_s60_p.cpp" +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfigmanager_s60_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfigmanager_s60_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCONFIGURATIONMANAGERPRIVATE_H +#define QNETWORKCONFIGURATIONMANAGERPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +#include +#include +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include +#endif + +class CCommsDatabase; + +QT_BEGIN_NAMESPACE +class QTimer; +QT_END_NAMESPACE + +QTM_BEGIN_NAMESPACE + +class QNetworkSessionPrivate; +class AccessPointsAvailabilityScanner; + +class QNetworkConfigurationManagerPrivate : public QObject, public CActive, public MConnectionMonitorObserver +{ + Q_OBJECT + +public: + QNetworkConfigurationManagerPrivate(); + virtual ~QNetworkConfigurationManagerPrivate(); + + QNetworkConfiguration defaultConfiguration(); + void performAsyncConfigurationUpdate(); + +Q_SIGNALS: + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void configurationUpdateComplete(); + void configurationChanged(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); + +public Q_SLOTS: + void updateConfigurations(); + +private: + void registerPlatformCapabilities(); + void updateStatesToSnaps(); + bool changeConfigurationStateTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState); + bool changeConfigurationStateAtMinTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState); + bool changeConfigurationStateAtMaxTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState); +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + QNetworkConfigurationPrivate* configFromConnectionMethodL(RCmConnectionMethod& connectionMethod); +#else + bool readNetworkConfigurationValuesFromCommsDb( + TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration); + void readNetworkConfigurationValuesFromCommsDbL( + TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration); +#endif + + void updateConfigurationsL(); + void updateActiveAccessPoints(); + void updateAvailableAccessPoints(); + void accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo); + void startCommsDatabaseNotifications(); + void stopCommsDatabaseNotifications(); + + QNetworkConfiguration defaultConfigurationL(); + TBool GetS60PlatformVersion(TUint& aMajor, TUint& aMinor) const; + void startMonitoringIAPData(TUint32 aIapId); + QExplicitlySharedDataPointer dataByConnectionId(TUint aConnectionId); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // MConnectionMonitorObserver + void EventL(const CConnMonEventBase& aEvent); + +public: // Data + //this table contains an up to date list of all configs at any time. + //it must be updated if configurations change, are added/removed or + //the members of ServiceNetworks change + QHash > accessPointConfigurations; + QHash > snapConfigurations; + QHash > userChoiceConfigurations; + QNetworkConfigurationManager::Capabilities capFlags; + +private: // Data + bool iFirstUpdate; + CCommsDatabase* ipCommsDB; + RConnectionMonitor iConnectionMonitor; + + TBool iWaitingCommsDatabaseNotifications; + TBool iOnline; + TBool iInitOk; + TBool iUpdateGoingOn; + + + AccessPointsAvailabilityScanner* ipAccessPointsAvailabilityScanner; + + friend class QNetworkSessionPrivate; + friend class AccessPointsAvailabilityScanner; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + RCmManager iCmManager; +#endif +}; + +class AccessPointsAvailabilityScanner : public CActive +{ +public: + AccessPointsAvailabilityScanner(QNetworkConfigurationManagerPrivate& owner, + RConnectionMonitor& connectionMonitor); + ~AccessPointsAvailabilityScanner(); + + void StartScanning(); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // Data + QNetworkConfigurationManagerPrivate& iOwner; + RConnectionMonitor& iConnectionMonitor; + TConnMonIapInfoBuf iIapBuf; +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfiguration.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfiguration.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,401 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworkconfiguration.h" + +#ifdef Q_OS_SYMBIAN +#include "qnetworkconfiguration_s60_p.h" +#elif Q_WS_MAEMO_6 +#include "qnetworkconfiguration_maemo_p.h" +#else +#include "qnetworkconfiguration_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +/*! + \class QNetworkConfiguration + + \brief The QNetworkConfiguration class provides an abstraction of one or more access point configurations. + + \inmodule QtNetwork + \ingroup bearer + + QNetworkConfiguration encapsulates a single access point or service network. + In most cases a single access point configuration can be mapped to one network + interface. However a single network interface may not always map to only one + access point configuration. Multiple configurations for the same + network device may enable multiple access points. An example + device that could exhibit such a configuration might be a + Smartphone which allows the user to manage multiple WLAN + configurations while the device itself has only one WLAN network device. + + The QNetworkConfiguration also supports the concept of service networks. + This concept allows the grouping of multiple access point configurations + into one entity. Such a group is called service network and can be + beneficial in cases whereby a network session to a + particular destination network is required (e.g. a company network). + When using a service network the user doesn't usually care which one of the + connectivity options is chosen (e.g. corporate WLAN or VPN via GPRS) + as long as he can reach the company's target server. Depending + on the current position and time some of the access points that make + up the service network may not even be available. Furthermore + automated access point roaming can be enabled which enables the device + to change the network interface configuration dynamically while maintaining + the applications connection to the target network. It allows adaption + to the changing environment and may enable optimization with regards to + cost, speed or other network parameters. + + Special configurations of type UserChoice provide a placeholder configuration which is + resolved to an actual network configuration by the platform when a + \l {QNetworkSession}{session} is \l {QNetworkSession::open()}{opened}. Not all platforms + support the concept of a user choice configuration. + + \section1 Configuration states + + The list of available configurations can be obtained via + QNetworkConfigurationManager::allConfigurations(). A configuration can have + multiple states. The \l Defined configuration state indicates that the configuration + is stored on the device. However the configuration is not yet ready to be activated + as e.g. a WLAN may not be available at the current time. + + The \l Discovered state implies that the configuration is \l Defined and + the outside conditions are such that the configuration can be used immediately + to open a new network session. An example of such an outside condition may be + that the Ethernet cable is actually connected to the device or that the WLAN + with the specified SSID is in range. + + The \l Active state implies that the configuration is \l Discovered. A configuration + in this state is currently being used by an application. The underlying network + interface has a valid IP configuration and can transfer IP packets between the + device and the target network. + + The \l Undefined state indicates that the system has knowledge of possible target + networks but cannot actually use that knowledge to connect to it. An example + for such a state could be an encrypted WLAN that has been discovered + but the user hasn't actually saved a configuration including the required password + which would allow the device to connect to it. + + Depending on the type of configuration some states are transient in nature. A GPRS/UMTS + connection may almost always be \l Discovered if the GSM/UMTS network is available. + However if the GSM/UMTS network looses the connection the associated configuration may change its state + from \l Discovered to \l Defined as well. A similar use case might be triggered by + WLAN availability. QNetworkConfigurationManager::updateConfigurations() can be used to + manually trigger updates of states. Note that some platforms do not require such updates + as they implicitly change the state once it has been discovered. If the state of a + configuration changes all related QNetworkConfiguration instances change their state automatically. + + \sa QNetworkSession, QNetworkConfigurationManager +*/ + +/*! + \enum QNetworkConfiguration::Type + + This enum describes the type of configuration. + + \value InternetAccessPoint The configuration specifies the details for a single access point. + Note that configurations of type InternetAccessPoint may be part + of other QNetworkConfigurations of type ServiceNetwork. + \value ServiceNetwork The configuration is based on a group of QNetworkConfigurations of + type InternetAccessPoint. All group members can reach the same + target network. This type of configuration is a mandatory + requirement for roaming enabled network sessions. On some + platforms this form of configuration may also be called Service + Network Access Point (SNAP). + \value UserChoice The configuration is a placeholder which will be resolved to an + actual configuration by the platform when a session is opened. Depending + on the platform the selection may generate a popup dialog asking the user + for his preferred choice. + \value Invalid The configuration is invalid. +*/ + +/*! + \enum QNetworkConfiguration::StateFlag + + Specifies the configuration states. + + \value Undefined This state is used for transient configurations such as newly discovered + WLANs for which the user has not actually created a configuration yet. + \value Defined Defined configurations are known to the system but are not immediately + usable (e.g. a configured WLAN is not within range or the Ethernet cable + is currently not plugged into the machine). + \value Discovered A discovered configuration can be immediately used to create a new + QNetworkSession. An example of a discovered configuration could be a WLAN + which is within in range. If the device moves out of range the discovered + flag is dropped. A second example is a GPRS configuration which generally + remains discovered for as long as the phone has network coverage. A + configuration that has this state is also in state + QNetworkConfiguration::Defined. If the configuration is a service network + this flag is set if at least one of the underlying access points + configurations has the Discovered state. + \value Active The configuration is currently used by an open network session + (see \l QNetworkSession::isOpen()). However this does not mean that the + current process is the entity that created the open session. It merely + indicates that if a new QNetworkSession were to be constructed based on + this configuration \l QNetworkSession::state() would return + \l QNetworkSession::Connected. This state implies the + QNetworkConfiguration::Discovered state. +*/ + +/*! + \enum QNetworkConfiguration::Purpose + + Specifies the purpose of the configuration. + + \value UnknownPurpose The configuration doesn't specify any purpose. This is the default value. + \value PublicPurpose The configuration can be used for general purpose internet access. + \value PrivatePurpose The configuration is suitable to access a private network such as an office Intranet. + \value ServiceSpecificPurpose The configuration can be used for operator specific services (e.g. + receiving MMS messages or content streaming). +*/ + +/*! + Constructs an invalid configuration object. + + \sa isValid() +*/ +QNetworkConfiguration::QNetworkConfiguration() + : d(0) +{ +} + +/*! + Creates a copy of the QNetworkConfiguration object contained in \a other. +*/ +QNetworkConfiguration::QNetworkConfiguration(const QNetworkConfiguration& other) + : d(other.d) +{ +} + +/*! + Copies the content of the QNetworkConfiguration object contained in \a other into this one. +*/ +QNetworkConfiguration& QNetworkConfiguration::operator=(const QNetworkConfiguration& other) +{ + d = other.d; + return *this; +} + +/*! + Frees the resources associated with the QNetworkConfiguration object. +*/ +QNetworkConfiguration::~QNetworkConfiguration() +{ +} + +/*! + Returns true, if this configuration is the same as the \a other + configuration given; otherwise returns false. +*/ +bool QNetworkConfiguration::operator==(const QNetworkConfiguration& other) const +{ + if (!d) + return !other.d; + + if (!other.d) + return false; + + return (d == other.d); +} + +/*! + \fn bool QNetworkConfiguration::operator!=(const QNetworkConfiguration& other) const + + Returns true if this configuration is not the same as the \a other + configuration given; otherwise returns false. +*/ + +/*! + Returns the user visible name of this configuration. + + The name may either be the name of the underlying access point or the + name for service network that this configuration represents. +*/ +QString QNetworkConfiguration::name() const +{ + return d ? d->name : QString(); +} + +/*! + Returns the unique and platform specific identifier for this network configuration; + otherwise an empty string. +*/ +QString QNetworkConfiguration::identifier() const +{ + return d ? d->id : QString(); +} + +/*! + Returns the type of the configuration. + + A configuration can represent a single access point configuration or + a set of access point configurations. Such a set is called service network. + A configuration that is based on a service network can potentially support + roaming of network sessions. +*/ +QNetworkConfiguration::Type QNetworkConfiguration::type() const +{ + return d ? d->type : QNetworkConfiguration::Invalid; +} + +/*! + Returns true if this QNetworkConfiguration object is valid. + A configuration may become invalid if the user deletes the configuration or + the configuration was default-constructed. + + The addition and removal of configurations can be monitored via the + QNetworkConfigurationManager. + + \sa QNetworkConfigurationManager +*/ +bool QNetworkConfiguration::isValid() const +{ + return d ? d->isValid : false; +} + +/*! + Returns the current state of the configuration. +*/ +QNetworkConfiguration::StateFlags QNetworkConfiguration::state() const +{ + return d ? d->state : QNetworkConfiguration::Undefined; +} + +/*! + Returns the purpose of this configuration. + + The purpose field may be used to programmatically determine the + purpose of a configuration. Such information is usually part of the + access point or service network meta data. +*/ +QNetworkConfiguration::Purpose QNetworkConfiguration::purpose() const +{ + return d ? d->purpose : QNetworkConfiguration::UnknownPurpose; +} + +/*! + Returns true if this configuration supports roaming; otherwise false. +*/ +bool QNetworkConfiguration::isRoamingAvailable() const +{ + return d ? d->roamingSupported : false; +} + +/*! + Returns all sub configurations of this network configuration. + Only network configurations of type \l ServiceNetwork can have children. Otherwise + this function returns an empty list. +*/ +QList QNetworkConfiguration::children() const +{ + QList results; + if (type() != QNetworkConfiguration::ServiceNetwork || !isValid() ) + return results; + + QMutableListIterator > iter(d->serviceNetworkMembers); + QExplicitlySharedDataPointer p(0); + while(iter.hasNext()) { + p = iter.next(); + //if we have an invalid member get rid of it -> was deleted earlier on + if (!p->isValid) + iter.remove(); + + QNetworkConfiguration item; + item.d = p; + results << item; + } + + return results; +} + +/*! + Returns the type of bearer. The string is not translated and + therefore can not be shown to the user. The subsequent table presents the currently known + bearer types: + + \table + \header + \o Value + \o Description + \row + \o Unknown + \o The session is based on an unknown or unspecified bearer type. + \row + \o Ethernet + \o The session is based on Ethernet. + \row + \o WLAN + \o The session is based on Wireless LAN. + \row + \o 2G + \o The session uses CSD, GPRS, HSCSD, EDGE or cdmaOne. + \row + \o CDMA2000 + \o The session uses CDMA. + \row + \o WCDMA + \o The session uses W-CDMA/UMTS. + \row + \o HSPA + \o The session uses High Speed Packet Access. + \row + \o Bluetooth + \o The session uses Bluetooth. + \row + \o WiMAX + \o The session uses WiMAX. + \endtable + + This function returns an empty string if this is an invalid configuration, + a network configuration of type \l QNetworkConfiguration::ServiceNetwork or + \l QNetworkConfiguration::UserChoice. +*/ +QString QNetworkConfiguration::bearerName() const +{ + if (!isValid()) + return QString(); + + return d->bearerName(); +} + + +QTM_END_NAMESPACE + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfiguration.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfiguration.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCONFIGURATION_H +#define QNETWORKCONFIGURATION_H + +#include "qmobilityglobal.h" + +#include +#include +#include + +QT_BEGIN_HEADER + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class Q_BEARER_EXPORT QNetworkConfiguration +{ +public: + QNetworkConfiguration(); + QNetworkConfiguration(const QNetworkConfiguration& other); + QNetworkConfiguration &operator=(const QNetworkConfiguration& other); + ~QNetworkConfiguration(); + + bool operator==(const QNetworkConfiguration& cp) const; + inline bool operator!=(const QNetworkConfiguration& cp) const + { return !operator==(cp); } + + enum Type { + InternetAccessPoint = 0, + ServiceNetwork, + UserChoice, + Invalid + }; + + enum Purpose { + UnknownPurpose = 0, + PublicPurpose, + PrivatePurpose, + ServiceSpecificPurpose + }; + + enum StateFlag { + Undefined = 0x0000001, + Defined = 0x0000002, + Discovered = 0x0000006, + Active = 0x000000e + }; + + Q_DECLARE_FLAGS(StateFlags, StateFlag) + + StateFlags state() const; + Type type() const; + Purpose purpose() const; + QString bearerName() const; + QString identifier() const; + bool isRoamingAvailable() const; + QList children() const; + + QString name() const; + bool isValid() const; + +private: + friend class QNetworkConfigurationPrivate; + friend class QNetworkConfigurationManager; + friend class QNetworkConfigurationManagerPrivate; + friend class QNetworkSessionPrivate; + QExplicitlySharedDataPointer d; +}; + +QTM_END_NAMESPACE + +QT_END_HEADER + +#endif //QNETWORKCONFIGURATION_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfiguration_maemo_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfiguration_maemo_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCONFIGURATIONPRIVATE_H +#define QNETWORKCONFIGURATIONPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +#include "qnetworkconfiguration.h" + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationManagerPrivate; + +class QNetworkConfigurationPrivate : public QSharedData +{ +public: + QNetworkConfigurationPrivate () + : isValid(false), type(QNetworkConfiguration::Invalid), + roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose), + network_attrs(0), service_attrs(0), manager(0) + { + } + + ~QNetworkConfigurationPrivate() + { + //release pointers to member configurations + serviceNetworkMembers.clear(); + } + + QString name; + bool isValid; + QString id; + QNetworkConfiguration::StateFlags state; + QNetworkConfiguration::Type type; + bool roamingSupported; + QNetworkConfiguration::Purpose purpose; + + QList > serviceNetworkMembers; + QNetworkInterface serviceInterface; + + /* In Maemo the id field (defined above) is the IAP id (which typically is UUID) */ + QByteArray network_id; /* typically WLAN ssid or similar */ + QString iap_type; /* is this one WLAN or GPRS */ + QString bearerName() const + { + if (iap_type == "WLAN_INFRA" || + iap_type == "WLAN_ADHOC") + return QString("WLAN"); + else if (iap_type == "GPRS") + return QString("HSPA"); + + //return whatever it is + //this may have to be split up later on + return iap_type; + } + + uint32_t network_attrs; /* network attributes for this IAP, this is the value returned by icd and passed to it when connecting */ + + QString service_type; + QString service_id; + uint32_t service_attrs; + + QNetworkConfigurationManagerPrivate *manager; + +private: + + // disallow detaching + QNetworkConfigurationPrivate &operator=(const QNetworkConfigurationPrivate &other); + QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONPRIVATE_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfiguration_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfiguration_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCONFIGURATIONPRIVATE_H +#define QNETWORKCONFIGURATIONPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworkconfiguration.h" +#include +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate : public QSharedData +{ +public: + QNetworkConfigurationPrivate () + : isValid(false), type(QNetworkConfiguration::Invalid), + roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose) + { +#ifdef BEARER_ENGINE + internet = false; +#endif + } + + ~QNetworkConfigurationPrivate() + { + //release pointers to member configurations + serviceNetworkMembers.clear(); + } + + QString name; + QString bearer; + inline QString bearerName() const + { + return bearer; + } + + bool isValid; + QString id; + QNetworkConfiguration::StateFlags state; + QNetworkConfiguration::Type type; + bool roamingSupported; + QNetworkConfiguration::Purpose purpose; + +#ifdef BEARER_ENGINE + bool internet; +#endif + + QList > serviceNetworkMembers; + QNetworkInterface serviceInterface; + +private: + + // disallow detaching + QNetworkConfigurationPrivate &operator=(const QNetworkConfigurationPrivate &other); + QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONPRIVATE_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfiguration_s60_p.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfiguration_s60_p.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworkconfiguration_s60_p.h" + +QTM_BEGIN_NAMESPACE + +QNetworkConfigurationPrivate::QNetworkConfigurationPrivate() + : isValid(false), type(QNetworkConfiguration::Invalid), + roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose), + bearer(QNetworkConfigurationPrivate::BearerUnknown), numericId(0), + connectionId(0), manager(0) +{ +} + +QNetworkConfigurationPrivate::~QNetworkConfigurationPrivate() +{ + //release pointers to member configurations + serviceNetworkMembers.clear(); +} + +QString QNetworkConfigurationPrivate::bearerName() const +{ + switch (bearer) { + case QNetworkConfigurationPrivate::BearerEthernet: return QLatin1String("Ethernet"); + case QNetworkConfigurationPrivate::BearerWLAN: return QLatin1String("WLAN"); + case QNetworkConfigurationPrivate::Bearer2G: return QLatin1String("2G"); + case QNetworkConfigurationPrivate::BearerCDMA2000: return QLatin1String("CDMA2000"); + case QNetworkConfigurationPrivate::BearerWCDMA: return QLatin1String("WCDMA"); + case QNetworkConfigurationPrivate::BearerHSPA: return QLatin1String("HSPA"); + case QNetworkConfigurationPrivate::BearerBluetooth: return QLatin1String("Bluetooth"); + case QNetworkConfigurationPrivate::BearerWiMAX: return QLatin1String("WiMAX"); + default: return QString(); + } +} + + +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkconfiguration_s60_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkconfiguration_s60_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCONFIGURATIONPRIVATE_H +#define QNETWORKCONFIGURATIONPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate : public QSharedData +{ +public: + enum Bearer { + BearerEthernet, + BearerWLAN, + Bearer2G, + BearerCDMA2000, + BearerWCDMA, + BearerHSPA, + BearerBluetooth, + BearerWiMAX, + BearerUnknown = -1 + }; + + QNetworkConfigurationPrivate(); + ~QNetworkConfigurationPrivate(); + + QString name; + bool isValid; + QString id; + QNetworkConfiguration::StateFlags state; + QNetworkConfiguration::Type type; + bool roamingSupported; + QNetworkConfiguration::Purpose purpose; + + QList > serviceNetworkMembers; + + QNetworkConfigurationPrivate::Bearer bearer; + QString bearerName() const; + TUint32 numericId; + TUint connectionId; + + TAny* manager; + + QString mappingName; + + QExplicitlySharedDataPointer serviceNetworkPtr; + +private: + // disallow detaching + QNetworkConfigurationPrivate &operator=(const QNetworkConfigurationPrivate &other); + QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONPRIVATE_H + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkmanagerservice_p.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkmanagerservice_p.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,993 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qnetworkmanagerservice_p.h" +#include "qnmdbushelper_p.h" + +QTM_BEGIN_NAMESPACE + +static QDBusConnection dbusConnection = QDBusConnection::systemBus(); + +class QNetworkManagerInterfacePrivate +{ +public: + QDBusInterface *connectionInterface; + bool valid; +}; + +QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfacePrivate(); + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), + dbusConnection); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManager"; + d->valid = false; + return; + } + d->valid = true; + nmDBusHelper = new QNmDBusHelper(this); + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + +} + +QNetworkManagerInterface::~QNetworkManagerInterface() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterface::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterface::setConnections() +{ + if(!isValid() ) + return false; + bool allOk = false; + if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), + QLatin1String("PropertiesChanged"), + nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { + allOk = true; + } + if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), + QLatin1String("DeviceAdded"), + this,SIGNAL(deviceAdded(QDBusObjectPath)))) { + allOk = true; + } + if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), + QLatin1String("DeviceRemoved"), + this,SIGNAL(deviceRemoved(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterface::connectionInterface() const +{ + return d->connectionInterface; +} + +QList QNetworkManagerInterface::getDevices() const +{ + QDBusReply > reply = d->connectionInterface->call(QLatin1String("GetDevices")); + return reply.value(); +} + +void QNetworkManagerInterface::activateConnection( const QString &serviceName, + QDBusObjectPath connectionPath, + QDBusObjectPath devicePath, + QDBusObjectPath specificObject) +{ + QDBusPendingCall pendingCall = d->connectionInterface->asyncCall(QLatin1String("ActivateConnection"), + QVariant(serviceName), + QVariant::fromValue(connectionPath), + QVariant::fromValue(devicePath), + QVariant::fromValue(specificObject)); + + QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this); + connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); +} + +void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const +{ + d->connectionInterface->call(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath)); +} + +bool QNetworkManagerInterface::wirelessEnabled() const +{ + return d->connectionInterface->property("WirelessEnabled").toBool(); +} + +bool QNetworkManagerInterface::wirelessHardwareEnabled() const +{ + return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); +} + +QList QNetworkManagerInterface::activeConnections() const +{ + QVariant prop = d->connectionInterface->property("ActiveConnections"); + return prop.value >(); +} + +quint32 QNetworkManagerInterface::state() +{ + return d->connectionInterface->property("State").toUInt(); +} + +class QNetworkManagerInterfaceAccessPointPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceAccessPointPrivate(); + d->path = dbusPathName; + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceAccessPoint"; + return; + } + d->valid = true; + +} + +QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceAccessPoint::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceAccessPoint::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper(this); + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + + if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), + QLatin1String("PropertiesChanged"), + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const +{ + return d->connectionInterface; +} + +quint32 QNetworkManagerInterfaceAccessPoint::flags() const +{ + return d->connectionInterface->property("Flags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const +{ + return d->connectionInterface->property("WpaFlags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const +{ + return d->connectionInterface->property("RsnFlags").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::ssid() const +{ + return d->connectionInterface->property("Ssid").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::frequency() const +{ + return d->connectionInterface->property("Frequency").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const +{ + return d->connectionInterface->property("MaxBitrate").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::strength() const +{ + return d->connectionInterface->property("Strength").toUInt(); +} + +class QNetworkManagerInterfaceDevicePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceDevicePrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE), + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManager"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDevice::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDevice::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper(this); + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE), + QLatin1String("StateChanged"), + nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDevice::udi() const +{ + return d->connectionInterface->property("Udi").toString(); +} + +QNetworkInterface QNetworkManagerInterfaceDevice::networkInterface() const +{ + return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString()); +} + +quint32 QNetworkManagerInterfaceDevice::ip4Address() const +{ + return d->connectionInterface->property("Ip4Address").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::deviceType() const +{ + return d->connectionInterface->property("DeviceType").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const +{ + QVariant prop = d->connectionInterface->property("Ip4Config"); + return prop.value(); +} + +class QNetworkManagerInterfaceDeviceWiredPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWiredPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWired"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWired::isValid() +{ + + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWired::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + + nmDBusHelper = new QNmDBusHelper(this); + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), + QLatin1String("PropertiesChanged"), + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDeviceWired::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWired::speed() const +{ + return d->connectionInterface->property("Speed").toUInt(); +} + +bool QNetworkManagerInterfaceDeviceWired::carrier() const +{ + return d->connectionInterface->property("Carrier").toBool(); +} + +class QNetworkManagerInterfaceDeviceWirelessPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWireless"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWireless::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWireless::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper(this); + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); + + if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + QLatin1String("AccessPointAdded"), + nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + QLatin1String("AccessPointRemoved"), + nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + QLatin1String("PropertiesChanged"), + nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const +{ + return d->connectionInterface; +} + +QList QNetworkManagerInterfaceDeviceWireless::getAccessPoints() +{ + QDBusReply > reply = d->connectionInterface->call(QLatin1String("GetAccessPoints")); + return reply.value(); +} + +QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const +{ + return d->connectionInterface->property("Bitrate").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const +{ + return d->connectionInterface->property("ActiveAccessPoint").value(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const +{ + return d->connectionInterface->property("WirelelessCapabilities").toUInt(); +} + +class QNetworkManagerSettingsPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerSettingsPrivate(); + d->path = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + QLatin1String(NM_DBUS_PATH_SETTINGS), + QLatin1String(NM_DBUS_IFACE_SETTINGS), + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettings"; + return; + } + d->valid = true; +} + +QNetworkManagerSettings::~QNetworkManagerSettings() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettings::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettings::setConnections() +{ + bool allOk = false; + + if (!dbusConnection.connect(d->path, QLatin1String(NM_DBUS_PATH_SETTINGS), + QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"), + this, SIGNAL(newConnection(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QList QNetworkManagerSettings::listConnections() +{ + QDBusReply > reply = d->connectionInterface->call(QLatin1String("ListConnections")); + return reply.value(); +} + +QDBusInterface *QNetworkManagerSettings::connectionInterface() const +{ + return d->connectionInterface; +} + + +class QNetworkManagerSettingsConnectionPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + QString service; + QNmSettingsMap settingsMap; + bool valid; +}; + +QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) +{ + qDBusRegisterMetaType(); + d = new QNetworkManagerSettingsConnectionPrivate(); + d->path = connectionObjectPath; + d->service = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + d->path, + QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManagerSettingsConnection"; + d->valid = false; + return; + } + d->valid = true; + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings")); + d->settingsMap = rep.value(); +} + +QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettingsConnection::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettingsConnection::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + if(!dbusConnection.connect(d->service, d->path, + QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("NewConnection"), + this, SIGNAL(updated(QNmSettingsMap)))) { + allOk = true; + } + + nmDBusHelper = new QNmDBusHelper(this); + connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), + this,SIGNAL(removed( const QString &))); + + if (!dbusConnection.connect(d->service, d->path, + QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"), + nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const +{ + return d->connectionInterface; +} + +QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() +{ + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings")); + d->settingsMap = rep.value(); + return d->settingsMap; +} + +NMDeviceType QNetworkManagerSettingsConnection::getType() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("type")); + while (ii != innerMap.end() && ii.key() == QLatin1String("type")) { + QString devType = ii.value().toString(); + if (devType == QLatin1String("802-3-ethernet")) { + return DEVICE_TYPE_802_3_ETHERNET; + } + if (devType == QLatin1String("802-11-wireless")) { + return DEVICE_TYPE_802_11_WIRELESS; + } + ii++; + } + i++; + } + return DEVICE_TYPE_UNKNOWN; +} + +bool QNetworkManagerSettingsConnection::isAutoConnect() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("autoconnect")); + while (ii != innerMap.end() && ii.key() == QLatin1String("autoconnect")) { + return ii.value().toBool(); + ii++; + } + i++; + } + return true; //default networkmanager is autoconnect +} + +quint64 QNetworkManagerSettingsConnection::getTimestamp() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("timestamp")); + while (ii != innerMap.end() && ii.key() == QLatin1String("timestamp")) { + return ii.value().toUInt(); + ii++; + } + i++; + } + return 0; +} + +QString QNetworkManagerSettingsConnection::getId() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("id")); + while (ii != innerMap.end() && ii.key() == QLatin1String("id")) { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getUuid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("uuid")); + while (ii != innerMap.end() && ii.key() == QLatin1String("uuid")) { + return ii.value().toString(); + ii++; + } + i++; + } + // is no uuid, return the connection path + return d->connectionInterface->path(); +} + +QString QNetworkManagerSettingsConnection::getSsid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("ssid")); + while (ii != innerMap.end() && ii.key() == QLatin1String("ssid")) { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getMacAddress() +{ + if(getType() == DEVICE_TYPE_802_3_ETHERNET) { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-3-ethernet")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("802-3-ethernet")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("mac-address")); + while (ii != innerMap.end() && ii.key() == QLatin1String("mac-address")) { + return ii.value().toString(); + ii++; + } + i++; + } + } + + else if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("mac-address")); + while (ii != innerMap.end() && ii.key() == QLatin1String("mac-address")) { + return ii.value().toString(); + ii++; + } + i++; + } + } + return QString(); +} + +QStringList QNetworkManagerSettingsConnection::getSeenBssids() +{ + if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find(QLatin1String("seen-bssids")); + while (ii != innerMap.end() && ii.key() == QLatin1String("seen-bssids")) { + return ii.value().toStringList(); + ii++; + } + i++; + } + } + return QStringList(); +} + +class QNetworkManagerConnectionActivePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent) +{ + d = new QNetworkManagerConnectionActivePrivate(); + d->path = activeConnectionObjectPath; + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettingsConnection"; + return; + } + d->valid = true; +} + +QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerConnectionActive::isValid() +{ + return d->valid; +} + +bool QNetworkManagerConnectionActive::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper(this); + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), + QLatin1String("PropertiesChanged"), + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerConnectionActive::serviceName() const +{ + return d->connectionInterface->property("ServiceName").toString(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::connection() const +{ + QVariant prop = d->connectionInterface->property("Connection"); + return prop.value(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const +{ + QVariant prop = d->connectionInterface->property("SpecificObject"); + return prop.value(); +} + +QList QNetworkManagerConnectionActive::devices() const +{ + QVariant prop = d->connectionInterface->property("Devices"); + return prop.value >(); +} + +quint32 QNetworkManagerConnectionActive::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +bool QNetworkManagerConnectionActive::defaultRoute() const +{ + return d->connectionInterface->property("Default").toBool(); +} + +class QNetworkManagerIp4ConfigPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) +{ + d = new QNetworkManagerIp4ConfigPrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_IP4_CONFIG), + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerIp4Config"; + return; + } + d->valid = true; +} + +QNetworkManagerIp4Config::~QNetworkManagerIp4Config() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerIp4Config::isValid() +{ + return d->valid; +} + +QStringList QNetworkManagerIp4Config::domains() const +{ + return d->connectionInterface->property("Domains").toStringList(); +} + +#include "moc_qnetworkmanagerservice_p.cpp" + +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworkmanagerservice_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworkmanagerservice_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,438 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKMANAGERSERVICE_H +#define QNETWORKMANAGERSERVICE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include +#include "qnmdbushelper_p.h" + +#ifndef NETWORK_MANAGER_H +typedef enum NMDeviceType +{ + DEVICE_TYPE_UNKNOWN = 0, + DEVICE_TYPE_802_3_ETHERNET, + DEVICE_TYPE_802_11_WIRELESS, + DEVICE_TYPE_GSM, + DEVICE_TYPE_CDMA +} NMDeviceType; + +typedef enum +{ + NM_DEVICE_STATE_UNKNOWN = 0, + NM_DEVICE_STATE_UNMANAGED, + NM_DEVICE_STATE_UNAVAILABLE, + NM_DEVICE_STATE_DISCONNECTED, + NM_DEVICE_STATE_PREPARE, + NM_DEVICE_STATE_CONFIG, + NM_DEVICE_STATE_NEED_AUTH, + NM_DEVICE_STATE_IP_CONFIG, + NM_DEVICE_STATE_ACTIVATED, + NM_DEVICE_STATE_FAILED +} NMDeviceState; + +#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager" + +#define NM_DBUS_PATH "/org/freedesktop/NetworkManager" +#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager" +#define NM_DBUS_INTERFACE_DEVICE NM_DBUS_INTERFACE ".Device" +#define NM_DBUS_INTERFACE_DEVICE_WIRED NM_DBUS_INTERFACE_DEVICE ".Wired" +#define NM_DBUS_INTERFACE_DEVICE_WIRELESS NM_DBUS_INTERFACE_DEVICE ".Wireless" +#define NM_DBUS_PATH_ACCESS_POINT NM_DBUS_PATH "/AccessPoint" +#define NM_DBUS_INTERFACE_ACCESS_POINT NM_DBUS_INTERFACE ".AccessPoint" + +#define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManagerSettings" + +#define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManagerSettings.Connection" +#define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManagerSettings" +#define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active" +#define NM_DBUS_INTERFACE_IP4_CONFIG NM_DBUS_INTERFACE ".IP4Config" + +#define NM_DBUS_SERVICE_USER_SETTINGS "org.freedesktop.NetworkManagerUserSettings" +#define NM_DBUS_SERVICE_SYSTEM_SETTINGS "org.freedesktop.NetworkManagerSystemSettings" + +#define NM_802_11_AP_FLAGS_NONE 0x00000000 +#define NM_802_11_AP_FLAGS_PRIVACY 0x00000001 +#endif + +QTM_BEGIN_NAMESPACE +typedef QMap< QString, QMap > QNmSettingsMap; +typedef QList ServerThing; +QTM_END_NAMESPACE + + +Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QNmSettingsMap)) +Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(ServerThing)) + +QTM_BEGIN_NAMESPACE + +class QNetworkManagerInterfacePrivate; +class QNetworkManagerInterface : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterface(QObject *parent = 0); + ~QNetworkManagerInterface(); + + QList getDevices() const; + void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject); + void deactivateConnection(QDBusObjectPath connectionPath) const; + + QDBusObjectPath path() const; + QDBusInterface *connectionInterface() const; + + bool wirelessEnabled() const; + bool wirelessHardwareEnabled() const; + QList activeConnections() const; + quint32 state(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void deviceAdded(QDBusObjectPath); + void deviceRemoved(QDBusObjectPath); + void propertiesChanged( const QString &, QMap); + void stateChanged(const QString&, quint32); + void activationFinished(QDBusPendingCallWatcher*); + +private Q_SLOTS: +private: + QNetworkManagerInterfacePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; + +class QNetworkManagerInterfaceAccessPointPrivate; +class QNetworkManagerInterfaceAccessPoint : public QObject +{ + Q_OBJECT + +public: + + enum DeviceState { + Unknown = 0, + Unmanaged, + Unavailable, + Disconnected, + Prepare, + Config, + NeedAuthentication, + IpConfig, + Activated, + Failed + }; + + enum ApFlag { + ApNone = 0x0, + Privacy = 0x1 + }; + + Q_DECLARE_FLAGS(ApFlags, ApFlag); + + enum ApSecurityFlag { + ApSecurityNone = 0x0, + PairWep40 = 0x1, + PairWep104 = 0x2, + PairTkip = 0x4, + PairCcmp = 0x8, + GroupWep40 = 0x10, + GroupWep104 = 0x20, + GroupTkip = 0x40, + GroupCcmp = 0x80, + KeyPsk = 0x100, + Key8021x = 0x200 + }; + + Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag); + + QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerInterfaceAccessPoint(); + + QDBusInterface *connectionInterface() const; + + quint32 flags() const; + quint32 wpaFlags() const; + quint32 rsnFlags() const; + QString ssid() const; + quint32 frequency() const; + QString hwAddress() const; + quint32 mode() const; + quint32 maxBitrate() const; + quint32 strength() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged(QMap ); + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerInterfaceAccessPointPrivate *d; + QNmDBusHelper *nmDBusHelper; + +}; + +class QNetworkManagerInterfaceDevicePrivate; +class QNetworkManagerInterfaceDevice : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent = 0); + ~QNetworkManagerInterfaceDevice(); + + QString udi() const; + QNetworkInterface networkInterface() const; + QDBusInterface *connectionInterface() const; + quint32 ip4Address() const; + quint32 state() const; + quint32 deviceType() const; + + QDBusObjectPath ip4config() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void stateChanged(const QString &, quint32); + +private: + QNetworkManagerInterfaceDevicePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; + +class QNetworkManagerInterfaceDeviceWiredPrivate; +class QNetworkManagerInterfaceDeviceWired : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWired(); + + QDBusInterface *connectionInterface() const; + QString hwAddress() const; + quint32 speed() const; + bool carrier() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerInterfaceDeviceWiredPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; + +class QNetworkManagerInterfaceDeviceWirelessPrivate; +class QNetworkManagerInterfaceDeviceWireless : public QObject +{ + Q_OBJECT + +public: + + enum DeviceCapability { + None = 0x0, + Wep40 = 0x1, + Wep104 = 0x2, + Tkip = 0x4, + Ccmp = 0x8, + Wpa = 0x10, + Rsn = 0x20 + }; + + QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWireless(); + + QDBusObjectPath path() const; + QList getAccessPoints(); + QDBusInterface *connectionInterface() const; + + QString hwAddress() const; + quint32 mode() const; + quint32 bitrate() const; + QDBusObjectPath activeAccessPoint() const; + quint32 wirelessCapabilities() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap); + void accessPointAdded(const QString &,QDBusObjectPath); + void accessPointRemoved(const QString &,QDBusObjectPath); +private: + QNetworkManagerInterfaceDeviceWirelessPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; + +class QNetworkManagerSettingsPrivate; +class QNetworkManagerSettings : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0); + ~QNetworkManagerSettings(); + + QDBusInterface *connectionInterface() const; + QList listConnections(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void newConnection(QDBusObjectPath); +private: + QNetworkManagerSettingsPrivate *d; +}; + +class QNetworkManagerSettingsConnectionPrivate; +class QNetworkManagerSettingsConnection : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0); + ~QNetworkManagerSettingsConnection(); + + QDBusInterface *connectionInterface() const; + QNmSettingsMap getSettings(); + bool setConnections(); + NMDeviceType getType(); + bool isAutoConnect(); + quint64 getTimestamp(); + QString getId(); + QString getUuid(); + QString getSsid(); + QString getMacAddress(); + QStringList getSeenBssids(); + bool isValid(); + +Q_SIGNALS: + + void updated(QMap< QString, QMap > s); + void removed(const QString &); + +private: + QNmDBusHelper *nmDBusHelper; + QNetworkManagerSettingsConnectionPrivate *d; +}; + +class QNetworkManagerConnectionActivePrivate; +class QNetworkManagerConnectionActive : public QObject +{ + Q_OBJECT + +public: + + enum ActiveConnectionState { + Unknown = 0, + Activating = 1, + Activated = 2 + }; + + QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0); + ~ QNetworkManagerConnectionActive(); + + QDBusInterface *connectionInterface() const; + QString serviceName() const; + QDBusObjectPath connection() const; + QDBusObjectPath specificObject() const; + QList devices() const; + quint32 state() const; + bool defaultRoute() const; + bool setConnections(); + bool isValid(); + + +Q_SIGNALS: + void propertiesChanged(QList); + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerConnectionActivePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; + +class QNetworkManagerIp4ConfigPrivate; +class QNetworkManagerIp4Config : public QObject +{ + Q_OBJECT + +public: + QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerIp4Config(); + + QStringList domains() const; + bool isValid(); + + private: + QNetworkManagerIp4ConfigPrivate *d; +}; +QTM_END_NAMESPACE + + +#endif //QNETWORKMANAGERSERVICE_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksession.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksession.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,711 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "qnetworksession.h" + +#ifdef Q_OS_SYMBIAN +#include "qnetworksession_s60_p.h" +#elif Q_WS_MAEMO_6 +#include "qnetworksession_maemo_p.h" +#else +#include "qnetworksession_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +/*! + \class QNetworkSession + + \brief The QNetworkSession class provides control over the system's access points + and enables session management for cases when multiple clients access the same access point. + + \inmodule QtNetwork + \ingroup bearer + + A QNetworkSession enables control over the system's network interfaces. The session's configuration + parameter are determined via the QNetworkConfiguration object to which it is bound. Depending on the + type of the session (single access point or service network) a session may be linked to one or more + network interfaces. By means of \l{open()}{opening} and \l{close()}{closing} of network sessions + a developer can start and stop the systems network interfaces. If the configuration represents + multiple access points (see \l QNetworkConfiguration::ServiceNetwork) more advanced features such as roaming may be supported. + + QNetworkSession supports session management within the same process and depending on the platform's + capabilities may support out-of-process sessions. If the same + network configuration is used by multiple open sessions the underlying network interface is only terminated once + the last session has been closed. + + \section1 Roaming + + Applications may connect to the preferredConfigurationChanged() signal in order to + receive notifications when a more suitable access point becomes available. + In response to this signal the application must either initiate the roaming via migrate() + or ignore() the new access point. Once the session has roamed the + newConfigurationActivated() signal is emitted. The application may now test the + carrier and must either accept() or reject() it. The session will return to the previous + access point if the roaming was rejected. The subsequent state diagram depicts the required + state transitions. + + \image roaming-states.png + + Some platforms may distinguish forced roaming and application level roaming (ALR). + ALR implies that the application controls (via migrate(), ignore(), accept() and reject()) + whether a network session can roam from one access point to the next. Such control is useful + if the application maintains stateful socket connections and wants to control the transition from + one interface to the next. Forced roaming implies that the system automatically roams to the next network without + consulting the application. This has the advantage that the application can make use of roaming features + without actually being aware of it. It is expected that the application detects that the underlying + socket is broken and automatically reconnects via the new network link. + + If the platform supports both modes of roaming, an application indicates its preference + by connecting to the preferredConfigurationChanged() signal. Connecting to this signal means that + the application wants to take control over the roaming behavior and therefore implies application + level roaming. If the client does not connect to the preferredConfigurationChanged(), forced roaming + is used. If forced roaming is not supported the network session will not roam by default. + + Some applications may want to suppress any form of roaming altogether. Possible use cases may be + high priority downloads or remote services which cannot handle a roaming enabled client. Clients + can suppress roaming by connecting to the preferredConfigurationChanged() signal and answer each + signal emission with ignore(). + + \sa QNetworkConfiguration, QNetworkConfigurationManager +*/ + +/*! + \enum QNetworkSession::State + + This enum describes the connectivity state of the session. If the session is based on a + single access point configuration the state of the session is the same as the state of the + associated network interface. + + \value Invalid The session is invalid due to an invalid configuration. This may + happen due to a removed access point or a configuration that was + invalid to begin with. + \value NotAvailable The session is based on a defined but not yet discovered QNetworkConfiguration + (see \l QNetworkConfiguration::StateFlag). + \value Connecting The network session is being established. + \value Connected The network session is connected. If the current process wishes to use this session + it has to register its interest by calling open(). A network session + is considered to be ready for socket operations if it isOpen() and connected. + \value Closing The network session is in the process of being shut down. + \value Disconnected The network session is not connected. The associated QNetworkConfiguration + has the state QNetworkConfiguration::Discovered. + \value Roaming The network session is roaming from one access point to another + access point. +*/ + +/*! + \enum QNetworkSession::SessionError + + This enum describes the session errors that can occur. + + \value UnknownSessionError An unidentified error occurred. + \value SessionAbortedError The session was aborted by the user or system. + \value RoamingError The session cannot roam to a new configuration. + \value OperationNotSupportedError The operation is not supported for current configuration. + \value InvalidConfigurationError The operation cannot currently be performed for the + current configuration. +*/ + +/*! + \fn void QNetworkSession::stateChanged(QNetworkSession::State state) + + This signal is emitted whenever the state of the network session changes. + The \a state parameter is the new state. + + \sa state() +*/ + +/*! + \fn void QNetworkSession::error(QNetworkSession::SessionError error) + + This signal is emitted after an error occurred. The \a error parameter + describes the error that occurred. + + \sa error(), errorString() +*/ + +/*! + \fn void QNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless) + + This signal is emitted when the preferred configuration/access point for the + session changes. Only sessions which are based on service network configurations + may emit this signal. \a config can be used to determine access point specific + details such as proxy settings and \a isSeamless indicates whether roaming will + break the sessions IP address. + + As a consequence to this signal the application must either start the roaming process + by calling migrate() or choose to ignore() the new access point. + + If the roaming process is non-seamless the IP address will change which means that + a socket becomes invalid. However seamless mobility can ensure that the local IP address + does not change. This is achieved by using a virtual IP address which is bound to the actual + link address. During the roaming process the virtual address is attached to the new link + address. + + Some platforms may support the concept of Forced Roaming and Application Level Roaming (ALR). + Forced roaming implies that the platform may simply roam to a new configuration without + consulting applications. It is up to the application to detect the link layer loss and reestablish + its sockets. In contrast ALR provides the opportunity to prevent the system from roaming. + If this session is based on a configuration that supports roaming the application can choose + whether it wants to be consulted (ALR use case) by connecting to this signal. For as long as this signal + connection remains the session remains registered as a roaming stakeholder; otherwise roaming will + be enforced by the platform. + + \sa migrate(), ignore(), QNetworkConfiguration::isRoamingAvailable() +*/ + +/*! + \fn void QNetworkSession::newConfigurationActivated() + + This signal is emitted once the session has roamed to the new access point. + The application may reopen its socket and test the suitability of the new network link. + Subsequently it must either accept() or reject() the new access point. + + \sa accept(), reject() +*/ + +/*! + \fn void QNetworkSession::opened() + + This signal is emitted when the network session has been opened. + + The underlying network interface will not be shut down as long as the session remains open. + Note that this feature is dependent on \l{QNetworkConfigurationManager::SystemSessionSupport}{system wide session support}. +*/ + +/*! + \fn void QNetworkSession::closed() + + This signal is emitted when the network session has been closed. +*/ + +/*! + Constructs a session based on \a connectionConfig with the given \a parent. + + \sa QNetworkConfiguration +*/ +QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent) + : QObject(parent) +{ + d = new QNetworkSessionPrivate; + d->q = this; + d->publicConfig = connectionConfig; + d->syncStateWithInterface(); + QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), + this, SIGNAL(opened())); +} + +/*! + Frees the resources associated with the QNetworkSession object. +*/ +QNetworkSession::~QNetworkSession() +{ + delete d; +} + +/*! + Creates an open session which increases the session counter on the underlying network interface. + The system will not terminate a network interface until the session reference counter reaches zero. + Therefore an open session allows an application to register its use of the interface. + + As a result of calling open() the interface will be started if it is not connected/up yet. + Some platforms may not provide support for out-of-process sessions. On such platforms the session + counter ignores any sessions held by another process. The platform capabilities can be + detected via QNetworkConfigurationManager::capabilities(). + + Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired + by connecting to the stateChanged(), opened() or error() signals. + + It is not a requirement to open a session in order to monitor the underlying network interface. + + \sa close(), stop(), isOpen() +*/ +void QNetworkSession::open() +{ + d->open(); +} + +/*! + Waits until the session has been opened, up to \a msecs milliseconds. If the session has been opened, this + function returns true; otherwise it returns false. In the case where it returns false, you can call error() + to determine the cause of the error. + + The following example waits up to one second for the session to be opened: + + \code + session->open(); + if (session->waitForOpened(1000)) + qDebug("Open!"); + \endcode + + If \a msecs is -1, this function will not time out. + + \sa open(), error() +*/ +bool QNetworkSession::waitForOpened(int msecs) +{ + if (d->isOpen) + return true; + + if (d->state != Connecting) + return false; + + QEventLoop* loop = new QEventLoop(this); + QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), + loop, SLOT(quit())); + QObject::connect(this, SIGNAL(error(QNetworkSession::SessionError)), + loop, SLOT(quit())); + + //final call + if (msecs>=0) + QTimer::singleShot(msecs, loop, SLOT(quit())); + + loop->exec(); + loop->disconnect(); + loop->deleteLater(); + + return d->isOpen; +} + +/*! + Decreases the session counter on the associated network configuration. If the session counter reaches zero + the active network interface is shut down. This also means that state() will only change from \l Connected to + \l Disconnected if the current session was the last open session. + + If the platform does not support out-of-process sessions calling this function does not stop the + interface. In this case \l{stop()} has to be used to force a shut down. + The platform capabilities can be detected via QNetworkConfigurationManager::capabilities(). + + Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired + by connecting to the stateChanged(), opened() or error() signals. + + \sa open(), stop(), isOpen() +*/ +void QNetworkSession::close() +{ + d->close(); +} + +/*! + Invalidates all open sessions against the network interface and therefore stops the + underlying network interface. This function always changes the session's state() flag to + \l Disconnected. + + On Symbian platform, a 'NetworkControl' capability is required for + full interface-level stop (without the capability, only the current session is stopped). + + \sa open(), close() +*/ +void QNetworkSession::stop() +{ + d->stop(); +} + +/*! + Returns the QNetworkConfiguration that this network session object is based on. + + \sa QNetworkConfiguration +*/ +QNetworkConfiguration QNetworkSession::configuration() const +{ + return d->publicConfig; +} + +/* + Returns the type of bearer currently used by this session. The string is not translated and + therefore can not be shown to the user. The subsequent table presents the currently known + bearer types: + + \table + \header + \o Value + \o Description + \row + \o Unknown + \o The session is based on an unknown or unspecified bearer type. + \row + \o Ethernet + \o The session is based on Ethernet. + \row + \o WLAN + \o The session is based on Wireless LAN. + \row + \o 2G + \o The session uses CSD, GPRS, HSCSD, EDGE or cdmaOne. + \row + \o CDMA2000 + \o The session uses CDMA. + \row + \o WCDMA + \o The session uses W-CDMA/UMTS. + \row + \o HSPA + \o The session uses High Speed Packet Access. + \row + \o Bluetooth + \o The session uses Bluetooth. + \row + \o WiMAX + \o The session uses WiMAX. + \endtable + + If the session is based on a network configuration of type + \l QNetworkConfiguration::ServiceNetwork the type of the preferred or currently + active configuration is returned. Therefore the bearer type may change + over time. + + This function returns an empty string if this session is based on an invalid configuration, or + a network configuration of type \l QNetworkConfiguration::ServiceNetwork with no + \l {QNetworkConfiguration::children()}{children}. +*/ +/*QString QNetworkSession::bearerName() const +{ + return d->bearerName(); +}*/ + +/*! + Returns the network interface that is used by this session. + + This function only returns a valid QNetworkInterface when this session is \l Connected. + + The returned interface may change as a result of a roaming process. + + Note: this function does not work in Symbian emulator due to the way the + connectivity is emulated on Windows. + + \sa state() +*/ +QNetworkInterface QNetworkSession::interface() const +{ + return d->currentInterface(); +} + +/*! + Returns true if this session is open. If the number of all open sessions is greater than + zero the underlying network interface will remain connected/up. + + The session can be controlled via open() and close(). +*/ +bool QNetworkSession::isOpen() const +{ + return d->isOpen; +} + +/*! + Returns the state of the session. + + If the session is based on a single access point configuration the state of the + session is the same as the state of the associated network interface. Therefore + a network session object can be used to monitor network interfaces. + + A \l QNetworkConfiguration::ServiceNetwork based session summarizes the state of all its children + and therefore returns the \l Connected state if at least one of the service network's + \l {QNetworkConfiguration::children()}{children()} configurations is active. + + Note that it is not required to hold an open session in order to obtain the network interface state. + A connected but closed session may be used to monitor network interfaces whereas an open and connected + session object may prevent the network interface from being shut down. + + \sa error(), stateChanged() +*/ +QNetworkSession::State QNetworkSession::state() const +{ + return d->state; +} + +/*! + Returns the type of error that last occurred. + + \sa state(), errorString() +*/ +QNetworkSession::SessionError QNetworkSession::error() const +{ + return d->error(); +} + +/*! + Returns a human-readable description of the last device error that + occurred. + + \sa error() +*/ +QString QNetworkSession::errorString() const +{ + return d->errorString(); +} + +/*! + Returns the value for property \a key. + + A network session can have properties attached which may describe the session in more details. + This function can be used to gain access to those properties. + + The following property keys are guaranteed to be specified on all platforms: + + \table + \header + \o Key \o Description + \row + \o ActiveConfiguration + \o If the session \l isOpen() this property returns the identifier of the + QNetworkConfiguration that is used by this session; otherwise an empty string. + + The main purpose of this key is to determine which Internet access point is used + if the session is based on a \l{QNetworkConfiguration::ServiceNetwork}{ServiceNetwork}. + The following code snippet highlights the difference: + \code + QNetworkConfigurationManager mgr; + QNetworkConfiguration ap = mgr.defaultConfiguration(); + QNetworkSession* session = new QNetworkSession(ap); + ... //code activates session + + QString ident = session->sessionProperty("ActiveConfiguration").toString(); + if ( ap.type() == QNetworkConfiguration::ServiceNetwork ) { + Q_ASSERT( ap.identifier() != ident ); + Q_ASSERT( ap.children().contains( mgr.configurationFromIdentifier(ident) ) ); + } else if ( ap.type() == QNetworkConfiguration::InternetAccessPoint ) { + Q_ASSERT( ap.identifier() == ident ); + } + \endcode + \row + \o UserChoiceConfiguration + \o If the session \l isOpen() and is bound to a QNetworkConfiguration of type + UserChoice, this property returns the identifier of the QNetworkConfiguration that the + configuration resolved to when \l open() was called; otherwise an empty string. + + The purpose of this key is to determine the real QNetworkConfiguration that the + session is using. This key is different to \i ActiveConfiguration in that + this key may return an identifier for either a + \l {QNetworkConfiguration::ServiceNetwork}{service network} or a + \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations + whereas \i ActiveConfiguration always returns identifiers to + \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations. + \row + \o ConnectInBackground + \o Setting this property to \i true before calling \l open() implies that the connection attempt + is made but if no connection can be established, the user is not connsulted and asked to select + a suitable connection. This property is not set by default and support for it depends on the platform. + \endtable +*/ +QVariant QNetworkSession::sessionProperty(const QString& key) const +{ + if (!d->publicConfig.isValid()) + return QVariant(); + + if (key == "ActiveConfiguration") { + if (!d->isOpen) + return QString(); + else + return d->activeConfig.identifier(); + } + + if (key == "UserChoiceConfiguration") { + if (!d->isOpen || d->publicConfig.type() != QNetworkConfiguration::UserChoice) + return QString(); + + if (d->serviceConfig.isValid()) + return d->serviceConfig.identifier(); + else + return d->activeConfig.identifier(); + } + + return d->sessionProperty(key); +} + +/*! + Sets the property \a value on the session. The property is identified using + \a key. Removing an already set property can be achieved by passing an + invalid QVariant. + + Note that the \i UserChoiceConfiguration and \i ActiveConfiguration + properties are read only and cannot be changed using this method. +*/ +void QNetworkSession::setSessionProperty(const QString& key, const QVariant& value) +{ + if (key == "ActiveConfiguration" + || key == "UserChoiceConfiguration") + return; + + d->setSessionProperty(key, value); +} + +/*! + Instructs the session to roam to the new access point. The old access point remains active + until the application calls accept(). + + The newConfigurationActivated() signal is emitted once roaming has been completed. + + \sa accept() +*/ +void QNetworkSession::migrate() +{ + d->migrate(); +} + +/*! + This function indicates that the application does not wish to roam the session. + + \sa migrate() +*/ +void QNetworkSession::ignore() +{ + // Needed on at least Symbian platform: the roaming must be explicitly + // ignore()'d or migrate()'d + d->ignore(); +} + +/*! + Instructs the session to permanently accept the new access point. Once this function + has been called the session may not return to the old access point. + + The old access point may be closed in the process if there are no other network sessions for it. + Therefore any open socket that still uses the old access point + may become unusable and should be closed before completing the migration. +*/ +void QNetworkSession::accept() +{ + d->accept(); +} + +/*! + The new access point is not suitable for the application. By calling this function the + session returns to the previous access point/configuration. This action may invalidate + any socket that has been created via the not desired access point. + + \sa accept() +*/ +void QNetworkSession::reject() +{ + d->reject(); +} + + +/*! + Returns the amount of data sent in bytes; otherwise 0. + + This field value includes the usage across all open network + sessions which use the same network interface. + + If the session is based on a service network configuration the number of + sent bytes across all active member configurations are returned. + + This function may not always be supported on all platforms and returns + 0. The platform capability can be detected via QNetworkConfigurationManager::DataStatistics. +*/ +quint64 QNetworkSession::bytesWritten() const +{ + return d->bytesWritten(); +} + +/*! + Returns the amount of data received in bytes; otherwise 0. + + This field value includes the usage across all open network + sessions which use the same network interface. + + If the session is based on a service network configuration the number of + sent bytes across all active member configurations are returned. + + This function may not always be supported on all platforms and returns + 0. The platform capability can be detected via QNetworkConfigurationManager::DataStatistics. +*/ +quint64 QNetworkSession::bytesReceived() const +{ + return d->bytesReceived(); +} + +/*! + Returns the number of seconds that the session has been active. +*/ +quint64 QNetworkSession::activeTime() const +{ + return d->activeTime(); +} + +/*! + \internal + + This function is required to detect whether the client wants to control + the roaming process. If he connects to preferredConfigurationChanged() signal + he intends to influence it. Otherwise QNetworkSession always roams + without registering this session as a stakeholder in the roaming process. + + For more details check the Forced vs ALR roaming section in the QNetworkSession + class description. +*/ +void QNetworkSession::connectNotify(const char *signal) +{ + QObject::connectNotify(signal); + //check for preferredConfigurationChanged() signal connect notification + //This is not required on all platforms +#ifdef Q_OS_SYMBIAN + if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) { + d->setALREnabled(true); + } +#endif +} + +/*! + \internal + + This function is called when the client disconnects from the preferredConfigurationChanged() + signal. + + \sa connectNotify() +*/ +void QNetworkSession::disconnectNotify(const char *signal) +{ + QObject::disconnectNotify(signal); + //check for preferredConfigurationChanged() signal disconnect notification + //This is not required on all platforms +#ifdef Q_OS_SYMBIAN + if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) { + d->setALREnabled(false); + } +#endif +} + +#include "moc_qnetworksession.cpp" + +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksession.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksession.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKSESSION_H +#define QNETWORKSESSION_H + +#include "qmobilityglobal.h" + +#include +#include +#include +#include +#include +#include "qnetworkconfiguration.h" + + +QT_BEGIN_HEADER + +QTM_BEGIN_NAMESPACE + +class QNetworkSessionPrivate; +class Q_BEARER_EXPORT QNetworkSession : public QObject +{ + Q_OBJECT +public: + enum State { + Invalid = 0, + NotAvailable, + Connecting, + Connected, + Closing, + Disconnected, + Roaming + }; + + enum SessionError { + UnknownSessionError = 0, + SessionAbortedError, + RoamingError, + OperationNotSupportedError, + InvalidConfigurationError + }; + + QNetworkSession(const QNetworkConfiguration& connConfig, QObject* parent =0); + virtual ~QNetworkSession(); + + bool isOpen() const; + QNetworkConfiguration configuration() const; + QNetworkInterface interface() const; + + State state() const; + SessionError error() const; + QString errorString() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + + bool waitForOpened(int msecs = 30000); + +public Q_SLOTS: + void open(); + void close(); + void stop(); + + //roaming related slots + void migrate(); + void ignore(); + void accept(); + void reject(); + + +Q_SIGNALS: + void stateChanged(QNetworkSession::State); + void opened(); + void closed(); + void error(QNetworkSession::SessionError); + void preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless); + void newConfigurationActivated(); + +protected: + virtual void connectNotify(const char *signal); + virtual void disconnectNotify(const char *signal); + +private: + QNetworkSessionPrivate* d; + friend class QNetworkSessionPrivate; + }; + +QTM_END_NAMESPACE + +QT_END_HEADER + +#endif //QNETWORKSESSION_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksession_maemo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksession_maemo.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,1192 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "qnetworksession_maemo_p.h" +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +static QHash properties; + +static QString get_network_interface(); +static DBusConnection *dbus_connection; +static DBusHandlerResult signal_handler(DBusConnection *connection, + DBusMessage *message, + void *user_data); + +#define ICD_DBUS_MATCH "type='signal'," \ + "interface='" ICD_DBUS_INTERFACE "'," \ + "path='" ICD_DBUS_PATH "'" + + +static inline DBusConnection *get_dbus_conn(DBusError *error) +{ + DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, error); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Listening to bus" << dbus_bus_get_unique_name(conn); +#endif + + return conn; +} + + +/* Helper class that monitors the Icd status messages and + * can change the IAP status accordingly. This is a singleton. + */ +class IcdListener : public QObject +{ + Q_OBJECT + +public: + IcdListener() : first_call(true) { } + friend DBusHandlerResult signal_handler(DBusConnection *connection, + DBusMessage *message, + void *user_data); + void setup(QNetworkSessionPrivate *d); + void cleanup(); + void cleanupSession(QNetworkSessionPrivate *ptr); + + enum IapConnectionStatus { + /* The IAP was connected */ + CONNECTED = 0, + /* The IAP was disconnected */ + DISCONNECTED, + /* The IAP is disconnecting */ + DISCONNECTING, + /* The IAP has a network address, but is not yet fully connected */ + NETWORK_UP + }; + +private: + void icdSignalReceived(QString&, QString&, QString&); + bool first_call; + QHash sessions; +}; + +Q_GLOBAL_STATIC(IcdListener, icdListener); + + +static DBusHandlerResult signal_handler(DBusConnection *, + DBusMessage *message, + void *user_data) +{ + if (dbus_message_is_signal(message, + ICD_DBUS_INTERFACE, + ICD_STATUS_CHANGED_SIG)) { + + IcdListener *icd = (IcdListener *)user_data; + DBusError error; + dbus_error_init(&error); + + char *iap_id = 0; + char *network_type = 0; + char *state = 0; + + if (dbus_message_get_args(message, &error, + DBUS_TYPE_STRING, &iap_id, + DBUS_TYPE_STRING, &network_type, + DBUS_TYPE_STRING, &state, + DBUS_TYPE_INVALID) == FALSE) { + qWarning() << QString("Failed to parse icd status signal: %1").arg(error.message); + } else { + QString _iap_id(iap_id); + QString _network_type(network_type); + QString _state(state); + + icd->icdSignalReceived(_iap_id, _network_type, _state); + } + + dbus_error_free(&error); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + + +void IcdListener::setup(QNetworkSessionPrivate *d) +{ + if (first_call) { + // We use the old Icd dbus interface like in ConIC + DBusError error; + dbus_error_init(&error); + + dbus_connection = get_dbus_conn(&error); + if (dbus_error_is_set(&error)) { + qWarning() << "Cannot get dbus connection."; + dbus_error_free(&error); + return; + } + + static struct DBusObjectPathVTable icd_vtable; + icd_vtable.message_function = signal_handler; + + dbus_bus_add_match(dbus_connection, ICD_DBUS_MATCH, &error); + if (dbus_error_is_set(&error)) { + qWarning() << "Cannot add match" << ICD_DBUS_MATCH; + dbus_error_free(&error); + return; + } + + if (dbus_connection_register_object_path(dbus_connection, + ICD_DBUS_PATH, + &icd_vtable, + (void*)this) == FALSE) { + qWarning() << "Cannot register dbus signal handler, interface"<< ICD_DBUS_INTERFACE << "path" << ICD_DBUS_PATH; + dbus_error_free(&error); + return; + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Listening" << ICD_STATUS_CHANGED_SIG << "signal from" << ICD_DBUS_SERVICE; +#endif + first_call = false; + dbus_error_free(&error); + } + + QString id = d->activeConfig.identifier(); + if (!sessions.contains(id)) { + QNetworkSessionPrivate *ptr = d; + sessions.insert(id, ptr); + } +} + + +void IcdListener::icdSignalReceived(QString& iap_id, +#ifdef BEARER_MANAGEMENT_DEBUG + QString& network_type, +#else + QString&, +#endif + QString& state) +{ + if (iap_id == OSSO_IAP_SCAN) // icd sends scan status signals which we will ignore + return; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Status received:" << iap_id << "type" << network_type << "state" << state; +#endif + + if (!sessions.contains(iap_id)) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "No session for IAP" << iap_id; +#endif + return; + } + + QNetworkSessionPrivate *session = sessions.value(iap_id); + QNetworkConfiguration ap_conf = session->manager.configurationFromIdentifier(iap_id); + if (!ap_conf.isValid()) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Unknown IAP" << iap_id; +#endif + return; + } + + IapConnectionStatus status; + + if (state == "IDLE") { + status = DISCONNECTED; + } else if (state == "CONNECTED") { + status = CONNECTED; + } else if (state == "NETWORKUP") { + status = NETWORK_UP; + } else { + //qDebug() << "Unknown state" << state; + return; + } + + if (status == DISCONNECTED) { + if (ap_conf.state() == QNetworkConfiguration::Active) { + /* The IAP was just disconnected by Icd */ + session->updateState(QNetworkSession::Disconnected); + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Got a network disconnect when in state" << ap_conf.state(); +#endif + } + } else if (status == CONNECTED) { + /* The IAP was just connected by Icd */ + session->updateState(QNetworkSession::Connected); + session->updateIdentifier(iap_id); + + if (session->publicConfig.identifier() == OSSO_IAP_ANY) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "connected when connecting to" << OSSO_IAP_ANY; +#endif + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "connected"; +#endif + } + } + + return; +} + + +void IcdListener::cleanup() +{ + if (!first_call) { + dbus_bus_remove_match(dbus_connection, ICD_DBUS_MATCH, NULL); + dbus_connection_unref(dbus_connection); + } +} + + +void IcdListener::cleanupSession(QNetworkSessionPrivate *ptr) +{ + if (ptr->publicConfig.type() == QNetworkConfiguration::UserChoice) + (void)sessions.take(ptr->activeConfig.identifier()); + else + (void)sessions.take(ptr->publicConfig.identifier()); +} + + +void QNetworkSessionPrivate::cleanupSession(void) +{ + icdListener()->cleanupSession(this); + + QObject::disconnect(q, SIGNAL(stateChanged(QNetworkSession::State)), this, SLOT(updateProxies(QNetworkSession::State))); +} + + +void QNetworkSessionPrivate::updateState(QNetworkSession::State newState) +{ + if( newState != state) { + state = newState; + + if (state == QNetworkSession::Disconnected) { + isOpen = false; + currentNetworkInterface.clear(); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + activeConfig.d->state = QNetworkConfiguration::Defined; + publicConfig.d->state = QNetworkConfiguration::Defined; + + } else if (state == QNetworkSession::Connected) { + isOpen = true; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + activeConfig.d->state = QNetworkConfiguration::Active; + activeConfig.d->type = QNetworkConfiguration::InternetAccessPoint; + } + publicConfig.d->state = QNetworkConfiguration::Active; + } + + emit q->stateChanged(newState); + } +} + + +void QNetworkSessionPrivate::updateIdentifier(QString &newId) +{ + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + activeConfig.d->network_attrs |= ICD_NW_ATTR_IAPNAME; + activeConfig.d->id = newId; + } else { + publicConfig.d->network_attrs |= ICD_NW_ATTR_IAPNAME; + if (publicConfig.d->id != newId) { + qWarning() << "Your config id changed from" << publicConfig.d->id << "to" << newId; + publicConfig.d->id = newId; + } + } +} + + +quint64 QNetworkSessionPrivate::getStatistics(bool sent) const +{ + /* This could be also implemented by using the Maemo::Icd::statistics() + * that gets the statistics data for a specific IAP. Change if + * necessary. + */ + Maemo::Icd icd; + QList stats_results; + quint64 counter_rx = 0, counter_tx = 0; + + if (!icd.statistics(stats_results)) { + return 0; + } + + foreach (Maemo::IcdStatisticsResult res, stats_results) { + if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) { + /* network_id is the IAP UUID */ + if (QString(res.params.network_id.data()) == activeConfig.identifier()) { + counter_tx = res.bytes_sent; + counter_rx = res.bytes_received; + } + } else { + /* We probably will never get to this branch */ + QNetworkConfigurationPrivate *d = activeConfig.d.data(); + if (res.params.network_id == d->network_id) { + counter_tx = res.bytes_sent; + counter_rx = res.bytes_received; + } + } + } + + if (sent) + return counter_tx; + else + return counter_rx; +} + + +quint64 QNetworkSessionPrivate::bytesWritten() const +{ + return getStatistics(true); +} + +quint64 QNetworkSessionPrivate::bytesReceived() const +{ + return getStatistics(false); +} + +quint64 QNetworkSessionPrivate::activeTime() const +{ + if (startTime.isNull()) { + return 0; + } + return startTime.secsTo(QDateTime::currentDateTime()); +} + + +QNetworkConfiguration& QNetworkSessionPrivate::copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy) +{ + if (deepCopy) { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QExplicitlySharedDataPointer ptr(cpPriv); + toConfig.d = ptr; + } + + toConfig.d->name = fromConfig.d->name; + toConfig.d->isValid = fromConfig.d->isValid; + // Note that we do not copy id field here as the publicConfig does + // not contain a valid IAP id. + toConfig.d->state = fromConfig.d->state; + toConfig.d->type = fromConfig.d->type; + toConfig.d->roamingSupported = fromConfig.d->roamingSupported; + toConfig.d->purpose = fromConfig.d->purpose; + toConfig.d->network_id = fromConfig.d->network_id; + toConfig.d->iap_type = fromConfig.d->iap_type; + toConfig.d->network_attrs = fromConfig.d->network_attrs; + toConfig.d->service_type = fromConfig.d->service_type; + toConfig.d->service_id = fromConfig.d->service_id; + toConfig.d->service_attrs = fromConfig.d->service_attrs; + toConfig.d->manager = fromConfig.d->manager; + + return toConfig; +} + + +/* This is called by QNetworkSession constructor and it updates the current + * state of the configuration. + */ +void QNetworkSessionPrivate::syncStateWithInterface() +{ + /* Start to listen Icd status messages. */ + icdListener()->setup(this); + + /* Initially we are not active although the configuration might be in + * connected state. + */ + isOpen = false; + opened = false; + + QObject::connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); + + if (publicConfig.d.data()) { + QNetworkConfigurationManagerPrivate* mgr = (QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager; + if (mgr) { + QObject::connect(mgr, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); + } else { + qWarning()<<"Manager object not set when trying to connect configurationChanged signal. Your configuration object is not correctly setup, did you remember to call manager.updateConfigurations() before creating session object?"; + state = QNetworkSession::Invalid; + lastError = QNetworkSession::UnknownSessionError; + return; + } + } + + QObject::connect(q, SIGNAL(stateChanged(QNetworkSession::State)), this, SLOT(updateProxies(QNetworkSession::State))); + + state = QNetworkSession::Invalid; + lastError = QNetworkSession::UnknownSessionError; + + switch (publicConfig.type()) { + case QNetworkConfiguration::InternetAccessPoint: + activeConfig = publicConfig; + break; + case QNetworkConfiguration::ServiceNetwork: + serviceConfig = publicConfig; + break; + case QNetworkConfiguration::UserChoice: + // active config will contain correct data after open() has succeeded + copyConfig(publicConfig, activeConfig); + + /* We create new configuration that holds the actual configuration + * returned by icd. This way publicConfig still contains the + * original user specified configuration. + * + * Note that the new activeConfig configuration is not inserted + * to configurationManager as manager class will get the newly + * connected configuration from gconf when the IAP is saved. + * This configuration manager update is done by IapMonitor class. + * If the ANY connection fails in open(), then the configuration + * data is not saved to gconf and will not be added to + * configuration manager IAP list. + */ +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug()<<"New configuration created for" << publicConfig.identifier(); +#endif + break; + default: + /* Invalid configuration, no point continuing */ + return; + } + + if (!activeConfig.isValid()) + return; + + /* Get the initial state from icd */ + Maemo::Icd icd; + QList state_results; + + /* Update the active config from first connection, this is ok as icd + * supports only one connection anyway. + */ + if (icd.state(state_results) && !state_results.isEmpty()) { + + /* If we did not get full state back, then we are not + * connected and can skip the next part. + */ + if (!(state_results.first().params.network_attrs == 0 && + state_results.first().params.network_id.isEmpty())) { + + /* If we try to connect to specific IAP and we get results back + * that tell the icd is actually connected to another IAP, + * then do not update current state etc. + */ + if (publicConfig.type() == QNetworkConfiguration::UserChoice || + publicConfig.d->id == state_results.first().params.network_id) { + + switch (state_results.first().state) { + case ICD_STATE_DISCONNECTED: + state = QNetworkSession::Disconnected; + if (activeConfig.d.data()) + activeConfig.d->isValid = true; + break; + case ICD_STATE_CONNECTING: + state = QNetworkSession::Connecting; + if (activeConfig.d.data()) + activeConfig.d->isValid = true; + break; + case ICD_STATE_CONNECTED: + { + if (!state_results.first().error.isEmpty()) + break; + + const QString id = state_results.first().params.network_id; + + QNetworkConfigurationManagerPrivate *mgr = (QNetworkConfigurationManagerPrivate*)activeConfig.d.data()->manager; + if (mgr->accessPointConfigurations.contains(id)) { + //we don't want the copied data if the config is already known by the manager + //just reuse it so that existing references to the old data get the same update + QExplicitlySharedDataPointer priv = mgr->accessPointConfigurations.value(activeConfig.d->id); + activeConfig.d = priv; + } + + + state = QNetworkSession::Connected; + activeConfig.d->network_id = state_results.first().params.network_id; + activeConfig.d->id = activeConfig.d->network_id; + activeConfig.d->network_attrs = state_results.first().params.network_attrs; + activeConfig.d->iap_type = state_results.first().params.network_type; + activeConfig.d->service_type = state_results.first().params.service_type; + activeConfig.d->service_id = state_results.first().params.service_id; + activeConfig.d->service_attrs = state_results.first().params.service_attrs; + activeConfig.d->type = QNetworkConfiguration::InternetAccessPoint; + activeConfig.d->state = QNetworkConfiguration::Active; + activeConfig.d->isValid = true; + currentNetworkInterface = get_network_interface(); + + Maemo::IAPConf iap_name(activeConfig.d->id); + QString name_value = iap_name.value("name").toString(); + if (!name_value.isEmpty()) + activeConfig.d->name = name_value; + else + activeConfig.d->name = activeConfig.d->id; + + + // Add the new active configuration to manager or update the old config + mgr = (QNetworkConfigurationManagerPrivate*)activeConfig.d.data()->manager; + if (!(mgr->accessPointConfigurations.contains(activeConfig.d->id))) { + QExplicitlySharedDataPointer ptr = activeConfig.d; + mgr->accessPointConfigurations.insert(activeConfig.d->id, ptr); + + QNetworkConfiguration item; + item.d = ptr; + emit mgr->configurationAdded(item); + +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"New configuration"<id<<"added to manager in sync"; +#endif + + } else { + mgr->configurationChanged((QNetworkConfigurationPrivate*)(activeConfig.d.data())); +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"Existing configuration"<id<<"updated in manager in sync"; +#endif + } + + } + break; + + case ICD_STATE_DISCONNECTING: + state = QNetworkSession::Closing; + if (activeConfig.d.data()) + activeConfig.d->isValid = true; + break; + default: + break; + } + } + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "status_req tells icd is not connected"; +#endif + } + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "status_req did not return any results from icd"; +#endif + } + + networkConfigurationsChanged(); +} + + +void QNetworkSessionPrivate::networkConfigurationsChanged() +{ + if (serviceConfig.isValid()) + updateStateFromServiceNetwork(); + else + updateStateFromActiveConfig(); +} + + +void QNetworkSessionPrivate::updateStateFromServiceNetwork() +{ + QNetworkSession::State oldState = state; + + foreach (const QNetworkConfiguration &config, serviceConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) + continue; + + if (activeConfig != config) { + activeConfig = config; + emit q->newConfigurationActivated(); + } + + state = QNetworkSession::Connected; + if (state != oldState) + emit q->stateChanged(state); + + return; + } + + if (serviceConfig.children().isEmpty()) + state = QNetworkSession::NotAvailable; + else + state = QNetworkSession::Disconnected; + + if (state != oldState) + emit q->stateChanged(state); +} + + +void QNetworkSessionPrivate::clearConfiguration(QNetworkConfiguration &config) +{ + config.d->network_id.clear(); + config.d->iap_type.clear(); + config.d->network_attrs = 0; + config.d->service_type.clear(); + config.d->service_id.clear(); + config.d->service_attrs = 0; +} + + +void QNetworkSessionPrivate::updateStateFromActiveConfig() +{ + QNetworkSession::State oldState = state; + + bool newActive = false; + + if (!activeConfig.d.data()) + return; + + if (!activeConfig.isValid()) { + state = QNetworkSession::Invalid; + clearConfiguration(activeConfig); + } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Connected; + newActive = opened; + } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + state = QNetworkSession::Disconnected; + } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + state = QNetworkSession::NotAvailable; + } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { + state = QNetworkSession::NotAvailable; + clearConfiguration(activeConfig); + } + + bool oldActive = isOpen; + isOpen = newActive; + + if (!oldActive && isOpen) + emit quitPendingWaitsForOpened(); + + if (oldActive && !isOpen) + emit q->closed(); + + if (oldState != state) { + emit q->stateChanged(state); + + if (state == QNetworkSession::Disconnected) { +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"session aborted error emitted for"<error(lastError); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"oldState ="<ifa_next) { + family = ifa->ifa_addr->sa_family; + if (family != AF_INET) { + continue; /* Currently only IPv4 is supported by icd dbus interface */ + } + if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == addr.s_addr) { + iface = QString(ifa->ifa_name); + break; + } + } + + freeifaddrs(ifaddr); + return iface; +} + + +void QNetworkSessionPrivate::open() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else if (!isOpen) { + + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + /* Caller is trying to connect to default IAP. + * At this time we will not know the IAP details so we just + * connect and update the active config when the IAP is + * connected. + */ + opened = true; + state = QNetworkSession::Connecting; + emit q->stateChanged(state); + QTimer::singleShot(0, this, SLOT(do_open())); + return; + } + + /* User is connecting to one specific IAP. If that IAP is not + * in discovered state we cannot continue. + */ + if ((activeConfig.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + lastError =QNetworkSession::InvalidConfigurationError; + emit q->error(lastError); + return; + } + opened = true; + + if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) { + state = QNetworkSession::Connecting; + emit q->stateChanged(state); + + QTimer::singleShot(0, this, SLOT(do_open())); + return; + } + + isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isOpen) + emit quitPendingWaitsForOpened(); + } else { + /* We seem to be active so inform caller */ + emit quitPendingWaitsForOpened(); + } +} + + +void QNetworkSessionPrivate::do_open() +{ + icd_connection_flags flags = connectFlags; + bool st; + QString result; + QString iap = publicConfig.identifier(); + + if (state == QNetworkSession::Connected) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Already connected to" << activeConfig.identifier(); +#endif + emit q->stateChanged(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + return; + } + + Maemo::IcdConnectResult connect_result; + Maemo::Icd icd(ICD_LONG_CONNECT_TIMEOUT); + QNetworkConfiguration config; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + config = activeConfig; + else + config = publicConfig; + + if (iap == OSSO_IAP_ANY) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connecting to default IAP" << iap; +#endif + st = icd.connect(flags, connect_result); + + } else { + + QList params; + Maemo::ConnectParams param; + param.connect.service_type = config.d->service_type; + param.connect.service_attrs = config.d->service_attrs; + param.connect.service_id = config.d->service_id; + param.connect.network_type = config.d->iap_type; + param.connect.network_attrs = config.d->network_attrs; + if (config.d->network_attrs & ICD_NW_ATTR_IAPNAME) + param.connect.network_id = QByteArray(iap.toLatin1()); + else + param.connect.network_id = config.d->network_id; + params.append(param); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("connecting to %s/%s/0x%x/%s/0x%x/%s", + param.connect.network_id.data(), + param.connect.network_type.toAscii().constData(), + param.connect.network_attrs, + param.connect.service_type.toAscii().constData(), + param.connect.service_attrs, + param.connect.service_id.toAscii().constData()); +#endif + st = icd.connect(flags, params, connect_result); + } + + if (st) { + result = connect_result.connect.network_id.data(); + QString connected_iap = result; + + if (connected_iap.isEmpty()) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connect to"<< iap << "failed, result is empty"; +#endif + updateState(QNetworkSession::Disconnected); + emit q->error(QNetworkSession::InvalidConfigurationError); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + cleanupAnyConfiguration(); + return; + } + + /* If the user tried to connect to some specific connection (foo) + * and we were already connected to some other connection (bar), + * then we cannot activate this session although icd has a valid + * connection to somewhere. + */ + if ((publicConfig.type() != QNetworkConfiguration::UserChoice) && + (connected_iap != config.identifier())) { + updateState(QNetworkSession::Disconnected); + emit q->error(QNetworkSession::InvalidConfigurationError); + return; + } + + + /* Did we connect to non saved IAP? */ + if (!(config.d->network_attrs & ICD_NW_ATTR_IAPNAME)) { + /* Because the connection succeeded, the IAP is now known. + */ + config.d->network_attrs |= ICD_NW_ATTR_IAPNAME; + config.d->id = connected_iap; + } + + /* User might have changed the IAP name when a new IAP was saved */ + Maemo::IAPConf iap_name(config.d->id); + QString name = iap_name.value("name").toString(); + if (!name.isEmpty()) + config.d->name = name; + + config.d->iap_type = connect_result.connect.network_type; + + config.d->isValid = true; + config.d->state = QNetworkConfiguration::Active; + config.d->type = QNetworkConfiguration::InternetAccessPoint; + + startTime = QDateTime::currentDateTime(); + updateState(QNetworkSession::Connected); + + currentNetworkInterface = get_network_interface(); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connected to" << result << config.d->name << "at" << currentNetworkInterface; +#endif + + /* We first check if the configuration already exists in the manager + * and if it is not found there, we then insert it. Note that this + * is only done for user choice config only because it can be missing + * from config manager list. + */ + + if (publicConfig.d->type == QNetworkConfiguration::UserChoice) { + +#ifdef BEARER_MANAGEMENT_DEBUG +#if 0 + QList configs; + QNetworkConfigurationManagerPrivate *conPriv = (QNetworkConfigurationManagerPrivate*)config.d.data()->manager; + QList cpsIdents = conPriv->accessPointConfigurations.keys(); + foreach( QString ii, cpsIdents) { + QExplicitlySharedDataPointer p = + conPriv->accessPointConfigurations.value(ii); + QNetworkConfiguration pt; + pt.d = conPriv->accessPointConfigurations.value(ii); + configs << pt; + } + + int all = configs.count(); + qDebug() << "All configurations:" << all; + foreach(QNetworkConfiguration p, configs) { + qDebug() << p.name() <<": isvalid->" <"<< p.type() << + " roaming->" << p.isRoamingAvailable() << "identifier->" << p.identifier() << + " purpose->" << p.purpose() << " state->" << p.state(); + } +#endif +#endif + + QNetworkConfigurationManagerPrivate *mgr = (QNetworkConfigurationManagerPrivate*)config.d.data()->manager; + if (!mgr->accessPointConfigurations.contains(result)) { + QExplicitlySharedDataPointer ptr = config.d; + mgr->accessPointConfigurations.insert(result, ptr); + + QNetworkConfiguration item; + item.d = ptr; + emit mgr->configurationAdded(item); + +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"New configuration"< priv = mgr->accessPointConfigurations.value(result); + QNetworkConfiguration reference; + reference.d = priv; + copyConfig(config, reference, false); + config = reference; + activeConfig = reference; + mgr->configurationChanged((QNetworkConfigurationPrivate*)(config.d.data())); + +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"Existing configuration"<error(QNetworkSession::UnknownSessionError); + } +} + + +void QNetworkSessionPrivate::cleanupAnyConfiguration() +{ +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug()<<"Removing configuration created for" << activeConfig.d->id; +#endif + activeConfig = publicConfig; +} + + +void QNetworkSessionPrivate::close() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else if (isOpen) { + opened = false; + isOpen = false; + emit q->closed(); + } +} + + +void QNetworkSessionPrivate::stop() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else { + if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Closing; + emit q->stateChanged(state); + + Maemo::Icd icd; +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "stopping session" << publicConfig.identifier(); +#endif + icd.disconnect(ICD_CONNECTION_FLAG_APPLICATION_EVENT); + startTime = QDateTime(); + + /* Note that the state will go disconnected in + * updateStateFromActiveConfig() which gets called after + * configurationChanged is emitted (below). + */ + + activeConfig.d->state = QNetworkConfiguration::Discovered; + QNetworkConfigurationManagerPrivate *mgr = (QNetworkConfigurationManagerPrivate*)activeConfig.d.data()->manager; + mgr->configurationChanged((QNetworkConfigurationPrivate*)activeConfig.d.data()); + + opened = false; + isOpen = false; + + } else { + opened = false; + isOpen = false; + emit q->closed(); + } + } +} + + +void QNetworkSessionPrivate::migrate() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivate::accept() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivate::ignore() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivate::reject() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +QNetworkInterface QNetworkSessionPrivate::currentInterface() const +{ + if (!publicConfig.isValid() || state != QNetworkSession::Connected) + return QNetworkInterface(); + + if (currentNetworkInterface.isEmpty()) + return QNetworkInterface(); + + return QNetworkInterface::interfaceFromName(currentNetworkInterface); +} + + +void QNetworkSessionPrivate::setSessionProperty(const QString& key, const QVariant& value) +{ + if (value.isValid()) { + properties.insert(key, value); + + if (key == "ConnectInBackground") { + bool v = value.toBool(); + if (v) + connectFlags = ICD_CONNECTION_FLAG_APPLICATION_EVENT; + else + connectFlags = ICD_CONNECTION_FLAG_USER_EVENT; + } + } else { + properties.remove(key); + + /* Set default value when property is removed */ + if (key == "ConnectInBackground") + connectFlags = ICD_CONNECTION_FLAG_USER_EVENT; + } +} + + +QVariant QNetworkSessionPrivate::sessionProperty(const QString& key) const +{ + return properties.value(key); +} + + +QString QNetworkSessionPrivate::errorString() const +{ + QString errorStr; + switch(q->error()) { + case QNetworkSession::RoamingError: + errorStr = QObject::tr("Roaming error"); + break; + case QNetworkSession::SessionAbortedError: + errorStr = QObject::tr("Session aborted by user or system"); + break; + default: + case QNetworkSession::UnknownSessionError: + errorStr = QObject::tr("Unidentified Error"); + break; + } + return errorStr; +} + + +QNetworkSession::SessionError QNetworkSessionPrivate::error() const +{ + return QNetworkSession::UnknownSessionError; +} + + +void QNetworkSessionPrivate::updateProxies(QNetworkSession::State newState) +{ + if ((newState == QNetworkSession::Connected) && + (newState != currentState)) + updateProxyInformation(); + else if ((newState == QNetworkSession::Disconnected) && + (currentState == QNetworkSession::Closing)) + clearProxyInformation(); + + currentState = newState; +} + + +void QNetworkSessionPrivate::updateProxyInformation() +{ + Maemo::ProxyConf::update(); +} + + +void QNetworkSessionPrivate::clearProxyInformation() +{ + Maemo::ProxyConf::clear(); +} + + +#include "qnetworksession_maemo.moc" +#include "moc_qnetworksession_maemo_p.cpp" + +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksession_maemo_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksession_maemo_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKSESSIONPRIVATE_H +#define QNETWORKSESSIONPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// +#include "qnetworkconfigmanager_maemo_p.h" +#include "qnetworksession.h" + +#include +#include +#include + +#ifdef Q_WS_MAEMO_6 +#include +#endif + +QTM_BEGIN_NAMESPACE + +class QNetworkSessionPrivate : public QObject +{ + Q_OBJECT +public: + QNetworkSessionPrivate() : + tx_data(0), rx_data(0), m_activeTime(0), isOpen(false), +#ifdef Q_WS_MAEMO_6 + connectFlags(ICD_CONNECTION_FLAG_USER_EVENT), +#else + connectFlags(0), +#endif + currentState(QNetworkSession::Invalid) + { + } + + ~QNetworkSessionPrivate() + { + cleanupSession(); + } + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + + void open(); + void close(); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +private: + void updateStateFromServiceNetwork(); + void updateStateFromActiveConfig(); + +Q_SIGNALS: + //releases any pending waitForOpened() calls + void quitPendingWaitsForOpened(); + +private Q_SLOTS: + void do_open(); + void networkConfigurationsChanged(); + void configurationChanged(const QNetworkConfiguration &config); + void updateProxies(QNetworkSession::State newState); + +private: + QNetworkConfigurationManager manager; + + quint64 tx_data; + quint64 rx_data; + quint64 m_activeTime; + + // The config set on QNetworkSession. + QNetworkConfiguration publicConfig; + + // If publicConfig is a ServiceNetwork this is a copy of publicConfig. + // If publicConfig is an UserChoice that is resolved to a ServiceNetwork this is the actual + // ServiceNetwork configuration. + QNetworkConfiguration serviceConfig; + + // This is the actual active configuration currently in use by the session. + // Either a copy of publicConfig or one of serviceConfig.children(). + QNetworkConfiguration activeConfig; + + QNetworkConfiguration& copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy = true); + void clearConfiguration(QNetworkConfiguration &config); + void cleanupAnyConfiguration(); + + QNetworkSession::State state; + bool isOpen; + bool opened; + icd_connection_flags connectFlags; + + QNetworkSession::SessionError lastError; + + QNetworkSession* q; + friend class QNetworkSession; + + QDateTime startTime; + QString currentNetworkInterface; + friend class IcdListener; + void updateState(QNetworkSession::State); + void updateIdentifier(QString &newId); + quint64 getStatistics(bool sent) const; + void cleanupSession(void); + + void updateProxyInformation(); + void clearProxyInformation(); + QNetworkSession::State currentState; +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKSESSIONPRIVATE_H + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksession_p.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksession_p.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,540 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworksession_p.h" +#include "qnetworksession.h" +#include "qnetworksessionengine_p.h" +#include "qgenericengine_p.h" + +#ifdef Q_OS_WIN +#include "qnlaengine_win_p.h" +#endif +#ifdef Q_OS_WIN32 +#include "qnativewifiengine_win_p.h" +#endif +#ifdef Q_OS_DARWIN +#include "qcorewlanengine_mac_p.h" +#endif +#include +#include +#include + +#include + +#if defined(BACKEND_NM) +#include "qnmwifiengine_unix_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +#if defined(BACKEND_NM) +static bool NetworkManagerAvailable() +{ + QDBusConnection dbusConnection = QDBusConnection::systemBus(); + if (dbusConnection.isConnected()) { + QDBusConnectionInterface *dbiface = dbusConnection.interface(); + QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); + if (reply.isValid()) + return reply.value(); + } + return false; +} +#endif + +static QNetworkSessionEngine *getEngineFromId(const QString &id) +{ +#ifdef Q_OS_WIN + QNlaEngine *nla = QNlaEngine::instance(); + if (nla && nla->hasIdentifier(id)) + return nla; +#endif + +#ifdef Q_OS_WIN32 + QNativeWifiEngine *nativeWifi = QNativeWifiEngine::instance(); + if (nativeWifi && nativeWifi->hasIdentifier(id)) + return nativeWifi; +#endif + +#if defined(BACKEND_NM) + if(NetworkManagerAvailable()) { + QNmWifiEngine *nmwiifi = QNmWifiEngine::instance(); + if (nmwiifi && nmwiifi->hasIdentifier(id)) + return nmwiifi; + } +#endif +#ifdef Q_OS_DARWIN + QCoreWlanEngine *coreWifi = QCoreWlanEngine::instance(); + if (coreWifi && coreWifi->hasIdentifier(id)) + return coreWifi; + +#endif + QGenericEngine *generic = QGenericEngine::instance(); + if (generic && generic->hasIdentifier(id)) + return generic; + + return 0; +} + +class QNetworkSessionManagerPrivate : public QObject +{ + Q_OBJECT + +public: + QNetworkSessionManagerPrivate(QObject *parent = 0); + ~QNetworkSessionManagerPrivate(); + + void forceSessionClose(const QNetworkConfiguration &config); + +Q_SIGNALS: + void forcedSessionClose(const QNetworkConfiguration &config); +}; + +#include "qnetworksession_p.moc" + +Q_GLOBAL_STATIC(QNetworkSessionManagerPrivate, sessionManager); + +QNetworkSessionManagerPrivate::QNetworkSessionManagerPrivate(QObject *parent) +: QObject(parent) +{ +} + +QNetworkSessionManagerPrivate::~QNetworkSessionManagerPrivate() +{ +} + +void QNetworkSessionManagerPrivate::forceSessionClose(const QNetworkConfiguration &config) +{ + emit forcedSessionClose(config); +} + +void QNetworkSessionPrivate::syncStateWithInterface() +{ + connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); + connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); + connect(sessionManager(), SIGNAL(forcedSessionClose(QNetworkConfiguration)), + this, SLOT(forcedSessionClose(QNetworkConfiguration))); + + opened = false; + state = QNetworkSession::Invalid; + lastError = QNetworkSession::UnknownSessionError; + + qRegisterMetaType + ("QNetworkSessionEngine::ConnectionError"); + + switch (publicConfig.type()) { + case QNetworkConfiguration::InternetAccessPoint: + activeConfig = publicConfig; + engine = getEngineFromId(activeConfig.identifier()); + if (engine) { + connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + Qt::QueuedConnection); + } + break; + case QNetworkConfiguration::ServiceNetwork: + serviceConfig = publicConfig; + // Defer setting engine and signals until open(). + // fall through + case QNetworkConfiguration::UserChoice: + // Defer setting serviceConfig and activeConfig until open(). + // fall through + default: + engine = 0; + } + + networkConfigurationsChanged(); +} + +void QNetworkSessionPrivate::open() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else if (!isOpen) { + if ((activeConfig.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + lastError =QNetworkSession::InvalidConfigurationError; + emit q->error(lastError); + return; + } + opened = true; + + if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active && + (activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + state = QNetworkSession::Connecting; + emit q->stateChanged(state); + + engine->connectToId(activeConfig.identifier()); + } + + isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isOpen) + emit quitPendingWaitsForOpened(); + } +} + +void QNetworkSessionPrivate::close() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else if (isOpen) { + opened = false; + isOpen = false; + emit q->closed(); + } +} + +void QNetworkSessionPrivate::stop() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else { + if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Closing; + emit q->stateChanged(state); + + engine->disconnectFromId(activeConfig.identifier()); + + sessionManager()->forceSessionClose(activeConfig); + } + + opened = false; + isOpen = false; + emit q->closed(); + } +} + +void QNetworkSessionPrivate::migrate() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivate::accept() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivate::ignore() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivate::reject() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +QNetworkInterface QNetworkSessionPrivate::currentInterface() const +{ + if (!publicConfig.isValid() || !engine || state != QNetworkSession::Connected) + return QNetworkInterface(); + + QString interface = engine->getInterfaceFromId(activeConfig.identifier()); + + if (interface.isEmpty()) + return QNetworkInterface(); + return QNetworkInterface::interfaceFromName(interface); +} + +QVariant QNetworkSessionPrivate::sessionProperty(const QString& /*key*/) const +{ + return QVariant(); +} + +void QNetworkSessionPrivate::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) +{ +} + +/*QString QNetworkSessionPrivate::bearerName() const +{ + if (!publicConfig.isValid() || !engine) + return QString(); + + return engine->bearerName(activeConfig.identifier()); +}*/ + +QString QNetworkSessionPrivate::errorString() const +{ + switch (lastError) { + case QNetworkSession::UnknownSessionError: + return tr("Unknown session error."); + case QNetworkSession::SessionAbortedError: + return tr("The session was aborted by the user or system."); + case QNetworkSession::OperationNotSupportedError: + return tr("The requested operation is not supported by the system."); + case QNetworkSession::InvalidConfigurationError: + return tr("The specified configuration cannot be used."); + case QNetworkSession::RoamingError: + return tr("Roaming was aborted or is not possible."); + + } + + return QString(); +} + +QNetworkSession::SessionError QNetworkSessionPrivate::error() const +{ + return lastError; +} + +quint64 QNetworkSessionPrivate::bytesWritten() const +{ +#if defined(BACKEND_NM) + if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &config, publicConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return static_cast(getEngineFromId(config.d->id))->sentDataForId(config.d->id); + } + } + } else { + return static_cast(getEngineFromId(activeConfig.d->id))->sentDataForId(activeConfig.d->id); + } + } +#endif + return tx_data; +} + +quint64 QNetworkSessionPrivate::bytesReceived() const +{ +#if defined(BACKEND_NM) + if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &config, publicConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(config.d->id); + } + } + } else { + return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(activeConfig.d->id); + } + } +#endif + return rx_data; +} + +quint64 QNetworkSessionPrivate::activeTime() const +{ +#if defined(BACKEND_NM) + if (startTime.isNull()) { + return 0; + } + if(state == QNetworkSession::Connected ) + return startTime.secsTo(QDateTime::currentDateTime()); +#endif + return m_activeTime; +} + +void QNetworkSessionPrivate::updateStateFromServiceNetwork() +{ + QNetworkSession::State oldState = state; + + foreach (const QNetworkConfiguration &config, serviceConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) + continue; + + if (activeConfig != config) { + if (engine) { + disconnect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError))); + } + + activeConfig = config; + engine = getEngineFromId(activeConfig.identifier()); + if (engine) { + connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + Qt::QueuedConnection); + } + emit q->newConfigurationActivated(); + } + + state = QNetworkSession::Connected; + if (state != oldState) + emit q->stateChanged(state); + + return; + } + + if (serviceConfig.children().isEmpty()) + state = QNetworkSession::NotAvailable; + else + state = QNetworkSession::Disconnected; + + if (state != oldState) + emit q->stateChanged(state); +} + +void QNetworkSessionPrivate::updateStateFromActiveConfig() +{ + QNetworkSession::State oldState = state; + + bool newActive = false; + + if (!activeConfig.isValid()) { + state = QNetworkSession::Invalid; + } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Connected; + newActive = opened; + } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + state = QNetworkSession::Disconnected; + } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + state = QNetworkSession::NotAvailable; + } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { + state = QNetworkSession::NotAvailable; + } + + bool oldActive = isOpen; + isOpen = newActive; + + if (!oldActive && isOpen) + emit quitPendingWaitsForOpened(); + if (oldActive && !isOpen) + emit q->closed(); + + if (oldState != state) + emit q->stateChanged(state); +} + +void QNetworkSessionPrivate::networkConfigurationsChanged() +{ + if (serviceConfig.isValid()) + updateStateFromServiceNetwork(); + else + updateStateFromActiveConfig(); +#if defined(BACKEND_NM) + setActiveTimeStamp(); +#endif +} + +void QNetworkSessionPrivate::configurationChanged(const QNetworkConfiguration &config) +{ + if (serviceConfig.isValid() && (config == serviceConfig || config == activeConfig)) + updateStateFromServiceNetwork(); + else if (config == activeConfig) + updateStateFromActiveConfig(); +} + +void QNetworkSessionPrivate::forcedSessionClose(const QNetworkConfiguration &config) +{ + if (activeConfig == config) { + opened = false; + isOpen = false; + + emit q->closed(); + + lastError = QNetworkSession::SessionAbortedError; + emit q->error(lastError); + } +} + +void QNetworkSessionPrivate::connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error) +{ + if (activeConfig.identifier() == id) { + networkConfigurationsChanged(); + switch (error) { + case QNetworkSessionEngine::OperationNotSupported: + lastError = QNetworkSession::OperationNotSupportedError; + opened = false; + break; + case QNetworkSessionEngine::InterfaceLookupError: + case QNetworkSessionEngine::ConnectError: + case QNetworkSessionEngine::DisconnectionError: + default: + lastError = QNetworkSession::UnknownSessionError; + } + emit q->error(lastError); + } +} + +#if defined(BACKEND_NM) +void QNetworkSessionPrivate::setActiveTimeStamp() +{ + if(NetworkManagerAvailable()) { + startTime = QDateTime(); + return; + } + QString connectionIdent = q->configuration().identifier(); + QString interface = currentInterface().hardwareAddress().toLower(); + QString devicePath = "/org/freedesktop/Hal/devices/net_" + interface.replace(":","_"); + + QString path; + QString serviceName; + QNetworkManagerInterface * ifaceD; + ifaceD = new QNetworkManagerInterface(); + + QList connections = ifaceD->activeConnections(); + foreach(QDBusObjectPath conpath, connections) { + QNetworkManagerConnectionActive *conDetails; + conDetails = new QNetworkManagerConnectionActive(conpath.path()); + QDBusObjectPath connection = conDetails->connection(); + serviceName = conDetails->serviceName(); + QList so = conDetails->devices(); + foreach(QDBusObjectPath device, so) { + + if(device.path() == devicePath) { + path = connection.path(); + } + break; + } + } +if(serviceName.isEmpty()) + return; + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(serviceName); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(serviceName, path.path()); + startTime = QDateTime::fromTime_t(sysIface->getTimestamp()); + // isOpen = (publicConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + } + if(startTime.isNull()) + startTime = QDateTime::currentDateTime(); +} +#endif + +#include "moc_qnetworksession_p.cpp" +QTM_END_NAMESPACE + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksession_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksession_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKSESSIONPRIVATE_H +#define QNETWORKSESSIONPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworkconfigmanager_p.h" +#include "qnetworksession.h" +#ifdef BEARER_ENGINE +#include "qnetworksessionengine_p.h" +#endif + +#include "qnetworksession.h" +#include +#include + +QTM_BEGIN_NAMESPACE +#ifdef BEARER_ENGINE +class QNetworkSessionEngine; +#endif + +class QNetworkSessionPrivate : public QObject +{ + Q_OBJECT +public: + QNetworkSessionPrivate() : + tx_data(0), rx_data(0), m_activeTime(0), isOpen(false) + { + } + + ~QNetworkSessionPrivate() + { + } + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + QString bearerName() const; + + void open(); + void close(); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +private: + void updateStateFromServiceNetwork(); + void updateStateFromActiveConfig(); + +Q_SIGNALS: + //releases any pending waitForOpened() calls + void quitPendingWaitsForOpened(); + +private Q_SLOTS: +#ifdef BEARER_ENGINE + void networkConfigurationsChanged(); + void configurationChanged(const QNetworkConfiguration &config); + void forcedSessionClose(const QNetworkConfiguration &config); + void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); +#endif + +private: + QNetworkConfigurationManager manager; + + quint64 tx_data; + quint64 rx_data; + quint64 m_activeTime; + + // The config set on QNetworkSession. + QNetworkConfiguration publicConfig; + + // If publicConfig is a ServiceNetwork this is a copy of publicConfig. + // If publicConfig is an UserChoice that is resolved to a ServiceNetwork this is the actual + // ServiceNetwork configuration. + QNetworkConfiguration serviceConfig; + + // This is the actual active configuration currently in use by the session. + // Either a copy of publicConfig or one of serviceConfig.children(). + QNetworkConfiguration activeConfig; + + QNetworkSession::State state; + bool isOpen; + +#ifdef BEARER_ENGINE + bool opened; + + QNetworkSessionEngine *engine; +#endif + QNetworkSession::SessionError lastError; + + QNetworkSession* q; + friend class QNetworkSession; + +#if defined(BEARER_ENGINE) && defined(BACKEND_NM) + QDateTime startTime; + void setActiveTimeStamp(); +#endif +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKSESSIONPRIVATE_H + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksession_s60_p.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksession_s60_p.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,1147 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qnetworksession_s60_p.h" +#include "qnetworkconfiguration_s60_p.h" +#include "qnetworkconfigmanager_s60_p.h" +#include +#include +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +QNetworkSessionPrivate::QNetworkSessionPrivate() + : CActive(CActive::EPriorityStandard), state(QNetworkSession::Invalid), + isOpen(false), ipConnectionNotifier(0), iError(QNetworkSession::UnknownSessionError), + iALREnabled(0) +{ + CActiveScheduler::Add(this); + + // Try to load "Open C" dll dynamically and + // try to attach to setdefaultif function dynamically. + if (iOpenCLibrary.Load(_L("libc")) == KErrNone) { + iDynamicSetdefaultif = (TOpenCSetdefaultifFunction)iOpenCLibrary.Lookup(564); + } + + TRAP_IGNORE(iConnectionMonitor.ConnectL()); +} + +QNetworkSessionPrivate::~QNetworkSessionPrivate() +{ + isOpen = false; + + // Cancel Connection Progress Notifications first. + // Note: ConnectionNotifier must be destroyed before Canceling RConnection::Start() + // => deleting ipConnectionNotifier results RConnection::CancelProgressNotification() + delete ipConnectionNotifier; + ipConnectionNotifier = NULL; + + // Cancel possible RConnection::Start() + Cancel(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (iMobility) { + delete iMobility; + iMobility = NULL; + } +#endif + + iConnection.Close(); + iSocketServ.Close(); + if (iDynamicSetdefaultif) { + iDynamicSetdefaultif(0); + } + + iConnectionMonitor.CancelNotifications(); + iConnectionMonitor.Close(); + + iOpenCLibrary.Close(); +} + +void QNetworkSessionPrivate::syncStateWithInterface() +{ + if (!publicConfig.d) { + return; + } + + // Start monitoring changes in IAP states + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + + // Check open connections to see if there is already + // an open connection to selected IAP or SNAP + TUint count; + TRequestStatus status; + iConnectionMonitor.GetConnectionCount(count, status); + User::WaitForRequest(status); + if (status.Int() != KErrNone) { + return; + } + + TUint numSubConnections; + TUint connectionId; + for (TUint i = 1; i <= count; i++) { + TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections); + if (ret == KErrNone) { + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + TInt connectionStatus; + iConnectionMonitor.GetIntAttribute(connectionId, 0, KConnectionStatus, connectionStatus, status); + User::WaitForRequest(status); + if (connectionStatus == KLinkLayerOpen) { + if (state != QNetworkSession::Closing) { + if (newState(QNetworkSession::Connected, apId)) { + return; + } + } + } + } + } + } + + if (state != QNetworkSession::Connected) { + // There were no open connections to used IAP or SNAP + if (iError == QNetworkSession::InvalidConfigurationError) { + newState(QNetworkSession::Invalid); + } + else if ((publicConfig.d.data()->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::NotAvailable); + } + } +} + +QNetworkInterface QNetworkSessionPrivate::interface(TUint iapId) const +{ + QString interfaceName; + + TSoInetInterfaceInfo ifinfo; + TPckg ifinfopkg(ifinfo); + TSoInetIfQuery ifquery; + TPckg ifquerypkg(ifquery); + + // Open dummy socket for interface queries + RSocket socket; + TInt retVal = socket.Open(iSocketServ, _L("udp")); + if (retVal != KErrNone) { + return QNetworkInterface(); + } + + // Start enumerating interfaces + socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl); + while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) == KErrNone) { + ifquery.iName = ifinfo.iName; + TInt err = socket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg); + if(err == KErrNone && ifquery.iZone[1] == iapId) { // IAP ID is index 1 of iZone + if(ifinfo.iAddress.Address() > 0) { + interfaceName = QString::fromUtf16(ifinfo.iName.Ptr(),ifinfo.iName.Length()); + break; + } + } + } + + socket.Close(); + + if (interfaceName.isEmpty()) { + return QNetworkInterface(); + } + + return QNetworkInterface::interfaceFromName(interfaceName); +} + +QNetworkInterface QNetworkSessionPrivate::currentInterface() const +{ + if (!publicConfig.isValid() || state != QNetworkSession::Connected) { + return QNetworkInterface(); + } + + return activeInterface; +} + +QVariant QNetworkSessionPrivate::sessionProperty(const QString& /*key*/) const +{ + return QVariant(); +} + +void QNetworkSessionPrivate::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) +{ +} + +QString QNetworkSessionPrivate::errorString() const +{ + switch (iError) { + case QNetworkSession::UnknownSessionError: + return tr("Unknown session error."); + case QNetworkSession::SessionAbortedError: + return tr("The session was aborted by the user or system."); + case QNetworkSession::OperationNotSupportedError: + return tr("The requested operation is not supported by the system."); + case QNetworkSession::InvalidConfigurationError: + return tr("The specified configuration cannot be used."); + case QNetworkSession::RoamingError: + return tr("Roaming was aborted or is not possible."); + } + + return QString(); +} + +QNetworkSession::SessionError QNetworkSessionPrivate::error() const +{ + return iError; +} + +void QNetworkSessionPrivate::open() +{ + if (isOpen || (state == QNetworkSession::Connecting)) { + return; + } + + // Cancel notifications from RConnectionMonitor + // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring + iConnectionMonitor.CancelNotifications(); + + // Configuration must be at least in Discovered - state for connecting purposes. + if ((publicConfig.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + newState(QNetworkSession::Invalid); + iError = QNetworkSession::InvalidConfigurationError; + emit q->error(iError); + syncStateWithInterface(); + return; + } + + TInt error = iSocketServ.Connect(); + if (error != KErrNone) { + // Could not open RSocketServ + newState(QNetworkSession::Invalid); + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + syncStateWithInterface(); + return; + } + + error = iConnection.Open(iSocketServ); + if (error != KErrNone) { + // Could not open RConnection + iSocketServ.Close(); + newState(QNetworkSession::Invalid); + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + syncStateWithInterface(); + return; + } + + // Use RConnection::ProgressNotification for IAP/SNAP monitoring + // (<=> ConnectionProgressNotifier uses RConnection::ProgressNotification) + if (!ipConnectionNotifier) { + ipConnectionNotifier = new ConnectionProgressNotifier(*this,iConnection); + } + if (ipConnectionNotifier) { + ipConnectionNotifier->StartNotifications(); + } + + if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + // Search through existing connections. + // If there is already connection which matches to given IAP + // try to attach to existing connection. + TBool connected(EFalse); + TConnectionInfoBuf connInfo; + TUint count; + if (iConnection.EnumerateConnections(count) == KErrNone) { + for (TUint i=1; i<=count; i++) { + // Note: GetConnectionInfo expects 1-based index. + if (iConnection.GetConnectionInfo(i, connInfo) == KErrNone) { + if (connInfo().iIapId == publicConfig.d.data()->numericId) { + if (iConnection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { + activeConfig = publicConfig; + activeInterface = interface(activeConfig.d.data()->numericId); + connected = ETrue; + startTime = QDateTime::currentDateTime(); + if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = publicConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + error = iDynamicSetdefaultif(&ifr); + } + isOpen = true; + // Make sure that state will be Connected + newState(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + break; + } + } + } + } + } + if (!connected) { + TCommDbConnPref pref; + pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); + pref.SetIapId(publicConfig.d.data()->numericId); + iConnection.Start(pref, iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } + } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + TConnSnapPref snapPref(publicConfig.d.data()->numericId); + iConnection.Start(snapPref, iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + iKnownConfigsBeforeConnectionStart = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys(); + iConnection.Start(iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } + + if (error != KErrNone) { + isOpen = false; + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + } +} + +TUint QNetworkSessionPrivate::iapClientCount(TUint aIAPId) const +{ + TRequestStatus status; + TUint connectionCount; + iConnectionMonitor.GetConnectionCount(connectionCount, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + for (TUint i = 1; i <= connectionCount; i++) { + TUint connectionId; + TUint subConnectionCount; + iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + if (apId == aIAPId) { + TConnMonClientEnumBuf buf; + iConnectionMonitor.GetPckgAttribute(connectionId, 0, KClientInfo, buf, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + return buf().iCount; + } + } + } + } + return 0; +} + +void QNetworkSessionPrivate::close(bool allowSignals) +{ + if (!isOpen) { + return; + } + + TUint activeIap = activeConfig.d.data()->numericId; + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + + Cancel(); +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (iMobility) { + delete iMobility; + iMobility = NULL; + } +#endif + + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + + iConnection.Close(); + iSocketServ.Close(); + if (iDynamicSetdefaultif) { + iDynamicSetdefaultif(0); + } + +#ifdef Q_CC_NOKIAX86 + if ((allowSignals && iapClientCount(activeIap) <= 0) || +#else + if ((allowSignals && iapClientCount(activeIap) <= 1) || +#endif + (publicConfig.type() == QNetworkConfiguration::UserChoice)) { + newState(QNetworkSession::Closing); + } + + syncStateWithInterface(); + if (allowSignals) { + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + newState(QNetworkSession::Disconnected); + } + emit q->closed(); + } +} + +void QNetworkSessionPrivate::stop() +{ + if (!isOpen) { + return; + } + isOpen = false; + newState(QNetworkSession::Closing); + iConnection.Stop(RConnection::EStopAuthoritative); + isOpen = true; + close(false); + emit q->closed(); +} + +void QNetworkSessionPrivate::migrate() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->MigrateToPreferredCarrier(); +#endif +} + +void QNetworkSessionPrivate::ignore() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->IgnorePreferredCarrier(); + if (!iALRUpgradingConnection) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::Connected,iOldRoamingIap); + } +#endif +} + +void QNetworkSessionPrivate::accept() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->NewCarrierAccepted(); + if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = activeConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + iDynamicSetdefaultif(&ifr); + } + newState(QNetworkSession::Connected, iNewRoamingIap); +#endif +} + +void QNetworkSessionPrivate::reject() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->NewCarrierRejected(); + if (!iALRUpgradingConnection) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::Connected, iOldRoamingIap); + } +#endif +} + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +void QNetworkSessionPrivate::PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo, + TAccessPointInfo aNewAPInfo, + TBool aIsUpgrade, + TBool aIsSeamless) +{ + iOldRoamingIap = aOldAPInfo.AccessPoint(); + iNewRoamingIap = aNewAPInfo.AccessPoint(); + newState(QNetworkSession::Roaming); + if (iALREnabled > 0) { + iALRUpgradingConnection = aIsUpgrade; + QList configs = publicConfig.children(); + for (int i=0; i < configs.count(); i++) { + if (configs[i].d.data()->numericId == aNewAPInfo.AccessPoint()) { + emit q->preferredConfigurationChanged(configs[i],aIsSeamless); + } + } + } else { + migrate(); + } +} + +void QNetworkSessionPrivate::NewCarrierActive(TAccessPointInfo /*aNewAPInfo*/, TBool /*aIsSeamless*/) +{ + if (iALREnabled > 0) { + emit q->newConfigurationActivated(); + } else { + accept(); + } +} + +void QNetworkSessionPrivate::Error(TInt /*aError*/) +{ + if (isOpen) { + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::RoamingError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + // In some cases IAP is still in Connected state when + // syncStateWithInterface(); is called + // => Following call makes sure that Session state + // changes immediately to Disconnected. + newState(QNetworkSession::Disconnected); + emit q->closed(); + } +} +#endif + +void QNetworkSessionPrivate::setALREnabled(bool enabled) +{ + if (enabled) { + iALREnabled++; + } else { + iALREnabled--; + } +} + +QNetworkConfiguration QNetworkSessionPrivate::bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const +{ + QNetworkConfiguration config; + QList subConfigurations = snapConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].state() == QNetworkConfiguration::Active) { + config = subConfigurations[i]; + break; + } else if (!config.isValid() && subConfigurations[i].state() == QNetworkConfiguration::Discovered) { + config = subConfigurations[i]; + } + } + if (!config.isValid() && subConfigurations.count() > 0) { + config = subConfigurations[0]; + } + return config; +} + +quint64 QNetworkSessionPrivate::bytesWritten() const +{ + return transferredData(KUplinkData); +} + +quint64 QNetworkSessionPrivate::bytesReceived() const +{ + return transferredData(KDownlinkData); +} + +quint64 QNetworkSessionPrivate::transferredData(TUint dataType) const +{ + if (!publicConfig.isValid()) { + return 0; + } + + QNetworkConfiguration config; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (serviceConfig.isValid()) { + config = serviceConfig; + } else { + if (activeConfig.isValid()) { + config = activeConfig; + } + } + } else { + config = publicConfig; + } + + if (!config.isValid()) { + return 0; + } + + TUint count; + TRequestStatus status; + iConnectionMonitor.GetConnectionCount(count, status); + User::WaitForRequest(status); + if (status.Int() != KErrNone) { + return 0; + } + + TUint transferredData = 0; + TUint numSubConnections; + TUint connectionId; + bool configFound; + for (TUint i = 1; i <= count; i++) { + TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections); + if (ret == KErrNone) { + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + configFound = false; + if (config.type() == QNetworkConfiguration::ServiceNetwork) { + QList configs = config.children(); + for (int i=0; i < configs.count(); i++) { + if (configs[i].d.data()->numericId == apId) { + configFound = true; + break; + } + } + } else if (config.d.data()->numericId == apId) { + configFound = true; + } + if (configFound) { + TUint tData; + iConnectionMonitor.GetUintAttribute(connectionId, 0, dataType, tData, status ); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + transferredData += tData; + } + } + } + } + } + + return transferredData; +} + +quint64 QNetworkSessionPrivate::activeTime() const +{ + if (!isOpen || startTime.isNull()) { + return 0; + } + return startTime.secsTo(QDateTime::currentDateTime()); +} + +QNetworkConfiguration QNetworkSessionPrivate::activeConfiguration(TUint32 iapId) const +{ + if (iapId == 0) { + _LIT(KSetting, "IAP\\Id"); + iConnection.GetIntSetting(KSetting, iapId); + } + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + // Try to search IAP from the used SNAP using IAP Id + QList children = publicConfig.children(); + for (int i=0; i < children.count(); i++) { + if (children[i].d.data()->numericId == iapId) { + return children[i]; + } + } + + // Given IAP Id was not found from the used SNAP + // => Try to search matching IAP using mappingName + // mappingName contains: + // 1. "Access point name" for "Packet data" Bearer + // 2. "WLAN network name" (= SSID) for "Wireless LAN" Bearer + // 3. "Dial-up number" for "Data call Bearer" or "High Speed (GSM)" Bearer + // <=> Note: It's possible that in this case reported IAP is + // clone of the one of the IAPs of the used SNAP + // => If mappingName matches, clone has been found + QNetworkConfiguration pt; + pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(QString::number(qHash(iapId))); + if (pt.d) { + for (int i=0; i < children.count(); i++) { + if (children[i].d.data()->mappingName == pt.d.data()->mappingName) { + return children[i]; + } + } + } else { + // Given IAP Id was not found from known IAPs array + return QNetworkConfiguration(); + } + + // Matching IAP was not found from used SNAP + // => IAP from another SNAP is returned + // (Note: Returned IAP matches to given IAP Id) + return pt; + } +#endif + + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (publicConfig.d.data()->manager) { + QNetworkConfiguration pt; + // Try to found User Selected IAP from known IAPs (accessPointConfigurations) + pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(QString::number(qHash(iapId))); + if (pt.d) { + return pt; + } else { + // Check if new (WLAN) IAP was created in IAP/SNAP dialog + // 1. Sync internal configurations array to commsdb first + ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->updateConfigurations(); + // 2. Check if new configuration was created during connection creation + QList knownConfigs = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys(); + if (knownConfigs.count() > iKnownConfigsBeforeConnectionStart.count()) { + // Configuration count increased => new configuration was created + // => Search new, created configuration + QString newIapId; + for (int i=0; i < iKnownConfigsBeforeConnectionStart.count(); i++) { + if (knownConfigs[i] != iKnownConfigsBeforeConnectionStart[i]) { + newIapId = knownConfigs[i]; + break; + } + } + if (newIapId.isEmpty()) { + newIapId = knownConfigs[knownConfigs.count()-1]; + } + pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(newIapId); + if (pt.d) { + return pt; + } + } + } + } + return QNetworkConfiguration(); + } + + return publicConfig; +} + +void QNetworkSessionPrivate::RunL() +{ + TInt statusCode = iStatus.Int(); + + switch (statusCode) { + case KErrNone: // Connection created succesfully + { + TInt error = KErrNone; + QNetworkConfiguration newActiveConfig = activeConfiguration(); + if (!newActiveConfig.isValid()) { + error = KErrGeneral; + } else if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = newActiveConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + error = iDynamicSetdefaultif(&ifr); + } + + if (error != KErrNone) { + isOpen = false; + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + return; + } + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + // Activate ALR monitoring + iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this); + } +#endif + isOpen = true; + activeConfig = newActiveConfig; + activeInterface = interface(activeConfig.d.data()->numericId); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + QNetworkConfiguration pt; + pt.d = activeConfig.d.data()->serviceNetworkPtr; + serviceConfig = pt; + } + + startTime = QDateTime::currentDateTime(); + + newState(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + } + break; + case KErrNotFound: // Connection failed + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::InvalidConfigurationError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + break; + case KErrCancel: // Connection attempt cancelled + case KErrAlreadyExists: // Connection already exists + default: + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + break; + } +} + +void QNetworkSessionPrivate::DoCancel() +{ + iConnection.Close(); +} + +bool QNetworkSessionPrivate::newState(QNetworkSession::State newState, TUint accessPointId) +{ + // Make sure that activeConfig is always updated when SNAP is signaled to be + // connected. + if (isOpen && publicConfig.type() == QNetworkConfiguration::ServiceNetwork && + newState == QNetworkSession::Connected) { + activeConfig = activeConfiguration(accessPointId); + activeInterface = interface(activeConfig.d.data()->numericId); + } + + // Make sure that same state is not signaled twice in a row. + if (state == newState) { + return true; + } + + // Make sure that Connecting state does not overwrite Roaming state + if (state == QNetworkSession::Roaming && newState == QNetworkSession::Connecting) { + return false; + } + + bool emitSessionClosed = false; + if (isOpen && state == QNetworkSession::Connected && newState == QNetworkSession::Disconnected) { + // Active & Connected state should change directly to Disconnected state + // only when something forces connection to close (eg. when another + // application or session stops connection or when network drops + // unexpectedly). + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::SessionAbortedError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + // Start monitoring changes in IAP states + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + emitSessionClosed = true; // Emit SessionClosed after state change has been reported + } + + bool retVal = false; + if (accessPointId == 0) { + state = newState; + emit q->stateChanged(state); + retVal = true; + } else { + if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (publicConfig.d.data()->numericId == accessPointId) { + state = newState; + emit q->stateChanged(state); + retVal = true; + } + } else if (publicConfig.type() == QNetworkConfiguration::UserChoice && isOpen) { + if (activeConfig.d.data()->numericId == accessPointId) { + state = newState; + emit q->stateChanged(state); + retVal = true; + } + } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++) { + if (subConfigurations[i].d.data()->numericId == accessPointId) { + if (newState == QNetworkSession::Connected) { + // Make sure that when AccessPoint is reported to be Connected + // also state of the related configuration changes to Active. + subConfigurations[i].d.data()->state = QNetworkConfiguration::Active; + + state = newState; + emit q->stateChanged(state); + retVal = true; + } else { + if (newState == QNetworkSession::Disconnected) { + // Make sure that when AccessPoint is reported to be disconnected + // also state of the related configuration changes from Active to Defined. + subConfigurations[i].d.data()->state = QNetworkConfiguration::Defined; + } + QNetworkConfiguration config = bestConfigFromSNAP(publicConfig); + if ((config.state() == QNetworkConfiguration::Defined) || + (config.state() == QNetworkConfiguration::Discovered)) { + state = newState; + emit q->stateChanged(state); + retVal = true; + } + } + } + } + } + } + + if (emitSessionClosed) { + emit q->closed(); + } + + return retVal; +} + +void QNetworkSessionPrivate::handleSymbianConnectionStatusChange(TInt aConnectionStatus, + TInt aError, + TUint accessPointId) +{ + switch (aConnectionStatus) + { + // Connection unitialised + case KConnectionUninitialised: + break; + + // Starting connetion selection + case KStartingSelection: + break; + + // Selection finished + case KFinishedSelection: + if (aError == KErrNone) + { + // The user successfully selected an IAP to be used + break; + } + else + { + // The user pressed e.g. "Cancel" and did not select an IAP + newState(QNetworkSession::Disconnected,accessPointId); + } + break; + + // Connection failure + case KConnectionFailure: + newState(QNetworkSession::NotAvailable); + break; + + // Prepearing connection (e.g. dialing) + case KPsdStartingConfiguration: + case KPsdFinishedConfiguration: + case KCsdFinishedDialling: + case KCsdScanningScript: + case KCsdGettingLoginInfo: + case KCsdGotLoginInfo: + break; + + // Creating connection (e.g. GPRS activation) + case KCsdStartingConnect: + case KCsdFinishedConnect: + newState(QNetworkSession::Connecting,accessPointId); + break; + + // Starting log in + case KCsdStartingLogIn: + break; + + // Finished login + case KCsdFinishedLogIn: + break; + + // Connection open + case KConnectionOpen: + break; + + case KLinkLayerOpen: + newState(QNetworkSession::Connected,accessPointId); + break; + + // Connection blocked or suspended + case KDataTransferTemporarilyBlocked: + break; + + // Hangup or GRPS deactivation + case KConnectionStartingClose: + newState(QNetworkSession::Closing,accessPointId); + break; + + // Connection closed + case KConnectionClosed: + break; + + case KLinkLayerClosed: + newState(QNetworkSession::Disconnected,accessPointId); + break; + + // Unhandled state + default: + break; + } +} + +void QNetworkSessionPrivate::EventL(const CConnMonEventBase& aEvent) +{ + switch (aEvent.EventType()) + { + case EConnMonConnectionStatusChange: + { + CConnMonConnectionStatusChange* realEvent; + realEvent = (CConnMonConnectionStatusChange*) &aEvent; + + TUint connectionId = realEvent->ConnectionId(); + TInt connectionStatus = realEvent->ConnectionStatus(); + + // Try to Find IAP Id using connection Id + TUint apId = 0; + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].d.data()->connectionId == connectionId) { + apId = subConfigurations[i].d.data()->numericId; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (publicConfig.d.data()->connectionId == connectionId) { + apId = publicConfig.d.data()->numericId; + } + } + + if (apId > 0) { + handleSymbianConnectionStatusChange(connectionStatus, KErrNone, apId); + } + } + break; + + case EConnMonCreateConnection: + { + CConnMonCreateConnection* realEvent; + realEvent = (CConnMonCreateConnection*) &aEvent; + TUint apId; + TUint connectionId = realEvent->ConnectionId(); + TRequestStatus status; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + // Store connection id to related AccessPoint Configuration + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].d.data()->numericId == apId) { + subConfigurations[i].d.data()->connectionId = connectionId; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (publicConfig.d.data()->numericId == apId) { + publicConfig.d.data()->connectionId = connectionId; + } + } + } + } + break; + + case EConnMonDeleteConnection: + { + CConnMonDeleteConnection* realEvent; + realEvent = (CConnMonDeleteConnection*) &aEvent; + TUint connectionId = realEvent->ConnectionId(); + // Remove connection id from related AccessPoint Configuration + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].d.data()->connectionId == connectionId) { + subConfigurations[i].d.data()->connectionId = 0; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (publicConfig.d.data()->connectionId == connectionId) { + publicConfig.d.data()->connectionId = 0; + } + } + } + break; + + default: + // For unrecognized events + break; + } +} + +ConnectionProgressNotifier::ConnectionProgressNotifier(QNetworkSessionPrivate& owner, RConnection& connection) + : CActive(CActive::EPriorityStandard), iOwner(owner), iConnection(connection) +{ + CActiveScheduler::Add(this); +} + +ConnectionProgressNotifier::~ConnectionProgressNotifier() +{ + Cancel(); +} + +void ConnectionProgressNotifier::StartNotifications() +{ + if (!IsActive()) { + SetActive(); + } + iConnection.ProgressNotification(iProgress, iStatus); +} + +void ConnectionProgressNotifier::StopNotifications() +{ + Cancel(); +} + +void ConnectionProgressNotifier::DoCancel() +{ + iConnection.CancelProgressNotification(); +} + +void ConnectionProgressNotifier::RunL() +{ + if (iStatus == KErrNone) { + iOwner.handleSymbianConnectionStatusChange(iProgress().iStage, iProgress().iError); + + SetActive(); + iConnection.ProgressNotification(iProgress, iStatus); + } +} + +#include "moc_qnetworksession_s60_p.cpp" + +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksession_s60_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksession_s60_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKSESSIONPRIVATE_H +#define QNETWORKSESSIONPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworksession.h" + +#include + +#include +#include +#include +#include +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include +#endif + +typedef int(*TOpenCSetdefaultifFunction)(const struct ifreq*); + +QTM_BEGIN_NAMESPACE + +class ConnectionProgressNotifier; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +class QNetworkSessionPrivate : public QObject, public CActive, public MMobilityProtocolResp, + public MConnectionMonitorObserver +#else +class QNetworkSessionPrivate : public QObject, public CActive, public MConnectionMonitorObserver +#endif +{ + Q_OBJECT +public: + QNetworkSessionPrivate(); + ~QNetworkSessionPrivate(); + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + + void setALREnabled(bool enabled); + + void open(); + void close(bool allowSignals = true); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +public: // From MMobilityProtocolResp + void PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo, + TAccessPointInfo aNewAPInfo, + TBool aIsUpgrade, + TBool aIsSeamless); + + void NewCarrierActive(TAccessPointInfo aNewAPInfo, TBool aIsSeamless); + + void Error(TInt aError); +#endif + +Q_SIGNALS: + //releases any pending waitForOpened() calls + void quitPendingWaitsForOpened(); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // MConnectionMonitorObserver + void EventL(const CConnMonEventBase& aEvent); + +private: + TUint iapClientCount(TUint aIAPId) const; + quint64 transferredData(TUint dataType) const; + bool newState(QNetworkSession::State newState, TUint accessPointId = 0); + void handleSymbianConnectionStatusChange(TInt aConnectionStatus, TInt aError, TUint accessPointId = 0); + QNetworkConfiguration bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const; + QNetworkConfiguration activeConfiguration(TUint32 iapId = 0) const; + QNetworkInterface interface(TUint iapId) const; + +private: // data + // The config set on QNetworkSession + mutable QNetworkConfiguration publicConfig; + + // If publicConfig is a ServiceNetwork this is a copy of publicConfig. + // If publicConfig is an UserChoice that is resolved to a ServiceNetwork this is the actual + // ServiceNetwork configuration. + mutable QNetworkConfiguration serviceConfig; + + // This is the actual active configuration currently in use by the session. + // Either a copy of publicConfig or one of serviceConfig.children(). + mutable QNetworkConfiguration activeConfig; + + mutable QNetworkInterface activeInterface; + + QNetworkSession::State state; + bool isOpen; + + QNetworkSession* q; + QDateTime startTime; + + RLibrary iOpenCLibrary; + TOpenCSetdefaultifFunction iDynamicSetdefaultif; + + mutable RSocketServ iSocketServ; + mutable RConnection iConnection; + mutable RConnectionMonitor iConnectionMonitor; + ConnectionProgressNotifier* ipConnectionNotifier; +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + CActiveCommsMobilityApiExt* iMobility; +#endif + + QNetworkSession::SessionError iError; + TInt iALREnabled; + TBool iALRUpgradingConnection; + + QList iKnownConfigsBeforeConnectionStart; + + TUint32 iOldRoamingIap; + TUint32 iNewRoamingIap; + + friend class QNetworkSession; + friend class ConnectionProgressNotifier; +}; + +class ConnectionProgressNotifier : public CActive +{ +public: + ConnectionProgressNotifier(QNetworkSessionPrivate& owner, RConnection& connection); + ~ConnectionProgressNotifier(); + + void StartNotifications(); + void StopNotifications(); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // Data + QNetworkSessionPrivate& iOwner; + RConnection& iConnection; + TNifProgressBuf iProgress; + +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKSESSIONPRIVATE_H + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksessionengine.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksessionengine.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworksessionengine_p.h" + +QTM_BEGIN_NAMESPACE + +QNetworkSessionEngine::QNetworkSessionEngine(QObject *parent) +: QObject(parent) +{ +} + +QNetworkSessionEngine::~QNetworkSessionEngine() +{ +} + +#include "moc_qnetworksessionengine_p.cpp" +QTM_END_NAMESPACE + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksessionengine_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksessionengine_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKSESSIONENGINE_P_H +#define QNETWORKSESSIONENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class QNetworkSessionEngine : public QObject +{ + Q_OBJECT + +public: + enum ConnectionError { + InterfaceLookupError = 0, + ConnectError, + OperationNotSupported, + DisconnectionError, + }; + + QNetworkSessionEngine(QObject *parent = 0); + virtual ~QNetworkSessionEngine(); + + virtual QList getConfigurations(bool *ok = 0) = 0; + virtual QString getInterfaceFromId(const QString &id) = 0; + virtual bool hasIdentifier(const QString &id) = 0; + + //virtual QString bearerName(const QString &id) = 0; + + virtual void connectToId(const QString &id) = 0; + virtual void disconnectFromId(const QString &id) = 0; + + virtual void requestUpdate() = 0; + +Q_SIGNALS: + void configurationsChanged(); + void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); +}; + +QTM_END_NAMESPACE + +#endif diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnetworksessionengine_win_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnetworksessionengine_win_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKSESSIONENGINE_WIN_P_H +#define QNETWORKSESSIONENGINE_WIN_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#undef interface +#include + +#ifndef NS_NLA + +#define NS_NLA 15 + +enum NLA_BLOB_DATA_TYPE { + NLA_RAW_DATA = 0, + NLA_INTERFACE = 1, + NLA_802_1X_LOCATION = 2, + NLA_CONNECTIVITY = 3, + NLA_ICS = 4 +}; + +enum NLA_CONNECTIVITY_TYPE { + NLA_NETWORK_AD_HOC = 0, + NLA_NETWORK_MANAGED = 1, + NLA_NETWORK_UNMANAGED = 2, + NLA_NETWORK_UNKNOWN = 3 +}; + +enum NLA_INTERNET { + NLA_INTERNET_UNKNOWN = 0, + NLA_INTERNET_NO = 1, + NLA_INTERNET_YES = 2 +}; + +struct NLA_BLOB { + struct { + NLA_BLOB_DATA_TYPE type; + DWORD dwSize; + DWORD nextOffset; + } header; + + union { + // NLA_RAW_DATA + CHAR rawData[1]; + + // NLA_INTERFACE + struct { + DWORD dwType; + DWORD dwSpeed; + CHAR adapterName[1]; + } interfaceData; + + // NLA_802_1X_LOCATION + struct { + CHAR information[1]; + } locationData; + + // NLA_CONNECTIVITY + struct { + NLA_CONNECTIVITY_TYPE type; + NLA_INTERNET internet; + } connectivity; + + // NLA_ICS + struct { + struct { + DWORD speed; + DWORD type; + DWORD state; + WCHAR machineName[256]; + WCHAR sharedAdapterName[256]; + } remote; + } ICS; + } data; +}; +#endif + +enum NDIS_MEDIUM { + NdisMedium802_3 = 0, +}; + +enum NDIS_PHYSICAL_MEDIUM { + NdisPhysicalMediumWirelessLan = 1, + NdisPhysicalMediumBluetooth = 10, + NdisPhysicalMediumWiMax = 12, +}; + +#define OID_GEN_MEDIA_SUPPORTED 0x00010103 +#define OID_GEN_PHYSICAL_MEDIUM 0x00010202 + +#define IOCTL_NDIS_QUERY_GLOBAL_STATS \ + CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) + +#endif // QNETWORKSESSIONENGINE_WIN_P_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnlaengine_win.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnlaengine_win.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,600 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnlaengine_win_p.h" +#include "qnetworkconfiguration_p.h" + +#include +#include +#include +#include + +#include + +#include "qnetworksessionengine_win_p.h" + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) + +QWindowsSockInit::QWindowsSockInit() +: version(0) +{ + //### should we try for 2.2 on all platforms ?? + WSAData wsadata; + + // IPv6 requires Winsock v2.0 or better. + if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) { + qWarning("QBearerManagementAPI: WinSock v2.0 initialization failed."); + } else { + version = 0x20; + } +} + +QWindowsSockInit::~QWindowsSockInit() +{ + WSACleanup(); +} + +#ifdef BEARER_MANAGEMENT_DEBUG +static void printBlob(NLA_BLOB *blob) +{ + qDebug() << "==== BEGIN NLA_BLOB ===="; + + qDebug() << "type:" << blob->header.type; + qDebug() << "size:" << blob->header.dwSize; + qDebug() << "next offset:" << blob->header.nextOffset; + + switch (blob->header.type) { + case NLA_RAW_DATA: + qDebug() << "Raw Data"; + qDebug() << '\t' << blob->data.rawData; + break; + case NLA_INTERFACE: + qDebug() << "Interface"; + qDebug() << "\ttype:" << blob->data.interfaceData.dwType; + qDebug() << "\tspeed:" << blob->data.interfaceData.dwSpeed; + qDebug() << "\tadapter:" << blob->data.interfaceData.adapterName; + break; + case NLA_802_1X_LOCATION: + qDebug() << "802.1x Location"; + qDebug() << '\t' << blob->data.locationData.information; + break; + case NLA_CONNECTIVITY: + qDebug() << "Connectivity"; + qDebug() << "\ttype:" << blob->data.connectivity.type; + qDebug() << "\tinternet:" << blob->data.connectivity.internet; + break; + case NLA_ICS: + qDebug() << "ICS"; + qDebug() << "\tspeed:" << blob->data.ICS.remote.speed; + qDebug() << "\ttype:" << blob->data.ICS.remote.type; + qDebug() << "\tstate:" << blob->data.ICS.remote.state; + qDebug() << "\tmachine name:" << blob->data.ICS.remote.machineName; + qDebug() << "\tshared adapter name:" << blob->data.ICS.remote.sharedAdapterName; + break; + default: + qDebug() << "UNKNOWN BLOB TYPE"; + } + + qDebug() << "===== END NLA_BLOB ====="; +} +#endif + +static QString qGetInterfaceType(const QString &interface) +{ +#ifdef Q_OS_WINCE + Q_UNUSED(interface) +#else + unsigned long oid; + DWORD bytesWritten; + + NDIS_MEDIUM medium; + NDIS_PHYSICAL_MEDIUM physicalMedium; + + HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, + FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (handle == INVALID_HANDLE_VALUE) + return QLatin1String("Unknown"); + + oid = OID_GEN_MEDIA_SUPPORTED; + bytesWritten = 0; + bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &medium, sizeof(medium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + return QLatin1String("Unknown"); + } + + oid = OID_GEN_PHYSICAL_MEDIUM; + bytesWritten = 0; + result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + + if (medium == NdisMedium802_3) + return QLatin1String("Ethernet"); + else + return QLatin1String("Unknown"); + } + + CloseHandle(handle); + + if (medium == NdisMedium802_3) { + switch (physicalMedium) { + case NdisPhysicalMediumWirelessLan: + return QLatin1String("WLAN"); + case NdisPhysicalMediumBluetooth: + return QLatin1String("Bluetooth"); + case NdisPhysicalMediumWiMax: + return QLatin1String("WiMAX"); + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Physical Medium" << physicalMedium; +#endif + return QLatin1String("Ethernet"); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << medium << physicalMedium; +#endif + +#endif + + return QLatin1String("Unknown"); +} + +class QNlaThread : public QThread +{ + Q_OBJECT + +public: + QNlaThread(QNlaEngine *parent = 0); + ~QNlaThread(); + + QList getConfigurations(); + + void forceUpdate(); + +protected: + virtual void run(); + +private: + void updateConfigurations(QList &configs); + DWORD parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const; + QNetworkConfigurationPrivate *parseQuerySet(const WSAQUERYSET *querySet) const; + void fetchConfigurations(); + +signals: + void networksChanged(); + +private: + QMutex mutex; + HANDLE handle; + bool done; + QList fetchedConfigurations; +}; + +QNlaThread::QNlaThread(QNlaEngine *parent) +: QThread(parent), handle(0), done(false) +{ +} + +QNlaThread::~QNlaThread() +{ + mutex.lock(); + + done = true; + + if (handle) { + /* cancel completion event */ + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + } + mutex.unlock(); + + wait(); +} + +QList QNlaThread::getConfigurations() +{ + QMutexLocker locker(&mutex); + + QList foundConfigurations; + + for (int i = 0; i < fetchedConfigurations.count(); ++i) { + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; + config->name = fetchedConfigurations.at(i)->name; + config->isValid = fetchedConfigurations.at(i)->isValid; + config->id = fetchedConfigurations.at(i)->id; + config->state = fetchedConfigurations.at(i)->state; + config->type = fetchedConfigurations.at(i)->type; + config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; + config->purpose = fetchedConfigurations.at(i)->purpose; + config->internet = fetchedConfigurations.at(i)->internet; + if (QNlaEngine *engine = qobject_cast(parent())) { + config->bearer = engine->bearerName(config->id); + } + + foundConfigurations.append(config); + } + + return foundConfigurations; +} + +void QNlaThread::forceUpdate() +{ + mutex.lock(); + + if (handle) { + /* cancel completion event */ + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + handle = 0; + } + mutex.unlock(); +} + +void QNlaThread::run() +{ + WSAEVENT changeEvent = WSACreateEvent(); + if (changeEvent == WSA_INVALID_EVENT) { + qWarning("WSACreateEvent error %d", WSAGetLastError()); + return; + } + + while (true) { + fetchConfigurations(); + + WSAQUERYSET qsRestrictions; + + memset(&qsRestrictions, 0, sizeof(qsRestrictions)); + qsRestrictions.dwSize = sizeof(qsRestrictions); + qsRestrictions.dwNameSpace = NS_NLA; + + mutex.lock(); + if (done) { + mutex.unlock(); + break; + } + int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &handle); + mutex.unlock(); + + if (result == SOCKET_ERROR) { + qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + break; + } + + WSACOMPLETION completion; + WSAOVERLAPPED overlapped; + + memset(&overlapped, 0, sizeof(overlapped)); + overlapped.hEvent = changeEvent; + + memset(&completion, 0, sizeof(completion)); + completion.Type = NSP_NOTIFY_EVENT; + completion.Parameters.Event.lpOverlapped = &overlapped; + + DWORD bytesReturned = 0; + result = WSANSPIoctl(handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0, + &bytesReturned, &completion); + if (result == SOCKET_ERROR) { + int error = WSAGetLastError(); + if (error != WSA_IO_PENDING) { + qWarning("WSANSPIoctl error %d", error); + break; + } + } + +#ifndef Q_OS_WINCE + // Not interested in unrelated IO completion events + // although we also don't want to block them + while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} +#else + WaitForSingleObject(changeEvent, WSA_INFINITE); +#endif + + mutex.lock(); + if (handle) { + result = WSALookupServiceEnd(handle); + if (result == SOCKET_ERROR) { + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + mutex.unlock(); + break; + } + handle = 0; + } + mutex.unlock(); + } + + WSACloseEvent(changeEvent); +} + +void QNlaThread::updateConfigurations(QList &configs) +{ + mutex.lock(); + + while (!fetchedConfigurations.isEmpty()) + delete fetchedConfigurations.takeFirst(); + + fetchedConfigurations = configs; + + mutex.unlock(); + + emit networksChanged(); +} + +DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const +{ +#ifdef BEARER_MANAGEMENT_DEBUG + printBlob(blob); +#endif + + switch (blob->header.type) { + case NLA_RAW_DATA: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); +#endif + break; + case NLA_INTERFACE: + cpPriv->state = QNetworkConfiguration::Active; + if (QNlaEngine *engine = qobject_cast(parent())) { + engine->configurationInterface[cpPriv->id.toUInt()] = + QString(blob->data.interfaceData.adapterName); + } + break; + case NLA_802_1X_LOCATION: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); +#endif + break; + case NLA_CONNECTIVITY: + if (blob->data.connectivity.internet == NLA_INTERNET_YES) + cpPriv->internet = true; + else + cpPriv->internet = false; +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__); +#endif + break; + case NLA_ICS: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_ICS", __FUNCTION__); +#endif + break; + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type %d", __FUNCTION__, blob->header.type); +#endif + ; + } + + return blob->header.nextOffset; +} + +QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *querySet) const +{ + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + + cpPriv->name = QString::fromWCharArray(querySet->lpszServiceInstanceName); + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(QLatin1String("NLA:") + cpPriv->name)); + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "size:" << querySet->dwSize; + qDebug() << "service instance name:" << QString::fromUtf16(querySet->lpszServiceInstanceName); + qDebug() << "service class id:" << querySet->lpServiceClassId; + qDebug() << "version:" << querySet->lpVersion; + qDebug() << "comment:" << QString::fromUtf16(querySet->lpszComment); + qDebug() << "namespace:" << querySet->dwNameSpace; + qDebug() << "namespace provider id:" << querySet->lpNSProviderId; + qDebug() << "context:" << QString::fromUtf16(querySet->lpszContext); + qDebug() << "number of protocols:" << querySet->dwNumberOfProtocols; + qDebug() << "protocols:" << querySet->lpafpProtocols; + qDebug() << "query string:" << QString::fromUtf16(querySet->lpszQueryString); + qDebug() << "number of cs addresses:" << querySet->dwNumberOfCsAddrs; + qDebug() << "cs addresses:" << querySet->lpcsaBuffer; + qDebug() << "output flags:" << querySet->dwOutputFlags; +#endif + + if (querySet->lpBlob) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "blob size:" << querySet->lpBlob->cbSize; + qDebug() << "blob data:" << querySet->lpBlob->pBlobData; +#endif + + DWORD offset = 0; + do { + NLA_BLOB *blob = reinterpret_cast(querySet->lpBlob->pBlobData + offset); + DWORD nextOffset = parseBlob(blob, cpPriv); + if (nextOffset == offset) + break; + else + offset = nextOffset; + } while (offset != 0 && offset < querySet->lpBlob->cbSize); + } + + return cpPriv; +} + +void QNlaThread::fetchConfigurations() +{ + QList foundConfigurations; + + WSAQUERYSET qsRestrictions; + HANDLE hLookup = 0; + + memset(&qsRestrictions, 0, sizeof(qsRestrictions)); + qsRestrictions.dwSize = sizeof(qsRestrictions); + qsRestrictions.dwNameSpace = NS_NLA; + + int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup); + if (result == SOCKET_ERROR) { + qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + mutex.lock(); + fetchedConfigurations.clear(); + mutex.unlock(); + } + + char buffer[0x10000]; + while (result == 0) { + DWORD bufferLength = sizeof(buffer); + result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL, + &bufferLength, reinterpret_cast(buffer)); + + if (result == SOCKET_ERROR) { + int error = WSAGetLastError(); + + if (error == WSA_E_NO_MORE) + break; + + if (error == WSAEFAULT) { + qDebug() << "buffer not big enough" << bufferLength; + break; + } + + qWarning("WSALookupServiceNext error %d", WSAGetLastError()); + break; + } + + QNetworkConfigurationPrivate *cpPriv = + parseQuerySet(reinterpret_cast(buffer)); + + foundConfigurations.append(cpPriv); + } + + if (hLookup) { + result = WSALookupServiceEnd(hLookup); + if (result == SOCKET_ERROR) { + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + } + } + + updateConfigurations(foundConfigurations); +} + +QNlaEngine::QNlaEngine(QObject *parent) +: QNetworkSessionEngine(parent), nlaThread(0) +{ + nlaThread = new QNlaThread(this); + connect(nlaThread, SIGNAL(networksChanged()), + this, SIGNAL(configurationsChanged())); + nlaThread->start(); + + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); +} + +QNlaEngine::~QNlaEngine() +{ + delete nlaThread; +} + +QList QNlaEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + + return nlaThread->getConfigurations(); +} + +QString QNlaEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QNlaEngine::hasIdentifier(const QString &id) +{ + if (configurationInterface.contains(id.toUInt())) + return true; + + bool result = false; + QList l = nlaThread->getConfigurations(); + while (!l.isEmpty()) { + QNetworkConfigurationPrivate* cpPriv = l.takeFirst(); + if (!result && cpPriv->id == id) { + result = true; + } + delete cpPriv; + } + + return result; +} + +QString QNlaEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QNlaEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QNlaEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QNlaEngine::requestUpdate() +{ + nlaThread->forceUpdate(); +} + +QNlaEngine *QNlaEngine::instance() +{ + return nlaEngine(); +} + +#include "qnlaengine_win.moc" +#include "moc_qnlaengine_win_p.cpp" +QTM_END_NAMESPACE + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnlaengine_win_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnlaengine_win_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNLAENGINE_P_H +#define QNLAENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworksessionengine_p.h" + +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class QNlaThread; + +class QWindowsSockInit +{ +public: + QWindowsSockInit(); + ~QWindowsSockInit(); + int version; +}; + +class QNlaEngine : public QNetworkSessionEngine +{ + Q_OBJECT + + friend class QNlaThread; + +public: + QNlaEngine(QObject *parent = 0); + ~QNlaEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QNlaEngine *instance(); + +private: + QWindowsSockInit winSock; + QNlaThread *nlaThread; + QMap configurationInterface; +}; + +QTM_END_NAMESPACE + +#endif diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnmdbushelper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnmdbushelper.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// this class is for helping qdbus get stuff + +#include "qnmdbushelper_p.h" + +#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) +#include "qnetworkmanagerservice_p.h" + +#include +#include +#include +#include +#endif + +#include + +QTM_BEGIN_NAMESPACE + + +QNmDBusHelper::QNmDBusHelper(QObject * parent) + : QObject(parent) +{ +} + +QNmDBusHelper::~QNmDBusHelper() +{ +} + +void QNmDBusHelper::deviceStateChanged(quint32 state) + { + QDBusMessage msg = this->message(); + if(state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + emit pathForStateChanged(msg.path(), state); + } + } + +void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointAdded(msg.path(), path); + } +} + +void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointRemoved(msg.path(), path); + } +} + +void QNmDBusHelper::slotPropertiesChanged(QMap map) +{ + QDBusMessage msg = this->message(); + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { //state only applies to device interfaces + quint32 state = i.value().toUInt(); + if( state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + emit pathForPropertiesChanged( msg.path(), map); + } + } else if( i.key() == "ActiveAccessPoint") { + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value().path(); + // } else if( i.key() == "Strength") + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); + // else + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); + } + } +} + +void QNmDBusHelper::slotSettingsRemoved() +{ + QDBusMessage msg = this->message(); + emit pathForSettingsRemoved(msg.path()); +} + +#include "moc_qnmdbushelper_p.cpp" +QTM_END_NAMESPACE diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnmdbushelper_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnmdbushelper_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNMDBUSHELPERPRIVATE_H +#define QNMDBUSHELPERPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) +#include +#include +#include +#endif + +QTM_BEGIN_NAMESPACE + +#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) + +class QNmDBusHelper: public QObject, protected QDBusContext + { + Q_OBJECT + public: + QNmDBusHelper(QObject *parent = 0); + ~QNmDBusHelper(); + + public slots: + void deviceStateChanged(quint32); + void slotAccessPointAdded( QDBusObjectPath ); + void slotAccessPointRemoved( QDBusObjectPath ); + void slotPropertiesChanged( QMap); + void slotSettingsRemoved(); + +Q_SIGNALS: + void pathForStateChanged(const QString &, quint32); + void pathForAccessPointAdded(const QString &, QDBusObjectPath ); + void pathForAccessPointRemoved(const QString &, QDBusObjectPath ); + void pathForPropertiesChanged(const QString &, QMap); + void pathForSettingsRemoved(const QString &); +}; +#endif + +QTM_END_NAMESPACE + +#endif// QNMDBUSHELPERPRIVATE_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnmwifiengine_unix.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnmwifiengine_unix.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,856 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnmwifiengine_unix_p.h" +#include "qnetworkconfiguration_p.h" +#include + +#include +#include + +#include +#include + +#include + +QTM_BEGIN_NAMESPACE +Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) +typedef QList > QNmSettingsAddressMap; +QTM_END_NAMESPACE + +Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QNmSettingsAddressMap)) + +QTM_BEGIN_NAMESPACE + +QNmWifiEngine::QNmWifiEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + iface = new QNetworkManagerInterface(this); + if(!iface->isValid()) { + return; + } + iface->setConnections(); + connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), + this,SLOT(addDevice(QDBusObjectPath))); +// connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), +// this,SLOT(removeDevice(QDBusObjectPath))); + connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), + this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); + + QList list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + addDevice(path); + } + + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + QNetworkManagerSettings *settingsiface; + foreach (QString service, connectionServices) { + settingsiface = new QNetworkManagerSettings(service, this); + settingsiface->setConnections(); + connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), + this,(SLOT(newConnection(QDBusObjectPath)))); + } + + updated = false; +} + +QNmWifiEngine::~QNmWifiEngine() +{ +} + +QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) +{ + QString newname; + if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface->ip4config().path(); + QNetworkManagerIp4Config * ipIface; + ipIface = new QNetworkManagerIp4Config(path); + newname = ipIface->domains().join(" "); + delete ipIface; + } + //fallback to interface name + if(newname.isEmpty()) + newname = devIface->networkInterface().name(); + return newname; +} + + +QList QNmWifiEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = false; + + if(!updated) { + foundConfigurations.clear(); + if(knownSsids.isEmpty()) + updateKnownSsids(); + + scanForAccessPoints(); + updateActiveConnectionsPaths(); + knownConnections(); + + accessPointConnections(); + + updated = true; + } + return foundConfigurations; +} + +void QNmWifiEngine::knownConnections() +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + + QString connPath; + + QScopedPointer settingsiface; + foreach (QString service, connectionServices) { + QString ident; + settingsiface.reset(new QNetworkManagerSettings(service)); + QList list = settingsiface->listConnections(); + + QNetworkManagerSettingsConnection *sysIface; + foreach(QDBusObjectPath path, list) { + ident = path.path(); + bool addIt = false; + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + sysIface = new QNetworkManagerSettingsConnection(service, path.path(), this); + sysIface->setConnections(); + connect(sysIface, SIGNAL(removed(QString)), + this,SLOT(settingsConnectionRemoved(QString))); + + cpPriv->name = sysIface->getId(); + cpPriv->isValid = true; + cpPriv->id = sysIface->getUuid(); + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = getStateForId(cpPriv->id); + + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + + + if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { + QString mac = sysIface->getMacAddress(); + if(!mac.length() > 2) { + QString devPath; + devPath = deviceConnectionPath(mac); + + QNetworkManagerInterfaceDevice devIface(devPath); + cpPriv->serviceInterface = devIface.networkInterface(); + QScopedPointer devWiredIface; + devWiredIface.reset(new QNetworkManagerInterfaceDeviceWired(devIface.connectionInterface()->path())); + cpPriv->internet = devWiredIface->carrier(); + + // use this mac addy + } else { + cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); + } + + cpPriv->internet = true; + + addIt = true; + } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { + QString mac = sysIface->getMacAddress();; + if(!mac.length() > 2) { + QString devPath; + devPath = deviceConnectionPath(mac); + + QNetworkManagerInterfaceDevice devIface(devPath); + cpPriv->serviceInterface = devIface.networkInterface(); + // use this mac addy + } else { + cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); + } + addIt = true; + // get the wifi interface state first.. do we need this? + // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); + } + if(addIt) { + foundConfigurations.append(cpPriv); + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + cpPriv->bearer = bearerName(cpPriv->id); + } + } + } +} + +void QNmWifiEngine::accessPointConnections() +{ + QList list = iface->getDevices(); + QScopedPointer devIface; + foreach(QDBusObjectPath path, list) { + devIface.reset(new QNetworkManagerInterfaceDevice(path.path())); + if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + QList apList = availableAccessPoints.uniqueKeys(); + + QList::const_iterator i; + for (i = apList.constBegin(); i != apList.constEnd(); ++i) { + QNetworkConfigurationPrivate* cpPriv; + cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); + if(cpPriv->isValid) { + foundConfigurations.append(cpPriv); + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + cpPriv->bearer = bearerName(cpPriv->id); + } + } + } + } +} + +QString QNmWifiEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id); +} + +bool QNmWifiEngine::hasIdentifier(const QString &id) +{ + if (configurationInterface.contains(id)) + return true; + + return false; +} + +QString QNmWifiEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + QScopedPointer devIface; + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + devIface.reset(new QNetworkManagerInterfaceDevice(path.path())); + + if(interface == devIface->networkInterface().name()) { + + switch(devIface->deviceType()) { + case DEVICE_TYPE_802_3_ETHERNET: + return QLatin1String("Ethernet"); + break; + case DEVICE_TYPE_802_11_WIRELESS: + return QLatin1String("WLAN"); + break; + case DEVICE_TYPE_GSM: + return QLatin1String("2G"); + break; + case DEVICE_TYPE_CDMA: + return QLatin1String("CDMA2000"); + break; + default: + break; + } + } + } + return QLatin1String("Unknown"); +} + +void QNmWifiEngine::connectToId(const QString &id) +{ + activatingConnectionPath = id; + QStringList connectionSettings = getConnectionPathForId(id); + if(connectionSettings.isEmpty()) { + emit connectionError(id, OperationNotSupported); + return; + } + + QDBusObjectPath connectionPath(connectionSettings.at(1)); + QString interface = getInterfaceFromId(id); + + interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); + QString devPath; + devPath = deviceConnectionPath(interface); + QDBusObjectPath devicePath(devPath); + + iface->activateConnection( + connectionSettings.at(0), + connectionPath, + devicePath, + connectionPath); +} + +void QNmWifiEngine::disconnectFromId(const QString &id) +{ + QString activeConnectionPath = getActiveConnectionPath(id); + + if (!activeConnectionPath.isEmpty()) { + QScopedPointer activeCon; + activeCon.reset(new QNetworkManagerConnectionActive(activeConnectionPath)); + QScopedPointer settingsCon; + settingsCon.reset(new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path())); + + if(settingsCon->getType() == DEVICE_TYPE_802_3_ETHERNET) { //use depreciated value for now + emit connectionError(id, OperationNotSupported); + } else { + QDBusObjectPath dbpath(activeConnectionPath); + iface->deactivateConnection(dbpath); + activatingConnectionPath = ""; + } + } +} + +void QNmWifiEngine::requestUpdate() +{ + updated = false; + knownSsids.clear(); + availableAccessPoints.clear(); + emitConfigurationsChanged(); +} + +QNmWifiEngine *QNmWifiEngine::instance() +{ + QDBusConnection dbusConnection = QDBusConnection::systemBus(); + if (dbusConnection.isConnected()) { + QDBusConnectionInterface *dbiface = dbusConnection.interface(); + QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); + if (reply.isValid() && reply.value()) + return nmWifiEngine(); + } + + return 0; +} + +void QNmWifiEngine::updateKnownSsids() +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + + QScopedPointer settingsiface; + foreach (QString service, connectionServices) { + settingsiface.reset(new QNetworkManagerSettings(service)); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection sysIface(service, path.path()); + knownSsids << sysIface.getSsid(); + } + } +} + +void QNmWifiEngine::updateActiveConnectionsPaths() +{ //need to know which connection paths are currently active/connected + QScopedPointer dbIface; + activeConnectionPaths.clear(); + dbIface.reset(new QNetworkManagerInterface); + QList connections = dbIface->activeConnections(); + foreach(QDBusObjectPath conpath, connections) { + activeConnectionPaths << conpath.path(); + } +} + +QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) +{ + + QScopedPointer devIface(new QNetworkManagerInterfaceDevice(iPath)); + QScopedPointer devWirelessIface(new QNetworkManagerInterfaceDeviceWireless(iPath)); + + QString activeAPPath = devWirelessIface->activeAccessPoint().path(); + + QScopedPointer accessPointIface(new QNetworkManagerInterfaceAccessPoint(path.path())); + + QString ident = accessPointIface->connectionInterface()->path(); + quint32 nmState = devIface->state(); + + QString ssid = accessPointIface->ssid(); + QString hwAddy = accessPointIface->hwAddress(); + QString sInterface = devIface->networkInterface().name(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + bool addIt = true; + + if(addIt) { + + cpPriv->name = ssid; + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->serviceInterface = devIface->networkInterface(); + + cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); + + if(activeAPPath == accessPointIface->connectionInterface()->path()) { + cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); + } + if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + else + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + return cpPriv; + } else { + cpPriv->isValid = false; + } + return cpPriv; +} + + + QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) +{ + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; + // this is the state of the wifi device interface + if(isKnown) + state = ( QNetworkConfiguration::Defined); + + switch(nmState) { //device interface state, not AP state + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_UNMANAGED: + case NM_DEVICE_STATE_UNAVAILABLE: + state = (QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_DISCONNECTED: + { + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + } + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + } + break; + }; + return state; +} + +QString QNmWifiEngine::getActiveConnectionPath(const QString &id) +{ + QStringList connectionSettings = getConnectionPathForId(id); + QNetworkManagerInterface ifaceD; + QList connections = ifaceD.activeConnections(); + QScopedPointer conDetailsD; + foreach(QDBusObjectPath path, connections) { + conDetailsD.reset(new QNetworkManagerConnectionActive( path.path())); + if(conDetailsD->connection().path() == connectionSettings.at(1) + && conDetailsD->serviceName() == connectionSettings.at(0)) + return path.path(); + } + return QString(); +} + + QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) + { + QNetworkConfiguration::StateFlags flag; + switch (nmstate) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_FAILED: + case NM_DEVICE_STATE_UNMANAGED: + flag = (QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + case NM_DEVICE_STATE_UNAVAILABLE: + flag = (QNetworkConfiguration::Defined); + break; + case NM_DEVICE_STATE_DISCONNECTED: + flag = ( flag | QNetworkConfiguration::Discovered ); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + flag = ( flag | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Active ); + } + break; + default: + flag = ( QNetworkConfiguration::Defined); + break; + }; + return flag; + } + +void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) +{ + if(nmState == NM_DEVICE_STATE_ACTIVATED + || nmState == NM_DEVICE_STATE_DISCONNECTED + || nmState == NM_DEVICE_STATE_UNAVAILABLE + || nmState == NM_DEVICE_STATE_FAILED) { + + QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); + switch (nmState) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_FAILED: + state = (QNetworkConfiguration::Undefined); + emit connectionError(activatingConnectionPath, ConnectError); + requestUpdate(); + break; + case NM_DEVICE_STATE_UNAVAILABLE: + state = (QNetworkConfiguration::Defined); + requestUpdate(); + break; + case NM_DEVICE_STATE_DISCONNECTED: + state = ( state | QNetworkConfiguration::Discovered ); + requestUpdate(); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + state = ( state | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Active ); + requestUpdate(); + } + break; + default: + state = ( QNetworkConfiguration::Defined); + break; + }; + } +} + +void QNmWifiEngine::addDevice(QDBusObjectPath path) +{ + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path(), this); + devIface->setConnections(); + connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), + this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); + + if(!devicePaths.contains(path.path())) + devicePaths << path.path(); + + switch(devIface->deviceType()) { + case DEVICE_TYPE_802_3_ETHERNET: + { + QNetworkManagerInterfaceDeviceWired * devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path(), this); + devWiredIface->setConnections(); + connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), + this,SLOT(cmpPropertiesChanged( const QString &, QMap))); + requestUpdate(); + } + break; + case DEVICE_TYPE_802_11_WIRELESS: + { + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path(), this); + devWirelessIface->setConnections(); + + connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), + this,SLOT(cmpPropertiesChanged( const QString &, QMap))); + + connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), + this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), + this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); + requestUpdate(); + + } + break; + default: + break; + }; +} + +void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { //only applies to device interfaces + updateDeviceInterfaceState(path, i.value().toUInt()); + } + if( i.key() == "ActiveAccessPoint") { + } + if( i.key() == "Carrier") { //someone got plugged in + } + } +} + +void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) +{ + if(aPath.contains("devices")) { + requestUpdate(); + } +} + +void QNmWifiEngine::accessPointAdded( const QString &/*aPath*/, QDBusObjectPath /*oPath*/) +{ + requestUpdate(); +} + +QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) +{ + bool isAvailable = false; + QStringList conPath = getConnectionPathForId(id); + QString aconpath = getActiveConnectionPath(id); + + if(!aconpath.isEmpty()) { + //active connection + QNetworkManagerConnectionActive aConn(aconpath); + + QList devs = aConn.devices(); + + QScopedPointer ifaceDevice; + QScopedPointer devWiredIface; + foreach(QDBusObjectPath dev, devs) { + ifaceDevice.reset(new QNetworkManagerInterfaceDevice(dev.path())); + + if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { + + if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { + // this is it! + return getStateFlag(ifaceDevice->state()); + } else { + continue; + } + + if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || + ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { + isAvailable = true; + + devWiredIface.reset(new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path())); + if(!devWiredIface->carrier()) + return QNetworkConfiguration::Defined; + } + } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + + } + + return getStateFlag(ifaceDevice->state()); + } + } else { + // not active + QScopedPointer sysIface; + sysIface.reset(new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1))); + if(sysIface->isValid()) { + if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { + QString ssid = sysIface->getSsid(); + bool ok = false; + + if(knownSsids.contains(ssid, Qt::CaseSensitive)) { + foreach(QString onessid, knownSsids) { + if(onessid == ssid && availableAccessPoints.contains(ssid)) { + ok = true; + break; + } + } + } + if(ok) + return getStateFlag(NM_DEVICE_STATE_DISCONNECTED); + else + return getStateFlag(NM_DEVICE_STATE_UNAVAILABLE); + } + } + } + + return QNetworkConfiguration::Defined; //not active, but we know this connection +} + +bool QNmWifiEngine::isAddressOfConnection(const QString &id, quint32 ipaddress) +{ + QStringList conPath = getConnectionPathForId(id); + QString aConPath = getActiveConnectionPath(id); + if(aConPath.isEmpty()) { + // not active + return false; + } + + QScopedPointer aConn; + aConn.reset(new QNetworkManagerConnectionActive(aConPath)); + QScopedPointer ifaceDevice; + QList devices = aConn->devices(); + foreach(QDBusObjectPath device, devices) { + ifaceDevice.reset(new QNetworkManagerInterfaceDevice(device.path())); + if(ifaceDevice->ip4Address() == ipaddress) { + return true; + } + } + return false; +} + +QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) +{ + // check active connections first. + QStringList conIdPath = getConnectionPathForId(id); + + QNetworkInterface interface; + QScopedPointer aConn; + + foreach(QString conpath, activeConnectionPaths) { + aConn.reset(new QNetworkManagerConnectionActive(conpath)); + if(aConn->connection().path() == conIdPath.at(1) + && aConn->serviceName() == conIdPath.at(0)) { + + QList devs = aConn->devices(); + QNetworkManagerInterfaceDevice ifaceDevice(devs[0].path()); //just take the first one + return ifaceDevice.networkInterface(); + } + } + + //try guessing + QList list = iface->getDevices(); + QScopedPointer devIface; + foreach(QDBusObjectPath path, list) { + devIface.reset(new QNetworkManagerInterfaceDevice(path.path())); + if(devIface->deviceType() == type ) { + if(devIface->state() == NM_DEVICE_STATE_DISCONNECTED) { + return devIface->networkInterface(); + } + } + } + return QNetworkInterface(); +} + +quint64 QNmWifiEngine::receivedDataForId(const QString &id) const +{ + if(configurationInterface.count() > 1) + return 0; + quint64 result = 0; + + QString devFile; + devFile = configurationInterface.value(id); + QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); + if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&rx); + in >> result; + rx.close(); + } + return result; +} + +quint64 QNmWifiEngine::sentDataForId(const QString &id) const +{ + if(configurationInterface.count() > 1) + return 0; + quint64 result = 0; + QString devFile; + devFile = configurationInterface.value(id); + + QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); + if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + return result; +} + +void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) +{ + requestUpdate(); +} + +void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) +{ + requestUpdate(); +} + +void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) +{ + QDBusPendingReply reply = *openCall; + if (reply.isError()) { + qWarning() <<"Error" << reply.error().name() << reply.error().message() + < list = iface->getDevices(); + + QScopedPointer devIface; + QScopedPointer devWirelessIface; + QScopedPointer accessPointIface; + foreach(QDBusObjectPath path, list) { + devIface.reset(new QNetworkManagerInterfaceDevice(path.path())); + + if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + + devWirelessIface.reset(new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path())); + ////////////// AccessPoints + QList apList = devWirelessIface->getAccessPoints(); + + foreach(QDBusObjectPath path, apList) { + accessPointIface.reset(new QNetworkManagerInterfaceAccessPoint(path.path())); + QString ssid = accessPointIface->ssid(); + availableAccessPoints.insert(ssid, path); + } + } + } +} + +QString QNmWifiEngine::deviceConnectionPath(const QString &mac) +{ + QString newMac = mac; + newMac = newMac.replace(":","_").toLower(); + //device object path might not contain just mac address + //might contain extra numbers on the end. thanks HAL + foreach(QString device, devicePaths) { + if(device.contains(newMac)) { + newMac = device; + break; + } + } + return newMac; +} + +QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + QScopedPointer settingsiface; + foreach (QString service, connectionServices) { + settingsiface.reset(new QNetworkManagerSettings(service)); + QList list = settingsiface->listConnections(); + QScopedPointer sysIface; + foreach(QDBusObjectPath path, list) { + sysIface.reset(new QNetworkManagerSettingsConnection(service, path.path())); + if(sysIface->getUuid() == uuid) + return QStringList() << service << sysIface->connectionInterface()->path(); + } + } + return QStringList(); +} + +#include "moc_qnmwifiengine_unix_p.cpp" + +QTM_END_NAMESPACE + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/bearer/qnmwifiengine_unix_p.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/bearer/qnmwifiengine_unix_p.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,159 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNMWIFIENGINE_P_H +#define QNMWIFIENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +//#include + +#include +#include +#include +#include + +#include "qnetworksessionengine_p.h" +#include +#include +#include + + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNmWifiEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNmWifiEngine(QObject *parent = 0); + ~QNmWifiEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QNmWifiEngine *instance(); + + QStringList knownSsids; + inline void emitConfigurationsChanged() { emit configurationsChanged(); } + QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); + + QStringList getConnectionPathForId(const QString &uuid); + //QString getConnectionPathForId(const QString &name = QString()); + quint64 sentDataForId(const QString &id) const; + quint64 receivedDataForId(const QString &id) const; + +private: + bool updated; + QString activatingConnectionPath; + QStringList activeConnectionPaths; + + + QMap availableAccessPoints; + void scanForAccessPoints(); + + QStringList devicePaths; + + void updateActiveConnectionsPaths(); + void updateKnownSsids(); + void accessPointConnections(); + void knownConnections(); + QString deviceConnectionPath(const QString &mac); + + QList foundConfigurations; + // QHash > allConfigurations; + + QNetworkManagerInterface *iface; + + QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); + QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); + + QString getActiveConnectionPath(const QString &identifier); + QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); + + QNetworkConfiguration::StateFlags getStateForId(const QString &id); + + QNetworkInterface getBestInterface(quint32 type, const QString &conPath); + + QMap configurationInterface; + + bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); + +private slots: + void updateDeviceInterfaceState(const QString &, quint32); + void addDevice(QDBusObjectPath path); + +Q_SIGNALS: + void configurationChanged(const QNetworkConfiguration& config); + +private slots: + void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); + void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); + void cmpPropertiesChanged(const QString &, QMap map); + void newConnection(QDBusObjectPath); + void settingsConnectionRemoved(const QString &); + void slotActivationFinished(QDBusPendingCallWatcher*); +}; + +QTM_END_NAMESPACE + +#endif + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/global/global.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/global/global.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,25 @@ +#for now we do not actually have anything to build +#just ensure installation of public headers +TEMPLATE = subdirs + +include(../../common.pri) +PUBLIC_HEADERS += qmobilityglobal.h + +headers.files = $$PUBLIC_HEADERS +headers.path = $$QT_MOBILITY_INCLUDE +INSTALLS+= headers + +symbian { + path=$$MW_LAYER_PUBLIC_EXPORT_PATH("") + + exportPath=$$EPOCROOT"."$$dirname(path) + nativePath=$$replace(exportPath, /,\) + exists($$nativePath) { + } else { + system($$QMAKE_MKDIR $$nativePath) + } + + for(header, headers.files) { + BLD_INF_RULES.prj_exports += "$$header $$MW_LAYER_PUBLIC_EXPORT_PATH($$basename(header))" + } +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/global/qmobilityglobal.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/global/qmobilityglobal.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMOBILITYGLOBAL_H +#define QMOBILITYGLOBAL_H + + +#define QTM_VERSION_STR "1.0.0" +/* + QTM_VERSION is (major << 16) + (minor << 8) + patch. +*/ +#define QTM_VERSION 0x010000 +/* + can be used like #if (QTM_VERSION >= QTM_VERSION_CHECK(1, 0, 0)) +*/ +#define QTM_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) + +#define QTM_PACKAGEDATE_STR "YYYY-MM-DD" + +#define QTM_PACKAGE_TAG "" + +#if defined(QTM_BUILD_UNITTESTS) +# include +# if !defined(QT_BUILD_INTERNAL) +# define QT_BUILD_INTERNAL +# endif +#endif +#include + +#if defined(SYMBIAN_DATABASEMANAGER_SERVER) +# define Q_SERVICEFW_EXPORT +#else +# if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) +# if defined(QT_NODLL) +# undef QT_MAKEDLL +# undef QT_DLL +# elif defined(QT_MAKEDLL) +# if defined(QT_DLL) +# undef QT_DLL +# endif +# if defined(QT_BUILD_BEARER_LIB) +# define Q_BEARER_EXPORT Q_DECL_EXPORT +# else +# define Q_BEARER_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_CFW_LIB) +# define Q_PUBLISHSUBSCRIBE_EXPORT Q_DECL_EXPORT +# else +# define Q_PUBLISHSUBSCRIBE_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_CONTACTS_LIB) +# define Q_CONTACTS_EXPORT Q_DECL_EXPORT +# else +# define Q_CONTACTS_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_VERSIT_LIB) +# define Q_VERSIT_EXPORT Q_DECL_EXPORT +# else +# define Q_VERSIT_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_LOCATION_LIB) +# define Q_LOCATION_EXPORT Q_DECL_EXPORT +# else +# define Q_LOCATION_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_MESSAGING_LIB) +# define Q_MESSAGING_EXPORT Q_DECL_EXPORT +# else +# define Q_MESSAGING_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_MEDIA_LIB) +# define Q_MEDIA_EXPORT Q_DECL_EXPORT +# else +# define Q_MEDIA_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_SFW_LIB) +# define Q_SERVICEFW_EXPORT Q_DECL_EXPORT +# else +# define Q_SERVICEFW_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_SYSINFO_LIB) +# define Q_SYSINFO_EXPORT Q_DECL_EXPORT +# else +# define Q_SYSINFO_EXPORT Q_DECL_IMPORT +# endif +# if defined(QT_BUILD_SENSORS_LIB) +# define Q_SENSORS_EXPORT Q_DECL_EXPORT +# else +# define Q_SENSORS_EXPORT Q_DECL_IMPORT +# endif +# elif defined(QT_DLL) /* use a Qt DLL library */ +# define Q_BEARER_EXPORT Q_DECL_IMPORT +# define Q_PUBLISHSUBSCRIBE_EXPORT Q_DECL_IMPORT +# define Q_CONTACTS_EXPORT Q_DECL_IMPORT +# define Q_VERSIT_EXPORT Q_DECL_IMPORT +# define Q_LOCATION_EXPORT Q_DECL_IMPORT +# define Q_MEDIA_EXPORT Q_DECL_IMPORT +# define Q_MESSAGING_EXPORT Q_DECL_IMPORT +# define Q_SERVICEFW_EXPORT Q_DECL_IMPORT +# define Q_SYSINFO_EXPORT Q_DECL_IMPORT +# define Q_SENSORS_EXPORT Q_DECL_IMPORT +# endif +# else +# endif +# if !defined(Q_SERVICEFW_EXPORT) +# if defined(QT_SHARED) +# define Q_BEARER_EXPORT Q_DECL_EXPORT +# define Q_PUBLISHSUBSCRIBE_EXPORT Q_DECL_EXPORT +# define Q_CONTACTS_EXPORT Q_DECL_EXPORT +# define Q_VERSIT_EXPORT Q_DECL_EXPORT +# define Q_LOCATION_EXPORT Q_DECL_EXPORT +# define Q_MEDIA_EXPORT Q_DECL_EXPORT +# define Q_MESSAGING_EXPORT Q_DECL_EXPORT +# define Q_SERVICEFW_EXPORT Q_DECL_EXPORT +# define Q_SYSINFO_EXPORT Q_DECL_EXPORT +# define Q_SENSORS_EXPORT Q_DECL_EXPORT +# else +# define Q_BEARER_EXPORT +# define Q_PUBLISHSUBSCRIBE_EXPORT +# define Q_CONTACTS_EXPORT +# define Q_VERSIT_EXPORT +# define Q_LOCATION_EXPORT +# define Q_MEDIA_EXPORT +# define Q_MESSAGING_EXPORT +# define Q_SERVICEFW_EXPORT +# define Q_SYSINFO_EXPORT +# define Q_SENSORS_EXPORT +# endif +# endif +#endif + +// The namespace is hardcoded as moc has issues resolving +// macros which would be a prerequisite for a dynmamic namespace +#define QTM_NAMESPACE QtMobility + +#ifdef QTM_NAMESPACE +# define QTM_PREPEND_NAMESPACE(name) ::QTM_NAMESPACE::name +# define QTM_BEGIN_NAMESPACE namespace QTM_NAMESPACE { +# define QTM_END_NAMESPACE } +# define QTM_USE_NAMESPACE using namespace QTM_NAMESPACE; +#else +# define QTM_PREPEND_NAMESPACE(name) ::name +# define QTM_BEGIN_NAMESPACE +# define QTM_END_NAMESPACE +# define QTM_USE_NAMESPACE +#endif + +//in case Qt is in namespace +QT_USE_NAMESPACE + +#endif // QMOBILITYGLOBAL_H diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/s60installs/bwins/QtBeareru.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/s60installs/bwins/QtBeareru.def Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,79 @@ +EXPORTS + ?getStaticMetaObject@QNetworkConfigurationManager@QtMobility@@SAABUQMetaObject@@XZ @ 1 NONAME ; struct QMetaObject const & QtMobility::QNetworkConfigurationManager::getStaticMetaObject(void) + ?open@QNetworkSession@QtMobility@@QAEXXZ @ 2 NONAME ; void QtMobility::QNetworkSession::open(void) + ?qt_metacall@QNetworkSession@QtMobility@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 3 NONAME ; int QtMobility::QNetworkSession::qt_metacall(enum QMetaObject::Call, int, void * *) + ?getStaticMetaObject@QNetworkSession@QtMobility@@SAABUQMetaObject@@XZ @ 4 NONAME ; struct QMetaObject const & QtMobility::QNetworkSession::getStaticMetaObject(void) + ?trUtf8@QNetworkConfigurationManager@QtMobility@@SA?AVQString@@PBD0@Z @ 5 NONAME ; class QString QtMobility::QNetworkConfigurationManager::trUtf8(char const *, char const *) + ?bytesReceived@QNetworkSession@QtMobility@@QBE_KXZ @ 6 NONAME ; unsigned long long QtMobility::QNetworkSession::bytesReceived(void) const + ?stateChanged@QNetworkSession@QtMobility@@IAEXW4State@12@@Z @ 7 NONAME ; void QtMobility::QNetworkSession::stateChanged(enum QtMobility::QNetworkSession::State) + ?trUtf8@QNetworkSession@QtMobility@@SA?AVQString@@PBD0@Z @ 8 NONAME ; class QString QtMobility::QNetworkSession::trUtf8(char const *, char const *) + ?sessionProperty@QNetworkSession@QtMobility@@QBE?AVQVariant@@ABVQString@@@Z @ 9 NONAME ; class QVariant QtMobility::QNetworkSession::sessionProperty(class QString const &) const + ?configuration@QNetworkSession@QtMobility@@QBE?AVQNetworkConfiguration@2@XZ @ 10 NONAME ; class QtMobility::QNetworkConfiguration QtMobility::QNetworkSession::configuration(void) const + ?waitForOpened@QNetworkSession@QtMobility@@QAE_NH@Z @ 11 NONAME ; bool QtMobility::QNetworkSession::waitForOpened(int) + ?type@QNetworkConfiguration@QtMobility@@QBE?AW4Type@12@XZ @ 12 NONAME ; enum QtMobility::QNetworkConfiguration::Type QtMobility::QNetworkConfiguration::type(void) const + ?error@QNetworkSession@QtMobility@@IAEXW4SessionError@12@@Z @ 13 NONAME ; void QtMobility::QNetworkSession::error(enum QtMobility::QNetworkSession::SessionError) + ?identifier@QNetworkConfiguration@QtMobility@@QBE?AVQString@@XZ @ 14 NONAME ; class QString QtMobility::QNetworkConfiguration::identifier(void) const + ?connectNotify@QNetworkSession@QtMobility@@MAEXPBD@Z @ 15 NONAME ; void QtMobility::QNetworkSession::connectNotify(char const *) + ?configurationAdded@QNetworkConfigurationManager@QtMobility@@IAEXABVQNetworkConfiguration@2@@Z @ 16 NONAME ; void QtMobility::QNetworkConfigurationManager::configurationAdded(class QtMobility::QNetworkConfiguration const &) + ?interface@QNetworkSession@QtMobility@@QBE?AVQNetworkInterface@@XZ @ 17 NONAME ; class QNetworkInterface QtMobility::QNetworkSession::interface(void) const + ?closed@QNetworkSession@QtMobility@@IAEXXZ @ 18 NONAME ; void QtMobility::QNetworkSession::closed(void) + ?updateCompleted@QNetworkConfigurationManager@QtMobility@@IAEXXZ @ 19 NONAME ; void QtMobility::QNetworkConfigurationManager::updateCompleted(void) + ?preferredConfigurationChanged@QNetworkSession@QtMobility@@IAEXABVQNetworkConfiguration@2@_N@Z @ 20 NONAME ; void QtMobility::QNetworkSession::preferredConfigurationChanged(class QtMobility::QNetworkConfiguration const &, bool) + ?name@QNetworkConfiguration@QtMobility@@QBE?AVQString@@XZ @ 21 NONAME ; class QString QtMobility::QNetworkConfiguration::name(void) const + ??8QNetworkConfiguration@QtMobility@@QBE_NABV01@@Z @ 22 NONAME ; bool QtMobility::QNetworkConfiguration::operator==(class QtMobility::QNetworkConfiguration const &) const + ?trUtf8@QNetworkConfigurationManager@QtMobility@@SA?AVQString@@PBD0H@Z @ 23 NONAME ; class QString QtMobility::QNetworkConfigurationManager::trUtf8(char const *, char const *, int) + ?ignore@QNetworkSession@QtMobility@@QAEXXZ @ 24 NONAME ; void QtMobility::QNetworkSession::ignore(void) + ??0QNetworkSession@QtMobility@@QAE@ABVQNetworkConfiguration@1@PAVQObject@@@Z @ 25 NONAME ; QtMobility::QNetworkSession::QNetworkSession(class QtMobility::QNetworkConfiguration const &, class QObject *) + ?bytesWritten@QNetworkSession@QtMobility@@QBE_KXZ @ 26 NONAME ; unsigned long long QtMobility::QNetworkSession::bytesWritten(void) const + ?isOpen@QNetworkSession@QtMobility@@QBE_NXZ @ 27 NONAME ; bool QtMobility::QNetworkSession::isOpen(void) const + ?tr@QNetworkSession@QtMobility@@SA?AVQString@@PBD0H@Z @ 28 NONAME ; class QString QtMobility::QNetworkSession::tr(char const *, char const *, int) + ??0QNetworkConfiguration@QtMobility@@QAE@XZ @ 29 NONAME ; QtMobility::QNetworkConfiguration::QNetworkConfiguration(void) + ?state@QNetworkConfiguration@QtMobility@@QBE?AV?$QFlags@W4StateFlag@QNetworkConfiguration@QtMobility@@@@XZ @ 30 NONAME ; class QFlags QtMobility::QNetworkConfiguration::state(void) const + ?children@QNetworkConfiguration@QtMobility@@QBE?AV?$QList@VQNetworkConfiguration@QtMobility@@@@XZ @ 31 NONAME ; class QList QtMobility::QNetworkConfiguration::children(void) const + ?isValid@QNetworkConfiguration@QtMobility@@QBE_NXZ @ 32 NONAME ; bool QtMobility::QNetworkConfiguration::isValid(void) const + ?activeTime@QNetworkSession@QtMobility@@QBE_KXZ @ 33 NONAME ; unsigned long long QtMobility::QNetworkSession::activeTime(void) const + ??_EQNetworkSession@QtMobility@@UAE@I@Z @ 34 NONAME ; QtMobility::QNetworkSession::~QNetworkSession(unsigned int) + ?disconnectNotify@QNetworkSession@QtMobility@@MAEXPBD@Z @ 35 NONAME ; void QtMobility::QNetworkSession::disconnectNotify(char const *) + ?purpose@QNetworkConfiguration@QtMobility@@QBE?AW4Purpose@12@XZ @ 36 NONAME ; enum QtMobility::QNetworkConfiguration::Purpose QtMobility::QNetworkConfiguration::purpose(void) const + ?migrate@QNetworkSession@QtMobility@@QAEXXZ @ 37 NONAME ; void QtMobility::QNetworkSession::migrate(void) + ?isRoamingAvailable@QNetworkConfiguration@QtMobility@@QBE_NXZ @ 38 NONAME ; bool QtMobility::QNetworkConfiguration::isRoamingAvailable(void) const + ?trUtf8@QNetworkSession@QtMobility@@SA?AVQString@@PBD0H@Z @ 39 NONAME ; class QString QtMobility::QNetworkSession::trUtf8(char const *, char const *, int) + ?bearerName@QNetworkConfiguration@QtMobility@@QBE?AVQString@@XZ @ 40 NONAME ; class QString QtMobility::QNetworkConfiguration::bearerName(void) const + ??0QNetworkConfigurationManager@QtMobility@@QAE@PAVQObject@@@Z @ 41 NONAME ; QtMobility::QNetworkConfigurationManager::QNetworkConfigurationManager(class QObject *) + ?tr@QNetworkSession@QtMobility@@SA?AVQString@@PBD0@Z @ 42 NONAME ; class QString QtMobility::QNetworkSession::tr(char const *, char const *) + ?onlineStateChanged@QNetworkConfigurationManager@QtMobility@@IAEX_N@Z @ 43 NONAME ; void QtMobility::QNetworkConfigurationManager::onlineStateChanged(bool) + ?opened@QNetworkSession@QtMobility@@IAEXXZ @ 44 NONAME ; void QtMobility::QNetworkSession::opened(void) + ?configurationFromIdentifier@QNetworkConfigurationManager@QtMobility@@QBE?AVQNetworkConfiguration@2@ABVQString@@@Z @ 45 NONAME ; class QtMobility::QNetworkConfiguration QtMobility::QNetworkConfigurationManager::configurationFromIdentifier(class QString const &) const + ??4QNetworkConfiguration@QtMobility@@QAEAAV01@ABV01@@Z @ 46 NONAME ; class QtMobility::QNetworkConfiguration & QtMobility::QNetworkConfiguration::operator=(class QtMobility::QNetworkConfiguration const &) + ?setSessionProperty@QNetworkSession@QtMobility@@QAEXABVQString@@ABVQVariant@@@Z @ 47 NONAME ; void QtMobility::QNetworkSession::setSessionProperty(class QString const &, class QVariant const &) + ?staticMetaObject@QNetworkConfigurationManager@QtMobility@@2UQMetaObject@@B @ 48 NONAME ; struct QMetaObject const QtMobility::QNetworkConfigurationManager::staticMetaObject + ?configurationChanged@QNetworkConfigurationManager@QtMobility@@IAEXABVQNetworkConfiguration@2@@Z @ 49 NONAME ; void QtMobility::QNetworkConfigurationManager::configurationChanged(class QtMobility::QNetworkConfiguration const &) + ??9QNetworkConfiguration@QtMobility@@QBE_NABV01@@Z @ 50 NONAME ; bool QtMobility::QNetworkConfiguration::operator!=(class QtMobility::QNetworkConfiguration const &) const + ??1QNetworkConfiguration@QtMobility@@QAE@XZ @ 51 NONAME ; QtMobility::QNetworkConfiguration::~QNetworkConfiguration(void) + ?tr@QNetworkConfigurationManager@QtMobility@@SA?AVQString@@PBD0H@Z @ 52 NONAME ; class QString QtMobility::QNetworkConfigurationManager::tr(char const *, char const *, int) + ?reject@QNetworkSession@QtMobility@@QAEXXZ @ 53 NONAME ; void QtMobility::QNetworkSession::reject(void) + ?capabilities@QNetworkConfigurationManager@QtMobility@@QBE?AV?$QFlags@W4Capability@QNetworkConfigurationManager@QtMobility@@@@XZ @ 54 NONAME ; class QFlags QtMobility::QNetworkConfigurationManager::capabilities(void) const + ?newConfigurationActivated@QNetworkSession@QtMobility@@IAEXXZ @ 55 NONAME ; void QtMobility::QNetworkSession::newConfigurationActivated(void) + ??_EQNetworkConfigurationManager@QtMobility@@UAE@I@Z @ 56 NONAME ; QtMobility::QNetworkConfigurationManager::~QNetworkConfigurationManager(unsigned int) + ?tr@QNetworkConfigurationManager@QtMobility@@SA?AVQString@@PBD0@Z @ 57 NONAME ; class QString QtMobility::QNetworkConfigurationManager::tr(char const *, char const *) + ?qt_metacall@QNetworkConfigurationManager@QtMobility@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 58 NONAME ; int QtMobility::QNetworkConfigurationManager::qt_metacall(enum QMetaObject::Call, int, void * *) + ?updateConfigurations@QNetworkConfigurationManager@QtMobility@@QAEXXZ @ 59 NONAME ; void QtMobility::QNetworkConfigurationManager::updateConfigurations(void) + ?qt_metacast@QNetworkConfigurationManager@QtMobility@@UAEPAXPBD@Z @ 60 NONAME ; void * QtMobility::QNetworkConfigurationManager::qt_metacast(char const *) + ?close@QNetworkSession@QtMobility@@QAEXXZ @ 61 NONAME ; void QtMobility::QNetworkSession::close(void) + ?errorString@QNetworkSession@QtMobility@@QBE?AVQString@@XZ @ 62 NONAME ; class QString QtMobility::QNetworkSession::errorString(void) const + ?metaObject@QNetworkSession@QtMobility@@UBEPBUQMetaObject@@XZ @ 63 NONAME ; struct QMetaObject const * QtMobility::QNetworkSession::metaObject(void) const + ?configurationRemoved@QNetworkConfigurationManager@QtMobility@@IAEXABVQNetworkConfiguration@2@@Z @ 64 NONAME ; void QtMobility::QNetworkConfigurationManager::configurationRemoved(class QtMobility::QNetworkConfiguration const &) + ??1QNetworkConfigurationManager@QtMobility@@UAE@XZ @ 65 NONAME ; QtMobility::QNetworkConfigurationManager::~QNetworkConfigurationManager(void) + ?metaObject@QNetworkConfigurationManager@QtMobility@@UBEPBUQMetaObject@@XZ @ 66 NONAME ; struct QMetaObject const * QtMobility::QNetworkConfigurationManager::metaObject(void) const + ?staticMetaObject@QNetworkSession@QtMobility@@2UQMetaObject@@B @ 67 NONAME ; struct QMetaObject const QtMobility::QNetworkSession::staticMetaObject + ?isOnline@QNetworkConfigurationManager@QtMobility@@QBE_NXZ @ 68 NONAME ; bool QtMobility::QNetworkConfigurationManager::isOnline(void) const + ?defaultConfiguration@QNetworkConfigurationManager@QtMobility@@QBE?AVQNetworkConfiguration@2@XZ @ 69 NONAME ; class QtMobility::QNetworkConfiguration QtMobility::QNetworkConfigurationManager::defaultConfiguration(void) const + ?stop@QNetworkSession@QtMobility@@QAEXXZ @ 70 NONAME ; void QtMobility::QNetworkSession::stop(void) + ?allConfigurations@QNetworkConfigurationManager@QtMobility@@QBE?AV?$QList@VQNetworkConfiguration@QtMobility@@@@V?$QFlags@W4StateFlag@QNetworkConfiguration@QtMobility@@@@@Z @ 71 NONAME ; class QList QtMobility::QNetworkConfigurationManager::allConfigurations(class QFlags) const + ?error@QNetworkSession@QtMobility@@QBE?AW4SessionError@12@XZ @ 72 NONAME ; enum QtMobility::QNetworkSession::SessionError QtMobility::QNetworkSession::error(void) const + ??0QNetworkConfiguration@QtMobility@@QAE@ABV01@@Z @ 73 NONAME ; QtMobility::QNetworkConfiguration::QNetworkConfiguration(class QtMobility::QNetworkConfiguration const &) + ?qt_metacast@QNetworkSession@QtMobility@@UAEPAXPBD@Z @ 74 NONAME ; void * QtMobility::QNetworkSession::qt_metacast(char const *) + ??1QNetworkSession@QtMobility@@UAE@XZ @ 75 NONAME ; QtMobility::QNetworkSession::~QNetworkSession(void) + ?state@QNetworkSession@QtMobility@@QBE?AW4State@12@XZ @ 76 NONAME ; enum QtMobility::QNetworkSession::State QtMobility::QNetworkSession::state(void) const + ?accept@QNetworkSession@QtMobility@@QAEXXZ @ 77 NONAME ; void QtMobility::QNetworkSession::accept(void) + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/s60installs/eabi/QtBeareru.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/s60installs/eabi/QtBeareru.def Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,81 @@ +EXPORTS + _ZN10QtMobility15QNetworkSession11qt_metacallEN11QMetaObject4CallEiPPv @ 1 NONAME + _ZN10QtMobility15QNetworkSession11qt_metacastEPKc @ 2 NONAME + _ZN10QtMobility15QNetworkSession12stateChangedENS0_5StateE @ 3 NONAME + _ZN10QtMobility15QNetworkSession13connectNotifyEPKc @ 4 NONAME + _ZN10QtMobility15QNetworkSession13waitForOpenedEi @ 5 NONAME + _ZN10QtMobility15QNetworkSession16disconnectNotifyEPKc @ 6 NONAME + _ZN10QtMobility15QNetworkSession16staticMetaObjectE @ 7 NONAME DATA 16 + _ZN10QtMobility15QNetworkSession18setSessionPropertyERK7QStringRK8QVariant @ 8 NONAME + _ZN10QtMobility15QNetworkSession19getStaticMetaObjectEv @ 9 NONAME + _ZN10QtMobility15QNetworkSession25newConfigurationActivatedEv @ 10 NONAME + _ZN10QtMobility15QNetworkSession29preferredConfigurationChangedERKNS_21QNetworkConfigurationEb @ 11 NONAME + _ZN10QtMobility15QNetworkSession4openEv @ 12 NONAME + _ZN10QtMobility15QNetworkSession4stopEv @ 13 NONAME + _ZN10QtMobility15QNetworkSession5closeEv @ 14 NONAME + _ZN10QtMobility15QNetworkSession5errorENS0_12SessionErrorE @ 15 NONAME + _ZN10QtMobility15QNetworkSession6acceptEv @ 16 NONAME + _ZN10QtMobility15QNetworkSession6closedEv @ 17 NONAME + _ZN10QtMobility15QNetworkSession6ignoreEv @ 18 NONAME + _ZN10QtMobility15QNetworkSession6openedEv @ 19 NONAME + _ZN10QtMobility15QNetworkSession6rejectEv @ 20 NONAME + _ZN10QtMobility15QNetworkSession7migrateEv @ 21 NONAME + _ZN10QtMobility15QNetworkSessionC1ERKNS_21QNetworkConfigurationEP7QObject @ 22 NONAME + _ZN10QtMobility15QNetworkSessionC2ERKNS_21QNetworkConfigurationEP7QObject @ 23 NONAME + _ZN10QtMobility15QNetworkSessionD0Ev @ 24 NONAME + _ZN10QtMobility15QNetworkSessionD1Ev @ 25 NONAME + _ZN10QtMobility15QNetworkSessionD2Ev @ 26 NONAME + _ZN10QtMobility21QNetworkConfigurationC1ERKS0_ @ 27 NONAME + _ZN10QtMobility21QNetworkConfigurationC1Ev @ 28 NONAME + _ZN10QtMobility21QNetworkConfigurationC2ERKS0_ @ 29 NONAME + _ZN10QtMobility21QNetworkConfigurationC2Ev @ 30 NONAME + _ZN10QtMobility21QNetworkConfigurationD1Ev @ 31 NONAME + _ZN10QtMobility21QNetworkConfigurationD2Ev @ 32 NONAME + _ZN10QtMobility21QNetworkConfigurationaSERKS0_ @ 33 NONAME + _ZN10QtMobility28QNetworkConfigurationManager11qt_metacallEN11QMetaObject4CallEiPPv @ 34 NONAME + _ZN10QtMobility28QNetworkConfigurationManager11qt_metacastEPKc @ 35 NONAME + _ZN10QtMobility28QNetworkConfigurationManager15updateCompletedEv @ 36 NONAME + _ZN10QtMobility28QNetworkConfigurationManager16staticMetaObjectE @ 37 NONAME DATA 16 + _ZN10QtMobility28QNetworkConfigurationManager18configurationAddedERKNS_21QNetworkConfigurationE @ 38 NONAME + _ZN10QtMobility28QNetworkConfigurationManager18onlineStateChangedEb @ 39 NONAME + _ZN10QtMobility28QNetworkConfigurationManager19getStaticMetaObjectEv @ 40 NONAME + _ZN10QtMobility28QNetworkConfigurationManager20configurationChangedERKNS_21QNetworkConfigurationE @ 41 NONAME + _ZN10QtMobility28QNetworkConfigurationManager20configurationRemovedERKNS_21QNetworkConfigurationE @ 42 NONAME + _ZN10QtMobility28QNetworkConfigurationManager20updateConfigurationsEv @ 43 NONAME + _ZN10QtMobility28QNetworkConfigurationManagerC1EP7QObject @ 44 NONAME + _ZN10QtMobility28QNetworkConfigurationManagerC2EP7QObject @ 45 NONAME + _ZN10QtMobility28QNetworkConfigurationManagerD0Ev @ 46 NONAME + _ZN10QtMobility28QNetworkConfigurationManagerD1Ev @ 47 NONAME + _ZN10QtMobility28QNetworkConfigurationManagerD2Ev @ 48 NONAME + _ZNK10QtMobility15QNetworkSession10activeTimeEv @ 49 NONAME + _ZNK10QtMobility15QNetworkSession10metaObjectEv @ 50 NONAME + _ZNK10QtMobility15QNetworkSession11errorStringEv @ 51 NONAME + _ZNK10QtMobility15QNetworkSession12bytesWrittenEv @ 52 NONAME + _ZNK10QtMobility15QNetworkSession13bytesReceivedEv @ 53 NONAME + _ZNK10QtMobility15QNetworkSession13configurationEv @ 54 NONAME + _ZNK10QtMobility15QNetworkSession15sessionPropertyERK7QString @ 55 NONAME + _ZNK10QtMobility15QNetworkSession5errorEv @ 56 NONAME + _ZNK10QtMobility15QNetworkSession5stateEv @ 57 NONAME + _ZNK10QtMobility15QNetworkSession6isOpenEv @ 58 NONAME + _ZNK10QtMobility15QNetworkSession9interfaceEv @ 59 NONAME + _ZNK10QtMobility21QNetworkConfiguration10bearerNameEv @ 60 NONAME + _ZNK10QtMobility21QNetworkConfiguration10identifierEv @ 61 NONAME + _ZNK10QtMobility21QNetworkConfiguration18isRoamingAvailableEv @ 62 NONAME + _ZNK10QtMobility21QNetworkConfiguration4nameEv @ 63 NONAME + _ZNK10QtMobility21QNetworkConfiguration4typeEv @ 64 NONAME + _ZNK10QtMobility21QNetworkConfiguration5stateEv @ 65 NONAME + _ZNK10QtMobility21QNetworkConfiguration7isValidEv @ 66 NONAME + _ZNK10QtMobility21QNetworkConfiguration7purposeEv @ 67 NONAME + _ZNK10QtMobility21QNetworkConfiguration8childrenEv @ 68 NONAME + _ZNK10QtMobility21QNetworkConfigurationeqERKS0_ @ 69 NONAME + _ZNK10QtMobility28QNetworkConfigurationManager10metaObjectEv @ 70 NONAME + _ZNK10QtMobility28QNetworkConfigurationManager12capabilitiesEv @ 71 NONAME + _ZNK10QtMobility28QNetworkConfigurationManager17allConfigurationsE6QFlagsINS_21QNetworkConfiguration9StateFlagEE @ 72 NONAME + _ZNK10QtMobility28QNetworkConfigurationManager20defaultConfigurationEv @ 73 NONAME + _ZNK10QtMobility28QNetworkConfigurationManager27configurationFromIdentifierERK7QString @ 74 NONAME + _ZNK10QtMobility28QNetworkConfigurationManager8isOnlineEv @ 75 NONAME + _ZTIN10QtMobility15QNetworkSessionE @ 76 NONAME + _ZTIN10QtMobility28QNetworkConfigurationManagerE @ 77 NONAME + _ZTVN10QtMobility15QNetworkSessionE @ 78 NONAME + _ZTVN10QtMobility28QNetworkConfigurationManagerE @ 79 NONAME + diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/s60installs/s60installs.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/s60installs/s60installs.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,63 @@ +TEMPLATE = subdirs + +symbian: { + include(../../staticconfig.pri) + load(data_caging_paths) + include($$QT_MOBILITY_BUILD_TREE/config.pri) + + SUBDIRS = + TARGET = "QtMobility" + TARGET.UID3 = 0x2002AC89 + # TP preview 0.1.0 + # Beta 0.2.0 + # Final 1.0.0 + + VERSION = 1.0.0 + + vendorinfo = \ + "; Localised Vendor name" \ + "%{\"Nokia\"}" \ + " " \ + "; Unique Vendor name" \ + ":\"Nokia\"" \ + " " + qtmobilitydeployment.pkg_prerules += vendorinfo + + epoc31 = $$(EPOCROOT31) + epoc32 = $$(EPOCROOT32) + epoc50 = $$(EPOCROOT50) + + # default to EPOCROOT if EPOCROOTxy not defined + isEmpty(epoc31) { + EPOCROOT31 = $${EPOCROOT} + } else { + EPOCROOT31 = $$(EPOCROOT31) + } + isEmpty(epoc32) { + EPOCROOT32 = $${EPOCROOT} + }else { + EPOCROOT32 = $$(EPOCROOT32) + } + isEmpty(epoc50) { + EPOCROOT50 = $${EPOCROOT} + } else { + EPOCROOT50 = $$(EPOCROOT50) + } + + bearer = \ + "IF package(0x1028315F)" \ + " \"$$EPOCROOT50\epoc32/release/armv5/urel/QtBearer.dll\" - \"!:\\sys\\bin\\QtBearer.dll\"" \ + "ELSEIF package(0x102752AE)" \ + " \"$$EPOCROOT50\epoc32/release/armv5/urel/QtBearer.dll\" - \"!:\\sys\\bin\\QtBearer.dll\"" \ + "ELSEIF package(0x102032BE)" \ + " \"$$EPOCROOT31\epoc32/release/armv5/urel/QtBearer.dll\" - \"!:\\sys\\bin\\QtBearer.dll\"" \ + "ELSE" \ + " \"$$EPOCROOT50\epoc32/release/armv5/urel/QtBearer.dll\" - \"!:\\sys\\bin\\QtBearer.dll\"" \ + "ENDIF" + + qtmobilitydeployment.pkg_postrules += bearer + + qtmobilitydeployment.path = /sys/bin + + DEPLOYMENT += qtmobilitydeployment +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/src/src.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/src/src.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,11 @@ +include(../staticconfig.pri) + +TEMPLATE = subdirs +SUBDIRS += global + +contains(mobility_modules,bearer): SUBDIRS += bearer + +symbian { + SUBDIRS += s60installs/s60installs.pro +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/staticconfig.pri --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/staticconfig.pri Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,14 @@ +# +# Fix up QT_MOBILITY_SOURCE_TREE if it isn't defined +# +# Symbian MCL builds do not run configure and hence don't have +# .qmake.cache which set QT_MOBILITY_SOURCE_TREE and +# QT_MOBILITY_BUILD_TREE. Therefore we need to define a fallback. +# This has the disadvantage that shadow builds are not supported. + + +isEmpty(QT_MOBILITY_SOURCE_TREE):QT_MOBILITY_SOURCE_TREE = $$PWD +isEmpty(QT_MOBILITY_BUILD_TREE):QT_MOBILITY_BUILD_TREE = $$PWD + +#now include the dynamic config +include($$QT_MOBILITY_BUILD_TREE/config.pri) diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/auto.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/auto.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,10 @@ +TEMPLATE = subdirs + +include(../../staticconfig.pri) + +contains(mobility_modules,bearer) { + SUBDIRS += qnetworkconfigmanager \ #Bearer management + qnetworkconfiguration \ + qnetworksession +} + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qbearertestcommon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qbearertestcommon.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBEARERTESTCOMMON_H +#define QBEARERTESTCOMMON_H + +// Wait for __expr to happen, while still allowing events to be processed. +#define QTRY_NOOP(__expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 15000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + } while(0) + +// Will try to wait for the condition while allowing event processing +#define QTRY_VERIFY(__expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 90000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QVERIFY(__expr); \ + } while(0) + +// Will try to wait for the condition while allowing event processing +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 90000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) + +#endif + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,22 @@ +SOURCES += tst_qnetworkconfigmanager.cpp +HEADERS += ../qbearertestcommon.h +TARGET = tst_qnetworkconfigurationmanager +CONFIG += testcase + +QT = core network + +INCLUDEPATH += ../../../src/bearer + +include(../../../common.pri) +CONFIG += mobility +MOBILITY = bearer + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +} + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,335 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "../qbearertestcommon.h" +#include "qnetworkconfiguration.h" +#include "qnetworkconfigmanager.h" + +#ifdef Q_WS_MAEMO_6 +#include +#include +#endif + +QTM_USE_NAMESPACE +class tst_QNetworkConfigurationManager : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void allConfigurations(); + void defaultConfiguration(); + void configurationFromIdentifier(); + +private: +#ifdef Q_WS_MAEMO_6 + Maemo::IAPConf *iapconf; + Maemo::IAPConf *iapconf2; + Maemo::IAPConf *gprsiap; +#define MAX_IAPS 50 + Maemo::IAPConf *iaps[MAX_IAPS]; + QProcess *icd_stub; +#endif +}; + +void tst_QNetworkConfigurationManager::initTestCase() +{ +#ifdef Q_WS_MAEMO_6 + iapconf = new Maemo::IAPConf("007"); + iapconf->setValue("ipv4_type", "AUTO"); + iapconf->setValue("wlan_wepkey1", "connt"); + iapconf->setValue("wlan_wepdefkey", 1); + iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); + iapconf->setValue("name", "James Bond"); + iapconf->setValue("type", "WLAN_INFRA"); + + gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); + gprsiap->setValue("ask_password", false); + gprsiap->setValue("gprs_accesspointname", "internet"); + gprsiap->setValue("gprs_password", ""); + gprsiap->setValue("gprs_username", ""); + gprsiap->setValue("ipv4_autodns", true); + gprsiap->setValue("ipv4_type", "AUTO"); + gprsiap->setValue("sim_imsi", "244070123456789"); + gprsiap->setValue("name", "MI6"); + gprsiap->setValue("type", "GPRS"); + + iapconf2 = new Maemo::IAPConf("osso.net"); + iapconf2->setValue("ipv4_type", "AUTO"); + iapconf2->setValue("wlan_wepkey1", "osso.net"); + iapconf2->setValue("wlan_wepdefkey", 1); + iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); + iapconf2->setValue("name", "osso.net"); + iapconf2->setValue("type", "WLAN_INFRA"); + iapconf2->setValue("wlan_security", "WEP"); + + /* Create large number of IAPs in the gconf and see what happens */ + fflush(stdout); + printf("Creating %d IAPS: ", MAX_IAPS); + for (int i=0; isetValue("name", QString("test-iap-")+num); + iaps[i]->setValue("type", "WLAN_INFRA"); + iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); + iaps[i]->setValue("wlan_security", "WPA_PSK"); + iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); + printf("."); + fflush(stdout); + } + printf("\n"); + fflush(stdout); + + icd_stub = new QProcess(this); + icd_stub->start("/usr/bin/icd2_stub.py"); + QTest::qWait(1000); + + // Add a known network to scan list that icd2 stub returns + QProcess dbus_send; + // 007 network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); + dbus_send.waitForFinished(); + + // osso.net network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); + dbus_send.waitForFinished(); +#endif +} + + +void tst_QNetworkConfigurationManager::cleanupTestCase() +{ +#ifdef Q_WS_MAEMO_6 + iapconf->clear(); + delete iapconf; + iapconf2->clear(); + delete iapconf2; + gprsiap->clear(); + delete gprsiap; + + printf("Deleting %d IAPS : ", MAX_IAPS); + for (int i=0; iclear(); + delete iaps[i]; + printf("."); + fflush(stdout); + } + printf("\n"); + qDebug() << "Deleted" << MAX_IAPS << "IAPs"; + + icd_stub->terminate(); + icd_stub->waitForFinished(); +#endif +} + +void tst_QNetworkConfigurationManager::init() +{ +} + +void tst_QNetworkConfigurationManager::cleanup() +{ +} + +void printConfigurationDetails(const QNetworkConfiguration& p) +{ + qDebug() << p.name() <<": isvalid->" <"<< p.type() << + " roaming->" << p.isRoamingAvailable() << "identifier->" << p.identifier() << + " purpose->" << p.purpose() << " state->" << p.state(); +} + +void tst_QNetworkConfigurationManager::allConfigurations() +{ + QNetworkConfigurationManager manager; + QList preScanConfigs = manager.allConfigurations(); + + foreach(QNetworkConfiguration c, preScanConfigs) + { + QVERIFY2(c.type()!=QNetworkConfiguration::UserChoice, "allConfiguration must not return UserChoice configs"); + } + + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + QList configs = manager.allConfigurations(); + + int all = configs.count(); + qDebug() << "All configurations:" << all; + QVERIFY(all); + foreach(QNetworkConfiguration p, configs) { + QVERIFY(p.isValid()); + printConfigurationDetails(p); + QVERIFY(p.type() != QNetworkConfiguration::Invalid); + QVERIFY(p.type() != QNetworkConfiguration::UserChoice); + } + + configs = manager.allConfigurations(QNetworkConfiguration::Undefined); + int undefined = configs.count(); + QVERIFY(undefined <= all); + qDebug() << "Undefined configurations:" << undefined; + foreach( const QNetworkConfiguration p, configs) { + printConfigurationDetails(p); + QVERIFY(p.state() & QNetworkConfiguration::Undefined); + QVERIFY(!(p.state() & QNetworkConfiguration::Defined)); + } + + //get defined configs only (same as all) + configs = manager.allConfigurations(QNetworkConfiguration::Defined); + int defined = configs.count(); + qDebug() << "Defined configurations:" << defined; + QVERIFY(defined <= all); + foreach( const QNetworkConfiguration p, configs) { + printConfigurationDetails(p); + QVERIFY(p.state() & QNetworkConfiguration::Defined); + QVERIFY(!(p.state() & QNetworkConfiguration::Undefined)); + } + + //get discovered configurations only + configs = manager.allConfigurations(QNetworkConfiguration::Discovered); + int discovered = configs.count(); + //QVERIFY(discovered); + qDebug() << "Discovered configurations:" << discovered; + foreach(const QNetworkConfiguration p, configs) { + printConfigurationDetails(p); + QVERIFY(p.isValid()); + QVERIFY(!(p.state() & QNetworkConfiguration::Undefined)); + QVERIFY(p.state() & QNetworkConfiguration::Defined); + QVERIFY(p.state() & QNetworkConfiguration::Discovered); + } + + //getactive configurations only + configs = manager.allConfigurations(QNetworkConfiguration::Active); + int active = configs.count(); + if (active) + QVERIFY(manager.isOnline()); + else + QVERIFY(!manager.isOnline()); + + //QVERIFY(active); + qDebug() << "Active configurations:" << active; + foreach(const QNetworkConfiguration p, configs) { + printConfigurationDetails(p); + QVERIFY(p.isValid()); + QVERIFY(!(p.state() & QNetworkConfiguration::Undefined)); + QVERIFY(p.state() & QNetworkConfiguration::Active); + QVERIFY(p.state() & QNetworkConfiguration::Discovered); + QVERIFY(p.state() & QNetworkConfiguration::Defined); + } + + QVERIFY(all >= discovered); + QVERIFY(discovered >= active); +} + + +void tst_QNetworkConfigurationManager::defaultConfiguration() +{ + QNetworkConfigurationManager manager; + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + QList configs = manager.allConfigurations(); + QNetworkConfiguration defaultConfig = manager.defaultConfiguration(); + + bool confirm = configs.contains(defaultConfig); + bool isUserChoice = (defaultConfig.type() == QNetworkConfiguration::UserChoice); + + //user choice config is not part of allConfigurations() + QVERIFY(isUserChoice != confirm); + if (!isUserChoice) { + QVERIFY(confirm || !defaultConfig.isValid()); + QVERIFY(!(confirm && !defaultConfig.isValid())); + } else { + QVERIFY(defaultConfig.isValid()); + QCOMPARE(defaultConfig.name(), QString("UserChoice")); + QCOMPARE(defaultConfig.children().count(), 0); + QVERIFY(!defaultConfig.isRoamingAvailable()); + QCOMPARE(defaultConfig.state(), QNetworkConfiguration::Discovered); + QNetworkConfiguration copy = manager.configurationFromIdentifier(defaultConfig.identifier()); + QVERIFY(copy == defaultConfig); + } +} + +void tst_QNetworkConfigurationManager::configurationFromIdentifier() +{ + QNetworkConfigurationManager manager; + QSet allIdentifier; + + //force an update to get maximum number of configs + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + QList configs = manager.allConfigurations(); + + foreach(QNetworkConfiguration c, configs) { + QVERIFY(!allIdentifier.contains(c.identifier())); + allIdentifier.insert(c.identifier()); + + QNetworkConfiguration direct = manager.configurationFromIdentifier(c.identifier()); + QVERIFY(direct.isValid()); + QVERIFY(direct == c); + } + + //assume that there is no item with identifier 'FooBar' + QVERIFY(!allIdentifier.contains("FooBar")); + QNetworkConfiguration invalid = manager.configurationFromIdentifier("FooBar"); + QVERIFY(!invalid.isValid()); +} + + +QTEST_MAIN(tst_QNetworkConfigurationManager) +#include "tst_qnetworkconfigmanager.moc" diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,22 @@ +SOURCES += tst_qnetworkconfiguration.cpp +HEADERS += ../qbearertestcommon.h +TARGET = tst_qnetworkconfiguration +CONFIG += testcase + +QT = core network + +INCLUDEPATH += ../../../src/bearer + +include(../../../common.pri) +CONFIG += mobility +MOBILITY = bearer + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +} + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,303 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "../qbearertestcommon.h" +#include "qnetworkconfiguration.h" +#include "qnetworkconfigmanager.h" + +#ifdef Q_WS_MAEMO_6 +#include +#include +#endif + +QTM_USE_NAMESPACE +class tst_QNetworkConfiguration : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void invalidPoint(); + void comparison(); + void children(); + void isRoamingAvailable(); + +private: +#ifdef Q_WS_MAEMO_6 + Maemo::IAPConf *iapconf; + Maemo::IAPConf *iapconf2; + Maemo::IAPConf *gprsiap; +#define MAX_IAPS 50 + Maemo::IAPConf *iaps[MAX_IAPS]; + QProcess *icd_stub; +#endif +}; + +void tst_QNetworkConfiguration::initTestCase() +{ +#ifdef Q_WS_MAEMO_6 + iapconf = new Maemo::IAPConf("007"); + iapconf->setValue("ipv4_type", "AUTO"); + iapconf->setValue("wlan_wepkey1", "connt"); + iapconf->setValue("wlan_wepdefkey", 1); + iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); + iapconf->setValue("name", "James Bond"); + iapconf->setValue("type", "WLAN_INFRA"); + + iapconf2 = new Maemo::IAPConf("osso.net"); + iapconf2->setValue("ipv4_type", "AUTO"); + iapconf2->setValue("wlan_wepkey1", "osso.net"); + iapconf2->setValue("wlan_wepdefkey", 1); + iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); + iapconf2->setValue("name", "osso.net"); + iapconf2->setValue("type", "WLAN_INFRA"); + iapconf2->setValue("wlan_security", "WEP"); + + gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); + gprsiap->setValue("ask_password", false); + gprsiap->setValue("gprs_accesspointname", "internet"); + gprsiap->setValue("gprs_password", ""); + gprsiap->setValue("gprs_username", ""); + gprsiap->setValue("ipv4_autodns", true); + gprsiap->setValue("ipv4_type", "AUTO"); + gprsiap->setValue("sim_imsi", "244070123456789"); + gprsiap->setValue("name", "MI6"); + gprsiap->setValue("type", "GPRS"); + + /* Create large number of IAPs in the gconf and see what happens */ + fflush(stdout); + printf("Creating %d IAPS: ", MAX_IAPS); + for (int i=0; isetValue("name", QString("test-iap-")+num); + iaps[i]->setValue("type", "WLAN_INFRA"); + iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); + iaps[i]->setValue("wlan_security", "WPA_PSK"); + iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); + printf("."); + fflush(stdout); + } + printf("\n"); + fflush(stdout); + + icd_stub = new QProcess(this); + icd_stub->start("/usr/bin/icd2_stub.py"); + QTest::qWait(1000); + + // Add a known network to scan list that icd2 stub returns + QProcess dbus_send; + // 007 network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); + dbus_send.waitForFinished(); + + // osso.net network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); + dbus_send.waitForFinished(); +#endif +} + +void tst_QNetworkConfiguration::cleanupTestCase() +{ +#ifdef Q_WS_MAEMO_6 + iapconf->clear(); + delete iapconf; + iapconf2->clear(); + delete iapconf2; + gprsiap->clear(); + delete gprsiap; + + printf("Deleting %d IAPS : ", MAX_IAPS); + for (int i=0; iclear(); + delete iaps[i]; + printf("."); + fflush(stdout); + } + printf("\n"); + qDebug() << "Deleted" << MAX_IAPS << "IAPs"; + + // Terminate icd2 stub + icd_stub->terminate(); + icd_stub->waitForFinished(); +#endif +} + +void tst_QNetworkConfiguration::invalidPoint() +{ + QNetworkConfiguration pt; + + QVERIFY(pt.name().isEmpty()); + QVERIFY(!pt.isValid()); + QVERIFY(pt.type() == QNetworkConfiguration::Invalid); + QVERIFY(!(pt.state() & QNetworkConfiguration::Defined)); + QVERIFY(!(pt.state() & QNetworkConfiguration::Discovered)); + QVERIFY(!(pt.state() & QNetworkConfiguration::Active)); + QVERIFY(!pt.isRoamingAvailable()); + + QNetworkConfiguration pt2(pt); + QVERIFY(pt2.name().isEmpty()); + QVERIFY(!pt2.isValid()); + QVERIFY(pt2.type() == QNetworkConfiguration::Invalid); + QVERIFY(!(pt2.state() & QNetworkConfiguration::Defined)); + QVERIFY(!(pt2.state() & QNetworkConfiguration::Discovered)); + QVERIFY(!(pt2.state() & QNetworkConfiguration::Active)); + QVERIFY(!pt2.isRoamingAvailable()); + +} + +void tst_QNetworkConfiguration::comparison() +{ + //test copy constructor and assignment operator + //compare invalid connection points + QNetworkConfiguration pt1; + QVERIFY(!pt1.isValid()); + QVERIFY(pt1.type() == QNetworkConfiguration::Invalid); + + QNetworkConfiguration pt2(pt1); + QVERIFY(pt1==pt2); + QVERIFY(!(pt1!=pt2)); + QVERIFY(pt1.name() == pt2.name()); + QVERIFY(pt1.isValid() == pt2.isValid()); + QVERIFY(pt1.type() == pt2.type()); + QVERIFY(pt1.state() == pt2.state()); + QVERIFY(pt1.purpose() == pt2.purpose()); + + + QNetworkConfiguration pt3; + pt3 = pt1; + QVERIFY(pt1==pt3); + QVERIFY(!(pt1!=pt3)); + QVERIFY(pt1.name() == pt3.name()); + QVERIFY(pt1.isValid() == pt3.isValid()); + QVERIFY(pt1.type() == pt3.type()); + QVERIFY(pt1.state() == pt3.state()); + QVERIFY(pt1.purpose() == pt3.purpose()); + + //test case must run on machine that has valid connection points + QNetworkConfigurationManager manager; + QList preScanConfigs = manager.allConfigurations(); + + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + QList configs = manager.allConfigurations(QNetworkConfiguration::Discovered); + QVERIFY(configs.count()); + QNetworkConfiguration defaultConfig = manager.defaultConfiguration(); + QVERIFY(defaultConfig.isValid()); + QVERIFY(defaultConfig.type() != QNetworkConfiguration::Invalid); + QVERIFY(!defaultConfig.name().isEmpty()); + + pt3 = defaultConfig; + QVERIFY(defaultConfig==pt3); + QVERIFY(!(defaultConfig!=pt3)); + QVERIFY(defaultConfig.name() == pt3.name()); + QVERIFY(defaultConfig.isValid() == pt3.isValid()); + QVERIFY(defaultConfig.type() == pt3.type()); + QVERIFY(defaultConfig.state() == pt3.state()); + QVERIFY(defaultConfig.purpose() == pt3.purpose()); +} + +void tst_QNetworkConfiguration::children() +{ + QNetworkConfigurationManager manager; + QList configs = manager.allConfigurations(); + + foreach(QNetworkConfiguration c, configs) + { + if ( c.type() == QNetworkConfiguration::ServiceNetwork ) { + qDebug() << "found service network" << c.name() << c.children().count(); + QVERIFY(c.isValid()); + QList members = c.children(); + foreach(QNetworkConfiguration child, members) { + QVERIFY(child.isValid()); + QVERIFY(configs.contains(child)); + qDebug() << "\t" << child.name(); + } + } + } +} + +void tst_QNetworkConfiguration::isRoamingAvailable() +{ + QNetworkConfigurationManager manager; + QList configs = manager.allConfigurations(); + + //force update to get maximum list + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + foreach(QNetworkConfiguration c, configs) + { + QVERIFY(QNetworkConfiguration::UserChoice != c.type()); + QVERIFY(QNetworkConfiguration::Invalid != c.type()); + if ( c.type() == QNetworkConfiguration::ServiceNetwork ) { + //cannot test flag as some SNAPs may not support roaming anyway + //QVERIFY(c.roamingavailable()) + if ( c.children().count() <= 1 ) + QVERIFY(!c.isRoamingAvailable()); + foreach(QNetworkConfiguration child, c.children()) { + QVERIFY(QNetworkConfiguration::InternetAccessPoint == child.type()); + QCOMPARE(child.children().count(), 0); + } + } else { + QVERIFY(!c.isRoamingAvailable()); + } + } +} + +QTEST_MAIN(tst_QNetworkConfiguration) +#include "tst_qnetworkconfiguration.moc" diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworksession/lackey/lackey.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworksession/lackey/lackey.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,18 @@ +SOURCES += main.cpp +TARGET = qnetworksessionlackey +INCLUDEPATH += ../../../../src/bearer +DEPENDPATH += ../../../../src/bearer + +QT = core network + +CONFIG+= testcase + +include(../../../../common.pri) + +symbian { + # Needed for interprocess communication and opening QNetworkSession + TARGET.CAPABILITY = NetworkControl NetworkServices +} + +CONFIG += mobility +MOBILITY = bearer diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworksession/lackey/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworksession/lackey/main.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include + +QTM_USE_NAMESPACE + + +#define NO_DISCOVERED_CONFIGURATIONS_ERROR 1 +#define SESSION_OPEN_ERROR 2 + + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + + QNetworkConfigurationManager manager; + QList discovered = + manager.allConfigurations(QNetworkConfiguration::Discovered); + + foreach(QNetworkConfiguration config, discovered) { + qDebug() << "Lackey: Name of the config enumerated: " << config.name(); + qDebug() << "Lackey: State of the config enumerated: " << config.state(); + } + + if (discovered.isEmpty()) { + qDebug("Lackey: no discovered configurations, returning empty error."); + return NO_DISCOVERED_CONFIGURATIONS_ERROR; + } + + // Cannot read/write to processes on WinCE or Symbian. + // Easiest alternative is to use sockets for IPC. + + QLocalSocket oopSocket; + + oopSocket.connectToServer("tst_qnetworksession"); + oopSocket.waitForConnected(-1); + + qDebug() << "Lackey started"; + + QNetworkSession *session = 0; + do { + if (session) { + delete session; + session = 0; + } + + qDebug() << "Discovered configurations:" << discovered.count(); + + if (discovered.isEmpty()) { + qDebug() << "No more discovered configurations"; + break; + } + + qDebug() << "Taking first configuration"; + + QNetworkConfiguration config = discovered.takeFirst(); + + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + qDebug() << config.name() << " is active, therefore skipping it (looking for configs in 'discovered' state)."; + continue; + } + + qDebug() << "Creating session for" << config.name() << config.identifier(); + + session = new QNetworkSession(config); + + QString output = QString("Starting session for %1\n").arg(config.identifier()); + oopSocket.write(output.toAscii()); + oopSocket.waitForBytesWritten(); + session->open(); + session->waitForOpened(); + } while (!(session && session->isOpen())); + + qDebug() << "lackey: loop done"; + + if (!session) { + qDebug() << "Could not start session"; + + oopSocket.disconnectFromServer(); + oopSocket.waitForDisconnected(-1); + + return SESSION_OPEN_ERROR; + } + + QString output = QString("Started session for %1\n").arg(session->configuration().identifier()); + oopSocket.write(output.toAscii()); + oopSocket.waitForBytesWritten(); + + oopSocket.waitForReadyRead(); + oopSocket.readLine(); + + session->stop(); + + delete session; + + oopSocket.disconnectFromServer(); + oopSocket.waitForDisconnected(-1); + + return 0; +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworksession/qnetworksession.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworksession/qnetworksession.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = lackey tst_qnetworksession diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,1196 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include "../../qbearertestcommon.h" +#include +#include + +#ifdef Q_WS_MAEMO_6 +#include +#include +#endif + +QTM_USE_NAMESPACE + +Q_DECLARE_METATYPE(QNetworkConfiguration) +Q_DECLARE_METATYPE(QNetworkConfiguration::Type); +Q_DECLARE_METATYPE(QNetworkSession::State); +Q_DECLARE_METATYPE(QNetworkSession::SessionError); + +class tst_QNetworkSession : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + + void outOfProcessSession(); + void invalidSession(); + + void repeatedOpenClose_data(); + void repeatedOpenClose(); + + void roamingErrorCodes(); + + void sessionProperties_data(); + void sessionProperties(); + + void userChoiceSession_data(); + void userChoiceSession(); + + void sessionOpenCloseStop_data(); + void sessionOpenCloseStop(); + +private: + QNetworkConfigurationManager manager; + + uint inProcessSessionManagementCount; + +#ifdef Q_WS_MAEMO_6 + Maemo::IAPConf *iapconf; + Maemo::IAPConf *iapconf2; + Maemo::IAPConf *gprsiap; +#define MAX_IAPS 10 + Maemo::IAPConf *iaps[MAX_IAPS]; + QProcess *icd_stub; +#endif +}; + +// Helper functions +bool openSession(QNetworkSession *session); +bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration = true); +QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType); + +void tst_QNetworkSession::initTestCase() +{ + qRegisterMetaType("QNetworkSession::State"); + qRegisterMetaType("QNetworkSession::SessionError"); + qRegisterMetaType("QNetworkConfiguration"); + qRegisterMetaType("QNetworkConfiguration::Type"); + +#ifdef Q_WS_MAEMO_6 + iapconf = new Maemo::IAPConf("007"); + iapconf->setValue("ipv4_type", "AUTO"); + iapconf->setValue("wlan_wepkey1", "connt"); + iapconf->setValue("wlan_wepdefkey", 1); + iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); + iapconf->setValue("name", "James Bond"); + iapconf->setValue("type", "WLAN_INFRA"); + + gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); + gprsiap->setValue("ask_password", false); + gprsiap->setValue("gprs_accesspointname", "internet"); + gprsiap->setValue("gprs_password", ""); + gprsiap->setValue("gprs_username", ""); + gprsiap->setValue("ipv4_autodns", true); + gprsiap->setValue("ipv4_type", "AUTO"); + gprsiap->setValue("sim_imsi", "244070123456789"); + gprsiap->setValue("name", "MI6"); + gprsiap->setValue("type", "GPRS"); + + iapconf2 = new Maemo::IAPConf("osso.net"); + iapconf2->setValue("ipv4_type", "AUTO"); + iapconf2->setValue("wlan_wepkey1", "osso.net"); + iapconf2->setValue("wlan_wepdefkey", 1); + iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); + iapconf2->setValue("name", "osso.net"); + iapconf2->setValue("type", "WLAN_INFRA"); + iapconf2->setValue("wlan_security", "WEP"); + + /* Create large number of IAPs in the gconf and see what happens */ + fflush(stdout); + printf("Creating %d IAPS: ", MAX_IAPS); + for (int i=0; isetValue("name", QString("test-iap-")+num); + iaps[i]->setValue("type", "WLAN_INFRA"); + iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); + iaps[i]->setValue("wlan_security", "WPA_PSK"); + iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); + printf("."); + fflush(stdout); + } + printf("\n"); + fflush(stdout); + + icd_stub = new QProcess(this); + icd_stub->start("/usr/bin/icd2_stub.py"); + QTest::qWait(1000); + + // Add a known network to scan list that icd2 stub returns + QProcess dbus_send; + // 007 network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); + dbus_send.waitForFinished(); + + // osso.net network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); + dbus_send.waitForFinished(); +#endif + + inProcessSessionManagementCount = 0; + + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); + QTRY_VERIFY(spy.count() == 1); +} + +void tst_QNetworkSession::cleanupTestCase() +{ + if (!(manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport) && + (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces) && + inProcessSessionManagementCount == 0) { + QFAIL("No usable configurations found to complete all possible " + "tests in inProcessSessionManagement()"); + } + +#ifdef Q_WS_MAEMO_6 + iapconf->clear(); + delete iapconf; + iapconf2->clear(); + delete iapconf2; + gprsiap->clear(); + delete gprsiap; + + printf("Deleting %d IAPS : ", MAX_IAPS); + for (int i=0; iclear(); + delete iaps[i]; + printf("."); + fflush(stdout); + } + printf("\n"); + qDebug() << "Deleted" << MAX_IAPS << "IAPs"; + + icd_stub->terminate(); + icd_stub->waitForFinished(); +#endif +} + +void tst_QNetworkSession::invalidSession() +{ + // Verify that session created with invalid configuration remains in invalid state + QNetworkSession session(QNetworkConfiguration(), 0); + QVERIFY(!session.isOpen()); + QVERIFY(session.state() == QNetworkSession::Invalid); + + // Verify that opening session with invalid configuration both 1) emits invalidconfigurationerror + // and 2) sets session's state as invalid. + QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); + session.open(); + session.waitForOpened(1000); // Should bail out right away + QVERIFY(errorSpy.count() == 1); + QNetworkSession::SessionError error = + qvariant_cast (errorSpy.first().at(0)); + QVERIFY(error == QNetworkSession::InvalidConfigurationError); + QVERIFY(session.state() == QNetworkSession::Invalid); + + // Check same thing with a config from platform (there are subtle differences + // because emtpy configuration does not have private pointer). Test with config + // in '(un)defined' state + QList allConfigs = manager.allConfigurations(); + foreach(QNetworkConfiguration config, allConfigs) { + if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { + QNetworkSession session2(config); + QSignalSpy errorSpy2(&session2, SIGNAL(error(QNetworkSession::SessionError))); + session2.open(); + session2.waitForOpened(1000); // Should bail out right away + QVERIFY(errorSpy2.count() == 1); + QNetworkSession::SessionError error2 = + qvariant_cast (errorSpy2.first().at(0)); + QVERIFY(error2 == QNetworkSession::InvalidConfigurationError); + QVERIFY(session2.state() == QNetworkSession::Invalid); + break; // Once is enough + } + } +} + +void tst_QNetworkSession::sessionProperties_data() +{ + QTest::addColumn("configuration"); + + QTest::newRow("invalid configuration") << QNetworkConfiguration(); + + foreach (const QNetworkConfiguration &config, manager.allConfigurations()) { + const QString name = config.name().isEmpty() ? QString("") : config.name(); + QTest::newRow(name.toLocal8Bit().constData()) << config; + } +} + +void tst_QNetworkSession::sessionProperties() +{ + QFETCH(QNetworkConfiguration, configuration); + + QNetworkSession session(configuration); + + QVERIFY(session.configuration() == configuration); + + QStringList validBearerNames = QStringList() << QLatin1String("Unknown") + << QLatin1String("Ethernet") + << QLatin1String("WLAN") + << QLatin1String("2G") + << QLatin1String("CDMA2000") + << QLatin1String("WCDMA") + << QLatin1String("HSPA") + << QLatin1String("Bluetooth") + << QLatin1String("WiMAX"); + + if (!configuration.isValid()) { + QVERIFY(configuration.bearerName().isEmpty()); + } else { + switch (configuration.type()) + { + case QNetworkConfiguration::ServiceNetwork: + case QNetworkConfiguration::UserChoice: + default: + QVERIFY(configuration.bearerName().isEmpty()); + break; + case QNetworkConfiguration::InternetAccessPoint: + QVERIFY(validBearerNames.contains(configuration.bearerName())); + break; + } + } + + // QNetworkSession::interface() should return an invalid interface unless + // session is in the connected state. +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid()); +#endif + + if (!configuration.isValid()) { + QVERIFY(configuration.state() == QNetworkConfiguration::Undefined && + session.state() == QNetworkSession::Invalid); + } else { + switch (configuration.state()) { + case QNetworkConfiguration::Undefined: + QVERIFY(session.state() == QNetworkSession::NotAvailable); + break; + case QNetworkConfiguration::Defined: + QVERIFY(session.state() == QNetworkSession::NotAvailable); + break; + case QNetworkConfiguration::Discovered: + QVERIFY(session.state() == QNetworkSession::Connecting || + session.state() == QNetworkSession::Disconnected); + break; + case QNetworkConfiguration::Active: + QVERIFY(session.state() == QNetworkSession::Connected || + session.state() == QNetworkSession::Closing || + session.state() == QNetworkSession::Roaming); + break; + default: + QFAIL("Invalid configuration state"); + }; + } +} + +void tst_QNetworkSession::repeatedOpenClose_data() { + QTest::addColumn("bearerType"); + QTest::addColumn("configurationType"); + QTest::addColumn("repeatTimes"); + + QTest::newRow("WLAN_IAP") << "WLAN" << QNetworkConfiguration::InternetAccessPoint << 3; + // QTest::newRow("Cellular_IAP") << "cellular" << QNetworkConfiguration::InternetAccessPoint << 3; + // QTest::newRow("SNAP") << "bearer_type_not_relevant_with_SNAPs" << QNetworkConfiguration::ServiceNetwork << 3; +} + +// Tests repeated-open close. +void tst_QNetworkSession::repeatedOpenClose() { + QFETCH(QString, bearerType); + QFETCH(QNetworkConfiguration::Type, configurationType); + QFETCH(int, repeatTimes); + + // First check that opening once succeeds and determine if repeatable testing is doable + QNetworkConfiguration config = suitableConfiguration(bearerType, configurationType); + if (!config.isValid()) { + QSKIP("No suitable configurations, skipping this round of repeated open-close test.", SkipSingle); + } + qDebug() << "Using following configuratio to repeatedly open and close: " << config.name(); + QNetworkSession permanentSession(config); + if (!openSession(&permanentSession) || + !closeSession(&permanentSession)) { + QSKIP("Unable to open/close session, skipping this round of repeated open-close test.", SkipSingle); + } + for (int i = repeatTimes; i > 0; i--) { + QVERIFY(openSession(&permanentSession)); + QVERIFY(closeSession(&permanentSession)); + } +} + +void tst_QNetworkSession::roamingErrorCodes() { + +#ifndef Q_OS_SYMBIAN + QSKIP("Roaming supported on Symbian.", SkipAll); +#else + QNetworkConfiguration wlanIapConfig = suitableConfiguration("WLAN", QNetworkConfiguration::InternetAccessPoint); + if (!wlanIapConfig.isValid()) { + QSKIP("No WLAN IAP accessible, skipping test.", SkipAll); + } + // Check that opening and closing two sessions on same config work gracefully: + QNetworkSession iapSession(wlanIapConfig); + QVERIFY(openSession(&iapSession)); + QNetworkSession adminIapSession(wlanIapConfig); + QVERIFY(openSession(&adminIapSession)); + QVERIFY(closeSession(&iapSession, false)); // false == not a last session based on the configuration + QVERIFY(closeSession(&adminIapSession)); + + // Open configurations again, force close bearer and check that errors are emitted correctly + // on the other session + QVERIFY(openSession(&iapSession)); + QVERIFY(openSession(&adminIapSession)); + QSignalSpy errorSpy(&iapSession, SIGNAL(error(QNetworkSession::SessionError))); + adminIapSession.stop(); // requires NetworkControl capabilities + QTRY_VERIFY(!errorSpy.isEmpty()); // wait for error signals + QNetworkSession::SessionError error = qvariant_cast(errorSpy.first().at(0)); + QVERIFY(error == QNetworkSession::SessionAbortedError); + QVERIFY(iapSession.state() == QNetworkSession::Disconnected); + QVERIFY(adminIapSession.state() == QNetworkSession::Disconnected); +#endif // Q_OS_SYMBIAN + /* + // Check for roaming error. Challenging to automate, therefore commented out. + // Case requires that you have controllable WLAN in Internet SNAP (only). + QNetworkConfiguration snapConfig = suitableConfiguration("bearer_not_relevant_with_snaps", QNetworkConfiguration::ServiceNetwork); + if (!snapConfig.isValid()) { + QSKIP("No SNAP accessible, skipping test.", SkipAll); + } + QNetworkSession snapSession(snapConfig); + QVERIFY(openSession(&snapSession)); + QSignalSpy errorSpySnap(&snapSession, SIGNAL(error(QNetworkSession::SessionError))); + qDebug("Disconnect the WLAN now"); + QTRY_VERIFY(!errorSpySnap.isEmpty()); // wait for error signals + QVERIFY(errorSpySnap.count() == 1); + error = qvariant_cast(errorSpySnap.first().at(0)); + qDebug() << "Error received when turning off wlan on SNAP: " << error; + QVERIFY(error == QNetworkSession::RoamingError); + + qDebug("Connect the WLAN now"); + QTest::qWait(60000); // Wait for WLAN to get up + QNetworkConfiguration wlanIapConfig2 = suitableConfiguration("WLAN", QNetworkConfiguration::InternetAccessPoint); + QNetworkSession iapSession2(wlanIapConfig2); + QVERIFY(openSession(&iapSession2)); + QSignalSpy errorSpy2(&iapSession2, SIGNAL(error(QNetworkSession::SessionError))); + qDebug("Disconnect the WLAN now"); + QTRY_VERIFY(!errorSpy2.isEmpty()); // wait for error signals + QVERIFY(errorSpy2.count() == 1); + error = qvariant_cast(errorSpy2.first().at(0)); + QVERIFY(error == QNetworkSession::SessionAbortedError); + QVERIFY(iapSession2.state() == QNetworkSession::Disconnected); + */ +} + +void tst_QNetworkSession::userChoiceSession_data() +{ + QTest::addColumn("configuration"); + + QNetworkConfiguration config = manager.defaultConfiguration(); + if (config.type() == QNetworkConfiguration::UserChoice) + QTest::newRow("UserChoice") << config; + else + QSKIP("Default configuration is not a UserChoice configuration.", SkipAll); +} + +void tst_QNetworkSession::userChoiceSession() +{ + QFETCH(QNetworkConfiguration, configuration); + + QVERIFY(configuration.type() == QNetworkConfiguration::UserChoice); + + QNetworkSession session(configuration); + + // Check that configuration was really set + QVERIFY(session.configuration() == configuration); + + QVERIFY(!session.isOpen()); + + // Check that session is not active + QVERIFY(session.sessionProperty("ActiveConfiguration").toString().isEmpty()); + + // The remaining tests require the session to be not NotAvailable. + if (session.state() == QNetworkSession::NotAvailable) + QSKIP("Network is not available.", SkipSingle); + + QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened())); + QSignalSpy sessionClosedSpy(&session, SIGNAL(closed())); + QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening the session. + { + bool expectStateChange = session.state() != QNetworkSession::Connected; + + session.open(); + + session.waitForOpened(); + + if (session.isOpen()) + QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring up the interface, + // but the operation is not supported. + QSKIP("Configuration does not support open().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring up the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to open session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else if (error == QNetworkSession::UnknownSessionError) { + QSKIP("Unknown session error.", SkipSingle); + } else { + QFAIL("Error opening session."); + } + } else if (!sessionOpenedSpy.isEmpty()) { + QCOMPARE(sessionOpenedSpy.count(), 1); + QVERIFY(sessionClosedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(!stateChangedSpy.isEmpty()); + + QVERIFY(session.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + + const QString userChoiceIdentifier = + session.sessionProperty("UserChoiceConfiguration").toString(); + + QVERIFY(!userChoiceIdentifier.isEmpty()); + QVERIFY(userChoiceIdentifier != configuration.identifier()); + + QNetworkConfiguration userChoiceConfiguration = + manager.configurationFromIdentifier(userChoiceIdentifier); + + QVERIFY(userChoiceConfiguration.isValid()); + QVERIFY(userChoiceConfiguration.type() != QNetworkConfiguration::UserChoice); + + const QString testIdentifier("abc"); + //resetting UserChoiceConfiguration is ignored (read only property) + session.setSessionProperty("UserChoiceConfiguration", testIdentifier); + QVERIFY(session.sessionProperty("UserChoiceConfiguration").toString() != testIdentifier); + + const QString activeIdentifier = + session.sessionProperty("ActiveConfiguration").toString(); + + QVERIFY(!activeIdentifier.isEmpty()); + QVERIFY(activeIdentifier != configuration.identifier()); + + QNetworkConfiguration activeConfiguration = + manager.configurationFromIdentifier(activeIdentifier); + + QVERIFY(activeConfiguration.isValid()); + QVERIFY(activeConfiguration.type() == QNetworkConfiguration::InternetAccessPoint); + + //resetting ActiveConfiguration is ignored (read only property) + session.setSessionProperty("ActiveConfiguration", testIdentifier); + QVERIFY(session.sessionProperty("ActiveConfiguration").toString() != testIdentifier); + + if (userChoiceConfiguration.type() == QNetworkConfiguration::InternetAccessPoint) { + QVERIFY(userChoiceConfiguration == activeConfiguration); + } else { + QVERIFY(userChoiceConfiguration.type() == QNetworkConfiguration::ServiceNetwork); + QVERIFY(userChoiceConfiguration.children().contains(activeConfiguration)); + } + } else { + QFAIL("Timeout waiting for session to open."); + } + } +} + +void tst_QNetworkSession::sessionOpenCloseStop_data() +{ + QTest::addColumn("configuration"); + QTest::addColumn("forceSessionStop"); + + foreach (const QNetworkConfiguration &config, manager.allConfigurations()) { + const QString name = config.name().isEmpty() ? QString("") : config.name(); + QTest::newRow((name + QLatin1String(" close")).toLocal8Bit().constData()) + << config << false; + QTest::newRow((name + QLatin1String(" stop")).toLocal8Bit().constData()) + << config << true; + } +} + +void tst_QNetworkSession::sessionOpenCloseStop() +{ + QFETCH(QNetworkConfiguration, configuration); + QFETCH(bool, forceSessionStop); + + QNetworkSession session(configuration); + + // Test initial state of the session. + { + QVERIFY(session.configuration() == configuration); + QVERIFY(!session.isOpen()); + // session may be invalid if configuration is removed between when + // sessionOpenCloseStop_data() is called and here. + QVERIFY((configuration.isValid() && (session.state() != QNetworkSession::Invalid)) || + (!configuration.isValid() && (session.state() == QNetworkSession::Invalid))); + QVERIFY(session.error() == QNetworkSession::UnknownSessionError); + } + + // The remaining tests require the session to be not NotAvailable. + if (session.state() == QNetworkSession::NotAvailable) + QSKIP("Network is not available.", SkipSingle); + + QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened())); + QSignalSpy sessionClosedSpy(&session, SIGNAL(closed())); + QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening the session. + { + QNetworkSession::State previousState = session.state(); + bool expectStateChange = previousState != QNetworkSession::Connected; + + session.open(); + + session.waitForOpened(); + + if (session.isOpen()) + QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + + QVERIFY(session.state() == previousState); + + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring up the interface, + // but the operation is not supported. + QSKIP("Configuration does not support open().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring up the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to open session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else if (error == QNetworkSession::UnknownSessionError) { + QSKIP("Unknown Session error.", SkipSingle); + } else { + QFAIL("Error opening session."); + } + } else if (!sessionOpenedSpy.isEmpty()) { + QCOMPARE(sessionOpenedSpy.count(), 1); + QVERIFY(sessionClosedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) { + QTRY_VERIFY(stateChangedSpy.count() >= 2); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy.at(0).at(0)); + QVERIFY(state == QNetworkSession::Connecting); + + state = qvariant_cast(stateChangedSpy.at(1).at(0)); + QVERIFY(state == QNetworkSession::Connected); + } + + QVERIFY(session.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + } else { + QFAIL("Timeout waiting for session to open."); + } + } + + sessionOpenedSpy.clear(); + sessionClosedSpy.clear(); + stateChangedSpy.clear(); + errorSpy.clear(); + + QNetworkSession session2(configuration); + + QSignalSpy sessionOpenedSpy2(&session2, SIGNAL(opened())); + QSignalSpy sessionClosedSpy2(&session2, SIGNAL(closed())); + QSignalSpy stateChangedSpy2(&session2, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy2(&session2, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening a second session. + { + QVERIFY(session2.configuration() == configuration); + QVERIFY(!session2.isOpen()); + QVERIFY(session2.state() == QNetworkSession::Connected); + QVERIFY(session.error() == QNetworkSession::UnknownSessionError); + + session2.open(); + + QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty()); + + QVERIFY(session.isOpen()); + QVERIFY(session2.isOpen()); + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session2.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); + QCOMPARE(session.interface().index(), session2.interface().index()); + } + + sessionOpenedSpy2.clear(); + + if (forceSessionStop) { + // Test forcing the second session to stop the interface. + QNetworkSession::State previousState = session.state(); +#ifdef Q_CC_NOKIAX86 + // For S60 emulator builds: RConnection::Stop does not work on all Emulators + bool expectStateChange = false; +#else + bool expectStateChange = previousState != QNetworkSession::Disconnected; +#endif + + session2.stop(); + + QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty()); + + QVERIFY(!session2.isOpen()); + + if (!errorSpy2.isEmpty()) { + QVERIFY(!errorSpy.isEmpty()); + + // check for SessionAbortedError + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + QNetworkSession::SessionError error2 = + qvariant_cast(errorSpy2.first().at(0)); + + QVERIFY(error == QNetworkSession::SessionAbortedError); + QVERIFY(error2 == QNetworkSession::SessionAbortedError); + + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorSpy2.count(), 1); + + errorSpy.clear(); + errorSpy2.clear(); + } + + QVERIFY(errorSpy.isEmpty()); + QVERIFY(errorSpy2.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(stateChangedSpy2.count() >= 2 || !errorSpy2.isEmpty()); + + if (!errorSpy2.isEmpty()) { + QVERIFY(session2.state() == previousState); + QVERIFY(session.state() == previousState); + + QNetworkSession::SessionError error = + qvariant_cast(errorSpy2.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring down the interface, + // but the operation is not supported. + QSKIP("Configuration does not support stop().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring down the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to stop session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else { + QFAIL("Error stopping session."); + } + } else if (!sessionClosedSpy2.isEmpty()) { + if (expectStateChange) { + if (configuration.type() == QNetworkConfiguration::ServiceNetwork) { + bool roamedSuccessfully = false; + + QCOMPARE(stateChangedSpy2.count(), 4); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy2.at(0).at(0)); + QVERIFY(state == QNetworkSession::Connecting); + + state = qvariant_cast(stateChangedSpy2.at(1).at(0)); + QVERIFY(state == QNetworkSession::Connected); + + state = qvariant_cast(stateChangedSpy2.at(2).at(0)); + QVERIFY(state == QNetworkSession::Closing); + + state = qvariant_cast(stateChangedSpy2.at(3).at(0)); + QVERIFY(state == QNetworkSession::Disconnected); + + QTRY_VERIFY(stateChangedSpy.count() > 0); + state = qvariant_cast(stateChangedSpy.at(0).at(0)); + if (state == QNetworkSession::Roaming) { + QTRY_VERIFY(!errorSpy.isEmpty() || stateChangedSpy.count() > 1); + if (stateChangedSpy.count() > 1) { + state = qvariant_cast(stateChangedSpy.at(1).at(0)); + if (state == QNetworkSession::Connected) { + roamedSuccessfully = true; + QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); + } + } + } + if (roamedSuccessfully) { + QString configId = session.sessionProperty("ActiveConfiguration").toString(); + QNetworkConfiguration config = manager.configurationFromIdentifier(configId); + QNetworkSession session3(config); + QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError))); + QSignalSpy sessionOpenedSpy3(&session3, SIGNAL(opened())); + + session3.open(); + session3.waitForOpened(); + + if (session.isOpen()) + QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty()); + + session.stop(); + + QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); + QTRY_VERIFY(session3.state() == QNetworkSession::Disconnected); + } +#ifndef Q_CC_NOKIAX86 + if (!roamedSuccessfully) + QVERIFY(!errorSpy.isEmpty()); +#endif + } else { + QCOMPARE(stateChangedSpy2.count(), 2); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy2.at(0).at(0)); + QVERIFY(state == QNetworkSession::Closing); + + state = qvariant_cast(stateChangedSpy2.at(1).at(0)); + QVERIFY(state == QNetworkSession::Disconnected); + } + + QTRY_VERIFY(!sessionClosedSpy.isEmpty()); + QVERIFY(session.state() == QNetworkSession::Disconnected); + QVERIFY(session2.state() == QNetworkSession::Disconnected); + } + + QVERIFY(errorSpy2.isEmpty()); + + ++inProcessSessionManagementCount; + } else { + QFAIL("Timeout waiting for session to stop."); + } + +#ifndef Q_CC_NOKIAX86 + QVERIFY(!sessionClosedSpy.isEmpty()); +#endif + QVERIFY(!sessionClosedSpy2.isEmpty()); + +#ifndef Q_CC_NOKIAX86 + QVERIFY(!session.isOpen()); +#endif + QVERIFY(!session2.isOpen()); + } else { + // Test closing the second session. + { + int stateChangedCountBeforeClose = stateChangedSpy2.count(); + session2.close(); + + QTRY_VERIFY(!sessionClosedSpy2.isEmpty()); +#ifndef Q_CC_NOKIAX86 + QVERIFY(stateChangedSpy2.count() == stateChangedCountBeforeClose); +#endif + + QVERIFY(sessionClosedSpy.isEmpty()); + + QVERIFY(session.isOpen()); + QVERIFY(!session2.isOpen()); + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session2.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); + QCOMPARE(session.interface().index(), session2.interface().index()); + } + + sessionClosedSpy2.clear(); + + // Test closing the first session. + { +#ifdef Q_CC_NOKIAX86 + // For S60 emulator builds: RConnection::Close does not actually + // close network connection on all Emulators + bool expectStateChange = false; +#else + bool expectStateChange = session.state() != QNetworkSession::Disconnected && + manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport; +#endif + + session.close(); + + QTRY_VERIFY(!sessionClosedSpy.isEmpty() || !errorSpy.isEmpty()); + + QVERIFY(!session.isOpen()); + + if (expectStateChange) + QTRY_VERIFY(!stateChangedSpy.isEmpty() || !errorSpy.isEmpty()); + + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring down the interface, + // but the operation is not supported. + QSKIP("Configuration does not support close().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring down the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to close session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else { + QFAIL("Error closing session."); + } + } else if (!sessionClosedSpy.isEmpty()) { + QVERIFY(sessionOpenedSpy.isEmpty()); + QCOMPARE(sessionClosedSpy.count(), 1); + if (expectStateChange) + QVERIFY(!stateChangedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); + + ++inProcessSessionManagementCount; + } else { + QFAIL("Timeout waiting for session to close."); + } + } + } +} + +QDebug operator<<(QDebug debug, const QList &list) +{ + debug.nospace() << "( "; + foreach (const QNetworkConfiguration &config, list) + debug.nospace() << config.identifier() << ", "; + debug.nospace() << ")\n"; + return debug; +} + +// Note: outOfProcessSession requires that at least one configuration is +// at Discovered -state. +void tst_QNetworkSession::outOfProcessSession() +{ +#if defined(Q_OS_SYMBIAN) && defined(__WINS__) + QSKIP("Symbian emulator does not support two [QR]PRocesses linking a dll (QtBearer.dll) with global writeable static data.", SkipAll); +#endif + QNetworkConfigurationManager manager; + // Create a QNetworkConfigurationManager to detect configuration changes made in Lackey. This + // is actually the essence of this testcase - to check that platform mediates/reflects changes + // regardless of process boundaries. The interprocess communication is more like a way to get + // this test-case act correctly and timely. + QList before = manager.allConfigurations(QNetworkConfiguration::Active); + QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration))); + + // Cannot read/write to processes on WinCE or Symbian. + // Easiest alternative is to use sockets for IPC. + QLocalServer oopServer; + // First remove possible earlier listening address which would cause listen to fail + // (e.g. previously abruptly ended unit test might cause this) + QLocalServer::removeServer("tst_qnetworksession"); + oopServer.listen("tst_qnetworksession"); + + QProcess lackey; + lackey.start("qnetworksessionlackey"); + QVERIFY(lackey.waitForStarted()); + + QVERIFY(oopServer.waitForNewConnection(-1)); + QLocalSocket *oopSocket = oopServer.nextPendingConnection(); + + do { + QByteArray output; + + if(oopSocket->waitForReadyRead()) { + output = oopSocket->readLine().trimmed(); + } + + if (output.startsWith("Started session ")) { + QString identifier = QString::fromLocal8Bit(output.mid(20).constData()); + QNetworkConfiguration changed; + + do { + QTRY_VERIFY(!spy.isEmpty()); + changed = qvariant_cast(spy.takeFirst().at(0)); + } while (changed.identifier() != identifier); + + QVERIFY((changed.state() & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active); + + QVERIFY(!before.contains(changed)); + + QList after = + manager.allConfigurations(QNetworkConfiguration::Active); + + QVERIFY(after.contains(changed)); + + spy.clear(); + + oopSocket->write("stop\n"); + oopSocket->waitForBytesWritten(); + + do { + QTRY_VERIFY(!spy.isEmpty()); + + changed = qvariant_cast(spy.takeFirst().at(0)); + } while (changed.identifier() != identifier); + + QVERIFY((changed.state() & QNetworkConfiguration::Active) != + QNetworkConfiguration::Active); + + QList afterStop = + manager.allConfigurations(QNetworkConfiguration::Active); + + QVERIFY(!afterStop.contains(changed)); + + oopSocket->disconnectFromServer(); + oopSocket->waitForDisconnected(-1); + + lackey.waitForFinished(); + } + // This is effected by QTBUG-4903, process will always report as running + //} while (lackey.state() == QProcess::Running); + + // Workaround: the socket in the lackey will disconnect on exit + } while (oopSocket->state() == QLocalSocket::ConnectedState); + + switch (lackey.exitCode()) { + case 0: + qDebug("Lackey returned exit success (0)"); + break; + case 1: + QSKIP("No discovered configurations found.", SkipAll); + case 2: + QSKIP("Lackey could not start session.", SkipAll); + default: + QSKIP("Lackey failed", SkipAll); + } +} + +// A convinience / helper function for testcases. Return the first matching configuration. +// Ignores configurations in other than 'discovered' -state. Returns invalid (QNetworkConfiguration()) +// if none found. +QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType) { + // Refresh configurations and derive configurations matching given parameters. + QNetworkConfigurationManager mgr; + QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); + mgr.updateConfigurations(); + QTRY_NOOP(updateSpy.count() == 1); + if (updateSpy.count() != 1) { + qDebug("tst_QNetworkSession::suitableConfiguration() failure: unable to update configurations"); + return QNetworkConfiguration(); + } + QList discoveredConfigs = mgr.allConfigurations(QNetworkConfiguration::Discovered); + foreach(QNetworkConfiguration config, discoveredConfigs) { + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + // qDebug() << "Dumping config because is active: " << config.name(); + discoveredConfigs.removeOne(config); + } else if (config.type() != configType) { + // qDebug() << "Dumping config because type (IAP/SNAP) mismatches: " << config.name(); + discoveredConfigs.removeOne(config); + } else if ((config.type() == QNetworkConfiguration::InternetAccessPoint) && + bearerType == "cellular") { // 'cellular' bearertype is for convinience + if (config.bearerName() != "2G" && + config.bearerName() != "CDMA2000" && + config.bearerName() != "WCDMA" && + config.bearerName() != "HSPA") { + // qDebug() << "Dumping config because bearer mismatches (cellular): " << config.name(); + discoveredConfigs.removeOne(config); + } + } else if ((config.type() == QNetworkConfiguration::InternetAccessPoint) && + bearerType != config.bearerName()) { + // qDebug() << "Dumping config because bearer mismatches (WLAN): " << config.name(); + discoveredConfigs.removeOne(config); + } + } + if (discoveredConfigs.isEmpty()) { + qDebug("tst_QNetworkSession::suitableConfiguration() failure: no suitable configurations present."); + return QNetworkConfiguration(); + } else { + return discoveredConfigs.first(); + } +} + +// A convinience function for test-cases: opens the given configuration and return +// true if it was done gracefully. +bool openSession(QNetworkSession *session) { + QNetworkConfigurationManager mgr; + QSignalSpy openedSpy(session, SIGNAL(opened())); + QSignalSpy stateChangeSpy(session, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy(session, SIGNAL(error(QNetworkSession::SessionError))); + QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration))); + // Store some initial statuses, because expected signals differ if the config is already + // active by some other session + QNetworkConfiguration::StateFlags configInitState = session->configuration().state(); + QNetworkSession::State sessionInitState = session->state(); + + if (session->isOpen() || + !session->sessionProperty("ActiveConfiguration").toString().isEmpty()) { + qDebug("tst_QNetworkSession::openSession() failure: session was already open / active."); + return false; + } else { + session->open(); + session->waitForOpened(120000); // Bringing interfaces up and down may take time at platform + } + // Check that connection opening went by the book. Add checks here if more strictness needed. + if (!session->isOpen()) { + qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::open() failed."); + return false; + } + if (openedSpy.count() != 1) { + qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::opened() - signal not received."); + return false; + } + if (!errorSpy.isEmpty()) { + qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::error() - signal was detected."); + return false; + } + if (sessionInitState != QNetworkSession::Connected && + stateChangeSpy.isEmpty()) { + qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::stateChanged() - signals not detected."); + return false; + } + if (configInitState != QNetworkConfiguration::Active && + configChangeSpy.isEmpty()) { + qDebug("tst_QNetworkSession::openSession() failure: QNetworkConfigurationManager::configurationChanged() - signals not detected."); + return false; + } + if (session->configuration().state() != QNetworkConfiguration::Active) { + qDebug("tst_QNetworkSession::openSession() failure: session's configuration is not in 'Active' -state."); + return false; + } + return true; +} + +// Helper function for closing opened session. Performs checks that +// session is closed gradefully (e.g. signals). Function does not delete +// the session. The lastSessionOnConfiguration (true by default) is used to +// tell if there are more sessions open, basing on same configration. This +// impacts the checks made. +bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration) { + if (!session) { + qDebug("tst_QNetworkSession::closeSession() failure: NULL session given"); + return false; + } + if (session->state() != QNetworkSession::Connected || + !session->isOpen()) { + qDebug("tst_QNetworkSession::closeSession() failure: session is not opened."); + return false; + } + QNetworkConfigurationManager mgr; + QSignalSpy sessionClosedSpy(session, SIGNAL(closed())); + QSignalSpy sessionStateChangedSpy(session, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy sessionErrorSpy(session, SIGNAL(error(QNetworkSession::SessionError))); + QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration))); + + session->close(); + + if (!sessionErrorSpy.isEmpty()) { + qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::error() received."); + return false; + } + if (sessionClosedSpy.count() != 1) { + qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::closed() signal not received."); + return false; + } + if (lastSessionOnConfiguration && + sessionStateChangedSpy.isEmpty()) { + qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::stateChanged() signals not received."); + return false; + } + if (lastSessionOnConfiguration && + session->state() != QNetworkSession::Disconnected) { + qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession is not in Disconnected -state"); + return false; + } + QTRY_NOOP(!configChangeSpy.isEmpty()); + if (lastSessionOnConfiguration && + configChangeSpy.isEmpty()) { + qDebug("tst_QNetworkSession::closeSession() failure: QNetworkConfigurationManager::configurationChanged() - signal not detected."); + return false; + } + if (lastSessionOnConfiguration && + session->configuration().state() != QNetworkConfiguration::Discovered) { + qDebug("tst_QNetworkSession::closeSession() failure: session's configuration is not back in 'Discovered' -state."); + return false; + } + return true; +} + + + +QTEST_MAIN(tst_QNetworkSession) + +#include "tst_qnetworksession.moc" + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,28 @@ +SOURCES += tst_qnetworksession.cpp +HEADERS += ../../qbearertestcommon.h +TARGET = tst_qnetworksession +CONFIG += testcase + +QT = core network + +INCLUDEPATH += ../../../../src/bearer + +include(../../../../common.pri) +CONFIG += mobility +MOBILITY = bearer + +wince* { + LACKEY.sources = $$OUTPUT_DIR/build/tests/bin/qnetworksessionlackey.exe + LACKEY.path = . + DEPLOYMENT += LACKEY +} + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData PowerMgmt +} + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/bearerex.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/bearerex.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,560 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "bearerex.h" + +#include + +Q_DECLARE_METATYPE(QNetworkConfiguration) + +BearerEx::BearerEx(QWidget* parent) + : QMainWindow(parent) +{ + setupUi(this); + + createMenus(); + + connect(&m_NetworkConfigurationManager, SIGNAL(updateCompleted()), this, SLOT(configurationsUpdateCompleted())); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationAdded(const QNetworkConfiguration&)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), + this, SLOT(configurationRemoved(const QNetworkConfiguration&))); + connect(&m_NetworkConfigurationManager, SIGNAL(onlineStateChanged(bool)), + this, SLOT(onlineStateChanged(bool))); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), + this, SLOT(configurationChanged(const QNetworkConfiguration&))); + showConfigurations(); +} + +void BearerEx::createMenus() +{ + QAction* act1 = new QAction(tr("Show Details"), this); + menuBar()->addAction(act1); + connect(act1, SIGNAL(triggered()), this, SLOT(on_showDetailsButton_clicked())); + + QAction* exitAct = new QAction(tr("Exit"), this); + menuBar()->addAction(exitAct); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); +} + +void BearerEx::showConfigurations() +{ + listWidget->clear(); + QListWidgetItem* listItem; + + QNetworkConfiguration defaultConfig = m_NetworkConfigurationManager.defaultConfiguration(); + if (defaultConfig.type() == QNetworkConfiguration::UserChoice) { + listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + font.setUnderline(true); + listItem->setFont(font); + listItem->setText(" UserChoice"); + listItem->setData(Qt::UserRole, qVariantFromValue(defaultConfig)); + listWidget->addItem(listItem); + } + + QList configurations = m_NetworkConfigurationManager.allConfigurations(); + for (int i=0; ifont(); + font.setBold(true); + font.setUnderline(true); + listItem->setFont(font); + } + listItem->setText(text); + listItem->setData(Qt::UserRole, qVariantFromValue(configurations[i])); + listWidget->addItem(listItem); + } +} + +void BearerEx::on_updateConfigurationsButton_clicked() +{ + m_NetworkConfigurationManager.updateConfigurations(); +} + +void BearerEx::on_updateListButton_clicked() +{ + showConfigurations(); +} + +void BearerEx::on_showDetailsButton_clicked() +{ + QListWidgetItem* item = listWidget->currentItem(); + if (!item) { + return; + } + + QNetworkConfiguration networkConfiguration = qVariantValue(item->data(Qt::UserRole)); + DetailedInfoDialog infoDialog(&networkConfiguration,this); + infoDialog.exec(); +} + +void BearerEx::on_createSessionButton_clicked() +{ + QListWidgetItem* item = listWidget->currentItem(); + if (!item) { + return; + } + QNetworkConfiguration networkConfiguration = qVariantValue(item->data(Qt::UserRole)); + int newTabIndex = mainTabWidget->count(); + SessionTab* newTab = new SessionTab(&networkConfiguration,&m_NetworkConfigurationManager,eventListWidget,newTabIndex-1); + QString label = QString("S")+QString::number(newTabIndex-1); + mainTabWidget->insertTab(newTabIndex,newTab,label); + mainTabWidget->setCurrentIndex(newTabIndex); +} + +void BearerEx::on_clearEventListButton_clicked() +{ + eventListWidget->clear(); +} + +void BearerEx::configurationAdded(const QNetworkConfiguration& config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("Added: ")+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationRemoved(const QNetworkConfiguration& config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("Removed: ")+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::onlineStateChanged(bool isOnline) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + if (isOnline) { + listItem->setText(QString("> Online")); + } else { + listItem->setText(QString("< Offline")); + } + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationChanged(const QNetworkConfiguration & config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QString state; + switch (config.state()) + { + case QNetworkConfiguration::Undefined: + state = "Undef : "; + break; + case QNetworkConfiguration::Defined: + state = "Def : "; + break; + case QNetworkConfiguration::Discovered: + state = "Disc : "; + break; + case QNetworkConfiguration::Active: + state = "Act : "; + break; + } + listItem->setText(state+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationsUpdateCompleted() +{ + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + msgBox.setText("Configurations update completed."); + msgBox.exec(); +} + +DetailedInfoDialog::DetailedInfoDialog(QNetworkConfiguration* apNetworkConfiguration, QWidget * parent) + : QDialog(parent) +{ + setupUi(this); + + tableWidget->setColumnCount(2); + int rowCount = 2; + + if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + rowCount = rowCount + apNetworkConfiguration->children().count(); + } + + tableWidget->setRowCount(rowCount); + tableWidget->setColumnWidth(1,250); + tableWidget->setItem(0, 0, new QTableWidgetItem(tr("Name"))); + tableWidget->setItem(0, 1, new QTableWidgetItem(apNetworkConfiguration->name())); + tableWidget->setItem(1, 0, new QTableWidgetItem(tr("Id"))); + tableWidget->setItem(1, 1, new QTableWidgetItem(apNetworkConfiguration->identifier())); + if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + for (int i=0; ichildren().count(); i++) { + tableWidget->setItem(i+2, 0, new QTableWidgetItem(QString("IAP")+QString::number(i+1))); + tableWidget->setItem(i+2, 1, new QTableWidgetItem(apNetworkConfiguration->children()[i].name())); + } + } + + tableWidget->setFocusPolicy(Qt::NoFocus); + +#ifdef Q_OS_SYMBIAN + this->showMaximized(); +#endif +} + +SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration, + QNetworkConfigurationManager* configManager, + QListWidget* eventListWidget, + int index, + BearerEx * parent) + : QWidget(parent), m_http(0), m_eventListWidget(eventListWidget), + m_index(index), m_httpRequestOngoing(false), m_alrEnabled (false) +{ + setupUi(this); + + m_ConfigManager = configManager; + m_NetworkSession = new QNetworkSession(*apNetworkConfiguration); + + // Update initial Session state to UI + newState(m_NetworkSession->state()); + + connect(m_NetworkSession, SIGNAL(newConfigurationActivated()), this, SLOT(newConfigurationActivated())); + connect(m_NetworkSession, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + connect(m_NetworkSession, SIGNAL(opened()), this, SLOT(opened())); + connect(m_NetworkSession, SIGNAL(closed()), this, SLOT(closed())); + connect(m_NetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(error(QNetworkSession::SessionError))); + + if (apNetworkConfiguration->type() == QNetworkConfiguration::InternetAccessPoint) { + snapLabel->hide(); + snapLineEdit->hide(); + alrButton->hide(); + iapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")"); + } else if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + snapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")"); + } + bearerLineEdit->setText(apNetworkConfiguration->bearerName()); + sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+ + QString(" / ")+ + QString::number(m_NetworkSession->bytesReceived())); + snapLineEdit->setFocusPolicy(Qt::NoFocus); + iapLineEdit->setFocusPolicy(Qt::NoFocus); + bearerLineEdit->setFocusPolicy(Qt::NoFocus); + sentRecDataLineEdit->setFocusPolicy(Qt::NoFocus); + stateLineEdit->setFocusPolicy(Qt::NoFocus); +} + +SessionTab::~SessionTab() +{ + delete m_NetworkSession; + delete m_http; +} + +void SessionTab::on_createQHttpButton_clicked() +{ + if (m_httpRequestOngoing) { + return; + } + + if (m_http) { + disconnect(m_http, 0, 0, 0); + delete m_http; + } + m_http = new QHttp(this); + createQHttpButton->setText("Recreate QHttp"); + connect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool))); +} + +void SessionTab::on_sendRequestButton_clicked() +{ + if (m_http) { + QString urlstring("http://www.google.com"); + QUrl url(urlstring); + m_http->setHost(url.host(), QHttp::ConnectionModeHttp, url.port() == -1 ? 0 : url.port()); + m_http->get(urlstring); + m_httpRequestOngoing = true; + } else { + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + msgBox.setText("QHttp not created.\nCreate QHttp First."); + msgBox.exec(); + } +} + +void SessionTab::on_openSessionButton_clicked() +{ + m_NetworkSession->open(); + if (m_NetworkSession->isOpen()) { + newState(m_NetworkSession->state()); + } +} + +void SessionTab::on_closeSessionButton_clicked() +{ + m_NetworkSession->close(); + if (!m_NetworkSession->isOpen()) { + newState(m_NetworkSession->state()); + } +} + +void SessionTab::on_stopConnectionButton_clicked() +{ + m_NetworkSession->stop(); +} + +void SessionTab::on_alrButton_clicked() +{ + if (!m_alrEnabled) { + connect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), + this, SLOT(preferredConfigurationChanged(const QNetworkConfiguration&, bool))); + alrButton->setText("Disable ALR"); + m_alrEnabled = true; + } else { + disconnect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), 0, 0); + alrButton->setText("Enable ALR"); + m_alrEnabled = false; + } +} + +void SessionTab::on_deleteSessionButton_clicked() +{ + setWindowTitle("Bearer Example"); + delete this; +} + +void SessionTab::newConfigurationActivated() +{ + QMessageBox msgBox; + msgBox.setText("New configuration activated."); + msgBox.setInformativeText("Do you want to accept new configuration?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (msgBox.exec() == QMessageBox::Yes) { + m_NetworkSession->accept(); + iapLineEdit->setText(m_config.name()+" ("+m_config.identifier()+")"); + } else { + m_NetworkSession->reject(); + } +} + +void SessionTab::preferredConfigurationChanged(const QNetworkConfiguration& config, bool /*isSeamless*/) +{ + m_config = config; + QMessageBox msgBox; + msgBox.setText("Roaming to new configuration."); + msgBox.setInformativeText("Do you want to migrate to "+config.name()+"?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (msgBox.exec() == QMessageBox::Yes) { + m_NetworkSession->migrate(); + } else { + m_NetworkSession->ignore(); + } +} + +void SessionTab::opened() +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Opened")); + m_eventListWidget->addItem(listItem); + + QVariant identifier = m_NetworkSession->property("ActiveConfiguration"); + if (!identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid()) { + iapLineEdit->setText(config.name()+" ("+config.identifier()+")"); + } + } + + if (m_NetworkSession->configuration().type() == QNetworkConfiguration::UserChoice) { + QVariant identifier = m_NetworkSession->property("UserChoiceConfiguration"); + if (!identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid() && (config.type() == QNetworkConfiguration::ServiceNetwork)) { + snapLineEdit->setText(config.name()); + } + } + } +} + +void SessionTab::closed() +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Closed")); + m_eventListWidget->addItem(listItem); +} + +QString SessionTab::stateString(QNetworkSession::State state) +{ + QString stateString; + switch (state) + { + case QNetworkSession::Invalid: + stateString = "Invalid"; + break; + case QNetworkSession::NotAvailable: + stateString = "NotAvailable"; + break; + case QNetworkSession::Connecting: + stateString = "Connecting"; + break; + case QNetworkSession::Connected: + stateString = "Connected"; + break; + case QNetworkSession::Closing: + stateString = "Closing"; + break; + case QNetworkSession::Disconnected: + stateString = "Disconnected"; + break; + case QNetworkSession::Roaming: + stateString = "Roaming"; + break; + } + return stateString; +} + +void SessionTab::stateChanged(QNetworkSession::State state) +{ + newState(state); + + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+stateString(state)); + m_eventListWidget->addItem(listItem); +} + +void SessionTab::newState(QNetworkSession::State state) +{ + QVariant identifier = m_NetworkSession->property("ActiveConfiguration"); + if (state == QNetworkSession::Connected && !identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid()) { + iapLineEdit->setText(config.name()+" ("+config.identifier()+")"); + bearerLineEdit->setText(config.bearerName()); + } + } else { + bearerLineEdit->setText(m_NetworkSession->configuration().bearerName()); + } + + QString active; + if (m_NetworkSession->isOpen()) { + active = " (O)"; + } + stateLineEdit->setText(stateString(state)+active); +} + +void SessionTab::error(QNetworkSession::SessionError error) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + + QString errorString; + switch (error) + { + case QNetworkSession::UnknownSessionError: + errorString = "UnknownSessionError"; + break; + case QNetworkSession::SessionAbortedError: + errorString = "SessionAbortedError"; + break; + case QNetworkSession::RoamingError: + errorString = "RoamingError"; + break; + case QNetworkSession::OperationNotSupportedError: + errorString = "OperationNotSupportedError"; + break; + case QNetworkSession::InvalidConfigurationError: + errorString = "InvalidConfigurationError"; + break; + } + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+errorString); + m_eventListWidget->addItem(listItem); + + msgBox.setText(errorString); + msgBox.exec(); +} + +void SessionTab::done(bool error) +{ + m_httpRequestOngoing = false; + + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + if (error) { + msgBox.setText("HTTP request failed."); + } else { + QString result(m_http->readAll()); + msgBox.setText(QString("HTTP request finished successfully.\nReceived ")+QString::number(result.length())+QString(" bytes.")); + } + msgBox.exec(); + + sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+ + QString(" / ")+ + QString::number(m_NetworkSession->bytesReceived())); +} + +// End of file + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/bearerex.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/bearerex.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef ACCESSPOINTMANAGEREX_H +#define ACCESSPOINTMANAGEREX_H + +#include + +#include "ui_bearerex.h" +#include "ui_detailedinfodialog.h" +#include "ui_sessiondialog.h" + +#include "qnetworkconfigmanager.h" +#include "qnetworksession.h" +#include "xqlistwidget.h" + +QT_BEGIN_NAMESPACE +class QHttp; +QT_END_NAMESPACE + +class SessionTab; + +QTM_USE_NAMESPACE + +class BearerEx : public QMainWindow, public Ui::BearerExMainWindow +{ + Q_OBJECT + +public: + BearerEx(QWidget* parent = 0); + void createMenus(); + void showConfigurations(); + +private Q_SLOTS: + void on_updateConfigurationsButton_clicked(); + void on_updateListButton_clicked(); + void on_showDetailsButton_clicked(); + void on_createSessionButton_clicked(); + void on_clearEventListButton_clicked(); + + void configurationsUpdateCompleted(); + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); + void configurationChanged(const QNetworkConfiguration & config); + +private: + QNetworkConfigurationManager m_NetworkConfigurationManager; + QAction* m_openAction; +}; + +class DetailedInfoDialog : public QDialog, public Ui::DetailedInfoDialog +{ + Q_OBJECT + +public: + DetailedInfoDialog(QNetworkConfiguration* apNetworkConfiguration = 0, QWidget* parent = 0); +}; + + +class SessionTab : public QWidget, public Ui::SessionTab +{ + Q_OBJECT + +public: + SessionTab(QNetworkConfiguration* apNetworkConfiguration = 0, QNetworkConfigurationManager* configManager = 0, + QListWidget* eventListWidget = 0, int index = 0, BearerEx* parent = 0); + ~SessionTab(); + + QString stateString(QNetworkSession::State state); + +private Q_SLOTS: + void on_createQHttpButton_clicked(); + void on_sendRequestButton_clicked(); + void on_openSessionButton_clicked(); + void on_closeSessionButton_clicked(); + void on_stopConnectionButton_clicked(); + void on_deleteSessionButton_clicked(); + void on_alrButton_clicked(); + void done(bool error); + + void newConfigurationActivated(); + void preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless); + void stateChanged(QNetworkSession::State state); + void newState(QNetworkSession::State state); + void opened(); + void closed(); + void error(QNetworkSession::SessionError error); + +private: //data + QHttp* m_http; + QNetworkSession* m_NetworkSession; + QNetworkConfigurationManager* m_ConfigManager; + QListWidget* m_eventListWidget; + QNetworkConfiguration m_config; + int m_index; + bool m_httpRequestOngoing; + bool m_alrEnabled; +}; + +#endif // ACCESSPOINTMANAGEREX_H + +// End of file + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/bearerex.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/bearerex.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,29 @@ +TEMPLATE = app +TARGET = BearerEx + +QT += core \ + gui \ + network + +FORMS += sessiondialog.ui \ + bearerex.ui \ + detailedinfodialog.ui +include(../../common.pri) +#not really a test case but deployment happens same way +CONFIG += testcase + +DEPENDPATH += . +INCLUDEPATH += . \ + ../../src/bearer + +# Example headers and sources +HEADERS += bearerex.h \ + xqlistwidget.h + +SOURCES += bearerex.cpp \ + main.cpp \ + xqlistwidget.cpp + +CONFIG += mobility +MOBILITY = bearer +symbian:TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/bearerex.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/bearerex.ui Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,95 @@ + + BearerExMainWindow + + + + 0 + 0 + 360 + 640 + + + + Bearer Example + + + + + + + + Main + + + + + + Network Configurations + + + Qt::AlignCenter + + + + + + + + + + + + Update Configs + + + + + + + Update List + + + + + + + Create Session + + + + + + + Show Details + + + + + + + + + + Events + + + + + + + + + Clear + + + + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/detailedinfodialog.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/detailedinfodialog.ui Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,54 @@ + + DetailedInfoDialog + + + + 0 + 0 + 308 + 396 + + + + Bearer Example + + + + + + Detailed information + + + + + + + + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DetailedInfoDialog + accept() + + + 205 + 371 + + + 223 + 8 + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/main.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include + +#include "bearerex.h" + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + BearerEx bearerEx; +#ifdef Q_OS_SYMBIAN + bearerEx.showMaximized(); +#else + bearerEx.show(); +#endif + return app.exec(); +} + +// End of file + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/sessiondialog.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/sessiondialog.ui Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,139 @@ + + SessionTab + + + + + + + + SNAP + + + + + + + true + + + + + + + IAP + + + + + + + true + + + true + + + + + + + Bearer + + + + + + + true + + + + + + + Sent/Rec. + + + + + + + true + + + + + + + State + + + + + + + true + + + + + + + + + + + Open Session + + + + + + + Close Session + + + + + + + Stop Conn. + + + + + + + Create QHttp + + + + + + + Send Test Req. + + + + + + + Enable ALR + + + + + + + Delete Session + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/xqlistwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/xqlistwidget.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "xqlistwidget.h" + +XQListWidget::XQListWidget(QWidget* parent) : QListWidget(parent) +{ +} + +void XQListWidget::keyPressEvent(QKeyEvent* event) +{ + switch (event->key()) + { + case Qt::Key_Left: + { + focusPreviousChild(); + break; + } + case Qt::Key_Right: + { + focusNextChild(); + break; + } + default: + { + QListWidget::keyPressEvent(event); + } + } +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/bearerex/xqlistwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/bearerex/xqlistwidget.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef XQLISTWIDGET_H +#define XQLISTWIDGET_H + +#include +#include + +class XQListWidget: public QListWidget +{ +public: + XQListWidget(QWidget* parent = 0); + +protected: + void keyPressEvent(QKeyEvent* event); +}; + +#endif // XQLISTWIDGET_H + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/networkmanager/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/networkmanager/README Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,2 @@ +This application serves as prototype/test-bed for NetworkManager development. The excellent (non-existing) documentation +for the various NetworkManager interfaces makes this harder than it should be. diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/networkmanager/dialog.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/networkmanager/dialog.ui Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,213 @@ + + + Dialog + + + + 0 + 0 + 919 + 657 + + + + Dialog + + + + + + + + Connections + + + + + + + + Path + + + + + State + + + + + Id + + + + + Settings + + + + + + + + + + + + Devices: + + + + + + + + Path + + + + + Managed + + + + + Interface + + + + + Driver + + + + + Type + + + + + State + + + + + IP4 Address + + + + + IP4 Config + + + + + Hostname + + + + + Domains + + + + + + + + + + Qt::Horizontal + + + + 908 + 20 + + + + + + + + true + + + + SSID + + + + + Strength + + + + + Wpa + + + + + Rsn + + + + + Freq + + + + + Hardware Address + + + + + Mode + + + + + Max Bitrate + + + + + + + + + + Start + + + + + + + Stop + + + + + + + Scan + + + + + + + Update + + + + + + + + + + diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/networkmanager/networkmanager.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/networkmanager/networkmanager.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,20 @@ +SOURCES += networkmanagertest.cpp nmview.cpp +HEADERS += nmview.h +TARGET = tst_networkmanagertest + +QT = core network dbus gui + +#not really a test case but deployment happens same way +CONFIG += testcase + +requires(contains(QT_CONFIG,dbus)) + +INCLUDEPATH += ../../src/bearer +include(../../common.pri) + +CONFIG += mobility +MOBILITY = bearer + +#MOC_DIR = .moc +#OBJECTS_DIR = .obj +FORMS += dialog.ui diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/networkmanager/networkmanagertest.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/networkmanager/networkmanagertest.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nmview.h" + +#include + +typedef QMap< QString, QMap > SettingsMap; +Q_DECLARE_METATYPE(SettingsMap) + +void printConnectionDetails(const QString& service) +{ + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface allCons(service, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS, dbc); + if (allCons.isValid()) { + QDBusReply > reply = allCons.call("ListConnections"); + if ( reply.isValid() ) { + qWarning() << "Known connections:"; + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + QDBusInterface sysIface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, path.path(), NM_DBUS_IFACE_SETTINGS_CONNECTION, dbc); + if (sysIface.isValid()) { + QDBusMessage r = sysIface.call("GetSettings"); + QDBusReply< SettingsMap > rep = sysIface.call("GetSettings"); + qWarning() << " GetSettings:" << r.arguments() << r.signature() << rep.isValid() << sysIface.lastError(); + QMap< QString, QMap > map = rep.value(); + QList list = map.keys(); + foreach (QString key, list) { + QMap innerMap = map[key]; + qWarning() << " Key: " << key; + QMap::const_iterator i = innerMap.constBegin(); + while (i != innerMap.constEnd()) { + QString k = i.key(); + qWarning() << " Key: " << k << " Entry: " << i.value(); + if (k == "addresses" && i.value().canConvert()) { + QDBusArgument arg = i.value().value(); + arg.beginArray(); + while (!arg.atEnd()) { + QDBusVariant addr; + arg >> addr; + uint ip = addr.variant().toUInt(); + qWarning() << ip; + qWarning() << " " << QHostAddress(htonl(ip)).toString(); + } + + } + i++; + } + } + } + } + } + } + + +} + +void readConnectionManagerDetails() +{ + qDBusRegisterMetaType(); + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + + uint state = iface.property("State").toUInt(); + switch(state) { + case NM_STATE_UNKNOWN: + qWarning() << "State: Unknown"; break; + case NM_STATE_ASLEEP: + qWarning() << "State: Asleep"; break; + case NM_STATE_CONNECTING: + qWarning() << "State: Connecting"; break; + case NM_STATE_CONNECTED: + qWarning() << "State: Connected"; break; + case NM_STATE_DISCONNECTED: + qWarning() << "State: Disconnected"; break; + } + //get list of network devices + QDBusReply > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + qWarning() << "Current devices:"; + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + QDBusInterface devIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_DEVICE, dbc); + if (devIface.isValid()) { + qWarning() << " Managed: " << devIface.property("Managed").toBool(); + qWarning() << " Interface: " << devIface.property("Interface").toString(); + qWarning() << " HAL UDI: " << devIface.property("Udi").toString(); + qWarning() << " Driver: " << devIface.property("Driver").toString(); + QVariant v = devIface.property("DeviceType"); + switch(v.toUInt()) { + case DEVICE_TYPE_UNKNOWN: + qWarning() << " DeviceType: Unknown" ; + break; + case DEVICE_TYPE_802_3_ETHERNET: + qWarning() << " DeviceType: Ethernet" ; + break; + case DEVICE_TYPE_802_11_WIRELESS: + qWarning() << " DeviceType: Wireless" ; + break; + case DEVICE_TYPE_GSM: + qWarning() << " DeviceType: GSM" ; + break; + case DEVICE_TYPE_CDMA: + qWarning() << " DeviceType: CDMA" ; + break; + + } + v = devIface.property("State"); + switch(v.toUInt()) { + case NM_DEVICE_STATE_UNKNOWN: + qWarning() << " State: Unknown" ; break; + case NM_DEVICE_STATE_UNMANAGED: + qWarning() << " State: Unmanaged" ; break; + case NM_DEVICE_STATE_UNAVAILABLE: + qWarning() << " State: Unavailable" ; break; + case NM_DEVICE_STATE_DISCONNECTED: + qWarning() << " State: Disconnected" ; break; + case NM_DEVICE_STATE_PREPARE: + qWarning() << " State: Preparing" ; break; + case NM_DEVICE_STATE_CONFIG: + qWarning() << " State: Being configured" ; break; + case NM_DEVICE_STATE_NEED_AUTH: + qWarning() << " State: Awaiting secrets" ; break; + case NM_DEVICE_STATE_IP_CONFIG: + qWarning() << " State: IP requested" ; break; + case NM_DEVICE_STATE_ACTIVATED: + qWarning() << " State: Activated" ; break; + case NM_DEVICE_STATE_FAILED: + qWarning() << " State: FAILED" ; break; + } + quint32 ip = devIface.property("Ip4Address").toUInt(); + qWarning() << " IP4Address: " << QHostAddress(htonl(ip)).toString(); + if (v.toUInt() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface.property("Ip4Config").value().path(); + qWarning() << " IP4Config: " << path; + QDBusInterface ipIface(NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_IP4_CONFIG, dbc); + if (ipIface.isValid()) { + qWarning() << " Hostname: " << ipIface.property("Hostname").toString(); + qWarning() << " Domains: " << ipIface.property("Domains").toStringList(); + qWarning() << " NisDomain: " << ipIface.property("NisDomain").toString(); + QDBusArgument arg= ipIface.property("Addresses").value(); + //qWarning() << " " << arg.currentType(); + qWarning() << " Addresses: " << ipIface.property("Addresses"); + qWarning() << " Nameservers: " << ipIface.property("Nameservers"); + qWarning() << " NisServers: " << ipIface.property("NisServers"); + } + + } + + } + } + } + + //get list of active connections + QVariant prop = iface.property("ActiveConnections"); + QList connections = prop.value >(); + QString activePath; + if ( connections.count() ) + qWarning() << "Active connections:"; + foreach(QDBusObjectPath path, connections) { + qWarning() << " " << path.path(); + activePath = path.path(); + QString serviceName; + QDBusInterface conIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_ACTIVE_CONNECTION, dbc); + if (conIface.isValid()) { + qWarning() << " default connection: " << conIface.property("Default").toBool(); + serviceName = conIface.property("ServiceName").toString(); + qWarning() << " service name: " << serviceName; + qWarning() << " connection path: " << conIface.property("Connection").value().path(); + qWarning() << " specific object:" << conIface.property("SpecificObject").value().path(); + qWarning() << " sharedServiceName: " << conIface.property("SharedServiceName").toString(); + QList devs = conIface.property("Devices").value >(); + qWarning() << " devices: "; + foreach(QDBusObjectPath p, devs) + qWarning() << " " << path.path(); + QVariant v = conIface.property("State"); + switch (v.toInt()) { + case NM_ACTIVE_CONNECTION_STATE_UNKNOWN: + qWarning()<< " State: unknown"; break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: + qWarning()<< " State: activating"; break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: + qWarning()<< " State: activated"; break; + } + } else { + qWarning() << conIface.lastError(); + } + + } + + printConnectionDetails(NM_DBUS_SERVICE_SYSTEM_SETTINGS); + printConnectionDetails(NM_DBUS_SERVICE_USER_SETTINGS); + + + //turn active connection off + /*QDBusObjectPath dbop("/org/freedesktop/NetworkManager/ActiveConnection/1"); + QVariant asd = QVariant::fromValue(dbop); + iface.call(QLatin1String("DeactivateConnection"), asd); + qWarning() << iface.lastError();*/ + + /*QDBusObjectPath p1device("/org/freedesktop/Hal/devices/net_00_60_6e_82_02_65"); + QVariant p1v = QVariant::fromValue(p1device); + QDBusObjectPath p1con("/org/freedesktop/NetworkManagerSettings/0"); + QVariant p1c = QVariant::fromValue(p1con); + QDBusObjectPath p1sp(""); + QVariant p1sp1 = QVariant::fromValue(p1sp); + iface.call(QLatin1String("ActivateConnection"), + QString("/org/freedesktop/NetworkManagerSystemSettings"), p1c,p1v, p1v ); + qWarning() << iface.lastError(); + */ +} + +int main( int argc, char** argv) +{ + QApplication app(argc, argv); + //readConnectionManagerDetails(); + QMainWindow main; + NMView view; + main.setCentralWidget(&view); + main.show(); + return app.exec(); + +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/networkmanager/nmview.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/networkmanager/nmview.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,1028 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "nmview.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +//#include "ui_dialog.h" + +#include +#include +#include +#include + +//static QDBusConnection dbc = QDBusConnection::systemBus(); +//typedef QMap< QString, QMap > SettingsMap; +//Q_DECLARE_METATYPE(SettingsMap) + + +NMView::NMView(QDialog* parent) + : QDialog(parent, 0), dbc(QDBusConnection::systemBus()) +{ + init(); + + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + updateConnections(); + getDevices(); +} + +NMView::~NMView() +{ +} +void NMView::init() +{ + setupUi(this); + sess = 0; +// readSettings(); + connect(startButton, SIGNAL(clicked()), this, SLOT(activate())); + connect(stopButton, SIGNAL(clicked()), this, SLOT(deactivate())); + connect(scanButton, SIGNAL(clicked()), this, SLOT(findAccessPoints())); + connect(updateButton, SIGNAL(clicked()), this, SLOT(update())); + + connect(cons, SIGNAL(itemActivated(QTreeWidgetItem*, int)), + this,SLOT(connectionItemActivated(QTreeWidgetItem*, int))); + + + connect(devicesTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*, int)), + this, SLOT(deviceItemActivated(QTreeWidgetItem*, int))); + + cons->header()->setResizeMode(QHeaderView::ResizeToContents); + devicesTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); + accessPointsTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); +// accessPointsTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); + + manager = new QNetworkConfigurationManager(this); + + connect(manager, SIGNAL(updateCompleted()), this, SLOT(updateCompleted())); + + connect(manager, SIGNAL(configurationAdded(const QNetworkConfiguration &)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + + devicesTreeWidget->header()->hideSection(0); + devicesTreeWidget->header()->hideSection(1); + devicesTreeWidget->header()->hideSection(3); + devicesTreeWidget->header()->hideSection(5); + devicesTreeWidget->header()->hideSection(6); + devicesTreeWidget->header()->hideSection(7); + devicesTreeWidget->header()->hideSection(8); + devicesTreeWidget->header()->hideSection(9); +} + +void NMView::updateConnections() +{ + cons->clear(); + manager->updateConfigurations(); + QList configs = manager->allConfigurations(); + foreach(QNetworkConfiguration p, configs) { + QStringList strlist; + strlist << p.name(); + strlist << stateToString(p.state()); + strlist << p.identifier(); + strlist << typeToString(p.type()); + QTreeWidgetItem *item; + item = new QTreeWidgetItem(strlist); + cons->insertTopLevelItem(0, item); + } + cons->sortItems ( 1, Qt::AscendingOrder); +} + +void NMView::getActiveConnections() +{ + QList configs = manager->allConfigurations(QNetworkConfiguration::Active); + foreach(QNetworkConfiguration p, configs) { + qWarning() << __FUNCTION__ << p.name() << p.identifier(); + } + +// QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); +// if (!iface.isValid()) { +// qWarning() << "Could not find NetworkManager"; +// return; +// } + +// QVariant prop = iface.property("ActiveConnections"); +// QList connections = prop.value >(); +// foreach(QDBusObjectPath path, connections) { +// QDBusInterface conDetails(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_ACTIVE_CONNECTION, dbc); +// if (conDetails.isValid()) { +// QString desc = path.path(); +// conDetails.property("Connection Path").value().path(); + +// QList devices = conDetails.property("Devices").value >(); +// +// foreach(QDBusObjectPath devpath, devices) { +// QDBusInterface devIface(NM_DBUS_SERVICE, devpath.path(), NM_DBUS_INTERFACE_DEVICE, dbc); +// desc += " "+devIface.property("Interface").toString(); +// desc += " "+QHostAddress(htonl(devIface.property("Ip4Address").toUInt())).toString(); + +// } + +// qWarning() << conDetails.property("Connection").value().path() << path.path(); + +// QListWidgetItem* item = new QListWidgetItem(desc, activeCons); +// item->setData(Qt::UserRole, path.path()); +// } +// } +} + +void NMView::update() +{ +// QNetworkManagerInterface *dbIface; +// dbIface = new QNetworkManagerInterface; +// QList connections = dbIface->activeConnections(); +// +// foreach(QDBusObjectPath conpath, connections) { +// QNetworkManagerConnectionActive *aConn; +// aConn = new QNetworkManagerConnectionActive(conpath.path()); +// // in case of accesspoint, specificObject will hold the accessPOintObjectPath +// qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); +// QList devs = aConn->devices(); +// foreach(QDBusObjectPath device, devs) { +// qWarning() << " " << device.path(); +// } +// } + + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + foreach (QString service, connectionServices) { + QDBusInterface allCons(service, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbc); + if (allCons.isValid()) { + QDBusReply > reply = allCons.call("ListConnections"); + if ( reply.isValid() ) { + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface sysIface(service, + path.path(), + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbc); + if (sysIface.isValid()) { + qWarning() << ""; + qWarning() << path.path(); + + // QDBusMessage r = sysIface.call("GetSettings"); + QDBusReply< QNmSettingsMap > rep = sysIface.call("GetSettings"); + + QMap< QString, QMap > map = rep.value(); + QList list = map.keys(); + foreach (QString key, list) { + QMap innerMap = map[key]; + qWarning() << " Key: " << key; + QMap::const_iterator i = innerMap.constBegin(); + + while (i != innerMap.constEnd()) { + QString k = i.key(); + qWarning() << " Key: " << k << " Entry: " << i.value(); + i++; + }//end innerMap + }//end foreach key + }//end settings connection + } // foreach path + } //end ListConnections + } //end settingsInterface + }// end services + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + if (iface.isValid()) { + QVariant prop = iface.property("ActiveConnections"); + QList connections = prop.value >(); + foreach(QDBusObjectPath conpath, connections) { + qWarning() << "Active connection" << conpath.path(); + QDBusInterface conDetails(NM_DBUS_SERVICE, + conpath.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + if (conDetails.isValid()) { + + QVariant prop = conDetails.property("Connection"); + QDBusObjectPath connection = prop.value(); + qWarning() << conDetails.property("Default").toBool() << connection.path(); + +// QVariant Sprop = conDetails.property("Devices"); +// QList so = Sprop.value >(); +// foreach(QDBusObjectPath device, so) { +// if(device.path() == devicePath) { +// path = connection.path(); +// } +// break; +// } + } + } + } +qWarning() << ""; +} + +void NMView::deactivate() +{ + QList configs = manager->allConfigurations(QNetworkConfiguration::Active); + foreach(QNetworkConfiguration p, configs) { + qWarning() << "Active cons" << p.name(); + if(p.name() == cons->currentItem()->text(0) + && p.identifier() == cons->currentItem()->text(2)) { + qWarning() <<__FUNCTION__<< p.name(); + if(!sess) { + sess = new QNetworkSession(p); + + connect(sess, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + connect(sess, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(networkSessionError(QNetworkSession::SessionError))); + } + sess->close(); + delete sess; + sess = 0; + } + } +} + +void NMView::activate() +{ + qWarning() << __FUNCTION__ << cons->currentItem()->text(0); + + QList configs = manager->allConfigurations(); + foreach(QNetworkConfiguration p, configs) { + if(p.name() == cons->currentItem()->text(0)) { + + sess = new QNetworkSession(p); + + connect(sess, SIGNAL(newConfigurationActivated()), + this, SLOT(getActiveConnections())); + + connect(sess, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + connect(sess, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(networkSessionError(QNetworkSession::SessionError))); + + sess->open(); + } + } +} + +void NMView::getDevices() +{ + qWarning() << ""; + qWarning() << __FUNCTION__; + devicesTreeWidget->clear(); + //qDBusRegisterMetaType(); + + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); +//NetworkManager interface + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + +// uint state = iface.property("State").toUInt(); +// switch(state) { +// case NM_STATE_UNKNOWN: +// qWarning() << "State: Unknown"; break; +// case NM_STATE_ASLEEP: +// qWarning() << "State: Asleep"; break; +// case NM_STATE_CONNECTING: +// qWarning() << "State: Connecting"; break; +// case NM_STATE_CONNECTED: +// qWarning() << "State: Connected"; break; +// case NM_STATE_DISCONNECTED: +// qWarning() << "State: Disconnected"; break; +// } + + //get list of network devices + QTreeWidgetItem *item; + QDBusReply > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { +// qWarning() << "Current devices:"; + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + QStringList devicesList; + qWarning() << " " << path.path(); + devicesList << path.path(); + + QDBusInterface devIface(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_DEVICE, + dbc); + if (devIface.isValid()) { + + + + ////// connect the dbus signal +// /*if(*/dbc.connect(NM_DBUS_SERVICE, +// path.path(), +// NM_DBUS_INTERFACE_DEVICE, +// "StateChanged", +// this,SLOT(deviceStateChanged(quint32))); +// { +// qWarning() << "XXXXXXXXXX dbus connect successful" << path.path(); +// } + + + // qWarning() << " Managed: " << devIface.property("Managed").toBool(); + devicesList << devIface.property("Managed").toString(); + // qWarning() << " Interface: " << devIface.property("Interface").toString(); + devicesList << devIface.property("Interface").toString(); + // qWarning() << " HAL UDI: " << devIface.property("Udi").toString(); + // qWarning() << " Driver: " << devIface.property("Driver").toString(); + devicesList << devIface.property("Driver").toString(); + + QString x = deviceTypeToString(devIface.property("DeviceType").toUInt()); + // qWarning() << " Type:" << x; + devicesList << x; + + if( devIface.property("DeviceType").toUInt() == DEVICE_TYPE_802_11_WIRELESS) { + qWarning() << "Device is WIFI"; + // // findAccessPoints(path.path()); + } + + QVariant v = devIface.property("State"); + x = deviceStateToString(v.toUInt()); +// qWarning() << " State:" << x; + devicesList << x; + + quint32 ip = devIface.property("Ip4Address").toUInt(); +// qWarning() << " IP4Address: " << QHostAddress(htonl(ip)).toString(); + devicesList << QHostAddress(htonl(ip)).toString(); + + + if (v.toUInt() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface.property("Ip4Config").value().path(); +// qWarning() << " IP4Config: " << path; + devicesList << path; + QDBusInterface ipIface(NM_DBUS_SERVICE, + path, + NM_DBUS_INTERFACE_IP4_CONFIG, + dbc); + if (ipIface.isValid()) { + // qWarning() << " Hostname: " << ipIface.property("Hostname").toString(); + devicesList << ipIface.property("Hostname").toString(); +// qWarning() << " Domains: " << ipIface.property("Domains").toStringList(); + devicesList << ipIface.property("Domains").toStringList().join(", "); +// qWarning() << " NisDomain: " << ipIface.property("NisDomain").toString(); + QDBusArgument arg= ipIface.property("Addresses").value(); +// qWarning() << " Addresses: " << ipIface.property("Addresses"); +// qWarning() << " Nameservers: " << ipIface.property("Nameservers"); +// qWarning() << " NisServers: " << ipIface.property("NisServers"); + } + + } + + } + item = new QTreeWidgetItem(devicesList); + devicesTreeWidget->insertTopLevelItem(0, item); + } + } + + +// netconfig(); + +} + +void NMView::readSettings() +{ + QDBusInterface settingsiface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbc); + //NetworkManagerSettings interface + if (settingsiface.isValid()) { + QDBusReply > reply = settingsiface.call("ListConnections"); + if ( reply.isValid() ) { + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() <<__FUNCTION__ << path.path(); + + } + } + } + + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + + // QStringList list = item->text().split(" -> "); + + QVariant prop = iface.property("ActiveConnections"); + QList connections = prop.value >(); + foreach(QDBusObjectPath path, connections) { + QDBusInterface conDetails(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + + if (conDetails.isValid()) { + QString desc = path.path(); + qWarning() << desc; + //if ( item->text(0) == conDetails.property("Connection").value().path() ) { + // QListWidgetItem* item = new QTreeWidgetItem( desc, + // cons); + // item->setData(Qt::UserRole, desc); + // activeItemActivated( item ); + //} + } + } +} + +void NMView::printConnectionDetails(const QString& service) +{ + Q_UNUSED(service); + +// +// qWarning() << __FUNCTION__ << service; +// +// QDBusConnection dbc = QDBusConnection::systemBus(); +// if (!dbc.isConnected()) { +// qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); +// return; +// } +// QDBusInterface allCons(service, +// NM_DBUS_PATH_SETTINGS, +// NM_DBUS_IFACE_SETTINGS, +// dbc); +// +// if (allCons.isValid()) { +// QDBusReply > reply = allCons.call("ListConnections"); +// +// if ( reply.isValid() ) { +// qWarning() << "Known connections:"; +// QList list = reply.value(); +// +// foreach(QDBusObjectPath path, list) { +// qWarning() << " " << path.path(); +// +// QDBusInterface sysIface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, +// path.path(), +// NM_DBUS_IFACE_SETTINGS_CONNECTION, +// dbc); +// +// if (sysIface.isValid()) { +// QDBusMessage r = sysIface.call("GetSettings"); +// QDBusReply< QSettingsMap > rep = sysIface.call("GetSettings"); +// +// qWarning() << " GetSettings:" << r.arguments() << r.signature() << rep.isValid() << sysIface.lastError(); +// +// QMap< QString, QMap > map = rep.value(); +// QList list = map.keys(); +// +// foreach (QString key, list) { +// QMap innerMap = map[key]; +// qWarning() << " Key: " << key; +// QMap::const_iterator i = innerMap.constBegin(); +// +// while (i != innerMap.constEnd()) { +// QString k = i.key(); +// qWarning() << " Key: " << k << " Entry: " << i.value(); +// +// if (k == "addresses" && i.value().canConvert()) { +// QDBusArgument arg = i.value().value(); +// arg.beginArray(); +// +// while (!arg.atEnd()) { +// QDBusVariant addr; +// arg >> addr; +// uint ip = addr.variant().toUInt(); +// qWarning() << ip; +// qWarning() << " " << QHostAddress(htonl(ip)).toString(); +// } +// +// } +// i++; +// } +// } +// } +// } +// } +// } + qWarning() << ""; +} + +void NMView::getNetworkDevices() +{ + +} + +void NMView::connectionItemActivated( QTreeWidgetItem * item, int col ) +{ + Q_UNUSED(col); + + qWarning() <<__FUNCTION__<< item->text(0); + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + QVariant prop = iface.property("ActiveConnections"); + QList connections = prop.value >(); + foreach(QDBusObjectPath path, connections) { + QDBusInterface conDetails(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + + if (conDetails.isValid()) { + QString desc = path.path(); + qWarning() << desc; + if ( item->text(0) == conDetails.property("Connection").value().path() ) { +// QListWidgetItem* item = new QTreeWidgetItem( desc, +// cons); +// item->setData(Qt::UserRole, desc); +// activeItemActivated( item ); + } + } + } +} + + + +void NMView::deviceItemActivated( QTreeWidgetItem * item , int section) +{ + Q_UNUSED(item); + Q_UNUSED(section); + + // qWarning() << item->text(section) << item->text(4); + //if(item->text(4) == "Wireless") findAccessPoints(item->text(0)); +} + + +void NMView::netconfig() +{ +// qWarning() << __FUNCTION__; + +// qDBusRegisterMetaType(); + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager Settings"; + return; + } else { + QDBusReply > reply = iface.call("ListConnections"); + QList list = reply.value(); +// qWarning() << reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + } + } +} + + +void NMView::findAccessPoints() +{ + accessPointsTreeWidget->clear(); + + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + + QDBusReply > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface devIface(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_DEVICE, + dbc); + if (devIface.isValid()) { + + if( devIface.property("DeviceType").toUInt() == DEVICE_TYPE_802_11_WIRELESS) { + +// qWarning() <<"deviface"<< devIface.path(); + QDBusInterface wififace(NM_DBUS_SERVICE, + devIface.path(), + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + dbc); + if (!wififace.isValid()) { + qWarning() << "Could not find NetworkManager wireless interface"; + return; + } + +///////////////////////// +// if(dbc.connect(NM_DBUS_SERVICE, +// path.path(), +// NM_DBUS_INTERFACE_DEVICE_WIRELESS, +// "PropertiesChanged", +// this,SLOT(aPPropertiesChanged( QMap))) ) { +// qWarning() << "PropertiesChanged connect"; +// } else { +// qWarning() << "NOT connect"; + +// } +///////////////////////// + qWarning() <<"wififace"<< wififace.path(); + QDBusReply > reply2 = wififace.call("GetAccessPoints"); + if ( reply2.isValid() ) { + QTreeWidgetItem *item; + QList list2 = reply2.value(); + foreach(QDBusObjectPath path2, list2) { + QDBusInterface accessPointIface(NM_DBUS_SERVICE, + path2.path(), + NM_DBUS_INTERFACE_ACCESS_POINT, + dbc); + if (accessPointIface.isValid()) { +//// qWarning() <<"path2" << path2.path(); + +// if(dbc.connect(NM_DBUS_SERVICE, //signal strength +// path2.path(), +// NM_DBUS_INTERFACE_ACCESS_POINT, +// "PropertiesChanged", +// this,SLOT(aPPropertiesChanged( QMap))) ) { +// qWarning() << "PropertiesChanged connect"; +// } else { +// qWarning() << "NOT connect"; +// +// } + + QStringList accessPoints; + accessPoints << accessPointIface.property("Ssid").toString(); + accessPoints << QString::number(accessPointIface.property("Strength").toInt()); + accessPoints << securityCapabilitiesToString(accessPointIface.property("WpaFlags" ).toInt()); + accessPoints << securityCapabilitiesToString(accessPointIface.property("RsnFlags" ).toInt()); + accessPoints << accessPointIface.property("Frequency" ).toString(); + accessPoints << accessPointIface.property("HwAddress" ).toString(); + accessPoints << deviceModeToString(accessPointIface.property("Mode" ).toInt()); + accessPoints << accessPointIface.property("MaxBitrate" ).toString(); + //HwAddress + // if(accessPointIface.property("Flags" ).toInt() == NM_802_11_AP_FLAGS_PRIVACY ) { + // qWarning() << "Secure"; + // } + item = new QTreeWidgetItem(accessPoints); + accessPointsTreeWidget->insertTopLevelItem(0, item); + } + } + } + } + } + } + } +} + +QString NMView::deviceStateToString(int state) +{ + QString ret; + switch(state) { + case NM_DEVICE_STATE_UNKNOWN: + ret = "Unknown"; + break; + case NM_DEVICE_STATE_UNMANAGED: + ret = "Unmanaged"; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + ret = "Unavailable"; + break; + case NM_DEVICE_STATE_DISCONNECTED: + ret = "Disconnected"; + break; + case NM_DEVICE_STATE_PREPARE: + ret = "Preparing to connect"; + break; + case NM_DEVICE_STATE_CONFIG: + ret = "Being configured"; + break; + case NM_DEVICE_STATE_NEED_AUTH: + ret = "Awaiting secrets"; + break; + case NM_DEVICE_STATE_IP_CONFIG: + ret = "IP requested"; + break; + case NM_DEVICE_STATE_ACTIVATED: + ret = "Activated"; + break; + case NM_DEVICE_STATE_FAILED: + ret = "FAILED"; + break; + }; + return ret; +} + +QString NMView::deviceTypeToString(int device) +{ + QString ret; + switch(device) { + case DEVICE_TYPE_UNKNOWN: + ret = "Unknown"; + break; + case DEVICE_TYPE_802_3_ETHERNET: + ret = "Ethernet"; + break; + case DEVICE_TYPE_802_11_WIRELESS: + ret = "Wireless"; + break; + case DEVICE_TYPE_GSM: + ret = "GSM"; + break; + case DEVICE_TYPE_CDMA: + ret = "CDMA"; + break; + }; + return ret; +} + +QString NMView::securityCapabilitiesToString(int caps) +{ + int check = caps; +// qWarning() << __FUNCTION__<< caps; + QString ret; + if( check == 0 ) + ret += "None."; + if( (check & NM_802_11_AP_SEC_PAIR_WEP40)) + ret += " 40-bit WEP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_WEP104) ) + ret += " 104-bit WEP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_TKIP) ) + ret += " TKIP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_CCMP) ) + ret += " CCMP encryption. "; + if( (check & NM_802_11_AP_SEC_GROUP_WEP40)) + ret += " 40-bit WEP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_WEP104)) + ret += " 104-bit WEP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_TKIP) ) + ret += " TKIP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_CCMP) ) + ret += " CCMP cipher. "; + if( (check & NM_802_11_AP_SEC_KEY_MGMT_PSK)) + ret += " PSK key management. "; + if( (check & NM_802_11_AP_SEC_KEY_MGMT_802_1X) ) + ret += " 802.1x key management. "; + return ret; +} + +QString NMView::deviceModeToString(int mode) +{ + QString ret; + switch (mode) { + case NM_802_11_MODE_UNKNOWN: + ret = "Unknown"; + break; + case NM_802_11_MODE_ADHOC: + ret = " (Adhoc)."; + break; + case NM_802_11_MODE_INFRA: + ret = " (Infrastructure)"; + }; + return ret; +} + +void NMView::netManagerState(quint32 state) +{ + qWarning() << __FUNCTION__ << state;// << old << reason; + switch(state) { + case NM_STATE_UNKNOWN: + qWarning() << "The NetworkManager daemon is in an unknown state. "; + break; + case NM_STATE_ASLEEP: + qWarning() << "The NetworkManager daemon is asleep and all interfaces managed by it are inactive. "; + break; + case NM_STATE_CONNECTING: + qWarning() << "The NetworkManager daemon is connecting a device. FIXME: What does this mean when one device is active and another is connecting? "; + break; + case NM_STATE_CONNECTED: + qWarning() <<"The NetworkManager daemon is connected. "; + break; + case NM_STATE_DISCONNECTED: + qWarning() << "The NetworkManager daemon is disconnected."; + break; + + }; +} + +void NMView::deviceStateChanged(quint32 state) +{ + qWarning() << __FUNCTION__ << state; + switch(state) { + case NM_DEVICE_STATE_UNKNOWN : + qWarning() <<"The device is in an unknown state. "; + break; + case NM_DEVICE_STATE_UNMANAGED: + qWarning() <<"The device is not managed by NetworkManager."; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + qWarning() <<"The device cannot be used (carrier off, rfkill, etc)."; + break; + case NM_DEVICE_STATE_DISCONNECTED: + qWarning() <<"The device is not connected."; + break; + case NM_DEVICE_STATE_PREPARE: + qWarning() <<"The device is preparing to connect."; + break; + case NM_DEVICE_STATE_CONFIG: + qWarning() <<"The device is being configured."; + break; + case NM_DEVICE_STATE_NEED_AUTH: + qWarning() <<"The device is awaiting secrets necessary to continue connection."; + break; + case NM_DEVICE_STATE_IP_CONFIG: + qWarning() <<"The IP settings of the device are being requested and configured."; + break; + case NM_DEVICE_STATE_ACTIVATED: + qWarning() <<"The device is active."; + break; + case NM_DEVICE_STATE_FAILED: + qWarning() <<"The device is in a failure state following an attempt to activate it."; + break; + }; +} + +void NMView::updateCompleted() +{ + qWarning() << __FUNCTION__; +} + +void NMView::newConfigurationActivated() +{ + qWarning() << __FUNCTION__; + getActiveConnections(); +} + +void NMView::stateChanged(QNetworkSession::State state) +{ + // QString stateStringstr; + switch (state) { + case QNetworkSession::Invalid: + stateString = "Invalid session"; + break; + case QNetworkSession::NotAvailable: + stateString = "Session is defined but not yet discovered"; + break; + case QNetworkSession::Connecting: + stateString = "Session is being established"; + break; + case QNetworkSession::Connected: + stateString = "Session is active and can be used for socket operations"; + cons->currentItem()->setText(1, "Active"); + break; + case QNetworkSession::Closing: + stateString = "Session is being shutdown"; + break; + case QNetworkSession::Disconnected: + qWarning() << __FUNCTION__; + manager->updateConfigurations(); + stateString = "Session disconnected"; + cons->currentItem()->setText(1,"Discovered") ; + break; + case QNetworkSession::Roaming: + stateString = "session is roaming from one AP to another"; + break; + }; + qWarning() << __FUNCTION__ << state << stateString; +} + +QString NMView::stateToString(int state) +{ + switch (state) { + case QNetworkConfiguration::Undefined: + return "Undefined"; + break; + case QNetworkConfiguration::Defined: + return "Defined"; + break; + case QNetworkConfiguration::Discovered: + return "Discovered"; + break; + case QNetworkConfiguration::Active: + return "Active"; + break; + }; + return ""; +} + +void NMView::configurationAdded(const QNetworkConfiguration &config) +{ + qWarning() << __FUNCTION__<< config.name() << config.identifier(); +} + +QString NMView::typeToString(int type) +{ + switch(type) { + case QNetworkConfiguration::InternetAccessPoint: + return "Internet AccessPoint"; + break; + case QNetworkConfiguration::ServiceNetwork: + return "Service Network"; + break; + }; + return QString(); +} + +void NMView::aPPropertiesChanged( QMap map) +{ + //QMap::const_iterator iterator = d->values.find(type + QLatin1String("Path")) + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().toUInt(); +// deviceStateChanged(i.value().toUInt()); + } else if( i.key() == "ActiveAccessPoint") { + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().value().path(); + } else if( i.key() == "Strength") + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().toUInt(); + else + qWarning() << __FUNCTION__ << i.key() << ": " << i.value(); + } +} + +void NMView::networkSessionError(QNetworkSession::SessionError error) +{ + QString errorStr; + switch(error) { + case QNetworkSession::RoamingError: + errorStr = "Roaming error"; + break; + case QNetworkSession::SessionAbortedError: + errorStr = "Session aborted by user or system"; + break; + default: + case QNetworkSession::UnknownSessionError: + errorStr = "Unidentified Error"; + break; + }; + + QMessageBox::warning(this, tr("NMView"), errorStr, QMessageBox::Ok); +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/networkmanager/nmview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/networkmanager/nmview.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "ui_dialog.h" + +QTM_USE_NAMESPACE + +QT_BEGIN_NAMESPACE +class QListWidget; +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +class NMView : public QDialog, private Ui::Dialog +{ + Q_OBJECT +public: + NMView(QDialog* parent = 0); + virtual ~NMView(); + +private: + void init(); + QString stateString; + + QDBusConnection dbc; + void printConnectionDetails(const QString&); + + QString deviceStateToString(int state); + QString deviceTypeToString(int device); + QString securityCapabilitiesToString(int caps); + QString deviceModeToString(int mode); +//QDBusInterface getInterface(); + QNetworkConfigurationManager *manager; + QNetworkSession *sess; + QString stateToString(int state); + QString typeToString(int type); + +private slots: + void update(); + void deactivate(); + void activate(); + void getActiveConnections(); + void updateConnections(); + void getDevices(); + // void readConnectionManagerDetails(); + void getNetworkDevices(); + void connectionItemActivated( QTreeWidgetItem *, int); +// void activeItemActivated( QListWidgetItem *); + void deviceItemActivated( QTreeWidgetItem *, int); + void netconfig(); + void findAccessPoints(); + + void netManagerState(quint32); + void readSettings(); + void updateCompleted(); + void newConfigurationActivated(); + + void stateChanged(QNetworkSession::State); + void deviceStateChanged(quint32 state); + + void configurationAdded(const QNetworkConfiguration &config); + void aPPropertiesChanged( QMap map); + void networkSessionError(QNetworkSession::SessionError); + +}; diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/networkmanager/startdlg.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/networkmanager/startdlg.cpp Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "startdlg.h" +#include + + +StartDialog::StartDialog(QWidget * parent) + :QDialog(parent) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + box = new QComboBox(); + layout->addWidget(box); + + QHBoxLayout* hbox = new QHBoxLayout(); + QPushButton* start = new QPushButton("Start"); + connect(start, SIGNAL(clicked()), this, SLOT(accept())); + QPushButton* cancel = new QPushButton("Cancel"); + connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); + + + hbox->addWidget(start); + hbox->addWidget(cancel); + + layout->addLayout(hbox); + + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + QDBusReply > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface devIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_DEVICE, dbc); + if ( devIface.isValid() ) { + box->addItem(devIface.property("Interface").toString(), QVariant(path.path())); + } + } + } +} + +QString StartDialog::device() const +{ + return dev; +} + +void StartDialog::accept() +{ + dev = box->itemData(box->currentIndex(), Qt::UserRole).toString(); + QDialog::accept(); +} diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/networkmanager/startdlg.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/networkmanager/startdlg.h Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include + +class StartDialog : public QDialog +{ + Q_OBJECT +public: + StartDialog(QWidget* parent = 0); + + QString device() const; + +public slots: + void accept(); +private: + QString dev; + QComboBox* box; +}; diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/rom/qtmobilitytests.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/rom/qtmobilitytests.iby Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published by +* the Free Software Foundation, version 2.1 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this program. If not, +* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". +* +* Description: +* +*/ + +#ifndef __QT_MOBILITYTESTS_IBY__ +#define __QT_MOBILITYTESTS_IBY__ + +#include + +#define UPGRADABLE_APP_REG_RSC(NAME) data=DATAZ_\PRIVATE\10003A3F\IMPORT\APPS\ ## NAME ## _reg.rsc Private\10003a3f\import\apps\ ## NAME ## _reg.rsc + +S60_APP_EXE(bearerex) +S60_APP_RESOURCE(bearerex) +UPGRADABLE_APP_REG_RSC(bearerex) + +#endif //__QT_MOBILITYTESTS_IBY__ diff -r 000000000000 -r cfcbf08528c4 qtmobility/tests/tests.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtmobility/tests/tests.pro Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,13 @@ +include(../staticconfig.pri) + +TEMPLATE = subdirs +SUBDIRS += auto + +contains(mobility_modules,bearer) { + contains(QT_CONFIG,dbus) { + !symbian:!mac:!maemo6:!maemo5:unix:SUBDIRS += networkmanager + } + symbian:SUBDIRS += bearerex +} + +#BLD_INF_RULES.prj_exports += "./rom/qtmobilitytests.iby $$CUSTOMER_VARIANT_APP_LAYER_IBY_EXPORT_PATH(qtmobilitytests.iby)" diff -r 000000000000 -r cfcbf08528c4 sysdef_1_5_1.dtd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sysdef_1_5_1.dtd Thu Apr 01 08:30:34 2010 +0300 @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +