Abuuritaanka Macaamiil [Vala iyo Gtk 3]

Caadi ahaan Linux waxaan ka maqanahay waxoogaa codsiyo ah, ama macaamiisha adeegyada qaar ka mid ah oo goor hore u soo baxa barnaamijyada kale, maxaa yeelay casharkaan waxaan ku arki doonaa sida loo abuuro macmiil (waxay noqon doontaa aragti fog oo ka sareysa), iyadoo la adeegsanayo REST API qiimo leh (iyo gtk 3).

API

Ma doonayo inaan sharaxo waxa uu yahay API, ama waxa loo yaqaan 'REST API' (waxaad ka heli kartaa macluumaad badan google), kaliya waxaan dhihi doonaa qiyaas ahaan waxaan sameyn doonaa codsiyo (GET ama POST) waana ku soo celi jawaabta qaabka JSON.

Casharrada waxaan go'aansaday inaan u adeegsado api-ka ay na siiso yaabina (fiiri dukumiintiyada api), oo na siinaya macluumaad taxane ah oo ku saabsan majaajillada, jilayaasha ...

Si aan u helno waxaan u baahanahay fure, oo aan ku heli karno diiwaangelinta, markii aan helno waxaan xaddidan nahay 3000 codsi.

Aan aragno tusaale API, si loogu yeero api-kan waa inaan isticmaalnaa furayaasheena (waxaan leenahay mid caam ah iyo mid gaar ah):

m

Si aan u aragno tusaalahan fudud waxaan adeegsan karnaa www.md5.net halka aan dhigno 1 "+" keyprivate "+" keypublic taasna waxay soo saartaa xashiishka, waan wici karnaa sida ay sawirka u dhigeyso. Waxaan heli doonaa jawaabta (kiiskan waa inaan aragno jilayaasha):

cilad ayaa ku jirta sawirka wicitaanku wuxuu noqon lahaa http://gateway.marvel.com/v1/dadweynaha/ majaajilo ...

mm

Waxaa jira barnaamijyo iyo waxyaabo loogu talagalay daalacayaasha oo fududeyn doona aragtida json:

m1 Waan arki karnaa inay ina siineyso magaca, sharraxaadda, thumbnail (sawirka astaamaha) ...

horumarinta webka yaabka leh

Ku daweynta JSON vala (Parseando).

Mana sharxi doono waxa qaababku yihiin json, waxaad ka heli kartaa macluumaadka khadka tooska ah. Waxaan ka heli karnaa tusaale fudud oo lagu sameeyay Vala Halkan.

Ugu horreyntii waxaan rakibnaa maktabadda json-glib haddii ay dhacdo inaannaan rakibin:

sudo apt-hel ku rakib libjson-glib-1.0-0 libjson-glib-1.0-0-dev

Waxaan sidoo kale rakibi doonaa libsoup:

sudo apt-get rakibi libsoup-2.4 libsoup2.4-dev
Furaha dadweynaha ama xashiishka u saari maayo codsiyada

Marka hore waxaan soo dejineynaa maktabadaha aan isticmaali doono:

adeegsiga Maraqa; adeegsiga Json; adeegsiga Gtk;

Diraya codsi:

var uri = "http://gateway.marvel.com/v1/public/comics?dateRange=2014-16-03%2C2014-16-03&orderBy=-onsaleDate&limit=10&ts=1&apikey=123&hash=555224458"; kalfadhiga var = Soup.SessionSync cusub (); farriin kala duwan = maraq cusub.Message ("GET", uri); fadhiga.send_message (fariin);

Urlku wuxuu na tusi doonaa ugu badnaan 10 majaajilo ah oo soo muuqday inta udhaxeysa 2 taariikho (00-03-2014, 16-03-2014).
Ugu horreyntii waxaan abuureynaa kalfadhi, ka dib waxaan dhisnaa codsiga nooca GET oo aan dirnaa.

Parseying json:

var root_object = parser.get_root () .get_object ();

wuxuu helaa sheyga ugu muhiimsan ie dhammaan koodhka json.

jawaab celin = root_object.get_object_member ("xogta"); natiijooyinka kala duwan = response.get_array_member ("natiijooyinka");

Waan qaban karnaa

Nidaaminta lambarka:

food (var geonode in results.get_elements ()) {var geoname = geonode.get_object (); stdout.printf ("% f \ n% s \ n% s \ n \ n", geoname.get_string_member ("id"), geoname.get_string_member ("magac"), geoname.get_double_member ("sharaxaad")); }

Waxaad arki kartaa tusaalooyin Halkan.

Muujinta macluumaadka:

Halkan waxaan horeyba u galnay sida aan u jecelnahay sida loo soo bandhigo macluumaadka, si aan u soo dejino sawirrada aan u adeegsan karno habkan:

async joogto ah Gdk.Pixbuf? get_img (url string) {Gdk.Pixbuf? pix = null; var file = File.new_for_uri (url); iskuday {GLib.InputStream @input_stream = dhalinta file.read_async (Mudnaanta.DEFAULT, null); pix = dhaliya Gdk.Pixbuf.from_stream_at_scale_async cusub (input_stream, 800, 600, run, null); } qabasho (Cilad e) {digniin (e.message); } soo noqo pix; }

Ahaanshaha hab lagu fuliyo dun kale (asynchronous) markii aad soo waceyso waa inaan ku sameynaa sidan:

get_img.begin (img_url, (obj, res) => {var pix = get_img.end (res);});

Halkee img_url yahay url sawirka aan ka helno json.

Si loo soo ururiyo aremos:

valac --pkg gtk + -3.0 --pkg libsoup-2.4 --pkg json-glib-1.0 customername.vala
Waxaan ka heli karnaa dukumiinti json-glib Halkan.

Talooyin

Qaar ka mid ah Talooyinka naga caawin kara abuuritaanka macmiilkeena / codsigeenna:

Qeexitaan

AppIndicator waa maktabad noo oggolaaneysa inaan barnaamijkeenna ka dhigno tilmaame qeybta sare (labadaba Elementary os iyo Ubuntu).

Ku rakibidda caddeyn 3-0.1

sudo apt-hel rakib libappindicator3-dev

Uruurinta:

valac --pkg gtk + -3.0 - qeexidappg3-0.1 barnaamijka.vala

Haddii ay dhacdo inaad qalad hesho, waxaa laga yaabaa inay tahay maxaa yeelay waxaad leedahay nooc cusub oo ah qeexeeyaha, haddii ay dhacdo tag / usr / share / vala / vapi waxaadna arki doontaa noocaagu.

Qabsashada 2014-02-23 15:30:57

Waxaan ka heli karnaa tusaale ah Websaydhka horumarinta Ubuntu.

Tusaale yar:

Qabsashada 2014-02-23 17:04:52

 

kala duwan tilmaame = Tusiyaha cusub ("win.title", "office-address-book", IndicatorCategory.APPLICATION_STATUS); tilmaame.set_status (IndicatorStatus.ACTIVE); var menu = cusub Gtk.Menu (); var item = cusub Gtk.MenuItem.with_label ("Ku dar xiriir cusub"); item.activate.connect (() => {//indicator.set_status(IndicatorStatus.ATTENTION); // CreateContact ();}); shey.sho (); menu.append (shey); shey = cusub Gtk.MenuItem.with_label ("Delete contact"); shey.sho (); item.activate.connect (() => {//indicator.set_status(IndicatorStatus.ATTENTION); // DeleteContact ();}); menu.append (shey); tilmaame.set_menu (menu);

Sawirro

Ku dhig astaan ​​dalabkeena:

Waxaan ka bilaabaynaa dhisaha fasalka Gtk.Window:

iskuday {// Buugga sawirka ee this.icon = cusub Gdk.Pixbuf.from_file ("fcbb.png"); } qabashada (Error e) {stderr.printf ("error:% s \ n", e.message); }

Qabsashada 2014-02-23 15:44:00

 

Sawir fudud

Sawir fudud oo ku jira Vala oo aan ku dhejin karno tusaale ahaan qaabeynta.

sawir = cusub Gtk. Sawir (); image.set_from_file ("fcb.png");

fcb

Fikrad

U adeegso vala iyo gtk macaamiisha? maya, aragtidayda feker ahaan way kafiicantahay uguna fududaan in la isticmaalo c ++ iyo Qt (QML), waxay sugeysaa in la sameeyo maqaal macaamiil loogu sameeyo QML.


Nuxurka maqaalka wuxuu u hogaansamayaa mabaadi'deena anshaxa tifaftirka. Si aad u soo sheegto khalad guji Halkan.

2 faallooyin, ka tag taada

Ka tag faalladaada

cinwaanka email aan la daabacin doonaa.

*

*

  1. Masuul ka ah xogta: Miguel Ángel Gatón
  2. Ujeedada xogta: Xakamaynta SPAM, maaraynta faallooyinka.
  3. Sharci: Oggolaanshahaaga
  4. Isgaarsiinta xogta: Xogta looma gudbin doono dhinacyada saddexaad marka laga reebo waajibaadka sharciga ah.
  5. Kaydinta xogta: Macluumaadka ay martigelisay Shabakadaha Occentus (EU)
  6. Xuquuqda: Waqti kasta oo aad xadidi karto, soo ceshan karto oo tirtiri karto macluumaadkaaga.

  1.   Marcos dijo

    mahadsanid carnal 😀, waa wax aad u wanaagsan in la arko waxa "dhowr sadar oo koodh ah" ay sameyn karaan markaad aqoon leedahay. tusaaluhu wuxuu siinayaa fikrado badan waxyaabo kale 😀

  2.   Waqti dheer 3000 dijo

    Talooyin aad u wanaagsan, bro.

    Eeg haddii aan samayn karo mid.

bool (run)